1: <?php
2: 3: 4: 5: 6: 7: 8:
9: class Kronolith_View_EditEvent
10: {
11: 12: 13: 14:
15: protected $_event;
16:
17: 18: 19:
20: public function __construct(Kronolith_Event $event)
21: {
22: $this->_event = $event;
23: }
24:
25: public function __get($property)
26: {
27: switch ($property) {
28: case 'event':
29: return $this->_event;
30: default:
31: throw new Kronolith_Exception('Property does not exist.');
32: }
33: }
34:
35: public function getTitle()
36: {
37: if (!$this->_event) {
38: return _("Not Found");
39: }
40: if (is_string($this->_event)) {
41: return $this->_event;
42: }
43: return sprintf(_("Edit %s"), $this->_event->getTitle());
44: }
45:
46: public function link()
47: {
48: return $this->_event->getEditUrl();
49: }
50:
51: public function html($active = true)
52: {
53: if (!$this->_event) {
54: echo '<h3>' . _("Event not found") . '</h3>';
55: exit;
56: }
57: if (is_string($this->_event)) {
58: echo '<h3>' . $this->_event . '</h3>';
59: exit;
60: }
61:
62: $identity = $GLOBALS['injector']->getInstance('Horde_Core_Factory_Identity')->create();
63:
64: if ($this->_event->hasPermission(Horde_Perms::EDIT)) {
65: $calendar_id = $this->_event->calendarType . '_' . $this->_event->calendar;
66: } else {
67: $calendar_id = 'internal_' . Kronolith::getDefaultCalendar(Horde_Perms::EDIT);
68: }
69: if (!$this->_event->hasPermission(Horde_Perms::EDIT)) {
70: try {
71: $calendar_id .= '\\' . $this->_event->getShare()->get('owner');
72: } catch (Exception $e) {
73: }
74: }
75: $GLOBALS['session']->set('kronolith', 'attendees', $this->_event->attendees);
76: $GLOBALS['session']->set('kronolith', 'resources', $this->_event->getResources());
77: if ($datetime = Horde_Util::getFormData('datetime')) {
78: $datetime = new Horde_Date($datetime);
79: $month = $datetime->month;
80: $year = $datetime->year;
81: } else {
82: $month = Horde_Util::getFormData('month', date('n'));
83: $year = Horde_Util::getFormData('year', date('Y'));
84: }
85:
86: $url = Horde_Util::getFormData('url');
87: $perms = Horde_Perms::EDIT;
88: if ($this->_event->creator == $GLOBALS['registry']->getAuth()) {
89: $perms |= Kronolith::PERMS_DELEGATE;
90: }
91: $calendars = Kronolith::listCalendars($perms, true);
92:
93: $buttons = array();
94: if (!$this->_event->hasPermission(Horde_Perms::EDIT) &&
95: ($GLOBALS['injector']->getInstance('Horde_Core_Perms')->hasAppPermission('max_events') === true ||
96: $GLOBALS['injector']->getInstance('Horde_Core_Perms')->hasAppPermission('max_events') > Kronolith::countEvents())) {
97: $buttons[] = '<input type="submit" class="button" name="saveAsNew" value="' . _("Save As New") . '" />';
98: } else {
99: if ($this->_event->hasPermission(Horde_Perms::EDIT)) {
100: $buttons[] = '<input type="submit" class="button" name="save" value="' . _("Save Event") . '" />';
101: }
102: if ($this->_event->initialized) {
103: if (!$this->_event->recurs() &&
104: ($GLOBALS['injector']->getInstance('Horde_Core_Perms')->hasAppPermission('max_events') === true ||
105: $GLOBALS['injector']->getInstance('Horde_Core_Perms')->hasAppPermission('max_events') > Kronolith::countEvents())) {
106: $buttons[] = '<input type="submit" class="button" name="saveAsNew" value="' . _("Save As New") . '" />';
107: }
108: }
109: }
110:
111: if (isset($url)) {
112: $cancelurl = new Horde_Url($url);
113: } else {
114: $cancelurl = Horde::url('month.php', true)
115: ->add(array('month' => $month, 'year' => $year));
116: }
117:
118: $event = &$this->_event;
119: $tags = implode(',', array_values($event->tags));
120:
121: Horde_Core_Ui_JsCalendar::init(array(
122: 'full_weekdays' => true
123: ));
124:
125: Horde::addScriptFile('edit.js', 'kronolith');
126: Horde::addScriptFile('popup.js', 'horde');
127:
128: echo '<div id="EditEvent"' . ($active ? '' : ' style="display:none"') . '>';
129: require KRONOLITH_TEMPLATES . '/edit/edit.inc';
130: echo '</div>';
131:
132: if ($active && $GLOBALS['browser']->hasFeature('dom')) {
133: if ($this->_event->hasPermission(Horde_Perms::READ)) {
134: $view = new Kronolith_View_Event($this->_event);
135: $view->html(false);
136: }
137: if ($this->_event->hasPermission(Horde_Perms::DELETE)) {
138: $delete = new Kronolith_View_DeleteEvent($this->_event);
139: $delete->html(false);
140: }
141: }
142: }
143:
144: public function getName()
145: {
146: return 'EditEvent';
147: }
148:
149: }
150: