/
EditCalendar.php
207 lines (191 loc) · 7.45 KB
/
EditCalendar.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
<?php
/**
* Horde_Form for editing calendars.
*
* See the enclosed file COPYING for license information (GPL). If you
* did not receive this file, see http://www.horde.org/licenses/gpl.
*
* @package Kronolith
*/
/**
* The Kronolith_EditCalendarForm class provides the form for editing a
* calendar.
*
* @author Chuck Hagenbuch <chuck@horde.org>
* @package Kronolith
*/
class Kronolith_Form_EditCalendar extends Horde_Form
{
/**
* Calendar being edited.
*/
protected $_calendar;
public function __construct($vars, $calendar)
{
$this->_calendar = $calendar;
$owner = $calendar->get('owner') == $GLOBALS['registry']->getAuth() ||
(is_null($calendar->get('owner')) &&
$GLOBALS['registry']->isAdmin());
parent::__construct(
$vars,
$owner
? sprintf(_("Edit %s"), $calendar->get('name'))
: $calendar->get('name')
);
$this->addHidden('', 'c', 'text', true);
$this->addVariable(_("Name"), 'name', 'text', true);
if (!$owner) {
$v = $this->addVariable(_("Owner"), 'owner', 'text', false);
$owner_name = $GLOBALS['injector']
->getInstance('Horde_Core_Factory_Identity')
->create($calendar->get('owner'))
->getValue('fullname');
if (trim($owner_name) == '') {
$owner_name = $calendar->get('owner');
}
$v->setDefault($owner_name ? $owner_name : _("System"));
}
$this->addVariable(_("Color"), 'color', 'colorpicker', false);
if ($GLOBALS['registry']->isAdmin()) {
$this->addVariable(_("System Calendar"), 'system', 'boolean', false, false, _("System calendars don't have an owner. Only administrators can change the calendar settings and permissions."));
}
$this->addVariable(_("Description"), 'description', 'longtext', false, false, null, array(4, 60));
$this->addVariable(_("Tags"), 'tags', 'Kronolith:KronolithTags', false);
/* Display URL. */
$url = Horde::url('month.php', true, -1)
->add('display_cal', $calendar->getName());
$this->addVariable(
_("Display URL"), '', 'link', false, false, null,
array(array(
'url' => $url,
'text' => $url,
'title' => _("Click or copy this URL to display this calendar"),
'target' => '_blank')
)
);
/* Subscription URLs. */
$url = $GLOBALS['registry']->get('webroot', 'horde');
if (isset($GLOBALS['conf']['urls']['pretty']) &&
$GLOBALS['conf']['urls']['pretty'] == 'rewrite') {
$webdavUrl = $url . '/rpc/kronolith/';
$caldavUrl = $url . '/rpc/calendars/';
$accountUrl = $url . '/rpc/';
} else {
$webdavUrl = $url . '/rpc.php/kronolith/';
$caldavUrl = $url . '/rpc.php/calendars/';
$accountUrl = $url . '/rpc.php/';
}
try {
$accountUrl = Horde::url($accountUrl, true, -1)
. 'principals/'. $GLOBALS['registry']->getAuth() . '/';
$caldavUrl = Horde::url($caldavUrl, true, -1)
. $GLOBALS['registry']->getAuth()
. '/'
. $GLOBALS['injector']->getInstance('Horde_Dav_Storage')->getExternalCollectionId($calendar->getName(), 'calendar')
. '/';
$this->addVariable(
_("CalDAV Subscription URL"), '', 'link', false, false, null,
array(array(
'url' => $caldavUrl,
'text' => $caldavUrl,
'title' => _("Copy this URL to a CalDAV client to subscribe to this calendar"),
'target' => '_blank')
)
);
$this->addVariable(
_("CalDAV Account URL"), '', 'link', false, false, null,
array(array(
'url' => $accountUrl,
'text' => $accountUrl,
'title' => _("Copy this URL to a CalDAV client to subscribe to all your calendars"),
'target' => '_blank')
)
);
} catch (Horde_Exception $e) {
}
$webdavUrl = Horde::url($webdavUrl, true, -1)
. ($calendar->get('owner')
? $calendar->get('owner')
: '-system-')
. '/' . $calendar->getName() . '.ics';
$this->addVariable(
_("WebDAV/ICS Subscription URL"), '', 'link', false, false, null,
array(array(
'url' => $webdavUrl,
'text' => $webdavUrl,
'title' => _("Copy this URL to a WebDAV or ICS client to subscribe to this calendar"),
'target' => '_blank')
)
);
/* Feed URL. */
$url = Kronolith::feedUrl($calendar->getName());
$this->addVariable(
_("Feed URL"), '', 'link', false, false, null,
array(array(
'url' => $url,
'text' => $url,
'title' => _("Copy this URL to a news feed reader to subscribe to this calendar"),
'target' => '_blank')
)
);
/* Embed code. */
$v = $this->addVariable(
_("Embed code"), '', 'longtext', false, false,
_("To embed this calendar in another website, use the code above."),
array(4, 60));
$v->setHelp('embed');
$v->setDefault(Kronolith::embedCode($calendar->getName()));
/* Permissions link. */
if (empty($GLOBALS['conf']['share']['no_sharing']) && $owner) {
$url = Horde::url('perms.php')->add('share', $calendar->getName());
$this->addVariable(
'', '', 'link', false, false, null,
array(array(
'url' => $url,
'text' => _("Change Permissions"),
'onclick' => Horde::popupJs(
$url,
array('params' => array('urlencode' => true)))
. 'return false;',
'class' => 'horde-button',
'target' => '_blank')
)
);
}
$this->setButtons(array(
_("Save"),
array('class' => 'horde-delete', 'value' => _("Delete")),
array('class' => 'horde-cancel', 'value' => _("Cancel"))
));
}
/**
* @throws Kronolith_Exception
*/
public function execute()
{
switch ($this->_vars->submitbutton) {
case _("Save"):
$info = array();
foreach (array('name', 'color', 'description', 'tags', 'system') as $key) {
$info[$key] = $this->_vars->get($key);
}
Kronolith::updateShare($this->_calendar, $info);
break;
case _("Delete"):
Horde::url('calendars/delete.php')
->add('c', $this->_vars->c)
->redirect();
break;
case _("Cancel"):
Horde::url($GLOBALS['prefs']->getValue('defaultview') . '.php', true)
->redirect();
break;
}
}
public function renderActive()
{
return parent::renderActive(
$this->getRenderer(array('varrenderer_driver' => array('kronolith', 'kronolith'))),
$this->_vars);
}
}