From bd9e96a0c94d263b734720a9e3e35d4d1e872de3 Mon Sep 17 00:00:00 2001 From: deva Date: Sat, 11 Oct 2008 18:07:19 +0000 Subject: Added 'add forum' functionality when logged in as admin. --- forum/utils/forums.php | 49 +++++++++++-------------------------------------- forum/utils/view.php | 18 ++++++++++++++++++ 2 files changed, 29 insertions(+), 38 deletions(-) diff --git a/forum/utils/forums.php b/forum/utils/forums.php index 9305623..85e977b 100644 --- a/forum/utils/forums.php +++ b/forum/utils/forums.php @@ -6,8 +6,6 @@ include_once($UTIL_DIR . "/threads.php"); class Forum { public $fid; - public $readlist; - public $writelist; public $name; private $newStuff; @@ -25,11 +23,9 @@ class Forum { echo ""; } - public function Forum($fid, $readlist, $writelist, $name) + public function Forum($fid, $name) { $this->fid = $fid; - $this->readlist = $readlist; - $this->writelist = $writelist; $this->name = $name; } } @@ -40,13 +36,16 @@ class Forums { public $forums = array(); public function add($forum) { + global $FORUMS_DIR; + if(!file_exists($FORUMS_DIR . "/". $forum->fid)) { + mkdir($FORUMS_DIR . "/". $forum->fid); + } $key = $forum->fid; $this->forums[$key] = $forum; } public function write() { - /* $fp = fopen($this->file, "w"); $block = TRUE; @@ -54,39 +53,15 @@ class Forums { fwrite($fp, "\n"); - fwrite($fp, "\n"); - foreach($this->members as $member) { - fwrite($fp, " id, ENT_QUOTES, "UTF-8") . "\"\n"); - fwrite($fp, " name=\"" . - htmlspecialchars($member->name, ENT_QUOTES, "UTF-8") . "\"\n"); - fwrite($fp, " description=\"" . - htmlspecialchars($member->description, ENT_QUOTES, "UTF-8") . "\"\n"); - fwrite($fp, " image=\"" . - htmlspecialchars($member->image, ENT_QUOTES, "UTF-8") . "\">\n"); - - - fwrite($fp, " \n"); + fwrite($fp, "\n"); + foreach($this->forums as $forum) { + fwrite($fp, " fid . "\"\n"); + fwrite($fp, " name=\"" . htmlspecialchars($forum->name, ENT_QUOTES, "UTF-8") . "\"/>\n"); } - fwrite($fp, "\n"); + fwrite($fp, "\n"); fclose($fp); - */ - } - - /* - public function deleteForumUser($id) - { - if($this->members[$id]) { - unset($this->members[$id]); - // $this->write(); - } else { - echo "

ERROR: User! ".$id." does not exist!

\n"; - return false; - } - return true; } - */ public function getForum($fid) { @@ -112,8 +87,6 @@ class Forums { foreach($forums as $f) { $forum = new Forum($f->getAttribute('fid'), - $f->getAttribute('readlist'), - $f->getAttribute('writelist'), $f->getAttribute('name')); $this->add($forum); @@ -126,7 +99,7 @@ class Forums { public function Forums($file) { $this->file = $file; - $this->read(); + if(file_exists($file)) $this->read(); } } diff --git a/forum/utils/view.php b/forum/utils/view.php index 0adb1a0..01e8b6a 100644 --- a/forum/utils/view.php +++ b/forum/utils/view.php @@ -23,6 +23,24 @@ echo "\n"; echo "

Forums

"; include_once("forums.php"); $forums = new Forums($FORUMS_DIR . "/forums.xml"); + + if($action == "addforum") { + $newfid = 0; + while($forums->getForum($newfid)) $newfid++; + + $forums->add(new Forum($newfid, $title)); + $forums->write(); + } + $forums->show(); + + if($current_user->uid == 0) { +?> +
+Add new forum: +
+ \ No newline at end of file -- cgit v1.2.3