diff -aburN --exclude='CVS*' phpgroupware.old/calendar/alarmpatch.README phpgroupware/calendar/alarmpatch.README --- phpgroupware.old/calendar/alarmpatch.README Wed Dec 31 17:00:00 1969 +++ phpgroupware/calendar/alarmpatch.README Wed Jan 8 19:49:36 2003 @@ -0,0 +1,52 @@ + +This patch implements email notifications of upcoming calendar events. +Email notifications are scheduled through the "Alarm Management" feature +that already partially existed in phpGroupWare/calendar. + +You will need to set up a cron to run the email script. Something like: + * * * * * /var/www/html/phpgroupware/calendar/cron + +This patch allows you to add one alarm in the "Calendar - Add" screen +so that you do not have to submit the event and then go back +and update the event just to get to the Alarm Management screen when +the majority of the time you probably just want one email notification +for that event. The alarm fields do NOT show up when editing the event +because if you want to edit an alarm you should use the Alarm Management screen. + +This patch allows you to set alarms on events you are a participant of +not just the events you are the owner of. + +rfc2445 implies multiple types of alarms (EMAIL, AUDIO, & DISPLAY) but +the mysql table phpgw_cal_alarm does not have a field for 'type' so +I have not implemented AUDIO & DISPLAY yet. + +rfc2445 implies the trigger can be a relative time or an absolute time +but so far I have only implemented relative time. + +This patch does not use the 'text' field because the cron message looks +up and sends most of the information about the event in the email notification. + +This patch does not allow editing of an alarm since there is currently no text field +and its easier just to remove and add a new alarm back in with a new relative time. + +If the time of an event is changed after an alarm is established the alarm does +not automatically change to the same relative time before the new event time. + +Recurring event alarms do not take into account exceptions (i.e. delete single event) + +It would be nice if the text field were longer than 50 characters. + +It would be nice to have a preference for each user to set the format of the email +message. The format field should allow some kind of replacement values +for SUBJECT, LOCATION, DESCRIPTION, START TIME, etc. + +This patch does not implement repeating 'alarms', but I can see how it would +be usefull to specify 'generate an email every 15 minutes for the hour before +the event'. + +Alarms for repeating events get re-established by the cron for the next event for +the same amount of time before the next event. + +I am not sure what the intent of the 'enabled' field is? History? The +database entry could just be removed when the alarm is generated. For now +I just disable it. diff -aburN --exclude='CVS*' phpgroupware.old/calendar/cron phpgroupware/calendar/cron --- phpgroupware.old/calendar/cron Wed Dec 31 17:00:00 1969 +++ phpgroupware/calendar/cron Wed Jan 8 19:11:18 2003 @@ -0,0 +1,737 @@ +#!/usr/bin/php -q +<?php + + // set this up as a cron to run every minute, something like: + // * * * * * /var/www/html/phpgroupware/calendar/cron + + $debug = 0; + + // + // these functions use mktime which attempts to take into account daylight savings time + // + + // + // add_days - return a unix timestamp with $days added to $time using mktime + // + function add_days ($time,$days) + { + + $tm = localtime($time,true); + $month = $tm[tm_mon]+1; // localtime month 0-11 + $year = $tm[tm_year]; + + $nextmonth = $month + 1; + $checkyear = $year; + if ($nextmonth > 12) + { + $nextmonth = 1; + $checkyear++; + } + $numdaysinmonth = date("j", mktime(0,0,0,$nextmonth,0,$checkyear)); + + $newday = $tm[tm_mday] + $days; + while ($newday > $numdaysinmonth) + { + $newday -= $numdaysinmonth; + $month++; + if ($month > 12) + { + $month = 1; + $year++; + } + $nextmonth = $month + 1; + $checkyear = $year; + if ($nextmonth > 12) + { + $nextmonth = 1; + $checkyear++; + } + $numdaysinmonth = date("j", mktime(0,0,0,$nextmonth,0,$checkyear)); + } + + return mktime($tm[tm_hour],$tm[tm_min],$tm[tm_sec],$month,$newday,$year); + + } + // + // add_months_bymday - return a unix timestamp by adding $months to $time where a + // month is the same day of the month (i.e. jan 9 to feb 9) + // + function add_months_bymday($time,$months) + { + $tm = localtime($time,true); + $mon = $tm[tm_mon]+1; // localtime month 0-11 + $year = $tm[tm_year]; + + $mon += $months; + while ($mon > 12) + { + $mon -= 12; + $year++; + } + + return mktime($tm[tm_hour],$tm[tm_min],$tm[tm_sec],$mon,$tm[tm_mday],$year); + } + // + // add_months_bywday - return a unix timestamp by adding $months to $time where a + // month is the nth weekday of the month (i.e. 2nd Tuesday of + // january to 2nd Tuesday of February) + // + function add_months_bywday($time,$months) + { + $tm = localtime($time,true); + $mon = $tm[tm_mon]+1; // localtime month 0-11 + $year = $tm[tm_year]; + + $mon += $months; + while ($mon > 12) + { + $mon -= 12; + $year++; + } + + $bom = mktime($tm[tm_hour],$tm[tm_min],$tm[tm_sec],$mon,1,$year); + $bomtm = localtime($bom,true); + if ($tm[tm_wday] >= $bomtm[tm_wday]) + { + $adddays = $tm[tm_wday] - $bomtm[tm_wday]; + } + else + { + $adddays = 7 - $bomtm[tm_wday] + $tm[tm_wday]; + } + // 7*24*3600 = 604800 = 1 week + // 24*3600 = 86400 = 1 day + $weeks = ceil($tm[tm_mday]/7); + // I will assume that the 5th occurance of a wday is to be the last + // occurance of the wday of the next month otherwise it + // would spill over into the month after that + // which makes the 4th and 5th occurance of a wday be the same + // day of the next month + if ($weeks == 5) + { + $weeks = 4; + } + return ($bom + (($weeks-1)*604800) + ($adddays*86400)); + } + // + // add_years - returns a unix timestamp with $years added to $time + // + function add_years($time,$years) + { + $tm = localtime($time,true); + $mon = $tm[tm_mon]+1; // localtime month 0-11 + return mktime($tm[tm_hour],$tm[tm_min],$tm[tm_sec],$mon,$tm[tm_mday],$tm[tm_year]+$years); + } + // + // getdays2next - returns the number of days from $dow to the next marked day in $dowbmap + // where dowbmap is 1 - sunday, 2 - monday, 4 - tuesday, 8 - wednesday, + // 16 - thursday, 32 - friday, 64 - saturday + // + function getdays2next($dow,$dowbmap) + { + global $wdb; + + if ($dowbmap == 0) + { + return -1; + } + if ($dow > 6) + { + return -2; + } + $count = 0; + do { + $count++; + $dow++; + if ($dow > 6) + { + $dow = 0; + } + } while (!($wdb[$dow] & $dowbmap)); + return $count; + } + + + // phpgroupware + + $GLOBALS['phpgw_info']['flags'] = array( + 'noheader' => True, + 'noapi' => True, + 'nonavbar' => True, + 'currentapp' => 'login' + ); + + include('/var/www/html/phpgroupware/header.inc.php'); + include(PHPGW_API_INC.'/functions.inc.php'); + include(PHPGW_INCLUDE_ROOT.'/calendar/inc/class.socalendar__.inc.php'); + + // initialize + + $wdb = array( + 0 => MCAL_M_SUNDAY, + 1 => MCAL_M_MONDAY, + 2 => MCAL_M_TUESDAY, + 3 => MCAL_M_WEDNESDAY, + 4 => MCAL_M_THURSDAY, + 5 => MCAL_M_FRIDAY, + 6 => MCAL_M_SATURDAY + ); + $pref = new preferences(); + $db = new db(); + $db->Database = $GLOBALS['phpgw_domain']['default']['db_name']; + $db->Host = $GLOBALS['phpgw_domain']['default']['db_host']; + $db->User = $GLOBALS['phpgw_domain']['default']['db_user']; + $db->Password = $GLOBALS['phpgw_domain']['default']['db_pass']; + + $now = time(); + + // get each alarm that needs email notification + + $db->lock(array('phpgw_cal_alarm')); + $db->query('SELECT * FROM phpgw_cal_alarm where alarm_enabled=1 and cal_time <= unix_timestamp()', + __LINE__,__FILE__); + + $count = $db->num_rows(); + if ($count < 1) + { + $db->unlock(); + exit; + } + + while ($db->next_record()) + { + $id = $db->f('alarm_id'); + $Alarm[$id] = Array( + 'cal_id' => $db->f('cal_id'), + 'cal_owner' => $db->f('cal_owner'), + 'cal_time' => $db->f('cal_time'), + 'cal_text' => $db->f('cal_text'), + 'alarm_enabled' => $db->f('enabled') + ); + } + + @reset($Alarm); + while (list($key, $alarm) = @each($Alarm)) + { + // disable here so that another instance of cron does not pick up these same alarms + $db->query('UPDATE phpgw_cal_alarm set alarm_enabled=0 where alarm_id='.$key, + __LINE__,__FILE__); + } + $db->unlock(); + + if ($debug) + { + echo $count.' alarm(s) at '.$now.' '.date("r", $now)."\n"; + } + + // get email addresses + + @reset($Alarm); + while (list($key, $alarm) = @each($Alarm)) + { + $owner = $alarm['cal_owner']; + if ($Email[$owner] == '') + { + $emailpref = $pref->create_email_preferences($owner); + $Email[$owner] = $emailpref['email']['address']; + $GLOBALS['phpgw']->accounts->get_account_name($owner,$lid,$fname,$lname); + $Name[$owner] = "$fname $lname"; + } + + if ($debug) + { + echo 'Alarm '.$key.' cal event '.$Alarm[$key]['cal_id'].' owner ' + .$Alarm[$key]['cal_owner'].' '.$Name[$owner].' '.$Email[$owner] + .' alarm time '.$Alarm[$key]['cal_time'].' = ' + .date("r", $Alarm[$key]['cal_time'])."\n"; + } + + } + + // the date & time functions below should be converted to use + // the users time format + + // loop through each alarm that went off and get information for the email + // and if it is a recurring event reset the alarm for the next occurance + + @reset($Alarm); + $db->lock(array('phpgw_cal','phpgw_cal_alarm','phpgw_cal_repeats')); + while (list($key, $alarm) = @each($Alarm)) + { + + $owner = $alarm['cal_owner']; + $body = 'This is an automatically generated reminder about the following appointment:' + ."\n\n"; + $db->query('SELECT * FROM phpgw_cal WHERE cal_id=' + .$alarm['cal_id'],__LINE__,__FILE__); + $db->next_record(); + $subject = 'Appointment Reminder Re: '.$db->f('title',1); + $body .= 'Regarding: '.$db->f('title',1)."\n"; + $body .= 'Location: '.$db->f('location')."\n"; + + $datetime = $db->f('datetime'); + $edatetime = $db->f('edatetime'); + $description = $db->f('description',1); + + if ($debug) + { + echo 'Alarm '.$key.' event start time '.$datetime.' = '.date("r", $datetime)."\n"; + echo 'Alarm '.$key.' event end time '.$edatetime.' = '.date("r", $edatetime)."\n"; + } + + $db->query('SELECT * FROM phpgw_cal_repeats where cal_id=' + .$alarm['cal_id'],__LINE__,__FILE__); + if ($db->next_record()) + { + $type = $db->f('recur_type'); + } + else + { + $type = MCAL_RECUR_NONE; + } + + // this section will reset recurring events alarms to go off the same amount of time + // prior to the next event + + switch ($type) { + case MCAL_RECUR_NONE: + if ($debug) + { + echo 'Alarm '.$key.' RECUR_NONE '."\n"; + } + $neweventtime = $datetime; + $date = date("l, F j, Y", $datetime); + $from = date("g:i a", $datetime); + $to = date("g:i a", $edatetime); + break; + + case MCAL_RECUR_DAILY: + if (($interval = $db->f('recur_interval')) == 0) + { + $interval = 1; + } + if ($debug) + { + echo 'Alarm '.$key.' RECUR_DAILY interval '.$interval."\n"; + } + + // the new alarm time to set must be some time in the future + + $newalmtime = $alarm['cal_time']; // initialize + while ($newalmtime <= $now) + { + $newalmtime = add_days($newalmtime,$interval); + } + + // the date & time of the meeting this email is for (for email) + // must be the first recurring event after this alarm + + $neweventtime = $datetime; + $newedatetime = $edatetime; + while ($neweventtime < $alarm['cal_time']) { + $neweventtime = add_days($neweventtime,$interval); + $newedatetime = add_days($newedatetime,$interval); + } + $date = date("l, F j, Y", $neweventtime); + $from = date("g:i a", $neweventtime); + $to = date("g:i a", $newedatetime); + + // the new alarm time cannot be past the enddate + + $enddate = $db->f('recur_enddate'); + + if (!$enddate || $neweventtime < $enddate) + { + if ($debug) + { + echo 'Alarm '.$key.' setting next alarm for '.$newalmtime.' = ' + .date("r", $newalmtime)."\n"; + } + $db->query('UPDATE phpgw_cal_alarm set cal_time='.$newalmtime + .', alarm_enabled=1 where alarm_id='.$key,__LINE__,__FILE__); + } + break; + + case MCAL_RECUR_WEEKLY: + if (($interval = $db->f('recur_interval')) == 0) + { + $interval = 1; + } + // this case is unique for interval because the first week + // of events we always add in and then skip weeks so subtract + // one week from interval + $interval--; + if ($debug) + { + echo 'Alarm '.$key.' RECUR_WEEKLY interval '.$interval."\n"; + } + + // RECUR_WEEKLY is dependent upon recur_data which is the + // days of the week of the event not the days of the week + // of the alarm so we need to get the amount of time prior + // to the event that the alarm should go off and subtract + // that from the date/time of the next recurring event + // calculated using recur_data + + $recurdow = $db->f('recur_data'); + if ($debug) + { + echo 'Alarm '.$key.' recur_data '.$recurdow."\n"; + } + + // find the first event after the alarm that just went off + // to get the date & time of the event for email + // and to calculate how much time before the event the + // alarm was set for to be used when resetting the alarm + // for the next event + + $neweventtime = $datetime; + $newedatetime = $edatetime; + $weekdays = 0; + if ($debug) + { + echo 'Alarm '.$key.' initial event time = '.$neweventtime.' = ' + .date("r", $neweventtime)."\n"; + } + while ($neweventtime < $alarm['cal_time']) { + + if ($debug) + { + echo 'Alarm '.$key.' Next event time = '.$neweventtime + .' = '.date("r", $neweventtime)."\n"; + } + + $days_to_next = getdays2next(date("w",$neweventtime),$recurdow); + + if ($debug) + { + echo 'Alarm '.$key.' days to next event = ' + .$days_to_next."\n"; + } + + $neweventtime = add_days($neweventtime,$days_to_next); + $newedatetime = add_days($newedatetime,$days_to_next); + $weekdays += $days_to_next; + if ($weekdays >= 7 && $interval > 0) + { + if ($debug) + { + echo 'Alarm '.$key.' skipping '.$interval.' weeks ' + ."\n"; + } + $neweventtime = add_days($neweventtime,$interval * 7); + $newedatetime = add_days($newedatetime,$interval * 7); + $weekdays = 0; + } + } + + if ($debug) + { + echo 'Alarm '.$key.' next event time after alarm = '.$neweventtime + .' = '.date("r", $neweventtime)."\n"; + } + + $date = date("l, F j, Y", $neweventtime); + $from = date("g:i a", $neweventtime); + $to = date("g:i a", $newedatetime); + $savneweventtime = $neweventtime; + + $diff = $neweventtime - $alarm['cal_time']; + + if ($debug) + { + echo 'Alarm '.$key.' amount of time before event to send email ' + .$diff."\n"; + } + + // the new event time must be some time in the future + + $newalmtime = $alarm['cal_time']; // intialize + + // compare the alarm time not the event time just in case the + // alarm was set such that it should have already gone off + // even though the event is still in the future + // this loop just used to get newalmtime by following each + // next event + + while ($newalmtime <= $now) + { + if ($debug) + { + echo 'Alarm '.$key.' Next event time = '.$neweventtime + .' = '.date("r", $neweventtime)."\n"; + } + + $days_to_next = getdays2next(date("w",$neweventtime),$recurdow); + + if ($debug) + { + echo 'Alarm '.$key.' days to next event = ' + .$days_to_next."\n"; + } + + $neweventtime = add_days($neweventtime,$days_to_next); + $weekdays += $days_to_next; + if ($weekdays >= 7 && $interval > 0) + { + if ($debug) + { + echo 'Alarm '.$key.' skipping '.$interval + .' weeks '."\n"; + } + $neweventtime = add_days($neweventtime,$interval * 7); + $weekdays = 0; + } + $newalmtime = $neweventtime - $diff; + } + + // reset neweventtime to event that alarm is about + $neweventtime = $savneweventtime; + + if ($debug) + { + echo 'Alarm '.$key.' Next event time = '.$neweventtime.' = ' + .date("r", $neweventtime)."\n"; + echo 'Alarm '.$key.' Next alarm time after now = '.$newalmtime + .' = '.date("r", $newalmtime)."\n"; + } + + // the new alarm time cannot be past the enddate + + $enddate = $db->f('recur_enddate'); + + if (!$enddate || $neweventtime < $enddate) + { + if ($debug) + { + echo 'Alarm '.$key.' setting next alarm for '.$newalmtime.' = ' + .date("r", $newalmtime)."\n"; + } + $db->query('UPDATE phpgw_cal_alarm set cal_time='.$newalmtime + .', alarm_enabled=1 where alarm_id='.$key,__LINE__,__FILE__); + } + break; + + case MCAL_RECUR_MONTHLY_MDAY: + if (($interval = $db->f('recur_interval')) == 0) + { + $interval = 1; + } + if ($debug) + { + echo 'Alarm '.$key.' RECUR_MONTHLY_MDAY interval '.$interval."\n"; + } + $newalmtime = $alarm['cal_time']; // initialize + while ($newalmtime <= $now) + { + $newalmtime = add_months_bymday($newalmtime,$interval); + if ($debug) + { + echo 'Alarm '.$key.' Next alarm time = '.$newalmtime.' = ' + .date("r", $newalmtime)."\n"; + } + } + + // the date & time of the meeting (for email) + // must be the first recurring event after this alarm + + $neweventtime = $datetime; + $newedatetime = $edatetime; + while ($neweventtime < $alarm['cal_time']) { + $neweventtime = add_months_bymday($neweventtime,$interval); + $newedatetime = add_months_bymday($newedatetime,$interval); + } + $date = date("l, F j, Y", $neweventtime); + $from = date("g:i a", $neweventtime); + $to = date("g:i a", $newedatetime); + + // the new alarm time cannot be past the enddate + + $enddate = $db->f('recur_enddate'); + + if (!$enddate || $neweventtime < $enddate) + { + if ($debug) + { + echo 'Alarm '.$key.' setting next alarm for '.$newalmtime.' = ' + .date("r", $newalmtime)."\n"; + } + $db->query('UPDATE phpgw_cal_alarm set cal_time='.$newalmtime + .', alarm_enabled=1 where alarm_id='.$key,__LINE__,__FILE__); + } + break; + + case MCAL_RECUR_MONTHLY_WDAY: + if (($interval = $db->f('recur_interval')) == 0) + { + $interval = 1; + } + if ($debug) + { + echo 'Alarm '.$key.' RECUR_MONTHLY_WDAY interval '.$interval."\n"; + } + + // RECUR_MONTHLY_WDAY is dependent upon the + // day of the week of the event not the day of the week + // of the alarm so we need to get the amount of time prior + // to the event that the alarm should go off and subtract + // that from the date/time of the next recurring event + + // the date & time of the meeting (for email) + // must be the first recurring event after this alarm + + $neweventtime = $datetime; + $newedatetime = $edatetime; + while ($neweventtime < $alarm['cal_time']) { + if ($debug) + { + echo 'Alarm '.$key.' Next event time = '.$neweventtime + .' = '.date("r", $neweventtime)."\n"; + } + $neweventtime = add_months_bywday($neweventtime,$interval); + $newedatetime = add_months_bywday($newedatetime,$interval); + } + if ($debug) + { + echo 'Alarm '.$key.' next event time after alarm = '.$neweventtime + .' = '.date("r", $neweventtime)."\n"; + } + $date = date("l, F j, Y", $neweventtime); + $from = date("g:i a", $neweventtime); + $to = date("g:i a", $newedatetime); + $savneweventtime = $neweventtime; + + $diff = $neweventtime - $alarm['cal_time']; + + if ($debug) + { + echo 'Alarm '.$key.' amount of time before event to send email ' + .$diff."\n"; + } + + $newalmtime = $alarm['cal_time']; // initialize + while ($newalmtime <= $now) + { + if ($debug) + { + echo 'Alarm '.$key.' Next event time = '.$neweventtime + .' = '.date("r", $neweventtime)."\n"; + } + $neweventtime = add_months_bywday($neweventtime,$interval); + $newalmtime = $neweventtime - $diff; + } + + if ($debug) + { + echo 'Alarm '.$key.' Last event time = '.$neweventtime.' = ' + .date("r", $neweventtime)."\n"; + } + + $neweventtime = $savneweventtime; + + if ($debug) + { + echo 'Alarm '.$key.' Reset event time = '.$neweventtime.' = ' + .date("r", $neweventtime)."\n"; + echo 'Alarm '.$key.' Next alarm time after now = '.$newalmtime + .' = '.date("r", $newalmtime)."\n"; + } + + // the new alarm time cannot be past the enddate + + $enddate = $db->f('recur_enddate'); + + if (!$enddate || $neweventtime < $enddate) + { + if ($debug) + { + echo 'Alarm '.$key.' setting next alarm for '.$newalmtime.' = ' + .date("r", $newalmtime)."\n"; + } + $db->query('UPDATE phpgw_cal_alarm set cal_time='.$newalmtime + .', alarm_enabled=1 where alarm_id='.$key,__LINE__,__FILE__); + } + break; + + case MCAL_RECUR_YEARLY: + if (($interval = $db->f('recur_interval')) == 0) + { + $interval = 1; + } + if ($debug) + { + echo 'Alarm '.$key.' RECUR_YEARLY interval '.$interval."\n"; + } + $newalmtime = $alarm['cal_time']; // initialize + while ($newalmtime <= $now) + { + $newalmtime = add_years($newalmtime,$interval); + } + + // the date & time of the meeting (for email) + // must be the first recurring event after this alarm + + $neweventtime = $datetime; + $newedatetime = $edatetime; + while ($neweventtime < $alarm['cal_time']) { + $neweventtime = add_years($neweventtime,$interval); + $newedatetime = add_years($newedatetime,$interval); + } + $date = date("l, F j, Y", $neweventtime); + $from = date("g:i a", $neweventtime); + $to = date("g:i a", $newedatetime); + + // the new alarm time cannot be past the enddate + + $enddate = $db->f('recur_enddate'); + + if (!$enddate || $neweventtime < $enddate) + { + if ($debug) + { + echo 'Alarm '.$key.' setting next alarm for '.$newalmtime.' = ' + .date("r", $newalmtime)."\n"; + } + $db->query('UPDATE phpgw_cal_alarm set cal_time='.$newalmtime + .', alarm_enabled=1 where alarm_id='.$key,__LINE__,__FILE__); + } + break; + + } + + if ($debug) + { + echo 'Alarm '.$key.' event time for email '.$date.' from '.$from.' to '.$to."\n"; + echo 'Alarm '.$key.' neweventtime '.$neweventtime.' = ' + .date("r", $neweventtime)."\n"; + } + + + if ($neweventtime < $now) + { + if ($debug) + { + echo 'Alarm '.$key.' event has already occurred. Not sending email.' + ."\n"; + } + continue; + } + + $body .= 'Date: '.$date."\n"; + $body .= 'Time: '.$from.' to '.$to."\n"; + $body .= 'Description:'."\n\n".$description."\n\n"; + + // the email is made to be from the user so that reply's + // do not go to root/postmaster/etc, You could add some text like: + // If you have any question regarding this email, please contact... + + mail($Name[$owner].' <'.$Email[$owner].'>', $subject, $body, + 'From: '.$Name[$owner].' <'.$Email[$owner].'>'."\r\n" + .'Reply-To: '.$Name[$owner].' <'.$Email[$owner].'>'."\r\n" + ); + + } + $db->unlock(); + + +?> diff -aburN --exclude='CVS*' phpgroupware.old/calendar/inc/class.boalarm.inc.php phpgroupware/calendar/inc/class.boalarm.inc.php --- phpgroupware.old/calendar/inc/class.boalarm.inc.php Fri Dec 6 21:56:45 2002 +++ phpgroupware/calendar/inc/class.boalarm.inc.php Tue Jan 7 16:57:42 2003 @@ -26,6 +26,8 @@ // var $debug = True; var $public_functions = array( + 'add' => True, + 'delete' => True ); function boalarm() @@ -36,6 +38,7 @@ $this->cal_id = $cal_id; } $this->cal = CreateObject('calendar.bocalendar',1); + $this->so = CreateObject('calendar.socalendar',1); $this->tz_offset = $this->cal->datetime->tz_offset; if($this->debug) @@ -67,5 +70,50 @@ { return $this->cal->read_entry($cal_id); } + function can_user_edit($event) + { + return $this->cal->can_user_edit($event); + } + function maketime($time) + { + return mktime($time['hour'],$time['min'],$time['sec'],$time['month'],$time['mday'],$time['year']); + } /* Public functions */ + function add() + { + $this->bo = CreateObject('calendar.bocalendar',1); + $cal_id = $GLOBALS['HTTP_POST_VARS']['cal_id']; + $alarmhours = $GLOBALS['HTTP_POST_VARS']['alarmhours']; + $alarmdays = $GLOBALS['HTTP_POST_VARS']['alarmdays']; + $alarmminutes = $GLOBALS['HTTP_POST_VARS']['alarmminutes']; + $event = $this->read_entry($cal_id); + $time = $this->maketime($event['start']) - + ($alarmdays * 24 * 3600) - + ($alarmhours * 3600) - + ($alarmminutes * 60); + + $alarm = Array( + 'time' => $time, + 'enabled' => 1 + ); + + $alarm['id'] = $this->so->add_alarm($cal_id,$alarm,$this->bo->owner); + + $event['alarm'][] = $alarm; + + ExecMethod('calendar.uicalendar.index'); + $GLOBALS['phpgw']->common->phpgw_exit(True); + } + function delete($params='') + { + $cal_id = $GLOBALS['HTTP_POST_VARS']['cal_id']; + $alarm = $GLOBALS['HTTP_POST_VARS']['alarm']; + while(list($key,$field) = @each($alarm)) + { + $this->so->delete_alarm($key); + } + ExecMethod('calendar.uicalendar.index'); + $GLOBALS['phpgw']->common->phpgw_exit(True); + } } +?> diff -aburN --exclude='CVS*' phpgroupware.old/calendar/inc/class.bocalendar.inc.php phpgroupware/calendar/inc/class.bocalendar.inc.php --- phpgroupware.old/calendar/inc/class.bocalendar.inc.php Fri Dec 6 21:56:45 2002 +++ phpgroupware/calendar/inc/class.bocalendar.inc.php Tue Jan 7 17:29:42 2003 @@ -805,8 +805,22 @@ $this->so->add_attribute('priority',$l_cal['priority']); $event = $this->get_cached_event(); - $event['title'] = $GLOBALS['phpgw']->db->db_addslashes($event['title']); - $event['description'] = $GLOBALS['phpgw']->db->db_addslashes($event['description']); + //$event['title'] = $GLOBALS['phpgw']->db->db_addslashes($event['title']); + //$event['description'] = $GLOBALS['phpgw']->db->db_addslashes($event['description']); + if ($l_cal['alarmdays'] > 0 || $l_cal['alarmhours'] > 0 || + $l_cal['alarmminutes'] > 0) + { + $time = $this->maketime($event['start']) - + ($l_cal['alarmdays'] * 24 * 3600) - + ($l_cal['alarmhours'] * 3600) - + ($l_cal['alarmminutes'] * 60); + + $event['alarm'][] = Array( + 'time' => $time, + 'enabled' => 1 + ); + } + $this->store_to_appsession($event); $datetime_check = $this->validate_update($event); print_debug('bo->validated_update() returnval',$datetime_check); diff -aburN --exclude='CVS*' phpgroupware.old/calendar/inc/class.bopreferences.inc.php phpgroupware/calendar/inc/class.bopreferences.inc.php --- phpgroupware.old/calendar/inc/class.bopreferences.inc.php Mon Sep 23 13:19:06 2002 +++ phpgroupware/calendar/inc/class.bopreferences.inc.php Tue Jan 7 21:34:13 2003 @@ -103,6 +103,9 @@ { $GLOBALS['phpgw']->preferences->delete('calendar','print_black_white'); } + $GLOBALS['phpgw']->preferences->add('calendar','default_email_days',intval($GLOBALS['HTTP_POST_VARS']['prefs']['default_email_days'])); + $GLOBALS['phpgw']->preferences->add('calendar','default_email_hours',intval($GLOBALS['HTTP_POST_VARS']['prefs']['default_email_hours'])); + $GLOBALS['phpgw']->preferences->add('calendar','default_email_min',intval($GLOBALS['HTTP_POST_VARS']['prefs']['default_email_min'])); $GLOBALS['phpgw']->preferences->save_repository(True); diff -aburN --exclude='CVS*' phpgroupware.old/calendar/inc/class.socalendar.inc.php phpgroupware/calendar/inc/class.socalendar.inc.php --- phpgroupware.old/calendar/inc/class.socalendar.inc.php Mon Sep 23 13:19:06 2002 +++ phpgroupware/calendar/inc/class.socalendar.inc.php Tue Jan 7 21:36:18 2003 @@ -213,6 +213,16 @@ $this->cal->store_event($event); } + function add_alarm($eventid,$alarm,$owner) + { + $this->cal->add_alarm($eventid,$alarm,$owner); + } + + function delete_alarm($alarmid) + { + $this->cal->delete_alarm($alarmid); + } + function delete_entry($id) { $this->cal->delete_event($id); diff -aburN --exclude='CVS*' phpgroupware.old/calendar/inc/class.socalendar_sql.inc.php phpgroupware/calendar/inc/class.socalendar_sql.inc.php --- phpgroupware.old/calendar/inc/class.socalendar_sql.inc.php Fri Dec 6 21:56:45 2002 +++ phpgroupware/calendar/inc/class.socalendar_sql.inc.php Tue Jan 7 21:38:54 2003 @@ -212,6 +212,7 @@ if($this->event['reference']) { + // What is event['reference']??? $alarm_cal_id = $event_id.','.$this->event['reference']; } else @@ -219,7 +220,9 @@ $alarm_cal_id = $event_id; } - $this->stream->query('SELECT * FROM phpgw_cal_alarm WHERE cal_id in ('.$alarm_cal_id.') AND cal_owner='.$this->user,__LINE__,__FILE__); + //echo '<!-- cal_id='.$alarm_cal_id.' -->'."\n"; + //$this->stream->query('SELECT * FROM phpgw_cal_alarm WHERE cal_id in ('.$alarm_cal_id.') AND cal_owner='.$this->user,__LINE__,__FILE__); + $this->stream->query('SELECT * FROM phpgw_cal_alarm WHERE cal_id='.$event_id.' AND cal_owner='.$this->user,__LINE__,__FILE__); if($this->stream->num_rows()) { while($this->stream->next_record()) @@ -421,7 +424,8 @@ $locks = Array( 'phpgw_cal', 'phpgw_cal_user', - 'phpgw_cal_repeats' + 'phpgw_cal_repeats', + 'phpgw_cal_alarm' ); $this->stream->lock($locks); if($event['id'] == 0) @@ -539,6 +543,29 @@ $this->stream->query('DELETE FROM phpgw_cal_repeats WHERE cal_id='.$event['id'],__LINE__,__FILE__); } + $alarmcount = count($event['alarm']); + if ($alarmcount > 1) + { + // this should never happen, $event['alarm'] should only be set + // if creating a new event and uicalendar only sets up 1 alarm + // the user must use "Alarm Management" to create/establish multiple + // alarms or to edit/change an alarm + echo '<!-- how did this happen, too many alarms -->'."\n"; + $this->stream->unlock(); + return True; + } + + if ($alarmcount == 1) + { + + list($key,$alarm) = @each($event['alarm']); + + $this->stream->query('INSERT INTO phpgw_cal_alarm(cal_id,cal_owner,cal_time,cal_text,alarm_enabled) VALUES('.$event['id'].','.$event['owner'].','.$alarm['time'].",'".$alarm['text']."',".$alarm['enabled'].')',__LINE__,__FILE__); + $this->stream->query('SELECT LAST_INSERT_ID()'); + $this->stream->next_record(); + $alarm['id'] = $this->stream->f(0); + } + print_debug('Event Saved: ID #',$event['id']); $this->stream->unlock(); @@ -574,6 +601,11 @@ ); $this->stream->query("UPDATE phpgw_cal_user SET cal_status='".$status_code_short[$status]."' WHERE cal_id=".$id." AND cal_login=".$owner,__LINE__,__FILE__); + if ($status == 'R') + { + $this->stream->query('UPDATE phpgw_cal_alarm set alarm_enabled=0 where cal_id='.$id.' and cal_owner='.$owner,__LINE__,__FILE__); + } + return True; } @@ -612,4 +644,15 @@ { return $this->localdates(mktime(0,0,0,intval(substr($d,4,2)),intval(substr($d,6,2)),intval(substr($d,0,4)))); } + function add_alarm($eventid,$alarm,$owner) + { + $this->stream->query('INSERT INTO phpgw_cal_alarm(cal_id,cal_owner,cal_time,cal_text,alarm_enabled) VALUES('.$eventid.','.$owner.','.$alarm['time'].",'".$alarm['text']."',1)",__LINE__,__FILE__); + $this->stream->query('SELECT LAST_INSERT_ID()'); + $this->stream->next_record(); + return($this->stream->f(0)); + } + function delete_alarm($alarmid) + { + $this->stream->query('DELETE FROM phpgw_cal_alarm WHERE alarm_id='.$alarmid,__LINE__,__FILE__); + } } diff -aburN --exclude='CVS*' phpgroupware.old/calendar/inc/class.uialarm.inc.php phpgroupware/calendar/inc/class.uialarm.inc.php --- phpgroupware.old/calendar/inc/class.uialarm.inc.php Fri Dec 6 21:56:45 2002 +++ phpgroupware/calendar/inc/class.uialarm.inc.php Tue Jan 7 19:44:27 2003 @@ -83,6 +83,7 @@ $this->template->set_block('alarm','alarm_headers','alarm_headers'); $this->template->set_block('alarm','list','list'); $this->template->set_block('alarm','hr','hr'); + $this->template->set_block('alarm','delete','delete'); } function output_template_array($row,$list,$var) @@ -100,17 +101,41 @@ $this->template->set_var('hr_text','<center><b>'.lang('Alarms').'</b></center></br><hr>'); $this->template->parse('row','hr',True); + $dout = '<select name="alarmdays">'."\n"; + for($i=0;$i<32;$i++) + { + $dout .= '<option value="'.$i.'"'.(@$GLOBALS['phpgw_info']['user']['preferences']['calendar']['default_email_days']==$i?' selected':'').'>'.$i.'</option>'."\n"; + } + $dout .= '</select>'."\n".lang("days"); + $hout = '<select name="alarmhours">'."\n"; + for($i=0;$i<24;$i++) + { + $hout .= '<option value="'.$i.'"'.(@$GLOBALS['phpgw_info']['user']['preferences']['calendar']['default_email_hours']==$i?' selected':'').'>'.$i.'</option>'."\n"; + } + $hout .= '</select>'."\n".lang("hours"); + $mout = '<select name="alarmminutes">'."\n"; + for($i=0;$i<60;$i++) + { + $mout .= '<option value="'.$i.'"'.(@$GLOBALS['phpgw_info']['user']['preferences']['calendar']['default_email_min']==$i?' selected':'').'>'.$i.'</option>'."\n"; + } + $mout .= '</select>'."\n".lang("minutes before the event"); $var = Array( - 'action_url' => $GLOBALS['phpgw']->link('/index.php',Array('menuaction'=>'calendar.uialarm.form_handler')), + 'action_url' => $GLOBALS['phpgw']->link('/index.php',Array('menuaction'=>'calendar.boalarm.delete')), 'time_lang' => lang('Time'), 'text_lang' => lang('Text'), 'enabled_pict' => $GLOBALS['phpgw']->common->image('calendar','enabled.gif'), - 'disabled_pict' => $GLOBALS['phpgw']->common->image('calendar','disabled.gif') + 'disabled_pict' => $GLOBALS['phpgw']->common->image('calendar','disabled.gif'), + 'input_text' => lang('Send an Email Reminder'), + 'input_days' => $dout, + 'input_hours' => $hout, + 'input_minutes' => $mout, + 'action_add' => $GLOBALS['phpgw']->link('/index.php',Array('menuaction'=>'calendar.boalarm.add')), + 'input_add' => '<input type="hidden" name="cal_id" value="'.$this->bo->cal_id.'">'."\n".'<input type="submit" value="Submit">' ); $this->output_template_array('row','alarm_headers',$var); - $this->template->set_var('hr_text','<hr>'); - $this->template->parse('row','hr',True); + //$this->template->set_var('hr_text','<hr>'); + //$this->template->parse('row','hr',True); if($this->event['alarm']) { @@ -118,14 +143,17 @@ while(list($key,$alarm) = each($this->event['alarm'])) { $var = Array( - 'edit_box' => '<input type="checkbox" name="alarm[id]" value="'.$alarm['id'].'">', + 'edit_box' => '<input type="checkbox" name="alarm['.$alarm['id'].']" value="'.$alarm['id'].'">', 'field' => $icon.$GLOBALS['phpgw']->common->show_date($alarm['time']), - 'data' => $alarm['text'], + //'data' => $alarm['text'], + 'data' => 'Email Notification', 'alarm_enabled' => ($alarm['enabled']?'<img src="'.$GLOBALS['phpgw']->common->image('calendar','enabled.gif').'" width="13" height="13" alt="enabled">':'&nbsp;'), 'alarm_disabled' => (!$alarm['enabled']?'<img src="'.$GLOBALS['phpgw']->common->image('calendar','disabled.gif').'" width="13" height="13" alt="disabled">':'&nbsp;') ); $this->output_template_array('row','list',$var); } + $this->template->set_var('input_delete','<input type=hidden name="cal_id" value="'.$this->bo->cal_id.'"><input type="submit" value="' . lang('Delete Selected Alarms') . '" onClick="return confirm(\'Are you sure\\nyou want to \\ndelete this entry?\\n\')">'); + $this->template->parse('row','delete',True); } $this->template->set_var('hr_text','<hr>'); $this->template->parse('row','hr',True); @@ -138,3 +166,4 @@ $this->prep_page(); } } +?> diff -aburN --exclude='CVS*' phpgroupware.old/calendar/inc/class.uicalendar.inc.php phpgroupware/calendar/inc/class.uicalendar.inc.php --- phpgroupware.old/calendar/inc/class.uicalendar.inc.php Fri Dec 6 21:56:45 2002 +++ phpgroupware/calendar/inc/class.uicalendar.inc.php Tue Jan 7 21:20:56 2003 @@ -814,6 +814,26 @@ } // } } + else + { + // allow me (who I am logged in as) to set up an alarm + // if I am a participant, but not the owner + reset($event['participants']); + while (list($user,$short_status) = each($event['participants'])) + { + if ($GLOBALS['phpgw_info']['user']['account_id'] == $user) + { + $var = Array( + 'action_url_button' => $GLOBALS['phpgw']->link('/index.php','menuaction=calendar.uialarm.manager'), + 'action_text_button' => lang('Alarm Management'), + 'action_confirm_button' => '', + 'action_extra_field' => '<input type="hidden" name="cal_id" value="'.$cal_id.'">' + ); + $p->set_var($var); + echo $p->fp('out','form_button'); + } + } + } $var = Array( 'action_url_button' => $this->page('export'), @@ -2589,6 +2609,9 @@ } if(@isset($event['alarm']) && count($event['alarm']) >= 1) { + // if the alarm is to go off the day before the event + // the icon does not show up because of 'alarm_today' + // - TOM if($this->bo->alarm_today($event,$rawdate_offset,$starttime)) { $picture[] = Array( @@ -3304,7 +3327,7 @@ $icon = '<img src="'.$GLOBALS['phpgw']->common->image('calendar',($alarm['enabled']?'enabled':'disabled')).'" width="13" height="13">'; $var = Array( 'field' => $icon.$GLOBALS['phpgw']->common->show_date($alarm['time']), - 'data' => $alarm['text'] + 'data' => 'Email Notification' ); $this->output_template_array($p,'row','list',$var); } @@ -4008,6 +4031,66 @@ ); } +// Reminder + // The user must use "Alarm Management" to change/modify an alarm + // so only display the email reminder fields if this is a new event + // i.e. not editing an existing event + + if ($event['id'] == 0) { + // get defaults + $days = $this->bo->prefs['calendar']['default_email_days']; + $hours = $this->bo->prefs['calendar']['default_email_hours']; + $min = $this->bo->prefs['calendar']['default_email_min']; + if (count($event['alarm']) > 1) + { + // this should not happen because when creating a new event + // only 1 alarm is displayed on the screen + // if the user wants more than 1 alarm they should + // use "Alarm Management" + echo '<!-- how did this happen, too many alarms -->'."\n"; + } + // if there was an error pick up what the user entered + if (@isset($event['alarm'])) + { + @reset($event['alarm']); + // just get the first one see above!!! + list($key,$alarm) = @each($event['alarm']); + $diff = $start - $alarm['time']; + $days = intval($diff / (24*3600)); + $hours = intval(($diff - ($days * 24 * 3600))/3600); + $min = intval(($diff - ($days * 24 * 3600) - ($hours * 3600))/60); + } + + // days + $dout = '<select name="cal[alarmdays]">'."\n"; + for($i=0;$i<32;$i++) + { + $dout .= '<option value="'.$i.'"'.($i==$days?' selected':'').'>'.$i.'</option>'."\n"; + } + $dout .= '</select>'."\n".' days '; + // hours + $hout = '<select name="cal[alarmhours]">'."\n"; + for($i=0;$i<25;$i++) + { + $hout .= '<option value="'.$i.'"'.($i==$hours?' selected':'').'>'.$i.'</option>'."\n"; + } + $hout .= '</select>'."\n".' hours '; + // minutes + $mout = '<select name="cal[alarmminutes]">'."\n"; + for($i=0;$i<61;$i++) + { + $mout .= '<option value="'.$i.'"'.($i==$min?' selected':'').'>'.$i.'</option>'."\n"; + } + $mout .= '</select>'."\n".' minutes '; + + + $var[] = Array( + 'field' => lang('Email Reminder'), + 'data' => $dout.$hout.$mout.'<br>before the event' + ); + + } + for($i=0;$i<count($var);$i++) { $this->output_template_array($p,'row','list',$var[$i]); diff -aburN --exclude='CVS*' phpgroupware.old/calendar/inc/class.uipreferences.inc.php phpgroupware/calendar/inc/class.uipreferences.inc.php --- phpgroupware.old/calendar/inc/class.uipreferences.inc.php Fri Dec 6 21:56:45 2002 +++ phpgroupware/calendar/inc/class.uipreferences.inc.php Tue Jan 7 21:43:28 2003 @@ -182,6 +182,30 @@ $this->display_item(lang('Print calendars in black & white'),'<input type="checkbox" name="prefs[print_black_white]" value="True"'.(@$this->bo->prefs['calendar']['print_black_white']?' checked':'').'>'."\n"); + $str = '<select name="prefs[default_email_days]">'; + for ($i=0;$i<=31;$i++) + { + $str .= '<option'.(@$this->bo->prefs['calendar']['default_email_days']==$i?' selected':'').'>'.$i; + } + $str .= '</select>'."\n"; + $this->display_item(lang('When creating new events default number of days before event to send reminder'),$str); + + $str = '<select name="prefs[default_email_hours]">'; + for ($i=0;$i<=24;$i++) + { + $str .= '<option'.(@$this->bo->prefs['calendar']['default_email_hours']==$i?' selected':'').'>'.$i; + } + $str .= '</select>'."\n"; + $this->display_item(lang('When creating new events default number of hours before event to send reminder'),$str); + + $str = '<select name="prefs[default_email_min]">'; + for ($i=0;$i<=60;$i++) + { + $str .= '<option'.(@$this->bo->prefs['calendar']['default_email_min']==$i?' selected':'').'>'.$i; + } + $str .= '</select>'."\n"; + $this->display_item(lang('When creating new events default number of minutes before event to send reminder'),$str); + $this->template->pparse('out','pref'); } diff -aburN --exclude='CVS*' phpgroupware.old/calendar/templates/default/alarm.tpl phpgroupware/calendar/templates/default/alarm.tpl --- phpgroupware.old/calendar/templates/default/alarm.tpl Thu Oct 25 17:54:21 2001 +++ phpgroupware/calendar/templates/default/alarm.tpl Tue Jan 7 21:46:25 2003 @@ -9,6 +9,13 @@ </font> </center> </form> +<form action="{action_add}" method="post" name="alarmadd"> +<center> +{input_text}&nbsp;{input_days}&nbsp;{input_hours}&nbsp;{input_minutes} +<p> +{input_add} +</center> +</form> <!-- END alarm_management --> <!-- BEGIN alarm_headers --> <tr> @@ -35,3 +42,10 @@ </td> </tr> <!-- END hr --> +<!-- BEGIN delete --> + <tr> + <td colspan="2"> + {input_delete} + </td> + </tr> +<!-- END delete -->