1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Xoopspoll form timepicker |
4
|
|
|
* |
5
|
|
|
* You may not change or alter any portion of this comment or credits |
6
|
|
|
* of supporting developers from this source code or any supporting source code |
7
|
|
|
* which is considered copyrighted (c) material of the original comment or credit authors. |
8
|
|
|
* This program is distributed in the hope that it will be useful, |
9
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
10
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
11
|
|
|
* |
12
|
|
|
* @copyright :: © {@link http://xoops.org/ XOOPS Project} |
13
|
|
|
* @license :: {@link http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU GPL 2} |
14
|
|
|
* @package :: xoopspoll |
15
|
|
|
* @subpackage:: class |
16
|
|
|
* @since :: 1.40 |
17
|
|
|
* @author :: TXMod Xoops (aka timgno) {@link http://www.txmodxoops.org/ TXMod Xoops} |
18
|
|
|
* @author :: zyspec <[email protected]> |
19
|
|
|
* @credits:: {@link http://www.trentrichardson.com Trent Richardson} |
20
|
|
|
*/ |
21
|
|
|
|
22
|
|
|
// defined('XOOPS_ROOT_PATH') || exit('XOOPS root path not defined'); |
|
|
|
|
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Creates a text field with jquery ui calendar & time select popup |
26
|
|
|
*/ |
27
|
|
|
class XoopspollFormDateTimePicker extends XoopsFormText |
|
|
|
|
28
|
|
|
{ |
29
|
|
|
/** |
30
|
|
|
* |
31
|
|
|
* Contains the maximum field size |
32
|
|
|
*/ |
33
|
|
|
const MAXSIZE = 25; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* |
37
|
|
|
* Constructor to build FormDateTimePicker object |
38
|
|
|
* @param mixed $caption HTML description to display for the element |
39
|
|
|
* @param mixed $name HTML element name (ie. name='$name') |
40
|
|
|
* @param mixed $size size of field to display |
41
|
|
|
* @param mixed $value timestamp of date/time to show |
42
|
|
|
*/ |
43
|
|
|
public function __construct($caption, $name, $size, $value) |
44
|
|
|
{ |
45
|
|
|
$value = (!is_numeric($value) || (0 === (int)$value)) ? time($value) : (int)$value; |
46
|
|
|
$size = (int)$size; |
47
|
|
|
$size = ($size > 0 && $size <= self::MAXSIZE) ? $size : self::MAXSIZE; |
48
|
|
|
parent::__construct($caption, $name, $size, self::MAXSIZE, $value); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* |
53
|
|
|
* Generate the HTML <input> to display the date/time field |
54
|
|
|
* @return string HTML code used to display in a form |
55
|
|
|
*/ |
56
|
|
|
public function render() |
|
|
|
|
57
|
|
|
{ |
58
|
|
|
static $included = false; |
59
|
|
|
|
60
|
|
|
$ele_name = $this->getName(); |
|
|
|
|
61
|
|
|
$ele_value = $this->getValue(true); |
62
|
|
|
// if (is_string($ele_value)) { |
|
|
|
|
63
|
|
|
if (!is_numeric($ele_value)) { |
64
|
|
|
$display_value = $ele_value; |
65
|
|
|
$ele_value = time(); |
|
|
|
|
66
|
|
|
} else { |
67
|
|
|
// $display_value = ''; |
|
|
|
|
68
|
|
|
// $display_value = formatTimestamp($ele_value, 'm'); |
|
|
|
|
69
|
|
|
$display_value = ucfirst(date(_MEDIUMDATESTRING, $ele_value)); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
if (is_object($GLOBALS['xoTheme'])) { |
73
|
|
|
$modHandler = xoops_getHandler('module'); |
74
|
|
|
$sys_module = $modHandler->getByDirname('system'); |
75
|
|
|
$configHandler = xoops_getHandler('config'); |
76
|
|
|
$moduleConfig = $configHandler->getConfigsByCat(0, $sys_module->getVar('mid')); |
77
|
|
|
$jq_theme_dir = $moduleConfig['jquery_theme']; |
78
|
|
|
|
79
|
|
|
$GLOBALS['xoTheme']->addStylesheet($GLOBALS['xoops']->url("modules/system/css/ui/{$jq_theme_dir}/ui.all.css")); |
80
|
|
|
$GLOBALS['xoTheme']->addScript('browse.php?Frameworks/jquery/jquery.js'); |
81
|
|
|
$GLOBALS['xoTheme']->addScript('browse.php?Frameworks/jquery/plugins/jquery.ui.js'); |
82
|
|
|
$GLOBALS['xoTheme']->addScript('browse.php?modules/xoopspoll/assets/js/jquery-ui-timepicker-addon.js'); |
83
|
|
|
$GLOBALS['xoTheme']->addScript('browse.php?modules/xoopspoll/assets/js/jquery-ui-sliderAccess.js'); |
84
|
|
|
$GLOBALS['xoTheme']->addStylesheet($GLOBALS['xoops']->url('modules/xoopspoll/assets/css/datetimepicker.css')); |
85
|
|
|
|
86
|
|
|
if (!$included) { |
87
|
|
|
$included = true; |
88
|
|
|
xoops_loadLanguage('admin', 'xoopspoll'); |
89
|
|
|
// setup regional date variables |
90
|
|
|
$reg_values = "closeText: '" . _AM_XOOPSPOLL_DTP_CLOSETEXT . "'," . "prevText: '" . _AM_XOOPSPOLL_DTP_PREVTEXT . "'," . "nextText: '" . _AM_XOOPSPOLL_DTP_NEXTTEXT . "'," . "currentText: '" . _AM_XOOPSPOLL_DTP_CURRENTTEXT . "'," |
91
|
|
|
. 'monthNames: [' . _AM_XOOPSPOLL_DTP_MONTHNAMES . '],' . 'monthNamesShort: [' . _AM_XOOPSPOLL_DTP_MONTHNAMESSHORT . '],' . 'dayNames: [' . _AM_XOOPSPOLL_DTP_DAYNAMES . '],' . 'dayNamesShort: [' |
92
|
|
|
. _AM_XOOPSPOLL_DTP_DAYNAMESSHORT . '],' . 'dayNamesMin: [' . _AM_XOOPSPOLL_DTP_DAYNAMESMIN . '],' . "weekHeader: '" . _AM_XOOPSPOLL_DTP_WEEKHEADER . "'," . "dateFormat: '" . _AM_XOOPSPOLL_DTP_DATEFORMAT . "'," |
93
|
|
|
. "firstDay: '" . _AM_XOOPSPOLL_DTP_FIRSTDAY . "'," . 'isRTL: ' . _AM_XOOPSPOLL_DTP_ISRTL . ',' . 'showMonthAfterYear: ' . _AM_XOOPSPOLL_DTP_SHOWMONTHAFTERYEAR . ',' . "yearSuffix: '" . _AM_XOOPSPOLL_DTP_YEARSUFFIX |
94
|
|
|
. "',"; |
95
|
|
|
// set regional time variables |
96
|
|
|
$reg_values .= "timeOnlyTitle: '" . _AM_XOOPSPOLL_DTP_TIMEONLYTITLE . "'," . "timeText: '" . _AM_XOOPSPOLL_DTP_TIMETEXT . "'," . "hourText: '" . _AM_XOOPSPOLL_DTP_HOURTEXT . "'," . "minuteText: '" . _AM_XOOPSPOLL_DTP_MINUTETEXT . "'," |
97
|
|
|
. "secondText: '" . _AM_XOOPSPOLL_DTP_SECONDTEXT . "'," . "millisecText: '" . _AM_XOOPSPOLL_DTP_MILLISECTEXT . "'," . "timeFormat: '" . _AM_XOOPSPOLL_DTP_TIMEFORMAT . "'," . 'ampm: false,' . 'stepMinute: 5'; |
98
|
|
|
|
99
|
|
|
$GLOBALS['xoTheme']->addScript('', '', ' |
100
|
|
|
$(function() { |
101
|
|
|
$( ".datetimepicker" ).datetimepicker({ |
102
|
|
|
' . $reg_values . ' |
103
|
|
|
}); |
104
|
|
|
}); |
105
|
|
|
'); |
106
|
|
|
} |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
return "<input type='text' name='{$ele_name}' id='{$ele_name}' class='datetimepicker' size='" . $this->getSize() . "' maxlength='" . $this->getMaxlength() . "' value='{$display_value}'" . $this->getExtra() . ' />'; |
110
|
|
|
} |
111
|
|
|
} |
112
|
|
|
|
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.