Advertisement
Guest User

Untitled

a guest
Jun 26th, 2017
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.93 KB | None | 0 0
  1. <?
  2. include "config.php";
  3. include "restrito.php";
  4. echo $menu;
  5. //
  6. $s="-";
  7.  
  8.  
  9. echo "<form action='calendar.php' method='POST'>
  10. <br>
  11. <b>Agenda</b>
  12. <hr>";
  13. //
  14.  
  15. // the XML file which holds your event data
  16. $xmlFile = "calendar.xml";
  17.  
  18. //
  19.  
  20. //
  21. $year=$_GET['year'];
  22. $monthNo=$_GET['monthNo'];
  23.  
  24.  
  25. if (!isset($year)) {
  26.     $year = date(Y);
  27. }
  28.  
  29. // get the month number (1-12) if one not provided
  30. if (!isset($monthNo)) {
  31.     $monthNo = date(n);
  32. }
  33.  
  34.  
  35. $monthName = date(F, mktime(0, 0, 0, $monthNo, 1, $year));
  36. if($monthName=='July')
  37. {
  38. $monthName='Julho';
  39. }
  40. else if($monthName=='June')
  41. {
  42. $monthName='Junho';
  43. }
  44. else if($monthName=='January')
  45. {
  46. $monthName='Janeiro';
  47. }
  48. else if($monthName=='February')
  49. {
  50. $monthName='Fevereiro';
  51. }
  52. else if($monthName=='March')
  53. {
  54. $monthName='Março';
  55. }
  56. else if($monthName=='April')
  57. {
  58. $monthName='Abril';
  59. }
  60. else if($monthName=='May')
  61. {
  62. $monthName='Maio';
  63. }
  64. else if($monthName=='August')
  65. {
  66. $monthName='Agosto';
  67. }
  68. else if($monthName=='September')
  69. {
  70. $monthName='Setembro';
  71. }
  72. else if($monthName=='October')
  73. {
  74. $monthName='Outubro';
  75. }
  76. else if($monthName=='November')
  77. {
  78. $monthName='Novembro';
  79. }
  80. else if($monthName=='December')
  81. {
  82. $monthName='Dezembro';
  83. }
  84.  
  85. // get the number of days in this month
  86. $daysInMonth = date(t);
  87.  
  88. //
  89. // GET XML DATA
  90. //
  91.  
  92. // get XML data
  93. $data = implode("", file($xmlFile));
  94.  
  95. // create XML parser
  96. $parser = xml_parser_create();
  97.  
  98. // set parser options
  99. xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
  100. xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
  101.  
  102. // parse XML data into arrays
  103. xml_parse_into_struct($parser, $data, $values, $tags);
  104.  
  105. // free parser
  106. xml_parser_free($parser);
  107.  
  108. // set variables for cycling through parsed XML data
  109. $i = 0; // set the array counter variable
  110. $lookForMonth = 0; // set default to false
  111. $getDays = 0; // set default to false
  112.  
  113. // cycle through parsed XML data
  114. while ($i < count($values)) {
  115.     // if close tag of current month, stop cycle
  116.     if ($values[$i][tag] == $monthName && $values[$i][type] == "close") {
  117.         break;
  118.     }
  119.  
  120.     // if close tag of current year, stop cycle
  121.     if ($values[$i][tag] == "Y$year" && $values[$i][type] == "close") {
  122.         break;
  123.     }
  124.  
  125.     // if open tag of current year, start looking for current month
  126.     if ($values[$i][tag] == "Y$year" && $values[$i][type] == "open") {
  127.         $lookForMonth = 1;
  128.     }
  129.  
  130.     // get days
  131.     if ($getDays) {
  132.         // get day number from tag name
  133.         $day = $values[$i][tag];
  134.  
  135.         // cut "D" off tag name
  136.         $day = substr($day, 1);
  137.  
  138.         // put day number as key and event description as value in new array
  139.         $event[$day] = $values[$i][value];
  140.     }
  141.  
  142.     // if tag of current month, start getting days
  143.     if ($lookForMonth && $values[$i][tag] == $monthName) {
  144.         $getDays = 1;
  145.     }
  146.  
  147.     // increment counter
  148.     $i++;
  149. }
  150.  
  151.  
  152. //
  153. // PRINT CALENDAR
  154. //
  155.  
  156. // print the HTML document header
  157. echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"calendar.css\">\n";
  158. echo "</head>\n\n";
  159. echo "<body>\n";
  160. echo "<title>Calendar</title>\n";
  161.  
  162.  
  163.  
  164.  
  165. // print the calendar table head
  166. echo "<table align=\"center\">\n";
  167. echo "<caption>$monthName $year</caption>\n";
  168. echo "<tr>\n";
  169. echo "\t<th>Dom</th>\n";
  170. echo "\t<th>Seg</th>\n";
  171. echo "\t<th>Ter</th>\n";
  172. echo "\t<th>Qua</th>\n";
  173. echo "\t<th>Qui</th>\n";
  174. echo "\t<th>Sex</th>\n";
  175. echo "\t<th>Sab</th>\n";
  176. echo "</tr>\n";
  177.  
  178. // for each day of the month
  179. for ($dayNo = 1; $dayNo <= $daysInMonth; $dayNo++) {
  180.     // get the day name
  181.     $dayName = date(D, mktime(0, 0, 0, $monthNo, $dayNo, $year));
  182.  
  183.     // if the first day of the month is not Sunday
  184.     if ($dayNo == 1 && $dayName != "Sun") {
  185.         // start a new row
  186.         echo "<tr>\n";
  187.  
  188.         // get the day of the week number (0-6)
  189.         $dayOfWeek = date(w, mktime(0, 0, 0, $monthNo, $dayNo, $year));
  190.  
  191.         // print empty table cells until we reach the first day of the month
  192.         for ($i = 0; $i < $dayOfWeek; $i++) {
  193.             echo "\t<td></td>\n";
  194.         }
  195.     }
  196.  
  197.     // if Sunday, start a new row
  198.     if ($dayName == "Sun") {
  199.         echo "<tr>\n";
  200.     }
  201.  
  202.     // if event exists for this day, print day cell with event
  203.     if (isset($event[$dayNo])) {
  204.         echo "\t<td class=\"event\"><b>$dayNo</b> $event[$dayNo]</td>\n";
  205.     }
  206.  
  207.     // otherwise, print day cell without event
  208.     else {
  209.  
  210.         echo "\t<td><center><b><big>$dayNo</big></b> <hr>
  211.         8:00  <input name='8_00-$dayNo-$monthNo-$year' size=15><br>
  212.         8:30  <input name='8_30-$dayNo-$monthNo-$year' size=15><br>
  213.         9:00  <input name='9_00-$dayNo-$monthNo-$year' size=15><br>
  214.         </b></td>\n";
  215.    
  216.        
  217.     }
  218.  
  219.     // if Saturday, close this row
  220.     if ($dayName == "Sat") {
  221.         echo "</tr>\n";
  222.     }
  223.  
  224.     // if the last day of the month is not Saturday
  225.     if ($dayNo == $daysInMonth && $dayName != "Sat") {
  226.         // get the day of the week number (0-6)
  227.         $dayOfWeek = date(w, mktime(0, 0, 0, $monthNo, $dayNo, $year));
  228.  
  229.         // print empty table cells until we reach Saturday
  230.         for ($i = 6; $i > $dayOfWeek; $i--) {
  231.             echo "\t<td></td>\n";
  232.         }
  233.  
  234.         // close this row
  235.         echo "</tr>\n";
  236.     }
  237.     $ndias=$dayNo;
  238.     $nano=$year;
  239.     $mes=$monthNo;
  240. }
  241. echo "<input type='hidden' name='ano' value='$nano'><input name='mes' type='hidden' value='$mes'>
  242. <input type='hidden' name='dias' value='$ndias'>
  243. ";
  244. // close the table
  245. echo "</table>\n";
  246. echo "<br>\n";
  247.  
  248. //
  249. // PRINT NAVIGATION MENU
  250. //
  251.  
  252. // calculate previous month
  253. $prevMonth = $monthNo - 1;
  254.  
  255. // if previous month number is 0, reset to 12 and decrement year
  256. if ($prevMonth == 0) {
  257.     $prevMonth = 12;
  258.     $prevYear = $year - 1;
  259. }
  260.  
  261. // otherwise, keep same year
  262. else {
  263.     $prevYear = $year;
  264. }
  265.  
  266. // calculate next month
  267. $nextMonth = $monthNo + 1;
  268.  
  269. // if next month number is 13, reset to 1 and increment year
  270. if ($nextMonth == 13) {
  271.     $nextMonth = 1;
  272.     $nextYear = $year + 1;
  273. }
  274.  
  275. // otherwise, keep same year
  276. else {
  277.     $nextYear = $year;
  278. }
  279. echo "<input type='submit' value='SALVAR'>";
  280. echo "<center>\n";
  281. echo "<a href=?year=$prevYear&monthNo=$prevMonth>Anterior</a> | <a href=?year=$nextYear&monthNo=$nextMonth>Proximo</a>\n";
  282. echo "</center>\n<hr>";
  283.  
  284. include "page-footer.php";
  285.  
  286. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement