title, ENT_QUOTES, "UTF-8") . "\"\n"); fwrite($fp, " time=\"" . $this->time . "\"\n"); fwrite($fp, " description=\"" . htmlspecialchars($this->description, ENT_QUOTES, "UTF-8") . "\"\n"); fwrite($fp, " flyer=\"" . $this->flyer . "\">\n"); fwrite($fp, " \n"); } public function show() { global $ICONS_DIR; $icons = new Icons($ICONS_DIR."/"); $icon = $icons->icons[$this->flyer]; $content = Markdown(htmlspecialchars_decode($this->description)); $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"); $description = $vars["description"]; $flyer = $vars["icon"]; default: $form = new Form("preview"); $form->addWidget(new LineEdit("Title", "title", $title)); $form->addWidget(new DateTimeEdit("Time", "time", $time)); $form->addWidget(new TextEdit("Description", "description", $description)); $form->addWidget(new ImageComboBox("Icon", "icon", $icon, new Icons($ICONS_DIR."/"))); $form->addWidget(new Button("Add event")); $form->render(); break; } } public function admin_edit($action, $vars) { global $ICONS_DIR; switch($action) { case "add": $this->events[$vars["eventid"]]->title = $vars["title"]; $this->events[$vars["eventid"]]->time = DateTimeEdit::toTimestamp($vars, "time"); $this->events[$vars["eventid"]]->description = $vars["description"]; $this->events[$vars["eventid"]]->flyer = $vars["icon"]; $this->write(); echo "\"" . $this->events[$vars["eventid"]]->title . "\" has now been edited."; break; case "preview": $event = new Event($vars["title"], DatetimeEdit::toTimestamp($vars, "time"), $vars["description"], $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->events[$vars["eventid"]]->title; if(isset($vars["time_year"])) $time = DateTimeEdit::toTimestamp($vars, "time"); else $time = $this->events[$vars["eventid"]]->time; if(isset($vars["description"])) $description = $vars["description"]; else $description = $this->events[$vars["eventid"]]->description; if(isset($vars["icon"])) $icon = $vars["icon"]; else $icon = $this->events[$vars["eventid"]]->flyer; $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 TextEdit("Description", "description", $description)); $form->addWidget(new ImageComboBox("Icon", "icon", $icon, new Icons($ICONS_DIR."/"))); $form->addWidget(new Button("Update event")); $form->render(); break; case "select": default: $eventlist = array(); foreach($this->events as $event) { $eventlist[$event->title] = $event->time; } $form = new Form("edit"); $form->addWidget(new ComboBox("Edit this event:", "eventid", "", $eventlist)); $form->addWidget(new Button("Edit...")); $form->render(); break; } } public function admin_delete($action, $vars) { switch($action) { case "delete": echo "\"". $this->events[$vars["eventid"]]->title . "\" has now been deleted."; unset($this->events[$vars["eventid"]]); $this->write(); break; case "confirm": echo "Really delete: " . $this->events[$vars["eventid"]]->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: $eventlist = array(); foreach($this->events as $event) { $eventlist[$event->title] = $event->time; } $form = new Form("confirm"); $form->addWidget(new ComboBox("Delete this event:", "eventid", "", $eventlist)); $form->addWidget(new Button("Delete...")); $form->render(); break; } } public function admin($sub, $action, $vars) { switch($sub) { case "add": $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) { foreach($params as $param) { switch($param) { case "coming": return $this->showcoming(-1); break; case "all": return $this->showall(-1); break; case "old": default: return $this->showold(-1); break; } } } public function showall($number) { $str = ""; $foundany = false; // Key sort ksort($this->events); // If number is -1 show all shows. if($number == -1) $number = 100000; foreach($this->events as $event) { $foundany = true; $str .= $event->show(); $number--; if(!$number) return $str; } if($foundany == false) return "No shows available at the moment."; return $str; } public function showcoming($number) { $str = ""; $foundany = false; // Key sort ksort($this->events); // If number is -1 show all shows. if($number == -1) $number = 100000; foreach($this->events as $event) { if($event->time >= time()) { $foundany = true; $str .= $event->show(); $number--; } if(!$number) return $str; } if($foundany == false) return "No shows available at the moment."; return $str; } public function showold($number) { $str = ""; // Key sort krsort($this->events); // If number is -1 show all shows. if($number == -1) $number = 100000; foreach($this->events as $event) { if($event->time <= time()) { $str .= $event->show(); $number--; } if(!$number) return $str; } return $str; } public function add($event) { $key = $event->time; // array_push($this->events, $event); $this->events[$key] = $event; } public function write() { $fp = fopen($this->file, "w"); fwrite($fp, "\n"); fwrite($fp, "