-1

I have software built on Zend and in PHP.

I am looking for a way to let each user choose the time delay before an appointment reminder email will be sent.

For Example:

User 1: Wants to send email 12 hours before event. User 2: Wants to send email 24 hours before event or appointment.

I can use a cron job to search and trigger an event based on a specific time before or after an event, but I can't find a way to let users customize it the way they want it.

Your help for a workaround would be greatly appreciated!

Grant Miller
  • 27,532
  • 16
  • 147
  • 165

1 Answers1

0

So why cant you provide them somewhere to input an option (or set group of options. ie 30min, 1hr, 3hr, 6hr, 12hr, 24hr etc) - then store that value in a table with a reference to the appointment and the user it applies to?

Something like:

  id    |    appointment   |       user       |   reminder(hrs)  |   sent
   1    |    Joe's Bday    |   jack@test.com  |       24         |     1
   2    |    Joe's Bday    |   mary@test.com  |       12         |     0

Example of how you'd use it

$query = "Select * from remindertable;"
$query_results = mysqli_query($db, $query);
while($row = mysqli_fetch_row($query_results)) {
   if($row[4] == 0) {       

      $query = "SELECT appt-time FROM <table w data> WHERE appt-name = '" .$row[1] ."' AND appt-user ='" .$row[2] ."'";
      $timequery = mysqli_query($db, $query);
      $timequery = mysqli_fetch_assoc($timequery);

      $appt-time = date('Y-m-d H:I:S', strtotime($timequery['appt-time']));
      $appt-time2 = new DateTime($appt-time);

      //Get Current Time from Database
      $query = "SELECT NOW()";
      $currentQuery = mysqli_query($db, $query);
      $currentQuery = mysqli_fetch_array($currentQuery);

      $current-time = date('Y-m-d H:I:S', strtotime($currentQuery[0]));
      $current-time2 = new DateTime($current-time);

      $interval = $current-time2->diff($appt-time2);

      //CHECK THE INTERVAL AGAINST THE VALUE FROM THE DATABASE AND UPDATE WHEN SENT
   }

}

http://php.net/manual/en/class.datetime.php

http://php.net/manual/en/datetime.diff.php

http://php.net/manual/en/class.dateinterval.php

James F
  • 169
  • 10
  • Thanks a lot for the idea! Do you think it would be a good idea to have it set by type of service-instead of having to input it for every appointment. I could have a script determine the type of appointment it is and then see the exact delay set for the service type. – Justin Forest Aug 31 '18 at 22:05
  • Ultimately thats going to depend on exactly how you intend to use it. The above allows for users to get different times to different events. Lets say with your service idea we classify as "Parties" if parties for Mary is set to 12 hours. so every party would send out reminder at 12hours. But what if Mary wants Boss' Bday to be 24 hrs instead so she doesnt forget a gift? – James F Sep 04 '18 at 18:31