]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/Calendar/CalendarDisplay.php
Release 6.5.0
[Github/sugarcrm.git] / modules / Calendar / CalendarDisplay.php
1 <?php
2 if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
3 /*********************************************************************************
4  * SugarCRM Community Edition is a customer relationship management program developed by
5  * SugarCRM, Inc. Copyright (C) 2004-2012 SugarCRM Inc.
6  * 
7  * This program is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU Affero General Public License version 3 as published by the
9  * Free Software Foundation with the addition of the following permission added
10  * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
11  * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
12  * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
13  * 
14  * This program is distributed in the hope that it will be useful, but WITHOUT
15  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16  * FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more
17  * details.
18  * 
19  * You should have received a copy of the GNU Affero General Public License along with
20  * this program; if not, see http://www.gnu.org/licenses or write to the Free
21  * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22  * 02110-1301 USA.
23  * 
24  * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
25  * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
26  * 
27  * The interactive user interfaces in modified source and object code versions
28  * of this program must display Appropriate Legal Notices, as required under
29  * Section 5 of the GNU Affero General Public License version 3.
30  * 
31  * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
32  * these Appropriate Legal Notices must retain the display of the "Powered by
33  * SugarCRM" logo. If the display of the logo is not reasonably feasible for
34  * technical reasons, the Appropriate Legal Notices must display the words
35  * "Powered by SugarCRM".
36  ********************************************************************************/
37
38
39
40
41 class CalendarDisplay {
42
43         /**
44          * colors of items on calendar
45          */
46         public $activity_colors = array(
47                 'Meetings' => array(
48                         'border' => '#1C5FBD',
49                         'body' => '#D2E5FC',
50                 ),
51                 'Calls' => array(
52                         'border' => '#DE4040',
53                         'body' => '#FCDCDC',
54                 ),
55                 'Tasks' => array(
56                         'border' => '#015900',
57                         'body' => '#B1F5AE',
58                 ),
59         );
60
61         /**
62          * constructor
63          * @param Calendar $cal
64          * @param string $dashlet_id for dashlet mode
65          */
66         function __construct(Calendar $cal,$dashlet_id = ""){
67                 $this->cal = $cal;
68                 $this->dashlet_id = $dashlet_id;
69         }
70
71         /**
72          * main displaying function of Calendar
73          */
74         public function display(){
75
76                 global $timedate;
77
78                 $cal = &$this->cal;
79                 $ss = new Sugar_Smarty();
80
81                 $ss->assign('APP',$GLOBALS['app_strings']);
82                 $ss->assign('APPLIST',$GLOBALS['app_list_strings']);
83                 $ss->assign('MOD',$GLOBALS['cal_strings']);
84
85                 $ss->assign('view',$cal->view);
86                 $ss->assign('style',$cal->style);
87                 $ss->assign('t_step',$cal->time_step);
88                 $ss->assign('current_user_id',$GLOBALS['current_user']->id);
89                 $ss->assign('current_user_name',$GLOBALS['current_user']->name);
90                 $ss->assign('time_format',$GLOBALS['timedate']->get_user_time_format());
91                 $ss->assign('enable_repeat',$this->cal->enable_repeat);
92                 $ss->assign('items_draggable',SugarConfig::getInstance()->get('calendar.items_draggable',true));
93                 $ss->assign('items_resizable',SugarConfig::getInstance()->get('calendar.items_resizable',true));
94                 $ss->assign('cells_per_day',$cal->cells_per_day);
95
96                 $ss->assign('dashlet',$cal->dashlet);
97                 $ss->assign('grid_start_ts',intval($cal->grid_start_ts));
98                 
99                 $ss->assign('year', $cal->date_time->format('Y'));
100                 $ss->assign('month', $cal->date_time->format('m'));
101                 $ss->assign('day', $cal->date_time->format('d'));
102
103                 $ss->assign('CALENDAR_FORMAT',$GLOBALS['timedate']->get_cal_date_format());
104                 $ss->assign('CALENDAR_FDOW',$GLOBALS['current_user']->get_first_day_of_week());
105
106
107                 if($cal->style == "basic"){
108                         switch($cal->view){
109                                 case "day":
110                                         $height = 250; break;
111                                 case "week":
112                                         $height = 250; break;
113                                 case "shared":
114                                         $height = 100; break;
115                                 default:
116                                         $height = 80; break;
117                         }
118                 }else{
119                         $height = 20;
120                 }
121                 $ss->assign('basic_min_height',$height);
122                 
123                 $ss->assign('isPrint', $this->cal->isPrint() ? 'true': 'false');
124
125
126                 if(count($cal->shared_ids)){
127                         $ss->assign('shared_ids',$cal->shared_ids);
128                         $ss->assign('shared_users_count',count($cal->shared_ids));
129                 }
130                 $ss->assign('activity_colors',$this->activity_colors);
131
132                 $ss->assign('scroll_slot',$this->cal->scroll_slot);
133
134                 $ss->assign('editview_width',SugarConfig::getInstance()->get('calendar.editview_width',800));
135                 $ss->assign('editview_height',SugarConfig::getInstance()->get('calendar.editview_height',600));
136
137                 $ss->assign('a_str',json_encode($cal->items));
138
139                 $ss->assign('sugar_body_only',(isset($_REQUEST['to_pdf']) && $_REQUEST['to_pdf'] || isset($_REQUEST['sugar_body_only']) && $_REQUEST['sugar_body_only']));
140                 require_once('include/json_config.php');
141                 global $json;
142                 $json = getJSONobj();
143                 $json_config = new json_config();
144                 $ss->assign('GRjavascript',$json_config->get_static_json_server(false, true, 'Meetings'));
145
146                 // form
147                 $user_default_date_start  = $timedate->asUser($timedate->getNow());
148                 $ss->assign('user_default_date_start',$user_default_date_start);
149                 // end form
150
151                 if($_REQUEST['module'] == "Calendar"){
152                         $this->load_settings_template($ss);
153                         $settings = "custom/modules/Calendar/tpls/settings.tpl";
154                         if(!file_exists($settings))
155                                 $settings = "modules/Calendar/tpls/settings.tpl";
156                         $ss->assign("settings",$settings);
157                 }
158
159                 $main = "custom/modules/Calendar/tpls/main.tpl";
160                 if(!file_exists($main))
161                         $main = "modules/Calendar/tpls/main.tpl";
162
163                 $form_tpl = "custom/modules/Calendar/tpls/form.tpl";
164                 if(!file_exists($form_tpl))
165                         $form_tpl = "modules/Calendar/tpls/form.tpl";
166                 $ss->assign("form",$form_tpl);
167
168                 if($this->cal->enable_repeat){
169                         $repeat_tpl = "custom/modules/Calendar/tpls/repeat.tpl";
170                         if(!file_exists($repeat_tpl))
171                                 $repeat_tpl = "modules/Calendar/tpls/repeat.tpl";
172                         $ss->assign("repeat",$repeat_tpl);
173
174                         $repeat_intervals = array();
175                         for($i = 1; $i <= 30; $i++)
176                                 $repeat_intervals[$i] = $i;
177                         $ss->assign("repeat_intervals",$repeat_intervals);
178
179
180                         $fdow = $GLOBALS['current_user']->get_first_day_of_week();
181                         $dow = array();
182                         for($i = $fdow; $i < $fdow + 7; $i++){
183                                 $day_index = $i % 7;
184                                 $dow[] = array("index" => $day_index , "label" => $GLOBALS['app_list_strings']['dom_cal_day_short'][$day_index + 1]);
185                         }
186                         $ss->assign("dow",$dow);
187
188                 }
189
190
191
192                 echo $ss->fetch($main);
193
194                 // grid
195                 $grid = new CalendarGrid($cal);
196                 echo $grid->display();
197                 // end grid
198         }
199
200         /**
201          * load settings popup template
202          */
203         protected function load_settings_template(&$ss){
204
205                 list($d_start_hour,$d_start_min) =  explode(":",$this->cal->day_start_time);
206                 list($d_end_hour,$d_end_min) =  explode(":",$this->cal->day_end_time);
207
208                 require_once("include/utils.php");
209                 global $app_strings,$app_list_strings,$beanList;
210                 global $timedate;
211
212                 $user_default_date_start  = $timedate->asUser($timedate->getNow());
213                 if(!isset($time_separator))
214                         $time_separator = ":";
215                 $date_format = $timedate->get_cal_date_format();
216                 $time_format = $timedate->get_user_time_format();
217                 $TIME_FORMAT = $time_format;
218                 $t23 = strpos($time_format, '23') !== false ? '%H' : '%I';
219                 if(!isset($match[2]) || $match[2] == '') {
220                         $CALENDAR_FORMAT = $date_format . ' ' . $t23 . $time_separator . "%M";
221                 }else{
222                         $pm = $match[2] == "pm" ? "%P" : "%p";
223                         $CALENDAR_FORMAT = $date_format . ' ' . $t23 . $time_separator . "%M" . $pm;
224                 }
225                 $hours_arr = array ();
226                 $num_of_hours = 24;
227                 $start_at = 0;
228                 $TIME_MERIDIEM = "";
229                 $time_pref = $timedate->get_time_format();
230                 $start_m = "";
231                 if(strpos($time_pref, 'a') || strpos($time_pref, 'A')){
232                         $num_of_hours = 12;
233                         $start_at = 1;
234                         $start_m = 'am';
235                         if($d_start_hour == 0){
236                                 $d_start_hour = 12;
237                                 $start_m = 'am';
238                         }else
239                                 if($d_start_hour == 12)
240                                         $start_m = 'pm';
241                         if($d_start_hour > 12){
242                                 $d_start_hour = $d_start_hour - 12;
243                                 $start_m = 'pm';
244                         }
245                         $end_m = 'am';
246                         if($d_end_hour == 0){
247                                 $d_end_hour = 12;
248                                 $end_m = 'am';
249                         }else
250                                 if($d_end_hour == 12)
251                                         $end_m = 'pm';
252
253                         if($d_end_hour > 12){
254                                 $d_end_hour = $d_end_hour - 12;
255                                 $end_m = 'pm';
256                         }
257                         if(strpos($time_pref, 'A')){
258                                 $start_m = strtoupper($start_m);
259                                 $end_m = strtoupper($end_m);
260                         }
261                         $options = strpos($time_pref, 'a') ? $app_list_strings['dom_meridiem_lowercase'] : $app_list_strings['dom_meridiem_uppercase'];
262                         $TIME_START_MERIDIEM = get_select_options_with_id($options, $start_m);
263                         $TIME_END_MERIDIEM = get_select_options_with_id($options, $end_m);
264                         $TIME_START_MERIDIEM = "<select id='day_start_meridiem' name='day_start_meridiem' tabindex='2'>".$TIME_START_MERIDIEM."</select>";
265                         $TIME_END_MERIDIEM = "<select id='day_end_meridiem' name='day_end_meridiem' tabindex='2'>".$TIME_END_MERIDIEM."</select>";
266                 }else{
267                         $TIME_START_MERIDIEM = $TIME_END_MERIDIEM = "";
268                 }
269                 for($i = $start_at; $i <= $num_of_hours; $i ++){
270                         $i = $i."";
271                         if (strlen($i) == 1)
272                                 $i = "0".$i;
273                         $hours_arr[$i] = $i;
274                 }
275                 $TIME_START_HOUR_OPTIONS = get_select_options_with_id($hours_arr, $d_start_hour);
276                 $TIME_START_MINUTES_OPTIONS = get_select_options_with_id(array('0'=>'00','15'=>'15','30'=>'30','45'=>'45'), $d_start_min);
277                 $TIME_END_HOUR_OPTIONS = get_select_options_with_id($hours_arr, $d_end_hour);
278                 $TIME_END_MINUTES_OPTIONS = get_select_options_with_id(array('0'=>'00','15'=>'15','30'=>'30','45'=>'45'), $d_end_min);
279
280                 $displayTimeslots = $GLOBALS['current_user']->getPreference('calendar_display_timeslots');
281                 if(is_null($displayTimeslots)) {
282                         $displayTimeslots = SugarConfig::getInstance()->get('calendar.display_timeslots', true);
283                 }
284
285                 $ss->assign('week',$_REQUEST['week']);
286                 $ss->assign('display_timeslots', $displayTimeslots);
287                 $ss->assign('show_calls',$this->cal->show_calls);
288                 $ss->assign('show_tasks',$this->cal->show_tasks);
289                 $ss->assign('TIME_START_HOUR_OPTIONS',$TIME_START_HOUR_OPTIONS);
290                 $ss->assign('TIME_START_MINUTES_OPTIONS',$TIME_START_MINUTES_OPTIONS);
291                 $ss->assign('TIME_START_MERIDIEM',$TIME_START_MERIDIEM);
292                 $ss->assign('TIME_END_HOUR_OPTIONS',$TIME_END_HOUR_OPTIONS);
293                 $ss->assign('TIME_END_MINUTES_OPTIONS',$TIME_END_MINUTES_OPTIONS);
294                 $ss->assign('TIME_END_MERIDIEM',$TIME_END_MERIDIEM);
295         }
296
297         /**
298          * Get date info string (legacy from old calendar)
299          * @return string
300          */
301         public function get_date_info($view, $date_time){
302                 $str = "";
303
304                 global $current_user;
305                 $dateFormat = $current_user->getUserDateTimePreferences();
306
307                 if($view == 'month'){
308                         for($i=0; $i<strlen($dateFormat['date']); $i++){
309                                 switch($dateFormat['date']{$i}){
310                                         case "Y":
311                                                 $str .= " ".$date_time->year;
312                                                 break;
313                                         case "m":
314                                                 $str .= " ".$date_time->get_month_name();
315                                                 break;
316                                 }
317                         }
318                 }else
319                         if($view == 'week' || $view == 'shared') {
320                                 $first_day = $date_time;
321
322                                 $first_day = CalendarUtils::get_first_day_of_week($date_time);
323                                 $last_day = $first_day->get("+6 days");
324
325                                 for($i=0; $i<strlen($dateFormat['date']); $i++) {
326                                         switch($dateFormat['date']{$i}){
327                                                 case "Y":
328                                                         $str .= " ".$first_day->year;
329                                                         break;
330                                                 case "m":
331                                                         $str .= " ".$first_day->get_month_name();
332                                                         break;
333                                                 case "d":
334                                                         $str .= " ".$first_day->get_day();
335                                                         break;
336                                         }
337                                 }
338                                 $str .= " - ";
339                                 for($i=0; $i<strlen($dateFormat['date']); $i++) {
340                                         switch($dateFormat['date']{$i}) {
341                                                 case "Y":
342                                                         $str .= " ".$last_day->year;
343                                                         break;
344                                                 case "m":
345                                                         $str .= " ".$last_day->get_month_name();
346                                                         break;
347                                                 case "d":
348                                                         $str .= " ".$last_day->get_day();
349                                                         break;
350                                         }
351                                 }
352                         }else if($view == 'day'){
353                                         $str .= $date_time->get_day_of_week()." ";
354
355                                         for($i=0; $i<strlen($dateFormat['date']); $i++){
356                                                 switch($dateFormat['date']{$i}){
357                                                         case "Y":
358                                                                 $str .= " ".$date_time->year;
359                                                                 break;
360                                                         case "m":
361                                                                 $str .= " ".$date_time->get_month_name();
362                                                                 break;
363                                                         case "d":
364                                                                 $str .= " ".$date_time->get_day();
365                                                                 break;
366                                                 }
367                                         }
368                         }else if($view == 'year') {
369                                 $str .= $date_time->year;
370                         }else{
371                                 sugar_die("echo_date_info: date not supported");
372                         }
373                 return $str;
374         }
375
376         /**
377          * Get link to next date range
378          * @return string
379          */
380         protected function get_next_calendar(){
381                 global $cal_strings,$image_path;
382                 $str = "";
383                 if($_REQUEST['module'] == "Calendar"){
384                         $str .= "<a href='".ajaxLink("index.php?action=index&module=Calendar&view=".$this->cal->view."&".$this->cal->get_neighbor_date_str("next"))."'>";
385
386                 }else{
387                         $str .= "<a href='#' onclick='return SUGAR.mySugar.retrieveDashlet(\"".$this->dashlet_id."\", \"index.php?module=Home&action=DynamicAction&DynamicAction=displayDashlet&sugar_body_only=1&".$this->cal->get_neighbor_date_str("next")."&id=".$this->dashlet_id."\")'>";
388                 }
389                         $str .= $cal_strings["LBL_NEXT_".strtoupper($this->cal->view)];
390
391                 $str .= "&nbsp;&nbsp;".SugarThemeRegistry::current()->getImage("calendar_next", 'align="absmiddle" border="0"' ,null,null,'.gif', '') . "</a>"; //setting alt tag blank on purpose for 508 compliance
392                 return $str;
393         }
394
395         /**
396          * Get link to previous date range
397          * @return string
398          */
399         protected function get_previous_calendar(){
400                 global $cal_strings,$image_path;
401                 $str = "";
402                 if($_REQUEST['module'] == "Calendar"){
403                         $str .= "<a href='".ajaxLink("index.php?action=index&module=Calendar&view=".$this->cal->view."&".$this->cal->get_neighbor_date_str("previous")."")."'>";
404                 }else{
405                         $str .= "<a href='#' onclick='return SUGAR.mySugar.retrieveDashlet(\"".$this->dashlet_id."\", \"index.php?module=Home&action=DynamicAction&DynamicAction=displayDashlet&sugar_body_only=1&".$this->cal->get_neighbor_date_str("previous")."&id=".$this->dashlet_id."\")'>";
406                 }
407                 $str .= SugarThemeRegistry::current()->getImage('calendar_previous','align="absmiddle" border="0"', null, null, '.gif', ''); //setting alt tag blank on purpose for 508 compliance
408                 $str .= "&nbsp;&nbsp;".$cal_strings["LBL_PREVIOUS_".strtoupper($this->cal->view)] . "</a>";
409                 return $str;
410         }
411
412         /**
413          * display header
414          * @param boolean $controls display ui contol itmes
415          */
416         public function display_calendar_header($controls = true){
417                 global $cal_strings;
418
419                 $ss = new Sugar_Smarty();
420                 $ss->assign("MOD",$cal_strings);
421                 $ss->assign("view",$this->cal->view);
422
423                 $ss->assign('print', $this->cal->isPrint());
424
425                 if($controls){
426                         $current_date = str_pad($this->cal->date_time->month,2,'0',STR_PAD_LEFT)."/".str_pad($this->cal->date_time->day,2,'0',STR_PAD_LEFT)."/".$this->cal->date_time->year;
427
428                         $tabs = array('day', 'week', 'month', 'year', 'shared');
429                         $tabs_params = array();
430                         foreach($tabs as $tab){
431                                 $tabs_params[$tab]['title'] = $cal_strings["LBL_".strtoupper($tab)];
432                                 $tabs_params[$tab]['id'] = $tab . "-tab";
433                                 $tabs_params[$tab]['link'] = "window.location.href='".ajaxLink("index.php?module=Calendar&action=index&view=". $tab . $this->cal->date_time->get_date_str())."'";
434                         }
435                         $ss->assign('controls',$controls);
436                         $ss->assign('tabs',$tabs);
437                         $ss->assign('tabs_params',$tabs_params);
438                         $ss->assign('current_date',$current_date);
439                         $ss->assign('start_weekday',$GLOBALS['current_user']->get_first_day_of_week());
440                         $ss->assign('cal_img',SugarThemeRegistry::current()->getImageURL("jscalendar.gif",false));
441                 }
442
443                 $ss->assign('previous',$this->get_previous_calendar());
444                 $ss->assign('next',$this->get_next_calendar());
445
446                 $ss->assign('date_info',$this->get_date_info($this->cal->view,$this->cal->date_time));
447
448                 $header = "custom/modules/Calendar/tpls/header.tpl";
449                 if(!file_exists($header))
450                         $header = "modules/Calendar/tpls/header.tpl";
451                 echo $ss->fetch($header);
452         }
453
454         /**
455          * display footer
456          */
457         public function display_calendar_footer(){
458                 global $cal_strings;
459
460                 $ss = new Sugar_Smarty();
461                 $ss->assign("MOD",$cal_strings);
462                 $ss->assign("view",$this->cal->view);
463
464                 $ss->assign('previous',$this->get_previous_calendar());
465                 $ss->assign('next',$this->get_next_calendar());
466
467                 $footer = "custom/modules/Calendar/tpls/footer.tpl";
468                 if(!file_exists($footer))
469                         $footer = "modules/Calendar/tpls/footer.tpl";
470                 echo $ss->fetch($footer);
471         }
472
473         /**
474          * display title
475          */
476         public function display_title(){
477                 global $mod_strings;
478                 //Hack to make this 6.5 compatible until this module is converted to MVC
479         echo "<div class='moduleTitle'><h2>". $mod_strings['LBL_MODULE_TITLE'] ."</h2></div>"; 
480         }
481
482         /**
483          * display html used in shared view
484          */
485         public function display_shared_html(){
486                         global $app_strings,$cal_strings,$action;
487
488                         $ss = new Sugar_Smarty();
489                         $ss->assign("APP",$app_strings);
490                         $ss->assign("MOD",$cal_strings);
491                         $ss->assign("UP",SugarThemeRegistry::current()->getImage('uparrow_big', 'border="0" style="margin-bottom: 1px;"', null, null, '.gif', $app_strings['LBL_SORT']));
492                         $ss->assign("DOWN",SugarThemeRegistry::current()->getImage('downarrow_big', 'border="0" style="margin-top: 1px;"', null, null, '.gif', $app_strings['LBL_SORT']));
493
494                         if(!empty($_REQUEST['edit_shared'])){
495                                 $ss->assign("edit_shared",true);
496                         }
497
498
499                         $ss->assign("users_options",get_select_options_with_id(get_user_array(false), $this->cal->shared_ids));
500
501                         $tpl = "modules/Calendar/tpls/shared_users.tpl";
502                         echo $ss->fetch($tpl);
503         }
504
505 }
506
507 ?>