'; $mostr .= '' . "\r\n"; $firstmonth = FALSE; while ($daycounter<=$numberofdays) { $weekcounter = date("W", mktime(0, 0, 0, date($monthcounter), date($daycounter), date($yearcounter))); $weekcounter = ltrim($weekcounter, "0"); if ($positioncounter == 1) { $mostr .= ""; } if ($firstdayofmonth == $positioncounter) { $mostr .= '"; } elseif ($firstdayprinted == TRUE && $daycounter <= $numberofdays) { $mostr .= '"; } else { $mostr .= ''; } if ($daycounter > $numberofdays) { while ($positioncounter < 7) { $mostr .= ''; $positioncounter++; } } if ($positioncounter == 7) { $positioncounter = 1; $mostr .= ""; } else { $positioncounter++; } } $mostr .= '
' . date("F_Y", mktime(0, 0, 0, date($monthcounter), 1, date($yearcounter))) . '
' . gettext("Mon") . ' ' . gettext("Tue") . ' ' . gettext("Wed") . ' ' . gettext("Thu") . ' ' . gettext("Fri") . ' ' . gettext("Sat") . ' ' . gettext("Sun") . '
' . $daycounter . "\r\n"; $daycounter++; $firstdayprinted = TRUE; $mostr .= "' . $daycounter . "\r\n"; $daycounter++; $mostr .= "

'; $mostr .= gettext('Click individual date to select that date only. Click the appropriate weekday Header to select all occurrences of that weekday. '); $mostr .= '

'; if ($monthcounter == 12) { $monthcounter = 1; $yearcounter++; } else { $monthcounter++; } $tblstr .= $mostr; } //end for loop return($tblstr); } function build_month_list() { $list = array(); $monthcounter = date("n"); $monthlimit = $monthcounter + 12; $yearcounter = date("Y"); for ($k = 0; $k < 12; $k++) { $list[$monthcounter] = date("F_y", mktime(0, 0, 0, date($monthcounter), 1, date($yearcounter))); if ($monthcounter == 12) { $monthcounter = 1; $yearcounter++; } else { $monthcounter++; } } return($list); } if ($input_errors) { print_input_errors($input_errors); } $form = new Form(); $section = new Form_Section('Schedule Information'); $input = new Form_Input( 'name', 'Schedule Name', 'text', $pconfig['name'] ); $input->setHelp((is_schedule_inuse($pconfig['name']) != true) ? 'The name of the schedule may only consist of the characters "a-z, A-Z, 0-9 and _".': 'This schedule is in use so the name may not be modified!'); if (is_schedule_inuse($pconfig['name']) == true) { $input->setReadonly(); } $section->addInput($input); $section->addInput(new Form_Input( 'descr', 'Description', 'text', $pconfig['descr'] ))->setHelp('A description may be entered here for administrative reference (not parsed). '); $section->addInput(new Form_Select( 'monthsel', 'Month', null, build_month_list() )); $section->addInput(new Form_StaticText( 'Date', build_date_table() )); $group = new Form_Group('Time'); $group->add(new Form_Select( 'starttimehour', null, null, array_combine(range(0, 23, 1), range(0, 23, 1)) ))->setHelp('Start Hrs'); $group->add(new Form_Select( 'starttimemin', null, null, array('00' => '00', '15' => '15', '30' => '30', '45' => '45', '59' => '59') ))->setHelp('Start Mins'); $group->add(new Form_Select( 'stoptimehour', null, '23', array_combine(range(0, 23, 1), range(0, 23, 1)) ))->setHelp('Stop Hrs'); $group->add(new Form_Select( 'stoptimemin', null, '59', array('00' => '00', '15' => '15', '30' => '30', '45' => '45', '59' => '59') ))->setHelp('Stop Mins'); $group->setHelp('Select the time range for the day(s) selected on the Month(s) above. A full day is 0:00-23:59.'); $section->add($group); $section->addInput(new Form_Input( 'timerangedescr', 'Time range description', 'text', $pconfig['timerangedescr'] ))->setHelp('A description may be entered here for administrative reference (not parsed). '); $group = new Form_Group(null); $group->add(new Form_Button( 'btnaddtime', 'Add Time', null, 'fa-plus' ))->setAttribute('type','button')->addClass('btn-success btn-sm'); $group->add(new Form_Button( 'btnclrsel', 'Clear selection', null, 'fa-undo' ))->setAttribute('type','button')->addClass('btn-info btn-sm'); $section->add($group); if (isset($id) && $a_schedules[$id]) { $section->addInput(new Form_Input( 'id', null, 'hidden', $id )); } $form->add($section); $section = new Form_Section('Configured Ranges'); $counter = 0; if ($getSchedule) { $maxrows = count($pconfig['timerange']) -1; foreach ($pconfig['timerange'] as $timerange) { $tempFriendlyTime = ""; $tempID = ""; if ($timerange) { $dayFriendly = ""; $tempFriendlyTime = ""; $timedescr = $timerange['rangedescr']; //get hours $temptimerange = $timerange['hour']; $temptimeseparator = strrpos($temptimerange, "-"); $starttime = substr ($temptimerange, 0, $temptimeseparator); $stoptime = substr ($temptimerange, $temptimeseparator+1); $currentDay = ""; $firstDay = ""; $nextDay = ""; $foundEnd = false; $firstDayFound = false; $firstPrint = false; $firstprint2 = false; if ($timerange['month']) { $tempmontharray = explode(",", $timerange['month']); $tempdayarray = explode(",", $timerange['day']); $arraycounter = 0; foreach ($tempmontharray as $monthtmp) { $month = $tempmontharray[$arraycounter]; $day = $tempdayarray[$arraycounter]; $daypos = date("w", mktime(0, 0, 0, date($month), date($day), date("Y"))); //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. if ($daypos == 0) { $daypos = 7; } $weeknumber = date("W", mktime(0, 0, 0, date($month), date($day), date("Y"))); $weeknumber = ltrim($weeknumber, "0"); if ($firstPrint) { $tempID .= ","; } $tempID .= "w" . $weeknumber . "p" . $daypos . "-m" . $month . "d" . $day; $firstPrint = true; if (!$firstDayFound) { $firstDay = $day; $firstmonth = $month; $firstDayFound = true; } $currentDay = $day; $nextDay = $tempdayarray[$arraycounter+1]; $currentDay++; if (($currentDay != $nextDay) || ($tempmontharray[$arraycounter] != $tempmontharray[$arraycounter+1])) { if ($firstprint2) { $tempFriendlyTime .= ", "; } $currentDay--; if ($currentDay != $firstDay) { $tempFriendlyTime .= $monthArray[$firstmonth-1] . " " . $firstDay . " - " . $currentDay ; } else { $tempFriendlyTime .= $monthArray[$month-1] . " " . $day; } $firstDayFound = false; $firstprint2 = true; } $arraycounter++; } } else { $dayFriendly = $timerange['position']; $tempID = $dayFriendly; } $tempTime = $tempID . "||" . $starttime . "-" . $stoptime . "||" . $timedescr; //following code makes the days friendly appearing, IE instead of Mon, Tues, Wed it will show Mon - Wed $foundEnd = false; $firstDayFound = false; $firstprint = false; $tempFriendlyDayArray = explode(",", $dayFriendly); $currentDay = ""; $firstDay = ""; $nextDay = ""; $i = 0; if (!$timerange['month']) { foreach ($tempFriendlyDayArray as $day) { if ($day != "") { if (!$firstDayFound) { $firstDay = $tempFriendlyDayArray[$i]; $firstDayFound = true; } $currentDay =$tempFriendlyDayArray[$i]; //get next day $nextDay = $tempFriendlyDayArray[$i+1]; $currentDay++; if ($currentDay != $nextDay) { if ($firstprint) { $tempFriendlyTime .= ", "; } $currentDay--; if ($currentDay != $firstDay) { $tempFriendlyTime .= $dayArray[$firstDay-1] . " - " . $dayArray[$currentDay-1]; } else { $tempFriendlyTime .= $dayArray[$firstDay-1]; } $firstDayFound = false; $firstprint = true; } $i++; } } } $group = new Form_Group(''); $group->add(new Form_Input( 'tempFriendlyTime' . $counter, null, 'text', $tempFriendlyTime ))->setWidth(2)->setHelp($counter == $maxrows ? 'Day(s)':''); $group->add(new Form_Input( 'starttime' . $counter, null, 'text', $starttime ))->setWidth(2)->setHelp($counter == $maxrows ? 'Start time':''); $group->add(new Form_Input( 'stoptime' . $counter, null, 'text', $stoptime ))->setWidth(2)->setHelp($counter == $maxrows ? 'Stop time':''); $group->add(new Form_Input( 'timedescr' . $counter, null, 'text', $timedescr ))->setWidth(2)->setHelp($counter == $maxrows ? 'Description':''); $group->add(new Form_Button( 'Delete' . $counter, 'Delete', null, 'fa-trash' ))->setAttribute('type','button')->addClass('btn-xs btn-warning'); $group->add(new Form_Input( 'schedule' . $counter, null, 'hidden', $tempID )); $group->addClass('schedulegrp' . $counter); $counter++; $section->add($group); } } } // This is just a marker that the javascript can use to insertBefore() when adding new rows $section->addInput(new Form_Input( 'marker', null, 'hidden' ))->addClass('noranges'); $form->add($section); print($form); ?>