summaryrefslogtreecommitdiff
path: root/utils/modules
diff options
context:
space:
mode:
Diffstat (limited to 'utils/modules')
-rw-r--r--utils/modules/events.php214
1 files changed, 191 insertions, 23 deletions
diff --git a/utils/modules/events.php b/utils/modules/events.php
index bdbe43e..f14622e 100644
--- a/utils/modules/events.php
+++ b/utils/modules/events.php
@@ -1,4 +1,6 @@
<?php
+/* -*- Mode: php; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+
include_once($UTIL_DIR . "/convert.php");
class Event {
@@ -7,21 +9,36 @@ class Event {
public $description;
public $flyer;
- public function show()
- {
- $str = "<div class=\"event\">\n";
- $str .= " <div class=\"event_title\">" .
- htmlspecialchars_decode($this->title, ENT_QUOTES) . "</div>\n";
- $str .= " <div class=\"event_time\">" . date("D M jS Y", $this->time) . "</div>\n";
- $str .= " <div class=\"event_description\">" .
- htmlspecialchars_decode($this->description, ENT_QUOTES) . "</div>\n";
- if($this->flyer) {
- $str .= " <img class=\"event_flyer\" alt=\"flyer\" src=\"gfx/flyers/" . $this->flyer . "\"/>\n";
+ public function write($fp)
+ {
+ fwrite($fp, " <event title=\"" .
+ htmlspecialchars($this->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, " </event>\n");
+ }
+
+ public function show()
+ {
+ global $ICONS_DIR;
+ $icons = new Icons($ICONS_DIR."/");
+ $icon = $icons->icons[$this->flyer];
+
+ $str = "<div class=\"event\">\n";
+ $str .= " <div class=\"event_title\">" .
+ htmlspecialchars_decode($this->title, ENT_QUOTES) . "</div>\n";
+ $str .= " <div class=\"event_time\">" . date("D M jS Y", $this->time) . "</div>\n";
+ $str .= " <div class=\"event_description\">" .
+ htmlspecialchars_decode($this->description, ENT_QUOTES) . "</div>\n";
+ if($this->flyer) {
+ $str .= " <img class=\"event_flyer\" alt=\"flyer\" src=\"".$icon->prefix.$icon->file."\"/>\n";
}
$str .= "</div>\n";
return $str;
}
-
+
public function Event($title, $time, $description, $flyer = "")
{
$this->title = $title;
@@ -38,21 +55,178 @@ class Events {
// Admin config
public $admin_title = "Events";
- public $admin_submodules = array("New Event" => "new",
+ public $admin_submodules = array("Add Event" => "add",
"Edit Event" => "edit",
"Delete Event" => "delete");
+ public function admin_add($action, $vars)
+ {
+ global $ICONS_DIR;
+
+ switch($action) {
+ case "add":
+ $event = new Event($vars["title"], DateTimeEdit::toTimestamp($vars, "time"),
+ $vars["description"], $vars["icon"]);
+ echo "\"" .$event->title . "\" has now been added.";
+ $this->add($event);
+ $this->write();
+ break;
+
+ case "preview":
+ $event = new Event($vars["title"], DateTimeEdit::toTimestamp($vars, "time"),
+ $vars["description"], $vars["icon"]);
+ echo "<div class=\"preview\">\n";
+ echo "<div class=\"content\">\n";
+ echo $event->show();
+ echo "</div>\n";
+ echo "</div>\n";
+ echo "<p>Looking ok?</p>";
+ $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 "<div class=\"preview\">\n";
+ echo "<div class=\"content\">\n";
+ echo $event->show();
+ echo "</div>\n";
+ echo "</div>\n";
+ echo "<p>Looking ok?</p>";
+ $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 "new":
- echo "New";
+ case "add":
+ $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;
}
}
@@ -158,13 +332,7 @@ class Events {
fwrite($fp, "<events>\n");
foreach($this->events as $event) {
- fwrite($fp, " <event title=\"" .
- htmlspecialchars($event->title, ENT_QUOTES, "UTF-8") . "\"\n");
- fwrite($fp, " time=\"" . $event->time . "\"\n");
- fwrite($fp, " description=\"" .
- htmlspecialchars($event->description, ENT_QUOTES, "UTF-8") . "\"\n");
- fwrite($fp, " flyer=\"" . $event->flyer . "\">\n");
- fwrite($fp, " </event>\n");
+ $event->write($fp);
}
fwrite($fp, "</events>\n");