summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordeva <deva>2010-02-28 10:20:09 +0000
committerdeva <deva>2010-02-28 10:20:09 +0000
commit8c69fd9b2e824114ee3cd0f6a7dcddc7e31d913c (patch)
tree5352520fe12cb1670d2d5f035483a172c467643b
parent5fac941e3295d4a094795aaf2f0e05c542879465 (diff)
Added users module. Made new password lineedit widget.
-rw-r--r--utils/forms.php50
-rw-r--r--utils/modules.php41
-rw-r--r--utils/modules/user.php16
-rw-r--r--utils/modules/users.php181
-rw-r--r--utils/user.php12
5 files changed, 276 insertions, 24 deletions
diff --git a/utils/forms.php b/utils/forms.php
index 45939e7..126d29f 100644
--- a/utils/forms.php
+++ b/utils/forms.php
@@ -19,6 +19,26 @@ class LineEdit {
}
}
+class LineEditPwd {
+ public $label, $name, $value;
+
+ function LineEditPwd($label, $name, $value = "")
+ {
+ $this->label = $label;
+ $this->name = $name;
+ $this->value = $value;
+ }
+
+ function render($indent = "")
+ {
+ $str = $indent . "<div class=\"input\">\n";
+ $str .= $indent . " <div class=\"label\">". $this->label ."</div>\n";
+ $str .= $indent . " <div class=\"widget\"><input name=\"vars[".$this->name."]\" value=\"".$this->value."\" type=\"password\"/></div>\n";
+ $str .= $indent . "</div>\n";
+ return $str;
+ }
+}
+
class FileUpload {
public $label, $name, $accept;
@@ -358,6 +378,36 @@ class ListEditor {
}
}
+class MultiList {
+ public $label, $name, $values;
+
+ function MultiList($label, $name, $values = "")
+ {
+ $this->label = $label;
+ $this->name = $name;
+ $this->values = $values;
+ }
+
+ function render($indent = "")
+ {
+ $str = $indent . "<div class=\"input\">\n";
+ $str .= $indent . " <div class=\"label\">". $this->label ."</div>\n";
+ $str .= $indent . " <div class=\"widget\">\n";
+ $str .= $indent . " <select multiple size=\"8\" id=\"items\" name=\"".$this->name."[]\">\n";
+ if(sizeof($this->values)) {
+ foreach($this->values as $value => $active) {
+ if($active == true) $sel = " selected=\"true\"";
+ else $sel = "";
+ $str .= $indent . " <option value=\"".$value."\"".$sel.">".$value."</option>\n";
+ }
+ }
+ $str .= $indent . " </select>\n";
+ $str .= $indent . " </div>\n";
+ $str .= $indent . "</div>\n";
+ return $str;
+ }
+}
+
class Form {
public $widgets = array();
public $action;
diff --git a/utils/modules.php b/utils/modules.php
index 2c4df69..0b72f08 100644
--- a/utils/modules.php
+++ b/utils/modules.php
@@ -2,6 +2,29 @@
$modules = array();
+function getModuleList()
+{
+ $mlist = array();
+
+ array_push($mlist, "config");
+ array_push($mlist, "discography");
+ array_push($mlist, "events");
+ array_push($mlist, "gallery");
+ array_push($mlist, "guestbook");
+ array_push($mlist, "icons");
+ array_push($mlist, "links");
+ array_push($mlist, "members");
+ array_push($mlist, "news");
+ array_push($mlist, "pages");
+ array_push($mlist, "downloads");
+ array_push($mlist, "newsletter");
+ array_push($mlist, "pressrelease");
+ array_push($mlist, "user");
+ array_push($mlist, "users");
+
+ return $mlist;
+}
+
function loadModule($modulename)
{
global $MODULES_DIR;
@@ -21,21 +44,9 @@ function loadModule($modulename)
function loadAllModules()
{
- loadModule("config");
- loadModule("discography");
- loadModule("events");
- loadModule("gallery");
- loadModule("guestbook");
- loadModule("icons");
- loadModule("links");
- loadModule("members");
- loadModule("news");
- loadModule("pages");
- loadModule("downloads");
- loadModule("newsletter");
- loadModule("pressrelease");
- loadModule("user");
- // loadModule("users");
+ foreach(getModuleList() as $m) {
+ loadModule($m);
+ }
}
function getModuleParams($code)
diff --git a/utils/modules/user.php b/utils/modules/user.php
index 5e9c23b..bd1ce37 100644
--- a/utils/modules/user.php
+++ b/utils/modules/user.php
@@ -18,16 +18,20 @@ class UserAdm {
switch($action) {
case "set":
$user = $this->users->findUser($UID);
- if($user &&
- $user->setPassword($vars['oldpwd'], $vars['newpwd'], $vars['rptpwd']) == 0) {
- $this->users->write();
+ if(!$user) return;
+ if($vars['oldpwd'] != "" &&
+ $vars['newpwd'] != "" &&
+ $vars['rptpwd'] != "") {
+ if($user->setPassword($vars['oldpwd'], $vars['newpwd'], $vars['rptpwd']) == 0) {
+ $this->users->write();
+ }
}
default:
$form = new Form("set");
- $form->addWidget(new LineEdit("Old password:", "oldpwd", ""));
- $form->addWidget(new LineEdit("New password:", "newpwd", ""));
- $form->addWidget(new LineEdit("Repeat password:", "rptpwd", ""));
+ $form->addWidget(new LineEditPwd("Old password:", "oldpwd", ""));
+ $form->addWidget(new LineEditPwd("New password:", "newpwd", ""));
+ $form->addWidget(new LineEditPwd("Repeat password:", "rptpwd", ""));
$form->addWidget(new Button("Update"));
$form->render();
break;
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
diff --git a/utils/user.php b/utils/user.php
index f189987..916c89a 100644
--- a/utils/user.php
+++ b/utils/user.php
@@ -17,7 +17,7 @@ class User {
return 1;
}
- if($password1 != $password2) { // Check if passowrds match.
+ if($password1 != $password2) { // Check if passwords match.
echo "<p>Passwords do not match!</p>\n";
return 1;
}
@@ -52,11 +52,17 @@ class Users {
private $file;
private $users = array();
- public function add($user) {
+ public function add($user)
+ {
$key = $user->userid;
$this->users[$key] = $user;
}
-
+
+ public function delete($user)
+ {
+ unset($this->users[$user]);
+ }
+
public function write()
{
$fp = fopen($this->file, "w");