]> git.datanom.net - webcal.git/blame - utils/configure.php
Initial upload
[webcal.git] / utils / configure.php
CommitLineData
a5eae6b7
MR
1<?php
2/* $Id$ */
3require_once 'config.inc.php';
4require_once 'user_validate.php';
5require_once 'timezone.php';
6require_once 'helper.php';
7
8valid_user();
9
10if (! defined($_SESSION['__ROOT__']) && empty($_SESSION['__ROOT__'])) {
11 if (session_id())
12 session_destroy();
13 header('Location: ' . WEB_ROOT . 'error.html');
14 exit;
15}
16
17require_once 'persistens.php';
18
19$user = $_SESSION['user_settings'];
20
21if (count($_POST) > 0 && isset($_POST['action'])) {
22 $db = Persistens::getInstance(DBDRIVER);
23
24 if ($_POST['action'] == "password") {
25 if ($_POST['pwd1'] == $_POST['pwd2']) {
26 $res = $db->changePassword($user->getUid(), sha1($_POST['pwd1']));
27 if ($res === TRUE) {
28 header("Location: " . WEB_ROOT . "logout.php");
29 exit();
30 }
31 //else {
32 // $res = "uid: ".$user->getUid()." ".$_POST['pwd1']." ".$_POST['pwd2']." -> $res";
33 //}
34 }
35 else {
36 $res = "Passwords did not compare";
37 }
38 $pageView = "<p style=\"text-align: center\">$res</p>";
39 }
40 else if ($_POST['action'] == "settings") {
41 file_put_contents('/tmp/davical.log',
42 __FILE__ . ": " . var_export($_POST, TRUE), FILE_APPEND);
43 $conf = array();
44 if ($_POST['endDay'] > $_POST['startDay']) {
45 $conf['daystart'] = $_POST['startDay'];
46 $conf['dayend'] = $_POST['endDay'];
47 }
48 else {
49 $conf['daystart'] = $user->getStartHour();
50 $conf['dayend'] = $user->getEndHour();
51 }
52 $conf['timeout'] =
53 ($_POST['timeout'] > 0) ? $_POST['timeout'] * 60 :
54 $user->getTimeout() / 60;
55 $conf['userview'] = $_POST['viewStyle'];
56 $conf['weekstart'] = ($_POST['startWeek'] == 'SU') ? 1 : 0;
57 $conf['timezone'] = $_POST['timezone'];
58 $conf['userrole'] = $user->getRole();
59 $res = $db->setUserSettings($user->getUid(), $conf);
60 if ($res === TRUE) {
61 $user->setSettings(array($conf));
62 header("Location: " . $_SERVER['PHP_SELF']);
63 exit();
64 }
65 $pageView = "<p style=\"text-align: center\">$res</p>";
66 }
67}
68else {
69 $timeout = $user->getTimeout() / 60;
70 $viewStyle = $user->getViewStyle();
71 switch ($viewStyle) {
72 case 'day':
73 $viewStyle = <<<_SELECT
74 <select name="viewStyle">
75 <option value="day" selected="true">Day</option>
76 <option value="week">Week</option>
77 <option value="month">Month</option>
78 </select>
79_SELECT;
80 break;
81 case 'week':
82 $viewStyle = <<<_SELECT
83 <select name="viewStyle">
84 <option value="day">Day</option>
85 <option value="week" selected="true">Week</option>
86 <option value="month">Month</option>
87 </select>
88_SELECT;
89 break;
90 case 'month':
91 $viewStyle = <<<_SELECT
92 <select name="viewStyle">
93 <option value="day">Day</option>
94 <option value="week">Week</option>
95 <option value="month" selected="true">Month</option>
96 </select>
97_SELECT;
98 break;
99 }
100 $weekStart = $user->getStartWeek();
101 if ($weekStart)
102 $weekStart = <<<_SELECT
103 <select name="startWeek">
104 <option value="SU" selected="true">Sunday</option>
105 <option value="MO">Monday</option>
106 </select>
107_SELECT;
108 else
109 $weekStart = <<<_SELECT
110 <select name="startWeek">
111 <option value="SU">Sunday</option>
112 <option value="MO" selected="true">Monday</option>
113 </select>
114_SELECT;
115
116 $dayStart = (int) $user->getStartHour();
117 $start = '<select name="startDay">';
118 for ($i = 0; $i < 25; $i++) {
119 $hour = ($i < 10) ? "0$i:00" : "$i:00";
120 $start .= "<option value=\"$i\"";
121 if ($i == $dayStart)
122 $start .= " selected=\"true\"";
123 $start .= ">$hour</option>";
124 }
125 $start .= '</select>';
126 $dayEnd = (int) $user->getEndHour();
127 $end = '<select name="endDay">';
128 for ($i = 0; $i < 25; $i++) {
129 $hour = ($i < 10) ? "0$i:00" : "$i:00";
130 $end .= "<option value=\"$i\"";
131 if ($i == $dayEnd)
132 $end .= " selected=\"true\"";
133 $end .= ">$hour</option>";
134 }
135 $end .= '</select>';
136
137 $current = $user->getTimezone();
138 foreach ($timezones as $timezone) {
139 $tz .= "<option value=\"$timezone\"";
140 if ($current == $timezone)
141 $tz .= ' selected="true"';
142 $tz .= ">$timezone</option>";
143 }
144
145 $url = getServerUrl();
146 if ($url[strlen($url)-1] == '/')
147 $url = substr($url, 0, -1);
148
149 $pageView = <<< __EOF
150 <p>
151 <form action="{$_SERVER['PHP_SELF']}" method="post">
152 <table class="config">
153 <tr>
154 <th>Setting</th><th>Current</th>
155 </tr>
156 <tr>
157 <td class="config">Session timeout in minuts</td>
158 <td class="config">
159 <input size="6" name="timeout" type="text" value="$timeout"/>
160 </td>
161 </tr>
162 <tr>
163 <td class="config">Default view</td><td>$viewStyle</td>
164 </tr>
165 <tr>
166 <td class="config">Timezone</td>
167 <td class="config">
168 <select name="timezone">
169 $tz
170 </select>
171 </td>
172 </tr>
173 <tr>
174 <td class="config">Week start on</td><td>$weekStart</td>
175 </tr>
176 <tr>
177 <td class="config">Day start</td>
178 <td class="config">$start</td>
179 </tr>
180 <tr>
181 <td class="config">Day end</td>
182 <td class="config">$end</td>
183 </tr>
184 <tr>
185 <input type="hidden" name="action" value="settings"/>
186 <td class="config" colspan="2" style="text-align: center">
187 <input type="submit" name="setting" value="Submit changes"/>
188 </td>
189 </tr>
190 </table>
191 </form>
192 </p>
193__EOF;
194 if (strtoupper($user->getUid()) != 'ADMIN') {
195 $pageView .= <<< __EOF
196 <p style="text-align: center">
197 <button type="button" id="calconfig"
198 onclick="document.location.href='$url/utils/calendar.php'">
199 Configure Calendars
200 </button>
201 </p>
202__EOF;
203 }
204 if ($user->getRole() === 0) {
205 $pageView .= <<<__EOF
206 <p style="text-align: center">
207 <button type="button" id="useradm"
208 onclick="document.location.href='$url/utils/users.php'">
209 Manage users
210 </button>
211 &nbsp;&nbsp;
212 <button type="button" id="ldapadm"
213 onclick="document.location.href='$url/utils/ldap.php'">
214 Configure LDAP
215 </button>
216 </p>
217__EOF;
218 }
219 $pageView .= <<<__EOF
220 <p>
221 <form action="{$_SERVER['PHP_SELF']}" method="post">
222 <table class="config">
223 <tr>
224 <th colspan="2" style="text-align: center">Change password</th>
225 </tr>
226 <tr>
227 <td colspan="2"><span style="background: red; font-weight: bold;">
228 &nbsp;After changing the password a relogin is required&nbsp;
229 </span></td>
230 </tr>
231 <tr>
232 <td class="config">New Password</td>
233 <td class="config"><input name="pwd1" type="password"/></td>
234 </tr>
235 <tr>
236 <td class="config">Repeat Password</td>
237 <td class="config"><input name="pwd2" type="password"/></td>
238 </tr>
239 <tr>
240 <input type="hidden" name="action" value="password"/>
241 <td class="config" colspan="2" style="text-align: center">
242 <input type="submit" name="password" value="Submit"/>
243 </td>
244 </tr>
245 </table>
246 </form>
247 </p>
248__EOF;
249}
250
251include TOP_FOLDER.'/include/header.inc.php';
252include TOP_FOLDER.'/include/menu.inc.php';
253
254print "<div id=\"ui\">$pageView</div>";
255
256include TOP_FOLDER.'/include/footer.inc.php';
257?>
This page took 0.067133 seconds and 5 git commands to generate.