1
|
<?php
|
2
|
/*
|
3
|
firewall_schedule_edit.php
|
4
|
Copyright (C) 2004 Scott Ullrich
|
5
|
All rights reserved.
|
6
|
|
7
|
originially part of m0n0wall (http://m0n0.ch/wall)
|
8
|
Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
|
9
|
All rights reserved.
|
10
|
|
11
|
Redistribution and use in source and binary forms, with or without
|
12
|
modification, are permitted provided that the following conditions are met:
|
13
|
|
14
|
1. Redistributions of source code must retain the above copyright notice,
|
15
|
this list of conditions and the following disclaimer.
|
16
|
|
17
|
2. Redistributions in binary form must reproduce the above copyright
|
18
|
notice, this list of conditions and the following disclaimer in the
|
19
|
documentation and/or other materials provided with the distribution.
|
20
|
|
21
|
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
22
|
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
23
|
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
24
|
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
25
|
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
26
|
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
27
|
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
28
|
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
29
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
30
|
POSSIBILITY OF SUCH DAMAGE.
|
31
|
*/
|
32
|
/*
|
33
|
pfSense_MODULE: schedules
|
34
|
*/
|
35
|
|
36
|
##|+PRIV
|
37
|
##|*IDENT=page-firewall-schedules-edit
|
38
|
##|*NAME=Firewall: Schedules: Edit page
|
39
|
##|*DESCR=Allow access to the 'Firewall: Schedules: Edit' page.
|
40
|
##|*MATCH=firewall_schedule_edit.php*
|
41
|
##|-PRIV
|
42
|
|
43
|
function schedulecmp($a, $b) {
|
44
|
return strcmp($a['name'], $b['name']);
|
45
|
}
|
46
|
|
47
|
function schedule_sort(){
|
48
|
global $g, $config;
|
49
|
|
50
|
if (!is_array($config['schedules']['schedule']))
|
51
|
return;
|
52
|
|
53
|
usort($config['schedules']['schedule'], "schedulecmp");
|
54
|
}
|
55
|
|
56
|
require("guiconfig.inc");
|
57
|
require_once("functions.inc");
|
58
|
require_once("filter.inc");
|
59
|
require_once("shaper.inc");
|
60
|
|
61
|
$pgtitle = array(gettext("Firewall"),gettext("Schedules"),gettext("Edit"));
|
62
|
|
63
|
$dayArray = array (gettext('Mon'),gettext('Tues'),gettext('Wed'),gettext('Thur'),gettext('Fri'),gettext('Sat'),gettext('Sun'));
|
64
|
$monthArray = array (gettext('January'),gettext('February'),gettext('March'),gettext('April'),gettext('May'),gettext('June'),gettext('July'),gettext('August'),gettext('September'),gettext('October'),gettext('November'),gettext('December'));
|
65
|
|
66
|
if (!is_array($config['schedules']['schedule']))
|
67
|
$config['schedules']['schedule'] = array();
|
68
|
|
69
|
$a_schedules = &$config['schedules']['schedule'];
|
70
|
|
71
|
if (is_numericint($_GET['id']))
|
72
|
$id = $_GET['id'];
|
73
|
if (isset($_POST['id']) && is_numericint($_POST['id']))
|
74
|
$id = $_POST['id'];
|
75
|
|
76
|
if (isset($id) && $a_schedules[$id]) {
|
77
|
$pconfig['name'] = $a_schedules[$id]['name'];
|
78
|
$pconfig['descr'] = html_entity_decode($a_schedules[$id]['descr']);
|
79
|
$pconfig['timerange'] = $a_schedules[$id]['timerange'];
|
80
|
$pconfig['schedlabel'] = $a_schedules[$id]['schedlabel'];
|
81
|
$getSchedule = true;
|
82
|
}
|
83
|
|
84
|
if ($_POST) {
|
85
|
|
86
|
if(strtolower($_POST['name']) == "lan")
|
87
|
$input_errors[] = gettext("Schedule may not be named LAN.");
|
88
|
if(strtolower($_POST['name']) == "wan")
|
89
|
$input_errors[] = gettext("Schedule may not be named WAN.");
|
90
|
if(strtolower($_POST['name']) == "")
|
91
|
$input_errors[] = gettext("Schedule name cannot be blank.");
|
92
|
|
93
|
$x = is_validaliasname($_POST['name']);
|
94
|
if (!isset($x)) {
|
95
|
$input_errors[] = gettext("Reserved word used for schedule name.");
|
96
|
} else {
|
97
|
if (is_validaliasname($_POST['name']) == false)
|
98
|
$input_errors[] = gettext("The schedule name may only consist of the characters a-z, A-Z, 0-9");
|
99
|
}
|
100
|
|
101
|
/* check for name conflicts */
|
102
|
foreach ($a_schedules as $schedule) {
|
103
|
if (isset($id) && ($a_schedules[$id]) && ($a_schedules[$id] === $schedule))
|
104
|
continue;
|
105
|
|
106
|
if ($schedule['name'] == $_POST['name']) {
|
107
|
$input_errors[] = gettext("A Schedule with this name already exists.");
|
108
|
break;
|
109
|
}
|
110
|
}
|
111
|
$schedule = array();
|
112
|
|
113
|
$schedule['name'] = $_POST['name'];
|
114
|
$schedule['descr'] = htmlentities($_POST['descr'], ENT_QUOTES, 'UTF-8');
|
115
|
|
116
|
$timerangeFound = false;
|
117
|
for ($x=0; $x<99; $x++){
|
118
|
if($_POST['schedule' . $x]) {
|
119
|
if (!preg_match('/^[0-9]+:[0-9]+$/', $_POST['starttime' . $x])) {
|
120
|
$input_errors[] = sprintf(gettext("Invalid start time - '%s'"), $_POST['starttime' . $x]);
|
121
|
continue;
|
122
|
}
|
123
|
if (!preg_match('/^[0-9]+:[0-9]+$/', $_POST['stoptime' . $x])) {
|
124
|
$input_errors[] = sprintf(gettext("Invalid start time - '%s'"), $_POST['stoptime' . $x]);
|
125
|
continue;
|
126
|
}
|
127
|
$timerangeFound = true;
|
128
|
$timeparts = array();
|
129
|
$firstprint = false;
|
130
|
$timestr = $_POST['schedule' . $x];
|
131
|
$timehourstr = $_POST['starttime' . $x];
|
132
|
$timehourstr .= "-";
|
133
|
$timehourstr .= $_POST['stoptime' . $x];
|
134
|
$timedescrstr = htmlentities($_POST['timedescr' . $x], ENT_QUOTES, 'UTF-8');
|
135
|
$dashpos = strpos($timestr, '-');
|
136
|
if ($dashpos === false)
|
137
|
{
|
138
|
$timeparts['position'] = $timestr;
|
139
|
}
|
140
|
else
|
141
|
{
|
142
|
$tempindarray = array();
|
143
|
$monthstr = "";
|
144
|
$daystr = "";
|
145
|
$tempindarray = explode(",", $timestr);
|
146
|
foreach ($tempindarray as $currentselection)
|
147
|
{
|
148
|
if ($currentselection){
|
149
|
if ($firstprint)
|
150
|
{
|
151
|
$monthstr .= ",";
|
152
|
$daystr .= ",";
|
153
|
}
|
154
|
$tempstr = "";
|
155
|
$monthpos = strpos($currentselection, "m");
|
156
|
$daypos = strpos($currentselection, "d");
|
157
|
$monthstr .= substr($currentselection, $monthpos+1, $daypos-$monthpos-1);
|
158
|
$daystr .= substr($currentselection, $daypos+1);
|
159
|
$firstprint = true;
|
160
|
}
|
161
|
}
|
162
|
$timeparts['month'] = $monthstr;
|
163
|
$timeparts['day'] = $daystr;
|
164
|
}
|
165
|
$timeparts['hour'] = $timehourstr;
|
166
|
$timeparts['rangedescr'] = $timedescrstr;
|
167
|
$schedule['timerange'][$x] = $timeparts;
|
168
|
}
|
169
|
}
|
170
|
|
171
|
if (!$timerangeFound)
|
172
|
$input_errors[] = gettext("The schedule must have at least one time range configured.");
|
173
|
|
174
|
if (!$input_errors) {
|
175
|
|
176
|
if (!empty($pconfig['schedlabel']))
|
177
|
$schedule['schedlabel'] = $pconfig['schedlabel'];
|
178
|
else
|
179
|
$schedule['schedlabel'] = uniqid();
|
180
|
|
181
|
if (isset($id) && $a_schedules[$id]){
|
182
|
$a_schedules[$id] = $schedule;
|
183
|
}
|
184
|
else{
|
185
|
$a_schedules[] = $schedule;
|
186
|
}
|
187
|
schedule_sort();
|
188
|
if (write_config())
|
189
|
filter_configure();
|
190
|
|
191
|
header("Location: firewall_schedule.php");
|
192
|
exit;
|
193
|
|
194
|
}
|
195
|
//we received input errors, copy data to prevent retype
|
196
|
else
|
197
|
{
|
198
|
if (!$_POST['schedule0'])
|
199
|
$getSchedule = false;
|
200
|
else
|
201
|
$getSchedule = true;
|
202
|
$pconfig['name'] = $schedule['name'];
|
203
|
$pconfig['descr'] = $schedule['descr'];
|
204
|
$pconfig['timerange'] = $schedule['timerange'];
|
205
|
}
|
206
|
|
207
|
}
|
208
|
include("head.inc");
|
209
|
|
210
|
/* put your custom HTML head content here */
|
211
|
/* using some of the $pfSenseHead function calls */
|
212
|
$jscriptstr = <<<EOD
|
213
|
<script type="text/javascript">
|
214
|
//<![CDATA[
|
215
|
var daysSelected = "";
|
216
|
var month_array = ['January','February','March','April','May','June','July','August','September','October','November','December'];
|
217
|
var day_array = ['Mon','Tues','Wed','Thur','Fri','Sat','Sun'];
|
218
|
var schCounter = 0;
|
219
|
|
220
|
function rgb2hex(rgb) {
|
221
|
var parts = rgb.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/);
|
222
|
if (parts == null)
|
223
|
return;
|
224
|
function hex(x) {
|
225
|
return ("0" + parseInt(x).toString(16)).slice(-2);
|
226
|
}
|
227
|
return ("#" + hex(parts[1]) + hex(parts[2]) + hex(parts[3])).toUpperCase();
|
228
|
}
|
229
|
|
230
|
function repeatExistingDays(){
|
231
|
var tempstr, tempstrdaypos, week, daypos, dayposdone = "";
|
232
|
|
233
|
var dayarray = daysSelected.split(",");
|
234
|
for (i=0; i<=dayarray.length; i++){
|
235
|
tempstr = dayarray[i];
|
236
|
tempstrdaypos = tempstr.search("p");
|
237
|
week = tempstr.substring(1,tempstrdaypos);
|
238
|
week = parseInt(week);
|
239
|
dashpos = tempstr.search("-");
|
240
|
daypos = tempstr.substring(tempstrdaypos+1, dashpos);
|
241
|
daypos = parseInt(daypos);
|
242
|
|
243
|
daydone = dayposdone.search(daypos);
|
244
|
tempstr = 'w' + week + 'p' + daypos;
|
245
|
daycell = eval('document.getElementById(tempstr)');
|
246
|
if (daydone == "-1"){
|
247
|
if (rgb2hex(daycell.style.backgroundColor) == "#F08080") // lightcoral
|
248
|
daytogglerepeating(week,daypos,true);
|
249
|
else
|
250
|
daytogglerepeating(week,daypos,false);
|
251
|
dayposdone += daypos + ",";
|
252
|
}
|
253
|
}
|
254
|
}
|
255
|
|
256
|
function daytogglerepeating(week,daypos,bExists){
|
257
|
var tempstr, daycell, dayoriginal = "";
|
258
|
for (j=1; j<=53; j++)
|
259
|
{
|
260
|
tempstr = 'w' + j + 'p' + daypos;
|
261
|
daycell = eval('document.getElementById(tempstr)');
|
262
|
dayoriginalpos = daysSelected.indexOf(tempstr);
|
263
|
|
264
|
//if bExists set to true, means cell is already select it
|
265
|
//unselect it and remove original day from daysSelected string
|
266
|
|
267
|
if (daycell != null)
|
268
|
{
|
269
|
if (bExists){
|
270
|
daycell.style.backgroundColor = "#FFFFFF"; // white
|
271
|
}
|
272
|
else
|
273
|
{
|
274
|
daycell.style.backgroundColor = "#F08080"; // lightcoral
|
275
|
}
|
276
|
|
277
|
if (dayoriginalpos != "-1")
|
278
|
{
|
279
|
dayoriginalend = daysSelected.indexOf(',', dayoriginalpos);
|
280
|
tempstr = daysSelected.substring(dayoriginalpos, dayoriginalend+1);
|
281
|
daysSelected = daysSelected.replace(tempstr, "");
|
282
|
|
283
|
}
|
284
|
}
|
285
|
}
|
286
|
}
|
287
|
|
288
|
function daytoggle(id) {
|
289
|
var runrepeat, tempstr = "";
|
290
|
var bFoundValid = false;
|
291
|
|
292
|
iddashpos = id.search("-");
|
293
|
var tempstrdaypos = id.search("p");
|
294
|
var week = id.substring(1,tempstrdaypos);
|
295
|
week = parseInt(week);
|
296
|
|
297
|
if (iddashpos == "-1")
|
298
|
{
|
299
|
idmod = id;
|
300
|
runrepeat = true;
|
301
|
var daypos = id.substr(tempstrdaypos+1);
|
302
|
}
|
303
|
else
|
304
|
{
|
305
|
idmod = id.substring(0,iddashpos);
|
306
|
var daypos = id.substring(tempstrdaypos+1,iddashpos);
|
307
|
}
|
308
|
|
309
|
daypos = parseInt(daypos);
|
310
|
|
311
|
while (!bFoundValid){
|
312
|
var daycell = document.getElementById(idmod);
|
313
|
|
314
|
if (daycell != null){
|
315
|
if (rgb2hex(daycell.style.backgroundColor) == "#FF0000"){ // red
|
316
|
daycell.style.backgroundColor = "#FFFFFF"; // white
|
317
|
str = id + ",";
|
318
|
daysSelected = daysSelected.replace(str, "");
|
319
|
}
|
320
|
else if (rgb2hex(daycell.style.backgroundColor) == "#F08080") // lightcoral
|
321
|
{
|
322
|
daytogglerepeating(week,daypos,true);
|
323
|
}
|
324
|
else //color is white cell
|
325
|
{
|
326
|
if (!runrepeat)
|
327
|
{
|
328
|
daycell.style.backgroundColor = "#FF0000"; // red
|
329
|
}
|
330
|
else
|
331
|
{
|
332
|
daycell.style.backgroundColor = "#F08080"; // lightcoral
|
333
|
daytogglerepeating(week,daypos,false);
|
334
|
}
|
335
|
daysSelected += id + ",";
|
336
|
}
|
337
|
bFoundValid = true;
|
338
|
}
|
339
|
else
|
340
|
{
|
341
|
//we found an invalid cell when column was clicked, move up to the next week
|
342
|
week++;
|
343
|
tempstr = "w" + week + "p" + daypos;
|
344
|
idmod = tempstr;
|
345
|
}
|
346
|
}
|
347
|
}
|
348
|
|
349
|
function update_month(){
|
350
|
var indexNum = document.forms[0].monthsel.selectedIndex;
|
351
|
var selected = document.forms[0].monthsel.options[indexNum].text;
|
352
|
|
353
|
for (i=0; i<=11; i++){
|
354
|
option = document.forms[0].monthsel.options[i].text;
|
355
|
document.popupMonthLayer = eval('document.getElementById (option)');
|
356
|
|
357
|
if(selected == option) {
|
358
|
document.popupMonthLayer.style.display="block";
|
359
|
}
|
360
|
else
|
361
|
document.popupMonthLayer.style.display="none";
|
362
|
}
|
363
|
}
|
364
|
|
365
|
function checkForRanges(){
|
366
|
if (daysSelected != "")
|
367
|
{
|
368
|
alert("You have not saved the specified time range. Please click 'Add Time' button to save the time range.");
|
369
|
return false;
|
370
|
}
|
371
|
else
|
372
|
{
|
373
|
return true;
|
374
|
}
|
375
|
}
|
376
|
|
377
|
function processEntries(){
|
378
|
var tempstr, starttimehour, starttimemin, stoptimehour, stoptimemin, errors = "";
|
379
|
var passedValidiation = true;
|
380
|
|
381
|
//get time specified
|
382
|
starttimehour = parseInt(document.getElementById("starttimehour").value);
|
383
|
starttimemin = parseInt(document.getElementById("starttimemin").value);
|
384
|
stoptimehour = parseInt(document.getElementById("stoptimehour").value);
|
385
|
stoptimemin = parseInt(document.getElementById("stoptimemin").value);
|
386
|
|
387
|
|
388
|
//do time checks
|
389
|
if (starttimehour > stoptimehour)
|
390
|
{
|
391
|
errors = "Error: Start Hour cannot be greater than Stop Hour.";
|
392
|
passedValidiation = false;
|
393
|
|
394
|
}
|
395
|
else if (starttimehour == stoptimehour)
|
396
|
{
|
397
|
if (starttimemin > stoptimemin){
|
398
|
errors = "Error: Start Minute cannot be greater than Stop Minute.";
|
399
|
passedValidiation = false;
|
400
|
}
|
401
|
}
|
402
|
|
403
|
if (passedValidiation){
|
404
|
addTimeRange();
|
405
|
}
|
406
|
else {
|
407
|
if (errors != "")
|
408
|
alert(errors);
|
409
|
}
|
410
|
}
|
411
|
|
412
|
function addTimeRange(){
|
413
|
var tempdayarray = daysSelected.split(",");
|
414
|
var tempstr, tempFriendlyDay, starttimehour, starttimemin, stoptimehour, nrtempFriendlyTime, rtempFriendlyTime, nrtempID, rtempID = "";
|
415
|
var stoptimemin, timeRange, tempstrdaypos, week, daypos, day, month, dashpos, nrtempTime, rtempTime, monthstr, daystr = "";
|
416
|
rtempFriendlyTime = "";
|
417
|
nrtempFriendlyTime = "";
|
418
|
nrtempID = "";
|
419
|
rtempID = "";
|
420
|
nrtempTime = "";
|
421
|
rtempTime = "";
|
422
|
tempdayarray.sort();
|
423
|
rtempFriendlyDay = "";
|
424
|
monthstr = "";
|
425
|
daystr = "";
|
426
|
|
427
|
//check for existing entries
|
428
|
var findCurrentCounter;
|
429
|
for (u=0; u<99; u++){
|
430
|
findCurrentCounter = document.getElementById("schedule" + u);
|
431
|
if (!findCurrentCounter)
|
432
|
{
|
433
|
schCounter = u;
|
434
|
break;
|
435
|
}
|
436
|
}
|
437
|
|
438
|
if (daysSelected != ""){
|
439
|
//get days selected
|
440
|
for (i=0; i<tempdayarray.length; i++)
|
441
|
{
|
442
|
tempstr = tempdayarray[i];
|
443
|
if (tempstr != "")
|
444
|
{
|
445
|
tempstrdaypos = tempstr.search("p");
|
446
|
week = tempstr.substring(1,tempstrdaypos);
|
447
|
week = parseInt(week);
|
448
|
dashpos = tempstr.search("-");
|
449
|
|
450
|
if (dashpos != "-1")
|
451
|
{
|
452
|
var nonrepeatingfound = true;
|
453
|
daypos = tempstr.substring(tempstrdaypos+1, dashpos);
|
454
|
daypos = parseInt(daypos);
|
455
|
monthpos = tempstr.search("m");
|
456
|
tempstrdaypos = tempstr.search("d");
|
457
|
month = tempstr.substring(monthpos+1, tempstrdaypos);
|
458
|
month = parseInt(month);
|
459
|
day = tempstr.substring(tempstrdaypos+1);
|
460
|
day = parseInt(day);
|
461
|
monthstr += month + ",";
|
462
|
daystr += day + ",";
|
463
|
nrtempID += tempstr + ",";
|
464
|
}
|
465
|
else
|
466
|
{
|
467
|
var repeatingfound = true;
|
468
|
daypos = tempstr.substr(tempstrdaypos+1);
|
469
|
daypos = parseInt(daypos);
|
470
|
rtempFriendlyDay += daypos + ",";
|
471
|
rtempID += daypos + ",";
|
472
|
}
|
473
|
}
|
474
|
}
|
475
|
|
476
|
//code below spits out friendly look format for nonrepeating schedules
|
477
|
var foundEnd = false;
|
478
|
var firstDayFound = false;
|
479
|
var firstprint = false;
|
480
|
var tempFriendlyMonthArray = monthstr.split(",");
|
481
|
var tempFriendlyDayArray = daystr.split(",");
|
482
|
var currentDay, firstDay, nextDay, currentMonth, nextMonth, firstDay, firstMonth = "";
|
483
|
for (k=0; k<tempFriendlyMonthArray.length; k++){
|
484
|
tempstr = tempFriendlyMonthArray[k];
|
485
|
if (tempstr != ""){
|
486
|
if (!firstDayFound)
|
487
|
{
|
488
|
firstDay = tempFriendlyDayArray[k];
|
489
|
firstDay = parseInt(firstDay);
|
490
|
firstMonth = tempFriendlyMonthArray[k];
|
491
|
firstMonth = parseInt(firstMonth);
|
492
|
firstDayFound = true;
|
493
|
}
|
494
|
currentDay = tempFriendlyDayArray[k];
|
495
|
currentDay = parseInt(currentDay);
|
496
|
//get next day
|
497
|
nextDay = tempFriendlyDayArray[k+1];
|
498
|
nextDay = parseInt(nextDay);
|
499
|
//get next month
|
500
|
|
501
|
currentDay++;
|
502
|
if ((currentDay != nextDay) || (tempFriendlyMonthArray[k] != tempFriendlyMonthArray[k+1])){
|
503
|
if (firstprint)
|
504
|
nrtempFriendlyTime += ", ";
|
505
|
currentDay--;
|
506
|
if (currentDay != firstDay)
|
507
|
nrtempFriendlyTime += month_array[firstMonth-1] + " " + firstDay + "-" + currentDay;
|
508
|
else
|
509
|
nrtempFriendlyTime += month_array[firstMonth-1] + " " + currentDay;
|
510
|
firstDayFound = false;
|
511
|
firstprint = true;
|
512
|
}
|
513
|
}
|
514
|
}
|
515
|
|
516
|
//code below spits out friendly look format for repeating schedules
|
517
|
foundEnd = false;
|
518
|
firstDayFound = false;
|
519
|
firstprint = false;
|
520
|
tempFriendlyDayArray = rtempFriendlyDay.split(",");
|
521
|
tempFriendlyDayArray.sort();
|
522
|
currentDay, firstDay, nextDay = "";
|
523
|
for (k=0; k<tempFriendlyDayArray.length; k++){
|
524
|
tempstr = tempFriendlyDayArray[k];
|
525
|
if (tempstr != ""){
|
526
|
if (!firstDayFound)
|
527
|
{
|
528
|
firstDay = tempFriendlyDayArray[k];
|
529
|
firstDay = parseInt(firstDay);
|
530
|
firstDayFound = true;
|
531
|
}
|
532
|
currentDay = tempFriendlyDayArray[k];
|
533
|
currentDay = parseInt(currentDay);
|
534
|
//get next day
|
535
|
nextDay = tempFriendlyDayArray[k+1];
|
536
|
nextDay = parseInt(nextDay);
|
537
|
currentDay++;
|
538
|
if (currentDay != nextDay){
|
539
|
if (firstprint)
|
540
|
rtempFriendlyTime += ", ";
|
541
|
currentDay--;
|
542
|
if (currentDay != firstDay)
|
543
|
rtempFriendlyTime += day_array[firstDay-1] + " - " + day_array[currentDay-1];
|
544
|
else
|
545
|
rtempFriendlyTime += day_array[firstDay-1];
|
546
|
firstDayFound = false;
|
547
|
firstprint = true;
|
548
|
}
|
549
|
}
|
550
|
}
|
551
|
|
552
|
//sort the tempID
|
553
|
var tempsortArray = rtempID.split(",");
|
554
|
var isFirstdone = false;
|
555
|
tempsortArray.sort();
|
556
|
//clear tempID
|
557
|
rtempID = "";
|
558
|
for (t=0; t<tempsortArray.length; t++)
|
559
|
{
|
560
|
if (tempsortArray[t] != ""){
|
561
|
if (!isFirstdone){
|
562
|
rtempID += tempsortArray[t];
|
563
|
isFirstdone = true;
|
564
|
}
|
565
|
else
|
566
|
rtempID += "," + tempsortArray[t];
|
567
|
}
|
568
|
}
|
569
|
|
570
|
|
571
|
//get time specified
|
572
|
starttimehour = document.getElementById("starttimehour").value
|
573
|
starttimemin = document.getElementById("starttimemin").value;
|
574
|
stoptimehour = document.getElementById("stoptimehour").value;
|
575
|
stoptimemin = document.getElementById("stoptimemin").value;
|
576
|
|
577
|
timeRange = "||" + starttimehour + ":";
|
578
|
timeRange += starttimemin + "-";
|
579
|
timeRange += stoptimehour + ":";
|
580
|
timeRange += stoptimemin;
|
581
|
|
582
|
//get description for time range
|
583
|
var tempdescr = document.getElementById("timerangedescr").value
|
584
|
|
585
|
if (nonrepeatingfound){
|
586
|
nrtempTime += nrtempID;
|
587
|
//add time ranges
|
588
|
nrtempTime += timeRange;
|
589
|
//add description
|
590
|
nrtempTime += "||" + tempdescr;
|
591
|
insertElements(nrtempFriendlyTime, starttimehour, starttimemin, stoptimehour, stoptimemin, tempdescr, nrtempTime, nrtempID);
|
592
|
}
|
593
|
|
594
|
if (repeatingfound){
|
595
|
rtempTime += rtempID;
|
596
|
//add time ranges
|
597
|
rtempTime += timeRange;
|
598
|
//add description
|
599
|
rtempTime += "||" + tempdescr;
|
600
|
insertElements(rtempFriendlyTime, starttimehour, starttimemin, stoptimehour, stoptimemin, tempdescr, rtempTime, rtempID);
|
601
|
}
|
602
|
|
603
|
}
|
604
|
else
|
605
|
{
|
606
|
//no days were selected, alert user
|
607
|
alert ("You must select at least 1 day before adding time");
|
608
|
}
|
609
|
}
|
610
|
|
611
|
function insertElements(tempFriendlyTime, starttimehour, starttimemin, stoptimehour, stoptimemin, tempdescr, tempTime, tempID){
|
612
|
|
613
|
//add it to the schedule list
|
614
|
d = document;
|
615
|
tbody = d.getElementById("scheduletable").getElementsByTagName("tbody").item(0);
|
616
|
tr = d.createElement("tr");
|
617
|
td = d.createElement("td");
|
618
|
td.innerHTML= "<span class='vexpl'>" + tempFriendlyTime + "<\/span>";
|
619
|
tr.appendChild(td);
|
620
|
|
621
|
td = d.createElement("td");
|
622
|
td.innerHTML="<input type='text' readonly class='vexpl' name='starttime" + schCounter + "' id='starttime" + schCounter + "' style=' word-wrap:break-word; width:100%; border:0px solid;' value='" + starttimehour + ":" + starttimemin + "' />";
|
623
|
tr.appendChild(td);
|
624
|
|
625
|
td = d.createElement("td");
|
626
|
td.innerHTML="<input type='text' readonly class='vexpl' name='stoptime" + schCounter + "' id='stoptime" + schCounter + "' style=' word-wrap:break-word; width:100%; border:0px solid;' value='" + stoptimehour + ":" + stoptimemin + "' />";
|
627
|
tr.appendChild(td);
|
628
|
|
629
|
td = d.createElement("td");
|
630
|
td.innerHTML="<input type='text' readonly class='vexpl' name='timedescr" + schCounter + "' id='timedescr" + schCounter + "' style=' word-wrap:break-word; width:100%; border:0px solid;' value='" + tempdescr + "' />";
|
631
|
tr.appendChild(td);
|
632
|
|
633
|
td = d.createElement("td");
|
634
|
td.innerHTML = "<a onclick='editRow(\"" + tempTime + "\",this); return false;' href='#'><img border='0' src='/themes/" + theme + "/images/icons/icon_e.gif' alt='edit' /></\a>";
|
635
|
tr.appendChild(td);
|
636
|
|
637
|
td = d.createElement("td");
|
638
|
td.innerHTML = "<a onclick='removeRow(this); return false;' href='#'><img border='0' src='/themes/" + theme + "/images/icons/icon_x.gif' alt='remove' /></\a>";
|
639
|
tr.appendChild(td);
|
640
|
|
641
|
td = d.createElement("td");
|
642
|
td.innerHTML="<input type='hidden' id='schedule" + schCounter + "' name='schedule" + schCounter + "' value='" + tempID + "' />";
|
643
|
tr.appendChild(td);
|
644
|
tbody.appendChild(tr);
|
645
|
|
646
|
schCounter++;
|
647
|
|
648
|
//reset calendar and time and descr
|
649
|
clearCalendar();
|
650
|
clearTime();
|
651
|
clearDescr();
|
652
|
}
|
653
|
|
654
|
|
655
|
function clearCalendar(){
|
656
|
var tempstr, daycell = "";
|
657
|
//clear days selected
|
658
|
daysSelected = "";
|
659
|
//loop through all 52 weeks
|
660
|
for (j=1; j<=53; j++)
|
661
|
{
|
662
|
//loop through all 7 days
|
663
|
for (k=1; k<8; k++){
|
664
|
tempstr = 'w' + j + 'p' + k;
|
665
|
daycell = eval('document.getElementById(tempstr)');
|
666
|
if (daycell != null){
|
667
|
daycell.style.backgroundColor = "#FFFFFF"; // white
|
668
|
}
|
669
|
}
|
670
|
}
|
671
|
}
|
672
|
|
673
|
function clearTime(){
|
674
|
document.getElementById("starttimehour").value = "0";
|
675
|
document.getElementById("starttimemin").value = "00";
|
676
|
document.getElementById("stoptimehour").value = "23";
|
677
|
document.getElementById("stoptimemin").value = "59";
|
678
|
}
|
679
|
|
680
|
function clearDescr(){
|
681
|
document.getElementById("timerangedescr").value = "";
|
682
|
}
|
683
|
|
684
|
function editRow(incTime, el) {
|
685
|
var check = checkForRanges();
|
686
|
|
687
|
if (check){
|
688
|
|
689
|
//reset calendar and time
|
690
|
clearCalendar();
|
691
|
clearTime();
|
692
|
|
693
|
var starttimehour, descr, days, tempstr, starttimemin, hours, stoptimehour, stoptimemin = "";
|
694
|
|
695
|
tempArray = incTime.split ("||");
|
696
|
|
697
|
days = tempArray[0];
|
698
|
hours = tempArray[1];
|
699
|
descr = tempArray[2];
|
700
|
|
701
|
var tempdayArray = days.split(",");
|
702
|
var temphourArray = hours.split("-");
|
703
|
tempstr = temphourArray[0];
|
704
|
var temphourArray2 = tempstr.split(":");
|
705
|
|
706
|
document.getElementById("starttimehour").value = temphourArray2[0];
|
707
|
document.getElementById("starttimemin").value = temphourArray2[1];
|
708
|
|
709
|
tempstr = temphourArray[1];
|
710
|
temphourArray2 = tempstr.split(":");
|
711
|
|
712
|
document.getElementById("stoptimehour").value = temphourArray2[0];
|
713
|
document.getElementById("stoptimemin").value = temphourArray2[1];
|
714
|
|
715
|
document.getElementById("timerangedescr").value = descr;
|
716
|
|
717
|
//toggle the appropriate days
|
718
|
for (i=0; i<tempdayArray.length; i++)
|
719
|
{
|
720
|
if (tempdayArray[i]){
|
721
|
var tempweekstr = tempdayArray[i];
|
722
|
dashpos = tempweekstr.search("-");
|
723
|
|
724
|
if (dashpos == "-1")
|
725
|
{
|
726
|
tempstr = "w2p" + tempdayArray[i];
|
727
|
}
|
728
|
else
|
729
|
{
|
730
|
tempstr = tempdayArray[i];
|
731
|
}
|
732
|
daytoggle(tempstr);
|
733
|
}
|
734
|
}
|
735
|
removeRownoprompt(el);
|
736
|
}
|
737
|
}
|
738
|
|
739
|
function removeRownoprompt(el) {
|
740
|
var cel;
|
741
|
while (el && el.nodeName.toLowerCase() != "tr")
|
742
|
el = el.parentNode;
|
743
|
|
744
|
if (el && el.parentNode) {
|
745
|
cel = el.getElementsByTagName("td").item(0);
|
746
|
el.parentNode.removeChild(el);
|
747
|
}
|
748
|
}
|
749
|
|
750
|
|
751
|
function removeRow(el) {
|
752
|
var check = confirm ("Do you really want to delete this time range?");
|
753
|
if (check){
|
754
|
var cel;
|
755
|
while (el && el.nodeName.toLowerCase() != "tr")
|
756
|
el = el.parentNode;
|
757
|
|
758
|
if (el && el.parentNode) {
|
759
|
cel = el.getElementsByTagName("td").item(0);
|
760
|
el.parentNode.removeChild(el);
|
761
|
}
|
762
|
}
|
763
|
}
|
764
|
//]]>
|
765
|
</script>
|
766
|
EOD;
|
767
|
?>
|
768
|
|
769
|
<body link="#0000CC" vlink="#0000CC" alink="#0000CC" onload="<?= $jsevents["body"]["onload"] ?>">
|
770
|
|
771
|
|
772
|
<?php include("fbegin.inc"); echo $jscriptstr; ?>
|
773
|
<?php if ($input_errors) print_input_errors($input_errors); ?>
|
774
|
<div id="inputerrors"></div>
|
775
|
|
776
|
<form action="firewall_schedule_edit.php" method="post" name="iform" id="iform">
|
777
|
<table width="100%" border="0" cellpadding="0" cellspacing="0" summary="firewall schedule">
|
778
|
<tr>
|
779
|
<td colspan="2" valign="top" class="listtopic"><?=gettext("Schedule information");?></td>
|
780
|
</tr>
|
781
|
<tr>
|
782
|
<td>
|
783
|
<table width="100%" border="0" cellpadding="6" cellspacing="0" summary="main area">
|
784
|
<tr>
|
785
|
<td width="15%" valign="top" class="vncellreq"><?=gettext("Schedule Name");?></td>
|
786
|
<td width="85%" class="vtable">
|
787
|
<?php if(is_schedule_inuse($pconfig['name']) == true): ?>
|
788
|
<input name="name" type="hidden" id="name" size="40" value="<?=htmlspecialchars($pconfig['name']);?>" />
|
789
|
<?php echo $pconfig['name']; ?>
|
790
|
<p>
|
791
|
<span class="vexpl"><?=gettext("NOTE: This schedule is in use so the name may not be modified!");?></span>
|
792
|
</p>
|
793
|
<?php else: ?>
|
794
|
<input name="name" type="text" id="name" size="40" maxlength="40" class="formfld unknown" value="<?=htmlspecialchars($pconfig['name']);?>" /><br />
|
795
|
<span class="vexpl">
|
796
|
<?=gettext("The name of the alias may only consist of the characters a-z, A-Z and 0-9");?>
|
797
|
</span>
|
798
|
<?php endif; ?>
|
799
|
</td>
|
800
|
</tr>
|
801
|
<tr>
|
802
|
<td width="15%" valign="top" class="vncell"><?=gettext("Description");?></td>
|
803
|
<td width="85%" class="vtable"><input name="descr" type="text" id="descr" size="40" maxlength="40" class="formfld unknown" value="<?=htmlspecialchars($pconfig['descr']);?>" /><br />
|
804
|
<span class="vexpl">
|
805
|
<?=gettext("You may enter a description here for your reference (not parsed).");?>
|
806
|
</span>
|
807
|
|
808
|
</td>
|
809
|
</tr>
|
810
|
<!-- tr>
|
811
|
</tr -->
|
812
|
<tr>
|
813
|
<td width="15%" valign="top" class="vncellreq"><?=gettext("Month");?></td>
|
814
|
<td width="85%" class="vtable">
|
815
|
<select name="monthsel" class="formselect" id="monthsel" onchange="update_month();">
|
816
|
<?php
|
817
|
$monthcounter = date("n");
|
818
|
$monthlimit = $monthcounter + 12;
|
819
|
$yearcounter = date("Y");
|
820
|
for ($k=0; $k<12; $k++){?>
|
821
|
<option value="<?php echo $monthcounter;?>"><?php echo date("F_y", mktime(0, 0, 0, date($monthcounter), 1, date($yearcounter)));?></option>
|
822
|
<?php
|
823
|
if ($monthcounter == 12)
|
824
|
{
|
825
|
$monthcounter = 1;
|
826
|
$yearcounter++;
|
827
|
}
|
828
|
else
|
829
|
{
|
830
|
$monthcounter++;
|
831
|
}
|
832
|
} ?>
|
833
|
</select><br /><br />
|
834
|
<?php
|
835
|
$firstmonth = TRUE;
|
836
|
$monthcounter = date("n");
|
837
|
$yearcounter = date("Y");
|
838
|
for ($k=0; $k<12; $k++){
|
839
|
$firstdayofmonth = date("w", mktime(0, 0, 0, date($monthcounter), 1, date($yearcounter)));
|
840
|
if ($firstdayofmonth == 0)
|
841
|
$firstdayofmonth = 7;
|
842
|
|
843
|
$daycounter = 1;
|
844
|
//number of day in month
|
845
|
$numberofdays = date("t", mktime(0, 0, 0, date($monthcounter), 1, date($yearcounter)));
|
846
|
$firstdayprinted = FALSE;
|
847
|
$lasttr = FALSE;
|
848
|
$positioncounter = 1;//7 for Sun, 1 for Mon, 2 for Tues, etc
|
849
|
?>
|
850
|
<div id="<?php echo date("F_y",mktime(0, 0, 0, date($monthcounter), 1, date($yearcounter)));?>" style=" position:relative; display:<?php if($firstmonth)echo "block";else echo "none";?>">
|
851
|
<table border="1" cellspacing="1" cellpadding="1" id="calTable<?=$monthcounter . $yearcounter;?>" class="tabcont" summary="month">
|
852
|
<tr><td colspan="7" align="center" class="listbg"><b><?php echo date("F_Y", mktime(0, 0, 0, date($monthcounter), 1, date($yearcounter)));?></b></td>
|
853
|
</tr>
|
854
|
<tr>
|
855
|
<td align="center" class="listhdrr" style="cursor: pointer;" onclick="daytoggle('w1p1');"><u><b><?=gettext("Mon");?></b></u></td>
|
856
|
<td align="center" class="listhdrr" style="cursor: pointer;" onclick="daytoggle('w1p2');"><u><b><?=gettext("Tue");?></b></u></td>
|
857
|
<td align="center" class="listhdrr" style="cursor: pointer;" onclick="daytoggle('w1p3');"><u><b><?=gettext("Wed");?></b></u></td>
|
858
|
<td align="center" class="listhdrr" style="cursor: pointer;" onclick="daytoggle('w1p4');"><u><b><?=gettext("Thu");?></b></u></td>
|
859
|
<td align="center" class="listhdrr" style="cursor: pointer;" onclick="daytoggle('w1p5');"><u><b><?=gettext("Fri");?></b></u></td>
|
860
|
<td align="center" class="listhdrr" style="cursor: pointer;" onclick="daytoggle('w1p6');"><u><b><?=gettext("Sat");?></b></u></td>
|
861
|
<td align="center" class="listhdrr" style="cursor: pointer;" onclick="daytoggle('w1p7');"><u><b><?=gettext("Sun");?></b></u></td>
|
862
|
</tr>
|
863
|
<?php
|
864
|
$firstmonth = FALSE;
|
865
|
while ($daycounter<=$numberofdays){
|
866
|
$weekcounter = date("W", mktime(0, 0, 0, date($monthcounter), date($daycounter), date($yearcounter)));
|
867
|
$weekcounter = ltrim($weekcounter, "0");
|
868
|
if ($positioncounter == 1)
|
869
|
{
|
870
|
echo "<tr>";
|
871
|
}
|
872
|
if ($firstdayofmonth == $positioncounter){?>
|
873
|
<td align="center" style="cursor: pointer;" class="listr" id="w<?=$weekcounter;?>p<?=$positioncounter;?>" onclick="daytoggle('w<?=$weekcounter;?>p<?=$positioncounter;?>-m<?=$monthcounter;?>d<?=$daycounter;?>');">
|
874
|
<?php echo $daycounter;
|
875
|
$daycounter++;
|
876
|
$firstdayprinted = TRUE;
|
877
|
echo "</td>";
|
878
|
}
|
879
|
elseif ($firstdayprinted == TRUE && $daycounter <= $numberofdays){?>
|
880
|
<td align="center" style="cursor: pointer;" class="listr" id="w<?=$weekcounter;?>p<?=$positioncounter;?>" onclick="daytoggle('w<?=$weekcounter;?>p<?=$positioncounter;?>-m<?=$monthcounter;?>d<?=$daycounter;?>');">
|
881
|
<?php echo $daycounter;
|
882
|
$daycounter++;
|
883
|
echo "</td>";
|
884
|
}
|
885
|
else
|
886
|
{
|
887
|
echo "<td align=\"center\" class=\"listr\"></td>";
|
888
|
}
|
889
|
|
890
|
if ($positioncounter == 7 || $daycounter > $numberofdays){
|
891
|
$positioncounter = 1;
|
892
|
echo "</tr>";
|
893
|
}
|
894
|
else{
|
895
|
$positioncounter++;
|
896
|
}
|
897
|
|
898
|
}//end while loop?>
|
899
|
</table>
|
900
|
</div>
|
901
|
<?php
|
902
|
|
903
|
if ($monthcounter == 12)
|
904
|
{
|
905
|
$monthcounter = 1;
|
906
|
$yearcounter++;
|
907
|
}
|
908
|
else
|
909
|
{
|
910
|
$monthcounter++;
|
911
|
}
|
912
|
} //end for loop
|
913
|
?>
|
914
|
<br />
|
915
|
<?=gettext("Click individual date to select that date only. Click the appropriate weekday Header to select all occurences of that weekday.");?>
|
916
|
</td>
|
917
|
</tr>
|
918
|
<tr>
|
919
|
<td width="15%" valign="top" class="vncellreq"><?=gettext("Time");?></td>
|
920
|
<td width="85%" class="vtable">
|
921
|
<table cellspacing="2" class="tabcont" summary="time">
|
922
|
<tr>
|
923
|
<td class="listhdrr" align="center"><?=gettext("Start Time");?></td><td></td><td class="listhdrr" align="center"><?=gettext("Stop Time");?></td>
|
924
|
</tr>
|
925
|
<tr>
|
926
|
<td>
|
927
|
<select name="starttimehour" class="formselect" id="starttimehour">
|
928
|
<?php
|
929
|
for ($i=0; $i<24; $i++)
|
930
|
{
|
931
|
echo "<option value=\"$i\">";
|
932
|
echo $i;
|
933
|
echo "</option>";
|
934
|
}
|
935
|
?>
|
936
|
</select> <?=gettext("Hr"); ?>
|
937
|
<select name="starttimemin" class="formselect" id="starttimemin">
|
938
|
<option value="00">00</option>
|
939
|
<option value="15">15</option>
|
940
|
<option value="30">30</option>
|
941
|
<option value="45">45</option>
|
942
|
<option value="59">59</option>
|
943
|
</select> <?=gettext("Min"); ?>
|
944
|
</td>
|
945
|
<td></td>
|
946
|
<td>
|
947
|
<select name="stoptimehour" class="formselect" id="stoptimehour">
|
948
|
<?php
|
949
|
for ($i=0; $i<24; $i++)
|
950
|
{
|
951
|
if ($i==23)
|
952
|
$selected = "selected=\"selected\"";
|
953
|
else
|
954
|
$selected = "";
|
955
|
|
956
|
echo "<option value=\"$i\" $selected>";
|
957
|
echo $i;
|
958
|
echo "</option>";
|
959
|
}
|
960
|
?>
|
961
|
</select> <?=gettext("Hr");?>
|
962
|
<select name="stoptimemin" class="formselect" id="stoptimemin">
|
963
|
<option value="00">00</option>
|
964
|
<option value="15">15</option>
|
965
|
<option value="30">30</option>
|
966
|
<option value="45">45</option>
|
967
|
<option value="59" selected="selected">59</option>
|
968
|
</select> <?=gettext("Min");?>
|
969
|
</td>
|
970
|
</tr>
|
971
|
</table><br />
|
972
|
<?=gettext("Select the time range for the day(s) selected on the Month(s) above. A full day is 0:00-23:59.")?>
|
973
|
</td>
|
974
|
</tr>
|
975
|
<tr>
|
976
|
<td width="15%" valign="top" class="vncell"><?=gettext("Time Range Description")?></td>
|
977
|
<td width="85%" class="vtable"><input name="timerangedescr" type="text" class="formfld unknown" id="timerangedescr" size="40" maxlength="40" /><br />
|
978
|
<span class="vexpl">
|
979
|
<?=gettext("You may enter a description here for your reference (not parsed).")?>
|
980
|
</span>
|
981
|
</td>
|
982
|
</tr>
|
983
|
<tr>
|
984
|
<td width="22%" valign="top"> </td>
|
985
|
<td width="78%">
|
986
|
<input type="button" value="<?=gettext("Add Time");?>" class="formbtn" onclick="javascript:processEntries();" />
|
987
|
<input type="button" value="<?=gettext("Clear Selection");?>" class="formbtn" onclick="javascript:clearCalendar(); clearTime(); clearDescr();" />
|
988
|
</td>
|
989
|
</tr>
|
990
|
<tr>
|
991
|
<td width="15%" valign="top" class="vtable"></td>
|
992
|
<td width="85%" class="vtable">
|
993
|
</td>
|
994
|
</tr>
|
995
|
<tr>
|
996
|
<td colspan="2" valign="top" class="listtopic"><?=gettext("Schedule repeat");?></td>
|
997
|
</tr>
|
998
|
<tr>
|
999
|
<td width="15%" valign="top" class="vncellreq"><?=gettext("Configured Ranges");?></td>
|
1000
|
<td width="85%">
|
1001
|
<table id="scheduletable" summary="range">
|
1002
|
<tbody>
|
1003
|
<tr>
|
1004
|
<td align="center" class="listbg" width="35%"><?=gettext("Day(s)");?></td>
|
1005
|
<td align="center" class="listbg" width="12%"><?=gettext("Start Time");?></td>
|
1006
|
<td align="center" class="listbg" width="11%"><?=gettext("Stop Time");?></td>
|
1007
|
<td align="center" class="listbg" width="42%"><?=gettext("Description");?></td>
|
1008
|
</tr>
|
1009
|
<?php
|
1010
|
if ($getSchedule){
|
1011
|
$counter = 0;
|
1012
|
|
1013
|
foreach($pconfig['timerange'] as $timerange) {
|
1014
|
$tempFriendlyTime = "";
|
1015
|
$tempID = "";
|
1016
|
if ($timerange){
|
1017
|
$dayFriendly = "";
|
1018
|
$tempFriendlyTime = "";
|
1019
|
$timedescr = $timerange['rangedescr'];
|
1020
|
|
1021
|
//get hours
|
1022
|
$temptimerange = $timerange['hour'];
|
1023
|
$temptimeseparator = strrpos($temptimerange, "-");
|
1024
|
|
1025
|
$starttime = substr ($temptimerange, 0, $temptimeseparator);
|
1026
|
$stoptime = substr ($temptimerange, $temptimeseparator+1);
|
1027
|
$currentDay = "";
|
1028
|
$firstDay = "";
|
1029
|
$nextDay = "";
|
1030
|
$foundEnd = false;
|
1031
|
$firstDayFound = false;
|
1032
|
$firstPrint = false;
|
1033
|
$firstprint2 = false;
|
1034
|
|
1035
|
if ($timerange['month']){
|
1036
|
$tempmontharray = explode(",", $timerange['month']);
|
1037
|
$tempdayarray = explode(",",$timerange['day']);
|
1038
|
$arraycounter = 0;
|
1039
|
foreach ($tempmontharray as $monthtmp){
|
1040
|
$month = $tempmontharray[$arraycounter];
|
1041
|
$day = $tempdayarray[$arraycounter];
|
1042
|
$daypos = date("w", mktime(0, 0, 0, date($month), date($day), date("Y")));
|
1043
|
//if sunday, set position to 7 to get correct week number. This is due to php limitations on ISO-8601. When we move to php5.1 we can change this.
|
1044
|
if ($daypos == 0){
|
1045
|
$daypos = 7;
|
1046
|
}
|
1047
|
$weeknumber = date("W", mktime(0, 0, 0, date($month), date($day), date("Y")));
|
1048
|
$weeknumber = ltrim($weeknumber, "0");
|
1049
|
|
1050
|
if ($firstPrint)
|
1051
|
{
|
1052
|
$tempID .= ",";
|
1053
|
}
|
1054
|
$tempID .= "w" . $weeknumber . "p" . $daypos . "-m" . $month . "d" . $day;
|
1055
|
$firstPrint = true;
|
1056
|
|
1057
|
if (!$firstDayFound)
|
1058
|
{
|
1059
|
$firstDay = $day;
|
1060
|
$firstmonth = $month;
|
1061
|
$firstDayFound = true;
|
1062
|
}
|
1063
|
|
1064
|
$currentDay = $day;
|
1065
|
$nextDay = $tempdayarray[$arraycounter+1];
|
1066
|
$currentDay++;
|
1067
|
if (($currentDay != $nextDay) || ($tempmontharray[$arraycounter] != $tempmontharray[$arraycounter+1])){
|
1068
|
if ($firstprint2)
|
1069
|
$tempFriendlyTime .= ", ";
|
1070
|
$currentDay--;
|
1071
|
if ($currentDay != $firstDay)
|
1072
|
$tempFriendlyTime .= $monthArray[$firstmonth-1] . " " . $firstDay . " - " . $currentDay ;
|
1073
|
else
|
1074
|
$tempFriendlyTime .= $monthArray[$month-1] . " " . $day;
|
1075
|
$firstDayFound = false;
|
1076
|
$firstprint2 = true;
|
1077
|
}
|
1078
|
$arraycounter++;
|
1079
|
}
|
1080
|
|
1081
|
}
|
1082
|
else
|
1083
|
{
|
1084
|
$dayFriendly = $timerange['position'];
|
1085
|
$tempID = $dayFriendly;
|
1086
|
}
|
1087
|
|
1088
|
$tempTime = $tempID . "||" . $starttime . "-" . $stoptime . "||" . $timedescr;
|
1089
|
|
1090
|
//following code makes the days friendly appearing, IE instead of Mon, Tues, Wed it will show Mon - Wed
|
1091
|
$foundEnd = false;
|
1092
|
$firstDayFound = false;
|
1093
|
$firstprint = false;
|
1094
|
$tempFriendlyDayArray = explode(",", $dayFriendly);
|
1095
|
$currentDay = "";
|
1096
|
$firstDay = "";
|
1097
|
$nextDay = "";
|
1098
|
$i = 0;
|
1099
|
if (!$timerange['month']){
|
1100
|
foreach ($tempFriendlyDayArray as $day){
|
1101
|
if ($day != ""){
|
1102
|
if (!$firstDayFound)
|
1103
|
{
|
1104
|
$firstDay = $tempFriendlyDayArray[$i];
|
1105
|
$firstDayFound = true;
|
1106
|
}
|
1107
|
$currentDay =$tempFriendlyDayArray[$i];
|
1108
|
//get next day
|
1109
|
$nextDay = $tempFriendlyDayArray[$i+1];
|
1110
|
$currentDay++;
|
1111
|
if ($currentDay != $nextDay){
|
1112
|
if ($firstprint)
|
1113
|
$tempFriendlyTime .= ", ";
|
1114
|
$currentDay--;
|
1115
|
if ($currentDay != $firstDay)
|
1116
|
$tempFriendlyTime .= $dayArray[$firstDay-1] . " - " . $dayArray[$currentDay-1];
|
1117
|
else
|
1118
|
$tempFriendlyTime .= $dayArray[$firstDay-1];
|
1119
|
$firstDayFound = false;
|
1120
|
$firstprint = true;
|
1121
|
}
|
1122
|
$i++;
|
1123
|
}
|
1124
|
}
|
1125
|
}
|
1126
|
|
1127
|
|
1128
|
?>
|
1129
|
<tr>
|
1130
|
<td>
|
1131
|
<span class="vexpl"><?php echo $tempFriendlyTime; ?></span>
|
1132
|
</td>
|
1133
|
<td>
|
1134
|
<input type='text' readonly='readonly' class='vexpl' name='starttime<?php echo $counter; ?>' id='starttime<?php echo $counter; ?>' style=' word-wrap:break-word; width:100%; border:0px solid;' value='<?php echo $starttime; ?>' />
|
1135
|
</td>
|
1136
|
<td>
|
1137
|
<input type='text' readonly='readonly' class='vexpl' name='stoptime<?php echo $counter; ?>' id='stoptime<?php echo $counter; ?>' style=' word-wrap:break-word; width:100%; border:0px solid;' value='<?php echo $stoptime; ?>' />
|
1138
|
</td>
|
1139
|
<td>
|
1140
|
<input type='text' readonly='readonly' class='vexpl' name='timedescr<?php echo $counter; ?>' id='timedescr<?php echo $counter; ?>' style=' word-wrap:break-word; width:100%; border:0px solid;' value='<?php echo $timedescr; ?>' />
|
1141
|
</td>
|
1142
|
<td>
|
1143
|
<a onclick='editRow("<?php echo $tempTime; ?>",this); return false;' href='#'><img border='0' src='/themes/<?php echo $g['theme']; ?>/images/icons/icon_e.gif' alt='edit' /></a>
|
1144
|
</td>
|
1145
|
<td>
|
1146
|
<a onclick='removeRow(this); return false;' href='#'><img border='0' src='/themes/<?php echo $g['theme']; ?>/images/icons/icon_x.gif' alt='remove' /></a>
|
1147
|
</td>
|
1148
|
<td>
|
1149
|
<input type='hidden' id='schedule<?php echo $counter; ?>' name='schedule<?php echo $counter; ?>' value='<?php echo $tempID; ?>' />
|
1150
|
</td>
|
1151
|
</tr>
|
1152
|
<?php
|
1153
|
$counter++;
|
1154
|
}//end if
|
1155
|
} // end foreach
|
1156
|
}//end if
|
1157
|
?>
|
1158
|
</tbody>
|
1159
|
</table>
|
1160
|
</td>
|
1161
|
</tr>
|
1162
|
<tr>
|
1163
|
<td width="15%" valign="top"> </td>
|
1164
|
<td width="85%">
|
1165
|
<input id="submit" name="submit" type="submit" onclick="return checkForRanges();" class="formbtn" value="<?=gettext("Save"); ?>" />
|
1166
|
<input id="cancelbutton" name="cancelbutton" type="button" class="formbtn" value="<?=gettext("Cancel"); ?>" onclick="history.back()" />
|
1167
|
<?php if (isset($id) && $a_schedules[$id]): ?>
|
1168
|
<input name="id" type="hidden" value="<?=htmlspecialchars($id);?>" />
|
1169
|
<?php endif; ?>
|
1170
|
</td>
|
1171
|
</tr>
|
1172
|
</table>
|
1173
|
|
1174
|
</td></tr></table></form>
|
1175
|
<?php include("fend.inc"); ?>
|
1176
|
</body>
|
1177
|
</html>
|