description)); $icons = new Icons($ICONS_DIR."/"); $icon = $icons->icons[$this->icon]; $str = "
Looking ok?
"; $form = new Form("add"); $form->addWidget(new Hidden($vars)); $form->addWidget(new Button("yes")); $form->render(); $form = new Form("retry"); $form->addWidget(new Hidden($vars)); $form->addWidget(new Button("no")); $form->render(); break; case "retry": $title = $vars["title"]; $time = DateTimeEdit::toTimestamp($vars, "time"); $category = $vars["category"]; $description = $vars["description"]; default: $form = new Form("preview"); $form->addWidget(new LineEdit("Title", "title", $title)); $form->addWidget(new DateTimeEdit("Time", "time", $time)); $form->addWidget(new ComboBox("Category", "category", $category, array("Main" => "main", "Site" => "site"))); $form->addWidget(new TextEdit("Description", "description", $description)); $form->addWidget(new ImageComboBox("Icon", "icon", $icon, new Icons($ICONS_DIR."/"))); $form->addWidget(new Button("Post news")); $form->render(); break; } } public function admin_edit($action, $vars) { global $UID, $ICONS_DIR; switch($action) { case "add": $this->news[$vars["newsid"]]->title = $vars["title"]; $this->news[$vars["newsid"]]->userid = $UID; $this->news[$vars["newsid"]]->time = DateTimeEdit::toTimestamp($vars, "time"); $this->news[$vars["newsid"]]->category = $vars["category"]; $this->news[$vars["newsid"]]->description = $vars["description"]; $this->news[$vars["newsid"]]->icon = $vars["icon"]; $this->write(); echo "\"" . $this->news[$vars["newsid"]]->title . "\" has now been edited."; break; case "preview": $n = new NewsEntry($vars["title"], DatetimeEdit::toTimestamp($vars, "time"), $vars["category"], $vars["description"], $UID, $vars["icon"]); echo "Looking ok?
"; $form = new Form("add"); $form->addWidget(new Hidden($vars)); $form->addWidget(new Button("yes")); $form->render(); $form = new Form("retry"); $form->addWidget(new Hidden($vars)); $form->addWidget(new Button("no")); $form->render(); 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 = DateTimeEdit::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; if(isset($vars["icon"])) $icon = $vars["icon"]; else $icon = $this->news[$vars["newsid"]]->icon; $form = new Form("preview"); $form->addWidget(new Hidden($vars)); $form->addWidget(new LineEdit("Title", "title", $title)); $form->addWidget(new DateTimeEdit("Time", "time", $time)); $form->addWidget(new ComboBox("Category", "category", $category, array("Main" => "main", "Site" => "site"))); $form->addWidget(new TextEdit("Description", "description", $description)); $form->addWidget(new ImageComboBox("Icon", "icon", $icon, new Icons($ICONS_DIR."/"))); $form->addWidget(new Button("Post news")); $form->render(); break; case "select": default: $newslist = array(); foreach($this->news as $newsentry) { $newslist[$newsentry->title] = $newsentry->time; } $form = new Form("edit"); $form->addWidget(new ComboBox("Edit this entry:", "newsid", "", $newslist)); $form->addWidget(new Button("Edit...")); $form->render(); break; } } public function admin_delete($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 . "?"; $form = new Form("delete"); $form->addWidget(new Hidden($vars)); $form->addWidget(new Button("yes")); $form->render(); $form = new Form("select"); $form->addWidget(new Hidden($vars)); $form->addWidget(new Button("no")); $form->render(); break; case "select": default: $newslist = array(); foreach($this->news as $newsentry) { $newslist[$newsentry->title] = $newsentry->time; } $form = new Form("confirm"); $form->addWidget(new ComboBox("Delete this entry:", "newsid", "", $newslist)); $form->addWidget(new Button("Delete...")); $form->render(); 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($params) { $str = ""; $module = "all"; $number = -1; foreach($params as $param => $value) { switch($param) { case "show": $module = $value; break; case "number": $number = $value; break; case "all": default: $module = "all"; $number = -1; break; } } $str .= $this->show($number, $module); return $str; } 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, "