From cce5e7710295021b41d9aaecc503a60fb99256be Mon Sep 17 00:00:00 2001 From: deva Date: Sat, 4 Oct 2008 10:38:03 +0000 Subject: Initial revision --- utils/events.php | 130 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 130 insertions(+) create mode 100644 utils/events.php (limited to 'utils/events.php') diff --git a/utils/events.php b/utils/events.php new file mode 100644 index 0000000..27ec873 --- /dev/null +++ b/utils/events.php @@ -0,0 +1,130 @@ +\n"; + echo "
" . + htmlspecialchars_decode($this->title, ENT_QUOTES) . "
\n"; + echo "
" . date("D M jS Y", $this->time) . "
\n"; + echo "
" . + htmlspecialchars_decode($this->description, ENT_QUOTES) . "
\n"; + if($this->flyer) { + echo " \"flyer\"flyer . "\"/>\n"; + } + echo "\n"; + } + + public function Event($title, $time, $description, $flyer = "") + { + $this->title = $title; + $this->time = $time; + $this->description = $description; + $this->flyer = $flyer; + } +} + +class Events { + + private $file; + private $events = array(); + + public function showcoming($number) + { + $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; + $event->show(); + $number--; + } + if(!$number) return; + } + + if($foundany == false) echo "No shows available at the moment."; + } + + public function showold($number) + { + // 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()) { + $event->show(); + $number--; + } + if(!$number) return; + } + } + + 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, "\n"); + foreach($this->events as $event) { + fwrite($fp, " 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, " \n"); + } + fwrite($fp, "\n"); + + fclose($fp); + } + + private function read() + { + + $dom = new DomDocument; + $dom->preserveWhiteSpace = FALSE; + $dom->load($this->file); + $params = $dom->getElementsByTagName('event'); + + foreach ($params as $param) { + $event = new Event($param->getAttribute('title'), + $param->getAttribute('time'), + $param->getAttribute('description'), + $param->getAttribute('flyer')); + $this->add($event); + } + + } + + public function Events($file) + { + $this->file = $file; + $this->read(); + } + +} + +?> \ No newline at end of file -- cgit v1.2.3