1 | <?php |
---|
2 | /** |
---|
3 | * Interface to jscalendar-1.0 |
---|
4 | * @package Smarty |
---|
5 | * @subpackage wf_plugins |
---|
6 | * @author boots |
---|
7 | * @author Sidnei Augusto Drovetto Junior |
---|
8 | * @version 1.1.2 |
---|
9 | * @link http://www.dynarch.com/projects/calendar/ {dhtml calendar} |
---|
10 | * (dynarch.com) |
---|
11 | * @param object &$smarty Instância do objeto smarty em uso |
---|
12 | * @param array $params Parameters array Following is the complete list of properties interpreted by Calendar.setup. |
---|
13 | * All of them have default values, so you can pass only those which you would like |
---|
14 | * to customize. |
---|
15 | * - Required: popup (inputField, displayArea, button), flat (flat) |
---|
16 | * - inputField string null The ID of your input field. |
---|
17 | * - displayArea string null |
---|
18 | * This is the ID of a <span>, <div>, or any other element that you would like |
---|
19 | * to use to display the current date. This is generally useful only if the |
---|
20 | * input field is hidden, as an area to display the date. |
---|
21 | * - button string null The ID of the calendar "trigger". This is an element (ordinarily a button or |
---|
22 | * an image) that will dispatch a certain event (usually "click") to the function that creates and displays the calendar. |
---|
23 | * |
---|
24 | * - eventName string "click" The name of the event that will trigger the calendar. The name should be |
---|
25 | * without the "on" prefix, such as "click" instead of "onclick". Virtually |
---|
26 | * all users will want to let this have the default value ("click"). Anyway, |
---|
27 | * it could be useful if, say, you want the calendar to appear when the input |
---|
28 | * field is focused and have no trigger button (in this case use "focus" as the |
---|
29 | * event name). |
---|
30 | * |
---|
31 | * - ifFormat string "%Y/%m/%d" |
---|
32 | * The format string that will be used to enter the date in the input field. |
---|
33 | * This format will be honored even if the input field is hidden. |
---|
34 | * |
---|
35 | * - daFormat string "%Y/%m/%d" |
---|
36 | * Format of the date displayed in the displayArea (if specified). |
---|
37 | * |
---|
38 | * - singleClick boolean true |
---|
39 | * Wether the calendar is in "single-click mode" or "double-click mode". If |
---|
40 | * true (the default) the calendar will be created in single-click mode. |
---|
41 | * |
---|
42 | * - disableFunc function null |
---|
43 | * A function that receives a JS Date object. It should return true if that |
---|
44 | * date has to be disabled, false otherwise. DEPRECATED (see below). |
---|
45 | * |
---|
46 | * - dateStatusFunc function null |
---|
47 | * A function that receives a JS Date object and returns a boolean or a string. |
---|
48 | * This function allows one to set a certain CSS class to some date, therefore |
---|
49 | * making it look different. If it returns true then the date will be disabled. |
---|
50 | * If it returns false nothing special happens with the given date. If it |
---|
51 | * returns a string then that will be taken as a CSS class and appended to the |
---|
52 | * date element. If this string is "disabled" then the date is also disabled |
---|
53 | * (therefore is like returning true). For more information please also refer |
---|
54 | * to section 4.3.8. |
---|
55 | * |
---|
56 | * - firstDay integer 0 |
---|
57 | * Specifies which day is to be displayed as the first day of week. Possible |
---|
58 | * values are 0 to 6; 0 means Sunday, 1 means Monday, ..., 6 means Saturday. |
---|
59 | * The end user can easily change this too, by clicking on the day name in the |
---|
60 | * calendar header. |
---|
61 | * |
---|
62 | * - weekNumbers boolean true |
---|
63 | * If "true" then the calendar will display week numbers. |
---|
64 | * |
---|
65 | * - align string "Bl" |
---|
66 | * Alignment of the calendar, relative to the reference element. The reference |
---|
67 | * element is dynamically chosen like this: if a displayArea is specified then |
---|
68 | * it will be the reference element. Otherwise, the input field is the |
---|
69 | * reference element. For the meaning of the alignment characters please |
---|
70 | * section 4.3.11. |
---|
71 | * |
---|
72 | * - range array [1900, 2999] |
---|
73 | * An array having exactly 2 elements, integers. (!) The first [0] element is |
---|
74 | * the minimum year that is available, and the second [1] element is the |
---|
75 | * maximum year that the calendar will allow. |
---|
76 | * |
---|
77 | * - flat string null |
---|
78 | * If you want a flat calendar, pass the ID of the parent object in this |
---|
79 | * property. If not, pass null here (or nothing at all as null is the default |
---|
80 | * value). |
---|
81 | * |
---|
82 | * - flatCallback function null |
---|
83 | * You should provide this function if the calendar is flat. It will be called |
---|
84 | * when the date in the calendar is changed with a reference to the calendar |
---|
85 | * object. See section 2.2 for an example of how to setup a flat calendar. |
---|
86 | * |
---|
87 | * - onSelect function null |
---|
88 | * If you provide a function handler here then you have to manage the |
---|
89 | * "click-on-date" event by yourself. Look in the calendar-setup.js and take as |
---|
90 | * an example the onSelect handler that you can see there. |
---|
91 | * |
---|
92 | * - onClose function null |
---|
93 | * This handler will be called when the calendar needs to close. You don't need |
---|
94 | * to provide one, but if you do it's your responsibility to hide/destroy the |
---|
95 | * calendar. You're on your own. Check the calendar-setup.js file for an |
---|
96 | * example. |
---|
97 | * |
---|
98 | * - onUpdate function null |
---|
99 | * If you supply a function handler here, it will be called right after the |
---|
100 | * target field is updated with a new date. You can use this to chain 2 |
---|
101 | * calendars, for instance to setup a default date in the second just after a |
---|
102 | * date was selected in the first. |
---|
103 | * |
---|
104 | * - date date null |
---|
105 | * This allows you to setup an initial date where the calendar will be |
---|
106 | * positioned to. If absent then the calendar will open to the today date. |
---|
107 | * |
---|
108 | * - showsTime boolean false |
---|
109 | * If this is set to true then the calendar will also allow time selection. |
---|
110 | * |
---|
111 | * - timeFormat string "24" |
---|
112 | * Set this to "12" or "24" to configure the way that the calendar will display |
---|
113 | * time. |
---|
114 | * |
---|
115 | * - electric boolean true |
---|
116 | * Set this to "false" if you want the calendar to update the field only when |
---|
117 | * closed (by default it updates the field at each date change, even if the |
---|
118 | * calendar is not closed) |
---|
119 | * |
---|
120 | * - position array null |
---|
121 | * Specifies the [x, y] position, relative to page's top-left corner, where the |
---|
122 | * calendar will be displayed. If not passed then the position will be computed |
---|
123 | * based on the "align" parameter. Defaults to "null" (not used). |
---|
124 | * |
---|
125 | * - cache boolean false |
---|
126 | * Set this to "true" if you want to cache the calendar object. This means that |
---|
127 | * a single calendar object will be used for all fields that require a popup |
---|
128 | * calendar |
---|
129 | * |
---|
130 | * - showOthers boolean false |
---|
131 | * If set to "true" then days belonging to months overlapping with the |
---|
132 | * currently displayed month will also be displayed in the calendar (but in a |
---|
133 | * "faded-out" color) |
---|
134 | * @access public |
---|
135 | * @return string código com os parametros de configuração a serem passados ao Calendar.setup |
---|
136 | */ |
---|
137 | function smarty_function_wf_calendar($params, &$smarty) |
---|
138 | { |
---|
139 | static $requires = array( |
---|
140 | 'flat' => 'string', |
---|
141 | 'inputField' => 'string', |
---|
142 | 'displayArea' => 'string', |
---|
143 | 'button' => 'string' |
---|
144 | ); |
---|
145 | |
---|
146 | static $allowed = array( |
---|
147 | 'date' => 'date', |
---|
148 | 'eventName' => 'string', |
---|
149 | 'cache' => 'boolean', |
---|
150 | 'multiple' => 'boolean', |
---|
151 | 'singleClick' => 'boolean', |
---|
152 | 'electric' => 'boolean', |
---|
153 | 'position' => 'array', |
---|
154 | 'align' => 'string', |
---|
155 | 'firstDay' => 'integer', |
---|
156 | 'weekNumbers' => 'boolean', |
---|
157 | 'range' => 'array', |
---|
158 | 'showOthers' => 'boolean', |
---|
159 | 'showsTime' => 'boolean', |
---|
160 | 'timeFormat' => 'string', |
---|
161 | 'ifFormat' => 'string', |
---|
162 | 'daFormat' => 'string', |
---|
163 | 'flatCallback' => 'function', |
---|
164 | 'dateStatusFunc' => 'function', |
---|
165 | 'dateTest' => 'function', |
---|
166 | 'onSelect' => 'function', |
---|
167 | 'onClose' => 'function', |
---|
168 | 'onUpdate' => 'function', |
---|
169 | 'name' => 'stromg', |
---|
170 | 'default' => 'boolean', |
---|
171 | 'value' => 'string' |
---|
172 | ); |
---|
173 | |
---|
174 | $output = ''; |
---|
175 | |
---|
176 | $path = $_SESSION['phpgw_info']['workflow']['server']['webserver_url'] . '/workflow/js/jscalendar/'; |
---|
177 | if (isset($params['path'])) |
---|
178 | $path = $params['path'] . '/'; |
---|
179 | |
---|
180 | $defaults = array( |
---|
181 | 'css' => $path . 'calendar-blue.css', |
---|
182 | 'src' => $path . 'calendar.js', |
---|
183 | 'lang' => $path . 'calendar-br.js', |
---|
184 | 'setup_src' => $path . 'calendar-setup.js', |
---|
185 | 'input_format' => $path . 'calendar-input.js'); |
---|
186 | |
---|
187 | foreach ($defaults as $field => $default) |
---|
188 | { |
---|
189 | $_field = "_{$field}"; |
---|
190 | if (array_key_exists($field, $params)) |
---|
191 | $$_field = (empty($params[$field])) ? $default : $params[$field]; |
---|
192 | else |
---|
193 | $$_field = $default; |
---|
194 | } |
---|
195 | |
---|
196 | static $wf_calendarJS = true; |
---|
197 | |
---|
198 | if ($wf_calendarJS) |
---|
199 | $output .= <<<EOF |
---|
200 | <link rel="stylesheet" type="text/css" media="all" href="{$_css}"> |
---|
201 | <script type="text/javascript" src="{$_src}"></script> |
---|
202 | <script type="text/javascript" src="{$_lang}"></script> |
---|
203 | <script type="text/javascript" src="{$_setup_src}"></script> |
---|
204 | <script type="text/javascript" src="{$_input_format}"></script> |
---|
205 | EOF; |
---|
206 | $wf_calendarJS = false; |
---|
207 | |
---|
208 | static $deprecated = array( |
---|
209 | 'disableFunc' => 'function' |
---|
210 | ); |
---|
211 | |
---|
212 | static $all = false; |
---|
213 | if (!$all) |
---|
214 | $all = array_merge($requires, $allowed, $deprecated); |
---|
215 | |
---|
216 | $inputFields = ""; |
---|
217 | if (isset($params['default']) && isset($params['name'])) |
---|
218 | if ($params['default'] == true) |
---|
219 | { |
---|
220 | $fieldValue = ""; |
---|
221 | if (isset($params['value'])) |
---|
222 | $fieldValue = $params['value']; |
---|
223 | $params['inputField'] = $params['name']; |
---|
224 | $params['button'] = $params['name'] . "-trigger"; |
---|
225 | $params['singleClick'] = true; |
---|
226 | $inputFields = "<input type=\"text\" id=\"" . $params['inputField'] . "\" name=\"" . $params['inputField'] . "\" value=\"" . $fieldValue . "\" size=\"10\" maxlength=\"10\" onkeypress=\"return(formatCalendarInput(this, event))\" onfocus=\"if (this.value == '$fieldValue') this.value='';\" onblur=\"if (this.value == '') this.value = '$fieldValue';\"/>"; |
---|
227 | $inputFields .= "\n<button id=\"" . $params['button'] . "\">...</button>"; |
---|
228 | } |
---|
229 | |
---|
230 | $_params = array(); |
---|
231 | |
---|
232 | foreach ($requires as $required => $type) |
---|
233 | { |
---|
234 | if (array_key_exists($required, $params) && !empty($params[$required])) |
---|
235 | { |
---|
236 | $_params[$required] = $params[$required]; |
---|
237 | } |
---|
238 | } |
---|
239 | if (empty($_params)) |
---|
240 | { |
---|
241 | $smarty->trigger_error("[wf_calendar] missing required parameter(s)", E_USER_ERROR); |
---|
242 | return false; |
---|
243 | } |
---|
244 | |
---|
245 | foreach ($allowed as $field=>$type) |
---|
246 | { |
---|
247 | if (array_key_exists($field, $params) && isset($params[$field])) |
---|
248 | { |
---|
249 | $_params[$field] = $params[$field]; |
---|
250 | } |
---|
251 | } |
---|
252 | |
---|
253 | foreach ($deprecated as $warn=>$type) |
---|
254 | { |
---|
255 | if (array_key_exists($warn, $params)) |
---|
256 | { |
---|
257 | $smarty->trigger_error("[dhtml_calendar] deprecated parameter '$warn'", E_USER_INFO); |
---|
258 | $_params[$warn] = $params[$warn]; |
---|
259 | } |
---|
260 | } |
---|
261 | |
---|
262 | $_params_out = ''; |
---|
263 | foreach ($_params as $field=>$value) |
---|
264 | { |
---|
265 | if (is_bool($value)) |
---|
266 | $value = $value ? 'true' : 'false'; |
---|
267 | else |
---|
268 | if (!is_numeric($value) && !($all[$field] == 'function')) |
---|
269 | $value = '"'.$value.'"'; |
---|
270 | if ($_params_out) |
---|
271 | $_params_out .= ','; |
---|
272 | $_params_out .= '"' . $field . '":' . $value; |
---|
273 | } |
---|
274 | |
---|
275 | $output .= $inputFields . '<script type="text/javascript">Calendar.setup({' . $_params_out . '});</script>'; |
---|
276 | return $output; |
---|
277 | } |
---|
278 | ?> |
---|