Skip to content

Commit

Permalink
Modified year selections on date pickers to be current time / year de…
Browse files Browse the repository at this point in the history
…pendent
  • Loading branch information
mikeho committed Jul 18, 2011
1 parent 137e908 commit a2c7d35
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
22 changes: 18 additions & 4 deletions includes/qcodo/_core/qform/QDateTimePickerBase.class.php
Expand Up @@ -4,13 +4,19 @@ class QDateTimePickerBase extends QControl {
// Private Member Variables
///////////////////////////

// DEFAULTS
// These are set at the bottom of this script
public static $DefaultMinimumYear;
public static $DefaultMaximumYear;

// MISC
protected $dttDateTime = null;
protected $strDateTimePickerType = QDateTimePickerType::Date;
protected $strDateTimePickerFormat = QDateTimePickerFormat::MonthDayYear;

protected $intMinimumYear = 1970;
protected $intMaximumYear = 2015;
// If these stay null, then it will use the $DefaultMinimumYear and $DefaultMaximumYear static variables on QDateTimePicker
protected $intMinimumYear = null;
protected $intMaximumYear = null;

protected $intSelectedMonth = null;
protected $intSelectedDay = null;
Expand Down Expand Up @@ -191,12 +197,17 @@ protected function GetControlHtml() {
}
}
$strDayListbox .= '</select>';


// Figure Out Min and Max Years
$intMinimumYear = (is_null($this->intMinimumYear)) ? QDateTimePicker::$DefaultMinimumYear : $this->intMinimumYear;
$intMaximumYear = (is_null($this->intMaximumYear)) ? QDateTimePicker::$DefaultMaximumYear : $this->intMaximumYear;

// Year
$strYearListbox = sprintf('<select name="%s_lstYear" id="%s_lstYear" class="year" %s%s>', $this->strControlId, $this->strControlId, $strAttributes, $strCommand);
if (!$this->blnRequired || $dttDateTime->IsDateNull())
$strYearListbox .= '<option value="">--</option>';
for ($intYear = $this->intMinimumYear; $intYear <= $this->intMaximumYear; $intYear++) {

for ($intYear = $intMinimumYear; $intYear <= $intMaximumYear; $intYear++) {
if (/*!$dttDateTime->IsDateNull() && */(($dttDateTime->Year == $intYear) || ($this->intSelectedYear == $intYear)))
$strSelected = ' selected="selected"';
else
Expand Down Expand Up @@ -477,4 +488,7 @@ public function __set($strName, $mixValue) {
}
}
}

QDateTimePickerBase::$DefaultMinimumYear = date('Y') - 30;
QDateTimePickerBase::$DefaultMaximumYear = date('Y') + 5;
?>
5 changes: 3 additions & 2 deletions includes/qcodo/qform/QDateTimePicker.class.php
Expand Up @@ -10,8 +10,9 @@ class QDateTimePicker extends QDateTimePickerBase {
protected $strDateTimePickerType = QDateTimePickerType::Date;
protected $strDateTimePickerFormat = QDateTimePickerFormat::MonthDayYear;

protected $intMinimumYear = 1970;
protected $intMaximumYear = 2015;
// If these stay null, then it will use the $DefaultMinimumYear and $DefaultMaximumYear static variables on QDateTimePicker
protected $intMinimumYear = null;
protected $intMaximumYear = null;

// Default format of the Hour field (see http://www.php.net/date for more info)
// Two digit representation of the hour in 12-hour format followed by UPPER-CASE 'AM' or 'PM'
Expand Down
2 changes: 1 addition & 1 deletion www/assets/php/_core/calendar.php
Expand Up @@ -122,7 +122,7 @@ function done() {
</select> &nbsp;
<select name="dttYear" class="dropdown" onchange="selectDate(document.myForm.dttYear.options[document.myForm.dttYear.selectedIndex].value)">
<?php
for ($intYear = 1970; $intYear <= 2010; $intYear++) {
for ($intYear = 1970; $intYear <= date('Y') + 1; $intYear++) {
$intTimestampLabel = mktime(0,0,0, $intSelectedMonth, 1, $intYear);
$strLabel = date("Y", $intTimestampLabel);
$strSelected = ($intYear == $intSelectedYear) ? 'selected="selected"' : '';
Expand Down

0 comments on commit a2c7d35

Please sign in to comment.