summaryrefslogtreecommitdiff
path: root/utils/user.php
diff options
context:
space:
mode:
Diffstat (limited to 'utils/user.php')
-rw-r--r--utils/user.php151
1 files changed, 151 insertions, 0 deletions
diff --git a/utils/user.php b/utils/user.php
new file mode 100644
index 0000000..508f83d
--- /dev/null
+++ b/utils/user.php
@@ -0,0 +1,151 @@
+<?php
+
+include_once("convert.php");
+
+class User {
+ public $userid;
+ public $password;
+ public $users;
+ public $news;
+ public $events;
+ public $guestbook;
+ public $gallery;
+ public $user;
+ public $newsletter;
+ public $pressrelease;
+
+ public function checkPassword($password) {
+ return $this->password == sha1(md5($password));
+ }
+
+ public function setPassword($oldpassword, $password1, $password2) {
+ if($this->checkPassword($oldpassword) == false) { // Doublecheck the validity of the user.
+ echo "<p>Current password is incorrect!</p>\n";
+ return 1;
+ }
+
+ if($password1 != $password2) { // Check if passowrds match.
+ echo "<p>Passwords do not match!</p>\n";
+ return 1;
+ }
+
+ echo "<p>Password updated successfully!</p>\n";
+
+ $this->password = sha1(md5($password1));
+ return 0;
+ }
+
+ public function User($userid, $password, $users, $news, $events, $guestbook, $gallery, $user, $newsletter, $pressrelease)
+ {
+ $this->userid = $userid;
+ $this->password = $password;
+ $this->users = $users;
+ $this->news = $news;
+ $this->events = $events;
+ $this->guestbook = $guestbook;
+ $this->gallery = $gallery;
+ $this->user = $user;
+ $this->newsletter = $newsletter;
+ $this->pressrelease = $pressrelease;
+ }
+}
+
+class Users {
+
+ private $file;
+ private $users = array();
+
+ public function add($user) {
+ $key = $user->userid;
+ $this->users[$key] = $user;
+ }
+
+ public function write()
+ {
+ $fp = fopen($this->file, "w");
+ fwrite($fp, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
+
+ fwrite($fp, "<users>\n");
+ foreach($this->users as $user) {
+ fwrite($fp, " <user userid=\"" .
+ htmlspecialchars($user->userid, ENT_QUOTES, "UTF-8") . "\"\n");
+ fwrite($fp, " password=\"" . $user->password . "\"\n");
+ fwrite($fp, " users=\"" . $user->users . "\"\n");
+ fwrite($fp, " news=\"" . $user->news . "\"\n");
+ fwrite($fp, " events=\"" . $user->events . "\"\n");
+ fwrite($fp, " guestbook=\"" . $user->guestbook . "\"\n");
+ fwrite($fp, " gallery=\"" . $user->gallery . "\"\n");
+ fwrite($fp, " user=\"" . $user->user . "\"\n");
+ fwrite($fp, " newsletter=\"" . $user->newsletter . "\"\n");
+ fwrite($fp, " pressrelease=\"" . $user->pressrelease . "\">\n");
+ fwrite($fp, " </user>\n");
+ }
+ fwrite($fp, "</users>\n");
+
+ fclose($fp);
+ }
+
+ public function deleteUser($userid)
+ {
+ if($userid != "admin") {
+ if($this->users[$userid]) {
+ unset($this->users[$userid]);
+ $this->write();
+ } else {
+ echo "<p>ERROR: User! <em>".$userid."</em> does not exist!</p>\n";
+ return false;
+ }
+ } else {
+ echo "<p>ERROR: You cannot delete the admin user!</p>\n";
+ return false;
+ }
+ return true;
+ }
+
+ public function findUser($userid)
+ {
+ $user = $this->users[$userid];
+ return $user;
+ }
+
+ public function useridList()
+ {
+ $useridlist = array();
+ foreach($this->users as $user) {
+ array_push($useridlist, $user->userid);
+ }
+ return $useridlist;
+ }
+
+ private function read()
+ {
+
+ $dom = new DomDocument;
+ $dom->preserveWhiteSpace = FALSE;
+ $dom->load($this->file);
+ $params = $dom->getElementsByTagName('user');
+
+ foreach ($params as $param) {
+ $user = new User($param->getAttribute('userid'),
+ $param->getAttribute('password'),
+ $param->getAttribute('users'),
+ $param->getAttribute('news'),
+ $param->getAttribute('events'),
+ $param->getAttribute('guestbook'),
+ $param->getAttribute('gallery'),
+ $param->getAttribute('user'),
+ $param->getAttribute('newsletter'),
+ $param->getAttribute('pressrelease'));
+ $this->add($user);
+ }
+
+ }
+
+ public function Users($file)
+ {
+ $this->file = $file;
+ $this->read();
+ }
+
+}
+?> \ No newline at end of file