1 | <?php |
---|
2 | class ui_mobilecalendar { |
---|
3 | |
---|
4 | var $bo; |
---|
5 | var $cat; |
---|
6 | var $link_tpl; |
---|
7 | |
---|
8 | var $public_functions = array( |
---|
9 | 'add' => true, |
---|
10 | 'init_schedule' => true, |
---|
11 | 'add_participants' => true, |
---|
12 | 'add_participant' => true, |
---|
13 | 'edit' => true, |
---|
14 | 'update' =>true, |
---|
15 | 'overlap' => true, |
---|
16 | 'index' => true |
---|
17 | ); |
---|
18 | |
---|
19 | function ui_mobilecalendar() { |
---|
20 | $this->bo = CreateObject('calendar.bocalendar',1); |
---|
21 | $this->cat = &$this->bo->cat; |
---|
22 | $GLOBALS['phpgw']->nextmatchs = CreateObject('phpgwapi.nextmatchs'); |
---|
23 | |
---|
24 | $this->link_tpl = CreateObject('phpgwapi.Template',PHPGW_APP_TPL); |
---|
25 | $this->link_tpl->set_unknowns('remove'); |
---|
26 | $this->link_tpl->set_file( |
---|
27 | Array( |
---|
28 | 'link_picture' => 'link_pict.tpl' |
---|
29 | ) |
---|
30 | ); |
---|
31 | $this->link_tpl->set_block('link_picture','link_pict','link_pict'); |
---|
32 | $this->link_tpl->set_block('link_picture','pict','pict'); |
---|
33 | $this->link_tpl->set_block('link_picture','link_open','link_open'); |
---|
34 | $this->link_tpl->set_block('link_picture','link_close','link_close'); |
---|
35 | $this->link_tpl->set_block('link_picture','link_text','link_text'); |
---|
36 | } |
---|
37 | |
---|
38 | function index() { |
---|
39 | $accountId = $GLOBALS['phpgw_info']['user']['account_id']; |
---|
40 | $uicalendar = CreateObject("calendar.uicalendar"); |
---|
41 | $daysofWeek = array(lang('Sunday'), lang('Monday'),lang('Tuesday'),lang('Wednesday'),lang('Thursday'),lang('Friday'),lang('Saturday')); |
---|
42 | $year = $uicalendar->bo->year; |
---|
43 | $month = $uicalendar->bo->month; |
---|
44 | $day = $uicalendar->bo->day; |
---|
45 | $start = $GLOBALS['phpgw']->datetime->get_weekday_start($year, $month, $day) + $GLOBALS['phpgw']->datetime->tz_offset; |
---|
46 | $tstart = $start - $GLOBALS['phpgw']->datetime->tz_offset; |
---|
47 | $tstop = $tstart + 604800; |
---|
48 | $uicalendar->bo->so->owner = $accountId; |
---|
49 | $uicalendar->bo->so->open_box($accountId); |
---|
50 | $uicalendar->bo->store_to_cache( |
---|
51 | Array( |
---|
52 | 'syear' => date('Y',$tstart), |
---|
53 | 'owner' => $accountId, |
---|
54 | 'smonth' => date('m',$tstart), |
---|
55 | 'sday' => date('d',$tstart), |
---|
56 | 'eyear' => date('Y',$tstop), |
---|
57 | 'emonth' => date('m',$tstop), |
---|
58 | 'eday' => date('d',$tstop) |
---|
59 | ) |
---|
60 | ); |
---|
61 | $daily = $uicalendar->bo->cached_events; |
---|
62 | $p = CreateObject('phpgwapi.Template', "../ac/templates/".$GLOBALS['phpgw_info']['server']['template_set']); |
---|
63 | $p->set_file(Array('view' => 'calendar.tpl')); |
---|
64 | $data[] = array(); |
---|
65 | @ksort($daily); |
---|
66 | $p->set_block("view","body"); |
---|
67 | if($daily){ |
---|
68 | $p->set_block('view','view_event'); |
---|
69 | foreach($daily as $date => $day_params) { |
---|
70 | $year = (int)substr($date,0,4); |
---|
71 | $month = (int)substr($date,4,2); |
---|
72 | $day = (int)substr($date,6,2); |
---|
73 | $day_of_week = $daysofWeek[$GLOBALS['phpgw']->datetime->day_of_week($year,$month,$day)]; |
---|
74 | $p->set_var("header_date",$day_of_week." - ".$day."/".$month."/".$year); |
---|
75 | for($i = 0; $i < count($day_params);$i++) |
---|
76 | { |
---|
77 | |
---|
78 | //Verifica se o usuario conectado é o dono do agendamento, se for não serão exibidos os links |
---|
79 | //Aceitar e Rejeitar |
---|
80 | $display = ""; |
---|
81 | if($accountId == $day_params[$i]['owner']) |
---|
82 | { |
---|
83 | $display = "none"; |
---|
84 | } |
---|
85 | |
---|
86 | $vars = $uicalendar->bo->event2array($day_params[$i]); |
---|
87 | $data = array ( |
---|
88 | "title_field" => $vars['title']['field'], |
---|
89 | "title_data" => $vars['title']['data'], |
---|
90 | "location_field" => $vars['location']['field'], |
---|
91 | "location_data" => $vars['location']['data'] ? $vars['location']['data'] : " ", |
---|
92 | "startdate_field" => $vars['startdate']['field'], |
---|
93 | "startdate_data" => substr($vars['startdate']['data'],13, 17), |
---|
94 | "enddate_field" => $vars['enddate']['field'], |
---|
95 | "enddate_data" => substr($vars['enddate']['data'],13, 17), |
---|
96 | "description_field" => $vars['description']['field'], |
---|
97 | "description_data" => $vars['description']['data'] ? $vars['description']['data'] : " ", |
---|
98 | //Links Aceitar e Rejeitar o compromisso |
---|
99 | "accept_title" => lang("Accept"), |
---|
100 | "accept_data" => "index.php?menuaction=mobile.ui_mobilemail.set_action&cal_id=" . $day_params[$i]['id'] . "&action=3", |
---|
101 | "reject_title" => lang("Reject"), |
---|
102 | "reject_data" => "index.php?menuaction=mobile.ui_mobilemail.set_action&cal_id=" . $day_params[$i]['id'] . "&action=0", |
---|
103 | "display" => $display |
---|
104 | ); |
---|
105 | |
---|
106 | // print_r($vars); |
---|
107 | $p->set_var($data); |
---|
108 | $p->parse('views','view_event',True); |
---|
109 | } |
---|
110 | } |
---|
111 | $p->parse('events','views'); |
---|
112 | //$p->pfp('out','views'); |
---|
113 | } |
---|
114 | else { |
---|
115 | $p->set_block('view','no_event'); |
---|
116 | $syear = date('Y',$tstart); |
---|
117 | $smonth = date('m',$tstart); |
---|
118 | $sday = date('d',$tstart); |
---|
119 | $eyear = date('Y',$tstop); |
---|
120 | $emonth = date('m',$tstop); |
---|
121 | $eday = date('d',$tstop); |
---|
122 | $p->set_var("start_date",$sday."/".$smonth."/".$syear); |
---|
123 | $p->set_var("end_date", $eday."/".$emonth."/".$eyear); |
---|
124 | $p->parse('events','no_event'); |
---|
125 | // $p->pfp('out','no_event'); |
---|
126 | } |
---|
127 | $p->set_var("lang_schedule",lang("schedule")); |
---|
128 | //$p->pfp('out','body'); |
---|
129 | $GLOBALS['phpgw_info']['mobiletemplate']->set_content($p->fp('out','body')); |
---|
130 | } |
---|
131 | |
---|
132 | function page($_page='',$params='') |
---|
133 | { |
---|
134 | if($_page == '') |
---|
135 | { |
---|
136 | $page_ = explode('.',$this->bo->prefs['calendar']['defaultcalendar']); |
---|
137 | $_page = $page_[0]; |
---|
138 | |
---|
139 | if ($_page=='planner_cat' || $_page=='planner_user') |
---|
140 | { |
---|
141 | $_page = 'planner'; |
---|
142 | } |
---|
143 | elseif ($_page=='index' || ($_page != 'day' && $_page != 'week' && $_page != 'month' && $_page != 'year' && $_page != 'planner')) |
---|
144 | { |
---|
145 | $_page = 'month'; |
---|
146 | $GLOBALS['phpgw']->preferences->add('calendar','defaultcalendar','month'); |
---|
147 | $GLOBALS['phpgw']->preferences->save_repository(); |
---|
148 | } |
---|
149 | } |
---|
150 | if($GLOBALS['phpgw_info']['flags']['currentapp'] == 'home' || |
---|
151 | strstr($GLOBALS['phpgw_info']['flags']['currentapp'],'mail')) // email, felamimail, ... |
---|
152 | { |
---|
153 | $page_app = 'calendar'; |
---|
154 | } |
---|
155 | else |
---|
156 | { |
---|
157 | $page_app = $GLOBALS['phpgw_info']['flags']['currentapp']; |
---|
158 | } |
---|
159 | if (is_array($params)) |
---|
160 | { |
---|
161 | $params['menuaction'] = $page_app.'.ui'.$page_app.'.'.$_page; |
---|
162 | } |
---|
163 | else |
---|
164 | { |
---|
165 | $params = 'menuaction='.$page_app.'.ui'.$page_app.'.'.$_page.$params; |
---|
166 | } |
---|
167 | return $GLOBALS['phpgw']->link('/index.php',$params); |
---|
168 | } |
---|
169 | |
---|
170 | function init_schedule() { |
---|
171 | $_SESSION['mobile_calendar'] = NULL; |
---|
172 | $this->add_participants(); |
---|
173 | } |
---|
174 | |
---|
175 | function add_participants() { |
---|
176 | |
---|
177 | $ui_cc = CreateObject('mobile.ui_mobilecc'); |
---|
178 | $ui_cc->contacts_list(true); |
---|
179 | } |
---|
180 | |
---|
181 | function add_participant() { |
---|
182 | |
---|
183 | $participants = $_SESSION["mobile_calendar"]; |
---|
184 | |
---|
185 | if(!is_array($participants)) |
---|
186 | $participants = array(); |
---|
187 | |
---|
188 | $participants[$_GET['user']] = $_GET['cn']; |
---|
189 | |
---|
190 | $_SESSION["mobile_calendar"] = $participants; |
---|
191 | |
---|
192 | $p = CreateObject('phpgwapi.Template',PHPGW_APP_TPL); |
---|
193 | $p->set_file(Array('continue' => 'keep_add_participants.tpl')); |
---|
194 | $p->set_block('continue','body'); |
---|
195 | $p->set_var('lang_add_participants',lang('keep add participants')); |
---|
196 | $p->set_var('lang_continue',lang('continue scheduling')); |
---|
197 | //$p->pfp('out','body'); |
---|
198 | $GLOBALS['phpgw_info']['mobiletemplate']->set_content($p->fp('out','body')); |
---|
199 | } |
---|
200 | |
---|
201 | function add($cd=0,$readsess=0) |
---|
202 | { |
---|
203 | if(!$this->bo->check_perms(PHPGW_ACL_ADD)) |
---|
204 | { |
---|
205 | $this->index(); |
---|
206 | } |
---|
207 | |
---|
208 | if($readsess) |
---|
209 | { |
---|
210 | $event = $this->bo->restore_from_appsession; |
---|
211 | if(!$event['owner']) |
---|
212 | { |
---|
213 | $this->bo->add_attribute('owner',$this->bo->owner); |
---|
214 | } |
---|
215 | $can_edit = True; |
---|
216 | } |
---|
217 | else |
---|
218 | { |
---|
219 | $this->bo->event_init(); |
---|
220 | $this->bo->add_attribute('id',0); |
---|
221 | |
---|
222 | $can_edit = True; |
---|
223 | $participants = (string)(get_var('participants',array('GET'),FALSE)); |
---|
224 | $starthour = (int)(get_var('hour',array('GET'),$this->bo->prefs['calendar']['workdaystarts'])); |
---|
225 | $startmin = (int)(get_var('minute',array('GET'),0)); |
---|
226 | $endmin = $startmin + (int)$this->bo->prefs['calendar']['defaultlength']; |
---|
227 | $endhour = $starthour + $this->bo->normalizeminutes($endmin); |
---|
228 | |
---|
229 | $subject = (string)(get_var('title',array('GET'),0)); |
---|
230 | if ($subject != '0') |
---|
231 | { |
---|
232 | $description = (string)(get_var('description',array('GET'),0)); |
---|
233 | $location = (string)(get_var('location',array('GET'),0)); |
---|
234 | } |
---|
235 | else |
---|
236 | unset($subject); |
---|
237 | |
---|
238 | $this->bo->set_start($this->bo->year,$this->bo->month,$this->bo->day,$starthour,$startmin,0); |
---|
239 | $this->bo->set_end($this->bo->year,$this->bo->month,$this->bo->day,$endhour,$endmin,0); |
---|
240 | $this->bo->set_title($subject); |
---|
241 | $this->bo->set_description($description); |
---|
242 | $this->bo->add_attribute('location',$location); |
---|
243 | $this->bo->set_ex_participants(''); |
---|
244 | $this->bo->add_attribute('uid',''); |
---|
245 | $this->bo->add_attribute('priority',2); |
---|
246 | if(@$this->bo->prefs['calendar']['default_private']) |
---|
247 | { |
---|
248 | $this->bo->set_class(False); |
---|
249 | } |
---|
250 | else |
---|
251 | { |
---|
252 | $this->bo->set_class(True); |
---|
253 | } |
---|
254 | |
---|
255 | $this->bo->add_attribute('participants','A',$this->bo->owner); |
---|
256 | $this->bo->set_recur_none(); |
---|
257 | $event = $this->bo->get_cached_event(); |
---|
258 | |
---|
259 | } |
---|
260 | $this->edit_form( |
---|
261 | Array( |
---|
262 | 'event' => $event, |
---|
263 | 'cd' => $cd |
---|
264 | ) |
---|
265 | ); |
---|
266 | //$GLOBALS['phpgw']->common->phpgw_footer(); |
---|
267 | } |
---|
268 | |
---|
269 | function edit($params='') |
---|
270 | { |
---|
271 | if($this->debug) |
---|
272 | { |
---|
273 | echo '<!-- params[readsess] = '.$params['readsess'].' -->'."\n"; |
---|
274 | echo '<!-- params[cd] = '.$params['cd'].' -->'."\n"; |
---|
275 | } |
---|
276 | |
---|
277 | if(isset($_GET['readsess'])) |
---|
278 | { |
---|
279 | $params['readsess'] = $_GET['readsess']; |
---|
280 | $params['cd'] = 0; |
---|
281 | } |
---|
282 | |
---|
283 | if($this->debug) |
---|
284 | { |
---|
285 | echo '<!-- params[readsess] = '.$params['readsess'].' -->'."\n"; |
---|
286 | echo '<!-- params[cd] = '.$params['cd'].' -->'."\n"; |
---|
287 | } |
---|
288 | |
---|
289 | if($params != '' && @is_array($params) && @isset($params['readsess'])) |
---|
290 | { |
---|
291 | $can_edit = True; |
---|
292 | $this->edit_form( |
---|
293 | Array( |
---|
294 | 'event' => $this->bo->restore_from_appsession(), |
---|
295 | 'cd' => $params['cd'] |
---|
296 | ) |
---|
297 | ); |
---|
298 | } |
---|
299 | elseif(isset($_GET['cal_id'])) |
---|
300 | { |
---|
301 | $cal_id = (int)$_GET['cal_id']; |
---|
302 | $event = $this->bo->read_entry($cal_id); |
---|
303 | |
---|
304 | if(!$this->bo->check_perms(PHPGW_ACL_EDIT,$event)) |
---|
305 | { |
---|
306 | Header('Location: '.$this->page('view','&cal_id='.$cal_id)); |
---|
307 | $GLOBALS['phpgw']->common->phpgw_exit(); |
---|
308 | } |
---|
309 | if(@isset($_POST['edit_type']) && $_POST['edit_type'] == 'single') |
---|
310 | { |
---|
311 | $event['id'] = 0; |
---|
312 | $this->bo->set_recur_date($event,$_POST['date']); |
---|
313 | $event['recur_type'] = MCAL_RECUR_NONE; |
---|
314 | $event['recur_interval'] = 0; |
---|
315 | $event['recur_data'] = 0; |
---|
316 | $event['recur_enddate']['month'] = 0; |
---|
317 | $event['recur_enddate']['mday'] = 0; |
---|
318 | $event['recur_enddate']['year'] = 0; |
---|
319 | $event['recur_exception'] = array(); |
---|
320 | } |
---|
321 | $this->edit_form( |
---|
322 | Array( |
---|
323 | 'event' => $event, |
---|
324 | 'cd' => $cd |
---|
325 | ) |
---|
326 | ); |
---|
327 | } |
---|
328 | } |
---|
329 | |
---|
330 | function update() { |
---|
331 | $params = array(); |
---|
332 | $params['from_mobile'] = true; |
---|
333 | $this->bo->update($params); |
---|
334 | } |
---|
335 | |
---|
336 | function edit_form($param) |
---|
337 | { |
---|
338 | if(!is_array($param)) |
---|
339 | { |
---|
340 | $this->index(); |
---|
341 | } |
---|
342 | |
---|
343 | if(isset($param['event'])) |
---|
344 | { |
---|
345 | $event = $param['event']; |
---|
346 | } |
---|
347 | |
---|
348 | $hourformat = substr($this->bo->users_timeformat,0,1); |
---|
349 | |
---|
350 | // $sb = CreateObject('phpgwapi.sbox'); |
---|
351 | $sb = CreateObject('phpgwapi.sbox2'); |
---|
352 | $jscal = CreateObject('phpgwapi.jscalendar'); // before phpgw_header() !!! |
---|
353 | |
---|
354 | unset($GLOBALS['phpgw_info']['flags']['noheader']); |
---|
355 | unset($GLOBALS['phpgw_info']['flags']['nonavbar']); |
---|
356 | $GLOBALS['phpgw_info']['flags']['noappheader'] = True; |
---|
357 | $GLOBALS['phpgw_info']['flags']['noappfooter'] = True; |
---|
358 | $GLOBALS['phpgw_info']['flags']['app_header'] = $event['id'] ? lang('Editing event') : lang('Adding event'); |
---|
359 | //$GLOBALS['phpgw']->common->phpgw_header(); |
---|
360 | |
---|
361 | $p = &$GLOBALS['phpgw']->template; |
---|
362 | $p->set_file( |
---|
363 | Array( |
---|
364 | 'edit' => 'edit.tpl', |
---|
365 | 'form_button' => 'form_button_script.tpl' |
---|
366 | ) |
---|
367 | ); |
---|
368 | $p->set_block('edit','edit_entry','edit_entry'); |
---|
369 | $p->set_block('edit','list','list'); |
---|
370 | $p->set_block('edit','hr','hr'); |
---|
371 | |
---|
372 | $vars = Array( |
---|
373 | 'font' => $this->theme['font'], |
---|
374 | 'bg_color' => $this->theme['bg_text'], |
---|
375 | 'action_url' => $GLOBALS['phpgw']->link('/ac/index.php',Array('menuaction'=>'mobile.ui_mobilecalendar.update')), |
---|
376 | 'accounts_link' => $GLOBALS['phpgw']->link('/index.php','menuaction=calendar.uicalendar.accounts_popup'), |
---|
377 | 'common_hidden' => '<input type="hidden" name="cal[id]" value="'.$event['id'].'">'."\n" |
---|
378 | . '<input type="hidden" name="cal[owner]" value="'.$event['owner'].'">'."\n" |
---|
379 | . '<input type="hidden" name="cal[uid]" value="'.$event['uid'].'">'."\n" |
---|
380 | . ($_GET['cal_id'] && $event['id'] == 0?'<input type="hidden" name="cal[reference]" value="'.$_GET['cal_id'].'">'."\n": |
---|
381 | (@isset($event['reference'])?'<input type="hidden" name="cal[reference]" value="'.$event['reference'].'">'."\n":'')) |
---|
382 | . (@isset($GLOBALS['phpgw_info']['server']['deny_user_grants_access']) && $GLOBALS['phpgw_info']['server']['deny_user_grants_access']? |
---|
383 | '<input type="hidden" name="participants[]" value="'.$this->bo->owner.'">'."\n":''), |
---|
384 | 'errormsg' => ($param['cd']?$GLOBALS['phpgw']->common->check_code($param['cd']):''), |
---|
385 | 'row_owner' => '<input type="hidden" name="participants[]" value="'.$event['owner'].$event['participants'][$event['owner']].'">' |
---|
386 | ); |
---|
387 | |
---|
388 | $p->set_var($vars); |
---|
389 | |
---|
390 | // Brief Description |
---|
391 | $var['title'] = Array( |
---|
392 | 'tr_color' => $this->theme['th_bg'], |
---|
393 | 'field' => lang('Title'), |
---|
394 | 'data' => '<input name="cal[title]" size="15" maxlength="80" value="'.$event['title'].'">' |
---|
395 | ); |
---|
396 | |
---|
397 | // Location |
---|
398 | $var['location'] = Array( |
---|
399 | 'field' => lang('Location'), |
---|
400 | 'data' => '<input name="cal[location]" size="15" maxlength="255" value="'.$event['location'].'">' |
---|
401 | ); |
---|
402 | |
---|
403 | // Date |
---|
404 | |
---|
405 | $start = $this->bo->maketime($event['start']) - $GLOBALS['phpgw']->datetime->tz_offset; |
---|
406 | $var['startdate'] = Array( |
---|
407 | 'field' => lang('Start Date'), |
---|
408 | |
---|
409 | 'data' => $GLOBALS['phpgw']->common->dateformatorder( |
---|
410 | $sb->getYears('start[year]',(int)$GLOBALS['phpgw']->common->show_date($start,'Y')), |
---|
411 | $sb->getMonths('start[month]',(int)$GLOBALS['phpgw']->common->show_date($start,'n')), |
---|
412 | $sb->getDays('start[mday]',(int)$GLOBALS['phpgw']->common->show_date($start,'d')), |
---|
413 | true |
---|
414 | ) |
---|
415 | |
---|
416 | // 'data' => $jscal->input('start[str]',$start) |
---|
417 | ); |
---|
418 | |
---|
419 | // Time |
---|
420 | if ($this->bo->prefs['common']['timeformat'] == '12') |
---|
421 | { |
---|
422 | $str .= '<input type="radio" name="start[ampm]" value="am"'.($event['start']['hour'] >= 12?'':' checked').'>am'."\n" |
---|
423 | . '<input type="radio" name="start[ampm]" value="pm"'.($event['start']['hour'] >= 12?' checked':'').'>pm'."\n"; |
---|
424 | } |
---|
425 | $var['starttime'] = Array( |
---|
426 | 'field' => lang('Start Time'), |
---|
427 | 'data' => '<input name="start[hour]" size="2" VALUE="'.$GLOBALS['phpgw']->common->show_date($start,$hourformat).'" maxlength="2">:<input name="start[min]" size="2" value="'.$GLOBALS['phpgw']->common->show_date($start,'i').'" maxlength="2">'."\n".$str |
---|
428 | ); |
---|
429 | |
---|
430 | // End Date |
---|
431 | $end = $this->bo->maketime($event['end']) - $GLOBALS['phpgw']->datetime->tz_offset; |
---|
432 | $var['enddate'] = Array( |
---|
433 | 'field' => lang('End Date'), |
---|
434 | |
---|
435 | 'data' => $GLOBALS['phpgw']->common->dateformatorder( |
---|
436 | $sb->getYears('end[year]',(int)$GLOBALS['phpgw']->common->show_date($end,'Y')), |
---|
437 | $sb->getMonths('end[month]',(int)$GLOBALS['phpgw']->common->show_date($end,'n')), |
---|
438 | $sb->getDays('end[mday]',(int)$GLOBALS['phpgw']->common->show_date($end,'d')),true |
---|
439 | ) |
---|
440 | |
---|
441 | // 'data' => $jscal->input('end[str]',$end) |
---|
442 | ); |
---|
443 | |
---|
444 | // End Time |
---|
445 | if ($this->bo->prefs['common']['timeformat'] == '12') |
---|
446 | { |
---|
447 | $str = '<input type="radio" name="end[ampm]" value="am"'.($event['end']['hour'] >= 12?'':' checked').'>am'."\n" |
---|
448 | . '<input type="radio" name="end[ampm]" value="pm"'.($event['end']['hour'] >= 12?' checked':'').'>pm'."\n"; |
---|
449 | } |
---|
450 | $var['endtime'] = Array( |
---|
451 | 'field' => lang('End Time'), |
---|
452 | 'data' => '<input name="end[hour]" size="2" VALUE="'.$GLOBALS['phpgw']->common->show_date($end,$hourformat).'" maxlength="2">:<input name="end[min]" size="2" value="'.$GLOBALS['phpgw']->common->show_date($end,'i').'" maxlength="2">'."\n".$str |
---|
453 | ); |
---|
454 | |
---|
455 | |
---|
456 | $participants = $_SESSION['mobile_calendar']; |
---|
457 | $str = " "; |
---|
458 | foreach($participants as $id => $nome) { |
---|
459 | $str.="<option value='$id' selected>$nome</option>"; |
---|
460 | } |
---|
461 | |
---|
462 | |
---|
463 | $var['participants'] = array |
---|
464 | ( |
---|
465 | 'field' => lang('Participants'), |
---|
466 | 'data' => " |
---|
467 | <select id='user_list' name='participants[]' style='width: 220px' multiple size='5'>".$str."</select></center> |
---|
468 | <script src='../calendar/templates/".$GLOBALS['phpgw_info']['user']['preferences']['common']['template_set']."/js/edit.js' type='text/javascript'></script> |
---|
469 | " |
---|
470 | ); |
---|
471 | |
---|
472 | |
---|
473 | /*$var['owner'] = Array( |
---|
474 | 'field' => $GLOBALS['phpgw']->common->grab_owner_name($event['owner']).' '.lang('Participates'), |
---|
475 | 'data' => '<input type="checkbox" name="participants[]" value="'.$event['owner'].$event['participants'][$event['owner']].'" checked read-only="true">' |
---|
476 | );*/ |
---|
477 | |
---|
478 | |
---|
479 | if (!isset($this->fields)) |
---|
480 | { |
---|
481 | $this->custom_fields = CreateObject('calendar.bocustom_fields'); |
---|
482 | $this->fields = &$this->custom_fields->fields; |
---|
483 | $this->stock_fields = &$this->custom_fields->stock_fields; |
---|
484 | } |
---|
485 | $preserved = False; |
---|
486 | foreach($this->fields as $field => $data) |
---|
487 | { |
---|
488 | /*if($field=='owner') |
---|
489 | $p->set_var('display',"visibility:hidden"); |
---|
490 | else |
---|
491 | $p->set_var('display'," ");*/ |
---|
492 | if (!$data['disabled']) |
---|
493 | { |
---|
494 | if (isset($var[$field])) |
---|
495 | { |
---|
496 | switch($field) |
---|
497 | { |
---|
498 | case 'startdate': |
---|
499 | $this->output_template_array($p,'row','list',$var['startdate']); |
---|
500 | $this->output_template_array($p,'row','list',$var['starttime']); |
---|
501 | break; |
---|
502 | case 'enddate': |
---|
503 | $this->output_template_array($p,'row','list',$var['enddate']); |
---|
504 | $this->output_template_array($p,'row','list',$var['endtime']); |
---|
505 | break; |
---|
506 | default: |
---|
507 | $this->output_template_array($p,'row','list',$var[$field]); |
---|
508 | } |
---|
509 | } |
---|
510 | elseif (!isset($this->stock_fields[$field])) // Custom field |
---|
511 | { |
---|
512 | $lang = lang($name = substr($field,1)); |
---|
513 | $size = 'SIZE='.($data['shown'] ? $data['shown'] : ($data['length'] ? $data['length'] : 30)). |
---|
514 | ' MAXLENGTH='.($data['length'] ? $data['length'] : 255); |
---|
515 | $v = array( |
---|
516 | 'field' => $lang == $name.'*' ? $name : $lang, |
---|
517 | 'data' => '<input name="cal['.htmlspecialchars($field).']" '.$size.' value="'.$event['#'.$name].'">' |
---|
518 | ); |
---|
519 | if ($data['title']) |
---|
520 | { |
---|
521 | $v['tr_color'] = $this->theme['th_bg']; |
---|
522 | } |
---|
523 | if (!$data['length'] && $data['title']) |
---|
524 | { |
---|
525 | $p->set_var('tr_color',$this->theme['th_bg']); |
---|
526 | $p->set_var('hr_text','<center><b>'.$v['field'].'</b></center>'); |
---|
527 | $p->parse('row','hr',True); |
---|
528 | } |
---|
529 | else |
---|
530 | { |
---|
531 | $this->output_template_array($p,'row','list',$v); |
---|
532 | } |
---|
533 | } |
---|
534 | } |
---|
535 | else // preserve disabled fields |
---|
536 | { |
---|
537 | switch ($field) |
---|
538 | { |
---|
539 | case 'owner': |
---|
540 | $preserved[$field] = $event['id'] ? $event['participants'][$event['owner']] : 'A'; |
---|
541 | break; |
---|
542 | case 'recure_type': |
---|
543 | foreach(array('recur_type','recur_enddate','recur_data','recur_interval') as $field) |
---|
544 | { |
---|
545 | $preserved[$field] = $event[$field]; |
---|
546 | } |
---|
547 | break; |
---|
548 | case 'startdate': |
---|
549 | case 'enddate': |
---|
550 | $field = substr($field,0,-4); |
---|
551 | default: |
---|
552 | $preserved[$field] = $event[$field]; |
---|
553 | } |
---|
554 | } |
---|
555 | } |
---|
556 | unset($var); |
---|
557 | if (is_array($preserved)) |
---|
558 | { |
---|
559 | //echo "preserving<pre>"; print_r($preserved); echo "</pre>\n"; |
---|
560 | $p->set_var('common_hidden',$p->get_var('common_hidden').'<input type="hidden" name="preserved" value="'.htmlspecialchars(serialize($preserved)).'">'."\n"); |
---|
561 | } |
---|
562 | $p->set_var('submit_button',lang('Save')); |
---|
563 | |
---|
564 | |
---|
565 | |
---|
566 | $delete_button = $cancel_button = ''; |
---|
567 | if ($event['id'] > 0) |
---|
568 | { |
---|
569 | $var = Array( |
---|
570 | 'action_url_button' => $this->page('delete','&cal_id='.$event['id']), |
---|
571 | 'action_text_button' => lang('Delete'), |
---|
572 | 'action_confirm_button' => "onClick=\"return confirm('".lang('Are you sure want to delete this entry?\\nThis will delete this entry for all users.')."')\"", |
---|
573 | 'action_extra_field' => '' |
---|
574 | ); |
---|
575 | $p->set_var($var); |
---|
576 | $delete_button = $p->fp('out','form_button'); |
---|
577 | |
---|
578 | } |
---|
579 | $p->set_var('delete_button',$delete_button); |
---|
580 | |
---|
581 | if ($this->bo->return_to) |
---|
582 | { |
---|
583 | $var = Array( |
---|
584 | 'action_url_button' => $GLOBALS['phpgw']->link('/index.php','menuaction='.$this->bo->return_to), |
---|
585 | 'action_text_button' => lang('Cancel'), |
---|
586 | 'action_confirm_button' => '', |
---|
587 | 'action_extra_field' => '' |
---|
588 | ); |
---|
589 | $p->set_var($var); |
---|
590 | $cancel_button = $p->fp('out','form_button'); |
---|
591 | } |
---|
592 | |
---|
593 | $p->set_var('lang_add_participants',lang("keep add participants")); |
---|
594 | |
---|
595 | $p->set_var('cancel_button',$cancel_button); |
---|
596 | $p->pparse('out','edit_entry'); |
---|
597 | |
---|
598 | } |
---|
599 | |
---|
600 | function get_organizations($context, $selected='', $recursive = false) |
---|
601 | { |
---|
602 | $s = CreateObject('phpgwapi.sector_search_ldap'); |
---|
603 | |
---|
604 | return ($recursive ? |
---|
605 | $s->get_organizations($context, $selected, false ,false) : |
---|
606 | $s->get_sectors($selected, false, false)); |
---|
607 | } |
---|
608 | |
---|
609 | function output_template_array(&$p,$row,$list,$var) |
---|
610 | { |
---|
611 | if (!isset($var['hidden_vars'])) |
---|
612 | { |
---|
613 | $var['hidden_vars'] = ''; |
---|
614 | } |
---|
615 | if (!isset($var['tr_color'])) |
---|
616 | { |
---|
617 | $var['tr_color'] = $GLOBALS['phpgw']->nextmatchs->alternate_row_color(); |
---|
618 | } |
---|
619 | $p->set_var($var); |
---|
620 | $p->parse($row,$list,True); |
---|
621 | } |
---|
622 | |
---|
623 | function overlap($params) { |
---|
624 | ini_set("display_errors","1"); |
---|
625 | if(!is_array($params)) |
---|
626 | { |
---|
627 | } |
---|
628 | else |
---|
629 | { |
---|
630 | $overlapping_events = $params['o_events']; |
---|
631 | $event = $params['this_event']; |
---|
632 | } |
---|
633 | |
---|
634 | $month = $event['start']['month']; |
---|
635 | $mday = $event['start']['mday']; |
---|
636 | $year = $event['start']['year']; |
---|
637 | |
---|
638 | $start = mktime($event['start']['hour'],$event['start']['min'],$event['start']['sec'],$month,$mday,$year) - $GLOBALS['phpgw']->datetime->tz_offset; |
---|
639 | $end = $this->bo->maketime($event['end']) - $GLOBALS['phpgw']->datetime->tz_offset; |
---|
640 | |
---|
641 | $overlap = ''; |
---|
642 | for($i=0;$i<count($overlapping_events);$i++) |
---|
643 | { |
---|
644 | $overlapped_event = $this->bo->read_entry($overlapping_events[$i],True); |
---|
645 | $overlap .= '<li>'.$this->link_to_entry($overlapped_event,$month,$mday,$year); |
---|
646 | $overlap .= '<ul>'; |
---|
647 | foreach($overlapped_event['participants'] as $id => $status) |
---|
648 | { |
---|
649 | $conflict = isset($event['participants'][$id]); |
---|
650 | $overlap .= '<li>'.($conflict?'<b>':''). |
---|
651 | $GLOBALS['phpgw']->common->grab_owner_name($id). |
---|
652 | ($conflict?'</b> - '.lang('Scheduling conflict'):'')."</li>\n"; |
---|
653 | } |
---|
654 | $overlap .= "</ul>\n"; |
---|
655 | } |
---|
656 | |
---|
657 | unset($GLOBALS['phpgw_info']['flags']['noheader']); |
---|
658 | unset($GLOBALS['phpgw_info']['flags']['nonavbar']); |
---|
659 | $GLOBALS['phpgw_info']['flags']['noappheader'] = True; |
---|
660 | $GLOBALS['phpgw_info']['flags']['noappfooter'] = True; |
---|
661 | $GLOBALS['phpgw_info']['flags']['app_header'] = $GLOBALS['phpgw_info']['apps']['calendar']['title'].' - '.lang('Scheduling Conflict'); |
---|
662 | //$GLOBALS['phpgw']->common->phpgw_header(); |
---|
663 | |
---|
664 | $p = $GLOBALS['phpgw']->template; |
---|
665 | $p->set_file( |
---|
666 | Array( |
---|
667 | 'overlap' => 'overlap.tpl', |
---|
668 | 'form_button' => 'form_button_script.tpl' |
---|
669 | ) |
---|
670 | ); |
---|
671 | |
---|
672 | $var = Array( |
---|
673 | 'color' => $this->theme['bg_text'], |
---|
674 | 'overlap_title' => lang('Scheduling Conflict'), |
---|
675 | 'overlap_text' => lang('Your suggested time of <B> %1 - %2 </B> conflicts with the following existing calendar entries:',$GLOBALS['phpgw']->common->show_date($start),$GLOBALS['phpgw']->common->show_date($end)), |
---|
676 | 'overlap_list' => $overlap |
---|
677 | ); |
---|
678 | $p->set_var($var); |
---|
679 | |
---|
680 | $date = sprintf("%04d%02d%02d",$this->bo->year,$this->bo->month,$this->bo->mday); |
---|
681 | $var = Array( |
---|
682 | 'action_url_button' => $GLOBALS['phpgw']->link('/ac/index.php',Array('menuaction'=>'mobile.ui_mobilecalendar.update','readsess'=>1)), |
---|
683 | 'action_text_button' => lang('Ignore Conflict'), |
---|
684 | 'action_confirm_button' => '', |
---|
685 | 'action_extra_field' => '' |
---|
686 | ); |
---|
687 | $this->output_template_array($p,'resubmit_button','form_button',$var); |
---|
688 | |
---|
689 | $var = Array( |
---|
690 | 'action_url_button' => $GLOBALS['phpgw']->link('/ac/index.php',Array('menuaction'=>'mobile.ui_mobilecalendar.edit','readsess'=>1,'date'=>$date)), |
---|
691 | 'action_text_button' => lang('Re-Edit Event'), |
---|
692 | 'action_confirm_button' => '', |
---|
693 | 'action_extra_field' => '' |
---|
694 | ); |
---|
695 | $this->output_template_array($p,'reedit_button','form_button',$var); |
---|
696 | $p->pparse('out','overlap'); |
---|
697 | } |
---|
698 | |
---|
699 | function link_to_entry($event,$month,$day,$year) |
---|
700 | { |
---|
701 | $str = ''; |
---|
702 | $is_private = !$event['public'] && !$this->bo->check_perms(PHPGW_ACL_READ,$event); |
---|
703 | $viewable = !$this->bo->printer_friendly && $this->bo->check_perms(PHPGW_ACL_READ,$event); |
---|
704 | |
---|
705 | $starttime = $this->bo->maketime($event['start']) - $GLOBALS['phpgw']->datetime->tz_offset; |
---|
706 | $endtime = $this->bo->maketime($event['end']) - $GLOBALS['phpgw']->datetime->tz_offset; |
---|
707 | $rawdate = mktime(0,0,0,$month,$day,$year); |
---|
708 | $rawdate_offset = $rawdate - $GLOBALS['phpgw']->datetime->tz_offset; |
---|
709 | $nextday = mktime(0,0,0,$month,$day + 1,$year) - $GLOBALS['phpgw']->datetime->tz_offset; |
---|
710 | if ((int)$GLOBALS['phpgw']->common->show_date($starttime,'Hi') && $starttime == $endtime) |
---|
711 | { |
---|
712 | $time = $GLOBALS['phpgw']->common->show_date($starttime,$this->bo->users_timeformat); |
---|
713 | } |
---|
714 | elseif ($starttime <= $rawdate_offset && $endtime >= $nextday - 60) |
---|
715 | { |
---|
716 | $time = '[ '.lang('All Day').' ]'; |
---|
717 | } |
---|
718 | elseif ((int)$GLOBALS['phpgw']->common->show_date($starttime,'Hi') || $starttime != $endtime) |
---|
719 | { |
---|
720 | if($starttime < $rawdate_offset && $event['recur_type'] == MCAL_RECUR_NONE) |
---|
721 | { |
---|
722 | $start_time = $GLOBALS['phpgw']->common->show_date($rawdate_offset,$this->bo->users_timeformat); |
---|
723 | } |
---|
724 | else |
---|
725 | { |
---|
726 | $start_time = $GLOBALS['phpgw']->common->show_date($starttime,$this->bo->users_timeformat); |
---|
727 | } |
---|
728 | |
---|
729 | if($endtime >= ($rawdate_offset + 86400)) |
---|
730 | { |
---|
731 | $end_time = $GLOBALS['phpgw']->common->show_date(mktime(23,59,59,$month,$day,$year) - $GLOBALS['phpgw']->datetime->tz_offset,$this->bo->users_timeformat); |
---|
732 | } |
---|
733 | else |
---|
734 | { |
---|
735 | $end_time = $GLOBALS['phpgw']->common->show_date($endtime,$this->bo->users_timeformat); |
---|
736 | } |
---|
737 | $time = $start_time.'-'.$end_time; |
---|
738 | } |
---|
739 | else |
---|
740 | { |
---|
741 | $time = ''; |
---|
742 | } |
---|
743 | |
---|
744 | $texttitle = $texttime = $textdesc = $textlocation = $textstatus = ''; |
---|
745 | |
---|
746 | |
---|
747 | |
---|
748 | if(!$is_private) |
---|
749 | { |
---|
750 | //$text .= $this->bo->display_status($event['users_status']); |
---|
751 | |
---|
752 | // split text for better display by templates, also see $texttime $texttitle $textdesc $textlocation |
---|
753 | $textstatus=$this->bo->display_status($event['users_status']); |
---|
754 | |
---|
755 | } |
---|
756 | |
---|
757 | /* |
---|
758 | $text = '<nobr> '.$time.' </nobr> '.$this->bo->get_short_field($event,$is_private,'title').$text. |
---|
759 | (!$is_private && $event['description'] ? ': <i>'.$this->bo->get_short_field($event,$is_private,'description').'</i>':''). |
---|
760 | $GLOBALS['phpgw']->browser->br; |
---|
761 | */ |
---|
762 | |
---|
763 | $texttime=$time; |
---|
764 | $texttitle=$this->bo->get_short_field($event,$is_private,'title'); |
---|
765 | $textdesc=(!$is_private && $event['description'] ? $this->bo->get_short_field($event,$is_private,'description'):''); |
---|
766 | // added $textlocation but this must be activated in the actual pict_link.tpl file of the used template set |
---|
767 | $textlocation=$this->bo->get_short_field($event,$is_private,'location'); |
---|
768 | |
---|
769 | if ($viewable) |
---|
770 | { |
---|
771 | $date = sprintf('%04d%02d%02d',$year,$month,$day); |
---|
772 | $this->link_tpl->set_var('link_link',$this->page('view','&cal_id='.$event['id'].'&date='.$date)); |
---|
773 | $this->link_tpl->set_var('lang_view',lang('View this entry')); |
---|
774 | $this->link_tpl->set_var('desc', $textdesc); |
---|
775 | $this->link_tpl->set_var('location', $textlocation); |
---|
776 | $this->link_tpl->parse('picture','link_open',True); |
---|
777 | } |
---|
778 | if (!$is_private) |
---|
779 | { |
---|
780 | if($event['priority'] == 3) |
---|
781 | { |
---|
782 | $picture[] = Array( |
---|
783 | 'pict' => $GLOBALS['phpgw']->common->image('calendar','high'), |
---|
784 | 'width' => 16, |
---|
785 | 'height'=> 16, |
---|
786 | 'title' => lang('high priority') |
---|
787 | ); |
---|
788 | } |
---|
789 | if($event['recur_type'] == MCAL_RECUR_NONE) |
---|
790 | { |
---|
791 | $picture[] = Array( |
---|
792 | 'pict' => $GLOBALS['phpgw']->common->image('calendar','circle'), |
---|
793 | 'width' => 9, |
---|
794 | 'height'=> 9, |
---|
795 | 'title' => lang('single event') |
---|
796 | ); |
---|
797 | } |
---|
798 | else |
---|
799 | { |
---|
800 | $picture[] = Array( |
---|
801 | 'pict' => $GLOBALS['phpgw']->common->image('calendar','recur'), |
---|
802 | 'width' => 12, |
---|
803 | 'height'=> 12, |
---|
804 | 'title' => lang('recurring event') |
---|
805 | ); |
---|
806 | } |
---|
807 | } |
---|
808 | $participants = $this->planner_participants($event['participants']); |
---|
809 | if(count($event['participants']) > 1) |
---|
810 | { |
---|
811 | $picture[] = Array( |
---|
812 | 'pict' => $GLOBALS['phpgw']->common->image('calendar','multi_3'), |
---|
813 | 'width' => 14, |
---|
814 | 'height'=> 14, |
---|
815 | 'title' => $participants |
---|
816 | ); |
---|
817 | } |
---|
818 | else |
---|
819 | { |
---|
820 | $picture[] = Array( |
---|
821 | 'pict' => $GLOBALS['phpgw']->common->image('calendar','single'), |
---|
822 | 'width' => 14, |
---|
823 | 'height'=> 14, |
---|
824 | 'title' => $participants |
---|
825 | ); |
---|
826 | } |
---|
827 | if($event['public'] == 0) |
---|
828 | { |
---|
829 | $picture[] = Array( |
---|
830 | 'pict' => $GLOBALS['phpgw']->common->image('calendar','private'), |
---|
831 | 'width' => 13, |
---|
832 | 'height'=> 13, |
---|
833 | 'title' => lang('private') |
---|
834 | ); |
---|
835 | } |
---|
836 | if(@isset($event['alarm']) && count($event['alarm']) >= 1 && !$is_private) |
---|
837 | { |
---|
838 | // if the alarm is to go off the day before the event |
---|
839 | // the icon does not show up because of 'alarm_today' |
---|
840 | // - TOM |
---|
841 | if($this->bo->alarm_today($event,$rawdate_offset,$starttime)) |
---|
842 | { |
---|
843 | $picture[] = Array( |
---|
844 | 'pict' => $GLOBALS['phpgw']->common->image('calendar','alarm'), |
---|
845 | 'width' => 13, |
---|
846 | 'height'=> 13, |
---|
847 | 'title' => lang('alarm') |
---|
848 | ); |
---|
849 | } |
---|
850 | } |
---|
851 | |
---|
852 | $description = $this->bo->get_short_field($event,$is_private,'description'); |
---|
853 | for($i=0;$i<count($picture);$i++) |
---|
854 | { |
---|
855 | $var = Array( |
---|
856 | 'pic_image' => $picture[$i]['pict'], |
---|
857 | 'width' => $picture[$i]['width'], |
---|
858 | 'height' => $picture[$i]['height'], |
---|
859 | 'title' => $picture[$i]['title'] |
---|
860 | ); |
---|
861 | $this->output_template_array($this->link_tpl,'picture','pict',$var); |
---|
862 | } |
---|
863 | if ($texttitle) |
---|
864 | { |
---|
865 | $var = Array( |
---|
866 | // 'text' => $text, |
---|
867 | 'time'=> $texttime, |
---|
868 | 'title'=> $texttitle, |
---|
869 | 'users_status'=>$textstatus, |
---|
870 | 'desc'=> $textdesc, |
---|
871 | 'location'=> "<br><b>Local:</b> ".$textlocation |
---|
872 | ); |
---|
873 | $this->output_template_array($this->link_tpl,'picture','link_text',$var); |
---|
874 | } |
---|
875 | |
---|
876 | if ($viewable) |
---|
877 | { |
---|
878 | $this->link_tpl->parse('picture','link_close',True); |
---|
879 | } |
---|
880 | $str = $this->link_tpl->fp('out','link_pict'); |
---|
881 | $this->link_tpl->set_var('picture',''); |
---|
882 | $this->link_tpl->set_var('out',''); |
---|
883 | // unset($p); |
---|
884 | return $str; |
---|
885 | } |
---|
886 | |
---|
887 | |
---|
888 | function planner_participants($parts) |
---|
889 | { |
---|
890 | static $id2lid; |
---|
891 | |
---|
892 | $names = ''; |
---|
893 | while (list($id,$status) = each($parts)) |
---|
894 | { |
---|
895 | $status = substr($this->bo->get_long_status($status),0,1); |
---|
896 | |
---|
897 | if (!isset($id2lid[$id])) |
---|
898 | { |
---|
899 | $id2lid[$id] = $GLOBALS['phpgw']->common->grab_owner_name($id); |
---|
900 | } |
---|
901 | if (strlen($names)) |
---|
902 | { |
---|
903 | $names .= ",\n"; |
---|
904 | } |
---|
905 | $names .= $id2lid[$id]." ($status)"; |
---|
906 | } |
---|
907 | if($this->debug) |
---|
908 | { |
---|
909 | echo '<!-- Inside participants() : '.$names.' -->'."\n"; |
---|
910 | } |
---|
911 | return $names; |
---|
912 | } |
---|
913 | |
---|
914 | |
---|
915 | } |
---|
916 | |
---|
917 | |
---|
918 | |
---|
919 | ?> |
---|