1 | <?php |
---|
2 | /**************************************************************************\ |
---|
3 | * eGroupWare - API jsCalendar setup (set up jsCalendar with user prefs) * |
---|
4 | * http://www.eGroupWare.org * |
---|
5 | * Modified by Ralf Becker <RalfBecker@outdoor-training.de> * |
---|
6 | * This file is derived from jscalendar's calendar-setup.js file and the * |
---|
7 | * english translation in lang/calendar-en.js. * |
---|
8 | * -------------------------------------------- * |
---|
9 | * This program is free software; you can redistribute it and/or modify it * |
---|
10 | * under the terms of the GNU General Public License as published by the * |
---|
11 | * Free Software Foundation; either version 2 of the License, or (at your * |
---|
12 | * option) any later version. * |
---|
13 | \**************************************************************************/ |
---|
14 | |
---|
15 | |
---|
16 | $GLOBALS['phpgw_info']['flags'] = Array( |
---|
17 | 'currentapp' => 'home', // can't be phpgwapi, nor jscalendar (no own directory) |
---|
18 | 'noheader' => True, |
---|
19 | 'nonavbar' => True, |
---|
20 | 'noappheader' => True, |
---|
21 | 'noappfooter' => True, |
---|
22 | 'nofooter' => True, |
---|
23 | 'nocachecontrol' => True // allow cacheing |
---|
24 | ); |
---|
25 | |
---|
26 | include_once dirname( __FILE__ ) . '/../../header.inc.php'; |
---|
27 | header('Content-type: text/javascript; charset='.$GLOBALS['phpgw']->translation->charset()); |
---|
28 | $GLOBALS['phpgw']->translation->add_app('jscalendar'); |
---|
29 | |
---|
30 | $dateformat = $GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat']; |
---|
31 | $jsDateFormat = str_replace(array('Y','d','m','M'),array('%Y','%d','%m','%b'),$dateformat); |
---|
32 | $dayFirst = strpos($dateformat,'d') < strpos($dateformat,'m'); |
---|
33 | $jsLongDateFormat = '%a, '.($dayFirst ? '%e' : '%b').($dateformat[1] == '.' ? '. ' : ' ').($dayFirst ? '%b' : '%e'); |
---|
34 | |
---|
35 | /* Copyright Mihai Bazon, 2002, 2003 | http://dynarch.com/mishoo/ |
---|
36 | * --------------------------------------------------------------------------- |
---|
37 | * |
---|
38 | * The DHTML Calendar |
---|
39 | * |
---|
40 | * Details and latest version at: |
---|
41 | * http://dynarch.com/mishoo/calendar.epl |
---|
42 | * |
---|
43 | * This script is distributed under the GNU Lesser General Public License. |
---|
44 | * Read the entire license text here: http://www.gnu.org/licenses/lgpl.html |
---|
45 | * |
---|
46 | * This file defines helper functions for setting up the calendar. They are |
---|
47 | * intended to help non-programmers get a working calendar on their site |
---|
48 | * quickly. This script should not be seen as part of the calendar. It just |
---|
49 | * shows you what one can do with the calendar, while in the same time |
---|
50 | * providing a quick and simple method for setting it up. If you need |
---|
51 | * exhaustive customization of the calendar creation process feel free to |
---|
52 | * modify this code to suit your needs (this is recommended and much better |
---|
53 | * than modifying calendar.js itself). |
---|
54 | */ |
---|
55 | |
---|
56 | |
---|
57 | /** |
---|
58 | * This function "patches" an input field (or other element) to use a calendar |
---|
59 | * widget for date selection. |
---|
60 | * |
---|
61 | * The "params" is a single object that can have the following properties: |
---|
62 | * |
---|
63 | * prop. name | description |
---|
64 | * ------------------------------------------------------------------------------------------------- |
---|
65 | * inputField | the ID of an input field to store the date |
---|
66 | * displayArea | the ID of a DIV or other element to show the date |
---|
67 | * button | ID of a button or other element that will trigger the calendar |
---|
68 | * eventName | event that will trigger the calendar, without the "on" prefix (default: "click") |
---|
69 | * ifFormat | date format that will be stored in the input field |
---|
70 | * daFormat | the date format that will be used to display the date in displayArea |
---|
71 | * titleFormat | the format to show the month in the title, default '%B, %Y' |
---|
72 | * singleClick | (true/false) wether the calendar is in single click mode or not (default: true) |
---|
73 | * firstDay | numeric: 0 to 6. "0" means display Sunday first, "1" means display Monday first, etc. |
---|
74 | * disableFirstDowChange| (true/false) disables manual change of first day of week |
---|
75 | * align | alignment (default: "Br"); if you don't know what's this see the calendar documentation |
---|
76 | * range | array with 2 elements. Default: [1900, 2999] -- the range of years available |
---|
77 | * weekNumbers | (true/false) if it's true (default) the calendar will display week numbers |
---|
78 | * flat | null or element ID; if not null the calendar will be a flat calendar having the parent with the given ID |
---|
79 | * flatCallback | function that receives a JS Date object and returns an URL to point the browser to (for flat calendar) |
---|
80 | * flatWeekCallback| gets called if a weeknumber get clicked, params are the cal-object and a date-object representing the start of the week |
---|
81 | * flatWeekTTip | Tooltip for the weeknumber (shown only if flatWeekCallback is set) |
---|
82 | * flatMonthCallback| gets called if a month (title) get clicked, params are the cal-object and a date-object representing the start of the month |
---|
83 | * flatMonthTTip | Tooltip for the month (shown only if flatMonthCallback is set) |
---|
84 | * disableFunc | function that receives a JS Date object and should return true if that date has to be disabled in the calendar |
---|
85 | * onSelect | function that gets called when a date is selected. You don't _have_ to supply this (the default is generally okay) |
---|
86 | * onClose | function that gets called when the calendar is closed. [default] |
---|
87 | * onUpdate | function that gets called after the date is updated in the input field. Receives a reference to the calendar. |
---|
88 | * date | the date that the calendar will be initially displayed to |
---|
89 | * showsTime | default: false; if true the calendar will include a time selector |
---|
90 | * timeFormat | the time format; can be "12" or "24", default is "12" |
---|
91 | * electric | if true (default) then given fields/date areas are updated for each move; otherwise they're updated only on close |
---|
92 | * step | configures the step of the years in drop-down boxes; default: 2 |
---|
93 | * position | configures the calendar absolute position; default: null |
---|
94 | * cache | if "true" (but default: "false") it will reuse the same calendar object, where possible |
---|
95 | * showOthers | if "true" (but default: "false") it will show days from other months too |
---|
96 | * |
---|
97 | * None of them is required, they all have default values. However, if you |
---|
98 | * pass none of "inputField", "displayArea" or "button" you'll get a warning |
---|
99 | * saying "nothing to setup". |
---|
100 | */ |
---|
101 | ?> |
---|
102 | //<pre> |
---|
103 | Calendar.setup = function (params) { |
---|
104 | function param_default(pname, def) { if (typeof params[pname] == "undefined") { params[pname] = def; } }; |
---|
105 | |
---|
106 | param_default("inputField", null); |
---|
107 | param_default("displayArea", null); |
---|
108 | param_default("button", null); |
---|
109 | param_default("eventName", "click"); |
---|
110 | param_default("ifFormat", "<?php /* was "%Y/%m/%d" */ echo $jsDateFormat; ?>"); |
---|
111 | param_default("daFormat", "<?php /* was "%Y/%m/%d" */ echo $jsDateFormat; ?>"); |
---|
112 | param_default("titleFormat", "%B %Y"); |
---|
113 | param_default("singleClick", true); |
---|
114 | param_default("disableFunc", null); |
---|
115 | param_default("dateStatusFunc", params["disableFunc"]); // takes precedence if both are defined |
---|
116 | param_default("disableFirstDowChange", true); |
---|
117 | param_default("firstDay", <?php // was 0 defaults to "Sunday" first |
---|
118 | $day2int = array('Sunday'=>0,'Monday'=>1,'Tuesday'=>2,'Wednesday'=>3,'Thursday'=>4,'Friday'=>5,'Saturday'=>6); |
---|
119 | echo (int) @$day2int[$GLOBALS['phpgw_info']['user']['preferences']['calendar']['weekdaystarts']]; ?>); // <?php echo $GLOBALS['phpgw_info']['user']['preferences']['calendar']['weekdaystarts']."\n"; ?> |
---|
120 | param_default("align", "Bl"); |
---|
121 | param_default("range", [1900, 2999]); |
---|
122 | param_default("weekNumbers", true); |
---|
123 | param_default("flat", null); |
---|
124 | param_default("flatCallback", null); |
---|
125 | param_default("flatWeekCallback",null); |
---|
126 | param_default("flatWeekTTip", null); |
---|
127 | param_default("flatmonthCallback",null); |
---|
128 | param_default("flatmonthTTip", null); |
---|
129 | param_default("onSelect", null); |
---|
130 | param_default("onClose", null); |
---|
131 | param_default("onUpdate", null); |
---|
132 | param_default("date", null); |
---|
133 | param_default("showsTime", false); |
---|
134 | param_default("timeFormat", "<?php /* was 24 */ echo $GLOBALS['phpgw_info']['user']['preferences']['common']['timeformat']; ?>"); |
---|
135 | param_default("electric", true); |
---|
136 | param_default("step", 2); |
---|
137 | param_default("position", null); |
---|
138 | param_default("cache", true); |
---|
139 | param_default("showOthers", true); <?php /* was false */ ?> |
---|
140 | |
---|
141 | var tmp = ["inputField", "displayArea", "button"]; |
---|
142 | for (var i in tmp) { |
---|
143 | if (typeof params[tmp[i]] == "string") { |
---|
144 | params[tmp[i]] = document.getElementById(params[tmp[i]]); |
---|
145 | } |
---|
146 | } |
---|
147 | if (!(params.flat || params.inputField || params.displayArea || params.button)) { |
---|
148 | alert("Calendar.setup:\n Nothing to setup (no fields found). Please check your code"); |
---|
149 | return false; |
---|
150 | } |
---|
151 | |
---|
152 | function onSelect(cal) { |
---|
153 | var p = cal.params; |
---|
154 | var update = (cal.dateClicked || p.electric); |
---|
155 | if (update && p.flat) { |
---|
156 | if (typeof p.flatCallback == "function") |
---|
157 | p.flatCallback(cal); |
---|
158 | else |
---|
159 | alert("No flatCallback given -- doing nothing."); |
---|
160 | return false; |
---|
161 | } |
---|
162 | if (update && p.inputField) { |
---|
163 | p.inputField.value = cal.date.print(p.ifFormat); |
---|
164 | if (typeof p.inputField.onchange == "function") |
---|
165 | p.inputField.onchange(); |
---|
166 | } |
---|
167 | if (update && p.displayArea) |
---|
168 | p.displayArea.innerHTML = cal.date.print(p.daFormat); |
---|
169 | if (update && p.singleClick && cal.dateClicked) |
---|
170 | cal.callCloseHandler(); |
---|
171 | if (update && typeof p.onUpdate == "function") |
---|
172 | p.onUpdate(cal); |
---|
173 | }; |
---|
174 | |
---|
175 | if (params.flat != null) { |
---|
176 | if (typeof params.flat == "string") |
---|
177 | params.flat = document.getElementById(params.flat); |
---|
178 | if (!params.flat) { |
---|
179 | alert("Calendar.setup:\n Flat specified but can't find parent."); |
---|
180 | return false; |
---|
181 | } |
---|
182 | var cal = new Calendar(params.firstDay, params.date, params.onSelect || onSelect); |
---|
183 | cal.showsTime = params.showsTime; |
---|
184 | cal.time24 = (params.timeFormat == "24"); |
---|
185 | cal.params = params; |
---|
186 | cal.weekNumbers = params.weekNumbers; |
---|
187 | cal.setRange(params.range[0], params.range[1]); |
---|
188 | cal.setDateStatusHandler(params.dateStatusFunc); |
---|
189 | cal.showsOtherMonths = params.showOthers; |
---|
190 | cal.create(params.flat); |
---|
191 | cal.show(); |
---|
192 | return false; |
---|
193 | } |
---|
194 | |
---|
195 | var triggerEl = params.button || params.displayArea || params.inputField; |
---|
196 | triggerEl["on" + params.eventName] = function() { |
---|
197 | var dateEl = params.inputField || params.displayArea; |
---|
198 | var dateFmt = params.inputField ? params.ifFormat : params.daFormat; |
---|
199 | var mustCreate = false; |
---|
200 | var cal = window.calendar; |
---|
201 | if (!(cal && params.cache)) { |
---|
202 | window.calendar = cal = new Calendar(params.firstDay, |
---|
203 | params.date, |
---|
204 | params.onSelect || onSelect, |
---|
205 | params.onClose || function(cal) { cal.hide(); }); |
---|
206 | cal.showsTime = params.showsTime; |
---|
207 | cal.time24 = (params.timeFormat == "24"); |
---|
208 | cal.weekNumbers = params.weekNumbers; |
---|
209 | mustCreate = true; |
---|
210 | } else { |
---|
211 | if (params.date) |
---|
212 | cal.setDate(params.date); |
---|
213 | cal.hide(); |
---|
214 | } |
---|
215 | cal.showsOtherMonths = params.showOthers; |
---|
216 | cal.yearStep = params.step; |
---|
217 | cal.setRange(params.range[0], params.range[1]); |
---|
218 | cal.params = params; |
---|
219 | cal.setDateStatusHandler(params.dateStatusFunc); |
---|
220 | cal.setDateFormat(dateFmt); |
---|
221 | if (mustCreate) |
---|
222 | cal.create(); |
---|
223 | cal.parseDate(dateEl.value || dateEl.innerHTML); |
---|
224 | cal.refresh(); |
---|
225 | if (!params.position) |
---|
226 | cal.showAtElement(params.button || params.displayArea || params.inputField, params.align); |
---|
227 | else |
---|
228 | cal.showAt(params.position[0], params.position[1]); |
---|
229 | return false; |
---|
230 | }; |
---|
231 | }; |
---|
232 | |
---|
233 | // eGroupWare translations, are read from the database |
---|
234 | |
---|
235 | // ** I18N |
---|
236 | |
---|
237 | // Calendar EN language |
---|
238 | // Author: Mihai Bazon, <mishoo@infoiasi.ro> |
---|
239 | // Encoding: any |
---|
240 | // Distributed under the same terms as the calendar itself. |
---|
241 | |
---|
242 | Calendar._DN = new Array |
---|
243 | (<?php // full day names |
---|
244 | foreach($day2int as $name => $n) |
---|
245 | { |
---|
246 | echo "\n \"".lang($name).'"'.($n < 6 ? ',' : ''); |
---|
247 | } |
---|
248 | ?>); |
---|
249 | |
---|
250 | Calendar._SDN = new Array |
---|
251 | (<?php // short day names |
---|
252 | foreach($day2int as $name => $n) |
---|
253 | { |
---|
254 | echo "\n \"".substr(lang($name),0,(int)lang('3 number of chars for day-shortcut')).'"'.($n < 6 ? ',' : ''); |
---|
255 | } |
---|
256 | ?>); |
---|
257 | Calendar._SDN_len = <?php echo (int) lang('3 number of chars for day-shortcut'); ?>; |
---|
258 | |
---|
259 | Calendar._MN = new Array |
---|
260 | (<?php // full month names |
---|
261 | $monthnames = array('January','February','March','April','May','June','July','August','September','October','November','December'); |
---|
262 | foreach($monthnames as $n => $name) |
---|
263 | { |
---|
264 | echo "\n \"".lang($name).'"'.($n < 11 ? ',' : ''); |
---|
265 | } |
---|
266 | ?>); |
---|
267 | |
---|
268 | Calendar._SMN = new Array |
---|
269 | (<?php // short month names |
---|
270 | $monthnames = array('January','February','March','April','May','June','July','August','September','October','November','December'); |
---|
271 | foreach($monthnames as $n => $name) |
---|
272 | { |
---|
273 | $short = lang(substr($name,0,3)); // test if our lang-file have a translation for the english short with 3 chars |
---|
274 | if (substr($short,-1) == '*') // else create one by truncating the full translation to x chars |
---|
275 | { |
---|
276 | $short = substr(lang($name),0,(int)lang('3 number of chars for month-shortcut')); |
---|
277 | } |
---|
278 | echo "\n \"".$short.'"'.($n < 11 ? ',' : ''); |
---|
279 | } |
---|
280 | ?>); |
---|
281 | Calendar._SMN_len = <?php echo (int) lang('3 number of chars for month-shortcut'); ?>; |
---|
282 | |
---|
283 | // tooltips |
---|
284 | Calendar._TT = {}; |
---|
285 | Calendar._TT["INFO"] = "<?php echo lang('About the calendar'); ?>"; |
---|
286 | |
---|
287 | Calendar._TT["ABOUT"] = |
---|
288 | "DHTML Date/Time Selector\n" + |
---|
289 | "(c) dynarch.com 2002-2003\n" + // don't translate this this ;-) |
---|
290 | "For latest version visit: http://dynarch.com/mishoo/calendar.epl\n" + |
---|
291 | "Distributed under GNU LGPL. See http://gnu.org/licenses/lgpl.html for details." + |
---|
292 | "\n\n" + |
---|
293 | "<?php echo lang('Date selection:'); ?>\n" + |
---|
294 | "<?php echo lang('- Use the %1, %2 buttons to select year','\xab','\xbb'); ?>\n" + |
---|
295 | "<?php echo lang('- Use the %1, %2 buttons to select month','" + String.fromCharCode(0x2039) + "','" + String.fromCharCode(0x203a) + "'); ?>\n" + |
---|
296 | "<?php echo lang('- Hold mouse button on any of the above buttons for faster selection.'); ?>"; |
---|
297 | Calendar._TT["ABOUT_TIME"] = "\n\n" + |
---|
298 | "<?php echo lang('Time selection:'); ?>\n" + |
---|
299 | "<?php echo lang('- Click on any of the time parts to increase it'); ?>\n" + |
---|
300 | "<?php echo lang('- or Shift-click to decrease it'); ?>\n" + |
---|
301 | "<?php echo lang('- or click and drag for faster selection.'); ?>"; |
---|
302 | |
---|
303 | Calendar._TT["TOGGLE"] = "<?php echo lang('Toggle first day of week'); ?>"; |
---|
304 | Calendar._TT["PREV_YEAR"] = "<?php echo lang('Prev. year (hold for menu)'); ?>"; |
---|
305 | Calendar._TT["PREV_MONTH"] = "<?php echo lang('Prev. month (hold for menu)'); ?>"; |
---|
306 | Calendar._TT["GO_TODAY"] = "<?php echo lang('Go Today'); ?>"; |
---|
307 | Calendar._TT["NEXT_MONTH"] = "<?php echo lang('Next month (hold for menu)'); ?>"; |
---|
308 | Calendar._TT["NEXT_YEAR"] = "<?php echo lang('Next year (hold for menu)'); ?>"; |
---|
309 | Calendar._TT["SEL_DATE"] = "<?php echo lang('Select date'); ?>"; |
---|
310 | Calendar._TT["DRAG_TO_MOVE"] = "<?php echo lang('Drag to move'); ?>"; |
---|
311 | Calendar._TT["PART_TODAY"] = " (<?php echo lang('today'); ?>)"; |
---|
312 | |
---|
313 | // the following is to inform that "%s" is to be the first day of week |
---|
314 | // %s will be replaced with the day name. |
---|
315 | Calendar._TT["DAY_FIRST"] = "<?php echo lang('Display %s first'); ?>"; |
---|
316 | |
---|
317 | // This may be locale-dependent. It specifies the week-end days, as an array |
---|
318 | // of comma-separated numbers. The numbers are from 0 to 6: 0 means Sunday, 1 |
---|
319 | // means Monday, etc. |
---|
320 | Calendar._TT["WEEKEND"] = "0,6"; |
---|
321 | |
---|
322 | Calendar._TT["CLOSE"] = "<?php echo lang('Close'); ?>"; |
---|
323 | Calendar._TT["TODAY"] = "<?php echo lang('Today'); ?>"; |
---|
324 | Calendar._TT["TIME_PART"] = "<?php echo lang('(Shift-)Click or drag to change value'); ?>"; |
---|
325 | |
---|
326 | // date formats |
---|
327 | //Calendar._TT["DEF_DATE_FORMAT"] = "%Y-%m-%d"; |
---|
328 | Calendar._TT["DEF_DATE_FORMAT"] = "<?php echo $jsDateFormat; ?>"; |
---|
329 | //Calendar._TT["TT_DATE_FORMAT"] = "%a, %b %e"; |
---|
330 | Calendar._TT["TT_DATE_FORMAT"] = "<?php echo $jsLongDateFormat; ?>"; |
---|
331 | |
---|
332 | Calendar._TT["WK"] = "<?php echo lang('Wk'); ?>"; |
---|
333 | Calendar._TT["TIME"] = "<?php echo lang('Time'); ?>:"; |
---|