Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?
- include "config.php";
- include "restrito.php";
- echo $menu;
- //
- $s="-";
- echo "<form action='calendar.php' method='POST'>
- <br>
- <b>Agenda</b>
- <hr>";
- //
- // the XML file which holds your event data
- $xmlFile = "calendar.xml";
- //
- //
- $year=$_GET['year'];
- $monthNo=$_GET['monthNo'];
- if (!isset($year)) {
- $year = date(Y);
- }
- // get the month number (1-12) if one not provided
- if (!isset($monthNo)) {
- $monthNo = date(n);
- }
- $monthName = date(F, mktime(0, 0, 0, $monthNo, 1, $year));
- if($monthName=='July')
- {
- $monthName='Julho';
- }
- else if($monthName=='June')
- {
- $monthName='Junho';
- }
- else if($monthName=='January')
- {
- $monthName='Janeiro';
- }
- else if($monthName=='February')
- {
- $monthName='Fevereiro';
- }
- else if($monthName=='March')
- {
- $monthName='Março';
- }
- else if($monthName=='April')
- {
- $monthName='Abril';
- }
- else if($monthName=='May')
- {
- $monthName='Maio';
- }
- else if($monthName=='August')
- {
- $monthName='Agosto';
- }
- else if($monthName=='September')
- {
- $monthName='Setembro';
- }
- else if($monthName=='October')
- {
- $monthName='Outubro';
- }
- else if($monthName=='November')
- {
- $monthName='Novembro';
- }
- else if($monthName=='December')
- {
- $monthName='Dezembro';
- }
- // get the number of days in this month
- $daysInMonth = date(t);
- //
- // GET XML DATA
- //
- // get XML data
- $data = implode("", file($xmlFile));
- // create XML parser
- $parser = xml_parser_create();
- // set parser options
- xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
- xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
- // parse XML data into arrays
- xml_parse_into_struct($parser, $data, $values, $tags);
- // free parser
- xml_parser_free($parser);
- // set variables for cycling through parsed XML data
- $i = 0; // set the array counter variable
- $lookForMonth = 0; // set default to false
- $getDays = 0; // set default to false
- // cycle through parsed XML data
- while ($i < count($values)) {
- // if close tag of current month, stop cycle
- if ($values[$i][tag] == $monthName && $values[$i][type] == "close") {
- break;
- }
- // if close tag of current year, stop cycle
- if ($values[$i][tag] == "Y$year" && $values[$i][type] == "close") {
- break;
- }
- // if open tag of current year, start looking for current month
- if ($values[$i][tag] == "Y$year" && $values[$i][type] == "open") {
- $lookForMonth = 1;
- }
- // get days
- if ($getDays) {
- // get day number from tag name
- $day = $values[$i][tag];
- // cut "D" off tag name
- $day = substr($day, 1);
- // put day number as key and event description as value in new array
- $event[$day] = $values[$i][value];
- }
- // if tag of current month, start getting days
- if ($lookForMonth && $values[$i][tag] == $monthName) {
- $getDays = 1;
- }
- // increment counter
- $i++;
- }
- //
- // PRINT CALENDAR
- //
- // print the HTML document header
- echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"calendar.css\">\n";
- echo "</head>\n\n";
- echo "<body>\n";
- echo "<title>Calendar</title>\n";
- // print the calendar table head
- echo "<table align=\"center\">\n";
- echo "<caption>$monthName $year</caption>\n";
- echo "<tr>\n";
- echo "\t<th>Dom</th>\n";
- echo "\t<th>Seg</th>\n";
- echo "\t<th>Ter</th>\n";
- echo "\t<th>Qua</th>\n";
- echo "\t<th>Qui</th>\n";
- echo "\t<th>Sex</th>\n";
- echo "\t<th>Sab</th>\n";
- echo "</tr>\n";
- // for each day of the month
- for ($dayNo = 1; $dayNo <= $daysInMonth; $dayNo++) {
- // get the day name
- $dayName = date(D, mktime(0, 0, 0, $monthNo, $dayNo, $year));
- // if the first day of the month is not Sunday
- if ($dayNo == 1 && $dayName != "Sun") {
- // start a new row
- echo "<tr>\n";
- // get the day of the week number (0-6)
- $dayOfWeek = date(w, mktime(0, 0, 0, $monthNo, $dayNo, $year));
- // print empty table cells until we reach the first day of the month
- for ($i = 0; $i < $dayOfWeek; $i++) {
- echo "\t<td></td>\n";
- }
- }
- // if Sunday, start a new row
- if ($dayName == "Sun") {
- echo "<tr>\n";
- }
- // if event exists for this day, print day cell with event
- if (isset($event[$dayNo])) {
- echo "\t<td class=\"event\"><b>$dayNo</b> $event[$dayNo]</td>\n";
- }
- // otherwise, print day cell without event
- else {
- echo "\t<td><center><b><big>$dayNo</big></b> <hr>
- 8:00 <input name='8_00-$dayNo-$monthNo-$year' size=15><br>
- 8:30 <input name='8_30-$dayNo-$monthNo-$year' size=15><br>
- 9:00 <input name='9_00-$dayNo-$monthNo-$year' size=15><br>
- </b></td>\n";
- }
- // if Saturday, close this row
- if ($dayName == "Sat") {
- echo "</tr>\n";
- }
- // if the last day of the month is not Saturday
- if ($dayNo == $daysInMonth && $dayName != "Sat") {
- // get the day of the week number (0-6)
- $dayOfWeek = date(w, mktime(0, 0, 0, $monthNo, $dayNo, $year));
- // print empty table cells until we reach Saturday
- for ($i = 6; $i > $dayOfWeek; $i--) {
- echo "\t<td></td>\n";
- }
- // close this row
- echo "</tr>\n";
- }
- $ndias=$dayNo;
- $nano=$year;
- $mes=$monthNo;
- }
- echo "<input type='hidden' name='ano' value='$nano'><input name='mes' type='hidden' value='$mes'>
- <input type='hidden' name='dias' value='$ndias'>
- ";
- // close the table
- echo "</table>\n";
- echo "<br>\n";
- //
- // PRINT NAVIGATION MENU
- //
- // calculate previous month
- $prevMonth = $monthNo - 1;
- // if previous month number is 0, reset to 12 and decrement year
- if ($prevMonth == 0) {
- $prevMonth = 12;
- $prevYear = $year - 1;
- }
- // otherwise, keep same year
- else {
- $prevYear = $year;
- }
- // calculate next month
- $nextMonth = $monthNo + 1;
- // if next month number is 13, reset to 1 and increment year
- if ($nextMonth == 13) {
- $nextMonth = 1;
- $nextYear = $year + 1;
- }
- // otherwise, keep same year
- else {
- $nextYear = $year;
- }
- echo "<input type='submit' value='SALVAR'>";
- echo "<center>\n";
- echo "<a href=?year=$prevYear&monthNo=$prevMonth>Anterior</a> | <a href=?year=$nextYear&monthNo=$nextMonth>Proximo</a>\n";
- echo "</center>\n<hr>";
- include "page-footer.php";
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement