Files
adminer/plugins/edit-calendar.php

56 lines
2.3 KiB
PHP
Raw Normal View History

2011-02-18 16:16:36 +01:00
<?php
/** Display jQuery UI Timepicker for each date and datetime field
2015-09-08 09:23:25 -07:00
* @link https://www.adminer.org/plugins/#use
2011-02-18 16:16:36 +01:00
* @uses jQuery-Timepicker, http://trentrichardson.com/examples/timepicker/
* @uses jQuery UI: core, widget, mouse, slider, datepicker
2017-02-27 13:43:33 +01:00
* @author Jakub Vrana, https://www.vrana.cz/
2018-01-14 11:03:54 +01: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 16:16:36 +01:00
*/
class AdminerEditCalendar {
2025-03-11 07:21:13 +01:00
protected $prepend, $langPath;
2011-02-18 16:16:36 +01:00
/**
* @param string text to append before first calendar usage
* @param string path to language file, %s stands for language code
*/
2018-01-13 16:25:11 +01: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"
2025-03-05 11:40:56 +01:00
. Adminer\script_src("jquery-ui/jquery.js")
. Adminer\script_src("jquery-ui/jquery-ui.js")
. Adminer\script_src("jquery-ui/jquery-ui-timepicker-addon.js")
2018-01-13 16:25:11 +01:00
;
}
2011-02-18 16:16:36 +01:00
$this->prepend = $prepend;
$this->langPath = $langPath;
}
2011-06-10 13:36:17 +02:00
function head() {
echo $this->prepend;
2025-03-05 11:28:53 +01:00
if ($this->langPath) {
2025-03-05 11:40:56 +01:00
$lang = Adminer\get_lang();
2011-06-10 13:36:17 +02:00
$lang = ($lang == "zh" ? "zh-CN" : ($lang == "zh-tw" ? "zh-TW" : $lang));
if ($lang != "en" && file_exists(sprintf($this->langPath, $lang))) {
2025-03-05 11:40:56 +01:00
echo Adminer\script_src(sprintf($this->langPath, $lang));
echo Adminer\script("jQuery(function () { jQuery.timepicker.setDefaults(jQuery.datepicker.regional['$lang']); });");
2011-06-10 13:36:17 +02:00
}
}
}
2011-02-18 16:16:36 +01:00
function editInput($table, $field, $attrs, $value) {
if (preg_match("~date|time~", $field["type"])) {
2011-02-18 16:16:36 +01:00
$dateFormat = "changeYear: true, dateFormat: 'yy-mm-dd'"; //! yy-mm-dd regional
2018-02-08 11:52:11 +01:00
$timeFormat = "showSecond: true, timeFormat: 'HH:mm:ss', timeInput: true";
2025-03-05 11:40:56 +01:00
return "<input id='fields-" . Adminer\h($field["field"]) . "' value='" . Adminer\h($value) . "'" . (@+$field["length"] ? " data-maxlength='" . (+$field["length"]) . "'" : "") . "$attrs>" . Adminer\script(
"jQuery('#fields-" . Adminer\js_escape($field["field"]) . "')."
2011-02-18 16:16:36 +01:00
. ($field["type"] == "time" ? "timepicker({ $timeFormat })"
2018-01-12 15:27:44 +01:00
: (preg_match("~time~", $field["type"]) ? "datetimepicker({ $dateFormat, $timeFormat })"
: "datepicker({ $dateFormat })"
2025-03-05 09:14:49 +01:00
)) . ";"
);
2011-02-18 16:16:36 +01:00
}
}
}