]> git.datanom.net - webcal.git/blob - events/eventgui.class.php
Initial upload
[webcal.git] / events / eventgui.class.php
1 <?php
2 /* $Id$ */
3
4 include_once 'config.inc.php';
5 include_once 'dateformat.class.php';
6 include_once 'caldavresource.class.php';
7 require_once 'calendar.class.php';
8 require_once 'helper.php';
9
10 class EventGUI {
11
12 private $event;
13 private $referer;
14 private $summary;
15 private $location;
16 private $description;
17 private $start;
18 private $end;
19 private $timezone;
20 private $dates;
21 private $rrule;
22 private $startdate;
23 private $enddate;
24 private $until;
25 private $cal;
26
27 function __construct(VEvent $event = NULL, $referer = '', $cal = NULL) {
28 $this->event = $event;
29 $this->referer = urldecode($referer);
30 $this->cal = $cal;
31 //print $this->referer;
32 //exit;
33 $this->summary = '';
34 $this->location = '';
35 $this->description = '';
36 $this->start = '';
37 $this->end = '';
38 $this->timezone = '';
39 $this->localtime = ($_SESSION['user_settings']->getTimeZone() !== NULL) ?
40 $_SESSION['user_settings']->getTimeZone() : TIMEZONE;
41 $root = WEB_ROOT;
42 $week_start_sunday = ($_SESSION['user_settings']->getStartWeek() !== NULL) ?
43 $_SESSION['user_settings']->getStartWeek() : WEEK_START_SUNDAY;
44 $week_start_sunday = ($week_start_sunday) ? 0 : 1;
45 $this->startdate = <<< __CAL1
46 <script type="text/javascript">
47 A_TCALDEF['imgpath'] = '{$root}js/img/';
48 A_TCALDEF['weekstart'] = $week_start_sunday;
49 new tcal ({
50 'formname': 'event_data',
51 'controlname': 'startdate'
52 });
53 </script>
54 __CAL1;
55 $this->enddate = <<< __CAL1
56 <script type="text/javascript">
57 A_TCALDEF['imgpath'] = '{$root}js/img/';
58 A_TCALDEF['weekstart'] = $week_start_sunday;
59 new tcal ({
60 'formname': 'event_data',
61 'controlname': 'enddate'
62 });
63 </script>
64 __CAL1;
65 $this->until = <<< __CAL1
66 <script type="text/javascript">
67 A_TCALDEF['imgpath'] = '{$root}js/img/';
68 A_TCALDEF['weekstart'] = $week_start_sunday;
69 new tcal ({
70 'formname': 'event_data',
71 'controlname': 'untildate'
72 });
73 </script>
74 __CAL1;
75 }
76
77 private function parseEvent() {
78 if (! $this->event)
79 return FALSE;
80 $comp = $this->event->getBaseComponent();
81 $this->summary = $comp->GetPValue('SUMMARY');
82 $this->location = $comp->GetPValue('LOCATION');
83 $this->description = $comp->GetPValue('DESCRIPTION');
84 $this->start = $comp->GetPValue('DTSTART');
85 $this->end = $comp->GetPValue('DTEND');
86 $this->timezone = $this->event->getTZID();
87 $rrule = $this->event->getRRule();
88 $this->dates = $rrule->getEventDates();
89 $this->rrule = $rrule->getAll();
90 //echo $this->start .':'. $this->end .'<br/>';
91 return TRUE;
92 }
93
94 private function createDT($elem, $name) {
95 $res = array();
96
97 //print_r($elem);
98 //echo '<br/>';
99 if (count($elem) > 1) {
100 $date = $elem[0];
101 $time = substr($elem[1], 0, 4);
102 }
103 else {
104 $date = $elem[0];
105 $time = '2359';
106 }
107 for ($i = 0; $i < substr($time, 2); $i += 15);
108 if ($i < 10)
109 $i = "0$i";
110 $time = substr($time, 0, 2) . $i;
111 //echo "$time<br/>";
112 $options = array();
113 for ($i = 0; $i < 24; $i++) {
114 $h = ($i < 10) ? "0$i" : $i;
115 $stop = ($i == 23) ? 61 : 60;
116 for ($j = 0; $j < $stop; $j += 15) {
117 $m = ($j < 10) ? "0$j" : $j;
118 if ($m == 60)
119 $m = 59;
120 $hm = "$h$m";
121 //echo "$hm<br/>";
122 $option = "<option value=\"$hm\"";
123 if ($hm == $time)
124 $option .= ' selected="selected"';
125 $option .= ">$hm</option>";
126 array_push($options, $option);
127 }
128 }
129 $select = "<select name=\"$name\" id=\"$name\">";
130 foreach ($options as $option)
131 $select .= $option;
132 $select .= '</select>';
133 $date = substr($date, 0, 4).'-'.substr($date, 4, 2).'-'.substr($date, 6);
134 //echo "$date<br/>";
135 $res['date'] = $date;
136 $res['time'] = $select;
137 return $res;
138 }
139
140 private function createTime() {
141 include_once 'timezone.php';
142
143 if ($this->start == '' || $this->end == '') {
144 $this->start = date("Ymd\THis");
145 $this->end = date("Ymd\THis", strtotime("+1 hour"));
146 $this->timezone = $_SESSION['user_settings']->getTimeZone();
147 }
148 //echo $this->start .':'. $this->end .'<br/>';
149 $tz = '<select name="tzid">';
150 foreach ($timezones as $timezone) {
151 $tz .= "<option value=\"$timezone\"";
152 if ($this->localtime == $timezone)
153 $tz .= ' selected="selected"';
154 $tz .= ">$timezone</option>";
155 }
156 $tz .= "</select>";
157 $dateFormat = new DateFormat();
158 $UTCStart = $dateFormat->UTC2Client($this->start);
159 $UTCEnd = $dateFormat->UTC2Client($this->end);
160 //echo $UTCStart .':'. $UTCEnd .'<br/>';
161 $startArray = explode('T', $UTCStart);
162 //echo "Client: ".$dateFormat->client2UTC($dateFormat->UTC2Client($this->start))."<br/>";
163 //echo "Local: ".$dateFormat->UTC2Local($this->start)."<br/>";
164 $start = $this->createDT($startArray, 'starttime');
165 $endArray = explode('T', $UTCEnd);
166 $end = $this->createDT($endArray, 'endtime');
167 $allDay = CaldavRessource::allDayEvent($UTCStart, $UTCEnd);
168 $allDay = ($allDay) ? 'checked="checked"' : '';
169 $datetime = "<table><caption style=\"font-weight: bold\">Date &amp; Time</caption>
170 <tr>
171 <td>All Day Event</td>
172 <td>
173 <script type=\"text/javascript\">
174 var observable1 = ['starttime', 'tcalico_1', 'enddate', 'endtime'];
175 document.write('<input type=\"checkbox\" name=\"allDay\" $allDay' +
176 'id=\"allDay\" onchange=\"stateSwitch(this, observable1, 0)\"/>');
177 </script>
178 </td>
179 <td>&nbsp;</td>
180 </tr>
181 <tr>
182 <td>Start</td>
183 <td>
184 <script type=\"text/javascript\">
185 document.write('<input type=\"text\" name=\"startdate\" ' +
186 'id=\"startdate\" size=\"12\" onchange=\"dateAlign(' +
187 'this)\" value=\"{$start['date']}\"/>');
188 </script>
189 $this->startdate
190 <!--{$start['date']}-->
191 </td>
192 <td>{$start['time']}</td>
193 <td rowspan=\"2\">$tz</td>
194 </tr>
195 <tr>
196 <td>End</td>
197 <td>
198 <script type=\"text/javascript\">
199 document.write('<input name=\"enddate\" type=\"text\" ' +
200 'id=\"enddate\" size=\"12\" onchange=\"dateAlign(' +
201 'this)\" value=\"{$end['date']}\"/>');
202 </script>
203 $this->enddate
204 <!--{$end['date']}-->
205 </td>
206 <td>
207 {$end['time']}
208 <script type=\"text/javascript\">
209 var observable4 = ['starttime', 'tcalico_1', 'enddate', 'endtime'];
210 stateSwitch(document.getElementById('allDay'), observable4, 1);
211 </script>
212 </td>
213 </tr>
214 </table>";
215 return $datetime;
216 }
217
218 private function recurRule($checked) {
219 $choices = array('DAILY', 'WEEKLY', 'MONTHLY', 'YEARLY');
220 $rule = '<span style="font-weight: bold">Recurrence Types</span><br/>';
221 foreach ($choices as $choice) {
222 $rule .= "<input type=\"radio\" name=\"recurrence\" value=\"$choice\"";
223 if (strtoupper($checked) == $choice)
224 $rule .= ' checked="checked"';
225 $rule .= "/>$choice<br/>";
226 }
227 return $rule;
228 }
229
230 private function rangeRule($rules) {
231 $until = '';
232 $times = '';
233 $count_check = '';
234 $until_check = '';
235 $no_check = '';
236
237 $range = $rules['until'][0];
238 if (! $range) {
239 $range = $rules['count'][0];
240 if ($range) {
241 $times = $range;
242 $count_check = 'checked="checked"';
243 }
244 else {
245 $no_check = 'checked="checked"';
246 }
247 }
248 else {
249 $until = substr($range, 0, 4).'-'.substr($range, 4, 2).
250 '-'.substr($range, 6, 2);
251 $until_check = 'checked="checked"';
252 }
253 $rule = <<<_RULE
254 <span style="font-weight: bold">Recurrence Range</span><br/>
255 <input type="radio" name="range" value="UNLIMITED" $no_check/>
256 No ending date<br/>
257 <input type="radio" name="range" value="COUNT" $count_check/>
258 End after
259 <input type="text" name="times" size="4"
260 value="$times"/>&nbsp;Occurrence(s)<br/>
261 <input type="radio" name="range" value="UNTIL" $until_check/>
262 End on
263 <input type="text" name="untildate" size="12" value="$until"/>
264 {$this->until}
265 _RULE;
266 return $rule;
267 }
268
269 private function createRecur() {
270 $recur = NULL;
271 $rrule = NULL;
272 if ($this->rrule) {
273 $rrule = array_diff_key($this->rrule, array('freq' => ''));
274 switch ($this->rrule['freq'][0]) {
275 case 'DAILY': $recur = 'DAILY'; break;
276 case 'WEEKLY': $recur = 'WEEKLY'; break;
277 case 'MONTHLY': $recur = 'MONTHLY'; break;
278 case 'YEARLY': $recur = 'YEARLY'; break;
279 }
280 }
281 $recur = $this->recurRule($recur);
282 $range = $this->rangeRule($rrule);
283 //print htmlentities($recur);
284 $res = <<<_TABLE
285 <table cellpadding="10">
286 <caption style="font-weight: bold">Recurrence Rule</caption>
287 <tr>
288 <td valign="top">$recur</td>
289 <td valign="top">$range</td>
290 </tr>
291 </table>
292 _TABLE;
293 return $res;
294 }
295
296 function getView() {
297 $title = '<input name="summary" size="53" value="_SUM_"/>';
298 $location = '<input name="location" size="53" value="_LOC_"/>';
299 $description =
300 '<textarea name="description" cols="60" rows="5">_DESC_</textarea>';
301 if ($this->parseEvent()) {
302 $title = str_replace('_SUM_', $this->summary, $title);
303 $location = str_replace('_LOC_', $this->location, $location);
304 $description = str_replace('_DESC_', $this->description, $description);
305 }
306 else {
307 $title = str_replace('_SUM_', '', $title);
308 $location = str_replace('_LOC_', '', $location);
309 $description = str_replace('_DESC_', '', $description);
310 }
311 $btn_label = ($_SESSION['EVENT_ACTION'] == 'NEW') ? "Create" : "Update";
312 unset($_SESSION['EVENT_ACTION']);
313 // for delete button
314 $etag = $this->event->getEtag();
315 $url = $this->event->getUrl();
316 $view = dirname($_SERVER['PHP_SELF']).'/delete_event.php';
317 //['starttime', 'enddate', 'endtime']
318 $view = "<div id=\"event\">
319 <form id=\"event_data\" method=\"post\" action=\"{$_SERVER['PHP_SELF']}\"
320 onsubmit=\"return enableAll(['starttime', 'enddate', 'endtime'])\">
321 <table>
322 <caption style=\"font-weight: bold\">General</caption>
323 <tr>
324 <td>Title</td><td>$title</td>
325 </tr>
326 <tr>
327 <td>Location</td><td>$location</td>
328 </tr>
329 <tr>
330 <td>Description</td><td>$description</td>
331 </tr>
332 </table><p/>".
333 $this->createTime()."<p/>".
334 $this->createRecur().
335 "<p style=\"text-align: center\">
336 <input type=\"hidden\" value=\"$this->referer\" name=\"referer\"/>
337 <input type=\"button\" value=\"Cancel\"
338 onclick=\"document.location.href='$this->referer'\"/>
339 <input type=\"submit\" value=\"$btn_label\"/>
340 <!--onclick=\"document.getElementById('event_data').submit()\"/>-->
341 <input type=\"button\" value=\"Delete\"
342 onclick=\"document.location.href='$view?etag=$etag&url=$url'+
343 '&cal=$this->cal&referer=$this->referer'\"/>
344 <!--onclick=\"javascript: alert('Update not available')\"/>-->
345 <!--<input type=\"submit\" name=\"update\" value=\"Update\"/>-->
346 </p>
347 </form>
348 </div>";
349 return $view;
350 }
351
352 }
353
354 ?>
This page took 0.103107 seconds and 6 git commands to generate.