Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 49 lines (44 sloc) 2.487 kb
6cb8749 Jakub Vrána New plugin: Edit calendar
authored
1 <?php
2
3 /** Display jQuery UI Timepicker for each date and datetime field
4 * @uses jQuery-Timepicker, http://trentrichardson.com/examples/timepicker/
5 * @uses jQuery UI: core, widget, mouse, slider, datepicker
6 * @author Jakub Vrana, http://www.vrana.cz/
7 * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
8 * @license http://www.gnu.org/licenses/gpl-2.0.html GNU General Public License, version 2 (one or other)
9 */
10 class AdminerEditCalendar {
11 var $prepend;
12 var $langPath;
13
14 /**
15 * @param string text to append before first calendar usage
16 * @param string path to language file, %s stands for language code
17 */
18 function AdminerEditCalendar($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") { //! insert <link> by JavaScript to achieve HTML validity
19 $this->prepend = $prepend;
20 $this->langPath = $langPath;
21 }
22
23 function editInput($table, $field, $attrs, $value) {
24 static $calendar = false;
25 if (ereg("date|time", $field["type"])) {
26 if (!$calendar) {
27 $calendar = true;
28 echo $this->prepend;
29 if ($this->langPath && function_exists('get_lang')) { // since Adminer 3.2.0
30 $lang = get_lang();
31 $lang = ($lang == "zh" ? "zh-CN" : ($lang == "zh-tw" ? "zh-TW" : $lang));
32 if ($lang != "en" && file_exists(sprintf($this->langPath, $lang))) {
33 printf("<script type='text/javascript' src='$this->langPath'></script>\n", $lang);
34 echo "<script type='text/javascript'>jQuery(function () { jQuery.timepicker.setDefaults(jQuery.datepicker.regional['$lang']); });</script>\n";
35 }
36 }
37 }
38 $dateFormat = "changeYear: true, dateFormat: 'yy-mm-dd'"; //! yy-mm-dd regional
39 $timeFormat = "showSecond: true, timeFormat: 'hh:mm:ss'";
40 return "<input id='fields-" . h($field["field"]) . "' value='" . h($value) . "'" . ($maxlength ? " maxlength='$maxlength'" : "") . "$attrs><script type='text/javascript'>jQuery(function () { jQuery('#fields-" . js_escape($field["field"]) . "')."
41 . ($field["type"] == "time" ? "timepicker({ $timeFormat })"
42 : (ereg("time", $field["type"]) ? "datetimepicker({ $dateFormat, $timeFormat })"
43 : "datepicker({ $dateFormat })"
44 )) . "; });</script>";
45 }
46 }
47
48 }
Something went wrong with that request. Please try again.