source: trunk/calendar/inc/class.uialarm.inc.php @ 7681

Revision 7681, 9.4 KB checked in by douglasz, 11 years ago (diff)

Ticket #3236 - Correcoes para Best Practice: Short Open Tag e Best Practice: Always Quote Array Keys.

  • Property svn:eol-style set to native
  • Property svn:executable set to *
Line 
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                        {
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'] );
131                                $time = (int)($_POST['time']['days'])*24*3600 +
132                                        (int)($_POST['time']['hours'])*3600 +
133                                        (int)($_POST['time']['mins'])*60;
134                                $alarm_time = $start_event - $time;
135                               
136                                if ($alarm_time <= time())
137                                {
138                                        echo    '<center>'.lang('Alarm is older than now!!!').'</center><center>'.
139                                                        '<form method="POST" action="'.$GLOBALS['phpgw']->link('/index.php',Array('menuaction'=>'calendar.uialarm.manager')).'">'.
140                                                        '<input type="hidden" value="'.$this->bo->cal_id.'" name="cal_id">'.
141                                                        '<input type="hidden" value="'.$_POST['return_to'].'" name="return_to">'.
142                                                        '<center><input type="submit" value="'.lang("Back").'"/></center></form></center>' ;
143                                        $GLOBALS['phpgw']->common->phpgw_exit(True);
144                                }
145                               
146                                foreach ( $this->bo->bo->so->cal->event['alarm'] as $object ){
147                                        if ($object['time'] == $alarm_time)
148                                        {
149                                                echo '<center>'.lang("Alarm already added!!!").'</center><center>'.
150                                                         '<form method="POST" action="'.$GLOBALS['phpgw']->link('/index.php',Array('menuaction'=>'calendar.uialarm.manager')).'">'.
151                                                         '<input type="hidden" value="'.$this->bo->cal_id.'" name="cal_id">'.
152                                                         '<input type="hidden" value="'.$_POST['return_to'].'" name="return_to">'.
153                                                         '<center><input type="submit" value="'.lang("Back").'"/></center></form></center>' ;
154                                                $GLOBALS['phpgw']->common->phpgw_exit(True);
155                                        }
156                                }
157
158                                if ($time > 0 && !$this->bo->add($this->event,$time,$_POST['owner']))
159                                {
160                                        echo '<center>'.lang('You do not have permission to add alarms to this event !!!').'</center>';
161                                        $GLOBALS['phpgw']->common->phpgw_exit(True);
162                                }
163                               
164                                if ($time == 0)
165                                {
166                                        echo '<center>'.lang("Invalid Alarm!!!").'</center><center>'.
167                                                         '<form method="POST" action="'.$GLOBALS['phpgw']->link('/index.php',Array('menuaction'=>'calendar.uialarm.manager')).'">'.
168                                                         '<input type="hidden" value="'.$this->bo->cal_id.'" name="cal_id">'.
169                                                         '<input type="hidden" value="'.$_POST['return_to'].'" name="return_to">'.
170                                                         '<center><input type="submit" value="'.lang("Back").'"/></center></form></center>' ;
171                                        $GLOBALS['phpgw']->common->phpgw_exit(True);
172                                }
173                        }
174                        if (!ExecMethod('calendar.uicalendar.view_event',$this->event))
175                        {
176                                echo '<center>'.lang('You do not have permission to read this record!').'</center>';
177                                $GLOBALS['phpgw']->common->phpgw_exit(True);
178                        }
179                        echo "<br>\n";
180                        $GLOBALS['phpgw']->template->set_var('th_bg',$this->theme['th_bg']);
181                        $GLOBALS['phpgw']->template->set_var('hr_text',lang('Alarms').':');
182                        $GLOBALS['phpgw']->template->fp('row','hr',True);
183                        $GLOBALS['phpgw']->template->pfp('phpgw_body','view_event');
184
185                        $var = Array(
186                                'tr_color'              => $this->theme['th_bg'],
187                                'lang_select'   => lang('Select'),
188                                'lang_time'             => lang('Time'),
189                                'lang_text'             => lang('Text'),
190                                'lang_owner'    => lang('Owner'),
191                                'lang_enabled'  => lang('enabled'),
192                                'lang_disabled' => lang('disabled'),
193                        );
194                        if($this->event['alarm'])
195                        {
196                                $this->output_template_array('rows','alarm_headers',$var);
197
198                                foreach($this->event['alarm'] as $key => $alarm)
199                                {
200                                        if (!$this->bo->check_perms(PHPGW_ACL_READALARM,$alarm['owner']))
201                                        {
202                                                continue;
203                                        }
204                                        $var = Array(
205                                                'field'    => $GLOBALS['phpgw']->common->show_date($alarm['time']),
206                                                //'data'   => $alarm['text'],
207                                                'data'     => lang('Email Notification'),
208                                                'owner'    => $GLOBALS['phpgw']->common->grab_owner_name($alarm['owner']),
209                                                'select'   => $this->html->checkbox("alarm[{$alarm['id']}]")
210                                        );
211                                        if ($this->bo->check_perms(PHPGW_ACL_DELETEALARM,$alarm['owner']))
212                                        {
213                                                ++$to_delete;
214                                        }
215                                        $this->output_template_array('rows','list',$var);
216                                }
217
218                                if ($to_delete)
219                                {
220                                        $this->template->set_var('delete_button',$this->html->submit_button('delete','Delete',"return confirm('".lang("Are you sure want to delete these alarms?")."')"));
221                                }
222                                $this->template->parse('rows','buttons',True);
223                        }
224                        if (isset($this->event['participants'][(int)$GLOBALS['phpgw_info']['user']['account_id']]))
225                        {
226                                $this->template->set_var(Array(
227                                        'input_days'    => $this->html->select('time[days]',$_POST['time']['days'],range(0,31),True).' '.lang('days'),
228                                        'input_hours'   => $this->html->select('time[hours]',$_POST['time']['hours'],range(0,24),True).' '.lang('hours'),
229                                        'input_minutes' => $this->html->select('time[mins]',$_POST['time']['mins'],range(0,60),True).' '.lang('minutes').' '.lang('before the event'),
230                                        'input_owner'   => $this->html->select('owner',$GLOBALS['phpgw_info']['user']['account_id'],$this->bo->participants($this->event,True),True),
231                                        'input_add'     => $this->html->submit_button('add','Add Alarm'),
232                                ));
233                        }
234                        $this->template->set_var(Array(
235                                'action_url'    => $GLOBALS['phpgw']->link('/index.php',Array('menuaction'=>'calendar.uialarm.manager')),
236                                'hidden_vars'   => $this->html->input_hidden(array(
237                                        'cal_id' => $this->bo->cal_id,
238                                        'return_to' => $_POST['return_to']
239                                )),
240                                'input_cancel'  => $this->html->submit_button('cancel','Cancel')
241                        ));
242//echo "<p>alarm_management='".htmlspecialchars($this->template->get_var('alarm_management'))."'</p>\n";
243                        $this->template->pfp('out','alarm_management');
244                        $GLOBALS['phpgw']->common->phpgw_footer();
245                }
246       
247        }
248?>
Note: See TracBrowser for help on using the repository browser.