/com_joomleague/components/com_joomleague/modules/mod_joomleague_calendar/calendarClass.php

https://gitlab.com/volleyuisp/joomleague · PHP · 303 lines · 232 code · 32 blank · 39 comment · 21 complexity · 20aa9434fc394956879cd3332872e3ef MD5 · raw file

  1. <?php
  2. //this is the PHP Calendar Class
  3. // PHP Calendar Class Version 1.4 (5th March 2001)
  4. //
  5. // Copyright David Wilkinson 2000 - 2001. All Rights reserved.
  6. //
  7. // This software may be used, modified and distributed freely
  8. // providing this copyright notice remains intact at the head
  9. // of the file.
  10. //
  11. // This software is freeware. The author accepts no liability for
  12. // any loss or damages whatsoever incurred directly or indirectly
  13. // from the use of this script. The author of this software makes
  14. // no claims as to its fitness for any purpose whatsoever. If you
  15. // wish to use this software you should first satisfy yourself that
  16. // it meets your requirements.
  17. //
  18. // URL: http://www.cascade.org.uk/software/php/calendar/
  19. // Email: davidw@cascade.org.uk
  20. class PHPCalendar
  21. {
  22. function getDayNames(){return $this->dayNames;}
  23. function setDayNames($names){$this->dayNames = $names;}
  24. function getMonthNames(){return $this->monthNames;}
  25. function setMonthNames($names){$this->monthNames = $names;}
  26. function getStartDay(){return $this->startDay;}
  27. function setStartDay($day){$this->startDay = $day; }
  28. function getStartMonth(){return $this->startMonth;}
  29. function setStartMonth($month){$this->startMonth = $month;}
  30. /*
  31. Return the HTML for a specified month
  32. */
  33. function getMonthView($month, $year)
  34. {
  35. return $this->getMonthHTML($month, $year);
  36. }
  37. /********************************************************************************
  38. The rest are private methods. No user-servicable parts inside.
  39. You shouldn't need to call any of these functions directly.
  40. *********************************************************************************/
  41. /*
  42. Calculate the number of days in a month, taking into account leap years.
  43. */
  44. function getDaysInMonth($month, $year)
  45. {
  46. if ($month < 1 || $month > 12)
  47. {
  48. return 0;
  49. }
  50. $d = $this->daysInMonth[$month - 1];
  51. if ($month == 2)
  52. {
  53. // Check for leap year
  54. // Forget the 4000 rule, I doubt I'll be around then...
  55. if ($year%4 == 0)
  56. {
  57. if ($year%100 == 0)
  58. {
  59. if ($year%400 == 0)
  60. {
  61. $d = 29;
  62. }
  63. }
  64. else
  65. {
  66. $d = 29;
  67. }
  68. }
  69. }
  70. return $d;
  71. }
  72. /*
  73. Generate the HTML for a given month
  74. */
  75. function getMonthHTML($m, $y, $showYear = 1)
  76. {
  77. $doc = JFactory::getDocument();
  78. $s = "";
  79. $a = $this->adjustDate($m, $y);
  80. $month = $a[0];
  81. $year = $a[1];
  82. $daysInMonth = $this->getDaysInMonth($month, $year);
  83. $date = getdate(mktime(12, 0, 0, $month, 1, $year));
  84. $daysInLastMonth = $this->getDaysInMonth(($month-1), $year);
  85. $first = $date["wday"];
  86. $monthName = $this->monthNames[$month - 1];
  87. $prev = $this->adjustDate($month - 1, $year);
  88. $next = $this->adjustDate($month + 1, $year);
  89. if ($showYear == 1)
  90. {
  91. $prevMonth = $this->getCalendarLink($prev[0], $prev[1]);
  92. $nextMonth = $this->getCalendarLink($next[0], $next[1]);
  93. $nextYear = $this->getCalendarLink($next[0], $next[1]);
  94. $prevYear = $this->getCalendarLink($prev[0], $prev[1]);
  95. }
  96. else
  97. {
  98. $prevMonth = "";
  99. $nextMonth = "";
  100. $prevYear = "";
  101. $nextYear = "";
  102. }
  103. $todaylink='';
  104. $language= JFactory::getLanguage(); //get the current language
  105. $language->load( 'mod_joomleague_calendar' ); //load the language ini file of the module
  106. $header = $monthName . (($showYear > 0) ? " " . $year : "");
  107. $s .= '<table id="jlctableCalendar-'.$this->modid.'" class="jlcCalendar">'."\n";
  108. $s .= " <tr>\n";
  109. $s .= ' <td align="center" class="jlcCalendarHeader jlcheaderArrow">' . '<a class="jlcheaderArrow" title="'
  110. . $language->_('MOD_JOOMLEAGUE_CALENDAR_PREVYEAR').'" id="jlcprevYear-' . $this->modid
  111. . '" href="javascript:void(0)" onclick="jlcnewDate('.$month.",". ($year-1).",".$this->modid
  112. . ');">&lt;&lt;</a>' . "</td>\n";
  113. $s .= ' <td align="center" class="jlcCalendarHeader jlcheaderArrow">' . '<a class="jlcheaderArrow" title="'
  114. . $language->_('MOD_JOOMLEAGUE_CALENDAR_PREVMONTH').'" id="jlcprevMonth-' . $this->modid
  115. . '" href="javascript:void(0)" onclick="jlcnewDate('.$prev[0].",". $prev[1].",".$this->modid
  116. . ');">&lt;</a>' . "</td>\n";
  117. $s .= '<td align="center" class="jlcCalendarHeader jlcheaderDate" colspan="3">'.$header."</td>\n";
  118. $s .= '<td align="center" class="jlcCalendarHeader jlcheaderArrow">' . '<a class="jlcheaderArrow" title="'
  119. . $language->_('MOD_JOOMLEAGUE_CALENDAR_NEXTMONTH').'" id="jlcnextMonth-' . $this->modid
  120. . '" href="'.'javascript:void(0)'.'" onclick="'."jlcnewDate(".$next[0].",". $next[1].",".$this->modid
  121. .');" >&gt;</a>' . "</td>\n";
  122. $s .= '<td align="center" class="jlcCalendarHeader jlcheaderArrow">' . '<a class="jlcheaderArrow" title="'
  123. . $language->_('MOD_JOOMLEAGUE_CALENDAR_NEXTYEAR').'" id="jlcnextYear-' . $this->modid
  124. . '" href="'.'javascript:void(0)'.'" onclick="'."jlcnewDate(".$month.",". ($year+1).",".$this->modid
  125. .');" >&gt;&gt;</a>' . "</td>\n";
  126. $s .= "</tr>\n";
  127. $s .= "<tr>\n";
  128. for($i=0;$i<7;$i++)
  129. {
  130. $s .= '<td class="jlcdayName">' . $this->dayNames[($this->startDay+$i)%7] . "</td>\n";
  131. }
  132. $s .= "</tr>\n";
  133. $d = $this->startDay + 1 - $first;
  134. while ($d > 1)
  135. {
  136. $d -= 7;
  137. }
  138. // if(!$day){
  139. $today = getdate(time());
  140. //}
  141. //else{$today = array("year"=>$y,"mon"=>$m,"mday"=>$day);}
  142. while ($d <= $daysInMonth)
  143. {
  144. $s .= "<tr>\n";
  145. for ($i = 0; $i < 7; $i++)
  146. {
  147. $class = ($year == $today["year"] && $month == $today["mon"] && $d == $today["mday"]) ? "highlight jlcCalendarDay jlcCalendarToday " : "jlcCalendarDay ";
  148. $s .= "<td class=\"";
  149. $tdEnd='">';
  150. if ($d > 0 && $d <= $daysInMonth)
  151. {
  152. $divday = ($d > 9) ? $d : '0'.$d;
  153. $divm = ($month > 9) ? $month : '0'.$month;
  154. $divid = 'jlcal_' . $year.'-'.$divm.'-'.$divday;
  155. $link = $this->getDateLink($d, $month, $year);
  156. $click = $this->getDateClick($d, $month, $year);
  157. $modalrel = ($link == "") ? '' : " rel=\"{handler: 'adopt', adopt:'jlCalList-".$this->modid."_temp'}\"";
  158. if($link && $class=="highlight jlcCalendarDay jlcCalendarToday ")
  159. {
  160. $todaylink=$click;
  161. $s .= $class . 'jlcCalendarTodayLink' . $tdEnd
  162. . '<a class="hasTip jlcCalendarToday jlcmodal' . $this->modid. '"'
  163. . ' href="' . $link . '" onclick="' . $click . '"';
  164. $s .= $modalrel . " >$divday</a>";
  165. }
  166. else
  167. {
  168. $s .= (($link == "") ? $class.$tdEnd.$divday : "jlcCalendarDay"
  169. . $tdEnd.'<a class="jlcCalendarDay hasTip jlcmodal' . $this->modid
  170. . '" href="' . $link . '" onclick="' . $click . '"'
  171. . $modalrel . " >$divday</a>");
  172. }
  173. }
  174. else
  175. {
  176. if($d <= 0) {
  177. $do = ($daysInLastMonth + $d);
  178. }
  179. else { $do = '0'.($d - $daysInMonth);}
  180. $s .= "jlcCalendarDay jlcCalendarDayEmpty " . $tdEnd . "$do";
  181. }
  182. $s .= "</td>\n";
  183. $d++;
  184. }
  185. $s .= "</tr>\n";
  186. }
  187. $s .= "</table>\n";
  188. if($todaylink!='' && $this->ajax == 0 && $this->lightbox == 1 && $this->lightbox_on_pageload == 1)
  189. {
  190. $doc->addScriptDeclaration('window.addEvent(\'domready\', function() {
  191. '.$todaylink.'
  192. });
  193. ');
  194. }
  195. $output = array();
  196. $output['calendar'] = $s;
  197. $output['list'] = $this->matches_output($m, $y, $d);
  198. $output['teamslist'] = $this->output_teamlist();
  199. return $output;
  200. }
  201. function adjustDate($month, $year)
  202. {
  203. $a = array();
  204. $a[0] = $month;
  205. $a[1] = $year;
  206. while ($a[0] > 12)
  207. {
  208. $a[0] -= 12;
  209. $a[1]++;
  210. }
  211. while ($a[0] <= 0)
  212. {
  213. $a[0] += 12;
  214. $a[1]--;
  215. }
  216. return $a;
  217. }
  218. /*
  219. The start day of the week. This is the day that appears in the first column
  220. of the calendar. Sunday = 0.
  221. */
  222. var $startDay = 0;
  223. /*
  224. The start month of the year. This is the month that appears in the first slot
  225. of the calendar in the year view. January = 1.
  226. */
  227. var $startMonth = 1;
  228. /*
  229. The labels to display for the days of the week. The first entry in this array
  230. represents Sunday.
  231. */
  232. var $dayNames = array("S", "M", "T", "W", "T", "F", "S");
  233. /*
  234. The labels to display for the months of the year. The first entry in this array
  235. represents January.
  236. */
  237. var $monthNames = array("January", "February", "March", "April", "May", "June",
  238. "July", "August", "September", "October", "November", "December");
  239. /*
  240. The number of days in each month. You're unlikely to want to change this...
  241. The first entry in this array represents January.
  242. */
  243. var $daysInMonth = array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
  244. var $modid = "";
  245. var $ajax = 0;
  246. var $lightbox = 0;
  247. var $lightbox_on_pageload = 0;
  248. var $usedteams = '';
  249. var $usedclubs = '';
  250. }
  251. ?>