diff options
author | deva <deva> | 2009-04-13 10:03:03 +0000 |
---|---|---|
committer | deva <deva> | 2009-04-13 10:03:03 +0000 |
commit | 6ed9c968c48e68e1178e96e79fae146a774cceae (patch) | |
tree | 75797972a74ddba61281af03862a58f75eb2a66f | |
parent | 7c460e093563325279e2b122e0670f4f685b65f3 (diff) |
Finished add/edit/delete admin functions.
-rw-r--r-- | utils/modules/news.php | 196 |
1 files changed, 154 insertions, 42 deletions
diff --git a/utils/modules/news.php b/utils/modules/news.php index 2505ffb..6137049 100644 --- a/utils/modules/news.php +++ b/utils/modules/news.php @@ -21,6 +21,11 @@ class NewsEntry { return $str; } + public function __toString() + { + return $this->title; + } + public function NewsEntry($title, $time, $category, $description) { $this->title = $title; @@ -41,57 +46,164 @@ class News { "Edit Newsentry" => "edit", "Delete Newsentry" => "delete"); + + public function admin_add($action, $vars) + { + switch($action) { + case "add": + $n = new NewsEntry($vars["title"], totimestamp($vars, "time"), $vars["category"], $vars["description"]); + $this->add($n); + $this->write(); + break; + + case "preview": + $n = new NewsEntry($vars["title"], totimestamp($vars, "time"), $vars["category"], $vars["description"]); + echo "<div class=\"preview\">\n"; + echo "<div class=\"content\">\n"; + echo $n->show(); + echo "</div>\n"; + echo "</div>\n"; + echo "<p>Looking ok?</p>"; + beginform("add"); + hidden($vars); + button("yes"); + endform(); + beginform("retry"); + hidden($vars); + button("no"); + endform(); + break; + + case "retry": + $title = $vars["title"]; + $time = totimestamp($vars, "time"); + $category = $vars["category"]; + $description = $vars["description"]; + default: + beginform("preview"); + lineedit("Title", "title", $title); + datetimeedit("Time", "time", $time); + combobox("Category", "category", $category, array("Main" => "main", "Site" => "site")); + textedit("Description", "description", $description); + button("Post news"); + endform(); + break; + } + } + + public function admin_edit($action, $vars) + { + switch($action) { + case "add": + $this->news[$vars["newsid"]]->title = $vars["title"]; + $this->news[$vars["newsid"]]->time = totimestamp($vars, "time"); + $this->news[$vars["newsid"]]->category = $vars["category"]; + $this->news[$vars["newsid"]]->description = $vars["description"]; + $this->write(); + echo "\"" . $this->news[$vars["newsid"]]->title . "\" has now been edited."; + break; + + case "preview": + $n = new NewsEntry($vars["title"], totimestamp($vars, "time"), $vars["category"], $vars["description"]); + echo "<div class=\"preview\">\n"; + echo "<div class=\"content\">\n"; + echo $n->show(); + echo "</div>\n"; + echo "</div>\n"; + echo "<p>Looking ok?</p>"; + beginform("add"); + hidden($vars); + button("yes"); + endform(); + beginform("retry"); + hidden($vars); + button("no"); + endform(); + break; + + case "edit": + case "retry": + if(isset($vars["title"])) $title = $vars["title"]; + else $title = $this->news[$vars["newsid"]]->title; + if(isset($vars["time_year"])) $time = totimestamp($vars, "time"); + else $time = $this->news[$vars["newsid"]]->time; + if(isset($vars["category"])) $category = $vars["category"]; + else $category = $this->news[$vars["newsid"]]->category; + if(isset($vars["description"])) $description = $vars["description"]; + else $description = $this->news[$vars["newsid"]]->description; + + beginform("preview"); + hidden($vars); + lineedit("Title", "title", $title); + datetimeedit("Time", "time", $time); + combobox("Category", "category", $category, array("Main" => "main", "Site" => "site")); + textedit("Description", "description", $description); + button("Post news"); + endform(); + break; + + case "select": + default: + $newslist = array(); + foreach($this->news as $newsentry) { + $newslist[$newsentry->title] = $newsentry->time; + } + beginform("edit"); + combobox("Edit this entry:", "newsid", "", $newslist); + button("Edit..."); + endform(); + break; + } + } + + public function admin_delete($sub, $action, $vars) + { + switch($action) { + case "delete": + echo $this->news[$vars["newsid"]]->title . " has now been deleted."; + unset($this->news[$vars["newsid"]]); + $this->write(); + break; + + case "confirm": + echo "Really delete: " . $this->news[$vars["newsid"]]->title . "?"; + beginform("delete"); + hidden($vars); + button("yes"); + endform(); + beginform("select"); + hidden($vars); + button("no"); + endform(); + break; + + case "select": + default: + $newslist = array(); + foreach($this->news as $newsentry) { + $newslist[$newsentry->title] = $newsentry->time; + } + beginform("confirm"); + combobox("Delete this entry:", "newsid", "", $newslist); + button("Delete..."); + endform(); + break; + } + } + public function admin($sub, $action, $vars) { switch($sub) { case "new": - switch($action) { - case "add": - $n = new NewsEntry($vars["title"], totimestamp($vars, "time"), $vars["category"], $vars["description"]); - $this->add($n); - $this->write(); - break; - - case "preview": - $n = new NewsEntry($vars["title"], totimestamp($vars, "time"), $vars["category"], $vars["description"]); - echo "<div class=\"preview\">\n"; - echo "<div class=\"content\">\n"; - echo $n->show(); - echo "</div>\n"; - echo "</div>\n"; - echo "<p>Looking ok?</p>"; - beginform("add"); - hidden($vars); - button("yes"); - endform(); - beginform("retry"); - hidden($vars); - button("no"); - endform(); - break; - - case "retry": - $title = $vars["title"]; - $time = totimestamp($vars, "time"); - $category = $vars["category"]; - $description = $vars["description"]; - default: - beginform("preview"); - lineedit("Title", "title", $title); - datetimeedit("Time", "time", $time); - combobox("Category", "category", $category, array("Main" => "main", "Site" => "site")); - textedit("Description", "description", $description); - button("Post news"); - endform(); - break; - } + $this->admin_add($action, $vars); break; case "edit": - echo "Edit"; + $this->admin_edit($action, $vars); break; + case "delete": - echo "Delete"; + $this->admin_delete($action, $vars); break; } } |