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