summaryrefslogtreecommitdiff
path: root/utils/modules/users.php
diff options
context:
space:
mode:
Diffstat (limited to 'utils/modules/users.php')
-rw-r--r--utils/modules/users.php181
1 files changed, 181 insertions, 0 deletions
diff --git a/utils/modules/users.php b/utils/modules/users.php
new file mode 100644
index 0000000..7e6fcd9
--- /dev/null
+++ b/utils/modules/users.php
@@ -0,0 +1,181 @@
+<?php /* -*- Mode: php; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+
+global $UTIL_DIR;
+
+include_once($UTIL_DIR . "/user.php");
+
+class UsersAdm {
+ public $users;
+
+ // Admin config
+ public $admin_title = "Users";
+ public $admin_submodules = array("Add user" => "add",
+ "Edit user" => "edit",
+ "Delete user" => "delete");
+
+ public function admin_add($action, $vars)
+ {
+ global $UID, $GLOBALS;
+
+ switch($action) {
+ case "add":
+ $modulesel = $GLOBALS["modulesel"];
+
+ $modstr = "";
+ foreach($modulesel as $m) {
+ if($modstr != "") $modstr .= " ";
+ $modstr .= $m;
+ }
+
+ $all = true;
+ foreach(getModuleList() as $m) {
+ if(in_array($m, $modulesel) == false) $all = false;
+ }
+
+ if($all == true) $modstr = "*";
+
+ $pwd = sha1(md5($vars["password"]));
+ $user = new User($vars["username"], $pwd, $modstr);
+ $this->users->add($user);
+ $this->users->write();
+ break;
+
+ default:
+ $modules = array();
+ foreach(getModuleList() as $m) {
+ $modules[$m] = false;
+ }
+ $form = new Form("add");
+ $form->addWidget(new LineEdit("Username:", "username", ""));
+ $form->addWidget(new LineEditPwd("Password:", "password", ""));
+ $form->addWidget(new MultiList("Modules:", "modulesel",
+ $modules));
+ $form->addWidget(new Button("Add"));
+ $form->render();
+ break;
+ }
+ }
+
+ public function admin_edit($action, $vars)
+ {
+ global $UID, $GLOBALS;
+
+ switch($action) {
+ case "write":
+ $modulesel = $GLOBALS["modulesel"];
+
+ $modstr = "";
+ foreach($modulesel as $m) {
+ if($modstr != "") $modstr .= " ";
+ $modstr .= $m;
+ }
+
+ $all = true;
+ foreach(getModuleList() as $m) {
+ if(in_array($m, $modulesel) == false) $all = false;
+ }
+
+ if($all == true) $modstr = "*";
+
+ $user = $this->users->findUser($vars["edtuser"]);
+
+ if($vars["password"] != "") {
+ $pwd = sha1(md5($vars["password"]));
+ $user->password = $pwd;
+ }
+ $user->modules = $modstr;
+ $this->users->write();
+ break;
+
+ case "edit":
+
+ $user = $this->users->findUser($vars["edtuser"]);
+
+ $modules = array();
+ foreach(getModuleList() as $m) {
+ $modules[$m] = $user->checkModule($m);
+ }
+ $form = new Form("write");
+ $form->addWidget(new Hidden(array("edtuser" => $user->userid)));
+ $form->addWidget(new LineEditPwd("Password:", "password", ""));
+ $form->addWidget(new MultiList("Modules:", "modulesel",
+ $modules));
+ $form->addWidget(new Button("Edit"));
+ $form->render();
+ break;
+
+ default:
+ $userlist = array();
+
+ foreach($this->users->useridList() as $u) {
+ $userlist[$u] = $u;
+ }
+
+ $form = new Form("edit");
+ $form->addWidget(new ComboBox("Select user to edit:", "edtuser", "",
+ $userlist));
+ $form->addWidget(new Button("Edit..."));
+ $form->render();
+ break;
+ }
+ }
+
+ public function admin_delete($action, $vars)
+ {
+ global $UID, $GLOBALS;
+
+ switch($action) {
+ case "delete":
+ if($vars["deluser"] == "admin") {
+ echo "<p>ERROR: You cannot delete the 'admin' user.</p>";
+ return;
+ }
+ $this->users->delete($vars["deluser"]);
+ $this->users->write();
+ break;
+
+ default:
+ $userlist = array();
+
+ foreach($this->users->useridList() as $u) {
+ $userlist[$u] = $u;
+ }
+
+ $form = new Form("delete");
+ $form->addWidget(new ComboBox("Select user to delete:", "deluser", "",
+ $userlist));
+ $form->addWidget(new Button("Delete"));
+ $form->render();
+ break;
+ }
+ }
+
+ public function admin($sub, $action, $vars)
+ {
+ switch($sub) {
+ case "add":
+ $this->admin_add($action, $vars);
+ break;
+ case "edit":
+ $this->admin_edit($action, $vars);
+ break;
+ case "delete":
+ $this->admin_delete($action, $vars);
+ break;
+ }
+ }
+
+
+ public function UsersAdm($file)
+ {
+ $this->users = new Users($file);
+ }
+}
+
+function users_init()
+{
+ global $DATA_DIR;
+ return new UserSAdm($DATA_DIR . "/users.xml");
+}
+
+?> \ No newline at end of file