"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 "
ERROR: You cannot delete the 'admin' user.
"; 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"); } ?>