api.calendar.php 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. ////////////////////////////////////////////////////////////////////////////////
  3. // Copyright (C) ReloadCMS Development Team //
  4. // http://reloadcms.sf.net //
  5. // //
  6. // This program is distributed in the hope that it will be useful, //
  7. // but WITHOUT ANY WARRANTY, without even the implied warranty of //
  8. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. //
  9. // //
  10. // This product released under GNU General Public License v2 //
  11. ////////////////////////////////////////////////////////////////////////////////
  12. class calendar {
  13. var $_temp = array();
  14. var $_events = array();
  15. var $_highlight = array();
  16. public function __construct($month, $year) {
  17. global $system;
  18. $this->_temp['first_day_stamp'] = mktime(0, 0, 0, $month, 1, $year);
  19. $this->_temp['first_day_week_pos'] = date('w', $this->_temp['first_day_stamp']);
  20. $this->_temp['number_of_days'] = date('t', $this->_temp['first_day_stamp']);
  21. }
  22. function assignEvent($day, $link) {
  23. $this->_events[(int) $day] = $link;
  24. }
  25. function highlightDay($day, $style = '!') {
  26. $this->_highlight[(int) $day] = $style;
  27. }
  28. function returnCalendar() {
  29. global $system;
  30. $return = '<table width="100%" border="0" cellspacing="1" cellpadding="0">';
  31. $return .= '<tr>';
  32. $return .= '<th align="center" colspan="7">' . rcms_date_localise(date('F Y', $this->_temp['first_day_stamp'])) . '</th>';
  33. $return .= '</tr>';
  34. $return .= '<tr>';
  35. $return .= rcms_date_localise('<th align="center">Mon</th><th align="center">Tue</th><th align="center">Wed</th><th align="center">Thu</th><th align="center">Fri</th><th align="center">Sat</th><th align="center">Sun</th>');
  36. $return .= '</tr>';
  37. $days_showed = 1;
  38. $cwpos = $this->_temp['first_day_week_pos'];
  39. if ($cwpos == 0)
  40. $cwpos = 7;
  41. while ($days_showed <= $this->_temp['number_of_days']) {
  42. $return .= '<tr>';
  43. if ($cwpos > 1) {
  44. $return .= '<td colspan="' . ($cwpos - 1) . '">&nbsp;</td>';
  45. }
  46. $inc = 0;
  47. for ($i = $days_showed; $i < $days_showed + 7 && $i <= $this->_temp['number_of_days'] && $cwpos <= 7; $i++) {
  48. $class = '';
  49. if (!empty($this->_highlight[$i])) {
  50. $class = 'special ';
  51. }
  52. if (empty($this->_events[$i])) {
  53. $class .= 'row2';
  54. } else {
  55. $class .= 'row3';
  56. }
  57. if (empty($this->_events[$i])) {
  58. $return .= '<td align="center" class="' . $class . '">' . $i . '</td>';
  59. } else {
  60. $return .= '<td align="center" class="' . $class . '"><a href="' . $this->_events[$i] . '" class="' . $class . '">' . $i . '</a></td>';
  61. }
  62. $cwpos++;
  63. $inc++;
  64. }
  65. $days_showed = $days_showed + $inc;
  66. $cwpos = 0;
  67. $return .= '</tr>';
  68. }
  69. $return .= '</table>';
  70. return $return;
  71. }
  72. }
  73. ?>