]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/Calendar/CalendarDisplay.php
Release 6.4.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-2011 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 class CalendarDisplay { 
40
41         /** 
42          * colors of items on calendar
43          */
44         public $activity_colors = array(
45                 'Meetings' => array(
46                         'border' => '#1C5FBD',
47                         'body' => '#D2E5FC',
48                 ),
49                 'Calls' => array(
50                         'border' => '#DE4040',
51                         'body' => '#FCDCDC',
52                 ),
53                 'Tasks' => array(
54                         'border' => '#015900',
55                         'body' => '#B1F5AE',
56                 ),
57         );
58         
59         /**
60          * constructor
61          * @param Calendar $cal
62          * @param string $dashlet_id for dashlet mode 
63          */
64         function __construct(&$cal,$dashlet_id = ""){
65                 $this->cal = &$cal;
66                 $this->dashlet_id = $dashlet_id;
67         }       
68         
69         /**
70          * main displaying function of Calendar
71          */
72         public function display(){
73         
74                 global $timedate;
75         
76                 $cal = &$this->cal;     
77                 $ss = new Sugar_Smarty();
78         
79                 $ss->assign('APP',$GLOBALS['app_strings']);
80                 $ss->assign('APPLIST',$GLOBALS['app_list_strings']);
81                 $ss->assign('MOD',$GLOBALS['cal_strings']);
82
83                 $ss->assign('view',$cal->view);
84                 $ss->assign('t_step',$cal->time_step);
85                 $ss->assign('current_user_id',$GLOBALS['current_user']->id);
86                 $ss->assign('current_user_name',$GLOBALS['current_user']->name);
87                 $ss->assign('time_format',$GLOBALS['timedate']->get_user_time_format());
88                 $ss->assign('items_draggable',SugarConfig::getInstance()->get('calendar.items_draggable',true));                
89                 $ss->assign('mouseover_expand',SugarConfig::getInstance()->get('calendar.mouseover_expand',true));
90                 $ss->assign('item_text','name');
91                 $ss->assign('cells_per_day',$cal->cells_per_day);
92                 $ss->assign('img_edit_inline',SugarThemeRegistry::current()->getImageURL('edit_inline.gif',false));
93                 $ss->assign('img_view_inline',SugarThemeRegistry::current()->getImageURL('view_inline.gif',false));
94                 $ss->assign('img_close',SugarThemeRegistry::current()->getImageURL('close.gif',false));         
95                 $ss->assign('dashlet',$cal->dashlet);
96                 
97                 $ss->assign('grid_start_ts',$cal->grid_start_ts);
98                 $ss->assign('celcount',$cal->celcount);         
99                 
100                 if(count($cal->shared_ids)){
101                         $ss->assign('shared_ids',$cal->shared_ids);
102                         $ss->assign('shared_users_count',count($cal->shared_ids));
103                 }                               
104                 $ss->assign('activity_colors',$this->activity_colors);  
105                 
106                 $ss->assign('scroll_slot',$this->cal->scroll_slot);     
107                 
108                 $ss->assign('editview_width',SugarConfig::getInstance()->get('calendar.editview_width',800));
109                 $ss->assign('editview_height',SugarConfig::getInstance()->get('calendar.editview_height',600)); 
110                 $ss->assign('a_str',$cal->get_activities_js());
111
112                 $ss->assign('sugar_body_only',(isset($_REQUEST['to_pdf']) && $_REQUEST['to_pdf'] || isset($_REQUEST['sugar_body_only']) && $_REQUEST['sugar_body_only']));
113                 require_once('include/json_config.php');
114                 global $json;
115                 $json = getJSONobj();
116                 $json_config = new json_config();
117                 $ss->assign('GRjavascript',$json_config->get_static_json_server(false, true, 'Meetings'));
118         
119                 // form
120                 $user_default_date_start  = $timedate->asUser($timedate->getNow());
121                 $ss->assign('user_default_date_start',$user_default_date_start);
122                 // end form     
123                 
124                 if($_REQUEST['module'] == "Calendar"){
125                         $this->load_settings_template($ss);
126                         $settings = "custom/modules/Calendar/tpls/settings.tpl";
127                         if(!file_exists($settings))
128                                 $settings = "modules/Calendar/tpls/settings.tpl";
129                         $ss->assign("settings",$settings);                      
130                 }
131         
132                 $main = "custom/modules/Calendar/tpls/main.tpl";
133                 if(!file_exists($main))
134                         $main = "modules/Calendar/tpls/main.tpl";
135                 $form_tpl = "custom/modules/Calendar/tpls/form.tpl";
136                 if(!file_exists($form_tpl))
137                         $form_tpl = "modules/Calendar/tpls/form.tpl";                   
138         
139                 $ss->assign("form",$form_tpl);
140                         
141                 echo $ss->fetch($main); 
142                 
143                 // drid
144                 $grid = new CalendarGrid($cal);
145                 echo $grid->display();
146                 // end grid     
147         }
148         
149         /**
150          * load settings popup template
151          */     
152         protected function load_settings_template(&$ss){        
153                 
154                 list($d_start_hour,$d_start_min) =  explode(":",$this->cal->day_start_time);            
155                 list($d_end_hour,$d_end_min) =  explode(":",$this->cal->day_end_time);  
156
157                 require_once("include/utils.php");
158                 global $app_strings,$app_list_strings,$beanList;
159                 global $timedate;
160                                 
161                 $user_default_date_start  = $timedate->asUser($timedate->getNow());
162                 if(!isset($time_separator))
163                         $time_separator = ":";  
164                 $date_format = $timedate->get_cal_date_format();
165                 $time_format = $timedate->get_user_time_format();
166                 $TIME_FORMAT = $time_format;      
167                 $t23 = strpos($time_format, '23') !== false ? '%H' : '%I';
168                 if(!isset($match[2]) || $match[2] == '') {
169                         $CALENDAR_FORMAT = $date_format . ' ' . $t23 . $time_separator . "%M";
170                 }else{
171                         $pm = $match[2] == "pm" ? "%P" : "%p";
172                         $CALENDAR_FORMAT = $date_format . ' ' . $t23 . $time_separator . "%M" . $pm;
173                 }
174                 $hours_arr = array ();
175                 $num_of_hours = 24;
176                 $start_at = 0;
177                 $TIME_MERIDIEM = "";
178                 $time_pref = $timedate->get_time_format();
179                 $start_m = "";          
180                 if(strpos($time_pref, 'a') || strpos($time_pref, 'A')){
181                         $num_of_hours = 12;
182                         $start_at = 1;                  
183                         $start_m = 'am';
184                         if($d_start_hour == 0){
185                                 $d_start_hour = 12;
186                                 $start_m = 'am';
187                         }else
188                                 if($d_start_hour == 12)
189                                         $start_m = 'pm';
190                         if($d_start_hour > 12){                         
191                                 $d_start_hour = $d_start_hour - 12;
192                                 $start_m = 'pm';
193                         }                               
194                         $end_m = 'am';
195                         if($d_end_hour == 0){
196                                 $d_end_hour = 12;
197                                 $end_m = 'am';
198                         }else
199                                 if($d_end_hour == 12)
200                                         $end_m = 'pm';                          
201                                         
202                         if($d_end_hour > 12){                           
203                                 $d_end_hour = $d_end_hour - 12;
204                                 $end_m = 'pm';
205                         }                               
206                         if(strpos($time_pref, 'A')){
207                                 $start_m = strtoupper($start_m);
208                                 $end_m = strtoupper($end_m);
209                         }
210                         $options = strpos($time_pref, 'a') ? $app_list_strings['dom_meridiem_lowercase'] : $app_list_strings['dom_meridiem_uppercase'];
211                         $TIME_START_MERIDIEM = get_select_options_with_id($options, $start_m);  
212                         $TIME_END_MERIDIEM = get_select_options_with_id($options, $end_m);  
213                         $TIME_START_MERIDIEM = "<select id='day_start_meridiem' name='day_start_meridiem' tabindex='2'>".$TIME_START_MERIDIEM."</select>";
214                         $TIME_END_MERIDIEM = "<select id='day_end_meridiem' name='day_end_meridiem' tabindex='2'>".$TIME_END_MERIDIEM."</select>";                      
215                 }else{
216                         $TIME_START_MERIDIEM = $TIME_END_MERIDIEM = "";
217                 }       
218                 for($i = $start_at; $i <= $num_of_hours; $i ++){
219                         $i = $i."";
220                         if (strlen($i) == 1)
221                                 $i = "0".$i;                    
222                         $hours_arr[$i] = $i;
223                 }
224                 $TIME_START_HOUR_OPTIONS = get_select_options_with_id($hours_arr, $d_start_hour);
225                 $TIME_START_MINUTES_OPTIONS = get_select_options_with_id(array('0'=>'00','15'=>'15','30'=>'30','45'=>'45'), $d_start_min);
226                 $TIME_END_HOUR_OPTIONS = get_select_options_with_id($hours_arr, $d_end_hour);
227                 $TIME_END_MINUTES_OPTIONS = get_select_options_with_id(array('0'=>'00','15'=>'15','30'=>'30','45'=>'45'), $d_end_min);
228                 
229                 $ss->assign('day',$_REQUEST['day']);
230                 $ss->assign('week',$_REQUEST['week']);
231                 $ss->assign('month',$_REQUEST['month']);
232                 $ss->assign('year',$_REQUEST['year']);
233                 $ss->assign('TIME_START_HOUR_OPTIONS',$TIME_START_HOUR_OPTIONS);                
234                 $ss->assign('TIME_START_MINUTES_OPTIONS',$TIME_START_MINUTES_OPTIONS);
235                 $ss->assign('TIME_START_MERIDIEM',$TIME_START_MERIDIEM);
236                 $ss->assign('TIME_END_HOUR_OPTIONS',$TIME_END_HOUR_OPTIONS);            
237                 $ss->assign('TIME_END_MINUTES_OPTIONS',$TIME_END_MINUTES_OPTIONS);
238                 $ss->assign('TIME_END_MERIDIEM',$TIME_END_MERIDIEM);
239                 $ss->assign('show_calls',$this->cal->show_calls);
240                 $ss->assign('show_tasks',$this->cal->show_tasks);
241         }
242         
243         /** 
244          * Get date info string (legacy from old calendar)
245          * @return string
246          */
247         public function get_date_info($view, $date_time){
248                 $str = "";
249
250                 global $current_user;
251                 $dateFormat = $current_user->getUserDateTimePreferences();
252
253                 if($view == 'month'){
254                         for($i=0; $i<strlen($dateFormat['date']); $i++){
255                                 switch($dateFormat['date']{$i}){
256                                         case "Y":
257                                                 $str .= " ".$date_time->year;
258                                                 break;
259                                         case "m":
260                                                 $str .= " ".$date_time->get_month_name();
261                                                 break;
262                                 }
263                         }
264                 }else
265                         if($view == 'week' || $view == 'shared') {
266                                 $first_day = $date_time;
267                                 
268                                 $first_day = CalendarUtils::get_first_day_of_week($date_time);                          
269                                 $last_day = $first_day->get("+6 days");                         
270
271                                 for($i=0; $i<strlen($dateFormat['date']); $i++) {
272                                         switch($dateFormat['date']{$i}){
273                                                 case "Y":
274                                                         $str .= " ".$first_day->year;
275                                                         break;
276                                                 case "m":
277                                                         $str .= " ".$first_day->get_month_name();
278                                                         break;
279                                                 case "d":
280                                                         $str .= " ".$first_day->get_day();
281                                                         break;
282                                         }
283                                 }
284                                 $str .= " - ";
285                                 for($i=0; $i<strlen($dateFormat['date']); $i++) {
286                                         switch($dateFormat['date']{$i}) {
287                                                 case "Y":
288                                                         $str .= " ".$last_day->year;
289                                                         break;
290                                                 case "m":
291                                                         $str .= " ".$last_day->get_month_name();
292                                                         break;
293                                                 case "d":
294                                                         $str .= " ".$last_day->get_day();
295                                                         break;
296                                         }
297                                 }
298                         }else if($view == 'day'){
299                                         $str .= $date_time->get_day_of_week()." ";
300
301                                         for($i=0; $i<strlen($dateFormat['date']); $i++){
302                                                 switch($dateFormat['date']{$i}){
303                                                         case "Y":
304                                                                 $str .= " ".$date_time->year;
305                                                                 break;
306                                                         case "m":
307                                                                 $str .= " ".$date_time->get_month_name();
308                                                                 break;
309                                                         case "d":
310                                                                 $str .= " ".$date_time->get_day();
311                                                                 break;
312                                                 }
313                                         }
314                         }else if($view == 'year') {
315                                 $str .= $date_time->year;
316                         }else{
317                                 sugar_die("echo_date_info: date not supported");
318                         }
319                 return $str;
320         }
321         
322         /**
323          * Get link to next date range
324          * @return string
325          */
326         protected function get_next_calendar(){ 
327                 global $cal_strings,$image_path;
328                 $str = "";
329                 if($_REQUEST['module'] == "Calendar"){
330                         $str .= "<a href='".ajaxLink("index.php?action=index&module=Calendar&view=".$this->cal->view."&".$this->cal->get_neighbor_date_str("next"))."'>";
331
332                 }else{
333                         $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."\")'>";
334                 }
335                         $str .= $cal_strings["LBL_NEXT_".strtoupper($this->cal->view)]; 
336
337                 $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
338                 return $str;
339         }
340         
341         /**
342          * Get link to previous date range
343          * @return string
344          */
345         protected function get_previous_calendar(){
346                 global $cal_strings,$image_path;
347                 $str = "";
348                 if($_REQUEST['module'] == "Calendar"){
349                         $str .= "<a href='".ajaxLink("index.php?action=index&module=Calendar&view=".$this->cal->view."&".$this->cal->get_neighbor_date_str("previous")."")."'>";
350                 }else{
351                         $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."\")'>";
352                 }
353                 $str .= SugarThemeRegistry::current()->getImage('calendar_previous','align="absmiddle" border="0"', null, null, '.gif', ''); //setting alt tag blank on purpose for 508 compliance
354                 $str .= "&nbsp;&nbsp;".$cal_strings["LBL_PREVIOUS_".strtoupper($this->cal->view)] . "</a>";
355                 return $str;
356         }
357
358         /**
359          * display header
360          * @param boolean $controls display ui contol elements 
361          */
362         public function display_calendar_header($controls = true){
363                 global $cal_strings;
364                 
365                 $ss = new Sugar_Smarty();
366                 $ss->assign("MOD",$cal_strings);
367                 $ss->assign("view",$this->cal->view);
368                 
369                 if($controls){
370                         $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;
371                                                         
372                         $tabs = array('day', 'week', 'month', 'year', 'shared');
373                         $tabs_params = array();         
374                         foreach($tabs as $tab){ 
375                                 $tabs_params[$tab]['title'] = $cal_strings["LBL_".strtoupper($tab)];
376                                 $tabs_params[$tab]['id'] = $tab . "_tab";
377                                 $tabs_params[$tab]['link'] = "window.location.href='".ajaxLink("index.php?module=Calendar&action=index&view=". $tab . $this->cal->date_time->get_date_str())."'";
378                         }               
379                         $ss->assign('controls',$controls);
380                         $ss->assign('tabs',$tabs);
381                         $ss->assign('tabs_params',$tabs_params);
382                         $ss->assign('current_date',$current_date);
383                         $ss->assign('start_weekday',$GLOBALS['current_user']->get_first_day_of_week());
384                         $ss->assign('cal_img',SugarThemeRegistry::current()->getImageURL("jscalendar.gif",false));              
385                 }
386         
387                 $ss->assign('previous',$this->get_previous_calendar());
388                 $ss->assign('next',$this->get_next_calendar());
389                 
390                 $ss->assign('date_info',$this->get_date_info($this->cal->view,$this->cal->date_time));
391                 
392                 $header = "custom/modules/Calendar/tpls/header.tpl";
393                 if(!file_exists($header))
394                         $header = "modules/Calendar/tpls/header.tpl";   
395                 echo $ss->fetch($header);
396         }
397
398         /**
399          * display footer
400          */
401         public function display_calendar_footer(){
402                 global $cal_strings;
403                 
404                 $ss = new Sugar_Smarty();
405                 $ss->assign("MOD",$cal_strings);
406                 $ss->assign("view",$this->cal->view);   
407                 
408                 $ss->assign('previous',$this->get_previous_calendar());
409                 $ss->assign('next',$this->get_next_calendar()); 
410                 
411                 $footer = "custom/modules/Calendar/tpls/footer.tpl";
412                 if(!file_exists($footer))
413                         $footer = "modules/Calendar/tpls/footer.tpl";   
414                 echo $ss->fetch($footer);
415         }
416
417         /**
418          * display title
419          */
420         public function display_title(){
421                 global $mod_strings;            
422                 echo get_module_title("Calendar","<span class='pointer'>&raquo;</span>".$mod_strings['LBL_MODULE_TITLE'], false);
423         }
424         
425         /**
426          * display html used in shared view
427          */
428         public function display_shared_html(){
429                         global $app_strings,$cal_strings,$action;                       
430                                                         
431                         $ss = new Sugar_Smarty();
432                         $ss->assign("APP",$app_strings);
433                         $ss->assign("MOD",$cal_strings);
434                         $ss->assign("UP",SugarThemeRegistry::current()->getImage('uparrow_big', 'border="0" style="margin-bottom: 1px;"', null, null, '.gif', $app_strings['LBL_SORT']));
435                         $ss->assign("DOWN",SugarThemeRegistry::current()->getImage('downarrow_big', 'border="0" style="margin-top: 1px;"', null, null, '.gif', $app_strings['LBL_SORT']));
436                         
437                         if(empty($_REQUEST['edit_shared'])){
438                                 $ss->assign("style","display: none");
439                         }
440                         
441                         
442                         $ss->assign("users_options",get_select_options_with_id(get_user_array(false), $this->cal->shared_ids));
443                         
444                         $tpl = "modules/Calendar/tpls/shared_users.tpl";        
445                         echo $ss->fetch($tpl);
446         }       
447         
448 }
449
450 ?>