/**
  * Modifies a current reservation, setting new start and end times or deleting it
  * @param array $all_invited_users array of all invited users to be used for DB insertion
  * @param array $users_to_invite array of newly invited users to be used for invitation emails
  * @param array $users_to_remove array of users that will be removed from invitation/participating in this reservation
  * @param array $unchanged_users array of users who have no status change at all
  * @param array $resources_to_add array of additional resources to add to this reservation
  * @param array $resources_to_remove array of additional resources to remove from this reservation
  * @param bool $del whether to delete it or not
  * @param boolean $mod_recur whether to modify all recurring reservations in this group
  */
 function mod_res($users_to_invite, $users_to_remove, $unchanged_users, $resources_to_add, $resources_to_remove, $del, $mod_recur)
 {
     $recurs = array();
     $valid_resids = array();
     $this->type = RES_TYPE_MODIFY;
     $orig_start_date = $this->start_date;
     // Store the original dates because they will be changed if we repeat
     $orig_end_date = $this->end_date;
     $accept_code = $this->db->get_new_id();
     if ($del) {
         // First, check if this should be deleted
         $this->del_res($mod_recur, mktime(0, 0, 0));
         return;
     }
     if (!$this->is_blackout) {
         $this->check_perms();
         // Check permissions
         $this->check_min_max();
         // Check min/max reservation times
     }
     if ($this->check_startdate()) {
         $this->check_times();
         // Check valid times
     }
     $this->is_repeat = $mod_recur;
     // If the mod_recur flag is set, it must be a recurring reservation
     $dates = array();
     // First, modify the current reservation
     if ($this->has_errors()) {
         // Print any errors generated above and kill app
         $this->print_all_errors(true);
     }
     $reminder = new Reminder();
     $reminder->setDB(new ReminderDB());
     $tmp_valid = false;
     $this->is_pending = $this->resource->get_property('approval');
     if ($this->is_repeat) {
         // Check and place all recurring reservations
         $recurs = $this->db->get_recur_ids($this->parentid, mktime(0, 0, 0));
         for ($i = 0; $i < count($recurs); $i++) {
             $this->id = $recurs[$i]['resid'];
             // Load reservation data
             $this->start_date = $recurs[$i]['start_date'];
             if ($this->is_repeat) {
                 // End date will always be the same as the start date for recurring reservations
                 $this->end_date = $this->start_date;
             }
             $is_valid = $this->check_res($resources_to_add);
             // Check overlap (dont kill)
             if ($is_valid) {
                 $tmp_valid = true;
                 // Only one recurring needs to pass
                 $this->db->mod_res($this, $users_to_invite, $users_to_remove, $resources_to_add, $resources_to_remove, $accept_code);
                 // And place the reservation
                 if (!empty($this->reminderid)) {
                     $reminder->update($this, $this->reminder_minutes_prior);
                 } else {
                     if ($this->reminder_minutes_prior != 0 && empty($this->reminderid)) {
                         $reminder->save($this, $this->reminder_minutes_prior);
                     }
                 }
                 $dates[] = $this->start_date;
                 $valid_resids[] = $this->id;
                 CmnFns::write_log($this->word . ' ' . $this->id . ' modified.  machid:' . $this->get_machid() . ', dates:' . $this->start_date . ' - ' . $this->end_date . ', start:' . $this->start . ', end:' . $this->end, $this->memberid, $_SERVER['REMOTE_ADDR']);
             }
         }
     } else {
         if ($this->check_res($resources_to_add)) {
             // Check overlap
             $this->db->mod_res($this, $users_to_invite, $users_to_remove, $resources_to_add, $resources_to_remove, $accept_code);
             // And place the reservation
             if (!empty($this->reminderid)) {
                 $reminder->update($this, $this->reminder_minutes_prior);
             } else {
                 if ($this->reminder_minutes_prior != 0 && empty($this->reminderid)) {
                     $reminder->save($this, $this->reminder_minutes_prior);
                 }
             }
             $dates[] = $this->start_date;
             $valid_resids[] = $this->id;
         }
     }
     // Restore original reservation dates
     $this->start_date = $orig_start_date;
     $this->end_date = $orig_end_date;
     if ($this->has_errors()) {
         // Print any errors generated when adding the reservations
         $this->print_all_errors(!$this->is_repeat);
     }
     if (!$this->is_blackout) {
         // Notify the user if they want
         $this->send_email('e_mod', null, $unchanged_users);
     }
     // Send out invites, if needed
     if (!$this->is_pending && count($users_to_invite) > 0) {
         $this->invite_users($users_to_invite, $dates, $accept_code);
     }
     if (!$this->is_pending && count($users_to_remove) > 0) {
         $this->remove_users_email($users_to_remove, $dates);
     }
     if (!$this->is_repeat || $tmp_valid) {
         $this->print_success('modified', $dates);
     }
 }
Exemple #2
0
* Sends all pending email reminders
* This file is meant to be run from the command line and has no HTML output
* @author Nick Korbel <*****@*****.**>
* @version 06-14-06
* @package phpScheduleIt Command Line
*
* Copyright (C) 2003 - 2007 phpScheduleIt
* License: GPL, see LICENSE
*/
$basedir = dirname(__FILE__) . '/..';
require_once $basedir . '/lib/Reminder.class.php';
require_once $basedir . '/lib/db/ReminderDB.class.php';
require_once $basedir . '/lib/ReminderEmail.class.php';
$max_date = date(REMINDER_DATE_FORMAT);
$reminder = new Reminder();
$reminder->setDB(new ReminderDB());
$reminders = $reminder->getReminders($max_date);
$reminderids_sent = array();
for ($i = 0; $i < count($reminders); $i++) {
    $cur = $reminders[$i];
    if (is_lang_valid($cur->lang)) {
        include get_language_path($cur->lang);
        // Make sure email is in correct language
        $mail = new ReminderEmail(new PHPMailer());
        $mail->buildFromReminder($cur);
        $mail->send();
        $reminderids_sent[] = $cur->id;
    }
}
$reminder->deleteReminders($reminderids_sent);
// Delete reminder records that were sent