]> git.datanom.net - webcal.git/blame - utils/newuser.php
Initial upload
[webcal.git] / utils / newuser.php
CommitLineData
a5eae6b7
MR
1<?php
2/* $Id$ */
3require_once 'config.inc.php';
4require_once 'user_validate.php';
5require_once 'helper.php';
6
7valid_user();
8
9if (! defined($_SESSION['__ROOT__']) && empty($_SESSION['__ROOT__'])) {
10 if (session_id())
11 session_destroy();
12 header('Location: ' . WEB_ROOT . 'error.html');
13 exit;
14}
15
16if (! has_admin_role()) {
17 if (session_id())
18 session_destroy();
19 header('Location: ' . WEB_ROOT . 'error.html');
20 exit;
21}
22
23require_once 'persistens.php';
24
25include TOP_FOLDER.'/include/header.inc.php';
26include TOP_FOLDER.'/include/menu.inc.php';
27$self =$_SERVER['PHP_SELF'];
28$db = Persistens::getInstance(DBDRIVER);
29
30if (count($_POST) > 0 && isset($_POST['action'])) {
31
32 if (strtolower($_POST['action']) == 'add') {
33 if ($_POST['pwd1'] != $_POST['pwd2']) {
34 $result = "Password does not match";
35 }
36 else {
37 $data = create_user_data(
38 $_POST['uid'], $_POST['pwd1'], $_POST['role']);
39 $result = $db->newUser($data);
40 if ($result === TRUE) {
41 $name = $db->getRoleName((int) $_POST['role']);
42 $result = "{$_POST['uid']} with role: {$name['name']} added";
43 }
44 $result = nl2br($result);
45 }
46 }
47 $pageView .= <<<__EOF
48<p style="text-align: center">
49 $result
50</p>
51__EOF;
52}
53else {
54 $roles = $db->getRoles();
55 $select = '<select name="role">';
56 foreach ($roles as $role) {
57 $select .= "<option value=\"{$role['id']}\">{$role['name']}</option>";
58 }
59 $select .= "</select>";
60 $pageView .= <<<__EOF
61 <form action="$self" method="post" id="new_form">
62 <p>
63 <table class="config">
64 <tr>
65 <th colspan="2" style="text-align: center">New user</th>
66 </tr>
67 <tr>
68 <td class="config">Username</td>
69 <td class="config"><input name="uid" type="text"/></td>
70 </tr>
71 <tr>
72 <td class="config">User role</td>
73 <td class="config">$select</td>
74 </tr>
75 <tr>
76 <td class="config">Password</td>
77 <td class="config"><input name="pwd1" type="password"/></td>
78 </tr>
79 <tr>
80 <td class="config">Repeat Password</td>
81 <td class="config"><input name="pwd2" type="password"/></td>
82 </tr>
83 <tr>
84 <td class="config" colspan="2" style="text-align: center">
85 <input type="submit" name="action" value="Add"/>
86 </td>
87 </tr>
88 </table>
89 </p>
90 </form>
91__EOF;
92}
93
94print "<div id=\"ui\">$pageView</div>";
95
96include TOP_FOLDER.'/include/footer.inc.php';
97
98?>
This page took 0.039889 seconds and 5 git commands to generate.