adminerevo/plugins/edit-calendar.php

57 lines
2.3 KiB
PHP
Raw Normal View History

2011-02-18 15:16:36 +00:00
<?php
/** Display jQuery UI Timepicker for each date and datetime field
2015-09-08 16:23:25 +00:00
* @link https://www.adminer.org/plugins/#use
2011-02-18 15:16:36 +00:00
* @uses jQuery-Timepicker, http://trentrichardson.com/examples/timepicker/
* @uses jQuery UI: core, widget, mouse, slider, datepicker
2017-02-27 12:43:33 +00:00
* @author Jakub Vrana, https://www.vrana.cz/
2018-01-14 10:03:54 +00:00
* @license https://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
* @license https://www.gnu.org/licenses/gpl-2.0.html GNU General Public License, version 2 (one or other)
2011-02-18 15:16:36 +00:00
*/
class AdminerEditCalendar {
2011-08-11 15:06:42 +00:00
/** @access protected */
2011-02-18 18:26:23 +00:00
var $prepend, $langPath;
2011-02-18 15:16:36 +00:00
/**
* @param string text to append before first calendar usage
* @param string path to language file, %s stands for language code
*/
2018-01-13 15:25:11 +00:00
function __construct($prepend = null, $langPath = "jquery-ui/i18n/jquery.ui.datepicker-%s.js") {
if ($prepend === null) {
$prepend = "<link rel='stylesheet' type='text/css' href='jquery-ui/jquery-ui.css'>\n"
. script_src("jquery-ui/jquery.js")
. script_src("jquery-ui/jquery-ui.js")
. script_src("jquery-ui/jquery-ui-timepicker-addon.js")
;
}
2011-02-18 15:16:36 +00:00
$this->prepend = $prepend;
$this->langPath = $langPath;
}
2011-06-10 11:36:17 +00:00
function head() {
echo $this->prepend;
if ($this->langPath && function_exists('get_lang')) { // since Adminer 3.2.0
$lang = get_lang();
$lang = ($lang == "zh" ? "zh-CN" : ($lang == "zh-tw" ? "zh-TW" : $lang));
if ($lang != "en" && file_exists(sprintf($this->langPath, $lang))) {
2018-01-13 15:25:11 +00:00
echo script_src(sprintf($this->langPath, $lang));
2018-01-12 14:27:44 +00:00
echo script("jQuery(function () { jQuery.timepicker.setDefaults(jQuery.datepicker.regional['$lang']); });");
2011-06-10 11:36:17 +00:00
}
}
}
2011-02-18 15:16:36 +00:00
function editInput($table, $field, $attrs, $value) {
if (preg_match("~date|time~", $field["type"])) {
2011-02-18 15:16:36 +00:00
$dateFormat = "changeYear: true, dateFormat: 'yy-mm-dd'"; //! yy-mm-dd regional
2018-02-08 10:52:11 +00:00
$timeFormat = "showSecond: true, timeFormat: 'HH:mm:ss', timeInput: true";
return "<input id='fields-" . h($field["field"]) . "' value='" . h($value) . "'" . (@+$field["length"] ? " data-maxlength='" . (+$field["length"]) . "'" : "") . "$attrs>" . script(
2018-01-12 14:27:44 +00:00
"jQuery('#fields-" . js_escape($field["field"]) . "')."
2011-02-18 15:16:36 +00:00
. ($field["type"] == "time" ? "timepicker({ $timeFormat })"
2018-01-12 14:27:44 +00:00
: (preg_match("~time~", $field["type"]) ? "datetimepicker({ $dateFormat, $timeFormat })"
: "datepicker({ $dateFormat })"
)) . ";");
2011-02-18 15:16:36 +00:00
}
}
2011-02-18 15:16:36 +00:00
}