Example #1
0
 protected function GetControlHtml()
 {
     // Ignore Class
     $strCssClass = $this->strCssClass;
     $this->strCssClass = '';
     $strAttributes = $this->GetAttributes();
     $this->strCssClass = $strCssClass;
     $strStyle = $this->GetStyleAttributes();
     if ($strStyle) {
         $strAttributes .= sprintf(' style="%s"', $strStyle);
     }
     $strCommand = sprintf(' onchange="Qcodo__DateTimePicker_Change(\'%s\', this);"', $this->strControlId);
     if ($this->dttDateTime) {
         $dttDateTime = $this->dttDateTime;
     } else {
         $dttDateTime = new QDateTime();
     }
     $strToReturn = '';
     // Generate Date-portion
     switch ($this->strDateTimePickerType) {
         case QDateTimePickerType::Date:
         case QDateTimePickerType::DateTime:
         case QDateTimePickerType::DateTimeSeconds:
             // Month
             $strMonthListbox = sprintf('<select name="%s_lstMonth" id="%s_lstMonth" class="month" %s%s>', $this->strControlId, $this->strControlId, $strAttributes, $strCommand);
             if (!$this->blnRequired || $dttDateTime->IsDateNull()) {
                 $strMonthListbox .= '<option value="">--</option>';
             }
             $dttMonth = new QDateTime('2000-01-01');
             for ($intMonth = 1; $intMonth <= 12; $intMonth++) {
                 if (!$dttDateTime->IsDateNull() && $dttDateTime->Month == $intMonth || $this->intSelectedMonth == $intMonth) {
                     $strSelected = ' selected="selected"';
                 } else {
                     $strSelected = '';
                 }
                 $dttMonth->Month = $intMonth;
                 $strMonthListbox .= sprintf('<option value="%s"%s>%s</option>', $intMonth, $strSelected, $dttMonth->ToString('MMM'));
             }
             $strMonthListbox .= '</select>';
             // Day
             $strDayListbox = sprintf('<select name="%s_lstDay" id="%s_lstDay" class="day" %s%s>', $this->strControlId, $this->strControlId, $strAttributes, $strCommand);
             if (!$this->blnRequired || $dttDateTime->IsDateNull()) {
                 $strDayListbox .= '<option value="">--</option>';
             }
             if ($dttDateTime->IsDateNull()) {
                 if ($this->blnRequired) {
                     // New DateTime, but we are required -- therefore, let's assume January is preselected
                     for ($intDay = 1; $intDay <= 31; $intDay++) {
                         $strDayListbox .= sprintf('<option value="%s">%s</option>', $intDay, $intDay);
                     }
                 } else {
                     // New DateTime -- but we are NOT required
                     // See if a month has been selected yet.
                     if ($this->intSelectedMonth) {
                         $intSelectedYear = $this->intSelectedYear ? $this->intSelectedYear : 2000;
                         $intDaysInMonth = date('t', mktime(0, 0, 0, $this->intSelectedMonth, 1, $intSelectedYear));
                         for ($intDay = 1; $intDay <= $intDaysInMonth; $intDay++) {
                             if ($dttDateTime->Day == $intDay || $this->intSelectedDay == $intDay) {
                                 $strSelected = ' selected="selected"';
                             } else {
                                 $strSelected = '';
                             }
                             $strDayListbox .= sprintf('<option value="%s"%s>%s</option>', $intDay, $strSelected, $intDay);
                         }
                     } else {
                         // It's ok just to have the "--" marks and nothing else
                     }
                 }
             } else {
                 $intDaysInMonth = $dttDateTime->PHPDate('t');
                 for ($intDay = 1; $intDay <= $intDaysInMonth; $intDay++) {
                     if ($dttDateTime->Day == $intDay || $this->intSelectedDay == $intDay) {
                         $strSelected = ' selected="selected"';
                     } else {
                         $strSelected = '';
                     }
                     $strDayListbox .= sprintf('<option value="%s"%s>%s</option>', $intDay, $strSelected, $intDay);
                 }
             }
             $strDayListbox .= '</select>';
             // 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++) {
                 if ($dttDateTime->Year == $intYear || $this->intSelectedYear == $intYear) {
                     $strSelected = ' selected="selected"';
                 } else {
                     $strSelected = '';
                 }
                 $strYearListbox .= sprintf('<option value="%s"%s>%s</option>', $intYear, $strSelected, $intYear);
             }
             $strYearListbox .= '</select>';
             // Put it all together
             switch ($this->strDateTimePickerFormat) {
                 case QDateTimePickerFormat::MonthDayYear:
                     $strToReturn .= $strMonthListbox . $strDayListbox . $strYearListbox;
                     break;
                 case QDateTimePickerFormat::DayMonthYear:
                     $strToReturn .= $strDayListbox . $strMonthListbox . $strYearListbox;
                     break;
                 case QDateTimePickerFormat::YearMonthDay:
                     $strToReturn .= $strYearListbox . $strMonthListbox . $strDayListbox;
                     break;
             }
     }
     switch ($this->strDateTimePickerType) {
         case QDateTimePickerType::DateTime:
         case QDateTimePickerType::DateTimeSeconds:
             $strToReturn .= '<span class="divider"></span>';
     }
     switch ($this->strDateTimePickerType) {
         case QDateTimePickerType::Time:
         case QDateTimePickerType::TimeSeconds:
         case QDateTimePickerType::DateTime:
         case QDateTimePickerType::DateTimeSeconds:
             // Hour
             $strHourListBox = sprintf('<select name="%s_lstHour" id="%s_lstHour" class="hour" %s>', $this->strControlId, $this->strControlId, $strAttributes);
             if (!$this->blnRequired || $dttDateTime->IsTimeNull()) {
                 $strHourListBox .= '<option value="">--</option>';
             }
             for ($intHour = 0; $intHour <= 23; $intHour++) {
                 if (!$dttDateTime->IsTimeNull() && $dttDateTime->Hour == $intHour) {
                     $strSelected = ' selected="selected"';
                 } else {
                     $strSelected = '';
                 }
                 $strHourListBox .= sprintf('<option value="%s"%s>%s</option>', $intHour, $strSelected, date('g A', mktime($intHour, 0, 0, 1, 1, 2000)));
             }
             $strHourListBox .= '</select>';
             // Minute
             $strMinuteListBox = sprintf('<select name="%s_lstMinute" id="%s_lstMinute" class="minute" %s>', $this->strControlId, $this->strControlId, $strAttributes);
             if (!$this->blnRequired || $dttDateTime->IsTimeNull()) {
                 $strMinuteListBox .= '<option value="">--</option>';
             }
             for ($intMinute = 0; $intMinute <= 59; $intMinute++) {
                 if (!$dttDateTime->IsTimeNull() && $dttDateTime->Minute == $intMinute) {
                     $strSelected = ' selected="selected"';
                 } else {
                     $strSelected = '';
                 }
                 $strMinuteListBox .= sprintf('<option value="%s"%s>%02d</option>', $intMinute, $strSelected, $intMinute);
             }
             $strMinuteListBox .= '</select>';
             // Seconds
             $strSecondListBox = sprintf('<select name="%s_lstSecond" id="%s_lstSecond" class="second" %s>', $this->strControlId, $this->strControlId, $strAttributes);
             if (!$this->blnRequired || $dttDateTime->IsTimeNull()) {
                 $strSecondListBox .= '<option value="">--</option>';
             }
             for ($intSecond = 0; $intSecond <= 59; $intSecond++) {
                 if (!$dttDateTime->IsTimeNull() && $dttDateTime->Second == $intSecond) {
                     $strSelected = ' selected="selected"';
                 } else {
                     $strSelected = '';
                 }
                 $strSecondListBox .= sprintf('<option value="%s"%s>%02d</option>', $intSecond, $strSelected, $intSecond);
             }
             $strSecondListBox .= '</select>';
             // PUtting it all together
             if ($this->strDateTimePickerType == QDateTimePickerType::DateTimeSeconds || $this->strDateTimePickerType == QDateTimePickerType::TimeSeconds) {
                 $strToReturn .= $strHourListBox . ':' . $strMinuteListBox . ':' . $strSecondListBox;
             } else {
                 $strToReturn .= $strHourListBox . ':' . $strMinuteListBox;
             }
     }
     if ($this->strCssClass) {
         $strCssClass = ' class="' . $this->strCssClass . '"';
     } else {
         $strCssClass = '';
     }
     return sprintf('<span id="%s"%s>%s</span>', $this->strControlId, $strCssClass, $strToReturn);
 }