root/modules/branches/2.2/timeconditions/page.timeconditions.php

Revision 2551, 24.7 kB (checked in by qldrob, 7 years ago)

Ah, that was a silly mistake. Not null, but default.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1 <?php /* $Id */
2 //Copyright (C) 2004 Coalescent Systems Inc. (info@coalescentsystems.ca)
3 //
4 //This program is free software; you can redistribute it and/or
5 //modify it under the terms of the GNU General Public License
6 //as published by the Free Software Foundation; either version 2
7 //of the License, or (at your option) any later version.
8 //
9 //This program is distributed in the hope that it will be useful,
10 //but WITHOUT ANY WARRANTY; without even the implied warranty of
11 //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 //GNU General Public License for more details.
13
14
15 isset($_REQUEST['action'])?$action = $_REQUEST['action']:$action='';
16 //the item we are currently displaying
17 isset($_REQUEST['itemid'])?$itemid=mysql_real_escape_string($_REQUEST['itemid']):$itemid='';
18
19 $dispnum = "timeconditions"; //used for switch on config.php
20
21 //if submitting form, update database
22 switch ($action) {
23     case "add":
24         timeconditions_add($_POST);
25         needreload();
26     break;
27     case "delete":
28         timeconditions_del($itemid);
29         needreload();
30     break;
31     case "edit"//just delete and re-add
32         timeconditions_edit($itemid,$_POST);
33         needreload();
34     break;
35 }
36
37
38 //get list of time conditions
39 $timeconditions = timeconditions_list();
40 ?>
41
42 </div> <!-- end content div so we can display rnav properly-->
43
44 <!-- right side menu -->
45 <div class="rnav">
46     <li><a id="<?php echo ($itemid=='' ? 'current':'') ?>" href="config.php?display=<?php echo urlencode($dispnum)?>"><?php echo _("Add Time Condition")?></a></li>
47 <?php
48 if (isset($timeconditions)) {
49     foreach ($timeconditions as $timecond) {
50         echo "<li><a id=\"".($itemid==$timecond['timeconditions_id'] ? 'current':'')."\" href=\"config.php?display=".urlencode($dispnum)."&itemid=".urlencode($timecond['timeconditions_id'])."\">{$timecond['displayname']}</a></li>";
51     }
52 }
53 ?>
54 </div>
55
56 <div style="float: right; padding: 5px; background: #e0e0ff; border: #2E78A7 solid 1px;">
57     <?php echo _("Server time:")?> <span id="idTime">00:00:00</span>
58 </div>
59
60 <script>
61 var hour = <?php $l = localtime(); echo $l[2]?>;
62 var min  = <?php $l = localtime(); echo $l[1]?>;
63 var sec  = <?php $l = localtime(); echo $l[0]?>;
64
65 // happily stollen from http://www.aspfaq.com/show.asp?id=2300
66 function PadDigits(n, totalDigits)
67 {
68     n = n.toString();
69     var pd = '';
70     if (totalDigits > n.length)
71     {
72         for (i=0; i < (totalDigits-n.length); i++)
73         {
74             pd += '0';
75         }
76     }
77     return pd + n.toString();
78 }
79
80 function updateTime()
81 {
82     sec++;
83     if (sec==60)
84     {
85         min++;
86         sec = 0;
87     }   
88        
89     if (min==60)
90     {
91         hour++;
92         min = 0;
93     }
94
95     if (hour==24)
96     {
97         hour = 0;
98     }
99    
100     document.getElementById("idTime").innerHTML = PadDigits(hour,2)+":"+PadDigits(min,2)+":"+PadDigits(sec,2);
101     setTimeout('updateTime()',1000);
102 }
103
104 updateTime();
105 </script>
106
107
108 <div class="content">
109 <?php
110 if ($action == 'delete') {
111     echo '<br><h3>'._("Time Condition").' '.$itemid.' '._("deleted").'!</h3>';
112 } else {
113     if ($itemid){
114         //get details for this time condition
115         $thisItem = timeconditions_get($itemid);
116     }
117
118     $delURL = $_SERVER['PHP_SELF'].'?'.$_SERVER['QUERY_STRING'].'&action=delete';
119 ?>
120
121     <h2><?php echo ($itemid ? _("Time Condition:")." ". $itemid : _("Add Time Condition")); ?></h2>
122 <?php        if ($itemid){ ?>
123     <p><a href="<?php echo $delURL ?>"><?php echo _("Delete Time Condition")?> <?php echo $itemid; ?></a></p>
124 <?php        } ?>
125     <form autocomplete="off" name="edit" action="<?php $_SERVER['PHP_SELF'] ?>" method="post" onsubmit="return edit_onsubmit();">
126     <input type="hidden" name="display" value="<?php echo $dispnum?>">
127     <input type="hidden" name="action" value="<?php echo ($itemid ? 'edit' : 'add') ?>">
128     <input type="hidden" name="deptname" value="<?php echo $_SESSION["AMP_user"]->_deptname ?>">
129     <table>
130     <tr><td colspan="2"><h5><?php echo ($itemid ? _("Edit Time Condition") : _("Add Time Condition")) ?><hr></h5></td></tr>
131
132 <?php        if ($itemid){ ?>
133         <input type="hidden" name="account" value="<?php echo $itemid; ?>">
134 <?php        }?>
135
136     <tr>
137         <td><a href="#" class="info"><?php echo _("Time Condition name:")?><span><?php echo _("Give this Time Condition a brief name to help you identify it.")?></span></a></td>
138         <td><input type="text" name="displayname" value="<?php echo (isset($thisItem['displayname']) ? $thisItem['displayname'] : ''); ?>"></td>
139     </tr>
140     <tr>
141         <td><a href="#" class="info"><?php echo _("Time to match:")?><span><?php echo _("time range|days of week|days of month|months<br><br>you can use an * as a wildcard.<br><br>ex: <b>9:00-17:00|mon-fri|*|*</b>")?></span></a></td>
142                <?php
143                    // ----- Load Time Pattern Variables -----
144         if (isset($thisItem)) {
145             list($time_hour, $time_wday, $time_mday, $time_month) = explode( '|', $thisItem['time'] );
146         } else {
147             list($time_hour, $time_wday, $time_mday, $time_month) = Array('*','-','-','-');
148         }
149             
150                ?>
151                <tr>
152                    <td><?php echo _("Time to start:")?></td>
153                    <td>
154                        <?php
155                            // Hour could be *, hh:mm, hh:mm-hhmm
156                            if ( $time_hour === '*' ) {
157                                $hour_start = $hour_finish = '-';
158                                $minute_start = $minute_finish = '-';
159                } else {
160                                list($hour_start_string, $hour_finish_string) = explode('-', $time_hour);
161                                list($hour_start, $minute_start) = explode( ':', $hour_start_string);
162                                list($hour_finish, $minute_finish) = explode( ':', $hour_finish_string);
163                                if ( !$hour_finish ) $hour_finish = $hour_start;
164                                if ( !$minute_finish ) $minute_finish = $minute_start;
165                            }
166                        ?>
167                         <select name="hour_start"/>
168                         <?php
169                            $default = '';
170                             if ( $hour_start === '-' ) $default = ' selected';
171                             echo "<option value=\"-\" $default>-";
172                             for ($i = 0 ; $i < 24 ; $i++) {
173                                $default = "";
174                                if ( sprintf("%02d", $i) === $hour_start ) $default = ' selected';
175                                 echo "<option value=\"$i\" $default> ".sprintf("%02d", $i);
176                             }
177                         ?>
178                         </select>
179                        <nbsp>:<nbsp>
180                         <select name="minute_start"/>
181                         <?php
182                            $default = '';
183                             if ( $minute_start === '-' ) $default = ' selected';
184                             echo "<option value=\"-\" $default>-";
185                             for ($i = 0 ; $i < 60 ; $i++) {
186                                 $default = "";
187                                 if ( sprintf("%02d", $i) === $minute_start ) $default = ' selected';
188                                 echo "<option value=\"$i\" $default> ".sprintf("%02d", $i);
189                             }
190                         ?>
191                         </select>
192                     </td>
193                </tr>
194                <tr>
195                    <td><?php echo _("Time to finish:")?></td>
196                    <td>
197                         <select name="hour_finish"/>
198                         <?php
199                            $default = '';
200                             if ( $hour_finish === '-' ) $default = ' selected';
201                             echo "<option value=\"-\" $default>-";
202                             for ($i = 0 ; $i < 24 ; $i++) {
203                                 $default = "";
204                                 if ( sprintf("%02d", $i) === $hour_finish) $default = ' selected';
205                                 echo "<option value=\"$i\" $default> ".sprintf("%02d", $i);
206                             }
207                         ?>
208                         </select>
209                        <nbsp>:<nbsp>
210                         <select name="minute_finish"/>
211                         <?php
212                             $default = '';
213                             if ( $minute_finish === '-' ) $default = ' selected';
214                             echo "<option value=\"-\" $default>-";
215                             for ($i = 0 ; $i < 60 ; $i++) {
216                                $default = '';
217                                 if ( sprintf("%02d", $i) === $minute_finish ) $default = ' selected';
218                                 echo "<option value=\"$i\" $default> ".sprintf("%02d", $i);
219                             }
220                         ?>
221                         </select>
222                     </td>
223                </tr>
224                 <tr>
225                    <?php
226                          // WDay could be *, day, day1-day2
227                          if ( $time_wday != '*' ) {
228                              list($wday_start, $wday_finish) = explode('-', $time_wday);
229                              if ( !$wday_finish) $wday_finish = $wday_start;
230                          } else {
231                              $wday_start = $wday_finish = '-';
232                          }
233                     ?>
234                    <td><?php echo _("Week Day Start:")?></td>
235                    <td>
236                        <select name="wday_start"/>
237                            <?php
238                                if ( $wday_start == '-' ) { $default = ' selected'; }
239                                else {$default = '';}
240                                echo "<option value=\"-\" $default>-";
241  
242                                if ( $wday_start == 'mon' ) { $default = ' selected'; }
243                                 else {$default = '';}
244                                echo "<option value=\"mon\" $default>" . _("Monday");
245
246                                 if ( $wday_start == 'tue' ) { $default = ' selected'; }
247                                else {$default = '';}
248                                 echo "<option value=\"tue\" $default>" . _("Tuesday");
249
250                                 if ( $wday_start == 'wed' ) { $default = ' selected'; }
251                                else {$default = '';}
252                                 echo "<option value=\"wed\" $default>" . _("Wednesday");
253
254                                 if ( $wday_start == 'thu' ) { $default = ' selected'; }
255                                 else {$default = '';}
256                                 echo "<option value=\"thu\" $default>" . _("Thursday");
257
258                                 if ( $wday_start == 'fri' ) { $default = ' selected'; }
259                                 else {$default = '';}
260                                 echo "<option value=\"fri\" $default>" . _("Friday");
261
262                                 if ( $wday_start == 'sat' ) { $default = ' selected'; }
263                                 else {$default = '';}
264                                 echo "<option value=\"sat\" $default>" . _("Saturday");
265
266                                if ( $wday_start == 'sun' ) { $default = ' selected'; }
267                                 else {$default = '';}
268                                 echo "<option value=\"sun\" $default>" . _("Sunday");
269                        ?>
270            </td>
271                </tr>
272                <tr>
273                    <td><?php echo _("Week Day finish:")?></td>
274                    <td>
275                        <select name="wday_finish"/>
276                        <?php
277                                if ( $wday_finish == '-' ) { $default = ' selected'; }
278                                else {$default = '';}
279                                echo "<option value=\"-\" $default>-";
280  
281                                if ( $wday_finish == 'mon' ) { $default = ' selected'; }
282                                 else {$default = '';}
283                                echo "<option value=\"mon\" $default>" . _("Monday");
284
285                                 if ( $wday_finish == 'tue' ) { $default = ' selected'; }
286                                else {$default = '';}
287                                 echo "<option value=\"tue\" $default>" . _("Tuesday");
288
289                                 if ( $wday_finish == 'wed' ) { $default = ' selected'; }
290                                else {$default = '';}
291                                 echo "<option value=\"wed\" $default>" . _("Wednesday");
292
293                                 if ( $wday_finish == 'thu' ) { $default = ' selected'; }
294                                 else {$default = '';}
295                                 echo "<option value=\"thu\" $default>" . _("Thursday");
296
297                                 if ( $wday_finish == 'fri' ) { $default = ' selected'; }
298                                 else {$default = '';}
299                                 echo "<option value=\"fri\" $default>" . _("Friday");
300
301                                 if ( $wday_finish == 'sat' ) { $default = ' selected'; }
302                                 else {$default = '';}
303                                 echo "<option value=\"sat\" $default>" . _("Saturday");
304
305                                if ( $wday_finish == 'sun' ) { $default = ' selected'; }
306                                 else {$default = '';}
307                                 echo "<option value=\"sun\" $default>" . _("Sunday");
308                        ?>
309                    </td>
310                 </tr>
311                 <tr>
312                    <td><?php echo _("Month Day start:")?></td>
313                     <?php
314                          // MDay could be *, day, day1-day2
315                          if ( $time_mday != '*' ) {
316                              list($mday_start, $mday_finish) = explode('-', $time_mday);
317                              if ( !$mday_finish) $mday_finish = $mday_start;
318                          } else {
319                              $mday_start = $mday_finish = '-';
320                          }
321                    ?>
322                   <td>
323                         <select name="mday_start"/>
324                          <?php
325                             $default = '';
326                             if ( $mday_start == '-' ) $default = ' selected';
327                             echo "<option value=\"-\" $default>-";
328                             for ($i = 1 ; $i < 32 ; $i++) {
329                                 $default = '';
330                                 if ( $i == $mday_start ) $default = ' selected';
331                                 echo "<option value=\"$i\" $default> $i";
332                             }
333                         ?>
334                         </select>
335                     </td>
336                <tr>
337                    <td><?php echo _("Month Day finish:")?></td>
338                   <td>
339                         <select name="mday_finish"/>
340                         <?php
341                             $default = '';
342                             if ( $mday_finish == '-' ) $default = ' selected';
343                             echo "<option value=\"-\" $default>-";
344                             for ($i = 1 ; $i < 32 ; $i++) {
345                                 $default = '';
346                                 if ( $i == $mday_finish ) $default = ' selected';
347                                 echo "<option value=\"$i\" $default> $i";
348                             }
349                         ?>
350                         </select>
351                     </td>
352                </tr>
353                 <tr>
354                    <td><?php echo _("Month start:")?></td>
355                      <?php
356                          // Month could be *, month, month1-month2
357                          if ( $time_month != '*' ) {
358                              list($month_start, $month_finish) = explode('-', $time_month);
359                              if ( !$month_finish) $month_finish = $month_start;
360                          } else {
361                              $month_start = $month_finish = '-';
362                          }
363                    ?>
364                   <td>
365                         <select name="month_start"/>
366                             <?php   
367                                 if ( $month_start == '-' ) { $default = ' selected'; }
368                                 else {$default = '';}
369                                 echo "<option value=\"-\" $default>-";
370                                 if ( $month_start == 'jan' ) { $default = ' selected'; }
371                                 else {$default = '';}
372                                 echo "<option value=\"jan\" $default>" . _("January");
373                               
374                                 if ( $month_start == 'feb' ) { $default = ' selected'; }
375                                 else {$default = '';}
376                                 echo "<option value=\"feb\" $default>" . _("February");
377
378                                 if ( $month_start == 'mar' ) { $default = ' selected'; }
379                                 else {$default = '';}
380                                 echo "<option value=\"mar\" $default>" . _("March");
381                               
382                                 if ( $month_start == 'apr' ) { $default = ' selected'; }
383                                 else {$default = '';}
384                                 echo "<option value=\"apr\" $default>" . _("April");
385  
386                                if ( $month_start == 'may' ) { $default = ' selected'; }
387                                 else {$default = '';}
388                                 echo "<option value=\"may\" $default>" . _("May");
389                               
390                                 if ( $month_start == 'jun' ) { $default = ' selected'; }
391                                else {$default = '';}
392                                 echo "<option value=\"jun\" $default>" . _("June");
393
394                                 if ( $month_start == 'jul' ) { $default = ' selected'; }
395                                 else {$default = '';}
396                                 echo "<option value=\"jul\" $default>" . _("July");
397                               
398                                 if ( $month_start == 'aug' ) { $default = ' selected'; }
399                                 else {$default = '';}
400                                 echo "<option value=\"aug\" $default>" . _("August");
401  
402                                if ( $month_start == 'sep' ) { $default = ' selected'; }
403                                 else {$default = '';}
404                                 echo "<option value=\"sep\" $default>" . _("September");
405                               
406                                 if ( $month_start == 'oct' ) { $default = ' selected'; }
407                                 else {$default = '';}
408                                 echo "<option value=\"oct\" $default>" . _("October");
409                                 if ( $month_start == 'nov' ) { $default = ' selected'; }
410                                 else {$default = '';}
411                                 echo "<option value=\"nov\" $default>" . _("November");
412                               
413                                 if ( $month_start == 'dec' ) { $default = ' selected'; }
414                                 else {$default = '';}
415                                 echo "<option value=\"dec\" $default>" . _("December");
416                          ?>
417                        </select>
418                      </td>
419         </tr>
420                 <tr>
421                     <td><?php echo _("Month finish:")?></td>
422                     <td>
423                         <select name="month_finish"/>
424                         <?php   
425                                 if ( $month_finish == '-' ) { $default = ' selected'; }
426                                 else {$default = '';}
427                                 echo "<option value=\"-\" $default>-";
428                                 if ( $month_finish == 'jan' ) { $default = ' selected'; }
429                                 else {$default = '';}
430                                 echo "<option value=\"jan\" $default>" . _("January");
431                               
432                                 if ( $month_finish == 'feb' ) { $default = ' selected'; }
433                                 else {$default = '';}
434                                 echo "<option value=\"feb\" $default>" . _("February");
435
436                                 if ( $month_finish == 'mar' ) { $default = ' selected'; }
437                                 else {$default = '';}
438                                 echo "<option value=\"mar\" $default>" . _("March");
439                               
440                                 if ( $month_finish == 'apr' ) { $default = ' selected'; }
441                                 else {$default = '';}
442                                 echo "<option value=\"apr\" $default>" . _("April");
443  
444                                if ( $month_finish == 'may' ) { $default = ' selected'; }
445                                 else {$default = '';}
446                                 echo "<option value=\"may\" $default>" . _("May");
447                               
448                                 if ( $month_finish == 'jun' ) { $default = ' selected'; }
449                                 else {$default = '';}
450                                 echo "<option value=\"jun\" $default>" . _("June");
451
452                                 if ( $month_finish == 'jul' ) { $default = ' selected'; }
453                                 else {$default = '';}
454                                 echo "<option value=\"jul\" $default>" . _("July");
455                               
456                                 if ( $month_finish == 'aug' ) { $default = ' selected'; }
457                                 else {$default = '';}
458                                 echo "<option value=\"aug\" $default>" . _("August");
459  
460                                if ( $month_finish == 'sep' ) { $default = ' selected'; }
461                                 else {$default = '';}
462                                 echo "<option value=\"sep\" $default>" . _("September");
463                               
464                                if ( $month_finish == 'oct' ) { $default = ' selected'; }
465                                 else {$default = '';}
466                                 echo "<option value=\"oct\" $default>" . _("October");
467
468                                 if ( $month_finish == 'nov' ) { $default = ' selected'; }
469                                 else {$default = '';}
470                                 echo "<option value=\"nov\" $default>" . _("November");
471                               
472                                 if ( $month_finish == 'dec' ) { $default = ' selected'; }
473                                 else {$default = '';}
474                                 echo "<option value=\"dec\" $default>" . _("December");
475                          ?>
476                          </select>
477                      </td>
478                 </tr>
479     </tr>
480     <tr><td colspan="2"><br><h5><?php echo _("Destination if time matches")?>:<hr></h5></td></tr>
481 <?php
482 //draw goto selects
483 if (isset($thisItem)) {
484     echo drawselects($thisItem['truegoto'],0);
485 } else {
486     echo drawselects(null, 0);
487 }
488 ?>
489
490     <tr><td colspan="2"><br><h5><?php echo _("Destination if time does not match")?>:<hr></h5></td></tr>
491
492 <?php
493 //draw goto selects
494 if (isset($thisItem)) {
495     echo drawselects($thisItem['falsegoto'],1);
496 } else {
497     echo drawselects(null, 1);
498 }
499 ?>
500
501     <tr>
502         <td colspan="2"><br><h6><input name="Submit" type="submit" value="<?php echo _("Submit Changes")?>"></h6></td>       
503     </tr>
504     </table>
505 <script language="javascript">
506 <!--
507
508 var theForm = document.edit;
509 theForm.displayname.focus();
510
511 function edit_onsubmit() {
512     var msgInvalidTimeCondName = "<?php echo _('Please enter a valid Time Conditions Name'); ?>";
513     var msgInvalidTimeMatch = "<?php echo _('Please enter the Time to Match, or set all to - to match all times.'); ?>";
514     var msgInvalidDay = "<?php echo _('Please select BOTH or NO days, not just one.'); ?>";
515     var msgInvalidMday = "<?php echo _('Please select BOTH or NO days of the month, not just one.'); ?>";
516     var msgInvalidMth = "<?php echo _('Please select BOTH or NO months, not just one.'); ?>";
517
518    
519     defaultEmptyOK = false;
520     if (!isAlphanumeric(theForm.displayname.value))
521         return warnInvalid(theForm.displayname, msgInvalidTimeCondName);
522    
523     // Check to see that they're either all '-' or all numbers.
524     if ((theForm.hour_start.value == "-" || theForm.hour_finish.value == "-"  || theForm.minute_start.value == "-" || theForm.minute_finish.value == "-") && (theForm.hour_start.value != "-" || theForm.hour_finish.value != "-"  || theForm.minute_start.value != "-" || theForm.minute_finish.value != "-"))
525         return warnInvalid(theForm.displayname, msgInvalidTimeMatch);
526
527     if ((theForm.wday_start.value == "-" || theForm.wday_finish.value == "-") && (theForm.wday_start.value != "-" ||theForm.wday_finish.value != "-" ))
528         return warnInvalid(theForm.displayname, msgInvalidDay);
529
530     if ((theForm.mday_start.value == "-" || theForm.mday_finish.value == "-") && (theForm.mday_start.value != "-" || theForm.mday_finish.value != "-" ))
531         return warnInvalid(theForm.displayname, msgInvalidMday);
532
533     if ((theForm.month_start.value == "-" || theForm.month_finish.value == "-") && (theForm.month_start.value != "-" || theForm.month_finish.value != "-" ))
534         return warnInvalid(theForm.displayname, msgInvalidMth);
535        
536     if (!validateDestinations(edit,2,true))
537         return false;
538    
539     return true;
540 }
541
542
543 //-->
544 </script>
545
546
547     </form>
548 <?php       
549 } //end if action == delete
550 ?>
551
Note: See TracBrowser for help on using the browser.