-Subproject commit 9be5a0ec75e41359a6820c1cf43193eaa1a22853
+Subproject commit f40058f8f817598e0533e9c57c6a4a0d3517afd9
MShippingChange::MShippingChange(QWidget*pa,MOShipping s,int costs)
:QDialog(pa)
{
- all=req->queryGetAllShipping().getshipping();
+ QList<MOShipping>ships=req->queryGetAllShipping().getshipping();
+ all.clear();
+ MSInterface*ifc=MSInterface::instance();
+ foreach(MOShipping ship,ships){
+ if(ifc){
+ if(ifc->checkFlags(ship.flags()))all<<ship;
+ }else all<<ship;
+ }
setWindowTitle(tr("Change Shipping Method"));
int cid=-1;
{
if(temp)temp->updateTemplates(true);
}
+
+bool MSInterface::checkFlags(const QStringList& fl) const
+{
+ foreach(QString f,fl){
+ f=f.trimmed();
+ if(f.isEmpty())continue;
+ if(f[0]=='+'){
+ if(!userflags.contains(f.mid(1)))return false;
+ }else if(f[0]=='-'){
+ if(userflags.contains(f.mid(1)))return false;
+ }else //ooops! invalid flag spec
+ return false;
+ }
+ //survived all tests
+ return true;
+}
///returns whether the user has a particular flag
Q_INVOKABLE bool hasFlag(QString f)const{return userflags.contains(f);}
+ ///checks the flags in the string list and returns true if all of them match
+ Q_INVOKABLE bool checkFlags(const QStringList&)const;
+
+ ///checks the space separeted flags in the string and returns true if all of them match
+ Q_INVOKABLE bool checkFlags(const QString&s)const{return checkFlags(s.split(" "));}
+
/**returns the directory where to store data retrieved from the server*/
Q_INVOKABLE QString dataDir()const;
/**returns the group in which to find settings in QSettings, this group can be used by any class that accesses the profile*/
cartship->addItem(tr("(No Shipping)"),-1);
MTGetAllShipping sh=MTGetAllShipping::query();
QList<MOShipping>ship=sh.getshipping();
+ MSInterface*ifc=MSInterface::instance();
for(int i=0;i<ship.size();i++){
+ if(ifc)if(!ifc->checkFlags(ship[i].flags()))continue;
cartship->addItem(ship[i].description());
cartship->setItemData(cartship->count()-1,(int)ship[i].shipid(),SHIPPING_IDROLE);
cartship->setItemData(cartship->count()-1,(int)ship[i].cost(),SHIPPING_PRICEROLE);
}
MOEvent ev=ge.getevent();
//get Price Category
- QList<MOEventPrice> ep=ev.price();
+ QList<MOEventPrice> ep=ev.priceFiltered();
if(ep.size()==0){
- QMessageBox::warning(this,tr("Warning"),tr("This event has no prices associated. Cannot sell tickets."));
+ QMessageBox::warning(this,tr("Warning"),tr("This event has no prices associated that you can use for sales. Cannot sell tickets."));
return;
}
int pcidx=0;
invoiceaddr->setToolTip(tr("The invoice address is not valid, please chose another one."));
}
if(cartship->currentIndex()>0 && cord.shippingtypeid().isNull()){
- QPalette red2=QComboBox().palette();red2.setColor(QPalette::Window,Qt::red);
+ QPalette red2=QComboBox().palette();
+ red2.setColor(QPalette::Window,Qt::red);
+ red2.setColor(QPalette::Button,Qt::red);
cartship->setPalette(red2);
cartship->setToolTip(tr("Shipping Type does not exist or you do not have permission to use it."));
}
{
return unix2dateTime(end());
}
+
+QList< MOEventPrice > MOEvent::priceFiltered() const
+{
+ QList<MOEventPrice> ep=price();
+ QList<MOEventPrice> ret;
+ MSInterface *ifc=MSInterface::instance();
+ if(ifc==0)return ep;
+ foreach(MOEventPrice p,ep){
+ if(ifc->checkFlags(p.flags()))
+ ret<<p;
+ }
+ return ret;
+}
/**returns whether the event is valid. an event can be invalid if it is uninitialized (negative ID) or the server request failed*/
bool isValid()const{return !eventid().isNull() && eventid().value()>0;}
+
+ ///returns only the prices that this user can order for
+ QList<MOEventPrice> priceFiltered()const;
};
Q_DECLARE_METATYPE(MOEvent)
{
if($this->prop_shippingtypeid !== null){
$ship=WTshipping::getFromDB($this->prop_shippingtypeid);
+ //check it exists
if(!is_a($ship,"WTshipping")){
$this->prop_shippingtypeid=null;
return false;
}
+ //check we have the right
+ global $session;
+ if(!$session->checkFlags($ship->flags)){
+ $this->prop_shippingtypeid=null;
+ return false;
+ }
}
return true;
}
/**helper function for createOrder: verifies customer settings*/
private function verifyTickets($trans,$salestop)
{
+ global $session;
$ret=true;
$evseats=array();
$evprice=array();
+ $pcat=array();
$now=time();
if($salestop>0)$now+=$salestop*3600;
foreach($this->prop_tickets as &$tick){
$ret=false;
continue;
}
+ //check event flags
+ if(!$session->checkFlags($ev->flags)){
+ $tick->setstatus(WOCartTicket::Invalid);
+ $ret=false;
+ continue;
+ }
+ //verify amount of seats in event
if(!array_key_exists($evid,$evseats))
$evseats[$evid]=$this->eventTicketStatistics($evid,$ev->capacity,$evprice);
//verify price category, set price
$ret=false;
continue;
}
+ //check that we have the right to sell this category
+ if(!array_key_exists($pcid,$pcat))
+ $pcat[$pcid]=$session->checkFlags(WTpricecategory::getFromDB($pcid)->flags);
+ if(!$pcat[$pcid]){
+ $tick->setstatus(WOCartTicket::Invalid);
+ $ret=false;
+ continue;
+ }
+ //set the price
$tick->setprice($evprice[$evid][$pcid]);
//check enough seats for event
// print_r($evseats);print_r($tick);
/**XML iface: get all events*/
public static function getAllEvents($trans)
{
+ //get all of them
$evlst=WOEvent::fromTableArrayevent(WTevent::selectFromDB("","ORDER BY starttime"));
- $trans->setevents($evlst);
+ //filter them by flags
+ $evlst2=array();
+ global $session;
+ foreach($evlst as $ev){
+ if($session->checkFlags($ev->getflags()))
+ $evlst2[]=$ev;
+ }
+ //return...
+ $trans->setevents($evlst2);
}
/**XML iface: get list of events*/
//get shipping
$shipid=$trans->getshippingid();
// print_r($shipid);
+ global $session;
if($shipid===false)$shipid=-1;else $shipid=$shipid+0;
if($shipid>=0){
$ship=WTshipping::getFromDB($shipid);
$trans->abortWithError(tr("Invalid shipping ID."));
return;
}
+ if(!$session->checkFlags($ship->flags)){
+ $trans->abortWithError(tr("You cannot use this shipping type."));
+ return;
+ }
}
//get order
$ord=WTorder::getFromDB($trans->getorderid());