| 135 | | //----- Time Hour Interval proccess ---- |
|---|
| 136 | | if ($minute_start == '-') { |
|---|
| 137 | | $time_minute_start = "*"; |
|---|
| 138 | | } else { |
|---|
| 139 | | $time_minute_start = sprintf("%02d",$minute_start); |
|---|
| 140 | | } |
|---|
| 141 | | if ($minute_finish == '-') { |
|---|
| 142 | | $time_minute_finish = "*"; |
|---|
| 143 | | } else { |
|---|
| 144 | | $time_minute_finish = sprintf("%02d",$minute_finish); |
|---|
| 145 | | } |
|---|
| 146 | | if ($hour_start == '-') { |
|---|
| 147 | | $time_hour_start = '*'; |
|---|
| 148 | | } else { |
|---|
| 149 | | $time_hour_start = sprintf("%02d",$hour_start) . ':' . $time_minute_start; |
|---|
| 150 | | } |
|---|
| 151 | | if ($hour_finish == '-') { |
|---|
| 152 | | $time_hour_finish = '*'; |
|---|
| 153 | | } else { |
|---|
| 154 | | $time_hour_finish = sprintf("%02d",$hour_finish) . ':' . $time_minute_finish; |
|---|
| 155 | | } |
|---|
| 156 | | if ($time_hour_start == $time_hour_finish) { |
|---|
| 157 | | $time_hour = $time_hour_start; |
|---|
| 158 | | } else { |
|---|
| 159 | | $time_hour = $time_hour_start . '-' . $time_hour_finish; |
|---|
| 160 | | } |
|---|
| 161 | | //----- Time Week Day Interval proccess ----- |
|---|
| 162 | | if ($wday_start == '-') { |
|---|
| 163 | | $time_wday_start = '*'; |
|---|
| 164 | | } else { |
|---|
| 165 | | $time_wday_start = $wday_start; |
|---|
| 166 | | } |
|---|
| 167 | | if ($wday_finish == '-') { |
|---|
| 168 | | $time_wday_finish = '*'; |
|---|
| 169 | | } else { |
|---|
| 170 | | $time_wday_finish = $wday_finish; |
|---|
| 171 | | } |
|---|
| 172 | | if ($time_wday_start == $time_wday_finish) { |
|---|
| 173 | | $time_wday = $time_wday_start; |
|---|
| 174 | | } else { |
|---|
| 175 | | $time_wday = $time_wday_start . '-' . $time_wday_finish; |
|---|
| 176 | | } |
|---|
| 177 | | //----- Time Month Day Interval proccess ----- |
|---|
| 178 | | if ($mday_start == '-') { |
|---|
| 179 | | $time_mday_start = '*'; |
|---|
| 180 | | } else { |
|---|
| 181 | | $time_mday_start = $mday_start; |
|---|
| 182 | | } |
|---|
| 183 | | if ($mday_finish == '-') { |
|---|
| 184 | | $time_mday_finish = '*'; |
|---|
| 185 | | } else { |
|---|
| 186 | | $time_mday_finish = $mday_finish; |
|---|
| 187 | | } |
|---|
| 188 | | if ($time_mday_start == $time_mday_finish) { |
|---|
| 189 | | $time_mday = $time_mday_start; |
|---|
| 190 | | } else { |
|---|
| 191 | | $time_mday = $time_mday_start . '-' . $time_mday_finish; |
|---|
| 192 | | } |
|---|
| 193 | | //----- Time Month Interval proccess ----- |
|---|
| 194 | | if ($month_start == '-') { |
|---|
| 195 | | $time_month_start = '*'; |
|---|
| 196 | | } else { |
|---|
| 197 | | $time_month_start = $month_start; |
|---|
| 198 | | } |
|---|
| 199 | | if ($month_finish == '-') { |
|---|
| 200 | | $time_month_finish = '*'; |
|---|
| 201 | | } else { |
|---|
| 202 | | $time_month_finish = $month_finish; |
|---|
| 203 | | } |
|---|
| 204 | | if ($time_month_start == $time_month_finish) { |
|---|
| 205 | | $time_month = $time_month_start; |
|---|
| 206 | | } else { |
|---|
| 207 | | $time_month = $time_month_start . '-' . $time_month_finish; |
|---|
| 208 | | } |
|---|
| 209 | | $time = $time_hour . '|' . $time_wday . '|' . $time_mday . '|' . $time_month; |
|---|
| 210 | | return $time; |
|---|
| | 141 | //----- Time Hour Interval proccess ---- |
|---|
| | 142 | // |
|---|
| | 143 | if ($minute_start == '-') { |
|---|
| | 144 | $time_minute_start = "*"; |
|---|
| | 145 | } else { |
|---|
| | 146 | $time_minute_start = sprintf("%02d",$minute_start); |
|---|
| | 147 | } |
|---|
| | 148 | if ($minute_finish == '-') { |
|---|
| | 149 | $time_minute_finish = "*"; |
|---|
| | 150 | } else { |
|---|
| | 151 | $time_minute_finish = sprintf("%02d",$minute_finish); |
|---|
| | 152 | } |
|---|
| | 153 | if ($hour_start == '-') { |
|---|
| | 154 | $time_hour_start = '*'; |
|---|
| | 155 | } else { |
|---|
| | 156 | $time_hour_start = sprintf("%02d",$hour_start) . ':' . $time_minute_start; |
|---|
| | 157 | } |
|---|
| | 158 | if ($hour_finish == '-') { |
|---|
| | 159 | $time_hour_finish = '*'; |
|---|
| | 160 | } else { |
|---|
| | 161 | $time_hour_finish = sprintf("%02d",$hour_finish) . ':' . $time_minute_finish; |
|---|
| | 162 | } |
|---|
| | 163 | if ($time_hour_start == $time_hour_finish) { |
|---|
| | 164 | $time_hour = $time_hour_start; |
|---|
| | 165 | } else { |
|---|
| | 166 | $time_hour = $time_hour_start . '-' . $time_hour_finish; |
|---|
| | 167 | } |
|---|
| | 168 | |
|---|
| | 169 | //----- Time Week Day Interval proccess ----- |
|---|
| | 170 | // |
|---|
| | 171 | if ($wday_start == '-') { |
|---|
| | 172 | $time_wday_start = '*'; |
|---|
| | 173 | } else { |
|---|
| | 174 | $time_wday_start = $wday_start; |
|---|
| | 175 | } |
|---|
| | 176 | if ($wday_finish == '-') { |
|---|
| | 177 | $time_wday_finish = '*'; |
|---|
| | 178 | } else { |
|---|
| | 179 | $time_wday_finish = $wday_finish; |
|---|
| | 180 | } |
|---|
| | 181 | if ($time_wday_start == $time_wday_finish) { |
|---|
| | 182 | $time_wday = $time_wday_start; |
|---|
| | 183 | } else { |
|---|
| | 184 | $time_wday = $time_wday_start . '-' . $time_wday_finish; |
|---|
| | 185 | } |
|---|
| | 186 | |
|---|
| | 187 | //----- Time Month Day Interval proccess ----- |
|---|
| | 188 | // |
|---|
| | 189 | if ($mday_start == '-') { |
|---|
| | 190 | $time_mday_start = '*'; |
|---|
| | 191 | } else { |
|---|
| | 192 | $time_mday_start = $mday_start; |
|---|
| | 193 | } |
|---|
| | 194 | if ($mday_finish == '-') { |
|---|
| | 195 | $time_mday_finish = '*'; |
|---|
| | 196 | } else { |
|---|
| | 197 | $time_mday_finish = $mday_finish; |
|---|
| | 198 | } |
|---|
| | 199 | if ($time_mday_start == $time_mday_finish) { |
|---|
| | 200 | $time_mday = $time_mday_start; |
|---|
| | 201 | } else { |
|---|
| | 202 | $time_mday = $time_mday_start . '-' . $time_mday_finish; |
|---|
| | 203 | } |
|---|
| | 204 | |
|---|
| | 205 | //----- Time Month Interval proccess ----- |
|---|
| | 206 | // |
|---|
| | 207 | if ($month_start == '-') { |
|---|
| | 208 | $time_month_start = '*'; |
|---|
| | 209 | } else { |
|---|
| | 210 | $time_month_start = $month_start; |
|---|
| | 211 | } |
|---|
| | 212 | if ($month_finish == '-') { |
|---|
| | 213 | $time_month_finish = '*'; |
|---|
| | 214 | } else { |
|---|
| | 215 | $time_month_finish = $month_finish; |
|---|
| | 216 | } |
|---|
| | 217 | if ($time_month_start == $time_month_finish) { |
|---|
| | 218 | $time_month = $time_month_start; |
|---|
| | 219 | } else { |
|---|
| | 220 | $time_month = $time_month_start . '-' . $time_month_finish; |
|---|
| | 221 | } |
|---|
| | 222 | $time = $time_hour . '|' . $time_wday . '|' . $time_mday . '|' . $time_month; |
|---|
| | 223 | return $time; |
|---|
| | 258 | |
|---|
| | 259 | |
|---|
| | 260 | |
|---|
| | 261 | /* |
|---|
| | 262 | The following functions are available to other modules. |
|---|
| | 263 | |
|---|
| | 264 | function timeconditions_timegroups_add_group($description,$times=null) return the inserted id |
|---|
| | 265 | expects an array of times, each an associative array |
|---|
| | 266 | Array ( [0] => Array ( [hour_start] => - [minute_start] => - [hour_finish] => - |
|---|
| | 267 | [minute_finish] => - [wday_start] => - [wday_finish] => - [mday_start] => - |
|---|
| | 268 | [mday_finish] => - [month_start] => - [month_finish] => - ) ) |
|---|
| | 269 | |
|---|
| | 270 | function timeconditions_timegroups_add_group_timestrings($description,$times=null) return the inserted id |
|---|
| | 271 | alternative to above. expects an array of time strings instead of associative array of hours minutes etc. |
|---|
| | 272 | |
|---|
| | 273 | function timeconditions_timegroups_list_groups() |
|---|
| | 274 | returns an array of id and descriptions for any time groups defined by the user |
|---|
| | 275 | the array contains inidces 0 and 1 for the rnav and associative value and text for select boxes |
|---|
| | 276 | |
|---|
| | 277 | function timeconditions_timegroups_get_times($timegroup) |
|---|
| | 278 | returns an array of id and time string of the users time selections for the selected timegroup |
|---|
| | 279 | |
|---|
| | 280 | function timeconditions_timegroups_buildtime( $hour_start, $minute_start, $hour_finish, $minute_finish, $wday_start, $wday_finish, $mday_start, $mday_finish, $month_start, $month_finish) |
|---|
| | 281 | should never be needed by another module, as this module should be the only place creating the time string, as it returns the string to other modules. |
|---|
| | 282 | |
|---|
| | 283 | function timeconditions_timegroups_drawtimeselects($name, $time) |
|---|
| | 284 | should never be needed by another module, as this module should be the only place drawing the time selects |
|---|
| | 285 | */ |
|---|
| | 286 | |
|---|
| | 287 | //lists any time groups defined by the user |
|---|
| | 288 | function timeconditions_timegroups_list_groups() { |
|---|
| | 289 | global $db; |
|---|
| | 290 | |
|---|
| | 291 | $sql = "select id, description from timegroups_groups order by description"; |
|---|
| | 292 | $results = $db->getAll($sql); |
|---|
| | 293 | if(DB::IsError($results)) { |
|---|
| | 294 | $results = null; |
|---|
| | 295 | } |
|---|
| | 296 | foreach ($results as $val) { |
|---|
| | 297 | $tmparray[] = array($val[0], $val[1], "value" => $val[0], "text" => $val[1]); |
|---|
| | 298 | } |
|---|
| | 299 | return $tmparray; |
|---|
| | 300 | } |
|---|
| | 301 | |
|---|
| | 302 | //--------------------------------------------- |
|---|
| | 303 | |
|---|
| | 304 | //timegroups page helper |
|---|
| | 305 | //we are using gui styles so there is very little on the page |
|---|
| | 306 | //the timegroups page is used to create time string |
|---|
| | 307 | //to be used by other modules for gotoif or includes or IFTIME func |
|---|
| | 308 | function timeconditions_timegroups_configpageinit($dispnum) { |
|---|
| | 309 | global $currentcomponent; |
|---|
| | 310 | |
|---|
| | 311 | switch ($dispnum) { |
|---|
| | 312 | case 'timegroups': |
|---|
| | 313 | $currentcomponent->addguifunc('timeconditions_timegroups_configpageload'); |
|---|
| | 314 | $currentcomponent->addprocessfunc('timeconditions_timegroups_configprocess', 5); |
|---|
| | 315 | break; |
|---|
| | 316 | } |
|---|
| | 317 | } |
|---|
| | 318 | |
|---|
| | 319 | //actually render the timegroups page |
|---|
| | 320 | function timeconditions_timegroups_configpageload() { |
|---|
| | 321 | global $currentcomponent; |
|---|
| | 322 | |
|---|
| | 323 | $descerr = 'Description must be alpha-numeric, and may not be left blank'; |
|---|
| | 324 | $extdisplay = isset($_REQUEST['extdisplay'])?$_REQUEST['extdisplay']:null; |
|---|
| | 325 | $action= isset($_REQUEST['action'])?$_REQUEST['action']:null; |
|---|
| | 326 | if ($action == 'del') { |
|---|
| | 327 | $currentcomponent->addguielem('_top', new gui_pageheading('title', _("Time Group").": $extdisplay"." deleted!", false), 0); |
|---|
| | 328 | unset($extdisplay); |
|---|
| | 329 | } |
|---|
| | 330 | //need to get page name/type dynamically |
|---|
| | 331 | $query = ($_SERVER['QUERY_STRING'])?$_SERVER['QUERY_STRING']:'type=setup&display=timegroups&extdisplay='.$extdisplay; |
|---|
| | 332 | $delURL = $_SERVER['PHP_SELF'].'?'.$query.'&action=del'; |
|---|
| | 333 | $info = ''; |
|---|
| | 334 | if (!$extdisplay) { |
|---|
| | 335 | $currentcomponent->addguielem('_top', new gui_pageheading('title', _("Add Time Group"), false), 0); |
|---|
| | 336 | $currentcomponent->addguielem('Time Group', new gui_textbox('description', '', 'Description', 'This will display as the name of this Time Group.', '!isAlphanumeric() || isWhitespace()', $descerr, false), 3); |
|---|
| | 337 | } else { |
|---|
| | 338 | $savedtimegroup= timeconditions_timegroups_get_group($extdisplay); |
|---|
| | 339 | $timegroup = $savedtimegroup[0]; |
|---|
| | 340 | $description = $savedtimegroup[1]; |
|---|
| | 341 | $currentcomponent->addguielem('_top', new gui_hidden('extdisplay', $extdisplay)); |
|---|
| | 342 | $currentcomponent->addguielem('_top', new gui_pageheading('title', _("Edit Time Group").": $description", false), 0); |
|---|
| | 343 | $currentcomponent->addguielem('_top', new gui_link('del', _("Delete Time Group")." $timegroup", $delURL, true, false), 0); |
|---|
| | 344 | $currentcomponent->addguielem('Time Group', new gui_textbox('description', $description, 'Description', 'This will display as the name of this Time Group.', '', '', false), 3); |
|---|
| | 345 | $timelist = timeconditions_timegroups_get_times($extdisplay); |
|---|
| | 346 | foreach ($timelist as $val) { |
|---|
| | 347 | $timehtml = timeconditions_timegroups_drawtimeselects('times['.$val[0].']',$val[1]); |
|---|
| | 348 | $timehtml = '<tr><td colspan="2"><table>'.$timehtml.'</table></td></tr>'; |
|---|
| | 349 | $currentcomponent->addguielem($val[1], new guielement('dest0', $timehtml, ''),5); |
|---|
| | 350 | } |
|---|
| | 351 | } |
|---|
| | 352 | $timehtml = timeconditions_timegroups_drawtimeselects('times[new]',null); |
|---|
| | 353 | $timehtml = '<tr><td colspan="2"><table>'.$timehtml.'</table></td></tr>'; |
|---|
| | 354 | $currentcomponent->addguielem('New Time', new guielement('dest0', $timehtml, ''),6); |
|---|
| | 355 | $currentcomponent->addguielem('_top', new gui_hidden('action', ($extdisplay ? 'edit' : 'add'))); |
|---|
| | 356 | } |
|---|
| | 357 | |
|---|
| | 358 | //handle timegroups page submit button |
|---|
| | 359 | function timeconditions_timegroups_configprocess() { |
|---|
| | 360 | $action= isset($_REQUEST['action'])?$_REQUEST['action']:null; |
|---|
| | 361 | $timegroup= isset($_REQUEST['extdisplay'])?$_REQUEST['extdisplay']:null; |
|---|
| | 362 | $description= isset($_REQUEST['description'])?$_REQUEST['description']:null; |
|---|
| | 363 | $times = isset($_REQUEST['times'])?$_REQUEST['times']:null; |
|---|
| | 364 | |
|---|
| | 365 | //addslashes |
|---|
| | 366 | switch ($action) { |
|---|
| | 367 | case 'add': |
|---|
| | 368 | timeconditions_timegroups_add_group($description,$times); |
|---|
| | 369 | break; |
|---|
| | 370 | case 'edit': |
|---|
| | 371 | timeconditions_timegroups_edit_group($timegroup,$description); |
|---|
| | 372 | timeconditions_timegroups_edit_times($timegroup,$times); |
|---|
| | 373 | break; |
|---|
| | 374 | case 'del': |
|---|
| | 375 | timeconditions_timegroups_del_group($timegroup); |
|---|
| | 376 | break; |
|---|
| | 377 | } |
|---|
| | 378 | } |
|---|
| | 379 | |
|---|
| | 380 | //these are the users time selections for the current timegroup |
|---|
| | 381 | function timeconditions_timegroups_get_times($timegroup) { |
|---|
| | 382 | global $db; |
|---|
| | 383 | |
|---|
| | 384 | $sql = "select id, time from timegroups_details where timegroupid = $timegroup"; |
|---|
| | 385 | $results = $db->getAll($sql); |
|---|
| | 386 | if(DB::IsError($results)) { |
|---|
| | 387 | $results = null; |
|---|
| | 388 | } |
|---|
| | 389 | foreach ($results as $val) { |
|---|
| | 390 | $tmparray[] = array($val[0], $val[1]); |
|---|
| | 391 | } |
|---|
| | 392 | return $tmparray; |
|---|
| | 393 | } |
|---|
| | 394 | |
|---|
| | 395 | //retrieve a single timegroup for the timegroups page |
|---|
| | 396 | function timeconditions_timegroups_get_group($timegroup) { |
|---|
| | 397 | global $db; |
|---|
| | 398 | |
|---|
| | 399 | $sql = "select id, description from timegroups_groups where id = $timegroup"; |
|---|
| | 400 | $results = $db->getAll($sql); |
|---|
| | 401 | if(DB::IsError($results)) { |
|---|
| | 402 | $results = null; |
|---|
| | 403 | } |
|---|
| | 404 | $tmparray = array($results[0][0], $results[0][1]); |
|---|
| | 405 | return $tmparray; |
|---|
| | 406 | } |
|---|
| | 407 | |
|---|
| | 408 | //add a new timegroup for timegroups page |
|---|
| | 409 | //expects an array of times, each an associative array |
|---|
| | 410 | //Array ( [0] => Array ( [hour_start] => - [minute_start] => - [hour_finish] => - |
|---|
| | 411 | //[minute_finish] => - [wday_start] => - [wday_finish] => - [mday_start] => - |
|---|
| | 412 | //[mday_finish] => - [month_start] => - [month_finish] => - ) ) |
|---|
| | 413 | function timeconditions_timegroups_add_group($description,$times=null) { |
|---|
| | 414 | global $db; |
|---|
| | 415 | |
|---|
| | 416 | $sql = "insert timegroups_groups(description) VALUES ('$description')"; |
|---|
| | 417 | $db->query($sql); |
|---|
| | 418 | $timegroup=mysql_insert_id(); |
|---|
| | 419 | if (isset($times)) { |
|---|
| | 420 | timeconditions_timegroups_edit_times($timegroup,$times); |
|---|
| | 421 | } |
|---|
| | 422 | needreload(); |
|---|
| | 423 | return $timegroup; |
|---|
| | 424 | } |
|---|
| | 425 | |
|---|
| | 426 | function timeconditions_timegroups_add_group_timestrings($description,$timestrings) { |
|---|
| | 427 | global $db; |
|---|
| | 428 | |
|---|
| | 429 | $sql = "insert timegroups_groups(description) VALUES ('$description')"; |
|---|
| | 430 | $db->query($sql); |
|---|
| | 431 | $timegroup=mysql_insert_id(); |
|---|
| | 432 | timeconditions_timegroups_edit_timestrings($timegroup,$timestrings); |
|---|
| | 433 | needreload(); |
|---|
| | 434 | return $timegroup; |
|---|
| | 435 | } |
|---|
| | 436 | |
|---|
| | 437 | //delete a single timegroup from the timegroups page |
|---|
| | 438 | function timeconditions_timegroups_del_group($timegroup) { |
|---|
| | 439 | global $db; |
|---|
| | 440 | |
|---|
| | 441 | $sql = "delete from timegroups_details where timegroupid = $timegroup"; |
|---|
| | 442 | $db->query($sql); |
|---|
| | 443 | $sql = "delete from timegroups_groups where id = $timegroup"; |
|---|
| | 444 | $db->query($sql); |
|---|
| | 445 | needreload(); |
|---|
| | 446 | } |
|---|
| | 447 | |
|---|
| | 448 | //update a single timegroup from the timegroups page |
|---|
| | 449 | function timeconditions_timegroups_edit_group($timegroup,$description) { |
|---|
| | 450 | global $db; |
|---|
| | 451 | |
|---|
| | 452 | $sql = "update timegroups_groups set description = '$description' where id = $timegroup"; |
|---|
| | 453 | $db->query($sql); |
|---|
| | 454 | needreload(); |
|---|
| | 455 | } |
|---|
| | 456 | |
|---|
| | 457 | //update the timegroup_detail under a single timegroup from the timegroups page |
|---|
| | 458 | function timeconditions_timegroups_edit_times($timegroup,$times) { |
|---|
| | 459 | global $db; |
|---|
| | 460 | |
|---|
| | 461 | $sql = "delete from timegroups_details where timegroupid = $timegroup"; |
|---|
| | 462 | $db->query($sql); |
|---|
| | 463 | foreach ($times as $key=>$val) { |
|---|
| | 464 | extract($val); |
|---|
| | 465 | $time = timeconditions_timegroups_buildtime( $hour_start, $minute_start, $hour_finish, $minute_finish, $wday_start, $wday_finish, $mday_start, $mday_finish, $month_start, $month_finish); |
|---|
| | 466 | if (isset($time) && $time != '' && $time <> '*|*|*|*') { |
|---|
| | 467 | $sql = "insert timegroups_details (timegroupid, time) values ($timegroup, '$time')"; |
|---|
| | 468 | $db->query($sql); |
|---|
| | 469 | } |
|---|
| | 470 | } |
|---|
| | 471 | needreload(); |
|---|
| | 472 | } |
|---|
| | 473 | |
|---|
| | 474 | //update the timegroup_detail under a single timegroup |
|---|
| | 475 | function timeconditions_timegroups_edit_timestrings($timegroup,$timestrings) { |
|---|
| | 476 | global $db; |
|---|
| | 477 | |
|---|
| | 478 | $sql = "delete from timegroups_details where timegroupid = $timegroup"; |
|---|
| | 479 | $db->query($sql); |
|---|
| | 480 | foreach ($timestrings as $key=>$val) { |
|---|
| | 481 | $time = $val; |
|---|
| | 482 | if (isset($time) && $time != '' && $time <> '*|*|*|*') { |
|---|
| | 483 | $sql = "insert timegroups_details (timegroupid, time) values ($timegroup, '$time')"; |
|---|
| | 484 | $db->query($sql); |
|---|
| | 485 | } |
|---|
| | 486 | } |
|---|
| | 487 | needreload(); |
|---|
| | 488 | } |
|---|
| | 489 | |
|---|
| | 490 | function timeconditions_timegroups_drawgroupselect($elemname, $currentvalue = '', $canbeempty = true, $onchange = '') { |
|---|
| | 491 | global $tabindex; |
|---|
| | 492 | $output = ''; |
|---|
| | 493 | $onchange = ($onchange != '') ? " onchange=\"$onchange\"" : ''; |
|---|
| | 494 | |
|---|
| | 495 | $output .= "\n\t\t\t<select name=\"$elemname\" tabindex=\"".++$tabindex."\" id=\"$elemname\"$onchange>\n"; |
|---|
| | 496 | // include blank option if required |
|---|
| | 497 | if ($canbeempty) { |
|---|
| | 498 | $output .= '<option value="">'._("--Select a Group--").'</option>'; |
|---|
| | 499 | } |
|---|
| | 500 | // build the options |
|---|
| | 501 | $valarray = timeconditions_timegroups_list_groups(); |
|---|
| | 502 | foreach ($valarray as $item) { |
|---|
| | 503 | $itemvalue = (isset($item['value']) ? $item['value'] : ''); |
|---|
| | 504 | $itemtext = (isset($item['text']) ? _($item['text']) : ''); |
|---|
| | 505 | $itemselected = ($currentvalue == $itemvalue) ? ' selected' : ''; |
|---|
| | 506 | |
|---|
| | 507 | $output .= "\t\t\t\t<option value=\"$itemvalue\"$itemselected>$itemtext</option>\n"; |
|---|
| | 508 | } |
|---|
| | 509 | $output .= "\t\t\t</select>\n\t\t"; |
|---|
| | 510 | return $output; |
|---|
| | 511 | } |
|---|
| | 512 | |
|---|
| | 513 | //---------------------------------stolen from time conditions and heavily modified------------------------------------------ |
|---|
| | 514 | |
|---|
| | 515 | function timeconditions_timegroups_drawtimeselects($name, $time) { |
|---|
| | 516 | $html = ''; |
|---|
| | 517 | // ----- Load Time Pattern Variables ----- |
|---|
| | 518 | if (isset($time)) { |
|---|
| | 519 | list($time_hour, $time_wday, $time_mday, $time_month) = explode('|', $time); |
|---|
| | 520 | } else { |
|---|
| | 521 | list($time_hour, $time_wday, $time_mday, $time_month) = Array('*','-','-','-'); |
|---|
| | 522 | } |
|---|
| | 523 | $html = $html.'<tr>'; |
|---|
| | 524 | $html = $html.'<td>'._("Time to start:").'</td>'; |
|---|
| | 525 | $html = $html.'<td>'; |
|---|
| | 526 | // Hour could be *, hh:mm, hh:mm-hhmm |
|---|
| | 527 | if ( $time_hour === '*' ) { |
|---|
| | 528 | $hour_start = $hour_finish = '-'; |
|---|
| | 529 | $minute_start = $minute_finish = '-'; |
|---|
| | 530 | } else { |
|---|
| | 531 | list($hour_start_string, $hour_finish_string) = explode('-', $time_hour); |
|---|
| | 532 | if ($hour_start_string === '*') { |
|---|
| | 533 | $hour_start_string = $hour_finish_string; |
|---|
| | 534 | } |
|---|
| | 535 | if ($hour_finish_string === '*') { |
|---|
| | 536 | $hour_finish_string = $hour_start_string; |
|---|
| | 537 | } |
|---|
| | 538 | list($hour_start, $minute_start) = explode( ':', $hour_start_string); |
|---|
| | 539 | list($hour_finish, $minute_finish) = explode( ':', $hour_finish_string); |
|---|
| | 540 | if ( !$hour_finish) { |
|---|
| | 541 | $hour_finish = $hour_start; |
|---|
| | 542 | } |
|---|
| | 543 | if ( !$minute_finish) { |
|---|
| | 544 | $minute_finish = $minute_start; |
|---|
| | 545 | } |
|---|
| | 546 | } |
|---|
| | 547 | $html = $html.'<select name="'.$name.'[hour_start]"/>'; |
|---|
| | 548 | $default = ''; |
|---|
| | 549 | if ( $hour_start === '-' ) { |
|---|
| | 550 | $default = ' selected'; |
|---|
| | 551 | } |
|---|
| | 552 | $html = $html."<option value=\"-\" $default>-"; |
|---|
| | 553 | for ($i = 0 ; $i < 24 ; $i++) { |
|---|
| | 554 | $default = ""; |
|---|
| | 555 | if ( sprintf("%02d", $i) === $hour_start ) { |
|---|
| | 556 | $default = ' selected'; |
|---|
| | 557 | } |
|---|
| | 558 | $html = $html."<option value=\"$i\" $default> ".sprintf("%02d", $i); |
|---|
| | 559 | } |
|---|
| | 560 | $html = $html.'</select>'; |
|---|
| | 561 | $html = $html.'<nbsp>:<nbsp>'; |
|---|
| | 562 | $html = $html.'<select name="'.$name.'[minute_start]"/>'; |
|---|
| | 563 | $default = ''; |
|---|
| | 564 | if ( $minute_start === '-' ) { |
|---|
| | 565 | $default = ' selected'; |
|---|
| | 566 | } |
|---|
| | 567 | $html = $html."<option value=\"-\" $default>-"; |
|---|
| | 568 | for ($i = 0 ; $i < 60 ; $i++) { |
|---|
| | 569 | $default = ""; |
|---|
| | 570 | if ( sprintf("%02d", $i) === $minute_start ) { |
|---|
| | 571 | $default = ' selected'; |
|---|
| | 572 | } |
|---|
| | 573 | $html = $html."<option value=\"$i\" $default> ".sprintf("%02d", $i); |
|---|
| | 574 | } |
|---|
| | 575 | $html = $html.'</select>'; |
|---|
| | 576 | $html = $html.'</td>'; |
|---|
| | 577 | $html = $html.'</tr>'; |
|---|
| | 578 | $html = $html.'<tr>'; |
|---|
| | 579 | $html = $html.'<td>'._("Time to finish:").'</td>'; |
|---|
| | 580 | $html = $html.'<td>'; |
|---|
| | 581 | $html = $html.'<select name="'.$name.'[hour_finish]"/>'; |
|---|
| | 582 | $default = ''; |
|---|
| | 583 | if ( $hour_finish === '-' ) { |
|---|
| | 584 | $default = ' selected'; |
|---|
| | 585 | } |
|---|
| | 586 | $html = $html."<option value=\"-\" $default>-"; |
|---|
| | 587 | for ($i = 0 ; $i < 24 ; $i++) { |
|---|
| | 588 | $default = ""; |
|---|
| | 589 | if ( sprintf("%02d", $i) === $hour_finish) { |
|---|
| | 590 | $default = ' selected'; |
|---|
| | 591 | } |
|---|
| | 592 | $html = $html."<option value=\"$i\" $default> ".sprintf("%02d", $i); |
|---|
| | 593 | } |
|---|
| | 594 | $html = $html.'</select>'; |
|---|
| | 595 | $html = $html.'<nbsp>:<nbsp>'; |
|---|
| | 596 | $html = $html.'<select name="'.$name.'[minute_finish]"/>'; |
|---|
| | 597 | $default = ''; |
|---|
| | 598 | if ( $minute_finish === '-' ) { |
|---|
| | 599 | $default = ' selected'; |
|---|
| | 600 | } |
|---|
| | 601 | $html = $html."<option value=\"-\" $default>-"; |
|---|
| | 602 | for ($i = 0 ; $i < 60 ; $i++) { |
|---|
| | 603 | $default = ''; |
|---|
| | 604 | if ( sprintf("%02d", $i) === $minute_finish ) { |
|---|
| | 605 | $default = ' selected'; |
|---|
| | 606 | } |
|---|
| | 607 | $html = $html."<option value=\"$i\" $default> ".sprintf("%02d", $i); |
|---|
| | 608 | } |
|---|
| | 609 | $html = $html.'</select>'; |
|---|
| | 610 | $html = $html.'</td>'; |
|---|
| | 611 | $html = $html.'</tr>'; |
|---|
| | 612 | $html = $html.'<tr>'; |
|---|
| | 613 | |
|---|
| | 614 | // WDay could be *, day, day1-day2 |
|---|
| | 615 | if ( $time_wday != '*' ) { |
|---|
| | 616 | list($wday_start, $wday_finish) = explode('-', $time_wday); |
|---|
| | 617 | if ($wday_start === '*') { |
|---|
| | 618 | $wday_start = $wday_finish; |
|---|
| | 619 | } |
|---|
| | 620 | if ($wday_finish === '*') { |
|---|
| | 621 | $wday_finish = $wday_start; |
|---|
| | 622 | } |
|---|
| | 623 | if ( !$wday_finish) { |
|---|
| | 624 | $wday_finish = $wday_start; |
|---|
| | 625 | } |
|---|
| | 626 | } else { |
|---|
| | 627 | $wday_start = $wday_finish = '-'; |
|---|
| | 628 | } |
|---|
| | 629 | $html = $html.'<td>'._("Week Day Start:").'</td>'; |
|---|
| | 630 | $html = $html.'<td>'; |
|---|
| | 631 | $html = $html.'<select name="'.$name.'[wday_start]"/>'; |
|---|
| | 632 | if ( $wday_start == '-' ) { |
|---|
| | 633 | $default = ' selected'; |
|---|
| | 634 | } else { |
|---|
| | 635 | $default = ''; |
|---|
| | 636 | } |
|---|
| | 637 | $html = $html."<option value=\"-\" $default>-"; |
|---|
| | 638 | |
|---|
| | 639 | if ( $wday_start == 'mon' ) { |
|---|
| | 640 | $default = ' selected'; |
|---|
| | 641 | } else { |
|---|
| | 642 | $default = ''; |
|---|
| | 643 | } |
|---|
| | 644 | $html = $html."<option value=\"mon\" $default>" . _("Monday"); |
|---|
| | 645 | |
|---|
| | 646 | if ( $wday_start == 'tue' ) { |
|---|
| | 647 | $default = ' selected'; |
|---|
| | 648 | } else { |
|---|
| | 649 | $default = ''; |
|---|
| | 650 | } |
|---|
| | 651 | $html = $html."<option value=\"tue\" $default>" . _("Tuesday"); |
|---|
| | 652 | |
|---|
| | 653 | if ( $wday_start == 'wed' ) { |
|---|
| | 654 | $default = ' selected'; |
|---|
| | 655 | } else { |
|---|
| | 656 | $default = ''; |
|---|
| | 657 | } |
|---|
| | 658 | $html = $html."<option value=\"wed\" $default>" . _("Wednesday"); |
|---|
| | 659 | |
|---|
| | 660 | if ( $wday_start == 'thu' ) { |
|---|
| | 661 | $default = ' selected'; |
|---|
| | 662 | } else { |
|---|
| | 663 | $default = ''; |
|---|
| | 664 | } |
|---|
| | 665 | $html = $html."<option value=\"thu\" $default>" . _("Thursday"); |
|---|
| | 666 | |
|---|
| | 667 | if ( $wday_start == 'fri' ) { |
|---|
| | 668 | $default = ' selected'; |
|---|
| | 669 | } else { |
|---|
| | 670 | $default = ''; |
|---|
| | 671 | } |
|---|
| | 672 | $html = $html."<option value=\"fri\" $default>" . _("Friday"); |
|---|
| | 673 | |
|---|
| | 674 | if ( $wday_start == 'sat' ) { |
|---|
| | 675 | $default = ' selected'; |
|---|
| | 676 | } else { |
|---|
| | 677 | $default = ''; |
|---|
| | 678 | } |
|---|
| | 679 | $html = $html."<option value=\"sat\" $default>" . _("Saturday"); |
|---|
| | 680 | |
|---|
| | 681 | if ( $wday_start == 'sun' ) { |
|---|
| | 682 | $default = ' selected'; |
|---|
| | 683 | } else { |
|---|
| | 684 | $default = ''; |
|---|
| | 685 | } |
|---|
| | 686 | $html = $html."<option value=\"sun\" $default>" . _("Sunday"); |
|---|
| | 687 | |
|---|
| | 688 | $html = $html.'</td>'; |
|---|
| | 689 | $html = $html.'</tr>'; |
|---|
| | 690 | $html = $html.'<tr>'; |
|---|
| | 691 | $html = $html.'<td>'._("Week Day finish:").'</td>'; |
|---|
| | 692 | $html = $html.'<td>'; |
|---|
| | 693 | $html = $html.'<select name="'.$name.'[wday_finish]"/>'; |
|---|
| | 694 | |
|---|
| | 695 | if ( $wday_finish == '-' ) { |
|---|
| | 696 | $default = ' selected'; |
|---|
| | 697 | } else { |
|---|
| | 698 | $default = ''; |
|---|
| | 699 | } |
|---|
| | 700 | $html = $html."<option value=\"-\" $default>-"; |
|---|
| | 701 | |
|---|
| | 702 | if ( $wday_finish == 'mon' ) { |
|---|
| | 703 | $default = ' selected'; |
|---|
| | 704 | } else { |
|---|
| | 705 | $default = ''; |
|---|
| | 706 | } |
|---|
| | 707 | $html = $html."<option value=\"mon\" $default>" . _("Monday"); |
|---|
| | 708 | |
|---|
| | 709 | if ( $wday_finish == 'tue' ) { |
|---|
| | 710 | $default = ' selected'; |
|---|
| | 711 | } else { |
|---|
| | 712 | $default = ''; |
|---|
| | 713 | } |
|---|
| | 714 | $html = $html."<option value=\"tue\" $default>" . _("Tuesday"); |
|---|
| | 715 | |
|---|
| | 716 | if ( $wday_finish == 'wed' ) { |
|---|
| | 717 | $default = ' selected'; |
|---|
| | 718 | } else { |
|---|
| | 719 | $default = ''; |
|---|
| | 720 | } |
|---|
| | 721 | $html = $html."<option value=\"wed\" $default>" . _("Wednesday"); |
|---|
| | 722 | |
|---|
| | 723 | if ( $wday_finish == 'thu' ) { |
|---|
| | 724 | $default = ' selected'; |
|---|
| | 725 | } else { |
|---|
| | 726 | $default = ''; |
|---|
| | 727 | } |
|---|
| | 728 | $html = $html."<option value=\"thu\" $default>" . _("Thursday"); |
|---|
| | 729 | |
|---|
| | 730 | if ( $wday_finish == 'fri' ) { |
|---|
| | 731 | $default = ' selected'; |
|---|
| | 732 | } else { |
|---|
| | 733 | $default = ''; |
|---|
| | 734 | } |
|---|
| | 735 | $html = $html."<option value=\"fri\" $default>" . _("Friday"); |
|---|
| | 736 | |
|---|
| | 737 | if ( $wday_finish == 'sat' ) { |
|---|
| | 738 | $default = ' selected'; |
|---|
| | 739 | } else { |
|---|
| | 740 | $default = ''; |
|---|
| | 741 | } |
|---|
| | 742 | $html = $html."<option value=\"sat\" $default>" . _("Saturday"); |
|---|
| | 743 | |
|---|
| | 744 | if ( $wday_finish == 'sun' ) { |
|---|
| | 745 | $default = ' selected'; |
|---|
| | 746 | } else { |
|---|
| | 747 | $default = ''; |
|---|
| | 748 | } |
|---|
| | 749 | $html = $html."<option value=\"sun\" $default>" . _("Sunday"); |
|---|
| | 750 | |
|---|
| | 751 | $html = $html.'</td>'; |
|---|
| | 752 | $html = $html.'</tr>'; |
|---|
| | 753 | $html = $html.'<tr>'; |
|---|
| | 754 | $html = $html.'<td>'._("Month Day start:").'</td>'; |
|---|
| | 755 | |
|---|
| | 756 | // MDay could be *, day, day1-day2 |
|---|
| | 757 | if ( $time_mday != '*' ) { |
|---|
| | 758 | list($mday_start, $mday_finish) = explode('-', $time_mday); |
|---|
| | 759 | if ($mday_start === '*') { |
|---|
| | 760 | $mday_start = $mday_finish; |
|---|
| | 761 | } |
|---|
| | 762 | if ($mday_finish === '*') { |
|---|
| | 763 | $mday_finish = $mday_start; |
|---|
| | 764 | } |
|---|
| | 765 | if ( !$mday_finish) { |
|---|
| | 766 | $mday_finish = $mday_start; |
|---|
| | 767 | } |
|---|
| | 768 | } else { |
|---|
| | 769 | $mday_start = $mday_finish = '-'; |
|---|
| | 770 | } |
|---|
| | 771 | |
|---|
| | 772 | $html = $html.'<td>'; |
|---|
| | 773 | $html = $html.'<select name="'.$name.'[mday_start]"/>'; |
|---|
| | 774 | $default = ''; |
|---|
| | 775 | if ( $mday_start == '-' ) { |
|---|
| | 776 | $default = ' selected'; |
|---|
| | 777 | } |
|---|
| | 778 | $html = $html."<option value=\"-\" $default>-"; |
|---|
| | 779 | for ($i = 1 ; $i < 32 ; $i++) { |
|---|
| | 780 | $default = ''; |
|---|
| | 781 | if ( $i == $mday_start ) { |
|---|
| | 782 | $default = ' selected'; |
|---|
| | 783 | } |
|---|
| | 784 | $html = $html."<option value=\"$i\" $default> $i"; |
|---|
| | 785 | } |
|---|
| | 786 | $html = $html.'</select>'; |
|---|
| | 787 | $html = $html.'</td>'; |
|---|
| | 788 | $html = $html.'<tr>'; |
|---|
| | 789 | $html = $html.'<td>'._("Month Day finish:").'</td>'; |
|---|
| | 790 | $html = $html.'<td>'; |
|---|
| | 791 | $html = $html.'<select name="'.$name.'[mday_finish]"/>'; |
|---|
| | 792 | $default = ''; |
|---|
| | 793 | if ( $mday_finish == '-' ) { |
|---|
| | 794 | $default = ' selected'; |
|---|
| | 795 | } |
|---|
| | 796 | $html = $html."<option value=\"-\" $default>-"; |
|---|
| | 797 | for ($i = 1 ; $i < 32 ; $i++) { |
|---|
| | 798 | $default = ''; |
|---|
| | 799 | if ( $i == $mday_finish ) { |
|---|
| | 800 | $default = ' selected'; |
|---|
| | 801 | } |
|---|
| | 802 | $html = $html."<option value=\"$i\" $default> $i"; |
|---|
| | 803 | } |
|---|
| | 804 | $html = $html.'</select>'; |
|---|
| | 805 | $html = $html.'</td>'; |
|---|
| | 806 | $html = $html.'</tr>'; |
|---|
| | 807 | $html = $html.'<tr>'; |
|---|
| | 808 | $html = $html.'<td>'._("Month start:").'</td>'; |
|---|
| | 809 | |
|---|
| | 810 | // Month could be *, month, month1-month2 |
|---|
| | 811 | if ( $time_month != '*' ) { |
|---|
| | 812 | list($month_start, $month_finish) = explode('-', $time_month); |
|---|
| | 813 | if ($month_start === '*') { |
|---|
| | 814 | $month_start = $month_finish; |
|---|
| | 815 | } |
|---|
| | 816 | if ($month_finish === '*') { |
|---|
| | 817 | $month_finish = $month_start; |
|---|
| | 818 | } |
|---|
| | 819 | if ( !$month_finish) { |
|---|
| | 820 | $month_finish = $month_start; |
|---|
| | 821 | } |
|---|
| | 822 | } else { |
|---|
| | 823 | $month_start = $month_finish = '-'; |
|---|
| | 824 | } |
|---|
| | 825 | $html = $html.'<td>'; |
|---|
| | 826 | $html = $html.'<select name="'.$name.'[month_start]"/>'; |
|---|
| | 827 | |
|---|
| | 828 | if ( $month_start == '-' ) { |
|---|
| | 829 | $default = ' selected'; |
|---|
| | 830 | } else { |
|---|
| | 831 | $default = ''; |
|---|
| | 832 | } |
|---|
| | 833 | $html = $html."<option value=\"-\" $default>-"; |
|---|
| | 834 | |
|---|
| | 835 | if ( $month_start == 'jan' ) { |
|---|
| | 836 | $default = ' selected'; |
|---|
| | 837 | } else { |
|---|
| | 838 | $default = ''; |
|---|
| | 839 | } |
|---|
| | 840 | $html = $html."<option value=\"jan\" $default>" . _("January"); |
|---|
| | 841 | |
|---|
| | 842 | if ( $month_start == 'feb' ) { |
|---|
| | 843 | $default = ' selected'; |
|---|
| | 844 | } else { |
|---|
| | 845 | $default = ''; |
|---|
| | 846 | } |
|---|
| | 847 | $html = $html."<option value=\"feb\" $default>" . _("February"); |
|---|
| | 848 | |
|---|
| | 849 | if ( $month_start == 'mar' ) { |
|---|
| | 850 | $default = ' selected'; |
|---|
| | 851 | } else { |
|---|
| | 852 | $default = ''; |
|---|
| | 853 | } |
|---|
| | 854 | $html = $html."<option value=\"mar\" $default>" . _("March"); |
|---|
| | 855 | |
|---|
| | 856 | if ( $month_start == 'apr' ) { |
|---|
| | 857 | $default = ' selected'; |
|---|
| | 858 | } else { |
|---|
| | 859 | $default = ''; |
|---|
| | 860 | } |
|---|
| | 861 | $html = $html."<option value=\"apr\" $default>" . _("April"); |
|---|
| | 862 | |
|---|
| | 863 | if ( $month_start == 'may' ) { |
|---|
| | 864 | $default = ' selected'; |
|---|
| | 865 | } else { |
|---|
| | 866 | $default = ''; |
|---|
| | 867 | } |
|---|
| | 868 | $html = $html."<option value=\"may\" $default>" . _("May"); |
|---|
| | 869 | |
|---|
| | 870 | if ( $month_start == 'jun' ) { |
|---|
| | 871 | $default = ' selected'; |
|---|
| | 872 | } else { |
|---|
| | 873 | $default = ''; |
|---|
| | 874 | } |
|---|
| | 875 | $html = $html."<option value=\"jun\" $default>" . _("June"); |
|---|
| | 876 | &nb |
|---|