root/modules/branches/2.6/timeconditions/functions.inc.php

Revision 6959, 34.4 kB (checked in by mickecarlsson, 5 years ago)

Enclosed text strings for localization, updated .pot file, updated sweish language for timeconditions

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1 <?php /* $Id */
2
3 function timeconditions_getdest($exten) {
4     return array('timeconditions,'.$exten.',1');
5 }
6
7 function timeconditions_getdestinfo($dest) {
8     global $active_modules;
9
10     if (substr(trim($dest),0,15) == 'timeconditions,') {
11         $exten = explode(',',$dest);
12         $exten = $exten[1];
13         $thisexten = timeconditions_get($exten);
14         if (empty($thisexten)) {
15             return array();
16         } else {
17             //$type = isset($active_modules['announcement']['type'])?$active_modules['announcement']['type']:'setup';
18             return array('description' => sprintf(_("Time Condition: %s"),$thisexten['displayname']),
19                          'edit_url' => 'config.php?display=timeconditions&itemid='.urlencode($exten),
20                         );
21         }
22     } else {
23         return false;
24     }
25 }
26
27 // returns a associative arrays with keys 'destination' and 'description'
28 function timeconditions_destinations() {
29     //get the list of timeconditions
30     $results = timeconditions_list(true);
31
32     // return an associative array with destination and description
33     if (isset($results)) {
34         foreach($results as $result){
35                 $extens[] = array('destination' => 'timeconditions,'.$result['timeconditions_id'].',1', 'description' => $result['displayname']);
36         }
37         return $extens;
38     } else {
39         return null;
40     }
41 }
42
43 /*     Generates dialplan for conferences
44     We call this with retrieve_conf
45 */
46 function timeconditions_get_config($engine) {
47     global $ext// is this the best way to pass this?
48     global $conferences_conf;
49
50     switch($engine) {
51         case "asterisk":
52             $timelist = timeconditions_list(true);
53             if(is_array($timelist)) {
54                 foreach($timelist as $item) {
55                     // add dialplan
56                     $times = timeconditions_timegroups_get_times($item['time']);
57                     if (is_array($times)) {
58                         foreach ($times as $time) {
59                             $ext->add('timeconditions', $item['timeconditions_id'], '', new ext_gotoiftime($time[1],$item['truegoto']));
60                         }
61                     }
62                     $ext->add('timeconditions', $item['timeconditions_id'], '', new ext_goto($item['falsegoto']));
63                 }
64             }
65         break;
66     }
67 }
68
69 function timeconditions_check_destinations($dest=true) {
70     global $active_modules;
71
72     $destlist = array();
73     if (is_array($dest) && empty($dest)) {
74         return $destlist;
75     }
76     $sql = "SELECT timeconditions_id, displayname, truegoto, falsegoto FROM timeconditions ";
77     if ($dest !== true) {
78         $sql .= "WHERE (truegoto in ('".implode("','",$dest)."') ) OR (falsegoto in ('".implode("','",$dest)."') )";
79     }
80     $results = sql($sql,"getAll",DB_FETCHMODE_ASSOC);
81
82     $type = isset($active_modules['timeconditions']['type'])?$active_modules['timeconditions']['type']:'setup';
83
84     foreach ($results as $result) {
85         $thisdest    = $result['truegoto'];
86         $thisid      = $result['timeconditions_id'];
87         $description = sprintf(_("Time Condition: %s"),$result['displayname']);
88         $thisurl     = 'config.php?display=timeconditions&itemid='.urlencode($thisid);
89         if ($dest === true || $dest = $thisdest) {
90             $destlist[] = array(
91                 'dest' => $thisdest,
92                 'description' => $description,
93                 'edit_url' => $thisurl,
94             );
95         }
96         $thisdest = $result['falsegoto'];
97         if ($dest === true || $dest = $thisdest) {
98             $destlist[] = array(
99                 'dest' => $thisdest,
100                 'description' => $description,
101                 'edit_url' => $thisurl,
102             );
103         }
104     }
105     return $destlist;
106 }
107
108 //get the existing meetme extensions
109 function timeconditions_list($getall=false) {
110     $results = sql("SELECT * FROM timeconditions","getAll",DB_FETCHMODE_ASSOC);
111     if(is_array($results)){
112         foreach($results as $result){
113             // check to see if we have a dept match for the current AMP User.
114             if ($getall || checkDept($result['deptname'])){
115                 // return this item's dialplan destination, and the description
116                 $allowed[] = $result;
117             }
118         }
119     }
120     if (isset($allowed)) {
121         return $allowed;
122     } else {
123         return null;
124     }
125 }
126
127 function timeconditions_get($id){
128     //get all the variables for the timecondition
129     $results = sql("SELECT * FROM timeconditions WHERE timeconditions_id = '$id'","getRow",DB_FETCHMODE_ASSOC);
130     return $results;
131 }
132
133 function timeconditions_del($id){
134     $results = sql("DELETE FROM timeconditions WHERE timeconditions_id = \"$id\"","query");
135 }
136
137 //obsolete handled in timegroups module
138 function timeconditions_get_time( $hour_start, $minute_start, $hour_finish, $minute_finish, $wday_start, $wday_finish, $mday_start, $mday_finish, $month_start, $month_finish) {
139
140     //----- Time Hour Interval proccess ----
141     //
142     if ($minute_start == '-') {
143         $time_minute_start = "*";
144     } else {
145         $time_minute_start = sprintf("%02d",$minute_start);
146     }
147     if ($minute_finish == '-') {
148         $time_minute_finish = "*";
149     } else {
150          $time_minute_finish = sprintf("%02d",$minute_finish);
151     }
152     if ($hour_start == '-') {
153         $time_hour_start = '*';
154     } else {
155         $time_hour_start = sprintf("%02d",$hour_start) . ':' . $time_minute_start;
156     }
157     if ($hour_finish == '-') {
158         $time_hour_finish = '*';
159     } else {
160         $time_hour_finish = sprintf("%02d",$hour_finish) . ':' . $time_minute_finish;
161     }
162     if ($time_hour_start == $time_hour_finish) {
163         $time_hour = $time_hour_start;
164     } else {
165         $time_hour = $time_hour_start . '-' . $time_hour_finish;
166     }
167
168     //----- Time Week Day Interval proccess -----
169     //
170     if ($wday_start == '-') {
171         $time_wday_start = '*';
172     } else {
173         $time_wday_start = $wday_start;
174     }
175     if ($wday_finish == '-') {
176         $time_wday_finish = '*';
177     } else {
178         $time_wday_finish = $wday_finish;
179     }
180     if ($time_wday_start == $time_wday_finish) {
181         $time_wday = $time_wday_start;
182     } else {
183         $time_wday = $time_wday_start . '-' . $time_wday_finish;
184     }
185
186     //----- Time Month Day Interval proccess -----
187     //
188     if ($mday_start == '-') {
189         $time_mday_start = '*';
190     } else {
191         $time_mday_start = $mday_start;
192     }
193     if ($mday_finish == '-') {
194         $time_mday_finish = '*';
195     } else {
196         $time_mday_finish = $mday_finish;
197     }
198     if ($time_mday_start == $time_mday_finish) {
199         $time_mday = $time_mday_start;
200     } else {
201         $time_mday = $time_mday_start . '-' . $time_mday_finish;
202     }
203
204     //----- Time Month Interval proccess -----
205     //
206     if ($month_start == '-') {
207         $time_month_start = '*';
208     } else {
209         $time_month_start = $month_start;
210     }
211     if ($month_finish == '-') {
212         $time_month_finish = '*';
213     } else {
214         $time_month_finish = $month_finish;
215     }
216     if ($time_month_start == $time_month_finish) {
217         $time_month = $time_month_start;
218     } else {
219         $time_month = $time_month_start . '-' . $time_month_finish;
220     }
221     $time = $time_hour . '|' . $time_wday . '|' . $time_mday . '|' . $time_month;
222     return $time;
223 }
224
225 function timeconditions_add($post){
226     if(!timeconditions_chk($post)) {
227         return false;
228     }
229     extract($post);
230
231     // $time = timeconditions_get_time( $hour_start, $minute_start, $hour_finish, $minute_finish, $wday_start, $wday_finish, $mday_start, $mday_finish, $month_start, $month_finish);
232
233     if(empty($displayname)) {
234          $displayname = "unnamed";
235     }
236     $results = sql("INSERT INTO timeconditions (displayname,time,truegoto,falsegoto,deptname) values (\"$displayname\",\"$time\",\"${$goto0.'0'}\",\"${$goto1.'1'}\",\"$deptname\")");
237 }
238
239 function timeconditions_edit($id,$post){
240     if(!timeconditions_chk($post)) {
241         return false;
242     }
243     extract($post);
244
245     // $time = timeconditions_get_time( $hour_start, $minute_start, $hour_finish, $minute_finish, $wday_start, $wday_finish, $mday_start, $mday_finish, $month_start, $month_finish);
246     
247     if(empty($displayname)) {
248         $displayname = "unnamed";
249     }
250     $results = sql("UPDATE timeconditions SET displayname = \"$displayname\", time = \"$time\", truegoto = \"${$goto0.'0'}\", falsegoto = \"${$goto1.'1'}\", deptname = \"$deptname\" WHERE timeconditions_id = \"$id\"");
251 }
252
253 // ensures post vars is valid
254 function timeconditions_chk($post){
255     return true;
256 }
257
258 function timeconditions_timegroups_usage($group_id) {
259
260     $results = sql("SELECT timeconditions_id, displayname FROM timeconditions WHERE time = '$group_id'","getAll",DB_FETCHMODE_ASSOC);
261     if (empty($results)) {
262         return array();
263     } else {
264         foreach ($results as $result) {
265             $usage_arr[] = array(
266                 "url_query" => "display=timeconditions&itemid=".$result['timeconditions_id'],
267                 "description" => $result['displayname'],
268             );
269         }
270         return $usage_arr;
271     }
272 }
273
274
275 function timeconditions_timegroups_list_usage($timegroup_id) {
276     global $active_modules;
277     $full_usage_arr = array();
278
279     foreach(array_keys($active_modules) as $mod) {
280         $function = $mod."_timegroups_usage";
281         if (function_exists($function)) {
282             $timegroup_usage = $function($timegroup_id);
283             if (!empty($timegroup_usage)) {
284                 $full_usage_arr = array_merge($full_usage_arr, $timegroup_usage);
285             }
286         }
287     }
288     return $full_usage_arr;
289 }
290
291 /*
292 The following functions are available to other modules.
293
294 function timeconditions_timegroups_add_group($description,$times=null) return the inserted id
295     expects an array of times, each an associative array
296     Array ( [0] => Array ( [hour_start] => - [minute_start] => - [hour_finish] => -
297     [minute_finish] => - [wday_start] => - [wday_finish] => - [mday_start] => -
298     [mday_finish] => - [month_start] => - [month_finish] => - ) )
299
300 function timeconditions_timegroups_add_group_timestrings($description,$times=null) return the inserted id
301     alternative to above. expects an array of time strings instead of associative array of hours minutes etc.
302
303 function timeconditions_timegroups_list_groups()
304     returns an array of id and descriptions for any time groups defined by the user
305     the array contains inidces 0 and 1 for the rnav and associative value and text for select boxes
306
307 function timeconditions_timegroups_get_times($timegroup)
308     returns an array of id and time string of the users time selections for the selected timegroup
309
310 function timeconditions_timegroups_buildtime( $hour_start, $minute_start, $hour_finish, $minute_finish, $wday_start, $wday_finish, $mday_start, $mday_finish, $month_start, $month_finish)
311     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.
312
313 function timeconditions_timegroups_drawtimeselects($name, $time)
314     should never be needed by another module, as this module should be the only place drawing the time selects
315 */
316
317 //lists any time groups defined by the user
318 function timeconditions_timegroups_list_groups() {
319     global $db;
320     $tmparray = array();
321
322     $sql = "select id, description from timegroups_groups order by description";
323     $results = $db->getAll($sql);
324     if(DB::IsError($results)) {
325         $results = null;
326     }
327     foreach ($results as $val) {
328         $tmparray[] = array($val[0], $val[1], "value" => $val[0], "text" => $val[1]);
329     }
330     return $tmparray;
331 }
332
333 //---------------------------------------------
334
335 //timegroups page helper
336 //we are using gui styles so there is very little on the page
337 //the timegroups page is used to create time string
338 //to be used by other modules for gotoif or includes or IFTIME func
339 function timeconditions_timegroups_configpageinit($dispnum) {
340 global $currentcomponent;
341
342     switch ($dispnum) {
343         case 'timegroups':
344             $currentcomponent->addguifunc('timeconditions_timegroups_configpageload');
345             $currentcomponent->addprocessfunc('timeconditions_timegroups_configprocess', 5); 
346         break;
347     }
348 }
349
350 //actually render the timegroups page
351 function timeconditions_timegroups_configpageload() {
352     global $currentcomponent;
353
354     $descerr = _("Description must be alpha-numeric, and may not be left blank");
355     $extdisplay = isset($_REQUEST['extdisplay'])?$_REQUEST['extdisplay']:null;
356     $action= isset($_REQUEST['action'])?$_REQUEST['action']:null;
357     if ($action == 'del') {
358         $currentcomponent->addguielem('_top', new gui_pageheading('title', _("Time Group").": $extdisplay"._(" deleted!"), false), 0);
359         unset($extdisplay);
360     }
361 //need to get page name/type dynamically
362     $query = ($_SERVER['QUERY_STRING'])?$_SERVER['QUERY_STRING']:'type=setup&display=timegroups&extdisplay='.$extdisplay;
363     $delURL = $_SERVER['PHP_SELF'].'?'.$query.'&action=del';
364     $info = '';
365     if (!$extdisplay) {
366         $currentcomponent->addguielem('_top', new gui_pageheading('title', _("Add Time Group"), false), 0);
367         $currentcomponent->addguielem(_("Time Group"), new gui_textbox('description', '', _("Description"), _("This will display as the name of this Time Group."), '!isAlphanumeric() || isWhitespace()', $descerr, false), 3);
368     } else {
369         $savedtimegroup= timeconditions_timegroups_get_group($extdisplay);
370         $timegroup = $savedtimegroup[0];
371         $description = $savedtimegroup[1];
372         $currentcomponent->addguielem('_top', new gui_hidden('extdisplay', $extdisplay));
373         $currentcomponent->addguielem('_top', new gui_pageheading('title', _("Edit Time Group").": $description", false), 0);
374         $tlabel = sprintf(_("Delete Time Group %s"),$extdisplay);
375         $label = '<span><img width="16" height="16" border="0" title="'.$tlabel.'" alt="" src="images/core_delete.png"/>&nbsp;'.$tlabel.'</span>';
376         $currentcomponent->addguielem('_top', new gui_link('del', $label, $delURL, true, false), 0);
377
378         $usage_list = timeconditions_timegroups_list_usage($extdisplay);
379         $count = 0;
380         foreach ($usage_list as $link) {
381             $label = '<span><img width="16" height="16" border="0" title="'.$link['description'].'" alt="" src="images/time_link.png"/>&nbsp;'.$link['description'].'</span>';
382             $timegroup_link = $_SERVER['PHP_SELF'].'?'.$link['url_query'];
383             $currentcomponent->addguielem(_("Used By"), new gui_link('link'.$count++, $label, $timegroup_link, true, false), 4);
384         }
385
386
387         $currentcomponent->addguielem(_("Time Group"), new gui_textbox('description', $description, _("Description"), _("This will display as the name of this Time Group."), '', '', false), 3);
388         $timelist = timeconditions_timegroups_get_times($extdisplay);
389         foreach ($timelist as $val) {
390             $timehtml = timeconditions_timegroups_drawtimeselects('times['.$val[0].']',$val[1]);
391             $timehtml = '<tr><td colspan="2"><table>'.$timehtml.'</table></td></tr>';
392             $currentcomponent->addguielem($val[1], new guielement('dest0', $timehtml, ''),5);
393         }
394     }
395     $timehtml = timeconditions_timegroups_drawtimeselects('times[new]',null);
396     $timehtml = '<tr><td colspan="2"><table>'.$timehtml.'</table></td></tr>';
397     $currentcomponent->addguielem(_("New Time"), new guielement('dest0', $timehtml, ''),6);
398     $currentcomponent->addguielem('_top', new gui_hidden('action', ($extdisplay ? 'edit' : 'add')));
399 }
400
401 //handle timegroups page submit button
402 function timeconditions_timegroups_configprocess() {
403     $action= isset($_REQUEST['action'])?$_REQUEST['action']:null;
404     $timegroup= isset($_REQUEST['extdisplay'])?$_REQUEST['extdisplay']:null;
405     $description= isset($_REQUEST['description'])?$_REQUEST['description']:null;
406     $times = isset($_REQUEST['times'])?$_REQUEST['times']:null;
407
408     switch ($action) {
409         case 'add':
410             timeconditions_timegroups_add_group($description,$times);
411             break;
412         case 'edit':
413             timeconditions_timegroups_edit_group($timegroup,$description);
414             timeconditions_timegroups_edit_times($timegroup,$times);
415             break;
416         case 'del':
417             timeconditions_timegroups_del_group($timegroup);
418             break;
419     }
420 }
421
422 //these are the users time selections for the current timegroup
423 function timeconditions_timegroups_get_times($timegroup) {
424     global $db;
425
426     $sql = "select id, time from timegroups_details where timegroupid = $timegroup";
427     $results = $db->getAll($sql);
428     if(DB::IsError($results)) {
429         $results = null;
430     }
431     foreach ($results as $val) {
432         $tmparray[] = array($val[0], $val[1]);
433     }
434     return $tmparray;
435 }
436
437 //retrieve a single timegroup for the timegroups page
438 function timeconditions_timegroups_get_group($timegroup) {
439     global $db;
440
441     $sql = "select id, description from timegroups_groups where id = $timegroup";
442     $results = $db->getAll($sql);
443     if(DB::IsError($results)) {
444          $results = null;
445     }
446     $tmparray = array($results[0][0], $results[0][1]);
447     return $tmparray;
448 }
449
450 //add a new timegroup for timegroups page
451 //expects an array of times, each an associative array
452 //Array ( [0] => Array ( [hour_start] => - [minute_start] => - [hour_finish] => -
453 //[minute_finish] => - [wday_start] => - [wday_finish] => - [mday_start] => -
454 //[mday_finish] => - [month_start] => - [month_finish] => - ) )
455 function timeconditions_timegroups_add_group($description,$times=null) {
456     global $db;
457
458     $sql = "insert timegroups_groups(description) VALUES ('$description')";
459     $db->query($sql);
460     $timegroup=mysql_insert_id();
461     if (isset($times)) {
462         timeconditions_timegroups_edit_times($timegroup,$times);
463     }
464     needreload();
465     return $timegroup;
466 }
467
468 function timeconditions_timegroups_add_group_timestrings($description,$timestrings) {
469     global $db;
470
471     $sql = "insert timegroups_groups(description) VALUES ('$description')";
472     $db->query($sql);
473     $timegroup=mysql_insert_id();
474     timeconditions_timegroups_edit_timestrings($timegroup,$timestrings);
475     needreload();
476     return $timegroup;
477 }
478
479 //delete a single timegroup from the timegroups page
480 function timeconditions_timegroups_del_group($timegroup) {
481     global $db;
482
483     $sql = "delete from timegroups_details where timegroupid = $timegroup";
484     $db->query($sql);
485     $sql = "delete from timegroups_groups where id = $timegroup";
486     $db->query($sql);
487     needreload();
488 }
489
490 //update a single timegroup from the timegroups page
491 function timeconditions_timegroups_edit_group($timegroup,$description) {
492     global $db;
493
494     $sql = "update timegroups_groups set description = '$description' where id = $timegroup";
495     $db->query($sql);
496     needreload();
497 }
498
499 //update the timegroup_detail under a single timegroup from the timegroups page
500 function timeconditions_timegroups_edit_times($timegroup,$times) {
501     global $db;
502
503     $sql = "delete from timegroups_details where timegroupid = $timegroup";
504     $db->query($sql);
505     foreach ($times as $key=>$val) {
506         extract($val);
507         $time = timeconditions_timegroups_buildtime( $hour_start, $minute_start, $hour_finish, $minute_finish, $wday_start, $wday_finish, $mday_start, $mday_finish, $month_start, $month_finish);
508         if (isset($time) && $time != '' && $time <> '*|*|*|*') {
509             $sql = "insert timegroups_details (timegroupid, time) values ($timegroup, '$time')";
510             $db->query($sql);
511         }
512     }
513     needreload();
514 }
515
516 //update the timegroup_detail under a single timegroup
517 function timeconditions_timegroups_edit_timestrings($timegroup,$timestrings) {
518     global $db;
519
520     $sql = "delete from timegroups_details where timegroupid = $timegroup";
521     $db->query($sql);
522     foreach ($timestrings as $key=>$val) {
523         $time = $val;
524         if (isset($time) && $time != '' && $time <> '*|*|*|*') {
525             $sql = "insert timegroups_details (timegroupid, time) values ($timegroup, '$time')";
526             $db->query($sql);
527         }
528     }
529     needreload();
530 }
531
532 function timeconditions_timegroups_drawgroupselect($elemname, $currentvalue = '', $canbeempty = true, $onchange = '') {
533     global $tabindex;
534     $output = '';
535     $onchange = ($onchange != '') ? " onchange=\"$onchange\"" : '';
536     
537     $output .= "\n\t\t\t<select name=\"$elemname\" tabindex=\"".++$tabindex."\" id=\"$elemname\"$onchange>\n";
538     // include blank option if required
539     if ($canbeempty) {
540         $output .= '<option value="">'._("--Select a Group--").'</option>';           
541     }
542     // build the options
543     $valarray = timeconditions_timegroups_list_groups();
544     foreach ($valarray as $item) {
545         $itemvalue = (isset($item['value']) ? $item['value'] : '');
546         $itemtext = (isset($item['text']) ? _($item['text']) : '');
547         $itemselected = ($currentvalue == $itemvalue) ? ' selected' : '';
548         
549         $output .= "\t\t\t\t<option value=\"$itemvalue\"$itemselected>$itemtext</option>\n";
550     }
551     $output .= "\t\t\t</select>\n\t\t";
552     return $output;
553 }
554
555 //---------------------------------stolen from time conditions and heavily modified------------------------------------------
556
557 function timeconditions_timegroups_drawtimeselects($name, $time) {
558     $html = '';
559     // ----- Load Time Pattern Variables -----
560     if (isset($time)) {
561         list($time_hour, $time_wday, $time_mday, $time_month) = explode('|', $time);
562     } else {
563         list($time_hour, $time_wday, $time_mday, $time_month) = Array('*','-','-','-');
564     }
565     $html = $html.'<tr>';
566     $html = $html.'<td>'._("Time to start:").'</td>';
567     $html = $html.'<td>';
568     // Hour could be *, hh:mm, hh:mm-hhmm
569     if ( $time_hour === '*' ) {
570         $hour_start = $hour_finish = '-';
571         $minute_start = $minute_finish = '-';
572     } else {
573         list($hour_start_string, $hour_finish_string) = explode('-', $time_hour);
574         if ($hour_start_string === '*') {
575             $hour_start_string = $hour_finish_string;
576         }
577         if ($hour_finish_string === '*') {
578             $hour_finish_string = $hour_start_string;
579         }
580         list($hour_start, $minute_start) = explode( ':', $hour_start_string);
581         list($hour_finish, $minute_finish) = explode( ':', $hour_finish_string);
582         if ( !$hour_finish) {
583             $hour_finish = $hour_start;
584         }
585         if ( !$minute_finish) {
586             $minute_finish = $minute_start;
587         }
588     }
589     $html = $html.'<select name="'.$name.'[hour_start]"/>';
590     $default = '';
591     if ( $hour_start === '-' ) {
592         $default = ' selected';
593     }
594     $html = $html."<option value=\"-\" $default>-";
595     for ($i = 0 ; $i < 24 ; $i++) {
596         $default = "";
597         if ( sprintf("%02d", $i) === $hour_start ) {
598             $default = ' selected';
599         }
600         $html = $html."<option value=\"$i\" $default> ".sprintf("%02d", $i);
601     }
602     $html = $html.'</select>';
603     $html = $html.'<nbsp>:<nbsp>';
604     $html = $html.'<select name="'.$name.'[minute_start]"/>';
605     $default = '';
606     if ( $minute_start === '-' ) {
607          $default = ' selected';
608     }
609     $html = $html."<option value=\"-\" $default>-";
610     for ($i = 0 ; $i < 60 ; $i++) {
611         $default = "";
612         if ( sprintf("%02d", $i) === $minute_start ) {
613              $default = ' selected';
614         }
615         $html = $html."<option value=\"$i\" $default> ".sprintf("%02d", $i);
616     }
617     $html = $html.'</select>';
618     $html = $html.'</td>';
619     $html = $html.'</tr>';
620     $html = $html.'<tr>';
621     $html = $html.'<td>'._("Time to finish:").'</td>';
622     $html = $html.'<td>';
623     $html = $html.'<select name="'.$name.'[hour_finish]"/>';
624     $default = '';
625     if ( $hour_finish === '-' ) {
626          $default = ' selected';
627     }
628     $html = $html."<option value=\"-\" $default>-";
629     for ($i = 0 ; $i < 24 ; $i++) {
630         $default = "";
631         if ( sprintf("%02d", $i) === $hour_finish) {
632              $default = ' selected';
633         }
634         $html = $html."<option value=\"$i\" $default> ".sprintf("%02d", $i);
635     }
636     $html = $html.'</select>';
637     $html = $html.'<nbsp>:<nbsp>';
638     $html = $html.'<select name="'.$name.'[minute_finish]"/>';
639     $default = '';
640     if ( $minute_finish === '-' ) {
641          $default = ' selected';
642     }
643     $html = $html."<option value=\"-\" $default>-";
644     for ($i = 0 ; $i < 60 ; $i++) {
645         $default = '';
646         if ( sprintf("%02d", $i) === $minute_finish ) {
647              $default = ' selected';
648         }
649         $html = $html."<option value=\"$i\" $default> ".sprintf("%02d", $i);
650     }
651     $html = $html.'</select>';
652     $html = $html.'</td>';
653     $html = $html.'</tr>';
654     $html = $html.'<tr>';
655
656     // WDay could be *, day, day1-day2
657     if ( $time_wday != '*' ) {
658         list($wday_start, $wday_finish) = explode('-', $time_wday);
659         if ($wday_start === '*') {
660             $wday_start = $wday_finish;
661         }
662         if ($wday_finish === '*') {
663             $wday_finish = $wday_start;
664         }
665         if ( !$wday_finish) {
666              $wday_finish = $wday_start;
667         }
668     } else {
669         $wday_start = $wday_finish = '-';
670     }
671     $html = $html.'<td>'._("Week Day Start:").'</td>';
672     $html = $html.'<td>';
673     $html = $html.'<select name="'.$name.'[wday_start]"/>';
674     if ( $wday_start == '-' ) {
675         $default = ' selected';
676     } else {
677         $default = '';
678     }
679     $html = $html."<option value=\"-\" $default>-";
680  
681     if ( $wday_start == 'mon' ) {
682         $default = ' selected';
683     } else {
684         $default = '';
685     }
686     $html = $html."<option value=\"mon\" $default>" . _("Monday");
687
688     if ( $wday_start == 'tue' ) {
689         $default = ' selected';
690     } else {
691         $default = '';
692     }
693     $html = $html."<option value=\"tue\" $default>" . _("Tuesday");
694
695     if ( $wday_start == 'wed' ) {
696         $default = ' selected';
697     } else {
698         $default = '';
699     }
700     $html = $html."<option value=\"wed\" $default>" . _("Wednesday");
701
702     if ( $wday_start == 'thu' ) {
703         $default = ' selected';
704     } else {
705         $default = '';
706     }
707     $html = $html."<option value=\"thu\" $default>" . _("Thursday");
708
709     if ( $wday_start == 'fri' ) {
710         $default = ' selected';
711     } else {
712         $default = '';
713     }
714     $html = $html."<option value=\"fri\" $default>" . _("Friday");
715
716     if ( $wday_start == 'sat' ) {
717         $default = ' selected';
718     } else {
719         $default = '';
720     }
721     $html = $html."<option value=\"sat\" $default>" . _("Saturday");
722
723     if ( $wday_start == 'sun' ) {
724         $default = ' selected';
725     } else {
726         $default = '';
727     }
728     $html = $html."<option value=\"sun\" $default>" . _("Sunday");
729
730     $html = $html.'</td>';
731     $html = $html.'</tr>';
732     $html = $html.'<tr>';
733     $html = $html.'<td>'._("Week Day finish:").'</td>';
734     $html = $html.'<td>';
735     $html = $html.'<select name="'.$name.'[wday_finish]"/>';
736
737     if ( $wday_finish == '-' ) {
738         $default = ' selected';
739     } else {
740         $default = '';
741     }
742     $html = $html."<option value=\"-\" $default>-";
743  
744     if ( $wday_finish == 'mon' ) {
745         $default = ' selected';
746     } else {
747         $default = '';
748     }
749     $html = $html."<option value=\"mon\" $default>" . _("Monday");
750
751     if ( $wday_finish == 'tue' ) {
752         $default = ' selected';
753     } else {
754         $default = '';
755     }
756     $html = $html."<option value=\"tue\" $default>" . _("Tuesday");
757
758     if ( $wday_finish == 'wed' ) {
759         $default = ' selected';
760     } else {
761         $default = '';
762     }
763     $html = $html."<option value=\"wed\" $default>" . _("Wednesday");
764
765     if ( $wday_finish == 'thu' ) {
766         $default = ' selected';
767     } else {
768         $default = '';
769     }
770     $html = $html."<option value=\"thu\" $default>" . _("Thursday");
771
772     if ( $wday_finish == 'fri' ) {
773         $default = ' selected';
774     } else {
775         $default = '';
776     }
777     $html = $html."<option value=\"fri\" $default>" . _("Friday");
778
779     if ( $wday_finish == 'sat' ) {
780         $default = ' selected';
781     } else {
782         $default = '';
783     }
784     $html = $html."<option value=\"sat\" $default>" . _("Saturday");
785
786     if ( $wday_finish == 'sun' ) {
787         $default = ' selected';
788     } else {
789         $default = '';
790     }
791     $html = $html."<option value=\"sun\" $default>" . _("Sunday");
792
793     $html = $html.'</td>';
794     $html = $html.'</tr>';
795     $html = $html.'<tr>';
796     $html = $html.'<td>'._("Month Day start:").'</td>';
797
798     // MDay could be *, day, day1-day2
799     if ( $time_mday != '*' ) {
800         list($mday_start, $mday_finish) = explode('-', $time_mday);
801         if ($mday_start === '*') {
802             $mday_start = $mday_finish;
803         }
804         if ($mday_finish === '*') {
805             $mday_finish = $mday_start;
806         }
807         if ( !$mday_finish) {
808             $mday_finish = $mday_start;
809         }
810     } else {
811         $mday_start = $mday_finish = '-';
812     }
813
814     $html = $html.'<td>';
815     $html = $html.'<select name="'.$name.'[mday_start]"/>';
816     $default = '';
817     if ( $mday_start == '-' ) {
818         $default = ' selected';
819     }
820     $html = $html."<option value=\"-\" $default>-";
821     for ($i = 1 ; $i < 32 ; $i++) {
822         $default = '';
823         if ( $i == $mday_start ) {
824              $default = ' selected';
825         }
826         $html = $html."<option value=\"$i\" $default> $i";
827     }
828     $html = $html.'</select>';
829     $html = $html.'</td>';
830     $html = $html.'<tr>';
831     $html = $html.'<td>'._("Month Day finish:").'</td>';
832     $html = $html.'<td>';
833     $html = $html.'<select name="'.$name.'[mday_finish]"/>';
834     $default = '';
835     if ( $mday_finish == '-' ) {
836          $default = ' selected';
837     }
838     $html = $html."<option value=\"-\" $default>-";
839     for ($i = 1 ; $i < 32 ; $i++) {
840         $default = '';
841         if ( $i == $mday_finish ) {
842              $default = ' selected';
843         }
844         $html = $html."<option value=\"$i\" $default> $i";
845     }
846     $html = $html.'</select>';
847     $html = $html.'</td>';
848     $html = $html.'</tr>';
849     $html = $html.'<tr>';
850     $html = $html.'<td>'._("Month start:").'</td>';
851
852     // Month could be *, month, month1-month2
853     if ( $time_month != '*' ) {
854         list($month_start, $month_finish) = explode('-', $time_month);
855         if ($month_start === '*') {
856             $month_start = $month_finish;
857         }
858         if ($month_finish === '*') {
859             $month_finish = $month_start;
860         }
861         if ( !$month_finish) {
862              $month_finish = $month_start;
863         }
864     } else {
865         $month_start = $month_finish = '-';
866     }
867     $html = $html.'<td>';
868     $html = $html.'<select name="'.$name.'[month_start]"/>';
869
870     if ( $month_start == '-' ) {
871         $default = ' selected';
872     } else {
873         $default = '';
874     }
875     $html = $html."<option value=\"-\" $default>-";
876
877     if ( $month_start == 'jan' ) {
878         $default = ' selected';
879     } else {
880         $default = '';
881     }
882     $html = $html."<option value=\"jan\" $default>" . _("January");
883                                   
884     if ( $month_start == 'feb' ) {
885         $default = ' selected';
886     } else {
887         $default = '';
888     }
889     $html = $html."<option value=\"feb\" $default>" . _("February");
890     
891     if ( $month_start == 'mar' ) {
892         $default = ' selected';
893     } else {
894         $default = '';
895     }
896     $html = $html."<option value=\"mar\" $default>" . _("March");
897                                   
898     if ( $month_start == 'apr' ) {
899         $default = ' selected';
900     } else {
901         $default = '';
902     }
903     $html = $html."<option value=\"apr\" $default>" . _("April");
904     
905     if ( $month_start == 'may' ) {
906         $default = ' selected';
907     } else {
908         $default = '';
909     }
910     $html = $html."<option value=\"may\" $default>" . _("May");
911                               
912     if ( $month_start == 'jun' ) {
913         $default = ' selected';
914     } else {
915         $default = '';
916     }
917     $html = $html."<option value=\"jun\" $default>" . _("June");
918
919     if ( $month_start == 'jul' ) {
920         $default = ' selected';
921     } else {
922         $default = '';
923     }
924     $html = $html."<option value=\"jul\" $default>" . _("July");
925                                   
926     if ( $month_start == 'aug' ) {
927         $default = ' selected';
928     } else {
929         $default = '';
930     }
931     $html = $html."<option value=\"aug\" $default>" . _("August");
932     
933     if ( $month_start == 'sep' ) {
934         $default = ' selected';
935     } else {
936         $default = '';
937     }
938     $html = $html."<option value=\"sep\" $default>" . _("September");
939                               
940     if ( $month_start == 'oct' ) {
941         $default = ' selected';
942     } else {
943         $default = '';
944     }
945     $html = $html."<option value=\"oct\" $default>" . _("October");
946
947     if ( $month_start == 'nov' ) {
948         $default = ' selected';
949     } else {
950         $default = '';
951     }
952     $html = $html."<option value=\"nov\" $default>" . _("November");
953                                   
954     if ( $month_start == 'dec' ) {
955         $default = ' selected';
956     } else {
957         $default = '';
958     }
959     $html = $html."<option value=\"dec\" $default>" . _("December");
960
961     $html = $html.'</select>';
962     $html = $html.'</td>';
963     $html = $html.'</tr>';
964     $html = $html.'<tr>';
965     $html = $html.'<td>'._("Month finish:").'</td>';
966     $html = $html.'<td>';
967     $html = $html.'<select name="'.$name.'[month_finish]"/>';
968
969     if ( $month_finish == '-' ) {
970         $default = ' selected';
971     } else {
972         $default = '';
973     }
974     $html = $html."<option value=\"-\" $default>-";
975
976     if ( $month_finish == 'jan' ) {
977         $default = ' selected';
978     } else {
979         $default = '';
980     }
981     $html = $html."<option value=\"jan\" $default>" . _("January");
982                                   
983     if ( $month_finish == 'feb' ) {
984         $default = ' selected';
985     } else {
986         $default = '';
987     }
988     $html = $html."<option value=\"feb\" $default>" . _("February");
989     
990     if ( $month_finish == 'mar' ) {
991         $default = ' selected';
992     } else {
993         $default = '';
994     }
995     $html = $html."<option value=\"mar\" $default>" . _("March");
996                                   
997     if ( $month_finish == 'apr' ) {
998         $default = ' selected';
999     } else {
1000         $default = '';
1001     }
1002     $html = $html."<option value=\"apr\" $default>" . _("April");
1003     
1004     if ( $month_finish == 'may' ) {
1005         $default = ' selected';
1006     } else {
1007         $default = '';
1008     }
1009     $html = $html."<option value=\"may\" $default>" . _("May");
1010                                   
1011     if ( $month_finish == 'jun' ) {
1012         $default = ' selected';
1013     } else {
1014         $default = '';
1015     }
1016     $html = $html."<option value=\"jun\" $default>" . _("June");
1017     
1018     if ( $month_finish == 'jul' ) {
1019         $default = ' selected';
1020     } else {
1021         $default = '';
1022     }
1023     $html = $html."<option value=\"jul\" $default>" . _("July");
1024                                   
1025     if ( $month_finish == 'aug' ) {
1026         $default = ' selected';
1027     } else {
1028         $default = '';
1029     }
1030     $html = $html."<option value=\"aug\" $default>" . _("August");
1031     
1032     if ( $month_finish == 'sep' ) {
1033         $default = ' selected';
1034     } else {
1035         $default = '';
1036     }
1037     $html = $html."<option value=\"sep\" $default>" . _("September");
1038                                   
1039     if ( $month_finish == 'oct' ) {
1040         $default = ' selected';
1041     } else {
1042         $default = '';
1043     }
1044     $html = $html."<option value=\"oct\" $default>" . _("October");
1045     
1046     if ( $month_finish == 'nov' ) {
1047         $default = ' selected';
1048     } else {
1049         $default = '';
1050     }
1051     $html = $html."<option value=\"nov\" $default>" . _("November");
1052                                   
1053     if ( $month_finish == 'dec' ) {
1054         $default = ' selected';
1055     } else {
1056         $default = '';
1057     }
1058     $html = $html."<option value=\"dec\" $default>" . _("December");
1059
1060     $html = $html.'</select>';
1061     $html = $html.'</td>';
1062     $html = $html.'</tr>';
1063     $html = $html.'</tr>';
1064     return $html;
1065 }
1066
1067 function timeconditions_timegroups_buildtime( $hour_start, $minute_start, $hour_finish, $minute_finish, $wday_start, $wday_finish, $mday_start, $mday_finish, $month_start, $month_finish) {
1068
1069     //----- Time Hour Interval proccess ----
1070     //
1071     if ($minute_start == '-') {
1072         $time_minute_start = "00";
1073     } else {
1074         $time_minute_start = sprintf("%02d",$minute_start);
1075     }
1076     if ($minute_finish == '-') {
1077         $time_minute_finish = "00";
1078     } else {
1079         $time_minute_finish = sprintf("%02d",$minute_finish);
1080     }
1081     if ($hour_start == '-') {
1082         $time_hour_start = '*';
1083     } else {
1084         $time_hour_start = sprintf("%02d",$hour_start) . ':' . $time_minute_start;
1085     }
1086     if ($hour_finish == '-') {
1087         $time_hour_finish = '*';
1088     } else {
1089         $time_hour_finish = sprintf("%02d",$hour_finish) . ':' . $time_minute_finish;
1090     }
1091     if ($time_hour_start === '*') {
1092         $time_hour_start = $time_hour_finish;
1093     }
1094     if ($time_hour_finish === '*') {$time_hour_finish = $time_hour_start;}
1095     if ($time_hour_start == $time_hour_finish) {
1096         $time_hour = $time_hour_start;
1097     } else {
1098         $time_hour = $time_hour_start . '-' . $time_hour_finish;
1099     }
1100
1101     //----- Time Week Day Interval proccess -----
1102     //
1103     if ($wday_start == '-') {
1104         $time_wday_start = '*';
1105     } else {
1106         $time_wday_start = $wday_start;
1107     }
1108     if ($wday_finish == '-') {
1109         $time_wday_finish = '*';
1110     } else {
1111         $time_wday_finish = $wday_finish;
1112     }
1113     if ($time_wday_start === '*') {
1114         $time_wday_start = $time_wday_finish;
1115     }
1116     if ($time_wday_finish === '*') {
1117         $time_wday_finish = $time_wday_start;
1118     }
1119     if ($time_wday_start == $time_wday_finish) {
1120         $time_wday = $time_wday_start;
1121     } else {
1122         $time_wday = $time_wday_start . '-' . $time_wday_finish;
1123     }
1124
1125     //----- Time Month Day Interval proccess -----
1126     //
1127     if ($mday_start == '-') {
1128         $time_mday_start = '*';
1129     } else {
1130         $time_mday_start = $mday_start;
1131     }
1132     if ($mday_finish == '-') {
1133         $time_mday_finish = '*';
1134     } else {
1135         $time_mday_finish = $mday_finish;
1136     }
1137     if ($time_mday_start === '*') {
1138         $time_mday_start = $time_mday_finish;
1139     }
1140     if ($time_mday_finish === '*') {
1141         $time_mday_finish = $time_mday_start;
1142     }
1143     if ($time_mday_start == $time_mday_finish) {
1144         $time_mday = $time_mday_start;
1145     } else {
1146         $time_mday = $time_mday_start . '-' . $time_mday_finish;
1147     }
1148
1149     //----- Time Month Interval proccess -----
1150     //
1151     if ($month_start == '-') {
1152         $time_month_start = '*';
1153     } else {
1154         $time_month_start = $month_start;
1155     }
1156     if ($month_finish == '-') {
1157         $time_month_finish = '*';
1158     } else {
1159         $time_month_finish = $month_finish;
1160     }
1161     if ($time_month_start === '*') {
1162         $time_month_start = $time_month_finish;
1163     }
1164     if ($time_month_finish === '*') {
1165         $time_month_finish = $time_month_start;
1166     }
1167     if ($time_month_start == $time_month_finish) {
1168         $time_month = $time_month_start;
1169     } else {
1170         $time_month = $time_month_start . '-' . $time_month_finish;
1171     }
1172     $time = $time_hour . '|' . $time_wday . '|' . $time_mday . '|' . $time_month;
1173     return $time;
1174 }
1175
1176 //---------------------------end stolen from timeconditions-------------------------------------
1177
1178 ?>
1179
Note: See TracBrowser for help on using the browser.