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
55 * @param Calendar $cal
57 function __construct(&$cal){
60 $this->today_ts = $GLOBALS['timedate']->getNow()->get_day_begin()->format('U');
62 $this->startday = $current_user->get_first_day_of_week();
64 $weekday_names = array();
65 for($i = 0; $i < 7; $i++){
66 $j = $i + $this->startday;
69 $weekday_names[$i] = $GLOBALS['app_list_strings']['dom_cal_day_short'][$j+1];
72 $this->weekday_names = $weekday_names;
74 $this->scrollable = false;
75 if(in_array($this->cal->view,array('day','week'))){
76 $this->scrollable = true;
79 $this->time_step = $this->cal->time_step;
80 $this->time_format = $GLOBALS['timedate']->get_time_format();
81 $this->date_time_format = $GLOBALS['timedate']->get_date_time_format();
86 /** Get html of calendar grid
89 public function display(){
90 $action = "display_".strtolower($this->cal->view);
91 return $this->$action();
94 /** Get html of time column
95 * @param integer $start timestamp
98 protected function get_time_column($start){
100 $head_content = " ";
101 if($this->cal->view == 'month'){
102 if($this->startday == 0)
106 $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>";
108 $str .= "<div class='left_time_col'>";
109 if(!$this->scrollable)
110 $str .= "<div class='day_head'>".$head_content."</div>";
111 for($i = 0; $i < 24; $i++){
112 for($j = 0; $j < 60; $j += $this->time_step){
115 $innerText = $GLOBALS['timedate']->fromTimestamp($start + $i * 3600)->format($this->time_format);
117 $innerText = " ";
119 if($j == 60 - $this->time_step && $this->time_step < 60){
120 $class = " odd_border";
124 if($this->scrollable || !$this->check_owt($i,$j,$this->cal->d_start_minutes,$this->cal->d_end_minutes))
125 $str .= "<div class='left_cell".$class."'>".$innerText."</div>";
133 * Get html of day slots column
134 * @param integer $start timestamp
135 * @param integer $day number of day in week
136 * @param string $prefix prefix for id of timeslot used in shared view
139 protected function get_day_column($start,$day = 0,$prefix = ""){
142 $str .= "<div class='day_col'>";
143 $str .= $this->get_day_head($start,$day);
144 for($i = 0; $i < 24; $i++){
145 for($j = 0; $j < 60; $j += $this->time_step){
146 $timestr = $GLOBALS['timedate']->fromTimestamp($curr_time)->format($this->time_format);
147 if($j == 60 - $this->time_step && $this->time_step < 60){
148 $class = " odd_border";
152 if($this->scrollable || !$this->check_owt($i,$j,$this->cal->d_start_minutes,$this->cal->d_end_minutes))
153 $str .= "<div id='t_".$curr_time.$prefix."' class='slot".$class."' time='".$timestr."' datetime='".$GLOBALS['timedate']->fromTimestamp($curr_time)->format($this->date_time_format)."'></div>";
154 $curr_time += $this->time_step*60;
162 * Get html of day head
163 * @param integer $start timestamp
164 * @param integer $day number of day in week
165 * @param bulean $force force display header
168 protected function get_day_head($start,$day = 0,$force = false){
170 if(!$this->scrollable || $force){
172 if($this->today_ts == $start)
173 $headstyle = " today";
174 $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>";
180 * Get true if out of working day
181 * @param integer $i hours
182 * @param integer $j minutes
183 * @param integer $r_start start of working day in minutes
184 * @param integer $r_end end of working day in minutes
187 protected function check_owt($i,$j,$r_start,$r_end){
188 if($i*60+$j < $r_start || $i*60+$j >= $r_end)
193 * Get html of week calendar grid
196 protected function display_week(){
198 $current_date = $this->cal->date_time;
199 $week_start = CalendarUtils::get_first_day_of_week($current_date);
200 $week_start_ts = $week_start->format('U') + $week_start->getOffset(); // convert to timestamp, ignore tz
203 $str .= "<div id='cal-grid' style='visibility: hidden;'>";
205 $str .= "<div style='overflow-y: hidden;'>";
206 $str .= "<div class='left_time_col'>";
207 $str .= "<div class='day_head'> </div>";
209 $str .= "<div class='week_block'>";
210 for($d = 0; $d < 7; $d++){
211 $curr_time = $week_start_ts + $d*86400;
212 $str .= "<div class='day_col'>";
213 $str .= $this->get_day_head($curr_time,$d,true);
219 $str .= "<div id='cal-scrollable' style='overflow-y: scroll; clear: both; height: 479px;'>";
220 $str .= $this->get_time_column($week_start_ts);
221 $str .= "<div class='week_block'>";
222 for($d = 0; $d < 7; $d++){
223 $curr_time = $week_start_ts + $d*86400;
224 $str .= $this->get_day_column($curr_time);
235 * Get html of day calendar grid
238 protected function display_day(){
240 $current_date = $this->cal->date_time;
241 $day_start_ts = $current_date->format('U') + $current_date->getOffset(); // convert to timestamp, ignore tz
244 $str .= "<div id='cal-grid' style=' min-width: 300px; visibility: hidden;'>";
245 $str .= "<div id='cal-scrollable' style='overflow-y: scroll; height: 479px;'>";
246 $str .= $this->get_time_column($day_start_ts);
248 $curr_time = $day_start_ts + $d*86400;
249 $str .= "<div class='week_block'>";
250 $str .= $this->get_day_column($curr_time);
259 * Get html of month calendar grid
262 protected function display_month(){
264 $current_date = $this->cal->date_time;
265 $month_start = $current_date->get_day_by_index_this_month(0);
266 $month_end = $month_start->get("+".$month_start->format('t')." days");
267 $week_start = CalendarUtils::get_first_day_of_week($month_start);
268 $week_start_ts = $week_start->format('U') + $week_start->getOffset(); // convert to timestamp, ignore tz
269 $month_end_ts = $month_end->format('U') + $month_end->getOffset();
272 $str .= "<div id='cal-grid' style='visibility: hidden;'>";
273 $curr_time_global = $week_start_ts;
275 while($curr_time_global < $month_end_ts){
276 $str .= $this->get_time_column($curr_time_global);
277 $str .= "<div class='week_block'>";
278 for($d = 0; $d < 7; $d++){
279 $curr_time = $week_start_ts + $d*86400 + $w*60*60*24*7;
280 $str .= $this->get_day_column($curr_time,$d);
283 $str .= "<div style='clear: left;'></div>";
284 $curr_time_global += 60*60*24*7;
293 * Get html of week shared grid
296 protected function display_shared(){
298 $current_date = $this->cal->date_time;
299 $week_start = CalendarUtils::get_first_day_of_week($current_date);
300 $week_start_ts = $week_start->format('U') + $week_start->getOffset(); // convert to timestamp, ignore tz
303 $str .= "<div id='cal-grid' style='visibility: hidden;'>";
306 $shared_user = new User();
307 foreach($this->cal->shared_ids as $member_id){
309 $user_number_str = "_".$user_number;
311 $shared_user->retrieve($member_id);
312 $str .= "<div style='clear: both;'></div>";
313 $str .= "<div class='monthCalBody'><h5 class='calSharedUser'>".$shared_user->full_name."</h5></div>";
314 $str .= "<div user_id='".$member_id."' user_name='".$shared_user->user_name."'>";
316 $str .= $this->get_time_column($week_start_ts);
317 $str .= "<div class='week_block'>";
318 for($d = 0; $d < 7; $d++){
319 $curr_time = $week_start_ts + $d*86400;
320 $str .= $this->get_day_column($curr_time,$d,$user_number_str);
332 * Get html of year calendar
335 protected function display_year(){
337 $weekEnd1 = 0 - $this->startday;
338 $weekEnd2 = -1 - $this->startday;
344 $year_start = SugarDateTime::createFromFormat("Y-m-d",$this->cal->date_time->year.'-01-01');
347 $str .= '<table id="daily_cal_table" cellspacing="1" cellpadding="0" border="0" width="100%">';
349 for($m = 0; $m < 12; $m++){
351 $month_start = $year_start->get("+".$m." months");
352 $month_start_ts = $month_start->format('U') + $month_start->getOffset();
353 $month_end = $month_start->get("+".$month_start->format('t')." days");
354 $week_start = CalendarUtils::get_first_day_of_week($month_start);
355 $week_start_ts = $week_start->format('U') + $week_start->getOffset(); // convert to timestamp, ignore tz
356 $month_end_ts = $month_end->format('U') + $month_end->getOffset();
360 $str .= '<td class="yearCalBodyMonth" align="center" valign="top" scope="row">';
361 $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>';
362 $str .= '<table id="daily_cal_table" cellspacing="1" cellpadding="0" border="0" width="100%">';
363 $str .= '<tr class="monthCalBodyTH">';
364 for($d = 0; $d < 7; $d++)
365 $str .= '<th width="14%">'.$this->weekday_names[$d].'</th>';
367 $curr_time_global = $week_start_ts;
369 while($curr_time_global < $month_end_ts){
370 $str .= '<tr class="monthViewDayHeight yearViewDayHeight">';
371 for($d = 0; $d < 7; $d++){
372 $curr_time = $week_start_ts + $d*86400 + $w*60*60*24*7;
374 if($curr_time < $month_start_ts || $curr_time >= $month_end_ts)
377 $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>';
379 if($d == $weekEnd1 || $d == $weekEnd2)
380 $str .= "<td class='weekEnd monthCalBodyWeekEnd'>";
382 $str .= "<td class='monthCalBodyWeekDay'>";
388 $curr_time_global += 60*60*24*7;
393 if(($m - 2) % 3 == 0)