[795] | 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 | static $allowed = array( |
---|
| 146 | 'date' => 'date', |
---|
| 147 | 'eventName' => 'string', |
---|
| 148 | 'cache' => 'boolean', |
---|
| 149 | 'multiple' => 'boolean', |
---|
| 150 | 'singleClick' => 'boolean', |
---|
| 151 | 'electric' => 'boolean', |
---|
| 152 | 'position' => 'array', |
---|
| 153 | 'align' => 'string', |
---|
| 154 | 'firstDay' => 'integer', |
---|
| 155 | 'weekNumbers' => 'boolean', |
---|
| 156 | 'range' => 'array', |
---|
| 157 | 'showOthers' => 'boolean', |
---|
| 158 | 'showsTime' => 'boolean', |
---|
| 159 | 'timeFormat' => 'string', |
---|
| 160 | 'ifFormat' => 'string', |
---|
| 161 | 'daFormat' => 'string', |
---|
| 162 | 'flatCallback' => 'function', |
---|
| 163 | 'dateStatusFunc' => 'function', |
---|
| 164 | 'dateTest' => 'function', |
---|
| 165 | 'onSelect' => 'function', |
---|
| 166 | 'onClose' => 'function', |
---|
| 167 | 'onUpdate' => 'function', |
---|
| 168 | 'name' => 'stromg', |
---|
| 169 | 'default' => 'boolean', |
---|
| 170 | 'value' => 'string'); |
---|
| 171 | |
---|
| 172 | static $deprecated = array( |
---|
| 173 | 'disableFunc' => 'function'); |
---|
| 174 | |
---|
| 175 | static $all = false; |
---|
| 176 | if (!$all) |
---|
| 177 | $all = array_merge($requires, $allowed, $deprecated); |
---|
| 178 | |
---|
| 179 | $inputFields = ""; |
---|
| 180 | if (isset($params['default']) && isset($params['name'])) |
---|
| 181 | if ($params['default'] == true) |
---|
| 182 | { |
---|
| 183 | $fieldValue = ""; |
---|
| 184 | if (isset($params['value'])) |
---|
| 185 | $fieldValue = $params['value']; |
---|
| 186 | $params['inputField'] = $params['name']; |
---|
| 187 | $params['button'] = $params['name'] . "-trigger"; |
---|
| 188 | $params['singleClick'] = true; |
---|
| 189 | $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';\"/>"; |
---|
| 190 | /* utilização de um elemento "input" do tipo "button" (ao invés de um elemento "button") para evitar que o calendário seja acionado ao se pressionar ENTER em nos campos do formulário */ |
---|
| 191 | //$inputFields .= "\n<button id=\"" . $params['button'] . "\">...</button>"; |
---|
| 192 | $inputFields .= "\n<input type=\"button\" id=\"" . $params['button'] . "\" value=\"...\"/>"; |
---|
| 193 | } |
---|
| 194 | |
---|
| 195 | $_params = array(); |
---|
| 196 | |
---|
| 197 | foreach ($requires as $required=>$type) |
---|
| 198 | { |
---|
| 199 | if (array_key_exists($required, $params) && !empty($params[$required])) |
---|
| 200 | { |
---|
| 201 | $_params[$required] = $params[$required]; |
---|
| 202 | } |
---|
| 203 | } |
---|
| 204 | if (empty($_params)) |
---|
| 205 | { |
---|
| 206 | $smarty->trigger_error("[wf_calendar] missing required parameter(s)", E_USER_ERROR); |
---|
| 207 | return false; |
---|
| 208 | } |
---|
| 209 | |
---|
| 210 | foreach ($allowed as $field=>$type) |
---|
| 211 | { |
---|
| 212 | if (array_key_exists($field, $params) && isset($params[$field])) |
---|
| 213 | { |
---|
| 214 | $_params[$field] = $params[$field]; |
---|
| 215 | } |
---|
| 216 | } |
---|
| 217 | |
---|
| 218 | foreach ($deprecated as $warn=>$type) |
---|
| 219 | { |
---|
| 220 | if (array_key_exists($warn, $params)) |
---|
| 221 | { |
---|
| 222 | $smarty->trigger_error("[dhtml_calendar] deprecated parameter '$warn'", E_USER_INFO); |
---|
| 223 | $_params[$warn] = $params[$warn]; |
---|
| 224 | } |
---|
| 225 | } |
---|
| 226 | |
---|
| 227 | $_params_out = ''; |
---|
| 228 | foreach ($_params as $field=>$value) |
---|
| 229 | { |
---|
| 230 | if (is_bool($value)) |
---|
| 231 | $value = $value ? 'true' : 'false'; |
---|
| 232 | else |
---|
| 233 | if (!is_numeric($value) && !($all[$field] == 'function')) |
---|
| 234 | $value = '"'.$value.'"'; |
---|
| 235 | if ($_params_out) |
---|
| 236 | $_params_out .= ','; |
---|
| 237 | $_params_out .= '"' . $field . '":' . $value; |
---|
| 238 | } |
---|
| 239 | |
---|
| 240 | return $inputFields . '<script type="text/javascript">Calendar.setup({' . $_params_out . '});</script>'; |
---|
| 241 | } |
---|
| 242 | ?> |
---|