return $this->id;
}
+ /**returns whether the customer has a valid id*/
+ public function isValid()
+ {
+ if($this->id===false)return false;
+ if($this->id<0)return false;
+ return true;
+ }
+
/** returns the name of the customer */
public function getName()
{
$xml->appendChild($root);
header("X-MagicSmoke-Status: Ok");
print($xml->saveXML());
-
+}
+
+/**machine interface: get a specific customer*/
+function getCustomerXml($cid)
+{
+ global $db;
+ //return customers
+ $res=$db->select("customer","*","customerid=".$db->escapeInt($cid));
+ if(count($res)>0){
+ $xml=new DOMDocument;
+ $cs=$xml->createElement("Customer");
+ $cs->setAttribute("id",$res[0]["customerid"]);
+ $cs->setAttribute("name",$res[0]["name"]);
+ $cs->appendChild($xml->createElement("Address",$res[0]["address"]));
+ $cs->appendChild($xml->createElement("Contact",$res[0]["contact"]));
+ $cs->appendChild($xml->createElement("Comment",$res[0]["comments"]));
+ $res=$db->select("webuser","email","customerid=".$db->escapeInt($cid));
+ if(count($res)>0)
+ $cs->setAttribute("mail",$res[0]["email"]);
+ $xml->appendChild($cs);
+ header("X-MagicSmoke-Status: Ok");
+ print($xml->saveXML());
+ }else{
+ header("X-MagicSmoke-Status: Error");
+ die(tr("Unknown Customer"));
+ }
+}
+
+/**machine interface: set a customer*/
+function setCustomerXml($xmldata)
+{
+ //TODO:do more extensive syntax checking and better error reporting
+ //get XML
+ $xml=new DOMDocument;
+ if($xml->loadXML($xmldata)===false){
+ header("X-MagicSmoke-Status: SyntaxError");
+ die(tr("Unable to parse XML."));
+ }
+ //stage 2: extract data from XML
+ $doc=$xml->documentElement;
+ global $db;
+ //get data
+ if($doc->hasAttribute("id"))
+ $id=$doc->getAttribute("id")+0;
+ else $id=-1;
+ $dt["name"]=$doc->getAttribute("name");
+ $dt["address"]="";
+ $dt["contact"]="";
+ $dt["comments"]="";
+ foreach($doc->getElementsByTagName("Address") as $el)
+ foreach($el->childNodes as $cn)
+ if($cn->nodeType==XML_TEXT_NODE)
+ $dt["address"]=trim($cn->wholeText);
+ foreach($doc->getElementsByTagName("Contact") as $el)
+ foreach($el->childNodes as $cn)
+ if($cn->nodeType==XML_TEXT_NODE)
+ $dt["contact"]=trim($cn->wholeText);
+ foreach($doc->getElementsByTagName("Comment") as $el)
+ foreach($el->childNodes as $cn)
+ if($cn->nodeType==XML_TEXT_NODE)
+ $dt["comments"]=trim($cn->wholeText);
+
+ if($id>=0){
+ $db->update("customer",$dt,"customerid=".$db->escapeInt($id));
+ }else{
+ $dt["customerid"]=$id;
+ $db->insert("customer",$dt);
+ }
+ header("X-MagicSmoke-Status: Ok");
}
?>
\ No newline at end of file
class Order
{
private $orderid;
- private $status;
+ private $status=false;
+ private $customerid=false;
/**instantiates an existing order with the given orderid or creates a new one if orderid===false*/
public function __construct($orderid=false)
}
$this->orderid=$res[0]["orderid"];
$this->status=$res[0]["status"];
+ $this->customerid=$res[0]["customerid"];
}
}
global $db;
//get event
$event=new Event($eventid);
+ //check that there are tickets available
+ if($event->availableTicketAmount()<$amount)return false;
//create ticket
$tc=array("eventid" => $eventid,
"price" => $event->getDefaultPrice(),
"status" => 0,
- "oderid" => $this->orderid
+ "orderid" => $this->orderid
);
$ret=array();
for($i=0;$i<$amount;$i++)$ret[]=$db->insert("ticket",$tc);
return $ret;
}
+ /**sets the customer of this order; returns 1 on success, false or 0 on failure*/
+ public function setCustomer($cust)
+ {
+ global $db;
+ if(!$this->canChange() || !$cust->isValid())return false;
+ return $db->update("order",array("customerid"=>$cust->getID()),"orderid=".$db->escapeInt($this->orderid));
+ }
+
/**places/finalizes the order; returns false on failure, true on success or if the order already was finalized()*/
public function placeOrder()
{
}
};
+function createOrderXml($xmldata,$ispaid)
+{
+ //parse XML data
+}
+
?>
\ No newline at end of file
tr("gethosts"),tr("sethost"),tr("addhost"),tr("deletehost"), //host management
tr("geteventlist"),tr("geteventdata"),tr("seteventdata"), //event infos
tr("getroomdata"),tr("setroomdata"),//room infos
- tr("getcustomerlist"), //customer info
+ tr("getcustomerlist"),tr("getcustomer"),tr("setcustomer"), //customer info
tr("createorder"),tr("createsale"), //sell/order stuff
tr("gettemplatelist"),tr("gettemplate"),tr("settemplate") //templates
);
exit();
}
+//get a specific customer
+if($SMOKEREQUEST=="getcustomer"){
+ getCustomerXml(trim($REQUESTDATA));
+ exit();
+}
+
+//set/create a specific customer
+if($SMOKEREQUEST=="setcustomer"){
+ setCustomerXml($REQUESTDATA);
+ exit();
+}
-if($SMOKEREQUEST=="createorder"){}
-if($SMOKEREQUEST=="createsale"){}
+
+if($SMOKEREQUEST=="createorder"){
+ createOrderXml($REQUESTDATA,false);
+ exit();
+}
+if($SMOKEREQUEST=="createsale"){
+ createOrderXml($REQUESTDATA,true);
+ exit();
+}
//EOF