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

Revision 3204, 24.8 kB (checked in by gregmac, 6 years ago)

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