[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Phpgroupware-users] Another satisifed customer
From: |
Tom Gasaway |
Subject: |
Re: [Phpgroupware-users] Another satisifed customer |
Date: |
Wed, 14 Aug 2002 12:11:07 -0600 |
For those of you that are interested, here is a set of patches and a cron that
implement email notifications of upcoming calendar events. The only problem is
that
the patch to calendar/inc/class.uicalendar.inc.php is for an older version
(1.66.2.19 instead of 1.66.2.20).
Tom
phpGroupWare Mail wrote:
>
> I just stumbled across phpGroupWare last week and I'm very impressed with it
> ...
> I do have a question for whomever is in charge of the calendar portion of the
> package. Are there any plans to add e-mail notifications of upcoming calendar
> events? I see that the calendar portion of the package is actually a modified
> version of the WebCalendar project on SourceForge. WebCalendar offers e-mail
> reminder capabilities, so I'm wondering if this is a feature that was removed
> from the phpGroupWare calendar or if the code used in the phpGroupWare
> calendar was from a version of WebCalendar before it had that capability. At
> any rate, are there any plans of that feature?
- You will need to set up a cron to run the email script. Something like:
* * * * * /var/www/html/phpgroupware/calendar/cron
- I added the ability to add one alarm in the "Calendar - Add" screen
so that the user does 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 they probably just want one email notification.
The alarm fields do NOT show up when editing the event because if they
want to edit an alarm they should use the Alarm Management screen.
- I added the ability to set an alarm on an event you are a participant of
not just the events you are the owner of.
- rfc2445 implies multiple types of alarms (EMAIL, AUDIO, & DISPLAY) and
the mysql table phpgw_cal_alarm does not have a field for 'type'.
I have not implemented AUDIO & DISPLAY yet.
- rfc2445 implies the trigger can be a relative time or an absolute time
so far I have only implemented relative time
- I do not use the 'text' field at this time because the cron message looks
up and sends most of the information about the event in the email
notification.
- I did 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.
- It would be nice if the text field were longer than 50 characters.
- It would be nice to add a preference for each user to set
the 'text' field so they don't have to type it in
for each event. The text field should allow some kind of replacement values
for SUBJECT, LOCATION, DESCRIPTION, START TIME, etc.
- I have not implemented 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 happens if the user edits/modifies/deletes a single event in the
series???
- 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.
#!/usr/bin/php -q
<?php
// set this up as a cron to run every minute, something like:
// * * * * * /var/www/html/phpgroupware/calendar/cron
// 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'), 'read');
$db->query('SELECT * FROM phpgw_cal_alarm where alarm_enabled=1 and
cal_time <= unix_timestamp()',__LINE__,__FILE__);
if ($db->num_rows() < 1)
{
$db->unlock();
exit;
}
while ($db->next_record())
{
$Alarm[$db->f('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')
);
}
$db->unlock();
// get email addresses
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";
}
}
// 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...
// the date & time functions below should be converted to use
// the users time format
// get info about each event
@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);
$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;
}
switch ($type) {
case MCAL_RECUR_NONE:
$db->query('UPDATE phpgw_cal_alarm set
alarm_enabled=0 where alarm_id='.$key,__LINE__,__FILE__);
$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;
}
$next = 24 * 3600 * $interval;
$newalmtime = $alarm['cal_time'] + $next;
// the new alarm time to set must be some time
in the future
while ($newalmtime < $now)
{
$newalmtime += $next;
}
// 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 += $next;
$newedatetime += $next;
}
$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 && $enddate < $neweventtime)
{
$db->query('UPDATE phpgw_cal_alarm set
alarm_enabled=0 where alarm_id='.$key,__LINE__,__FILE__);
}
else
{
$db->query('UPDATE phpgw_cal_alarm set
cal_time='.$newalmtime.' where alarm_id='.$key,__LINE__,__FILE__);
}
break;
case MCAL_RECUR_WEEKLY:
if (($interval = $db->f('recur_interval')) == 0)
{
$interval = 1;
}
$recurdow = $db->f('recur_data');
$dow = date("w", $alarm['cal_time']);
$j = $dow + 1;
$mult = 1;
// find the next day of week that is selected
while ($j != $dow)
{
if ($j > 6)
{
$j = 0;
}
if ($recurdow & $wdb[$j])
{
break;
}
$j++;
if ($mult++ > 7)
{
break;
}
}
$interval--;
$next = (24 * 3600 * $mult) + ($interval * 7 *
24 * 3600);
$newalmtime = $alarm['cal_time'] + $next;
// the new alarm time to set must be some time
in the future
while ($newalmtime < $now)
{
$newalmtime += $next;
}
// 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 += $next;
$newedatetime += $next;
}
$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 && $enddate < $neweventtime)
{
$db->query('UPDATE phpgw_cal_alarm set
alarm_enabled=0 where alarm_id='.$key,__LINE__,__FILE__);
}
else
{
$db->query('UPDATE phpgw_cal_alarm set
cal_time='.$newalmtime.' where alarm_id='.$key,__LINE__,__FILE__);
}
break;
case MCAL_RECUR_MONTHLY_MDAY:
if (($interval = $db->f('recur_interval')) == 0)
{
$interval = 1;
}
$tm = localtime($alarm['cal_time'],true);
$mon = $tm[tm_mon]+1+$interval;
$year = $tm[tm_year];
if ($mon > 12)
{
$mon -= 12;
$year++;
}
$newalmtime = mktime($tm[tm_hour], $tm[tm_min],
$tm[tm_sec],$mon,$tm[tm_mday],$year);
// 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']) {
$tm = localtime($neweventtime,true);
$mon = $tm[tm_mon]+1+$interval;
$year = $tm[tm_year];
if ($mon > 12)
{
$mon -= 12;
$year++;
}
$neweventtime = mktime($tm[tm_hour],
$tm[tm_min],$tm[tm_sec],$mon,
$tm[tm_mday],$year);
$tm = localtime($newedatetime,true);
$mon = $tm[tm_mon]+1+$interval;
$year = $tm[tm_year];
if ($mon > 12)
{
$mon -= 12;
$year++;
}
$newedatetime = mktime($tm[tm_hour],
$tm[tm_min],$tm[tm_sec],$mon,
$tm[tm_mday],$year);
}
$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 && $enddate < $neweventtime)
{
$db->query('UPDATE phpgw_cal_alarm set
alarm_enabled=0 where alarm_id='.$key,__LINE__,__FILE__);
}
else
{
$db->query('UPDATE phpgw_cal_alarm set
cal_time='.$newalmtime.' where alarm_id='.$key,__LINE__,__FILE__);
}
break;
case MCAL_RECUR_MONTHLY_WDAY:
if (($interval = $db->f('recur_interval')) == 0)
{
$interval = 1;
}
$tm = localtime($alarm['cal_time'],true);
$mon = $tm[tm_mon]+1+$interval;
$year = $tm[tm_year];
if ($mon > 12)
{
$mon -= 12;
$year++;
}
// begining of the next month + secs to begining
// of equivalent week + secs to same day of week
$newalmtime = mktime($tm[tm_hour],$tm[tm_min],
$tm[tm_sec],$mon,1,$year)
+ ((ceil($tm[tm_mday]/7)-1)*7*3600*24)
+ ($tm[tm_wday]*3600*24);
// 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']) {
$tm = localtime($neweventtime,true);
$mon = $tm[tm_mon]+1+$interval;
$year = $tm[tm_year];
if ($mon > 12)
{
$mon -= 12;
$year++;
}
$neweventtime = mktime($tm[tm_hour],
$tm[tm_min],$tm[tm_sec],$mon,1,$year)
+
((ceil($tm[tm_mday]/7)-1)*7*3600*24)
+ ($tm[tm_wday]*3600*24);
$tm = localtime($newedatetime,true);
$mon = $tm[tm_mon]+1+$interval;
$year = $tm[tm_year];
if ($mon > 12)
{
$mon -= 12;
$year++;
}
$newedatetime = mktime($tm[tm_hour],
$tm[tm_min],$tm[tm_sec],$mon,1,$year)
+
((ceil($tm[tm_mday]/7)-1)*7*3600*24)
+ ($tm[tm_wday]*3600*24);
}
$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 && $enddate < $neweventtime)
{
$db->query('UPDATE phpgw_cal_alarm set
alarm_enabled=0 where alarm_id='.$key,__LINE__,__FILE__);
}
else
{
$db->query('UPDATE phpgw_cal_alarm set
cal_time='.$newalmtime.' where alarm_id='.$key,__LINE__,__FILE__);
}
break;
case MCAL_RECUR_YEARLY:
if (($interval = $db->f('recur_interval')) == 0)
{
$interval = 1;
}
$tm = localtime($alarm['cal_time'],true);
$newalmtime = mktime($tm[tm_hour], $tm[tm_min],
$tm[tm_sec],$tm[tm_mon]+1,$tm[tm_mday],
$tm[tm_year]+$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']) {
$tm = localtime($neweventtime,true);
$neweventtime = mktime($tm[tm_hour],
$tm[tm_min],
$tm[tm_sec],$tm[tm_mon]+1,$tm[tm_mday],
$tm[tm_year]+$interval);
$tm = localtime($newedatetime,true);
$newedatetime = mktime($tm[tm_hour],
$tm[tm_min],
$tm[tm_sec],$tm[tm_mon]+1,$tm[tm_mday],
$tm[tm_year]+$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 && $enddate < $neweventtime)
{
$db->query('UPDATE phpgw_cal_alarm set
alarm_enabled=0 where alarm_id='.$key,__LINE__,__FILE__);
}
else
{
$db->query('UPDATE phpgw_cal_alarm set
cal_time='.$newalmtime.' where alarm_id='.$key,__LINE__,__FILE__);
}
break;
}
$body .= 'Date: '.$date."\n";
$body .= 'Time: '.$from.' to '.$to."\n";
$body .= 'Description:'."\n\n".$description."\n\n";
// verify if datetime < now don't send email
// double check here for MCAL_RECUR_NONE
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 -aur -Bb --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 28 08:53:33 2001
+++ phpgroupware/calendar/inc/class.boalarm.inc.php Sat Aug 10 22:35:19 2002
@@ -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)
@@ -72,6 +75,47 @@
{
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 -aur -Bb --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 Tue Jul 2
21:44:32 2002
+++ phpgroupware/calendar/inc/class.bocalendar.inc.php Sat Aug 10 21:55:09 2002
@@ -761,8 +761,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']);
+ 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);
if($this->debug)
diff -aur -Bb --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 Nov 5
18:49:16 2001
+++ phpgroupware/calendar/inc/class.bopreferences.inc.php Fri Aug 9
14:40:34 2002
@@ -92,6 +92,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 -aur -Bb --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 Wed Jun 26
12:04:36 2002
+++ phpgroupware/calendar/inc/class.socalendar.inc.php Tue Jul 2 22:06:36 2002
@@ -194,6 +194,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 -aur -Bb --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 Wed Jun 26
12:04:36 2002
+++ phpgroupware/calendar/inc/class.socalendar_sql.inc.php Sat Aug 10
22:45:32 2002
@@ -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__);
+ $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)
@@ -538,6 +542,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);
+ }
+
if($this->debug)
{
echo '<!-- Event ID #'.$event['id'].' saved! -->'."\n";
@@ -575,6 +602,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;
}
@@ -613,4 +645,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 -aur -Bb --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 28 08:53:33 2001
+++ phpgroupware/calendar/inc/class.uialarm.inc.php Sat Aug 10 22:34:41 2002
@@ -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' => 'Email Notification',
'alarm_enabled' =>
($alarm['enabled']?'<img
src="'.$GLOBALS['phpgw']->common->image('calendar','enabled.gif').'" width="13"
height="13" alt="enabled">':' '),
'alarm_disabled' =>
(!$alarm['enabled']?'<img
src="'.$GLOBALS['phpgw']->common->image('calendar','disabled.gif').'"
width="13" height="13" alt="disabled">':' ')
);
$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 -aur -Bb --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 Jul 26
08:58:32 2002
+++ phpgroupware/calendar/inc/class.uicalendar.inc.php Sat Aug 10 22:44:53 2002
@@ -12,7 +12,7 @@
* option) any later version. *
\**************************************************************************/
- /* $Id: class.uicalendar.inc.php,v 1.66.2.20 2002/07/16 02:03:55
skeeter Exp $ */
+ /* $Id: class.uicalendar.inc.php,v 1.66.2.19 2002/06/29 03:28:17
skeeter Exp $ */
class uicalendar
{
@@ -786,6 +789,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'),
@@ -2779,7 +2848,8 @@
$icon = '<img
src="'.$GLOBALS['phpgw']->common->image('calendar',($alarm['enabled']?'enabled.gif':'disabled.gif')).'"
width="13" height="13">';
$var = Array(
'field' =>
$icon.$GLOBALS['phpgw']->common->show_date($alarm['time']),
+ 'data' => 'Email Notification'
);
$this->output_template_array($p,'row','list',$var);
}
@@ -3467,6 +3537,88 @@
);
}
+// 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 ';
+
+ // absolute time & date
+ // if set to a time/date after the event
+ // do error checking in
class.bocalendar.inc.php
+ // need to set a flag in $alarm['absolute'] so
that
+ // when this function is called after an error
the
+ // correct time (absolute vs relative) can be
displayed
+ // from alarm['time']
+ // we need a button for 'today' so that the
date can be left blank
+ // as a default which means no email
+ //$start = $this->bo->maketime($event['start'])
- $GLOBALS['phpgw']->datetime->tz_offset;
+ //$str = 'or on<br>';
+ //$str .=
$GLOBALS['phpgw']->common->dateformatorder(
+ //
$sb->getYears('cal[year]',intval($GLOBALS['phpgw']->common->show_date($start,'Y'))),
+ //
$sb->getMonthText('cal[month]',intval($GLOBALS['phpgw']->common->show_date($start,'n'))),
+ //
$sb->getDays('cal[mday]',intval($GLOBALS['phpgw']->common->show_date($start,'d')));
+ //$str .= ' at<br>';
+ //if ($this->bo->prefs['common']['timeformat']
== '12')
+ //{
+ // $str .= '<input type="radio"
name="cal[ampm]" value="am"'.($event['start']['hour'] >= 12?'':'
checked').'>am'."\n"
+ // . '<input type="radio"
name="cal[ampm]" value="pm"'.($event['start']['hour'] >= 12?'
checked':'').'>pm'."\n";
+ //}
+ // 'data' => '<input name="cal[hour]"
size="2" VALUE="'.$GLOBALS['phpgw']->common->show_date($start,$hourformat).'"
maxlength="2">:<input name="cal[min]" size="2"
value="'.$GLOBALS['phpgw']->common->show_date($start,'i').'"
maxlength="2">'."\n".$str
+
+ $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 -aur -Bb --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 May 10
10:32:30 2002
+++ phpgroupware/calendar/inc/class.uipreferences.inc.php Fri Aug 9
15:21:41 2002
@@ -156,6 +156,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 -aur -Bb --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 May 14 12:47:56 2002
@@ -9,6 +9,13 @@
</font>
</center>
</form>
+<form action="{action_add}" method="post" name="alarmadd">
+<center>
+{input_text} {input_days} {input_hours} {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 -->