re-activated user tab, role and host handling is still missing
authorkonrad <konrad@6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33>
Mon, 28 Dec 2009 17:36:56 +0000 (17:36 +0000)
committerkonrad <konrad@6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33>
Mon, 28 Dec 2009 17:36:56 +0000 (17:36 +0000)
git-svn-id: https://silmor.de/svn/softmagic/smoke/trunk@364 6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33

18 files changed:
src/dialogs/checkdlg.cpp [new file with mode: 0644]
src/dialogs/checkdlg.h [moved from src/widgets/checkdlg.h with 51% similarity]
src/dialogs/dialogs.pri
src/iface/MORole.h [new file with mode: 0644]
src/mwin/acltabs.cpp
src/mwin/carttab.h
src/mwin/overview.cpp
src/widgets/checkdlg.cpp [deleted file]
src/widgets/widgets.pri
wob/user.wolf
woc/phpout.cpp
www/inc/loader.php
www/inc/machine/autoload.php
www/inc/machine/muser.php [new file with mode: 0644]
www/inc/machine/session.php
www/inc/wbase/table.php
www/inc/wext/autoload.php [new file with mode: 0644]
www/inc/wext/role.php [new file with mode: 0644]

diff --git a/src/dialogs/checkdlg.cpp b/src/dialogs/checkdlg.cpp
new file mode 100644 (file)
index 0000000..79135ff
--- /dev/null
@@ -0,0 +1,55 @@
+//
+// C++ Implementation: checkdlg
+//
+// Description: 
+//
+//
+// Author: Konrad Rosenbaum <konrad@silmor.de>, (C) 2008
+//
+// Copyright: See README/COPYING files that come with this distribution
+//
+//
+
+#include "checkdlg.h"
+
+#include <QCheckBox>
+#include <QScrollArea>
+#include <QPushButton>
+#include <QBoxLayout>
+
+MCheckDialog::MCheckDialog(QWidget*parent,const MCheckList&checks,QString title)
+       :QDialog(parent),m_list(checks)
+{
+       setWindowTitle(title);
+       //basic layout
+       QVBoxLayout *vl=new QVBoxLayout;
+       setLayout(vl);
+       QScrollArea *sa=new QScrollArea;
+       vl->addWidget(sa,10);
+       QHBoxLayout *hl=new QHBoxLayout;
+       vl->addLayout(hl,0);
+       hl->addStretch(10);
+       QPushButton*p;
+       hl->addWidget(p=new QPushButton(tr("Ok")),0);
+       connect(p,SIGNAL(clicked()),this,SLOT(accept()));
+       hl->addWidget(p=new QPushButton(tr("Cancel")),0);
+       connect(p,SIGNAL(clicked()),this,SLOT(reject()));
+       //fill area
+       QWidget*w=new QWidget;
+       w->setLayout(vl=new QVBoxLayout);
+       for(int i=0;i<m_list.size();i++){
+               QCheckBox *cb=new QCheckBox(m_list[i].label());
+               cb->setChecked(m_list[i].isSet());
+               vl->addWidget(cb);
+               m_boxes.append(cb);
+       }
+       sa->setWidget(w);
+}
+
+MCheckList MCheckDialog::getCheckList()const
+{
+       for(int i=0;i<m_boxes.size();i++)
+               m_list[i].set(m_boxes[i]->isChecked());
+       return m_list;
+}
+
similarity index 51%
rename from src/widgets/checkdlg.h
rename to src/dialogs/checkdlg.h
index e96cddb..a79a6cc 100644 (file)
 
 class QCheckBox;
 
-/**abstract base class for items that can be displayed in a MCheckDialog*/
+/**class for items that can be displayed in a MCheckDialog*/
 class MCheckItem
 {
        public:
-               /**constructs an empty check item*/
-               MCheckItem();
-               /**deletes the check item*/
-               virtual ~MCheckItem();
+               /**constructs a check item*/
+               MCheckItem(QString key=QString(),bool isset=false,QString label=QString())
+               {m_key=key;m_set=isset;if(label!="")m_label=label;else m_label=m_key;}
                
                /**overwrite this to return a label that can be displayed*/
-               virtual QString label()const=0;
+               virtual QString label()const{return m_label;}
                /**overwrite this to return a key string that identifies the item (default implementation returns the label)*/
-               virtual QString key()const;
+               virtual QString key()const{return m_key;}
                /**overwrite this to return whether the item is checked*/
-               virtual bool isSet()const=0;
+               virtual bool isSet()const{return m_set;}
                /**overwrite this to change the checking status of the item*/
-               virtual void set(bool)=0;
+               virtual void set(bool b){m_set=b;}
                
        protected:
-               friend class MCheckList;
-               /**overwrite this to creat an exact copy of the item (must be implemented and must return non-NULL)*/
-               virtual MCheckItem* copy()const=0;
+               QString m_key,m_label;
+               bool m_set;
 };
 
 /**implements a list of checkable items*/
-class MCheckList
-{
-       public:
-               /**instantiate an empty list*/
-               MCheckList();
-               /**creates an exact copy of the list (uses MCheckItem::copy() )*/
-               MCheckList(const MCheckList&);
-               /**deletes the list*/
-               ~MCheckList();
-               
-               /**adds an item to the list*/
-               void addItem(MCheckItem*);
-               /**returns the size of the list*/
-               int size()const;
-               
-               /**returns a writable reference to an item*/
-               MCheckItem& operator[](int);
-               /**returns a const reference to an item*/
-               const MCheckItem& operator[](int)const;
-               
-               /**makes this list an exact copy of the argument*/
-               MCheckList& operator=(const MCheckList&);
-       private:
-               QList<MCheckItem*> m_items;
-};
+typedef QList<MCheckItem> MCheckList;
 
 /**a dialog that consists of check boxes in a QScrollArea */
 class MCheckDialog:public QDialog
index c5377a2..0e72244 100644 (file)
@@ -7,6 +7,7 @@ HEADERS += \
        dialogs/login.h \
        dialogs/shipping.h \
        dialogs/customerdlg.h \
+       dialogs/checkdlg.h \
        dialogs/passwdchg.h
 
 SOURCES += \
@@ -18,6 +19,7 @@ SOURCES += \
        dialogs/login.cpp \
        dialogs/shipping.cpp \
        dialogs/customerdlg.cpp \
+       dialogs/checkdlg.cpp \
        dialogs/passwdchg.cpp
 
 INCLUDEPATH += ./dialogs
\ No newline at end of file
diff --git a/src/iface/MORole.h b/src/iface/MORole.h
new file mode 100644 (file)
index 0000000..ac961a5
--- /dev/null
@@ -0,0 +1,19 @@
+//
+// C++ Interface: unabstract
+//
+// Description: removes abstract flag from classes that only need to be abstract in PHP
+//
+//
+// Author: Konrad Rosenbaum <konrad@silmor.de>, (C) 2009
+//
+// Copyright: See README/COPYING files that come with this distribution
+//
+//
+
+#ifndef MAGICSMOKE_MOROLE_H
+#define MAGICSMOKE_MOROLE_H
+
+#include "MORoleAbstract.h"
+typedef MORoleAbstract MORole;
+
+#endif
\ No newline at end of file
index 94233a8..a6db96c 100644 (file)
 //
 
 #include "checkdlg.h"
-// #include "main.h"
-// #include "misc.h"
 #include "msinterface.h"
+#include "passwdchg.h"
 
 #include "acltabs.h"
 
-// #include <QApplication>
 #include <QBoxLayout>
-// #include <QCheckBox>
-// #include <QComboBox>
-// #include <QCryptographicHash>
-// #include <QDomDocument>
-// #include <QDomElement>
-// #include <QFile>
-// #include <QFileDialog>
-// #include <QFrame>
 #include <QInputDialog>
 #include <QLabel>
 #include <QLineEdit>
-// #include <QMenu>
-// #include <QMenuBar>
 #include <QMessageBox>
 #include <QPushButton>
-// #include <QSettings>
-// #include <QSpinBox>
 #include <QStandardItemModel>
-// #include <QStatusBar>
-// #include <QTabWidget>
 #include <QTableView>
-// #include <QTextEdit>
 
 #define req (MSInterface::instance())
 
@@ -59,27 +42,26 @@ MUserTab::MUserTab(QString pk)
        hl->addLayout(vl=new QVBoxLayout,0);
        vl->addWidget(p=new QPushButton(tr("New User...")),0);
        connect(p,SIGNAL(clicked()),this,SLOT(newUser()));
-       p->setEnabled(req->hasRole("adduser"));
+       p->setEnabled(req->hasRight(req->RCreateUser));
        vl->addWidget(p=new QPushButton(tr("Delete User...")),0);
        connect(p,SIGNAL(clicked()),this,SLOT(deleteUser()));
-       p->setEnabled(req->hasRole("deleteuser"));
+       p->setEnabled(req->hasRight(req->RDeleteUser));
        vl->addSpacing(20);
        vl->addWidget(p=new QPushButton(tr("Description...")),0);
        connect(p,SIGNAL(clicked()),this,SLOT(editUserDescription()));
-       p->setEnabled(req->hasRole("setuserdescription"));
+       p->setEnabled(req->hasRight(req->RSetUserDescription));
        vl->addWidget(p=new QPushButton(tr("Hosts...")),0);
        connect(p,SIGNAL(clicked()),this,SLOT(editUserHosts()));
-       p->setEnabled(req->hasRole("getuserhosts"));
+       p->setEnabled(req->hasRight(req->RGetUserHosts));
        vl->addWidget(p=new QPushButton(tr("Roles...")),0);
        connect(p,SIGNAL(clicked()),this,SLOT(editUserRoles()));
-       p->setEnabled(req->hasRole("getuseracl"));
+       p->setEnabled(req->hasRight(req->RGetUserRoles));
        vl->addWidget(p=new QPushButton(tr("Set Password...")),0);
        connect(p,SIGNAL(clicked()),this,SLOT(setUserPassword()));
-       p->setEnabled(req->hasRole("setpasswd"));
+       p->setEnabled(req->hasRight(req->RChangePassword));
        vl->addStretch(10);
        
-       //TODO: convert to right instead role
-       if(req->hasRole("getusers")){
+       if(req->hasRight(req->RGetAllUsers)){
                updateUsers();
        }else{
                setEnabled(false);
@@ -143,7 +125,7 @@ void MUserTab::deleteUser()
        QString rp=QInputDialog::getItem(this,tr("Delete User"),tr("Select which user will inherit this users database objects:"),rplc,0,false,&ok);
        if(!ok)return;
        //delete
-       MTDeleteUser ret=req->queryDeleteUser(name,rp);
+       MTDeleteUser ret=req->queryDeleteUser(name,rp[0]=='('?"":rp);
        if(ret.hasError())
                QMessageBox::warning(this,tr("Error"),tr("Cannot delete user: %1").arg(ret.errorString()));
        updateUsers();
@@ -159,7 +141,7 @@ void MUserTab::editUserDescription()
        QString descr=usermodel->data(usermodel->index(sel.row(),1)).toString();
        //edit descr
        bool ok;
-       descr=QInputDialog::getText(this,tr("Edit Description"),tr("Descriptionof user %1:").arg(name),QLineEdit::Normal,descr,&ok);
+       descr=QInputDialog::getText(this,tr("Edit Description"),tr("Description of user %1:").arg(name),QLineEdit::Normal,descr,&ok);
        if(ok)
                req->querySetUserDescription(name,descr);
        //update
@@ -167,18 +149,34 @@ void MUserTab::editUserDescription()
 }
 
 void MUserTab::editUserRoles()
-{/*TODO
+{
        //get selection
        QModelIndex sel=usertable->currentIndex();
        if(!sel.isValid())return;
        //get uname & descr
        QString name=usermodel->data(usermodel->index(sel.row(),0)).toString();
        //...
-       MOUser usr(req,name);
-       MCheckList acl=usr.getRoles();
-       MCheckDialog cd(this,acl,"Edit ACL of user "+name);
-       if(cd.exec()==QDialog::Accepted)
-               usr.setRoles(cd.getCheckList());*/
+       MTGetUserRoles gr=req->queryGetUserRoles(name);
+       if(gr.hasError()){
+               QMessageBox::warning(this,tr("Warning"),tr("Cannot retrieve user roles: %1").arg(gr.errorString()));
+               return;
+       }
+       MTGetAllRoles ar=req->queryGetAllRoles();
+       if(ar.hasError()){
+               QMessageBox::warning(this,tr("Warning"),tr("Cannot retrieve role descriptions: %1").arg(ar.errorString()));
+               return;
+       }
+       MCheckList acl;
+       QStringList urole=gr.getroles();
+       QList<MORole>aroles=ar.getroles();
+       for(int i=0;i<aroles.size();i++){
+               QString nm=aroles[i].name();
+               QString lb=nm+": "+aroles[i].description();
+               acl<<MCheckItem(nm,urole.contains(nm),lb);
+       }
+       MCheckDialog cd(this,acl,"Edit Roles of user "+name);
+       if(cd.exec()==QDialog::Accepted);
+//             usr.setRoles(cd.getCheckList());
 }
 
 void MUserTab::editUserHosts()
@@ -197,7 +195,7 @@ void MUserTab::editUserHosts()
 }
 
 void MUserTab::setUserPassword()
-{/*TODO
+{
        //get selection
        QModelIndex sel=usertable->currentIndex();
        if(!sel.isValid())return;
@@ -211,9 +209,11 @@ void MUserTab::setUserPassword()
                QMessageBox::warning(this,tr("Warning"),tr("The password must be non-empty and both lines must match"));
                return;
        }
-       //...
-       MUser usr(req,name);
-       usr.changePassword(p);*/
+       //query
+       MTChangePassword cp=req->queryChangePassword(name,p);
+       if(cp.hasError()){
+               QMessageBox::warning(this,tr("Warning"),tr("Error while setting password: %1").arg(cp.errorString()));
+       }
 }
 
 /*****************************************************************************/
index 976efb6..a0bb3a9 100644 (file)
@@ -31,6 +31,7 @@ class QSpinBox;
 class QStandardItemModel;
 class QTabWidget;
 class QTableView;
+class QTextEdit;
 
 class MSInterface;
 
index b34f36c..a56190c 100644 (file)
@@ -150,7 +150,7 @@ MOverview::MOverview(QString pk)
        if(!req->hasRole("getorderlist")){
                tab->setTabEnabled(tab->indexOf(ordertab),false);
        }
-       if(!req->hasRole("getusers")){
+       if(!req->hasRight(req->RGetAllUsers)){
                tab->setTabEnabled(tab->indexOf(usertab),false);
        }
        if(!req->hasRole("gethosts")){
diff --git a/src/widgets/checkdlg.cpp b/src/widgets/checkdlg.cpp
deleted file mode 100644 (file)
index 2d5a3f6..0000000
+++ /dev/null
@@ -1,104 +0,0 @@
-//
-// C++ Implementation: checkdlg
-//
-// Description: 
-//
-//
-// Author: Konrad Rosenbaum <konrad@silmor.de>, (C) 2008
-//
-// Copyright: See README/COPYING files that come with this distribution
-//
-//
-
-#include "checkdlg.h"
-
-#include <QCheckBox>
-#include <QScrollArea>
-#include <QPushButton>
-#include <QBoxLayout>
-
-MCheckDialog::MCheckDialog(QWidget*parent,const MCheckList&checks,QString title)
-       :QDialog(parent),m_list(checks)
-{
-       setWindowTitle(title);
-       //basic layout
-       QVBoxLayout *vl=new QVBoxLayout;
-       setLayout(vl);
-       QScrollArea *sa=new QScrollArea;
-       vl->addWidget(sa,10);
-       QHBoxLayout *hl=new QHBoxLayout;
-       vl->addLayout(hl,0);
-       hl->addStretch(10);
-       QPushButton*p;
-       hl->addWidget(p=new QPushButton(tr("Ok")),0);
-       connect(p,SIGNAL(clicked()),this,SLOT(accept()));
-       hl->addWidget(p=new QPushButton(tr("Cancel")),0);
-       connect(p,SIGNAL(clicked()),this,SLOT(reject()));
-       //fill area
-       QWidget*w=new QWidget;
-       w->setLayout(vl=new QVBoxLayout);
-       for(int i=0;i<m_list.size();i++){
-               QCheckBox *cb=new QCheckBox(m_list[i].label());
-               cb->setChecked(m_list[i].isSet());
-               vl->addWidget(cb);
-               m_boxes.append(cb);
-       }
-       sa->setWidget(w);
-}
-
-MCheckList MCheckDialog::getCheckList()const
-{
-       for(int i=0;i<m_boxes.size();i++)
-               m_list[i].set(m_boxes[i]->isChecked());
-       return m_list;
-}
-
-/**************************************************/
-
-MCheckItem::MCheckItem(){}
-MCheckItem::~MCheckItem(){}
-
-QString MCheckItem::key()const{qDebug("???????????");return label();}
-
-MCheckList::MCheckList(){}
-
-MCheckList::MCheckList(const MCheckList&l)
-{
-       for(int i=0;i<m_items.size();i++)
-               delete m_items[i];
-       m_items.clear();
-       for(int i=0;i<l.m_items.size();i++)
-               m_items.append(l.m_items[i]->copy());
-}
-
-MCheckList& MCheckList::operator=(const MCheckList&l)
-{
-       for(int i=0;i<l.m_items.size();i++)
-               m_items.append(l.m_items[i]->copy());
-}
-
-MCheckList::~MCheckList()
-{
-       for(int i=0;i<m_items.size();i++)
-               delete m_items[i];
-}
-
-void MCheckList::addItem(MCheckItem*i)
-{
-       if(i!=0)m_items.append(i);
-}
-
-int MCheckList::size()const
-{
-       return m_items.size();
-}
-
-MCheckItem& MCheckList::operator[](int i)
-{
-       return * m_items[i];
-}
-
-const MCheckItem& MCheckList::operator[](int i)const
-{
-       return * m_items[i];
-}
index 4ff2b0f..b6ff5eb 100644 (file)
@@ -1,14 +1,12 @@
 HEADERS += \
        widgets/waitcursor.h \
        widgets/centbox.h \
-       widgets/checkdlg.h \
        widgets/listview.h \
        widgets/treeview.h
 
 SOURCES += \
        widgets/waitcursor.cpp \
        widgets/centbox.cpp \
-       widgets/checkdlg.cpp \
        widgets/listview.cpp \
        widgets/treeview.cpp
 
index 555f34d..4026b7b 100644 (file)
        </Transaction>
        
        <Class name="User">
+               <Doc>This class represents the main information about users: login name plus description. Passwords are never carried towards the client, more detailed info is contained in other classes.</Doc>
                <Property name="name" type="astring"/>
                <Property name="description" type="string"/>
+               <Mapping table="user">
+                       <Map column="uname" property="name"/>
+                       <Map column="description"/>
+               </Mapping>
        </Class>
        
        <Class name="Host">
        
        <Transaction name="GetAllUsers">
                <Input/>
+               <Call lang="php" method="$this->setusers(WOUser::fromTableArrayuser(WTuser::selectFromDB()));"/>
                <Output>
                        <Var name="users" type="List:User"/>
                </Output>
                        <Var name="password" type="string"/>
                        <Var name="description" type="string"/>
                </Input>
+               <Call lang="php" method="MachineUser::createUser($this);"/>
                <Output>
                        <Var name="user" type="User"/>
                </Output>
                        <Var name="username" type="astring"/>
                        <Var name="password" type="string"/>
                </Input>
+               <Call lang="php" method="MachineUser::changePasswd($this);"/>
                <Output/>
        </Transaction>
        
                        <Var name="username" type="astring"/>
                        <Var name="mergewithuser" type="astring"/>
                </Input>
+               <Call lang="php" method="MachineUser::deleteUser($this);"/>
        </Transaction>
        
        <Transaction name="SetUserDescription">
                        <Var name="username" type="astring"/>
                        <Var name="description" type="string"/>
                </Input>
+               <Call lang="php" method="MachineUser::setUserDescription($this);"/>
        </Transaction>
        
        <Transaction name="GetUserRoles">
                <Input>
                        <Var name="username" type="astring"/>
                </Input>
+               <Call lang="php" method="MachineUser::getUserRoles($this);"/>
                <Output>
                        <Var name="roles" type="List:string"/>
-                       <Var name="rights" type="List:astring"/>
                </Output>
        </Transaction>
        
                        <Var name="username" type="astring"/>
                        <Var name="roles" type="List:string"/>
                </Input>
+               <Call lang="php" method="MachineUser::setUserRoles($this);"/>;
                <Output/>
        </Transaction>
        
+       <Class name="Role" abstract="yes">
+               <Property name="name" type="string"/>
+               <Property name="description" type="string"/>
+               <Property name="flags" type="string"/>
+               <Property name="rights" type="List:string"/>
+               <Mapping table="role">
+                       <Map column="rolename" property="name"/>
+                       <Map column="description"/>
+                       <Map column="flags"/>
+                       <Map property="rights">
+                               <Call lang="php" method="$data->getRightsFromDB()"/>
+                       </Map>
+                       <!-- how about rights? -->
+               </Mapping>
+       </Class>
+       
+       <Transaction name="GetAllRoles">
+               <Input/>
+               <Call lang="php" method="$this->setroles(WORole::fromTableArrayrole(WTrole::selectFromDB()));"/>
+               <Output>
+                       <Var name="roles" type="List:Role"/>
+               </Output>
+       </Transaction>
+       
+       <Transaction name="CreateRole"/>
+       
        <Transaction name="GetAllHostNames">
                <Input/>
                <Output>
index e1602c9..5f17b2a 100644 (file)
@@ -146,6 +146,9 @@ void WocPHPServerOut::newTable(const WocTable&tbl)
        //initializer
        code+="protected function __construct(array $data,$isfromdb){parent::__construct($data,$isfromdb,\""+tbl.name()+"\");}\n\n";
        
+       //static new instance for insert only
+       code+="public static function newRow(){return new WT"+tbl.name()+"(array(),false);}\n\n";
+       
        //static get instance
        QStringList cols=tbl.columns();
        QStringList pcols=tbl.primaryColumns();
index bc58c94..8ff61af 100644 (file)
@@ -4,6 +4,7 @@ include_once("inc/tr.php");
 //load WOB data
 include('./inc/wbase/autoload.php');
 include('./inc/wob/autoload.php');
+include('./inc/wext/autoload.php');
 //load DB drivers
 include('./inc/db/autoload.php');
 include('./config.php');
index 441eb97..8461d74 100644 (file)
@@ -16,4 +16,5 @@ $AUTOCLASS["Host"]="./inc/machine/host.php";
 $AUTOCLASS["Template"]="./inc/machine/template.php";
 $AUTOCLASS["Version"]="./inc/machine/version.php";
 $AUTOCLASS["Translation"]="./inc/machine/translation.php";
+$AUTOCLASS["MachineUser"]="./inc/machine/muser.php";
 ?>
\ No newline at end of file
diff --git a/www/inc/machine/muser.php b/www/inc/machine/muser.php
new file mode 100644 (file)
index 0000000..7521705
--- /dev/null
@@ -0,0 +1,114 @@
+<?
+//
+// PHP Implementation: muser
+//
+// Description: machine interface for user management
+//
+//
+// Author: Konrad Rosenbaum <konrad@silmor.de>, (C) 2009
+//
+// Copyright: See README/COPYING files that come with this distribution
+//
+//
+
+/**encapsulated machine user management in several static functions;
+it is called directly from the user centered transactions;
+DO NOT USE THIS CLASS OUTSIDE TRANSACTION CONTEXT!*/
+class MachineUser
+{
+       /**create a new user*/
+       static public function createUser($trans)
+       {
+               //check whether user exists
+               $usr=WTuser::getFromDB($trans->getusername());
+               if($usr!==false){
+                       $trans->abortWithError(tr("User already exists."));
+                       return;
+               }
+               //verify syntax
+               if(!ereg("^[a-zA-Z]([a-zA-Z_\\.-]*)$",$trans->getusername())){
+                       $trans->abortWithError(tr("Username is invalid."));
+                       return;
+               }
+               //create DB entry
+               $usr=WTuser::newRow();
+               $usr->uname=$trans->getusername();
+               $slt=getSalt();
+               $hsh=sha1($slt.$trans->getpassword());
+               $usr->passwd=$slt." ".$hsh;
+               $usr->insert();
+               $trans->setuser(MOUser::fromTableuser($usr));
+       }
+       
+       static public function deleteUser($trans)
+       {
+               //sanity check: do users exist
+               $un=$trans->getusername();
+               $usr=WTuser::getFromDB($un);
+               if($usr===false){
+                       $trans->abortWithError(tr("User does not exist."));
+                       return;
+               }
+               $mun=$trans->getmergewithuser();
+               if($mun=="")$mun=false;
+               $mu=false;
+               if($mun!==false){
+                       $mu=WTuser::getFromDB($mun);
+                       if($mu===false){
+                               $trans->abortWithError(tr("Merge target user does not exist!"));
+                               return;
+                       }
+               }
+               //check: are users identical?
+               if($un==$mun){
+                       $trans->abortWithError(tr("User and merge target user are identical."));
+                       return;
+               }
+               //perform merge
+               global $db;
+               if($mu!==false){
+                       //TODO: merge users
+               }
+               //delete user
+               $usr->deleteFromDB();
+       }
+       
+       static public function changePasswd($trans)
+       {
+               $usr=WTuser::getFromDB($trans->getusername());
+       }
+       
+       static public function setUserDescription($trans)
+       {
+               $usr=WTuser::getFromDB($trans->getusername());
+               if($usr===false){
+                       $trans->abortWithError(tr("User does not exist."));
+                       return;
+               }
+               $usr->description=$trans->getdescription();
+               $usr->update();
+       }
+       
+       static public function getUserRoles($trans)
+       {
+               //sanity check
+               $usr=WTuser::getFromDB($trans->getusername());
+               if($usr===false){
+                       $trans->abortWithError(tr("User does not exist."));
+                       return;
+               }
+               //get roles
+               global $db;
+               $rls=WTuserrole::selectFromDB("uname=".$db->escapeString($trans->getusername()));
+               $r=array();
+               foreach($rls as $rl){
+                       $r[]=$rl->role;
+               }
+               $trans->setroles($r);
+       }
+       
+       static public function setUserRoles($trans){}
+
+};
+
+?>
\ No newline at end of file
index 357a301..fe9e70f 100644 (file)
@@ -208,16 +208,6 @@ class Session
                if(in_array("_admin",$this->roles))return true;
                return in_array($transaction,$this->rights);
        }
-       
-       /**called for GetMyRoles transaction*/
-       public function getMyRoles()
-       {
-               global $db;
-               header("X-MagicSmoke-Status: Ok");
-               $res=$db->select("userrole","role","uname=".$db->escapeString($this->user));
-               foreach($res as $rl)
-                       print($rl["role"]."\n");
-       }
 };
 
 /**dummy class used by browsed pages to represent the virtual web user*/
index 7d103f2..a7e575a 100644 (file)
@@ -135,7 +135,7 @@ abstract class WobTable
        /**insert the object under a new primary key value into the DB (implicitly calls newKey); returns true on success*/
        public function insert()
        {
-               global $dbScheme;
+               global $dbScheme,$db;
                $this->isfromdb=false;
                //create new key
                $this->newKey();
@@ -148,7 +148,7 @@ abstract class WobTable
                $this->isfromdb=true;
                $this->data=$data;
                $this->cdata=array();
-               createAudit();
+               $this->createAudit();
                //assign primary key if sequence (otherwise newKey has done it)
                $seq=$dbScheme->hasSequence($this->table);
                if($seq!==false)
@@ -160,6 +160,7 @@ abstract class WobTable
        /**generate a new primary key value for insert and marks the object as not yet in the DB; the default sets the primary key to NULL if it is a sequence; call the original first if you overwrite it*/
        public function newKey()
        {
+               global $dbScheme;
                $this->isfromdb=false;
                $pk=$dbScheme->hasSequence($this->table);
                if($pk!==false){
@@ -178,7 +179,7 @@ abstract class WobTable
                if($succ){
                        foreach($this->cdata as $k=>$d)$this->data[$k]=$d;
                        $this->cdata=array();
-                       createAudit();
+                       $this->createAudit();
                }
                return $succ;
        }
diff --git a/www/inc/wext/autoload.php b/www/inc/wext/autoload.php
new file mode 100644 (file)
index 0000000..bc716bf
--- /dev/null
@@ -0,0 +1,15 @@
+<?
+//
+// PHP Implementation: autoload
+//
+// Description: 
+//
+//
+// Author: Konrad Rosenbaum <konrad@silmor.de>, (C) 2009
+//
+// Copyright: See README/COPYING files that come with this distribution
+//
+//
+
+$AUTOCLASS["WORole"]="inc/wext/role.php";
+?>
\ No newline at end of file
diff --git a/www/inc/wext/role.php b/www/inc/wext/role.php
new file mode 100644 (file)
index 0000000..4916d6a
--- /dev/null
@@ -0,0 +1,27 @@
+<?
+//
+// PHP Implementation: role
+//
+// Description: 
+//
+//
+// Author: Konrad Rosenbaum <konrad@silmor.de>, (C) 2009
+//
+// Copyright: See README/COPYING files that come with this distribution
+//
+//
+
+class WORole extends WORoleAbstract{
+       protected function getRightsFromDB()
+       {
+               global $db;
+               $rtl=$db->select("roleright","rolename=".$db->escapeString($this->prop_name));
+               $ret=array();
+               foreach($rtl as $rt){
+                       $ret[]=$rt["rightname"];
+               }
+               return $ret;
+       }
+};
+
+?>
\ No newline at end of file