class = 'Calendar'; $this->controlName = $name; // TODO: why controlName? Other classes have "name". $this->mMonthNames = array('January','February','March','April','May','June','July','August','September','October','November','December'); $this->mWeekDayShortNames = array('Su','Mo','Tu','We','Th','Fr','Sa'); } function setHighlight($highlight) { if ($highlight && $highlight != 'time') $this->highlight = $highlight; } function localize() { global $user; global $i18n; $this->mMonthNames = $i18n->monthNames; $this->mWeekDayShortNames = $i18n->weekdayShortNames; if (is_array($i18n->holidays)) { foreach ($i18n->holidays as $fday) { $date_a = explode("/",$fday); // format mm/dd $this->holidays[] = mktime(0,0,0, $date_a[0], $date_a[1], date("Y"));// + 7200; } } $this->weekStartDay = $user->week_start; } function setStyle($style) { $this->style = $style; } function setCellStyle($style) { $this->mCellStyle = $style; } function setACellStyle($style) { $this->mACellStyle = $style; } function setLinkStyle($style) { $this->mLinkStyle = $style; } function setShowHolidays($value) { $this->showHolidays = $value; } /** * @return void * @param date * @desc Enter description here... */ function toString($date="") { global $i18n; $indate = $this->value; if (!$indate) $indate = strftime(DB_DATEFORMAT); //current year and month if ( strlen ( $indate ) > 0 ) { $indateObj = new DateAndTime(DB_DATEFORMAT, $indate); $thismonth = $indateObj->getMonth(); $thisyear = $indateObj->getYear(); } else { $thismonth = date("m"); $thisyear = date("Y"); } // next date, month, year $next = mktime ( 2, 0, 0, $thismonth + 1, 1, $thisyear ); $nextyear = date ( "Y", $next ); $nextmonth = date ( "m", $next ); $nextdate = strftime (DB_DATEFORMAT, $next ); // prev date, month, year $prev = mktime ( 2, 0, 0, $thismonth - 1, 1, $thisyear ); $prevyear = date ( "Y", $prev ); $prevmonth = date ( "m", $prev ); $prevdate = strftime(DB_DATEFORMAT, $prev ); $str = $this->_genStyles(); $str .= '
'. //'<< '. '<<< '. $this->mMonthNames[$thismonth-1].' '.$thisyear. ' >>>'. //' >>'. '
'; $str .= '
'; $str .= ""; $weekend_start = 6 - $this->weekStartDay; // Saturday by default. $weekend_end = (7 - $this->weekStartDay) % 7; // Sunday by default. if (defined('WEEKEND_START_DAY')) { $weekend_start = (7 + WEEKEND_START_DAY - $this->weekStartDay) % 7; $weekend_end = (7 + WEEKEND_START_DAY + 1 - $this->weekStartDay) % 7; } for ( $i=0; $i<7; $i++ ) { $weekdayNameIdx = ($i + $this->weekStartDay) % 7; if ($i==$weekend_start || $i==$weekend_end) { $str .= ''; } else { $str .= ''; } } $str .= "\n"; list($wkstart,$monthstart,$monthend,$start_date) = $this->_getWeekDayBefore( $thisyear, $thismonth ); $active_dates = $this->_getActiveDates($monthstart, $monthend); for ( $i = $wkstart; $i<=$monthend; $i=mktime(0,0,0,$thismonth,$start_date+=7,$thisyear) ) { $str .= "\n"; for ( $j = 0; $j < 7; $j++ ) { $date = mktime(0,0,0,$thismonth,$start_date+$j,$thisyear); if (($date >= $monthstart) && ($date <= $monthend)) { $stl_cell = ""; $stl_link = ""; // weekend if ($j==$weekend_start || $j==$weekend_end) { $stl_cell = ' class="CalendarDayWeekend"'; $stl_link = ' class="CalendarLinkWeekend"'; } else { $stl_cell = ' class="CalendarDay"'; } // holidays //if ($this->showHolidays) { global $user; if ($user->show_holidays) { foreach ($this->holidays as $day) { if($day == $date) { $stl_cell = ' class="CalendarDayHoliday"'; $stl_link = ' class="CalendarLinkHoliday"'; } } } // selected day if ( $indate == strftime(DB_DATEFORMAT, $date)) $stl_cell = ' class="CalendarDaySelected"'; $str .= ''; // Entries exist. if($active_dates) { if( in_array(strftime(DB_DATEFORMAT, $date), $active_dates) ) $stl_link = ' class="CalendarLinkRecordsExist"'; } $str .= "controlName."=".strftime(DB_DATEFORMAT, $date)."\" tabindex=\"-1\">".date("d",$date).""; $str .= ""; } else { $str .= "\n"; } } $str .= "\n"; } $str .= "\n"; $str .= "
'.$this->mWeekDayShortNames[$weekdayNameIdx].''.$this->mWeekDayShortNames[$weekdayNameIdx].'
 
controlName."=".strftime(DB_DATEFORMAT)."\" tabindex=\"-1\">".$i18n->get('label.today')."
\n"; $str .= "controlName\" value=\"$indate\">\n"; // Add script to adjust today link to match browser today, as PHP may run in a different timezone. $str .= "\n"; return $str; } function getHtml() { return $this->toString(); } function _getWeekDayBefore($year, $month) { $weekday = date ( "w", mktime ( 2, 0, 0, $month, 1 - $this->weekStartDay, $year ) ); return array( mktime ( 0, 0, 0, $month, 1 - $weekday, $year ), mktime ( 0, 0, 0, $month, 1, $year ), mktime ( 0, 0, 0, $month + 1, 0, $year ), (1 - $weekday) ); } function _genStyles() { $str = "\n"; return $str; } // _getActiveDates returns an array of dates, for which entries exist for user. // Type of entries (time or expenses) is determined by $this->highlight value. function _getActiveDates($start, $end) { global $user; $user_id = $user->getUser(); $table = ($this->highlight == 'expenses') ? 'tt_expense_items' : 'tt_log'; $mdb2 = getConnection(); $start_date = date("Y-m-d", $start); $end_date = date("Y-m-d", $end); $sql = "SELECT date FROM $table WHERE date >= '$start_date' AND date <= '$end_date' AND user_id = $user_id AND status = 1"; $res = $mdb2->query($sql); if (!is_a($res, 'PEAR_Error')) { while ($row = $res->fetchRow()) { $out[] = date('Y-m-d', strtotime($row['date'])); } return @$out; } else return false; } }