From: Konrad Rosenbaum Date: Sun, 18 Dec 2016 19:32:53 +0000 (+0100) Subject: configuration for print@home, partially functional X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=1bb99df01b9458e162347c4984c8000afcced399;p=web%2Fkonrad%2Fsmoke.git configuration for print@home, partially functional Change-Id: Ib738eaa2c11f68671704c29a018cecf09ed917db --- diff --git a/iface/templates/templates.h b/iface/templates/templates.h index b9c0a7b..9e3f410 100644 --- a/iface/templates/templates.h +++ b/iface/templates/templates.h @@ -167,9 +167,6 @@ class MSIFACE_EXPORT MTemplateStore /**updates the template directory, does not do anything if force==false and the last update was less than 5min ago*/ void updateTemplates(bool force); - /**returns all templates (for MTemplateEditor)*/ - QList allTemplates(); - private: /**unused, just here to remove it from accessability*/ MTemplateStore()=delete; @@ -187,7 +184,8 @@ class MSIFACE_EXPORT MTemplateStore \param full the base name of the template to retrieve (eg. "ticket.xtt,1")*/ MTemplate getTemplateByFile(QString full); - + /**returns all templates (for MTemplateEditor)*/ + QList allTemplates(); private: QString profileid; diff --git a/iface/wext/MOKeyValuePair b/iface/wext/MOKeyValuePair new file mode 100644 index 0000000..a7ca73b --- /dev/null +++ b/iface/wext/MOKeyValuePair @@ -0,0 +1 @@ +#include"keyvalue.h" diff --git a/iface/wext/keyvalue.h b/iface/wext/keyvalue.h new file mode 100644 index 0000000..f294ff2 --- /dev/null +++ b/iface/wext/keyvalue.h @@ -0,0 +1,69 @@ +// +// C++ Interface: unabstract +// +// Description: removes abstract flag from classes that only need to be abstract in PHP +// +// +// Author: Konrad Rosenbaum , (C) 2009-2011 +// +// Copyright: See README/COPYING.GPL files that come with this distribution +// +// + +#ifndef MAGICSMOKE_MOORDER_H +#define MAGICSMOKE_MOORDER_H + +#include "MOKeyValuePairAbstract" +#include "misc.h" + +#include + +#ifndef MSIFACE_EXPORT +#define MSIFACE_EXPORT Q_DECL_IMPORT +#endif + + +/**this class represents a key value pair or part of a map/dictionary.*/ +class MSIFACE_EXPORT MOKeyValuePair:public MOKeyValuePairAbstract +{ + Q_GADGET + WOBJECT(MOKeyValuePair) +public: + MOKeyValuePair(QString k,QString v){setkey(k);setvalue(v);setisnull(false);} + MOKeyValuePair(QString k,nullptr_t){setkey(k);setisnull(true);} + + inline operator QPair () + { + return QPair(key(),value()); + } + +}; + + + +Q_DECLARE_METATYPE(MOKeyValuePair) +Q_DECLARE_METATYPE(QList) +Q_DECLARE_METATYPE(Nullable) + +#include +#include + +inline +QMap& mergeToMap(QMap&map, const QListpl) +{ + for(auto p:pl) + if(p.isnull()) + map.remove(p.key()); + else + map.insert(p.key(),p.value()); + return map; +} + +inline +QMap toMap(const QListpl) +{ + QMapmap; + return mergeToMap(map,pl); +} + +#endif diff --git a/iface/wext/wext.pri b/iface/wext/wext.pri index f9f30b6..fc013be 100644 --- a/iface/wext/wext.pri +++ b/iface/wext/wext.pri @@ -9,7 +9,8 @@ HEADERS += \ wext/address.h \ wext/event.h \ wext/customer.h \ - wext/transaction.h + wext/transaction.h \ + wext/keyvalue.h SOURCES += \ wext/customerinfo.cpp \ diff --git a/printathome/client.cpp b/printathome/clientcfg.cpp similarity index 99% rename from printathome/client.cpp rename to printathome/clientcfg.cpp index d1f4a38..5ade69e 100644 --- a/printathome/client.cpp +++ b/printathome/clientcfg.cpp @@ -10,7 +10,7 @@ // // -#include "client.h" +#include "clientcfg.h" #include "scli.h" diff --git a/printathome/client.h b/printathome/clientcfg.h similarity index 100% rename from printathome/client.h rename to printathome/clientcfg.h diff --git a/printathome/pah.cpp b/printathome/pah.cpp index 0874a3b..04cc513 100644 --- a/printathome/pah.cpp +++ b/printathome/pah.cpp @@ -16,7 +16,8 @@ #include #include "pah.h" -#include "client.h" +#include "clientcfg.h" +#include "servercfg.h" #include #include @@ -30,7 +31,7 @@ PrintIcon::PrintIcon() ctx->addAction(tr("Start &Printing now")); ctx->addSeparator(); ctx->addAction(tr("&Client Configuration..."),this,SLOT(clientConfig())); - ctx->addAction(tr("&Server Configuration...")); + ctx->addAction(tr("&Server Configuration..."),this,SLOT(serverConfig())); ctx->addSeparator(); ctx->addAction(tr("&Quit"),qApp,SLOT(quit())); setContextMenu(ctx); @@ -69,6 +70,11 @@ void PrintIcon::clientConfig() cc.exec(); } +void PrintIcon::serverConfig() +{ + MPServerConfig sc; + sc.exec(); +} int main(int argc,char**argv) diff --git a/printathome/pah.h b/printathome/pah.h index f1faadf..e47ce53 100644 --- a/printathome/pah.h +++ b/printathome/pah.h @@ -32,6 +32,7 @@ public: public slots: void setPrintMode(PrintMode); void clientConfig(); + void serverConfig(); }; -#endif \ No newline at end of file +#endif diff --git a/printathome/printathome.pro b/printathome/printathome.pro index 68806e3..e55a7ca 100644 --- a/printathome/printathome.pro +++ b/printathome/printathome.pro @@ -7,8 +7,8 @@ include(../iface/iface.pri) include(../commonlib/commonlib.pri) #sources -SOURCES += pah.cpp client.cpp -HEADERS += pah.h client.h +SOURCES += pah.cpp clientcfg.cpp servercfg.cpp +HEADERS += pah.h clientcfg.h servercfg.h RESOURCES += files.qrc diff --git a/printathome/servercfg.cpp b/printathome/servercfg.cpp new file mode 100644 index 0000000..bf92f50 --- /dev/null +++ b/printathome/servercfg.cpp @@ -0,0 +1,186 @@ +// +// C++ Implementation: print @ home +// +// Description: Client Settings +// +// +// Author: Konrad Rosenbaum , (C) 2016 +// +// Copyright: See README/COPYING.GPL files that come with this distribution +// +// + +#include "servercfg.h" + +#include "msinterface.h" +#include "templates.h" + +#include "MTGetAllContactTypes" +#include "MTGetPrintAtHomeSettings" +#include "MTSetPrintAtHomeSettings" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define TICKETCS "TicketChecksum" +#define VOUCHERCS "VoucherChecksum" +#define INVOICECS "InvoiceChecksum" +#define MAILCONTACTS "MailContactTypes" + +//seconds between forced re-inits +#define INIT_TIMER 5*60 + +QList MPServerConfig::mcontacttypes; +QDateTime MPServerConfig::mlastinit; +QMap MPServerConfig::msettings; + + +MPServerConfig::MPServerConfig(QWidget* parent) +:QDialog(parent) +{ + setWindowTitle(tr("Print@Home Server Configuration")); + QVBoxLayout*vl,*vl2; + setLayout(vl=new QVBoxLayout); + QFormLayout*fl; + vl->addLayout(fl=new QFormLayout); + //template for tickets + fl->addRow(tr("Ticket Template:"),mticket=new QComboBox); + //template for vouchers + fl->addRow(tr("Voucher Template:"),mvoucher=new QComboBox); + //template for invoice + fl->addRow(tr("Invoice Template:"),minvoice=new QComboBox); + //contacts + fl->addRow(tr("eMail Contacts:"),vl2=new QVBoxLayout); + //get settings + init(); + //update templates + QListtpl=req->templateStore()->allTemplates(); + int tp=-1,vp=-1,ip=-1; + const QString tc=ticketTemplateCS(),vc=voucherTemplateCS(),ic=invoiceTemplateCS(); + qDebug()<<"DEFAULTS tick"<addItem(tmp.description(),tmp.checksum()); + if(tc==tmp.checksum())tp=mticket->count()-1; + } + if(tmp.baseName()=="voucher"){ + mvoucher->addItem(tmp.description(),tmp.checksum()); + if(vc==tmp.checksum())vp=mvoucher->count()-1; + } + if(tmp.baseName()=="bill"){ + minvoice->addItem(tmp.description(),tmp.checksum()); + if(ic==tmp.checksum())ip=minvoice->count()-1; + } + } + mticket->setCurrentIndex(tp); + mvoucher->setCurrentIndex(vp); + minvoice->setCurrentIndex(ip); + //update contacts + QList mcont=mailContactTypeIds(); + qDebug()<<"DEFAULT contacts"<setChecked(mcont.contains(ctc.contacttypeid())); + vl2->addWidget(cb); + mcontacts.insert(ctc.contacttypeid(),cb); + } + + vl->addSpacing(15); + QHBoxLayout*hl; + vl->addLayout(hl=new QHBoxLayout); + hl->addStretch(1); + QPushButton*p; + hl->addWidget(p=new QPushButton(tr("&OK"))); + connect(p,SIGNAL(clicked()),this,SLOT(save()),Qt::DirectConnection); + connect(p,SIGNAL(clicked()),this,SLOT(accept()),Qt::QueuedConnection); + hl->addWidget(p=new QPushButton(tr("&Cancel"))); + connect(p,SIGNAL(clicked()),this,SLOT(reject())); + +} + +void MPServerConfig::init(bool force) +{ + if(!force && mlastinit>=QDateTime::currentDateTime().addSecs(-(INIT_TIMER)))return; + + auto getsettings=req->queryGetPrintAtHomeSettings(); + if(getsettings.hasError()) + QMessageBox::warning(nullptr,tr("Warning"),tr("Unable to retrieve Print@Home Settings: %1").arg(getsettings.errorString())); + else + msettings=toMap(getsettings.getsettings()); + qDebug()<<"NEW-SETTINGS"<queryGetAllContactTypes().gettypes(); + + mlastinit=QDateTime::currentDateTime(); +} + +void MPServerConfig::save() +{ + //gather data + QList settings; + settings.append(MOKeyValuePair(TICKETCS,mticket->currentData().toString())); + settings.append(MOKeyValuePair(VOUCHERCS,mvoucher->currentData().toString())); + settings.append(MOKeyValuePair(INVOICECS,minvoice->currentData().toString())); + QString mct; + for(int cid:mcontacts.keys()) + if(mcontacts[cid]->isChecked()) + mct+=QString("%1 ").arg(cid); + settings.append(MOKeyValuePair(MAILCONTACTS,mct)); + qDebug()<<"SAVING"<querySetPrintAtHomeSettings(settings); + if(setsettings.hasError()) + QMessageBox::warning(nullptr,tr("Warning"),tr("Unable to store Print@Home Settings: %1").arg(setsettings.errorString())); + + //force re-init + init(true); +} + +// TODO: THIS SHOULD REALLY BE STORED ON THE SERVER AS CONFIG VALUE!!!!!! +QString MPServerConfig::ticketTemplateCS() +{ + init(); + return msettings.value(TICKETCS); +} + +QString MPServerConfig::voucherTemplateCS() +{ + init(); + return msettings.value(VOUCHERCS); +} + +QString MPServerConfig::invoiceTemplateCS() +{ + init(); + return msettings.value(INVOICECS); +} + +QStringList MPServerConfig::mailContactTypes() +{ + QStringList ret; + for(int id:mailContactTypeIds()) + for(auto ct:mcontacttypes) + if(ct.contacttypeid()==id) + ret.append(ct.contacttype()); + return ret; +} + +QList MPServerConfig::mailContactTypeIds() +{ + init(); + QListret; + for(auto s:msettings.value(MAILCONTACTS).split(' ',QString::SkipEmptyParts)) + ret.append(s.toInt()); + return ret; +} diff --git a/printathome/servercfg.h b/printathome/servercfg.h new file mode 100644 index 0000000..da31ad7 --- /dev/null +++ b/printathome/servercfg.h @@ -0,0 +1,52 @@ +// +// C++ Interface: print @ home, client config +// +// Description: +// +// +// Author: Konrad Rosenbaum , (C) 2016 +// +// Copyright: See README/COPYING.GPL files that come with this distribution +// +// + +#ifndef MSMOKE_PAH_SERVER_H +#define MSMOKE_PAH_SERVER_H + +#include +#include +#include +#include + +#include "MOContactType" + +class QCheckBox; +class QLineEdit; +class QComboBox; +class QSpinBox; + +class MPServerConfig:public QDialog +{ + Q_OBJECT +public: + MPServerConfig(QWidget*parent=nullptr); + + static QStringList mailContactTypes(); + static QList mailContactTypeIds(); +public slots: + void save(); + +private: + QComboBox*mticket,*mvoucher,*minvoice; + QMapmcontacts; + static QMapmsettings; + static QListmcontacttypes; + static QDateTime mlastinit; + + static QString ticketTemplateCS(); + static QString voucherTemplateCS(); + static QString invoiceTemplateCS(); + static void init(bool force=false); +}; + +#endif diff --git a/wob/classes/basics.wolf b/wob/classes/basics.wolf index 47ba998..4d62b18 100644 --- a/wob/classes/basics.wolf +++ b/wob/classes/basics.wolf @@ -60,6 +60,7 @@ + diff --git a/wob/transact/order.wolf b/wob/transact/order.wolf index d55d46d..ab555c6 100644 --- a/wob/transact/order.wolf +++ b/wob/transact/order.wolf @@ -538,7 +538,7 @@ Gets all settings pertaining to Print@Home - + @@ -548,7 +548,7 @@ - + diff --git a/www/inc/wext/order.php b/www/inc/wext/order.php index 4c0e669..cfcb061 100644 --- a/www/inc/wext/order.php +++ b/www/inc/wext/order.php @@ -1001,6 +1001,35 @@ class WOOrder extends WOOrderAbstract //get items $trans->setitems(WOItemAudit::fromTableArrayitem_audit(WTitem_audit::selectFromDB("audituname=".$db->escapeString($uname)." AND audittime>=".$db->escapeInt($oldest),"ORDER BY auditid"))); } + + static public function getPrintAtHomeSettings($trans) + { + $res=array(); + $cfg=WTconfig::selectFromDB(); + foreach($cfg as $c) { + if(strncmp($c->ckey,"printathome:",12)==0) + $r=new WOKeyValuePair(); + $r->setkey(substr($c->ckey,12)); + $r->setvalue($c->cval); + $res[]=$r; + } + $trans->setsettings($res); + + } + + static public function setPrintAtHomeSettings($trans) + { + foreach($trans->getsettings() as $cfg) { + if($cfg->getisnull()){ + $ct=WTconfig::getFromDB("printathome:".$cfg->getkey()); + $ct->deleteFromDb(); + }else{ + $ct=WTconfig::newRow(array("ckey"=> ("printathome:".$cfg->getkey()), "cval"=>$cfg->getvalue())); + $ct->insertOrUpdate(); + } + } + + } };