|
|
|
<?php
|
|
|
|
|
|
|
|
/* For licensing terms, see /license.txt */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Form element to select a date and hour.
|
|
|
|
*/
|
|
|
|
class DateTimePicker extends HTML_QuickForm_text
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* DateTimePicker constructor.
|
|
|
|
*
|
|
|
|
* @param string $elementName
|
|
|
|
* @param string|array $elementLabel
|
|
|
|
* @param array $attributes
|
|
|
|
*/
|
|
|
|
public function __construct($elementName, $elementLabel = null, $attributes = null)
|
|
|
|
{
|
|
|
|
if (!isset($attributes['id'])) {
|
|
|
|
$attributes['id'] = $elementName;
|
|
|
|
}
|
|
|
|
$attributes['class'] = 'p-component p-inputtext';
|
|
|
|
parent::__construct($elementName, $elementLabel, $attributes);
|
|
|
|
$this->_appendName = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* HTML code to display this datepicker.
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function toHtml()
|
|
|
|
{
|
|
|
|
if ($this->_flagFrozen) {
|
|
|
|
return $this->getFrozenHtml();
|
|
|
|
}
|
|
|
|
|
|
|
|
$id = $this->getAttribute('id');
|
|
|
|
$value = $this->getValue();
|
|
|
|
|
|
|
|
$formattedValue = '';
|
|
|
|
if (!empty($value)) {
|
|
|
|
$formattedValue = api_format_date($value, DATE_TIME_FORMAT_LONG_24H);
|
|
|
|
}
|
|
|
|
|
|
|
|
$label = $this->getLabel();
|
|
|
|
if (is_array($label) && isset($label[0])) {
|
|
|
|
$label = $label[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
//$resetFieldX = sprintf(get_lang('Reset %s'), $label);
|
|
|
|
|
|
|
|
return '<input '.$this->_getAttrString($this->_attributes).' />'.$this->getElementJS();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $value
|
|
|
|
*/
|
|
|
|
public function setValue($value)
|
|
|
|
{
|
|
|
|
$value = substr($value, 0, 16);
|
|
|
|
$this->updateAttributes(['value' => $value]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the necessary javascript for this datepicker.
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
private function getElementJS()
|
|
|
|
{
|
|
|
|
$js = null;
|
|
|
|
$id = $this->getAttribute('id');
|
|
|
|
//timeFormat: 'hh:mm'
|
|
|
|
$js .= "<script>
|
|
|
|
$(function() {
|
|
|
|
var config = {
|
|
|
|
altInput: true,
|
|
|
|
altFormat: '".get_lang('F d, Y')." ".get_lang('at')." H:i',
|
|
|
|
enableTime: true,
|
|
|
|
dateFormat: 'Y-m-d H:i',
|
|
|
|
time_24hr: true,
|
|
|
|
wrap: false,
|
|
|
|
locale: {
|
|
|
|
firstDayOfWeek: 1
|
|
|
|
}
|
|
|
|
};
|
|
|
|
$('#{$id}').flatpickr(config);
|
|
|
|
});
|
|
|
|
</script>";
|
|
|
|
|
|
|
|
return $js;
|
|
|
|
}
|
|
|
|
}
|