Added user view page, updated repo view page, added ocmmit logs
[gwvp-mini.git] / gwvpmini / gwvpmini_admin.php
1 <?php
2
3 if(gwvpmini_isLoggedIn()) if(gwvpmini_isUserAdmin()) {
4         $MENU_ITEMS["20repos"]["text"] = "Administration";\r
5         $MENU_ITEMS["20repos"]["link"] = "$BASE_URL/admin";
6         $CALL_ME_FUNCTIONS["admin"] = "gwvpmini_AdminCallMe";
7 }
8
9 function gwvpmini_AdminCallMe()\r
10 {\r
11 \r
12         error_log("in admin callme");\r
13         if(isset($_REQUEST["q"])) {\r
14                 $query = $_REQUEST["q"];\r
15                 $qspl = explode("/", $query);\r
16                 if(isset($qspl[0])) {\r
17                         if($qspl[0] == "admin") {\r
18                                 if(isset($qspl[1])) {\r
19                                         if($qspl[1] == "user") {\r
20                                                 return "gwvpmini_AdminUserCreate";\r
21                                         }\r
22                                 } else {\r
23                                         error_log("i got here, where next?");\r
24                                         return "gwvpmini_AdminMainPage";\r
25                                 }\r
26                         } else return false;\r
27                 }\r
28                 else return false;\r
29         }\r
30 \r
31         return false;\r
32 }
33
34 function gwvpmini_AdminMainPage()
35 {
36         gwvpmini_goMainPage("gwvpmini_AdminMainPageBody");
37 }
38
39 function gwvpmini_AdminMainPageBody()
40 {
41         global $BASE_URL;
42         
43         $totalusers = gwvpmini_GetNUsers();
44         echo "<table><tr valign=\"top\"><td>";
45         echo "<h2>Users - $totalusers</h2>";
46         echo "<table border=\"1\">";
47         echo "<tr><th>Username</th><th>Email Address</th><th>Full Name</th><th>Description</th><th>Control</th></tr>";
48         foreach(gwvpmini_GetUsers() as $key => $val) {
49                 $id = $key;
50                 $un = $val["username"];
51                 $em = $val["email"];
52                 $fn = $val["fullname"];
53                 $ds = $val["desc"];
54                 echo "<tr><td>$un</td><td>$em</td><td>$fn</td><td>$ds</td><td><a href=\"$BASE_URL/admin/removeuser&id=$id\">Remove</a> <a href=\"$BASE_URL/admin/disableuser&id=$id\">Disable</a></td></tr>";
55         }
56         echo "</table>";
57         echo "</td><td>";
58         echo "<h3>Create User</h3>";
59         echo "<form method=\"post\" action=\"$BASE_URL/admin/user/create\">";
60         echo "<table border=\"1\">";\r
61         echo "<tr><th>Username</th><td><input type=\"text\" name=\"username\"></td></tr>";
62         echo "<tr><th>Password</th><td><input type=\"text\" name=\"password\"></td></tr>";
63         echo "<tr><th>Confirm Password</th><td><input type=\"text\" name=\"confpassword\"></td></tr>";
64         echo "<tr><th>Full Name</th><td><input type=\"text\" name=\"fullname\"></td></tr>";
65         echo "<tr><th>Description</th><td><input type=\"text\" name=\"desc\"></td></tr>";
66         echo "<tr><th>Email</th><td><input type=\"text\" name=\"email\"></td></tr>";
67         echo "<tr><th>Confirm Email</th><td><input type=\"text\" name=\"confemail\"></td></tr>";
68         echo "<tr><th>Admin?</th><td><input type=\"checkbox\" name=\"isadmin\"></td></tr>";
69         echo "<tr><td colspan=\"2\"><input type=\"submit\" name=\"Add\" value=\"Add\"></td></tr>";
70         echo "</table>";
71         echo "</form>";
72         echo "</td></tr></table>";
73         
74         $totalrepos = gwvpmini_GetNRepos();
75         echo "<h2>Repo's - $totalrepos</h2>";
76         echo "<table border=\"1\">";
77         echo "<tr><th>Repo Name</th><th>Repo Desc</th><th>Owner</th><th>Control</th></tr>";
78         foreach(gwvpmini_GetRepos() as $key => $val) {
79                 $id = $key;
80                 $rn = $val["name"];
81                 $ds = $val["desc"];
82                 $ow = $val["owner"];
83                 echo "<tr><td><a href=\"$BASE_URL/view/$rn\">$rn</a></td><td>$ds</td><td>$ow</td><td><a href=\"$BASE_URL/admin/removeuser&id=$id\">Remove</a> <a href=\"$BASE_URL/admin/disableuser&id=$id\">Disable</a></td></tr>";
84         }
85         echo "</table>";
86 }\r
87
88
89 function gwvpmini_AdminUserCreate()
90 {
91         global $BASE_URL;
92         
93         $name = $_REQUEST["username"];
94         $pass1 = $_REQUEST["password"];
95         $pass2 = $_REQUEST["confpassword"];\r
96         $fname = $_REQUEST["fullname"];
97         $desc = $_REQUEST["desc"];
98         $email1 = $_REQUEST["email"];\r
99         $email2 = $_REQUEST["confemail"];
100         if(isset($_REQUEST["isadmin"])) $level = 1;
101         else $level = 0;\r
102         
103         $id = gwvpmini_GetUserId($name);
104         
105         if(!$id) {
106                 if($pass1 != $pass2) {
107                         gwvpmini_SendMessage("error", "Passwords dont match");
108                         header("Location: $BASE_URL/admin");
109                         return;
110                 }
111                 if($email1 != $email2) {
112                         gwvpmini_SendMessage("error", "Email Addresses dont match");
113                         header("Location: $BASE_URL/admin");
114                         return;
115                 }
116                 
117                 gwvpmini_AddUser($name, $pass1, $fname, $email1, $desc, $level, 0);
118                 gwvpmini_SendMessage("info", "User $fname created");
119         } else {
120                 gwvpmini_SendMessage("error", "User $name already exists, cant create");
121         }
122         
123         header("Location: $BASE_URL/admin");
124         return;
125         
126 }
127 ?>