From 7c0111d40359ec104727d77d92a97f4ba188e84f Mon Sep 17 00:00:00 2001 From: deva Date: Tue, 9 Feb 2010 07:55:06 +0000 Subject: New shopping module. --- utils/modules/shop.php | 220 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 220 insertions(+) create mode 100644 utils/modules/shop.php (limited to 'utils/modules/shop.php') diff --git a/utils/modules/shop.php b/utils/modules/shop.php new file mode 100644 index 0000000..1a73b5a --- /dev/null +++ b/utils/modules/shop.php @@ -0,0 +1,220 @@ +title, ENT_QUOTES, "UTF-8") . "\"\n"); + fwrite($fp, " type=\"" . $this->type . "\"\n"); + fwrite($fp, " paypalkey=\"" . $this->paypalkey . "\">\n"); + fwrite($fp, " \n"); + */ + } + + public function show() + { + $str = ""; + + $str .= "
\n"; + $str .= "
".$this->title."
\n"; + $str .= "
\n"; + $str .= "
\n"; + $str .= " \n"; + $str .= " paypalkey."\"/>\n"; + $str .= " \n"; + $str .= "
\n"; + $str .= "
\n"; + $str .= "
\n"; + + return $str; + } + + public function Payment($title, $type, $paypalkey) + { + $this->title = $title; + $this->type = $type; + $this->paypalkey = $paypalkey; + } +} + +class ShopItem { + public $id; + public $title; + public $description; + public $image; + public $url; + public $payments = array(); + + public function write($fp) + { + /* + fwrite($fp, " title, ENT_QUOTES, "UTF-8") . "\"\n"); + fwrite($fp, " description=\"" . + htmlspecialchars($this->description, ENT_QUOTES, "UTF-8") . "\"\n"); + fwrite($fp, " image=\"" . $this->image . "\">\n"); + + fwrite($fp, " type=\"" . $this->type . "\"\n"); + fwrite($fp, " paypalkey=\"" . $this->paypalkey . "\">\n"); + fwrite($fp, " \n"); + */ + } + + public function show() + { + $str = ""; + + $str .= "
\n"; + $str .= "
".$this->title."
\n"; + if($this->url != "") $str .= "url."\">\n"; + $str .= " \"".$this-title."\" src=\"".$this->image."\"/>\n"; + if($this->url != "") $str .= "\n"; + $str .= "
".$this->description."
\n"; + + $str .= "
\n"; + foreach($this->payments as $p) { + $str .= $p->show(); + } + $str .= "
\n"; + $str .= "
\n"; + + return $str; + } + + public function addPayment($payment) + { + $key = $payment->title; + $this->payments[$key] = $payment; + } + + public function ShopItem($id, $title, $description, $image, $url) + { + $this->id = $id; + $this->title = $title; + $this->description = $description; + $this->image = $image; + $this->url = $url; + } +} + +class Shop { + + private $file; + private $shopitems = array(); + + // Admin config + public $admin_title = "Shop"; + public $admin_submodules = array("Add Item" => "add", + "Edit Item" => "edit", + "Delete Item" => "delete"); + + public function admin($sub, $action, $vars) + { + switch($sub) { + case "add": + break; + case "edit": + break; + case "delete": + break; + } + } + + public function run($params) + { + global $GLOBALS; + + $str = "
\n"; + + //foreach($params as $param => $value) {} + + if($this->shopitems) { + foreach($this->shopitems as $shopitem) { + $str .= $shopitem->show(); + } + } + + $str .= "
\n"; + + return $str; + } + + public function add($shopitem) { + $key = $shopitem->id; + $this->shopitems[$key] = $shopitem; + } + + public function write() + { + /* + $fp = fopen($this->file, "w"); + fwrite($fp, "\n"); + + fwrite($fp, "\n"); + foreach($this->discs as $disc) { + $disc->write($fp); + } + fwrite($fp, "\n"); + + fclose($fp); + */ + } + + private function read() + { + $dom = new DomDocument; + $dom->preserveWhiteSpace = FALSE; + $dom->load($this->file); + $shopitems = $dom->getElementsByTagName('shopitem'); + + if($shopitems) { + foreach($shopitems as $i) { + $shopitem = new ShopItem($i->getAttribute('id'), + $i->getAttribute('title'), + $i->getAttribute('description'), + $i->getAttribute('image'), + $i->getAttribute('url')); + + $payments = $i->getElementsByTagName('payment'); + if($payments) { + foreach($payments as $p) { + $payment = new Payment($p->getAttribute('title'), + $p->getAttribute('type'), + $p->getAttribute('paypalkey')); + $shopitem->addPayment($payment); + } + } + + $this->add($shopitem); + } + } + ksort($this->shopitems); + } + + public function Shop($file) + { + $this->file = $file; + if(file_exists($file)) $this->read(); + } + +} + +function shop_init() +{ + global $DATA_DIR; + return new Shop($DATA_DIR . "/shop.xml"); +} + +?> -- cgit v1.2.3