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.
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.
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
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
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.
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.
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 ********************************************************************************/
44 protected $cal; // Calendar object
45 protected $today_ts; // timestamp of today
46 protected $weekday_names; // string array of names of week days
47 protected $startday; // first day of week
48 protected $scrollable; // srolling in calendar
49 protected $time_step = 30; // time step
50 protected $time_format; // user time format
51 protected $date_time_format; // user date time format
52 protected $scroll_height; // height of scrollable div
56 * @param Calendar $cal
58 function __construct(&$cal){
61 $today = $GLOBALS['timedate']->getNow(true)->get_day_begin();
62 $this->today_ts = $today->format('U') + $today->getOffset();
63 $this->startday = $current_user->get_first_day_of_week();
65 $weekday_names = array();
66 for($i = 0; $i < 7; $i++){
67 $j = $i + $this->startday;
70 $weekday_names[$i] = $GLOBALS['app_list_strings']['dom_cal_day_short'][$j+1];
73 $this->weekday_names = $weekday_names;
75 $this->scrollable = false;
76 if(in_array($this->cal->view,array('day','week'))){
77 $this->scrollable = true;
78 if($this->cal->time_step < 30)
79 $this->scroll_height = 480;
81 $this->scroll_height = $this->cal->celcount * 15 + 1;
84 $this->time_step = $this->cal->time_step;
85 $this->time_format = $GLOBALS['timedate']->get_time_format();
86 $this->date_time_format = $GLOBALS['timedate']->get_date_time_format();
91 /** Get html of calendar grid
94 public function display(){
95 $action = "display_".strtolower($this->cal->view);
96 return $this->$action();
99 /** Get html of time column
100 * @param integer $start timestamp
103 protected function get_time_column($start){
105 $head_content = " ";
106 if($this->cal->view == 'month'){
107 if($this->startday == 0)
111 $head_content = "<a href='".ajaxLink("index.php?module=Calendar&action=index&view=week&hour=0&day=".$GLOBALS['timedate']->fromTimestamp($start)->format('j')."&month=".$GLOBALS['timedate']->fromTimestamp($start)->format('n')."&year=".$GLOBALS['timedate']->fromTimestamp($start)->format('Y'))."'>".$GLOBALS['timedate']->fromTimestamp($start + $wf*3600*24)->format('W')."</a>";
113 $str .= "<div class='left_time_col'>";
114 if(!$this->scrollable)
115 $str .= "<div class='day_head'>".$head_content."</div>";
116 for($i = 0; $i < 24; $i++){
117 for($j = 0; $j < 60; $j += $this->time_step){
120 $innerText = $GLOBALS['timedate']->fromTimestamp($start + $i * 3600)->format($this->time_format);
122 $innerText = " ";
124 if($j == 60 - $this->time_step && $this->time_step < 60){
125 $class = " odd_border";
129 if($this->scrollable || !$this->check_owt($i,$j,$this->cal->d_start_minutes,$this->cal->d_end_minutes))
130 $str .= "<div class='left_cell".$class."'>".$innerText."</div>";
138 * Get html of day slots column
139 * @param integer $start timestamp
140 * @param integer $day number of day in week
141 * @param string $prefix prefix for id of timeslot used in shared view
144 protected function get_day_column($start,$day = 0,$prefix = ""){
147 $str .= "<div class='day_col'>";
148 $str .= $this->get_day_head($start,$day);
149 for($i = 0; $i < 24; $i++){
150 for($j = 0; $j < 60; $j += $this->time_step){
151 $timestr = $GLOBALS['timedate']->fromTimestamp($curr_time)->format($this->time_format);
152 if($j == 60 - $this->time_step && $this->time_step < 60){
153 $class = " odd_border";
157 if($this->scrollable || !$this->check_owt($i,$j,$this->cal->d_start_minutes,$this->cal->d_end_minutes))
158 $str .= "<div id='t_".$curr_time.$prefix."' class='slot".$class."' time='".$timestr."' datetime='".$GLOBALS['timedate']->fromTimestamp($curr_time)->format($this->date_time_format)."'></div>";
159 $curr_time += $this->time_step*60;
167 * Get html of day head
168 * @param integer $start timestamp
169 * @param integer $day number of day in week
170 * @param bulean $force force display header
173 protected function get_day_head($start,$day = 0,$force = false){
175 if(!$this->scrollable || $force){
177 if($this->today_ts == $start)
178 $headstyle = " today";
179 $str .= "<div class='day_head".$headstyle."'><a href='".ajaxLink("index.php?module=Calendar&action=index&view=day&hour=0&day=".$GLOBALS['timedate']->fromTimestamp($start)->format('j')."&month=".$GLOBALS['timedate']->fromTimestamp($start)->format('n')."&year=".$GLOBALS['timedate']->fromTimestamp($start)->format('Y'))."'>".$this->weekday_names[$day]." ".$GLOBALS['timedate']->fromTimestamp($start)->format('d')."</a></div>";
185 * Get true if out of working day
186 * @param integer $i hours
187 * @param integer $j minutes
188 * @param integer $r_start start of working day in minutes
189 * @param integer $r_end end of working day in minutes
192 protected function check_owt($i,$j,$r_start,$r_end){
193 if($i*60+$j < $r_start || $i*60+$j >= $r_end)
198 * Get html of week calendar grid
201 protected function display_week(){
203 $current_date = $this->cal->date_time;
204 $week_start = CalendarUtils::get_first_day_of_week($current_date);
205 $week_start_ts = $week_start->format('U') + $week_start->getOffset(); // convert to timestamp, ignore tz
208 $str .= "<div id='cal-grid' style='visibility: hidden;'>";
210 $str .= "<div style='overflow-y: hidden;'>";
211 $str .= "<div class='left_time_col'>";
212 $str .= "<div class='day_head'> </div>";
214 $str .= "<div class='week_block'>";
215 for($d = 0; $d < 7; $d++){
216 $curr_time = $week_start_ts + $d*86400;
217 $str .= "<div class='day_col'>";
218 $str .= $this->get_day_head($curr_time,$d,true);
224 $str .= "<div id='cal-scrollable' style='clear: both; height: ".$this->scroll_height ."px;'>";
225 $str .= $this->get_time_column($week_start_ts);
226 $str .= "<div class='week_block'>";
227 for($d = 0; $d < 7; $d++){
228 $curr_time = $week_start_ts + $d*86400;
229 $str .= $this->get_day_column($curr_time);
240 * Get html of day calendar grid
243 protected function display_day(){
245 $current_date = $this->cal->date_time;
246 $day_start_ts = $current_date->format('U') + $current_date->getOffset(); // convert to timestamp, ignore tz
250 $str .= "<div id='cal-grid' style=' min-width: 300px; visibility: hidden;'>";
251 $str .= "<div id='cal-scrollable' style='height: ".$this->scroll_height ."px;'>";
252 $str .= $this->get_time_column($day_start_ts);
254 $curr_time = $day_start_ts + $d*86400;
255 $str .= "<div class='week_block'>";
256 $str .= $this->get_day_column($curr_time);
265 * Get html of month calendar grid
268 protected function display_month(){
270 $current_date = $this->cal->date_time;
271 $month_start = $current_date->get_day_by_index_this_month(0);
272 $month_end = $month_start->get("+".$month_start->format('t')." days");
273 $week_start = CalendarUtils::get_first_day_of_week($month_start);
274 $week_start_ts = $week_start->format('U') + $week_start->getOffset(); // convert to timestamp, ignore tz
275 $month_end_ts = $month_end->format('U') + $month_end->getOffset();
278 $str .= "<div id='cal-grid' style='visibility: hidden;'>";
279 $curr_time_global = $week_start_ts;
281 while($curr_time_global < $month_end_ts){
282 $str .= $this->get_time_column($curr_time_global);
283 $str .= "<div class='week_block'>";
284 for($d = 0; $d < 7; $d++){
285 $curr_time = $week_start_ts + $d*86400 + $w*60*60*24*7;
286 $str .= $this->get_day_column($curr_time,$d);
289 $str .= "<div style='clear: left;'></div>";
290 $curr_time_global += 60*60*24*7;
299 * Get html of week shared grid
302 protected function display_shared(){
304 $current_date = $this->cal->date_time;
305 $week_start = CalendarUtils::get_first_day_of_week($current_date);
306 $week_start_ts = $week_start->format('U') + $week_start->getOffset(); // convert to timestamp, ignore tz
309 $str .= "<div id='cal-grid' style='visibility: hidden;'>";
312 $shared_user = new User();
313 foreach($this->cal->shared_ids as $member_id){
315 $user_number_str = "_".$user_number;
317 $shared_user->retrieve($member_id);
318 $str .= "<div style='clear: both;'></div>";
319 $str .= "<div class='monthCalBody'><h5 class='calSharedUser'>".$shared_user->full_name."</h5></div>";
320 $str .= "<div user_id='".$member_id."' user_name='".$shared_user->user_name."'>";
322 $str .= $this->get_time_column($week_start_ts);
323 $str .= "<div class='week_block'>";
324 for($d = 0; $d < 7; $d++){
325 $curr_time = $week_start_ts + $d*86400;
326 $str .= $this->get_day_column($curr_time,$d,$user_number_str);
338 * Get html of year calendar
341 protected function display_year(){
343 $weekEnd1 = 0 - $this->startday;
344 $weekEnd2 = -1 - $this->startday;
350 $year_start = $GLOBALS['timedate']->fromString($this->cal->date_time->year.'-01-01');
353 $str .= '<table id="daily_cal_table" cellspacing="1" cellpadding="0" border="0" width="100%">';
355 for($m = 0; $m < 12; $m++){
357 $month_start = $year_start->get("+".$m." months");
358 $month_start_ts = $month_start->format('U') + $month_start->getOffset();
359 $month_end = $month_start->get("+".$month_start->format('t')." days");
360 $week_start = CalendarUtils::get_first_day_of_week($month_start);
361 $week_start_ts = $week_start->format('U') + $week_start->getOffset(); // convert to timestamp, ignore tz
362 $month_end_ts = $month_end->format('U') + $month_end->getOffset();
363 $table_id = "daily_cal_table".$m; //bug 47471
367 $str .= '<td class="yearCalBodyMonth" align="center" valign="top" scope="row">';
368 $str .= '<a class="yearCalBodyMonthLink" href="'.ajaxLink('index.php?module=Calendar&action=index&view=month&&hour=0&day=1&month='.($m+1).'&year='.$GLOBALS['timedate']->fromTimestamp($month_start_ts)->format('Y')).'">'.$GLOBALS['app_list_strings']['dom_cal_month_long'][$m+1].'</a>';
369 $str .= '<table id="'. $table_id. '" cellspacing="1" cellpadding="0" border="0" width="100%">';
370 $str .= '<tr class="monthCalBodyTH">';
371 for($d = 0; $d < 7; $d++)
372 $str .= '<th width="14%">'.$this->weekday_names[$d].'</th>';
374 $curr_time_global = $week_start_ts;
376 while($curr_time_global < $month_end_ts){
377 $str .= '<tr class="monthViewDayHeight yearViewDayHeight">';
378 for($d = 0; $d < 7; $d++){
379 $curr_time = $week_start_ts + $d*86400 + $w*60*60*24*7;
381 if($curr_time < $month_start_ts || $curr_time >= $month_end_ts)
384 $monC = '<a href="'.ajaxLink('index.php?module=Calendar&action=index&view=day&hour=0&day='.$GLOBALS['timedate']->fromTimestamp($curr_time)->format('j').'&month='.$GLOBALS['timedate']->fromTimestamp($curr_time)->format('n').'&year='.$GLOBALS['timedate']->fromTimestamp($curr_time)->format('Y')) .'">'.$GLOBALS['timedate']->fromTimestamp($curr_time)->format('j').'</a>';
386 if($d == $weekEnd1 || $d == $weekEnd2)
387 $str .= "<td class='weekEnd monthCalBodyWeekEnd'>";
389 $str .= "<td class='monthCalBodyWeekDay'>";
394 $curr_time_global += 60*60*24*7;
399 if(($m - 2) % 3 == 0)