--- /dev/null
+<html>
+<title>Magic Smoke ODT Templates</title>
+<body>
+<h1>Magic Smoke ODT Templates</h1>
+
+
+</html>
\ No newline at end of file
FIXME: special hosts (beginning with "_") return errors. Non-existing hosts are silently ignored.
+<h2>Customers</h2>
+
+<h2>Orders and Sales</h2>
+
+<h2>Templates</h2>
+
+Templates are used for printouts and documents. There are several types of templates:<p>
+
+<ul>
+<li><a href="prog_odttemplate.html">Open Document Text Template</a></li>
+<li><a href="prog_tickettemplate.html">XML Ticket printer template</a></li>
+</ul><p>
+
+Filenames of templates are restricted to the regular expression <tt>^[a-z0-9_.]+$</tt> and are case-insensitive.
+
+<h3>List of Templates</h3>
+
+The <tt>gettemplatelist</tt> transaction returns an informational list of templates. The request is empty, the response looks like:<p>
+
+<pre>
+<TList>
+ <Template name="filename" hash="md5-hash"/>
+ ...
+</TList>
+</pre>
+
+The Hash is caculated at the server side and can be used to find out whether the template has been changed. It does not necessarily need to be MD5 or any other specific algorithm, it can be any kind of ASCII string that shows changes (hence the client must remember the string if it wants to use it).
+
+<h3>Getting a Template</h3>
+
+The <tt>gettemplate</tt> transaction returns a specific template. The request contains only the file name, the response contains the template file as content. In case of an error the content is left empty and the status code is set appropriately.
+
+</h3>Setting a Template</h3>
+
+The <tt>settemplate</tt> transaction creates a new template file. The request contains the file name terminated with a newline ("\n") and then the binary content of the template - it is important that there are no additional characters between the newline and the template content. The response contains the new hash of the template or error details.
\ No newline at end of file
--- /dev/null
+<html>
+<title>Magic Smoke Ticket Templates</title>
+<body>
+<h1>Magic Smoke Ticket Templates</h1>
+
+
+</html>
\ No newline at end of file
if($dbScheme->isStringColumn($table,$k))
$val.=$this->escapeString($v);
else
+ if($dbScheme->isBlobColumn($table,$k))
+ $val.=$this->escapeBlob($v);
+ else
//don't know how to escape it...
$val.="NULL";
}
if($dbScheme->isStringColumn($table,$k))
$ret.=$this->escapeString($v);
else
+ if($dbScheme->isBlobColumn($table,$k))
+ $ret.=$this->escapeBlob($v);
+ else
//don't know how to escape it...
$ret.="NULL";
}
return "'".addslashes($s)."'";
}
+ /**escapes blobs; the default uses addslashes and encloses the value in ''*/
+ public function escapeBlob($s)
+ {
+ if($s === false) return "NULL";
+ return "'".addslashes($s)."'";
+ }
+
/**returns a configuration setting*/
public function getConfig($key)
{
if($type=="seq32")return "INT AUTO_INCREMENT";
if($type=="seq64")return "BIGINT AUTO_INCREMENT";
if($type=="text")return "TEXT";
+ if($type=="blob")return "MEDIUMBLOB"; //max.16MB of blob
$tpa=explode(":",$type);
if($tpa[0]=="string"){
if(isset($tpa[1]))
if($s === false) return "NULL";
return "'".mysqli_real_escape_string($this->dbhdl,$s)."'";
}
+
+ /**escapes blobs; it uses mysqli_escape_string and encloses the value in '' - blobs are binary strings in MySQL*/
+ public function escapeBlob($s)
+ {
+ if($s === false) return "NULL";
+ return "'".mysqli_real_escape_string($this->dbhdl,$s)."'";
+ }
};
\ No newline at end of file
// this needs to change to 64-bit int in 2038
"timeout"=>array("int32","notnull")
);
+ //templates
+ $this->scheme["template"]=array(
+ "filename" => array("string","primarykey"),
+ "content" => array("blob"),
+ "hash" => array("string:32","notnull") //md5
+ );
// //////////////////////
"customerid" => array("seq32","primarykey"),
//contact data
"name" => array("string","notnull"),
- "address" => array("string"),
+ "address" => array("text"),
"contact" => array("string"),//phone or something
"comments" => array("text"),
//online login data
//seller (_online for web forms)
"soldby" => array("string:64","foreignkey:users:uname"),
//if not null/empty: this address for delivery, customer address for invoice
- "deliveryaddress" => array("string"),
+ "deliveryaddress" => array("text"),
//if not null/empty: lodge/deposit the tickets at a seller with _deposit flag
"depositat" => array("string:64","foreignkey:users:uname"),
//status, see ORDER_* constants
//when the cart expires
"timeout" => array("int32","notnull"),
//shipping address during order process
- "shippingaddress" => array("string")
+ "shippingaddress" => array("text")
);
//buying tickets
$this->scheme["cart_ticket"]=array(
return false;
}
}
+
+ /**returns true if the given column is of a string type*/
+ public function isBlobColumn($tab,$col)
+ {
+ if(!isset($this->scheme[$tab][$col]))
+ return false;
+ $tpa=explode(":",$this->scheme[$tab][$col][0]);
+ switch($tpa[0]){
+ case "blob":
+ return true;
+ default:
+ return false;
+ }
+ }
};
$dbScheme=new DbScheme;
?>
\ No newline at end of file
--- /dev/null
+<?
+//
+// PHP Implementation: template
+//
+// Description:
+//
+//
+// Author: Konrad Rosenbaum <konrad@silmor.de>, (C) 2008
+//
+// Copyright: See README/COPYING files that come with this distribution
+//
+//
+
+function getTemplateList()
+{
+ global $db;
+ header("X-MagicSmoke-Status: Ok");
+ print("<TList>\n");
+ $res=$db->select("template","filename,hash");
+ for($i=0;$i<count($res);$i++){
+ //it is safe to do this since setTemplate checks syntax:
+ print("<Template name=\"".$res[$i]["filename"]."\" hash=\"".$res[$i]["hash"]."\"/>\n");
+ }
+ print("</TList>\n");
+}
+
+function getTemplate($fname)
+{
+ global $db;
+ $res=$db->select("template","content","filename=".$db->escapeString($fname));
+ if(count($res)==0){
+ header("X-MagicSmoke-Status: Error");
+ die(tr("Template File not found in database"));
+ }
+ header("X-MagicSmoke-Status: Ok");
+ print($res[0]["content"]);
+}
+
+function setTemplate($data)
+{
+ $pos=strpos($data,'\n');
+ if($pos===false){
+ header("X-MagicSmoke-Status: Error");
+ die(tr("Unable to find file name"));
+ }
+ //split
+ $fname=strtolower(trim(substr($data,0,$pos)));
+ $data=substr($data,$pos+1);
+ //syntax check
+ if(ereg("^[a-z0-9_\\.]+$",$fname)===false){
+ header("X-MagicSmoke-Status: Error");
+ die(tr("Illegal File Name"));
+ }
+ //store
+ $hash=md5($data);
+ global $db;
+ $db->beginTransaction();
+ $res=$db->select("template","filename","filename=".$db->escapeString($fname));
+ if(count($res)==1){
+ $db->update("template",array("content"=>$data,"hash"=>$hash),"filename=".$db->escapeString($fname));
+ }else{
+ $db->insert("template",array("content"=>$data,"hash"=>$hash,"filename"=>$fname));
+ }
+ $db->commitTransaction();
+ header("X-MagicSmoke-Status: Ok");
+}
+
+?>
\ 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"), //customer info
+ tr("createorder"),tr("createsale"), //sell/order stuff
+ tr("gettemplatelist"),tr("gettemplate"),tr("settemplate") //templates
);
/**contains the low-level request name from the client*/
$SMOKEREQUEST=strtolower($_SERVER["HTTP_X_MAGICSMOKE_REQUEST"]);
//load machine interface
include("inc/machine/session.php");
include("inc/machine/host.php");
+include("inc/machine/template.php");
// request to start a session
if($SMOKEREQUEST=="startsession"){
}
+//return list of templates
+if($SMOKEREQUEST=="gettemplatelist"){
+ getTemplateList();
+ exit();
+}
+//get specific template
+if($SMOKEREQUEST=="gettemplate"){
+ getTemplate(trim($REQUESTDATA));
+ exit();
+}
+//set a specific template
+if($SMOKEREQUEST=="settemplate"){
+ setTemplate($REQUESTDATA);
+ exit();
+}
+
+
//EOF
header("X-MagicSmoke-Status: Error");
die(tr("Internal Error: unknown command, hiccup in code structure."));