\n"; $str .= "
Looking ok?
"; 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 "Looking ok?
"; 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": $this->admin_add($action, $vars); break; case "edit": $this->admin_edit($action, $vars); break; case "delete": $this->admin_delete($action, $vars); break; } } public function run($module) { global $show; switch($module) { case "news": default: if($show == "all") return $this->show(-1, "all"); else return $this->show(-1, "main"); break; } } public function show($number, $category) { $str = ""; // If number is -1 show all shows. if($number == -1) $number = 100000; foreach($this->news as $newsentry) { if($newsentry->category == $category || $category == "all") { $str .= $newsentry->show(); $number--; } if(!$number) return $str; } return $str; } public function add($newsentry) { $key = $newsentry->time; $this->news[$key] = $newsentry; } public function write() { $fp = fopen($this->file, "w"); fwrite($fp, "\n"); fwrite($fp, "