QMessageBox::warning(0,tr("Connection Error"),tr("There were problems while authenticating the server. Aborting. Check your configuration."));
}
}
+
+void MSInterface::updateTemplates()
+{
+ if(temp)temp->updateTemplates(true);
+}
void setSessionId(QString sid){m_sessid=sid;}
/**handles SSL errors*/
virtual void sslErrors(const QList<QSslError>&);
-
+ /**force template store to update its templates*/
+ void updateTemplates();
+
private:
QString profileid,m_sessid,m_uname,m_passwd,m_host,m_hostkey;
mutable QList<Right>userrights;
#include "msinterface.h"
#include "passwdchg.h"
#include "customerdlg.h"
+#include "templatedlg.h"
#include "overview.h"
#include "eventstab.h"
m->addAction(tr("Change my &Password"),this,SLOT(setMyPassword()))
->setEnabled(req->hasRight(req->RChangeMyPassword));
m->addSeparator();
- m->addAction(tr("&Edit Templates..."),req,SLOT(editTemplates()));
+ m->addAction(tr("&Edit Templates..."),this,SLOT(editTemplates()));
m->addAction(tr("&Update Templates Now"),req,SLOT(updateTemplates()));
m->addSeparator();
m->addAction(tr("&Close Session"),this,SLOT(close()));
MAclWindow::showWindow(this);
}
+void MOverview::editTemplates()
+{
+ MTemplateEditor te(MSInterface::instance()->templateStore());
+ te.exec();
+}
+
/**********************************************/
MBackupDialog::MBackupDialog(QWidget*par,QString pk)
/**open ACL/user admin window*/
void aclWindow();
+ /**open template editor*/
+ void editTemplates();
+
private:
//the profile associated with this session
QString profilekey;
}
bool MTemplateStore::setTemplate(QString n,QString f)
-{/*TODO
+{
//very rough sanity check
QRegExp fregexp("[a-z0-9_\\.,]+");
if(!fregexp.exactMatch(n))return false;
QByteArray ba=fl.readAll();
fl.close();
//send to server
- if(!req->request("settemplate",n.toUtf8()+"\n"+ba))
- return false;
- if(req->responseStatus()!=MWebRequest::Ok)
+ MTSetTemplate st=req->querySetTemplate(n,ba,"");
+ if(st.hasError())
return false;
//delete it from cache, so it is retrieved again; force retrieval
//TODO: the server returns the hash (since dec08), use it and update the cache without retrieval
set.setValue("templates/"+profileid+"/lastupdate",0);
QFile(req->dataDir()+"/templates/"+n).remove();
//return success
- return true;*/return false;
+ return true;
}
bool MTemplateStore::deleteTemplate(QString n)
-{/*TODO
+{
//very rough sanity check
QRegExp fregexp("[a-z0-9_\\.,]+");
if(!fregexp.exactMatch(n))return false;
//send to server
- if(!req->request("deletetemplate",n.toUtf8()))
- return false;
- if(req->responseStatus()!=MWebRequest::Ok)
+ MTDeleteTemplate dt=req->queryDeleteTemplate(n);
+ if(dt.hasError())
return false;
//delete it from cache
QSettings set;
set.remove("templates/"+profileid+"/"+n);
QFile(req->dataDir()+"/templates/"+n).remove();
- return true;*/return false;
+ return true;
}
bool MTemplateStore::setTemplateDescription(QString n,QString d)
-{/*TODO
+{
//very rough sanity check
QRegExp fregexp("[a-z0-9_\\.,]+");
if(!fregexp.exactMatch(n))return false;
qDebug("setting %s '%s' -> '%s'",n.toAscii().data(),o.toAscii().data(),d.toAscii().data());
if(o==d)return true;
//send to server
- if(!req->request("settemplatedescription",n.toUtf8()+"\n"+d.toUtf8()))
- return false;
- if(req->responseStatus()!=MWebRequest::Ok)
+ MTSetTemplateDescription std=req->querySetTemplateDescription(n,d);
+ if(std.hasError())
return false;
//update internal description
set.setValue("description",d);
//return success
- return true;*/return false;
+ return true;
}
QList<MTemplate> MTemplateStore::allTemplates()
<Var name="templatefile" type="Template"/>
</Output>
</Transaction>
+
+ <Transaction name="SetTemplate">
+ <Input>
+ <Var name="filename" type="astring"/>
+ <Var name="templatedata" type="blob"/>
+ <Var name="description" type="string"/>
+ </Input>
+ <Call lang="php" method="WOTemplate::setFile($this);"/>
+ <Output>
+ <Var name="templatefile" type="Template"/>
+ </Output>
+ </Transaction>
+ <Transaction name="SetTemplateDescription">
+ <Input>
+ <Var name="filename" type="astring"/>
+ <Var name="description" type="string"/>
+ </Input>
+ <Call lang="php" method="WOTemplate::setTemplateDescription($this);"/>
+ </Transaction>
+ <Transaction name="DeleteTemplate">
+ <Input>
+ <Var name="filename" type="astring"/>
+ </Input>
+ <Call lang="php" method="WOTemplate::deleteTemplate($this);"/>
+ </Transaction>
</Wolf>
//TODO: filter by flags
$trans->settemplatefile(WOTemplate::fromTabletemplate(WTtemplate::getFromDB($trans->getfilename())));
}
+
+ /**called by the SetTemplate transaction*/
+ static public function setFile($trans)
+ {
+ //find it
+ $tm=WTtemplate::getFromDB($trans->getfilename());
+ if($tm===false)
+ $tm=WTtemplate::newRow();
+ //set data
+ $tm->filename=$trans->getfilename();
+ $tm->description=$trans->getdescription();
+ $tm->content=$trans->gettemplatedata();
+ $tm->hash=md5($trans->gettemplatedata());
+ $tm->dolog=false;
+ $tm->flags="";
+ //update
+ $tm->insertOrUpdate();
+ //return
+ $trans->settemplatefile(WOTemplate::fromTabletemplate($tm));
+ }
+ /**called by the SetTemplateDescription transaction*/
+ static public function setTemplateDescription($trans)
+ {
+ //find it
+ $tm=WTtemplate::getFromDB($trans->getfilename());
+ if($tm===false){
+ $trans->abortWithError(tr("No such template."));
+ return;
+ }
+ //overwrite
+ $tm->description=$trans->getdescription();
+ $tm->update();
+ }
+ /**called by the DeleteTemplate transaction*/
+ static public function deleteTemplate($trans)
+ {
+ //find it
+ $tm=WTtemplate::getFromDB($trans->getfilename());
+ if($tm===false){
+ $trans->abortWithError(tr("No such template."));
+ return;
+ }
+ //delete
+ $tm->deleteFromDb();
+ }
};
?>
\ No newline at end of file