show comments in event summary
authorkonrad <konrad@6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33>
Wed, 12 Nov 2008 15:36:58 +0000 (15:36 +0000)
committerkonrad <konrad@6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33>
Wed, 12 Nov 2008 15:36:58 +0000 (15:36 +0000)
git-svn-id: https://silmor.de/svn/softmagic/smoke/trunk@178 6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33

src/eventsummary.cpp
src/eventsummary.h
src/overview.cpp
www/inc/classes/event.php

index cf45cd4..de1baf9 100644 (file)
 #include <QPushButton>
 #include <QStandardItemModel>
 #include <QTableView>
+#include <QTextBrowser>
+
+inline QString htmlize(QString str)
+{
+       QString out;
+       for(int i=0;i<str.size();i++){
+               QChar c=str[i];
+               ushort ci=c.unicode();
+               if(c=='<')out+="&lt;";else
+               if(c=='>')out+="&gt;";else
+               if(c=='&')out+="&amp;";else
+               if(c=='\n')out+="<br/>\n";else
+               if(c.isSpace()||(c.unicode()>=32&&c.unicode()<=0x7f))out+=c;
+               else out+="&#"+QString::number(ci)+";";
+       }
+       return out;
+}
+
 
 MEventSummary::MEventSummary(QWidget*par,MWebRequest*rq,int eid)
        :QDialog(par)
@@ -34,12 +52,16 @@ MEventSummary::MEventSummary(QWidget*par,MWebRequest*rq,int eid)
        //get event data
        getEventData();
        getSummaryData();
-       //layout
+       //layout/tabs
        setWindowTitle(tr("Summary for Event %1").arg(title));
        QVBoxLayout*vl;
        setLayout(vl=new QVBoxLayout);
+       QTabWidget*tab;
+       vl->addWidget(tab=new QTabWidget);
+       QWidget*w;
+       tab->addTab(w=new QWidget,tr("Summary"));
        QGridLayout*gl;
-       vl->addLayout(gl=new QGridLayout,0);
+       w->setLayout(gl=new QGridLayout);
        int rc=0;
        gl->addWidget(new QLabel(tr("Title:")),rc,0);
        gl->addWidget(new QLabel(title),rc,1);
@@ -62,7 +84,7 @@ MEventSummary::MEventSummary(QWidget*par,MWebRequest*rq,int eid)
        
        QTableView*table;
        QStandardItemModel*model;
-       vl->addWidget(table=new QTableView,10);
+       tab->addTab(table=new QTableView,tr("Tickets"));
        table->setEditTriggers(QAbstractItemView::NoEditTriggers);
        table->setModel(model=new QStandardItemModel(this));
        model->insertColumns(0,4);
@@ -78,6 +100,20 @@ MEventSummary::MEventSummary(QWidget*par,MWebRequest*rq,int eid)
        }
        table->resizeColumnsToContents();
        
+       QTextBrowser *tb;
+       tab->addTab(tb=new QTextBrowser,tr("Comments"));
+       QString cmt;
+       for(int i=0;i<comments.size();i++){
+               Comment c=comments[i];
+               if(cmt=="")cmt="<html><body>";
+               else cmt+="<hr/>";
+               cmt+="<b>"+tr("Order: ");
+               cmt+=QString::number(c.orderid);
+               cmt+="</b><br/><b>"+tr("Customer: ")+htmlize(c.custname);
+               cmt+="</b><p/>"+htmlize(c.comment);
+       }
+       tb->setHtml(cmt);
+       
        QHBoxLayout*hl;
        vl->addSpacing(15);
        vl->addLayout(hl=new QHBoxLayout,0);
@@ -136,6 +172,17 @@ void MEventSummary::getSummaryData()
                tc.unused=el.attribute("unused","0").toInt();
                tickets.append(tc);
        }
+       nl=sum.elementsByTagName("Comment");
+       for(int i=0;i<nl.size();i++){
+               QDomElement el=nl.at(i).toElement();
+               if(el.isNull())continue;
+               Comment c;
+               c.custid=el.attribute("customerid","-1").toInt();
+               c.custname=el.attribute("customer");
+               c.orderid=el.attribute("orderid","-1").toInt();
+               c.comment=el.text();
+               comments.append(c);
+       }
 }
 
 void MEventSummary::print()
index 9f4a560..9efefb2 100644 (file)
@@ -50,6 +50,11 @@ class MEventSummary:public QDialog
                        int price,bought,used,unused;
                };
                QList<Tickets>tickets;
+               struct Comment{
+                       int custid,orderid;
+                       QString custname,comment;
+               };
+               QList<Comment>comments;
                
                //get basic data about event
                void getEventData();
index cc47cb1..278a732 100644 (file)
@@ -112,7 +112,7 @@ MOverview::MOverview(MWebRequest*mw,QString pk)
        connect(p,SIGNAL(clicked()),this,SLOT(eventOrderTicket()));
        p->setEnabled(req->hasRole("createorder"));
        vl->addSpacing(15);
-       vl->addWidget(p=new QPushButton(tr("Ticket Summary...")),0);
+       vl->addWidget(p=new QPushButton(tr("Event Summary...")),0);
        connect(p,SIGNAL(clicked()),this,SLOT(eventSummary()));
        p->setEnabled(req->hasRole("eventsummary"));
        vl->addSpacing(15);
index 6c98e5a..6eb2f35 100644 (file)
@@ -299,7 +299,7 @@ function getEventSummaryXml($evid)
 {
        global $db;
        //collect statistics
-       $res=$db->select("ticket","price,status","eventid=".$db->escapeInt($evid));
+       $res=$db->select("ticket","price,status,orderid","eventid=".$db->escapeInt($evid));
        $tcreserve=0;
        $tccancel=0;
        $totalmoney=0;
@@ -307,6 +307,7 @@ function getEventSummaryXml($evid)
        $tcbought=array();
        $tcused=array();
        $tcall=array();
+       $oids=array();
        foreach($res as $tc){
                switch($tc["status"]){
                        case TICKET_RESERVED:$tcreserve++;break;
@@ -336,6 +337,19 @@ function getEventSummaryXml($evid)
                                $total++;
                                break;
                }
+               if($tc["orderid"]!==false && !in_array($tc["orderid"],$oids))
+                       $oids[]=$tc["orderid"];
+       }
+       //get comments
+       sort($oids);
+       $comments=array();
+       foreach($oids as $oid){
+               $res=$db->select("order","comments,customerid","orderid=".$db->escapeInt($oid));
+               if($res===false || count($res)==0)continue;
+               if($res[0]["comments"]===false || trim($res[0]["comments"])=="")continue;
+               $res2=$db->select("customer","name","customerid=".$db->escapeInt($res[0]["customerid"]));
+               if($res2===false || count($res2)==0)continue;
+               $comments[]=array("cid"=>$res[0]["customerid"],"cs"=>$res2[0]["name"],"cm"=>$res[0]["comments"],"oid"=>$oid);
        }
        //create XML
        $xml=new DomDocument;
@@ -361,6 +375,14 @@ function getEventSummaryXml($evid)
                        $p->setAttribute("used",0);
                $doc->appendChild($p);
        }
+       foreach($comments as $comment){
+               $p=$xml->createElement("Comment");
+               $p->setAttribute("customerid",$comment["cid"]);
+               $p->setAttribute("customer",$comment["cs"]);
+               $p->setAttribute("orderid",$comment["oid"]);
+               $p->appendChild($xml->createTextNode($comment["cm"]));
+               $doc->appendChild($p);
+       }
        $xml->appendChild($doc);
        header("X-MagicSmoke-Status: Ok");
        print($xml->saveXml());