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";
    
    //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");
}
?>