1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** Display jQuery UI Timepicker for each date and datetime field |
4
|
|
|
* @link https://www.adminer.org/plugins/#use |
5
|
|
|
* @uses jQuery-Timepicker, http://trentrichardson.com/examples/timepicker/ |
6
|
|
|
* @uses jQuery UI: core, widget, mouse, slider, datepicker |
7
|
|
|
* @author Jakub Vrana, http://www.vrana.cz/ |
8
|
|
|
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0 |
9
|
|
|
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU General Public License, version 2 (one or other) |
10
|
|
|
*/ |
11
|
|
|
class AdminerEditCalendar { |
12
|
|
|
/** @access protected */ |
13
|
|
|
var $prepend, $langPath; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* @param string text to append before first calendar usage |
17
|
|
|
* @param string path to language file, %s stands for language code |
18
|
|
|
*/ |
19
|
|
|
function __construct($prepend = "<script type='text/javascript' src='jquery-ui/jquery.js'></script>\n<script type='text/javascript' src='jquery-ui/jquery-ui.js'></script>\n<script type='text/javascript' src='jquery-ui/jquery-ui-timepicker-addon.js'></script>\n<link rel='stylesheet' type='text/css' href='jquery-ui/jquery-ui.css'>\n", $langPath = 'jquery-ui/i18n/jquery.ui.datepicker-%s.js' |
|
|
|
|
20
|
|
|
) { |
21
|
|
|
$this->prepend = $prepend; |
22
|
|
|
$this->langPath = $langPath; |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
function head() { |
|
|
|
|
26
|
|
|
echo $this->prepend; |
27
|
|
|
if ($this->langPath && function_exists('get_lang')) { // since Adminer 3.2.0 |
28
|
|
|
$lang = get_lang(); |
29
|
|
|
$lang = ($lang == 'zh' ? 'zh-CN' : ($lang == 'zh-tw' ? 'zh-TW' : $lang)); |
30
|
|
|
if ($lang != 'en' && file_exists(sprintf($this->langPath, $lang))) { |
31
|
|
|
printf("<script type='text/javascript' src='$this->langPath'></script>\n", $lang); |
32
|
|
|
echo "<script type='text/javascript'>jQuery(function () { jQuery.timepicker.setDefaults(jQuery.datepicker.regional['$lang']); });</script>\n"; |
33
|
|
|
} |
34
|
|
|
} |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
function editInput($table, $field, $attrs, $value) { |
|
|
|
|
38
|
|
|
if (preg_match('~date|time~', $field['type'])) { |
39
|
|
|
$dateFormat = "changeYear: true, dateFormat: 'yy-mm-dd'"; //! yy-mm-dd regional |
40
|
|
|
$timeFormat = "showSecond: true, timeFormat: 'hh:mm:ss'"; |
41
|
|
|
return "<input id='fields-" . h($field['field']) . "' value='" . h($value) . "'" . (+$field['length'] ? " maxlength='" . (+$field['length']) . "'" : '') . "$attrs><script type='text/javascript'>jQuery('#fields-" . js_escape($field['field']) . "')." |
42
|
|
|
. ($field['type'] == 'time' ? "timepicker({ $timeFormat })" |
43
|
|
|
: (preg_match('~time~', $field['type']) ? "datetimepicker({ $dateFormat, $timeFormat })" |
44
|
|
|
: "datepicker({ $dateFormat })" |
45
|
|
|
)) . ';</script>'; |
46
|
|
|
} |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
} |
50
|
|
|
|
Adding explicit visibility (
private
,protected
, orpublic
) is generally recommend to communicate to other developers how, and from where this method is intended to be used.