<?php require_once '../../civicrm.config.php'; require_once 'CRM/Core/Config.php'; require_once 'CRM/Core/I18n.php'; require_once 'CRM/Utils/Date.php'; // assign the weekday and month names $DN = CRM_Utils_Date::getFullWeekdayNames(); $SDN = CRM_Utils_Date::getAbbrWeekdayNames(); $MN = CRM_Utils_Date::getFullMonthNames(); $SMN = CRM_Utils_Date::getAbbrMonthNames(); // assign the strings hash $TT['INFO'] = ts('About the calendar'); $TT['ABOUT'] = "DHTML Date/Time Selector\n(c) dynarch.com 2002-2005 / Author: Mihai Bazon\n" . ts('For latest version visit: %1', array(1 => 'http://www.dynarch.com/projects/calendar/')) . "\n" . ts('Distributed under GNU LGPL. See %1 for details.', array(1 => 'http://gnu.org/licenses/lgpl.html')) . "\n\n" . ts('Date selection:') . "\n" . ts('- use the \\xab, \\xbb buttons to select year,') . "\n" . ts('- use the \\u2039, \\u203a buttons to select month,') . "\n" . ts('- hold mouse button on any of the above buttons for faster selection.'); $TT['ABOUT_TIME'] = "\n\n" . ts('Time selection:') . "\n" . ts('- click on any of the time parts to increase it') . "\n" . ts('- or Shift-click to decrease it') . "\n" . ts('- or click and drag for faster selection.'); $holdForMenu = ts('hold for menu'); $TT['PREV_YEAR'] = ts('Prev. year') . " ({$holdForMenu})"; $TT['PREV_MONTH'] = ts('Prev. month') . " ({$holdForMenu})"; $TT['GO_TODAY'] = ts('Go Today'); $TT['NEXT_MONTH'] = ts('Next month') . " ({$holdForMenu})"; $TT['NEXT_YEAR'] = ts('Next year') . " ({$holdForMenu})"; $TT['SEL_DATE'] = ts('Select date'); $TT['DRAG_TO_MOVE'] = ts('Drag to move'); $TT['PART_TODAY'] = ' (' . ts('today') . ')'; $TT['DAY_FIRST'] = ts('Display %s first'); $TT['WEEKEND'] = '0,6'; $TT['CLOSE'] = ts('Close'); $TT['TODAY'] = ts('Today'); $TT['TIME_PART'] = ts('(Shift-)Click or drag to change value'); $TT['DEF_DATE_FORMAT'] = '%Y-%m-%d'; $TT['TT_DATE_FORMAT'] = '%a, %b %e';
/** * Class constructor * * @access public * @param string Element's name * @param mixed Label(s) for an element * @param array Options to control the element's display * @param mixed Either a typical HTML attribute string or an associative array */ function HTML_QuickForm_date($elementName = null, $elementLabel = null, $options = array(), $attributes = null) { $this->_locale = array('weekdays_short' => CRM_Utils_Date::getAbbrWeekdayNames(), 'weekdays_long' => CRM_Utils_Date::getFullWeekdayNames(), 'months_short' => CRM_Utils_Date::getAbbrMonthNames(), 'months_long' => CRM_Utils_Date::getFullMonthNames()); $this->HTML_QuickForm_element($elementName, $elementLabel, $attributes); $this->_persistantFreeze = true; $this->_appendName = true; $this->_type = 'date'; // set the options, do not bother setting bogus ones if (is_array($options)) { foreach ($options as $name => $value) { if (isset($this->_options[$name])) { if (is_array($value)) { $this->_options[$name] = @array_merge($this->_options[$name], $value); } else { $this->_options[$name] = $value; } } } } }
/** * converts the any given date to default date format. * * @param array $params has given date-format * @param int $dateType type of date * @param string $dateParam index of params * @static */ function convertToDefaultDate(&$params, $dateType, $dateParam) { if ($dateType == 1) { return; } if ($dateType == 2) { if ($params[$dateParam]) { $value = $params[$dateParam]; } $year = (int) substr($value, 6, 2); $year = $year < 100 ? "19" . "{$year}" : $year; $month = (int) substr($value, 0, 2); $day = (int) substr($value, 3, 2); $month = $month < 10 ? "0" . "{$month}" : $month; $day = $day < 10 ? "0" . "{$day}" : $day; if ($params[$dateParam]) { $params[$dateParam] = "{$year}{$month}{$day}"; } } if ($dateType == 4) { if ($params[$dateParam]) { $value = $params[$dateParam]; } $year = (int) substr($value, 6, 4); $month = (int) substr($value, 0, 2); $day = (int) substr($value, 3, 2); $month = $month < 10 ? "0" . "{$month}" : $month; $day = $day < 10 ? "0" . "{$day}" : $day; if ($params[$dateParam]) { $params[$dateParam] = "{$year}{$month}{$day}"; } } if ($dateType == 8) { if ($params[$dateParam]) { $value = $params[$dateParam]; } $dateArray = explode(' ', $value); $monthInt = 0; $fullMonths = CRM_Utils_Date::getFullMonthNames(); foreach ($fullMonths as $key => $val) { if ($dateArray[0] == $val) { $monthInt = $key; break; } } if (!$monthInt) { $abbrMonths = CRM_Utils_Date::getAbbrMonthNames(); foreach ($abbrMonths as $key => $val) { if ($dateArray[0] == $val) { $monthInt = $key; break; } } } $year = $dateArray[2]; $year = $year < 100 ? "19" . "{$year}" : $year; $day = (int) $dateArray[1]; $month = $monthInt < 10 ? "0" . "{$monthInt}" : $monthInt; $day = $day < 10 ? "0" . "{$day}" : $day; if ($params[$dateParam]) { $params[$dateParam] = "{$year}{$month}{$day}"; } } if ($dateType == 16) { if ($params[$dateParam]) { $value = $params[$dateParam]; } $dateArray = explode('-', $value); $monthInt = 0; $fullMonths = CRM_Utils_Date::getFullMonthNames(); foreach ($fullMonths as $key => $val) { if ($dateArray[1] == $val) { $monthInt = $key; break; } } if (!$monthInt) { $abbrMonths = CRM_Utils_Date::getAbbrMonthNames(); foreach ($abbrMonths as $key => $val) { if ($dateArray[1] == $val) { $monthInt = $key; break; } } } $year = $dateArray[2]; $year = $year < 100 ? "19" . "{$year}" : $year; $day = (int) $dateArray[0]; $month = $monthInt < 10 ? "0" . "{$monthInt}" : $monthInt; $day = $day < 10 ? "0" . "{$day}" : $day; if ($params[$dateParam]) { $params[$dateParam] = "{$year}{$month}{$day}"; } } }
static function signoutDetailsPerMonth($startDate, $endDate, $studentID = null) { // always do per academic year // which goes from Sept (09) - June (06) $currentYear = date('Y'); $m = $currentMonth = date('m'); $dateRange = array(); if ($m >= 9) { for ($i = 9; $i < $m; $i++) { $mon = $i == 9 ? '09' : $m; $end = self::getDaysInMonth($i, $currentYear); $dateRange[] = array('start' => "{$currentYear}{$mon}01", 'end' => "{$currentYear}{$mon}{$end}", 'year' => $currentYear, 'mon' => $mon); } } else { $startYear = $currentYear - 1; for ($i = 9; $i <= 12; $i++) { $mon = $i == 9 ? '09' : $i; $end = self::getDaysInMonth($i, $startYear); $dateRange[] = array('start' => "{$startYear}{$mon}01", 'end' => "{$startYear}{$mon}{$end}", 'year' => $startYear, 'mon' => $mon); } $nextYear = $currentYear + 1; for ($i = 1; $i <= $m; $i++) { $mon = "0{$i}"; $end = self::getDaysInMonth($i, $nextYear); $dateRange[] = array('start' => "{$currentYear}{$mon}01", 'end' => "{$currentYear}{$mon}{$end}", 'year' => $currentYear, 'mon' => $mon); } } $dateRange = array_reverse($dateRange); $monthNames = CRM_Utils_Date::getAbbrMonthNames(); $result = array(); foreach ($dateRange as $date) { $d = self::signoutDetails($date['start'], $date['end'], true, false, false, $studentID); if (!empty($d) && isset($d[$studentID]) && $d[$studentID]['blockCharge'] > 0 && empty($d[$studentID]['doNotCharge'])) { $mon = (int) $date['mon']; $yearMon = "{$date['year']} - {$monthNames[$mon]}"; $monYear = "{$monthNames[$mon]} - {$date['year']}"; $term = $mon > 9 ? 'Fall' : 'Spring'; $result[$yearMon] = array('blockCharge' => $d[$studentID]['blockCharge'], 'description' => "{$term} {$date['year']} - {$monYear}", 'year' => $date['year'], 'month' => $date['mon']); } } return $result; }