[2] | 1 | <?php |
---|
| 2 | /**************************************************************************\ |
---|
| 3 | * eGroupWare - Calendar * |
---|
| 4 | * http://www.egroupware.org * |
---|
| 5 | * Based on Webcalendar by Craig Knudsen <cknudsen@radix.net> * |
---|
| 6 | * http://www.radix.net/~cknudsen * |
---|
| 7 | * Modified by Mark Peters <skeeter@phpgroupware.org> * |
---|
| 8 | * -------------------------------------------- * |
---|
| 9 | * This program is free software; you can redistribute it and/or modify it * |
---|
| 10 | * under the terms of the GNU General Public License as published by the * |
---|
| 11 | * Free Software Foundation; either version 2 of the License, or (at your * |
---|
| 12 | * option) any later version. * |
---|
| 13 | \**************************************************************************/ |
---|
| 14 | |
---|
| 15 | |
---|
| 16 | class uialarm |
---|
| 17 | { |
---|
| 18 | var $template; |
---|
| 19 | var $template_dir; |
---|
| 20 | |
---|
| 21 | var $bo; |
---|
| 22 | var $event; |
---|
| 23 | |
---|
| 24 | var $debug = False; |
---|
| 25 | // var $debug = True; |
---|
| 26 | |
---|
| 27 | var $tz_offset; |
---|
| 28 | var $theme; |
---|
| 29 | |
---|
| 30 | var $public_functions = array( |
---|
| 31 | 'manager' => True |
---|
| 32 | ); |
---|
| 33 | |
---|
| 34 | function uialarm() |
---|
| 35 | { |
---|
| 36 | $GLOBALS['phpgw']->nextmatchs = CreateObject('phpgwapi.nextmatchs'); |
---|
| 37 | $GLOBALS['phpgw']->browser = CreateObject('phpgwapi.browser'); |
---|
| 38 | |
---|
| 39 | $this->theme = $GLOBALS['phpgw_info']['theme']; |
---|
| 40 | |
---|
| 41 | $this->bo = CreateObject('calendar.boalarm'); |
---|
| 42 | |
---|
| 43 | if($this->debug) |
---|
| 44 | { |
---|
| 45 | echo "BO Owner : ".$this->bo->owner."<br>\n"; |
---|
| 46 | } |
---|
| 47 | $this->template_dir = $GLOBALS['phpgw']->common->get_tpl_dir('calendar'); |
---|
| 48 | |
---|
| 49 | if (!is_object($GLOBALS['phpgw']->html)) |
---|
| 50 | { |
---|
| 51 | $GLOBALS['phpgw']->html = CreateObject('phpgwapi.html'); |
---|
| 52 | } |
---|
| 53 | $this->html = &$GLOBALS['phpgw']->html; |
---|
| 54 | } |
---|
| 55 | |
---|
| 56 | function prep_page() |
---|
| 57 | { |
---|
| 58 | if ($this->bo->cal_id <= 0 || |
---|
| 59 | !$this->event = $this->bo->read_entry($this->bo->cal_id)) |
---|
| 60 | { |
---|
| 61 | $GLOBALS['phpgw']->redirect_link('/index.php',Array( |
---|
| 62 | 'menuaction' => 'calendar.uicalendar.index' |
---|
| 63 | )); |
---|
| 64 | } |
---|
| 65 | |
---|
| 66 | unset($GLOBALS['phpgw_info']['flags']['noheader']); |
---|
| 67 | unset($GLOBALS['phpgw_info']['flags']['nonavbar']); |
---|
| 68 | $GLOBALS['phpgw_info']['flags']['app_header'] = $GLOBALS['phpgw_info']['apps']['calendar']['title'].' - '.lang('Alarm Management'); |
---|
| 69 | $GLOBALS['phpgw']->common->phpgw_header(); |
---|
| 70 | |
---|
| 71 | $this->template = CreateObject('phpgwapi.Template',$this->template_dir); |
---|
| 72 | |
---|
| 73 | $this->template->set_unknowns('remove'); |
---|
| 74 | $this->template->set_file( |
---|
| 75 | Array( |
---|
| 76 | 'alarm' => 'alarm.tpl' |
---|
| 77 | ) |
---|
| 78 | ); |
---|
| 79 | $this->template->set_block('alarm','alarm_management','alarm_management'); |
---|
| 80 | $this->template->set_block('alarm','alarm_headers','alarm_headers'); |
---|
| 81 | $this->template->set_block('alarm','list','list'); |
---|
| 82 | $this->template->set_block('alarm','hr','hr'); |
---|
| 83 | $this->template->set_block('alarm','buttons','buttons'); |
---|
| 84 | } |
---|
| 85 | |
---|
| 86 | function output_template_array($row,$list,$var) |
---|
| 87 | { |
---|
| 88 | if (!isset($var['tr_color'])) |
---|
| 89 | { |
---|
| 90 | $var['tr_color'] = $GLOBALS['phpgw']->nextmatchs->alternate_row_color(); |
---|
| 91 | } |
---|
| 92 | $this->template->set_var($var); |
---|
| 93 | $this->template->parse($row,$list,True); |
---|
| 94 | } |
---|
| 95 | |
---|
| 96 | /* Public functions */ |
---|
| 97 | |
---|
| 98 | function manager() |
---|
| 99 | { |
---|
| 100 | if ($_POST['cancel']) |
---|
| 101 | { |
---|
| 102 | $GLOBALS['phpgw']->redirect_link('/index.php','menuaction='.($_POST['return_to'] ? $_POST['return_to'] : 'calendar.uicalendar.index')); |
---|
| 103 | } |
---|
| 104 | if ($_POST['delete'] && count($_POST['alarm'])) |
---|
| 105 | { |
---|
| 106 | if ($this->bo->delete($_POST['alarm']) < 0) |
---|
| 107 | { |
---|
| 108 | echo '<center>'.lang('You do not have permission to delete this alarm !!!').'</center>'; |
---|
| 109 | $GLOBALS['phpgw']->common->phpgw_exit(True); |
---|
| 110 | } |
---|
| 111 | } |
---|
| 112 | if (($_POST['enable'] || $_POST['disable']) && count($_POST['alarm'])) |
---|
| 113 | { |
---|
| 114 | if ($this->bo->enable($_POST['alarm'],$_POST['enable']) < 0) |
---|
| 115 | { |
---|
| 116 | echo '<center>'.lang('You do not have permission to enable/disable this alarm !!!').'</center>'; |
---|
| 117 | $GLOBALS['phpgw']->common->phpgw_exit(True); |
---|
| 118 | } |
---|
| 119 | } |
---|
| 120 | $this->prep_page(); |
---|
| 121 | |
---|
| 122 | if ($_POST['add']) |
---|
| 123 | { |
---|
[22] | 124 | // Unix time format of event start |
---|
| 125 | $start_event=mktime( $this->bo->bo->so->cal->event['start']['hour'] , |
---|
| 126 | $this->bo->bo->so->cal->event['start']['min'] , |
---|
| 127 | $this->bo->bo->so->cal->event['start']['sec'] , |
---|
| 128 | $this->bo->bo->so->cal->event['start']['month'] , |
---|
| 129 | $this->bo->bo->so->cal->event['start']['mday'], |
---|
| 130 | $this->bo->bo->so->cal->event['start']['year'] ); |
---|
[2] | 131 | $time = (int)($_POST['time']['days'])*24*3600 + |
---|
| 132 | (int)($_POST['time']['hours'])*3600 + |
---|
| 133 | (int)($_POST['time']['mins'])*60; |
---|
[22] | 134 | $alarm_time = $start_event - $time; |
---|
| 135 | |
---|
[23] | 136 | if ($alarm_time <= time()) |
---|
| 137 | { |
---|
[29] | 138 | echo lang('Alarm is older than now!!!'); |
---|
[23] | 139 | $GLOBALS['phpgw']->common->phpgw_exit(True); |
---|
| 140 | } |
---|
| 141 | |
---|
[22] | 142 | foreach ( $this->bo->bo->so->cal->event['alarm'] as $object ){ |
---|
| 143 | if ($object['time'] == $alarm_time) |
---|
| 144 | { |
---|
| 145 | echo '<center>'.lang('Alarm already added!!!').'</center>'; |
---|
| 146 | $GLOBALS['phpgw']->common->phpgw_exit(True); |
---|
| 147 | } |
---|
| 148 | } |
---|
[2] | 149 | |
---|
| 150 | if ($time > 0 && !$this->bo->add($this->event,$time,$_POST['owner'])) |
---|
| 151 | { |
---|
| 152 | echo '<center>'.lang('You do not have permission to add alarms to this event !!!').'</center>'; |
---|
| 153 | $GLOBALS['phpgw']->common->phpgw_exit(True); |
---|
| 154 | } |
---|
| 155 | } |
---|
| 156 | if (!ExecMethod('calendar.uicalendar.view_event',$this->event)) |
---|
| 157 | { |
---|
| 158 | echo '<center>'.lang('You do not have permission to read this record!').'</center>'; |
---|
| 159 | $GLOBALS['phpgw']->common->phpgw_exit(True); |
---|
| 160 | } |
---|
| 161 | echo "<br>\n"; |
---|
| 162 | $GLOBALS['phpgw']->template->set_var('th_bg',$this->theme['th_bg']); |
---|
| 163 | $GLOBALS['phpgw']->template->set_var('hr_text',lang('Alarms').':'); |
---|
| 164 | $GLOBALS['phpgw']->template->fp('row','hr',True); |
---|
| 165 | $GLOBALS['phpgw']->template->pfp('phpgw_body','view_event'); |
---|
| 166 | |
---|
| 167 | $var = Array( |
---|
| 168 | 'tr_color' => $this->theme['th_bg'], |
---|
| 169 | 'lang_select' => lang('Select'), |
---|
| 170 | 'lang_time' => lang('Time'), |
---|
| 171 | 'lang_text' => lang('Text'), |
---|
| 172 | 'lang_owner' => lang('Owner'), |
---|
| 173 | 'lang_enabled' => lang('enabled'), |
---|
| 174 | 'lang_disabled' => lang('disabled'), |
---|
| 175 | ); |
---|
| 176 | if($this->event['alarm']) |
---|
| 177 | { |
---|
| 178 | $this->output_template_array('rows','alarm_headers',$var); |
---|
| 179 | |
---|
| 180 | foreach($this->event['alarm'] as $key => $alarm) |
---|
| 181 | { |
---|
| 182 | if (!$this->bo->check_perms(PHPGW_ACL_READALARM,$alarm['owner'])) |
---|
| 183 | { |
---|
| 184 | continue; |
---|
| 185 | } |
---|
| 186 | $var = Array( |
---|
| 187 | 'field' => $GLOBALS['phpgw']->common->show_date($alarm['time']), |
---|
| 188 | //'data' => $alarm['text'], |
---|
| 189 | 'data' => lang('Email Notification'), |
---|
| 190 | 'owner' => $GLOBALS['phpgw']->common->grab_owner_name($alarm['owner']), |
---|
| 191 | 'enabled' => $this->html->image('calendar',$alarm['enabled']?'enabled':'disabled',$alarm['enabled']?'enabled':'disabled','width="13" height="13"'), |
---|
| 192 | 'select' => $this->html->checkbox("alarm[$alarm[id]]") |
---|
| 193 | ); |
---|
| 194 | if ($this->bo->check_perms(PHPGW_ACL_DELETEALARM,$alarm['owner'])) |
---|
| 195 | { |
---|
| 196 | ++$to_delete; |
---|
| 197 | } |
---|
| 198 | $this->output_template_array('rows','list',$var); |
---|
| 199 | } |
---|
| 200 | $this->template->set_var('enable_button',$this->html->submit_button('enable','Enable')); |
---|
| 201 | $this->template->set_var('disable_button',$this->html->submit_button('disable','Disable')); |
---|
| 202 | if ($to_delete) |
---|
| 203 | { |
---|
[204] | 204 | $this->template->set_var('delete_button',$this->html->submit_button('delete','Delete',"return confirm('".lang("Are you sure want to delete these alarms?")."')")); |
---|
[2] | 205 | } |
---|
| 206 | $this->template->parse('rows','buttons',True); |
---|
| 207 | } |
---|
| 208 | if (isset($this->event['participants'][(int)$GLOBALS['phpgw_info']['user']['account_id']])) |
---|
| 209 | { |
---|
| 210 | $this->template->set_var(Array( |
---|
| 211 | 'input_days' => $this->html->select('time[days]',$_POST['time']['days'],range(0,31),True).' '.lang('days'), |
---|
| 212 | 'input_hours' => $this->html->select('time[hours]',$_POST['time']['hours'],range(0,24),True).' '.lang('hours'), |
---|
| 213 | 'input_minutes' => $this->html->select('time[mins]',$_POST['time']['mins'],range(0,60),True).' '.lang('minutes').' '.lang('before the event'), |
---|
| 214 | 'input_owner' => $this->html->select('owner',$GLOBALS['phpgw_info']['user']['account_id'],$this->bo->participants($this->event,True),True), |
---|
| 215 | 'input_add' => $this->html->submit_button('add','Add Alarm'), |
---|
| 216 | )); |
---|
| 217 | } |
---|
| 218 | $this->template->set_var(Array( |
---|
| 219 | 'action_url' => $GLOBALS['phpgw']->link('/index.php',Array('menuaction'=>'calendar.uialarm.manager')), |
---|
| 220 | 'hidden_vars' => $this->html->input_hidden(array( |
---|
| 221 | 'cal_id' => $this->bo->cal_id, |
---|
| 222 | 'return_to' => $_POST['return_to'] |
---|
| 223 | )), |
---|
| 224 | 'lang_enable' => lang('Enable'), |
---|
| 225 | 'lang_disable' => lang('Disable'), |
---|
| 226 | 'input_cancel' => $this->html->submit_button('cancel','Cancel') |
---|
| 227 | )); |
---|
| 228 | //echo "<p>alarm_management='".htmlspecialchars($this->template->get_var('alarm_management'))."'</p>\n"; |
---|
| 229 | $this->template->pfp('out','alarm_management'); |
---|
[15] | 230 | $GLOBALS['phpgw']->common->phpgw_footer(); |
---|
[2] | 231 | } |
---|
[15] | 232 | |
---|
[2] | 233 | } |
---|
| 234 | ?> |
---|