PageRenderTime 58ms CodeModel.GetById 29ms RepoModel.GetById 0ms app.codeStats 0ms

/blocks/mini_calendar/functions.php

https://github.com/eoconnell/bayonetcms
PHP | 196 lines | 137 code | 26 blank | 33 comment | 22 complexity | 43bb98bb3aa19188b28bc4d38a26fc28 MD5 | raw file
Possible License(s): GPL-3.0
  1. <?php
  2. /**
  3. * Bayonet Content Management System
  4. * Copyright (C) 2008 Joseph Hunkeler & Evan O'Connell
  5. *
  6. * This program is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. /**
  20. * Note to anyone feeling the need to edit this file...
  21. * You MUST declare $db as global inside your functions in order access MySQL from here.
  22. */
  23. /**
  24. * PrintCalendar() - prints the calendar with events
  25. */
  26. ?>
  27. <script type="text/javascript">
  28. function openEvent(date)
  29. {
  30. <?php echo "myWindow = window.open('". Bayonet_Config::$ini['site']['url'] . "blocks/mini_calendar/event.php?date='+date+'','','width=300,height=300');"; ?>
  31. myWindow = window.open('blocks/mini_calendar/event.php?date='+date+'','','width=300,height=300')
  32. myWindow.focus();
  33. }
  34. </script>
  35. <?php
  36. function PrintCalendar(){
  37. $date = time();
  38. date_default_timezone_set("America/New_York"); //EASTERN TIME ZONE
  39. $day = date('d', $date);
  40. $today = date('j', $date);
  41. $month = date('m', $date);
  42. $monthNum = date('n', $date);
  43. $year = date('Y', $date);
  44. /* Accounts for the last couple days from the previous months */
  45. $first_day = mktime(0,0,0,$monthNum, 1, $year);
  46. $title = date('F', $first_day);
  47. $day_of_week = date('D', $first_day);
  48. switch($day_of_week){
  49. case "Sun": $blank = 0; break;
  50. case "Mon": $blank = 1; break;
  51. case "Tue": $blank = 2; break;
  52. case "Wed": $blank = 3; break;
  53. case "Thu": $blank = 4; break;
  54. case "Fri": $blank = 5; break;
  55. case "Sat": $blank = 6; break;
  56. }
  57. /* calculates the days in the current month */
  58. $days_in_month = cal_days_in_month(0, $monthNum, $year);
  59. //makes sure that previous year is not year 0
  60. if($monthNum == 1){
  61. $previous_month = 12;
  62. $previous_year = $year-1;
  63. }else{
  64. $previous_month = $monthNum-1;
  65. $previous_year = $year;
  66. }
  67. //makes sure the next year is not year 13
  68. if($monthNum == 12){
  69. $next_month = 1;
  70. $next_year = $year+1;
  71. }else{
  72. $next_month = $monthNum+1;
  73. $next_year = $year;
  74. }
  75. ?>
  76. <center>
  77. <table class="calendar" style="background-color:white;" cellspacing="1" cellpadding="0">
  78. <tr style="background-color:#999999; height:20px;">
  79. <td colspan="50" style="vertical-align:middle; text-align:center;">
  80. <!-- <a href="?op=calendar&month=<?php echo $previous_month.'&year='.$previous_year; ?>"><<</a> -->
  81. <!-- Month Name and Year -->
  82. &nbsp;&nbsp;<span class="monthTitle"><?php echo strtoupper($title).' '.$year; ?></span>&nbsp;&nbsp;
  83. <!-- <a href="?op=calendar&month=<?php echo $next_month.'&year='.$next_year; ?>">>></a> -->
  84. </td>
  85. </tr>
  86. <tr>
  87. <th class="weekday">Sun</th><th class="weekday">Mon</th><th class="weekday">Tue</th><th class="weekday">Wed</th>
  88. <th class="weekday">Thu</th><th class="weekday">Fri</th><th class="weekday">Sat</th>
  89. </tr>
  90. <tr>
  91. <?php
  92. $day_count = 1; //holds the current day of the week 1-7
  93. $day_num = 1; //holds the current day of the month 1-31
  94. $days_monthbefore = cal_days_in_month(0, $previous_month, $year);
  95. //prints the numbers of days for the previous month
  96. while($blank > 0){
  97. $blank = $blank-1;
  98. $days_before = $days_monthbefore-$blank;
  99. echo '<td class="cal_notmonth">'.$days_before.'</td>'; //'.$days_before.'</td>';
  100. $day_count++;
  101. }
  102. $sqlToday = date("Y-m-d", mktime(0, 0, 0, $monthNum, $today, $year));
  103. $events = GetEventsOnInterval("{$year}-{$monthNum}-01","{$year}-{$monthNum}-{$days_in_month}");
  104. //loop printing each day of the CURRENT month ONLY
  105. while($day_num <= $days_in_month){
  106. if($day_count==1 || $day_count==7){
  107. echo '<td class="cal_weekend">'; //weekends
  108. }else{
  109. echo '<td class="cal_weekday">'; //weekdays
  110. }
  111. $sqlDate = date("Y-m-d", mktime(0, 0, 0, $monthNum, $day_num, $year));
  112. //checks to see if the current day has events
  113. $isEvent=false;
  114. foreach($events as $event){
  115. if($event['date'] == $sqlDate){
  116. $isEvent = true;
  117. if($event['date'] == $sqlToday){
  118. $todaysEvents[] = $event;
  119. }
  120. }
  121. }
  122. if($day_num == $today && $isEvent==true){
  123. echo '<div class="eventtoday">'.$day_num.'</div>';
  124. }else if($day_num == $today && $isEvent==false){
  125. echo '<div class="monthtoday">'.$day_num.'</div>';
  126. }else if($day_num != $today && $isEvent==true){
  127. echo "<div class=\"event\" onclick=\"openEvent('{$sqlDate}')\">";
  128. echo $day_num;
  129. echo '</div>';
  130. }else{
  131. echo $day_num;
  132. }
  133. echo '</td>';
  134. $day_num++;
  135. $day_count++;
  136. if($day_count > 7){
  137. echo '</tr><tr>';
  138. $day_count = 1;
  139. }
  140. }
  141. $days_after = 1;
  142. //loop for printing the days for the next month
  143. while($day_count > 1 && $day_count <=7){
  144. echo '<td class="cal_notmonth">'.$days_after.'</td>'; //'.$days_after.'</td>';
  145. $days_after++;
  146. $day_count++;
  147. }
  148. ?>
  149. </tr>
  150. </table>
  151. </center>
  152. <?php
  153. //list events for today
  154. if(count($todaysEvents)>0){
  155. echo "<h3>Today's Events</h3>";
  156. foreach($todaysEvents as $event){
  157. $time = date("g:i a", strtotime($event['date']." ".$event['time']));
  158. echo "<span style=\"background-color: {$event['color']}\">&nbsp;&nbsp;</span>&nbsp;{$event['title']} @ {$time}<br />";
  159. }
  160. }
  161. }
  162. function GetEventsOnInterval($start,$end){
  163. global $db;
  164. $result = $db->Query("SELECT `event_id`, `title`, `color`, `date`, `time` FROM `bayonet_events` WHERE `date` BETWEEN '$start' AND '$end' ORDER BY `time` ASC");
  165. $events = $db->Fetch($result);
  166. return $events;
  167. }
  168. ?>