]>
Commit | Line | Data |
---|---|---|
a5eae6b7 MR |
1 | <?php |
2 | /* $Id$ */ | |
3 | ||
4 | require_once 'calendar.class.php'; | |
5 | require_once 'user_validate.php'; | |
6 | require_once 'helper.php'; | |
7 | ||
8 | valid_user(); | |
9 | ||
10 | include_once 'config.inc.php'; | |
11 | include_once 'eventgui.class.php'; | |
12 | ||
13 | if (! defined($_SESSION['__ROOT__']) && empty($_SESSION['__ROOT__'])) { | |
14 | session_destroy(); | |
15 | header('Location: ' . WEB_ROOT . 'error.html'); | |
16 | exit; | |
17 | } | |
18 | ||
19 | if (isset($_SESSION['authenticate']) && $_SESSION['authenticate']->validUser()) { | |
20 | $view_style = ($_SESSION['user_settings']->getViewStyle()) ? | |
21 | $_SESSION['user_settings']->getViewStyle() : VIEW_STYLE; | |
22 | // $timeout = ($_SESSION['user_settings']->getTimeout()) ? | |
23 | // (int) $_SESSION['user_settings']->getTimeout() : TIMEOUT; | |
24 | $week_start_sunday = ($_SESSION['user_settings']->getStartWeek() !== NULL) ? | |
25 | $_SESSION['user_settings']->getStartWeek() : WEEK_START_SUNDAY; | |
26 | $start_hour = ($_SESSION['user_settings']->getStartHour()) ? | |
27 | (int) $_SESSION['user_settings']->getStartHour() : START_HOUR; | |
28 | $end_hour = ($_SESSION['user_settings']->getEndHour()) ? | |
29 | (int) $_SESSION['user_settings']->getEndHour() : END_HOUR; | |
30 | } | |
31 | ||
32 | $pwd = WEB_ROOT; | |
33 | if ($pwd[strlen($pwd)-1] == '/') | |
34 | $pwd = substr($pwd, 0, -1); | |
35 | ||
36 | if (isset($_POST) && count($_POST) > 0) { | |
37 | $exclude = array('tzid','range','times','untildate'); | |
38 | $start = array('date' => NULL, 'time' => NULL); | |
39 | $end = array('date' => NULL, 'time' => NULL); | |
40 | $referer = $_POST['referer']; | |
41 | $allDay = false; | |
42 | ||
43 | foreach ($_POST as $key => $value) { | |
44 | //echo "$key => $value<br/>"; | |
45 | if (strcmp($key, 'referer') == 0) | |
46 | continue; | |
47 | if (in_array($key, $exclude)) | |
48 | continue; | |
49 | if (strcasecmp($key, 'startdate') == 0) { | |
50 | $start['date'] = join('', explode('-',$value)); | |
51 | continue; | |
52 | } | |
53 | if (strcasecmp($key, 'starttime') == 0) { | |
54 | $start['time'] = $value; | |
55 | if (strlen($start['time']) < 5) | |
56 | $start['time'] .= '00'; | |
57 | continue; | |
58 | } | |
59 | if (strcasecmp($key, 'enddate') == 0) { | |
60 | $end['date'] = join('', explode('-',$value)); | |
61 | continue; | |
62 | } | |
63 | if (strcasecmp($key, 'endtime') == 0) { | |
64 | $end['time'] = $value; | |
65 | if (strlen($end['time']) < 5) | |
66 | $end['time'] .= '00'; | |
67 | continue; | |
68 | } | |
69 | if (strcasecmp("allDay", $key) == 0) { | |
70 | $allDay = true; | |
71 | continue; | |
72 | } | |
73 | if (strcasecmp("recurrence", $key) == 0) { | |
74 | $value = "FREQ=$value"; | |
75 | $key = "RRULE"; | |
76 | } | |
77 | //echo "$key => $value<br/>"; | |
78 | $_SESSION['current_event']->setProperty($key, $value); | |
79 | } | |
80 | //echo 'DTSTART: '. $start['date'].'T'.$start['time']; | |
81 | //echo '<br/>DTEND: '. $end['date'].'T'.$end['time']; | |
82 | //exit; | |
83 | if ($allDay) { | |
84 | $_SESSION['current_event']->setProperty( | |
85 | 'DTSTART;VALUE=DATE', $start['date']); | |
86 | $_SESSION['current_event']->setProperty( | |
87 | 'DTEND;VALUE=DATE', $end['date']); | |
88 | //echo "<br/>".$start['date']."<br/>"; | |
89 | //echo $end['date']."<br/>"; | |
90 | } | |
91 | else { | |
92 | $start = strtotime($start['date'].'T'.$start['time']); | |
93 | $end = strtotime($end['date'].'T'.$end['time']); | |
94 | //echo "<br/>".Calendar::timestamp2ICal($start, FALSE)."<br/>"; | |
95 | //echo Calendar::timestamp2ICal($end, FALSE)."<br/>"; | |
96 | //exit; | |
97 | $_SESSION['current_event']->setProperty('DTSTART', | |
98 | Calendar::timestamp2ICal($start, FALSE)); | |
99 | $_SESSION['current_event']->setProperty('DTEND', | |
100 | Calendar::timestamp2ICal($end, FALSE)); | |
101 | } | |
102 | //exit; | |
103 | if (isset($_SESSION['calendar'])) { | |
104 | $res = $_SESSION['calendar']->update( | |
105 | $_SESSION['current_event']->getUrl(), | |
106 | $_SESSION['current_event']->getEtag()); | |
107 | //print_r($res); | |
108 | //exit; | |
109 | unset($_SESSION['current_event']); | |
110 | unset($_SESSION['calendar']); | |
111 | unset($_SESSION['EVENT_ACTION']); | |
112 | if (count($res) == 0) { | |
113 | header('Location: ' . $referer); | |
114 | exit; | |
115 | } | |
116 | $msg = ''; | |
117 | foreach ($res as $elem) { | |
118 | $k = key($elem); | |
119 | $msg .= "$k: " . $elem[$k]; | |
120 | } | |
121 | } | |
122 | else | |
123 | throw new Exception("Error updating event"); | |
124 | //print "$msg\n"; | |
125 | $msg = join("", explode("\n", $msg)); | |
126 | $title = TITLE; | |
127 | $pwd = WEB_ROOT; | |
128 | $head = <<<__HEAD | |
129 | <?xml version="1.0" encoding="utf-8"?> | |
130 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" | |
131 | "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> | |
132 | <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> | |
133 | <head> | |
134 | <title>$title</title> | |
135 | <meta http-equiv="content-type" content="application/xhtml+xml; charset=UTF-8"/> | |
136 | <meta http-equiv="content-style-type" content="text/css"/> | |
137 | <link rel="stylesheet" type="text/css" href="$pwd/css/top_level.css" /> | |
138 | <link rel="shortcut icon" href="$pwd/pixmaps/favicon.ico" /> | |
139 | <script type="text/javascript" src="$pwd/js/helper.js"></script> | |
140 | </head> | |
141 | <body onload="error('$msg')"> | |
142 | <table style="width: 100%;"> | |
143 | <tr> | |
144 | <td style="width: 33%"><img src="$pwd/pixmaps/calendar.png" alt="calendar.png" /></td> | |
145 | <td style="width: 33%; text-align: center;"><a href="$pwd/logout.php"><img style="border: 0" src="$pwd/pixmaps/exit.png" width="32" height="32" alt="Logout" /><br/>Logout</a></td> | |
146 | <td style="text-align: right"><span style="font-size: 1.6em">DAViCal Web Calendar</span><br/> - A Web Interface for <a href="javascript: newwin('http://www.davical.org/');">DAViCal</a></td> | |
147 | </tr> | |
148 | </table> | |
149 | __HEAD; | |
150 | print "$head"; | |
151 | include TOP_FOLDER.'/include/menu.inc.php'; | |
152 | print "<div id=\"ui\"></div>"; | |
153 | include TOP_FOLDER.'/include/footer.inc.php'; | |
154 | exit; | |
155 | } | |
156 | else { | |
157 | $query = construct_URL($_SERVER['QUERY_STRING'], | |
158 | array('etag', 'referer', 'cal')); | |
159 | //print_r($_SESSION['all_events'][$query['cal']]); | |
160 | //exit; | |
161 | if (isset($query['cal']) && ! empty($query['cal'])) { | |
162 | $_SESSION['calendar'] = $_SESSION['all_events'][$query['cal']]; | |
163 | if (! is_object($_SESSION['calendar'])) | |
164 | throw new Exception("Missing calendar object"); | |
165 | ||
166 | if ($_SESSION['EVENT_ACTION'] == 'NEW') { | |
167 | $event = $_SESSION['calendar']->newComponent('VEVENT'); | |
168 | $_SESSION['current_event'] = $event; | |
169 | } | |
170 | else { | |
171 | foreach ($_SESSION['calendar'] as $vevent) { | |
172 | if ($vevent->getEtag() == $query['etag']) { | |
173 | $event = $vevent; | |
174 | break; | |
175 | } | |
176 | } | |
177 | $_SESSION['current_event'] = $event; | |
178 | } | |
179 | //print $query['referer']; | |
180 | //exit; | |
181 | $gui = new EventGUI($event, $query['referer'], $query['cal']); | |
182 | //unset($_GET['referer']); | |
183 | $calendar = $gui->getView(); | |
184 | } | |
185 | else { | |
186 | $text = '<h3 style="text-align: center">Choose an event from one of the listed calendars</h3>'; | |
187 | $text .= '<p>'; | |
188 | $text .= '<form id="cals" style="text-align: center" action="'. | |
189 | $_SERVER['PHP_SELF'].'" method="get">'; | |
190 | $text .= '<input type="hidden" name="referer" value="'.urldecode($query['referer']).'" />'; | |
191 | $text .= '<input type="hidden" id="cal" name="cal" value="" />'; | |
192 | $calendar = ''; | |
193 | foreach ($_SESSION['all_events'] as $name => $cal) { | |
194 | //$calendar .= "$name<br/>".var_export($cal, true)."<br/>"; | |
195 | $text .= $name.': <select name="etag" | |
196 | onchange="setCalendar(\'cals\', \'cal\', '."'$name'".')">'; | |
197 | $text .= '<option selected="selected"></option>'; | |
198 | foreach ($cal as $vevent) { | |
199 | $calendar .= $vevent->getEtag()."<br/>"; | |
200 | $text .= '<option value="'.$vevent->getEtag().'">'. | |
201 | $vevent->getDetails().'</option>'; | |
202 | } | |
203 | $text .= '</select><br/><br/>'; | |
204 | } | |
205 | $text .= '<input type="submit" value="Continue" />'; | |
206 | $text .= '</form></p>'; | |
207 | //print "{$_GET['referer']}"; | |
208 | //exit; | |
209 | print popup_window($text, $query['referer']); | |
210 | exit; | |
211 | } | |
212 | } | |
213 | include TOP_FOLDER.'/include/header.inc.php'; | |
214 | include TOP_FOLDER.'/include/menu.inc.php'; | |
215 | ||
216 | print "<div id=\"ui\">$calendar</div>"; | |
217 | include TOP_FOLDER.'/include/footer.inc.php'; | |
218 | ?> |