<h2>Customers</h2>
+<h3>Getting List of Customers</h3>
+
+The <tt>getcustomerlist</tt> transaction returns a short list of customers. The request is empty. The response returns this:
+
+<pre>
+<CustomerList>
+ <Customer id="integer ID" name="full name"/>
+ ...
+</CustomerList>
+</pre>
+
<h2>Orders and Sales</h2>
<h2>Templates</h2>
--- /dev/null
+//
+// C++ Implementation: customer
+//
+// Description:
+//
+//
+// Author: Konrad Rosenbaum <konrad@silmor.de>, (C) 2008
+//
+// Copyright: See README/COPYING files that come with this distribution
+//
+//
+
+#include "customer.h"
+#include "webrequest.h"
+
+#include <QDomElement>
+#include <QPushButton>
+#include <QListView>
+#include <QStandardItemModel>
+#include <QBoxLayout>
+
+MCustomer::MCustomer()
+{
+ m_req=0;
+ m_id=-1;
+}
+
+MCustomer::MCustomer(MWebRequest*r,const QDomElement&el)
+{
+ m_req=r;
+ bool b;
+ m_id=el.attribute("id","-1").toInt(&b);
+ if(!b)m_id=-1;
+ m_name=el.attribute("name");
+}
+
+MCustomer::MCustomer(const MCustomer&c)
+{
+ m_req=c.m_req;
+ m_id=c.m_id;
+ m_name=c.m_name;
+}
+
+MCustomer& MCustomer::operator=(const MCustomer&c)
+{
+ m_req=c.m_req;
+ m_id=c.m_id;
+ m_name=c.m_name;
+ return *this;
+}
+
+qint64 MCustomer::customerID()
+{
+ return m_id;
+}
+
+bool MCustomer::isValid()
+{
+ return m_id>-1;
+}
+
+QString MCustomer::name()
+{
+ return m_name;
+}
+
+QString MCustomer::getNameAddress()
+{
+ return m_name;
+}
+
+
+/*********************************************************/
+
+MCustomerListDialog::MCustomerListDialog(MWebRequest*r,QWidget*par,bool isselect,qint64 presel)
+ :QDialog(par)
+{
+ m_req=r;
+ if(isselect)
+ setWindowTitle(tr("Select a Customer"));
+ else
+ setWindowTitle(tr("Customers"));
+
+ //layout
+ QVBoxLayout*vl,*vl2;
+ QHBoxLayout*hl;
+ setLayout(vl=new QVBoxLayout);
+ vl->addLayout(hl=new QHBoxLayout,10);
+ hl->addWidget(m_listview=new QListView,10);
+ m_listview->setModel(m_listmodel=new QStandardItemModel(this));
+ m_listview->setEditTriggers(QAbstractItemView::NoEditTriggers);
+ hl->addLayout(vl2=new QVBoxLayout,0);
+ QPushButton*p;
+ vl2->addWidget(p=new QPushButton(tr("Details...")),0);
+ vl2->addWidget(p=new QPushButton(tr("Create new...")),0);
+ vl2->addWidget(p=new QPushButton(tr("Delete...")),0);
+ vl2->addStretch(2);
+ vl->addSpacing(15);
+ vl->addLayout(hl=new QHBoxLayout,0);
+ hl->addStretch(10);
+ if(isselect){
+ hl->addWidget(p=new QPushButton(tr("Select")),0);
+ connect(p,SIGNAL(clicked()),this,SLOT(accept()));
+ hl->addWidget(p=new QPushButton(tr("Cancel")),0);
+ connect(p,SIGNAL(clicked()),this,SLOT(reject()));
+ }else{
+ hl->addWidget(p=new QPushButton(tr("Close")),0);
+ connect(p,SIGNAL(clicked()),this,SLOT(reject()));
+ }
+
+ //update data
+ updateList();
+ if(presel>-1){
+ for(int i=0;i<m_listmodel->rowCount();i++){
+ QModelIndex idx=m_listmodel->index(0,i);
+ if(m_listmodel->data(idx,Qt::UserRole).toInt()==presel)
+ m_listview->setCurrentIndex(idx);
+ }
+ }
+}
+
+void MCustomerListDialog::updateList()
+{
+ //go to server
+ m_list=m_req->getAllCustomers();
+ //update widget
+ m_listmodel->clear();
+ m_listmodel->insertRows(0,m_list.size());
+ m_listmodel->insertColumn(0);
+ for(int i=0;i<m_list.size();i++){
+ QModelIndex idx=m_listmodel->index(i,0);
+ m_listmodel->setData(idx,m_list[i].name());
+ m_listmodel->setData(idx,i,Qt::UserRole);
+ }
+ m_listmodel->sort(0);
+}
+
+MCustomer MCustomerListDialog::getCustomer()
+{
+ //get selection
+ QModelIndex idx=m_listview->currentIndex();
+ if(!idx.isValid())return MCustomer();
+ //return object
+ int i=m_listmodel->data(idx,Qt::UserRole).toInt();
+ if(i<0||i>=m_list.size())return MCustomer();
+ return m_list[i];
+}
--- /dev/null
+//
+// C++ Interface: customer
+//
+// Description:
+//
+//
+// Author: Konrad Rosenbaum <konrad@silmor.de>, (C) 2008
+//
+// Copyright: See README/COPYING files that come with this distribution
+//
+//
+
+#ifndef MAGICSMOKE_CUSTOMER_H
+#define MAGICSMOKE_CUSTOMER_H
+
+#include <QString>
+#include <QDialog>
+#include <QList>
+
+class MWebRequest;
+class QDomElement;
+
+class MCustomer
+{
+ public:
+ /**creates an empty/invalid customer*/
+ MCustomer();
+ /**creates a customer from XML*/
+ MCustomer(MWebRequest*,const QDomElement&);
+ /**copies a customer*/
+ MCustomer(const MCustomer&);
+
+ /**copies a customer*/
+ MCustomer& operator=(const MCustomer&);
+
+ /**returns the ID of this customer or -1 if it is invalid*/
+ qint64 customerID();
+
+ /**returns whether the customer is valid*/
+ bool isValid();
+
+ /**returns the customers name*/
+ QString name();
+
+ /**returns the customers name and address*/
+ QString getNameAddress();
+ private:
+ qint64 m_id;
+ QString m_name;
+ MWebRequest*m_req;
+};
+
+class QListView;
+class QStandardItemModel;
+
+/**shows a list of customers, lets the user select and offers to alter/create customers*/
+class MCustomerListDialog:public QDialog
+{
+ Q_OBJECT
+ public:
+ /**creates a new customer list dialog; expects a usable webrequest object and a parent, if isselect is set to true it offers a select button, if selected is set to a matching customerID it will be pre-selected*/
+ MCustomerListDialog(MWebRequest*,QWidget*,bool isselect=false,qint64 selected=-1);
+
+ MCustomer getCustomer();
+
+ private:
+ QList<MCustomer> m_list;
+ QListView*m_listview;
+ QStandardItemModel*m_listmodel;
+ MWebRequest*m_req;
+
+ /**updates internal list*/
+ void updateList();
+};
+
+#endif
QHBoxLayout*hl2;
vl2->addLayout(hl2=new QHBoxLayout,0);
hl2->addStretch(10);
- hl2->addWidget(new QPushButton(tr("Add Ticket")),0);
- hl2->addWidget(new QPushButton(tr("Add Voucher")),0);
- hl2->addWidget(new QPushButton(tr("Remove Item")),0);
+ hl2->addWidget(p=new QPushButton(tr("Add Ticket")),0);
+ hl2->addWidget(p=new QPushButton(tr("Add Voucher")),0);
+ hl2->addWidget(p=new QPushButton(tr("Remove Item")),0);
QFrame*frm;
hl->addWidget(frm=new QFrame,0);
frm->setFrameShape(QFrame::VLine);
hl->addLayout(vl2=new QVBoxLayout,1);
- vl2->addWidget(new QPushButton(tr("Customer:")),0);
- vl2->addWidget(new QLabel("...blah\nPerson\nsomewhere"));
+ vl2->addWidget(p=new QPushButton(tr("Customer:")),0);
+ connect(p,SIGNAL(clicked()),this,SLOT(setCustomer()));
+ vl2->addWidget(cartcustomer=new QLabel("...\n \n \n "));
vl2->addWidget(frm=new QFrame,0);
frm->setFrameShape(QFrame::HLine);
vl2->addSpacing(10);
frm->setFrameShape(QFrame::HLine);
vl->addLayout(hl=new QHBoxLayout,0);
hl->addStretch(10);
- hl->addWidget(new QPushButton(tr("Save Order")));
- hl->addWidget(new QPushButton(tr("Clear")));
+ hl->addWidget(p=new QPushButton(tr("Order Items")));
+ p->setEnabled(req->hasRole("createorder"));
+ hl->addWidget(p=new QPushButton(tr("Sell Items")));
+ p->setEnabled(req->hasRole("createsale"));
+ hl->addWidget(p=new QPushButton(tr("Clear")));
//user tab
tab->addTab(usertab=new QWidget,tr("Users"));
eventtab->setEnabled(false);
tab->setTabEnabled(tab->indexOf(eventtab),false);
}
- if(!req->hasRole("createorder")){
+ if(!req->hasRole("createorder")&&!req->hasRole("createsale")){
carttab->setEnabled(false);
tab->setTabEnabled(tab->indexOf(carttab),false);
}
{
}
+void MOverview::setCustomer()
+{
+ MCustomerListDialog mcl(req,this,true,customer.customerID());
+ if(mcl.exec()!=QDialog::Accepted)return;
+ customer=mcl.getCustomer();
+ cartcustomer->setText(customer.getNameAddress());
+}
+
/**********************************************/
#include <QPointer>
#include <QDialog>
+#include "customer.h"
+
class MWebRequest;
class QTabWidget;
class QTableView;
class QStandardItemModel;
class QPushButton;
class QLineEdit;
+class QLabel;
/**Main Overview Window*/
class MOverview:public QMainWindow
/**export host to file*/
void exportHost();
+ /**decide what customer to use*/
+ void setCustomer();
+
private:
//my session object
QPointer<MWebRequest>req;
QTableView*eventtable,*usertable,*hosttable;
QStandardItemModel*eventmodel,*usermodel,*hostmodel;
QPushButton*thishostbutton;
+ QLabel*cartcustomer;
+ //cart
+ MCustomer customer;
};
/**Helper dialog for changing passwords*/
room.cpp \
user.cpp \
host.cpp \
+ customer.cpp \
checkdlg.cpp
#some PHP files are listed below to scan them for translatable items:
room.h \
user.h \
host.h \
+ customer.h \
checkdlg.h \
../www/machine.php \
../www/inc/machine/session.php \
return ret;
}
+QList<MCustomer> MWebRequest::getAllCustomers()
+{
+ errstr="";
+ if(!request("getcustomerlist",""))return QList<MCustomer>();
+ //parse return document
+ QDomDocument doc;
+ QString msg;int ln,cl;
+ if(!doc.setContent(rspdata,&msg,&ln,&cl)){
+ errstr=tr("Error parsing CustomerList XML data (line %1 column %2): %3").arg(ln).arg(cl).arg(msg);
+ return QList<MCustomer>();
+ }
+ QDomElement root=doc.documentElement();
+ QDomNodeList nl=root.elementsByTagName("Customer");
+ QList<MCustomer>ret;
+ for(int i=0;i<nl.size();i++){
+ QDomElement el=nl.at(i).toElement();
+ if(el.isNull())continue;
+ MCustomer cr(this,el);
+ if(cr.isValid())ret.append(cr);
+ }
+ return ret;
+}
+
QByteArray MWebRequest::responseBody()
{
return rspdata;
#include "event.h"
#include "user.h"
#include "host.h"
+#include "customer.h"
/**abstraction of requests to the web server, handles sessions and all data transfer*/
class MWebRequest:public QObject
/**returns a list of all hosts**/
QList<MHost>getAllHosts();
+ /**returns a list of all customers*/
+ QList<MCustomer>getAllCustomers();
+
/**return current host name of this session*/
QString hostName();
public function getByMail($mail)
{
global $db;
- $res=$db->select("customer","customerid","email=".$db->escapeString($mail));
+ $res=$db->select("webuser","customerid","email=".$db->escapeString($mail));
if(count($res)>0){
$this->id=$res[0]["customerid"];
return true;
{
if($this->id===false)return;
global $db;
- $db->update("customer",array("email"=>$mail),"customerid=".$db->escapeInt($this->id));
+ $db->beginTransaction();
+ $res=$db->select("webuser","customerid","customerid=".$db->escapeInt($this->id));
+ if(count($res)==1)
+ $db->update("webuser",array("email"=>$mail),"customerid=".$db->escapeInt($this->id));
+ else
+ $db->insert("webuser",array("email"=>$mail,"customerid"=>$this->id));
+ $db->commitTransaction();
}
/**sets the password of this customer*/
if($this->id===false)return;
global $db;
$pass=calcPasswd($pwd,getSalt());
- $db->update("customer",array("passwd"=>$pass),"customerid=".$db->escapeInt($this->id));
+ $db->beginTransaction();
+ $res=$db->select("webuser","customerid","customerid=".$db->escapeInt($this->id));
+ if(count($res)==1)
+ $db->update("webuser",array("passwd"=>$pass),"customerid=".$db->escapeInt($this->id));
+ else
+ $db->insert("webuser",array("passwd"=>$pass,"customerid"=>$this->id));
+ $db->commitTransaction();
}
/**sets the address of this customer*/
if($this->id===false)return false;
//get record
global $db;
- $res=$db->select("customer","passwd","customerid=".$db->escapeInt($this->id));
+ $res=$db->select("webuser","passwd","customerid=".$db->escapeInt($this->id));
//found anything?
if(count($res)<0)return false;
//is it a password
}
};
+/**machine interface: get the list of all existing customers*/
+function getCustomerListXml()
+{
+ global $db;
+ //return customers
+ $res=$db->select("customer","customerid,name","");
+ $xml=new DOMDocument;
+ $root=$xml->createElement("CustomerList");
+ if(count($res)>0)
+ foreach($res as $k => $rm){
+ $cs=$xml->createElement("Customer");
+ $cs->setAttribute("id",$rm["customerid"]);
+ $cs->setAttribute("name",$rm["name"]);
+ $root->appendChild($cs);
+ }
+ $xml->appendChild($root);
+ header("X-MagicSmoke-Status: Ok");
+ print($xml->saveXML());
+
+}
+
?>
\ No newline at end of file
"name" => array("string","notnull"),
"address" => array("text"),
"contact" => array("string"),//phone or something
- "comments" => array("text"),
+ "comments" => array("text")
+ );
+ $this->scheme["webuser"]=array(
//online login data
- "email" => array("string","unique"),
+ "email" => array("string","primarykey"),
+ "customerid" => array("int32","unique","foreignkey:customer:customerid"),
"passwd" => array("string:64"),//salted SHA-1 hash of passwd
);
//orders by customers
}
+//get the list of customers
+if($SMOKEREQUEST=="getcustomerlist"){
+ getCustomerListXml();
+ exit();
+}
+
+
+if($SMOKEREQUEST=="createorder"){}
+if($SMOKEREQUEST=="createsale"){}
+
+
//EOF
header("X-MagicSmoke-Status: Error");
die(tr("Internal Error: unknown command, hiccup in code structure."));