C'est bon, j'ai récupéré FormDateTimePicker du module xoopspoll
J'ai un peu adapté pour qu'on puisse mettre Date seule ou date/Heure
class FormDateTimePicker extends XoopsFormText
{
/**
* Contains the maximum field size
*/
public const MAXSIZE = 25;
protected $showTime;
/**
* Constructor to build FormDateTimePicker object
* @param mixed $caption HTML description to display for the element
* @param mixed $name HTML element name (ie. name='$name')
* @param mixed $size size of field to display
* @param mixed $value timestamp of date/time to show
*/
public function __construct($caption, $name, $size, $value, $showTime=true)
{
$value = (!is_numeric($value) || (0 === (int)$value)) ? null : (int)$value;
$size = (int)$size;
$size = ($size > 0 && $size <= self::MAXSIZE) ? $size : self::MAXSIZE;
$this->$showTime = $showTime;
parent::__construct($caption, $name, $size, self::MAXSIZE, $value);
}
/**
* Generate the HTML <input> to display the date/time field
* @return string HTML code used to display in a form
*/
public function render()
{
static $included = false;
$ele_name = $this->getName();
$ele_value = $this->getValue(true);
//if (is_string($ele_value)) {
if (!is_numeric($ele_value)) {
$display_value = $ele_value;
$ele_value = time();
} else if ($ele_value>0) {
//$display_value = '';
//$display_value = formatTimestamp($ele_value, 'm');
if ($this->$showTime)
$display_value = ucfirst(date("d-m-Y H:i", $ele_value)); // _MEDIUMDATESTRING = d-m-Y H:i
else
$display_value = ucfirst(date("d-m-Y", $ele_value)); // _MEDIUMDATESTRING = d-m-Y H:i
}
if (is_object($GLOBALS['xoTheme'])) {
$moduleHandler = xoops_getHandler('module');
$sys_module = $moduleHandler->getByDirname('system');
$configHandler = xoops_getHandler('config');
$moduleConfig = $configHandler->getConfigsByCat(0, $sys_module->getVar('mid'));
$jq_theme_dir = $moduleConfig['jquery_theme'];
$GLOBALS['xoTheme']->addStylesheet($GLOBALS['xoops']->url("modules/system/css/ui/{$jq_theme_dir}/ui.all.css"));
$GLOBALS['xoTheme']->addScript('browse.php?Frameworks/jquery/jquery.js');
$GLOBALS['xoTheme']->addScript('browse.php?Frameworks/jquery/plugins/jquery.ui.js');
$GLOBALS['xoTheme']->addScript('browse.php?modules/comin/assets/js/jquery-ui-timepicker-addon.js');
$GLOBALS['xoTheme']->addScript('browse.php?modules/comin/assets/js/jquery-ui-sliderAccess.js');
$GLOBALS['xoTheme']->addStylesheet($GLOBALS['xoops']->url('modules/comin/css/datetimepicker.css'));
if (!$included) {
$included = true;
xoops_loadLanguage('admin', 'Comin');
// setup regional date variables
$reg_values = "closeText: '"._AM_COMIN_DTP_CLOSETEXT."',"
."prevText: '"._AM_COMIN_DTP_PREVTEXT."',"
."nextText: '"._AM_COMIN_DTP_NEXTTEXT."',"
."currentText: '"._AM_COMIN_DTP_CURRENTTEXT."',"
.'monthNames: ['._AM_COMIN_DTP_MONTHNAMES.'],'
.'monthNamesShort: ['._AM_COMIN_DTP_MONTHNAMESSHORT.'],'
.'dayNames: ['._AM_COMIN_DTP_DAYNAMES.'],'
.'dayNamesShort: ['._AM_COMIN_DTP_DAYNAMESSHORT.'],'
.'dayNamesMin: ['._AM_COMIN_DTP_DAYNAMESMIN.'],'
."weekHeader: '"._AM_COMIN_DTP_WEEKHEADER."',"
."dateFormat: '"._AM_COMIN_DTP_DATEFORMAT."',"
."firstDay: '"._AM_COMIN_DTP_FIRSTDAY."',"
."isRTL: "._AM_COMIN_DTP_ISRTL.","
."showTimepicker: ".(($this->$showTime)?"true":"false")."," //
."showMonthAfterYear: "._AM_COMIN_DTP_SHOWMONTHAFTERYEAR.","
."yearSuffix: '"._AM_COMIN_DTP_YEARSUFFIX."',";
// set regional time variables
$reg_values .= "timeOnlyTitle: '"._AM_COMIN_DTP_TIMEONLYTITLE."',"
."timeText: '"._AM_COMIN_DTP_TIMETEXT."',"
."hourText: '"._AM_COMIN_DTP_HOURTEXT."',"
."minuteText: '"._AM_COMIN_DTP_MINUTETEXT."',"
."secondText: '"._AM_COMIN_DTP_SECONDTEXT."',"
."millisecText: '"._AM_COMIN_DTP_MILLISECTEXT."',"
."timeFormat: '"._AM_COMIN_DTP_TIMEFORMAT."',"
.'ampm: false,'.'stepMinute: 5';
$GLOBALS['xoTheme']->addScript('','','$(function() {$( ".datetimepicker" ).datetimepicker({'.$reg_values.'});});');
}
}
return "<input type='text' name='{$ele_name}' id='{$ele_name}' class='datetimepicker' size='".$this->getSize()."' maxlength='".$this->getMaxlength()."'
value='{$display_value}'".$this->getExtra().'>';
}
}