Overview

Packages

  • Kronolith
  • None

Classes

  • Kronolith
  • Kronolith_Ajax_Application
  • Kronolith_Ajax_Imple_ContactAutoCompleter
  • Kronolith_Ajax_Imple_Embed
  • Kronolith_Ajax_Imple_TagActions
  • Kronolith_Ajax_Imple_TagAutoCompleter
  • Kronolith_Api
  • Kronolith_Calendar
  • Kronolith_Calendar_External
  • Kronolith_Calendar_External_Tasks
  • Kronolith_Calendar_Holiday
  • Kronolith_Calendar_Internal
  • Kronolith_Calendar_Remote
  • Kronolith_Calendar_Resource
  • Kronolith_Calendars_Base
  • Kronolith_Calendars_Default
  • Kronolith_Calendars_Kolab
  • Kronolith_Day
  • Kronolith_Driver
  • Kronolith_Driver_Holidays
  • Kronolith_Driver_Horde
  • Kronolith_Driver_Ical
  • Kronolith_Driver_Kolab
  • Kronolith_Driver_Mock
  • Kronolith_Driver_Resource
  • Kronolith_Driver_Sql
  • Kronolith_Event
  • Kronolith_Event_Holidays
  • Kronolith_Event_Horde
  • Kronolith_Event_Ical
  • Kronolith_Event_Kolab
  • Kronolith_Event_Resource
  • Kronolith_Event_Sql
  • Kronolith_Exception
  • Kronolith_Factory_Calendars
  • Kronolith_Factory_Geo
  • Kronolith_Form_CreateCalendar
  • Kronolith_Form_CreateResource
  • Kronolith_Form_CreateResourceGroup
  • Kronolith_Form_DeleteCalendar
  • Kronolith_Form_DeleteResource
  • Kronolith_Form_DeleteResourceGroup
  • Kronolith_Form_EditCalendar
  • Kronolith_Form_EditRemoteCalendar
  • Kronolith_Form_EditResource
  • Kronolith_Form_EditResourceGroup
  • Kronolith_Form_SubscribeRemoteCalendar
  • Kronolith_Form_UnsubscribeRemoteCalendar
  • Kronolith_FreeBusy
  • Kronolith_FreeBusy_View
  • Kronolith_FreeBusy_View_Day
  • Kronolith_FreeBusy_View_Month
  • Kronolith_FreeBusy_View_Week
  • Kronolith_FreeBusy_View_Workweek
  • Kronolith_Geo_Base
  • Kronolith_Geo_Mysql
  • Kronolith_Geo_Sql
  • Kronolith_LoginTasks_SystemTask_Upgrade
  • Kronolith_LoginTasks_Task_PurgeEvents
  • Kronolith_Notification_Listener_AjaxStatus
  • Kronolith_Resource
  • Kronolith_Resource_Base
  • Kronolith_Resource_Group
  • Kronolith_Resource_Single
  • Kronolith_Storage
  • Kronolith_Storage_Kolab
  • Kronolith_Storage_Sql
  • Kronolith_Tagger
  • Kronolith_Test
  • Kronolith_View_Day
  • Kronolith_View_DeleteEvent
  • Kronolith_View_EditEvent
  • Kronolith_View_Event
  • Kronolith_View_ExportEvent
  • Kronolith_View_Month
  • Kronolith_View_Week
  • Kronolith_View_WorkWeek
  • Kronolith_View_Year
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: /**
  3:  * The Kronolith_View_Month:: class provides an API for viewing
  4:  * months.
  5:  *
  6:  * @author  Chuck Hagenbuch <chuck@horde.org>
  7:  * @author  Jan Schneider <jan@horde.org>
  8:  * @package Kronolith
  9:  */
 10: class Kronolith_View_Month
 11: {
 12:     /**
 13:      * @var integer
 14:      */
 15:     public $month;
 16: 
 17:     /**
 18:      * @var integer
 19:      */
 20:     public $year;
 21: 
 22:     /**
 23:      * @var Horde_Date
 24:      */
 25:     public $date;
 26: 
 27:     /**
 28:      * @var array
 29:      */
 30:     protected $_events = array();
 31: 
 32:     /**
 33:      * @var array
 34:      */
 35:     protected $_currentCalendars = array();
 36: 
 37:     /**
 38:      * @var integer
 39:      */
 40:     protected $_daysInView;
 41: 
 42:     /**
 43:      * @var integer
 44:      */
 45:     protected $_startOfView;
 46: 
 47:     /**
 48:      * @var integer
 49:      */
 50:     protected $_startday;
 51: 
 52:     /**
 53:      *
 54:      * @global Horde_Prefs $prefs
 55:      * @param Horde_Date $date
 56:      *
 57:      * @return Kronolith_View_Month
 58:      */
 59:     public function __construct(Horde_Date $date)
 60:     {
 61:         global $prefs;
 62: 
 63:         $this->month = $date->month;
 64:         $this->year = $date->year;
 65: 
 66:         // Need to calculate the start and length of the view.
 67:         $this->date = new Horde_Date($date);
 68:         $this->date->mday = 1;
 69:         $this->_startday = $this->date->dayOfWeek();
 70:         $this->_daysInView = Date_Calc::weeksInMonth($this->month, $this->year) * 7;
 71:         if (!$prefs->getValue('week_start_monday')) {
 72:             $this->_startOfView = 1 - $this->_startday;
 73: 
 74:             // We may need to adjust the number of days in the view if
 75:             // we're starting weeks on Sunday.
 76:             if ($this->_startday == Horde_Date::DATE_SUNDAY) {
 77:                 $this->_daysInView -= 7;
 78:             }
 79:             $endday = new Horde_Date(array('mday' => Horde_Date_Utils::daysInMonth($this->month, $this->year),
 80:                                            'month' => $this->month,
 81:                                            'year' => $this->year));
 82:             $endday = $endday->dayOfWeek();
 83:             if ($endday == Horde_Date::DATE_SUNDAY) {
 84:                 $this->_daysInView += 7;
 85:             }
 86:         } else {
 87:             if ($this->_startday == Horde_Date::DATE_SUNDAY) {
 88:                 $this->_startOfView = -5;
 89:             } else {
 90:                 $this->_startOfView = 2 - $this->_startday;
 91:             }
 92:         }
 93: 
 94:         $startDate = new Horde_Date(array('year' => $this->year,
 95:                                           'month' => $this->month,
 96:                                           'mday' => $this->_startOfView));
 97:         $endDate = new Horde_Date(array('year' => $this->year,
 98:                                         'month' => $this->month,
 99:                                         'mday' => $this->_startOfView + $this->_daysInView));
100: 
101:         if ($prefs->getValue('show_shared_side_by_side')) {
102:             $allCalendars = Kronolith::listInternalCalendars();
103:             $this->_currentCalendars = array();
104:             foreach ($GLOBALS['display_calendars'] as $id) {
105:                 $this->_currentCalendars[$id] = $allCalendars[$id];
106:             }
107:         } else {
108:             $this->_currentCalendars = array('internal_0' => true);
109:         }
110: 
111:         try {
112:             $this->_events = Kronolith::listEvents($startDate, $endDate);
113:         } catch (Exception $e) {
114:             $GLOBALS['notification']->push($e, 'horde.error');
115:             $this->_events = array();
116:         }
117:         if (!is_array($this->_events)) {
118:             $this->_events = array();
119:         }
120:     }
121: 
122:     public function html()
123:     {
124:         global $prefs;
125: 
126:         $sidebyside = $prefs->getValue('show_shared_side_by_side');
127:         $twentyFour = $prefs->getValue('twentyFour');
128:         $addLinks = Kronolith::getDefaultCalendar(Horde_Perms::EDIT) &&
129:             ($GLOBALS['injector']->getInstance('Horde_Core_Perms')->hasAppPermission('max_events') === true ||
130:              $GLOBALS['injector']->getInstance('Horde_Core_Perms')->hasAppPermission('max_events') > Kronolith::countEvents());
131: 
132:         if ($sidebyside) {
133:             require KRONOLITH_TEMPLATES . '/month/head_side_by_side.inc';
134:         } else {
135:             require KRONOLITH_TEMPLATES . '/month/head.inc';
136:         }
137: 
138:         $html = '';
139:         if (!$sidebyside && count($this->_currentCalendars)) {
140:             $html .= '<tr>';
141:         }
142: 
143:         $showLocation = Kronolith::viewShowLocation();
144:         $showTime = Kronolith::viewShowTime();
145:         $day_url = Horde::url('day.php');
146:         $this_link = $this->link(0, true);
147:         $new_url = Horde::url('new.php')->add('url', $this_link);
148:         $new_img = Horde::img('new_small.png', '+');
149: 
150:         foreach ($this->_currentCalendars as $id => $cal) {
151:             if ($sidebyside) {
152:                 $html .= '<tr>';
153:             }
154: 
155:             $cell = 0;
156:             for ($day = $this->_startOfView; $day < $this->_startOfView + $this->_daysInView; ++$day) {
157:                 $date = new Kronolith_Day($this->month, $day, $this->year);
158:                 $date->hour = $twentyFour ? 12 : 6;
159:                 $week = $date->weekOfYear();
160: 
161:                 if ($cell % 7 == 0 && $cell != 0) {
162:                     if ($sidebyside) {
163:                         $html .= '<td>' . htmlspecialchars($cal->get('name')) . '</td>';
164:                     } else {
165:                         $html .= "</tr>\n<tr>";
166:                     }
167:                 }
168:                 if ($date->isToday()) {
169:                     $style = 'today';
170:                 } elseif ($date->month != $this->month) {
171:                     $style = 'othermonth';
172:                 } elseif ($date->dayOfWeek() == 0 || $date->dayOfWeek() == 6) {
173:                     $style = 'weekend';
174:                 } else {
175:                     $style = 'text';
176:                 }
177: 
178:                 $html .= '<td class="' . $style . '" height="70" width="14%" valign="top"><div>';
179: 
180:                 $html .= $day_url->add('date', $date->dateString())
181:                     ->link(array('class' => 'day'))
182:                     . $date->mday . '</a>';
183: 
184:                 if ($addLinks) {
185:                     $new_url->add('date', $date->dateString());
186:                     if ($sidebyside) {
187:                         $new_url->add('calendar', $id);
188:                     }
189:                     $html .= $new_url->link(array('title' => _("Create a New Event"), 'class' => 'newEvent'))
190:                         . $new_img . '</a>';
191:                 }
192: 
193:                 if ($date->dayOfWeek() == Horde_Date::DATE_MONDAY) {
194:                     $html .= Horde::url('week.php')
195:                         ->add('date', $date->dateString())
196:                         ->link(array('class' => 'week'))
197:                         . sprintf(_("Week %d"), $week) . '</a>';
198:                 }
199: 
200:                 $html .= '</div><div class="clear">&nbsp;</div>';
201: 
202:                 $date_stamp = $date->dateString();
203:                 if (!empty($this->_events[$date_stamp])) {
204:                     foreach ($this->_events[$date_stamp] as $event) {
205:                         if (!$sidebyside || $event->calendar == $id) {
206:                             $html .= '<div class="month-eventbox"' . $event->getCSSColors() . '>'
207:                                 . $event->getLink($date, true, $this_link);
208:                             if ($showTime) {
209:                                 $html .= '<div class="event-time">' . htmlspecialchars($event->getTimeRange()) . '</div>';
210:                             }
211:                             if (!$event->isPrivate() && $showLocation) {
212:                                 $html .= '<div class="event-location">' . htmlspecialchars($event->getLocation()) . '</div>';
213:                             }
214:                             $html .= '</div>';
215:                         }
216:                     }
217:                 }
218: 
219:                 $html .= "</td>\n";
220:                 ++$cell;
221:             }
222: 
223:             if ($sidebyside) {
224:                 $html .= '</tr>';
225:             }
226:         }
227:         if (!$sidebyside && count($this->_currentCalendars)) {
228:             $html .= '</tr>';
229:         }
230: 
231:         echo $html . '</tbody></table>';
232:     }
233: 
234:     public function getMonth($offset = 0)
235:     {
236:         $month = new Horde_Date($this->date);
237:         $month->month += $offset;
238:         return $month;
239:     }
240: 
241:     public function link($offset = 0, $full = false)
242:     {
243:         $month = $this->getMonth($offset);
244:         return Horde::url('month.php', $full)
245:             ->add('date', $month->dateString());
246:     }
247: 
248:     public function getName()
249:     {
250:         return 'Month';
251:     }
252: 
253: }
254: 
API documentation generated by ApiGen