function get_cal_reminders() { // Get persons reminders $query = prepare("SELECT * \n FROM reminder\n JOIN reminderRecipient ON reminderRecipient.reminderID = reminder.reminderID\n WHERE personID = %d\n AND (reminderRecuringInterval = 'No' OR (reminderRecuringInterval != 'No' AND reminderActive))\n GROUP BY reminder.reminderID", $this->person->get_id()); $this->db->query($query); $reminders = array(); while ($row = $this->db->row()) { $reminder = new reminder(); $reminder->read_db_record($this->db); if ($reminder->is_alive()) { $reminderTime = format_date("U", $reminder->get_value("reminderTime")); // If repeating reminder if ($reminder->get_value('reminderRecuringInterval') != "No" && $reminder->get_value('reminderRecuringValue') != 0) { $interval = $reminder->get_value('reminderRecuringValue'); $intervalUnit = $reminder->get_value('reminderRecuringInterval'); while ($reminderTime < format_date("U", $this->last_date) + 86400) { $row["reminderTime"] = $reminderTime; $reminders[date("Y-m-d", $reminderTime)][] = $row; $reminderTime = $reminder->get_next_reminder_time($reminderTime, $interval, $intervalUnit); } // Else if once off reminder } else { $row["reminderTime"] = $reminderTime; $reminders[date("Y-m-d", $reminderTime)][] = $row; } } } return $reminders; }
$query = prepare("SELECT *\n FROM reminder\n WHERE reminderActive = 1\n AND reminderAdvNoticeSent = 0\n AND NOW() > \n CASE\n WHEN reminderAdvNoticeInterval = 'Minute' THEN DATE_SUB(reminderTime, INTERVAL reminderAdvNoticeValue MINUTE)\n WHEN reminderAdvNoticeInterval = 'Hour' THEN DATE_SUB(reminderTime, INTERVAL reminderAdvNoticeValue HOUR)\n WHEN reminderAdvNoticeInterval = 'Day' THEN DATE_SUB(reminderTime, INTERVAL reminderAdvNoticeValue DAY)\n WHEN reminderAdvNoticeInterval = 'Week' THEN DATE_SUB(reminderTime, INTERVAL reminderAdvNoticeValue WEEK)\n WHEN reminderAdvNoticeInterval = 'No' THEN NULL\n END\n "); $db->query($query); while ($db->next_record()) { $reminder = new reminder(); $reminder->read_db_record($db); //echo "<br>Adv: ".$reminder->get_id(); $current_user = new person(); $current_user->load_current_user($db->f('reminderCreatedUser')); singleton("current_user", $current_user); if (!$reminder->is_alive()) { $reminder->deactivate(); } else { $reminder->mail_advnotice(); } } // do reminders $query = prepare("SELECT *\n FROM reminder\n WHERE reminderActive = 1\n AND (reminderTime IS NULL OR NOW() > reminderTime)\n "); $db->query($query); while ($db->next_record()) { $reminder = new reminder(); $reminder->read_db_record($db); //echo "<br>Rem: ".$reminder->get_id(); $current_user = new person(); $current_user->load_current_user($db->f('reminderCreatedUser')); singleton("current_user", $current_user); if (!$reminder->is_alive()) { $reminder->deactivate(); } else { $reminder->mail_reminder(); } }