user add/remove
[gwvp-mini.git] / gwvpmini / gwvpmini_admin.php
index f1ad347..fcd6fa2 100644 (file)
@@ -16,8 +16,8 @@ function gwvpmini_AdminCallMe()
                if(isset($qspl[0])) {\r
                        if($qspl[0] == "admin") {\r
                                if(isset($qspl[1])) {\r
-                                       if($qspl[1] == "create") {\r
-                                               return "gwvpmini_RepoCreate";\r
+                                       if($qspl[1] == "user") {\r
+                                               return "gwvpmini_AdminUserCreate";\r
                                        }\r
                                } else {\r
                                        error_log("i got here, where next?");\r
@@ -41,6 +41,7 @@ function gwvpmini_AdminMainPageBody()
        global $BASE_URL;
        
        $totalusers = gwvpmini_GetNUsers();
+       echo "<table><tr valign=\"top\"><td>";
        echo "<h2>Users - $totalusers</h2>";
        echo "<table border=\"1\">";
        echo "<tr><th>Username</th><th>Email Address</th><th>Full Name</th><th>Description</th><th>Control</th></tr>";
@@ -53,6 +54,22 @@ function gwvpmini_AdminMainPageBody()
                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>";
        }
        echo "</table>";
+       echo "</td><td>";
+       echo "<h3>Create User</h3>";
+       echo "<form method=\"post\" action=\"$BASE_URL/admin/user/create\">";
+       echo "<table border=\"1\">";\r
+       echo "<tr><th>Username</th><td><input type=\"text\" name=\"username\"></td></tr>";
+       echo "<tr><th>Password</th><td><input type=\"text\" name=\"password\"></td></tr>";
+       echo "<tr><th>Confirm Password</th><td><input type=\"text\" name=\"confpassword\"></td></tr>";
+       echo "<tr><th>Full Name</th><td><input type=\"text\" name=\"fullname\"></td></tr>";
+       echo "<tr><th>Description</th><td><input type=\"text\" name=\"desc\"></td></tr>";
+       echo "<tr><th>Email</th><td><input type=\"text\" name=\"email\"></td></tr>";
+       echo "<tr><th>Confirm Email</th><td><input type=\"text\" name=\"confemail\"></td></tr>";
+       echo "<tr><th>Admin?</th><td><input type=\"checkbox\" name=\"isadmin\"></td></tr>";
+       echo "<tr><td colspan=\"2\"><input type=\"submit\" name=\"Add\" value=\"Add\"></td></tr>";
+       echo "</table>";
+       echo "</form>";
+       echo "</td></tr></table>";
        
        $totalrepos = gwvpmini_GetNRepos();
        echo "<h2>Repo's - $totalrepos</h2>";
@@ -68,4 +85,43 @@ function gwvpmini_AdminMainPageBody()
        echo "</table>";
 }\r
 
+
+function gwvpmini_AdminUserCreate()
+{
+       global $BASE_URL;
+       
+       $name = $_REQUEST["username"];
+       $pass1 = $_REQUEST["password"];
+       $pass2 = $_REQUEST["confpassword"];\r
+       $fname = $_REQUEST["fullname"];
+       $desc = $_REQUEST["desc"];
+       $email1 = $_REQUEST["email"];\r
+       $email2 = $_REQUEST["confemail"];
+       if(isset($_REQUEST["isadmin"])) $level = 1;
+       else $level = 0;\r
+       
+       $id = gwvpmini_GetUserId($name);
+       
+       if(!$id) {
+               if($pass1 != $pass2) {
+                       gwvpmini_SendMessage("error", "Passwords dont match");
+                       header("Location: $BASE_URL/admin");
+                       return;
+               }
+               if($email1 != $email2) {
+                       gwvpmini_SendMessage("error", "Email Addresses dont match");
+                       header("Location: $BASE_URL/admin");
+                       return;
+               }
+               
+               gwvpmini_AddUser($name, $pass1, $fname, $email1, $desc, $level, 0);
+               gwvpmini_SendMessage("info", "User $fname created");
+       } else {
+               gwvpmini_SendMessage("error", "User $name already exists, cant create");
+       }
+       
+       header("Location: $BASE_URL/admin");
+       return;
+       
+}
 ?>
\ No newline at end of file