static function showDateField($name, $options = array())
{
global $CFG_GLPI;
$p['value'] = '';
$p['maybeempty'] = true;
$p['canedit'] = true;
$p['min'] = '';
$p['max'] = '';
$p['showyear'] = true;
$p['display'] = true;
$p['rand'] = mt_rand();
$p['yearrange'] = '';
foreach ($options as $key => $val) {
if (isset($p[$key])) {
$p[$key] = $val;
}
}
$output = "<div class='no-wrap'>";
$output .= "<input id='showdate" . $p['rand'] . "' type='text' size='10' name='_{$name}' " . "value='" . self::convDate($p['value']) . "'>";
$output .= Html::hidden($name, array('value' => $p['value'], 'id' => "hiddendate" . $p['rand'], 'size' => 10));
if ($p['maybeempty'] && $p['canedit']) {
$output .= "<img src='" . $CFG_GLPI['root_doc'] . "/pics/reset.png' alt=\"" . __('Clear') . "\" id='resetdate" . $p['rand'] . "' class='pointer'>";
}
$output .= "</div>";
$js = '';
if ($p['maybeempty'] && $p['canedit']) {
$js .= "\$('#resetdate" . $p['rand'] . "').click(function(){\n \$('#showdate" . $p['rand'] . "').val('');\n \$('#hiddendate" . $p['rand'] . "').val('');\n });";
}
$js .= "\$( '#showdate" . $p['rand'] . "' ).datepicker({\n altField: '#hiddendate" . $p['rand'] . "',\n altFormat: 'yy-mm-dd',\n firstDay: 1,\n showOtherMonths: true,\n selectOtherMonths: true,\n showButtonPanel: true,\n changeMonth: true,\n changeYear: true,\n showOn: 'button',\n showWeek: true,\n buttonImage: '" . $CFG_GLPI['root_doc'] . "/pics/calendar.png',\n buttonImageOnly: true ";
if (!$p['canedit']) {
$js .= ",disabled: true";
}
if (!empty($p['min'])) {
$js .= ",minDate: '" . self::convDate($p['min']) . "'";
}
if (!empty($p['max'])) {
$js .= ",maxDate: '" . self::convDate($p['max']) . "'";
}
if (!empty($p['yearrange'])) {
$js .= ",yearRange: '" . $p['yearrange'] . "'";
}
switch ($_SESSION['glpidate_format']) {
case 1:
$p['showyear'] ? $format = 'dd-mm-yy' : ($format = 'dd-mm');
break;
case 2:
$p['showyear'] ? $format = 'mm-dd-yy' : ($format = 'mm-dd');
break;
default:
$p['showyear'] ? $format = 'yy-mm-dd' : ($format = 'mm-dd');
}
$js .= ",dateFormat: '" . $format . "'";
$js .= "});";
$output .= Html::scriptBlock($js);
if ($p['display']) {
echo $output;
return $p['rand'];
}
return $output;
}