Source for file CLI_STAFF.phpclass
Documentation is available at CLI_STAFF.phpclass
* Class file CLI_STAFF.phpclass
* @project Open CSP-Management
* @author Peter Krebs <pitlinz@users.sourceforge.net>
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
* @version $Id: CLI_STAFF.phpclass,v 1.16 2008/10/06 21:08:59 pitlinz Exp $
// ---------------------------------------------------------
// ---------------------------------------------------------
require_once __OCSP_DEFAULTCONFPATH__.
"client.conf.phpinc";
* Class file CLI_STAFF.phpclass
* @project Open CSP-Management
* @author Peter Krebs <pitlinz@users.sourceforge.net>
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
* @version $Id: CLI_STAFF.phpclass,v 1.16 2008/10/06 21:08:59 pitlinz Exp $
// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
* @constant string CLASS_SRC_FILE
// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
/*** class vars ------------------------------------------------------ */
* @staticvar array $loadedStaff
protected static $loadedStaff =
array();
/*** class methods --------------------------------------------------- */
* returns an instance out of the identity map
* @version pk-08-10-06 bugfix $aId
if (!isset
(self::$loadedStaff[$aId]))
self::$loadedStaff[$aId] =
self::factoryFromId($aId,$debug);
return self::$loadedStaff[$aId];
* adds a staff to the identity map
* @param CLI_STAFF $aStaff
public static function setInstance(&$aStaff,$debug=
False)
if ($debug) echoDebugMethod(__FILE__
,"static","CLI_STAFF::setInstance(" .
get_class($aStaff) .
");");
self::$loadedStaff[$aStaff->getId()] =
$aStaff;
* returns if a staff has been added to the identity map
return isset
(self::$loadedStaff[intval($aId)]);
// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
/*** compostion --------------------------------------------------- */
/*** attributes -------------------------------------------------- */
* @var string $myClassSrcFile
* @staticvar string $myTable name of the db table
* @var double $typeIsSet (time())
* @var CLI_STAFF_TYPE $myTypeObj
// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
* init the object and populate if an id is submitted
* @param mixed $client (CLIENT object or client id)
* @deprecated since pk-08-08-19
function CLI_STAFF($client=
NULL,$cstId=
0,$debug=
False)
* returns a client staff object
* @param mixed $client (CLIENT object or client id)
static public function factoryFromType($typeId,$client=
null,$cstId=
0,$debug=
False)
* returns a client staff object
* @param array $staffData
if ($debug) echoDebugMethod(__FILE__
,"static","CLI_STAFF::factoryFromRow()");
return $obj_type->factoryStaffFromRow($staffData,$debug);
* returns a client staff object
if ($debug) echoDebugMethod(__FILE__
,"static","CLI_STAFF::factoryFromId()");
return self::factoryFromRow($arr_row,$debug);
* set client table to config setting if set
function init($debug=
False) {
if (!empty($GLOBALS['CLIENT']['TABLES']['T_CLI_STAFF'])) {
$this->myTable=
$GLOBALS['CLIENT']['TABLES']['T_CLI_STAFF'];
return parent::init($debug);
* returns the name of the staff
return $this->CST_LASTNAME.
" ".
$this->CST_FIRSTNAME;
// #############################################################################
// #############################################################################
* returns the client type id
* sets the client type id
if ($debug) echo
"<p><b>CLI_STAFF::setType(\$aType=$aType)</b> (".
get_class($this).
")</p>";
* checks if $this->myTypeObj is set proper and return it
* @param CLI_STAFF_TYPE $aTypeObj
* returns the class specified by the staff type
if ($debug) echo
"<p><b>CLI_STAFF::getTypeClass()</b> (".
get_class($this).
")</p>\n";
$this->getTypeObj(); // to ensur $this->myTypeObj is set
* checks if this is type of class CSTTYPE_CLASS
* and returns the object ($this if ok else a new object of the right type)
* returns the name of the type (not the class !!!)
$this->getTypeObj(); // ensure $this->myTypeObj is set
// #############################################################################
// #############################################################################
* returns the the data array of a join
* @param boolean $withObjVars
* @todo CLI_STAFF::dbGetDataArray() filter
function dbGetDataArray($tables,$filter=
NULL,$withObjVars=
True,$debug=
False) {
ocsp_logError(__FILE__
,__LINE__
,"no database connection",E_ERROR);
$a_ret=
$this->getDBVal(False,$debug,$withObjVars);
foreach($tables as $tbl) {
if ($debug) echo
"<blockquote><p>getting data for: ".
$tbl.
"</p>\n";
$s_query=
"SELECT * FROM T_ADDRESS WHERE ADR_ID=".
intval($this->getDBField('ADR_ID'));
$a_tmp=
$this->myDBObj->quickQuery($s_query);
$s_query =
"SELECT u.* FROM T_SYS_USER u JOIN T_CLI_USER c USING(USR_ID)";
$s_query.=
" WHERE c.CLI_ID=".
$this->getCliId();
$s_query.=
" AND c.CST_ID=".
$this->getId();
if ($a_tmp=
$this->myDBObj->quickQuery($s_query)) {
$s_query=
"SELECT * FROM ".
$tbl.
" WHERE CST_ID=".
$this->getId();
if ($debug) echo
"<p>$s_query</p>\n";
if ($a_tmp=
$this->myDBObj->quickQuery($s_query)) {
} else if (!$this->myDBObj->tblHasColumn($tbl,'CST_ID',$debug)) {
foreach($a_cliTables as $tbl) {
$s_query=
"SELECT * FROM ".
$tbl.
" WHERE CLI_ID=".
$this->getCliId();
if ($debug) echo
"<p>$s_query</p>\n";
if ($a_tmp=
$this->myDBObj->quickQuery($s_query)) {
if ($debug) echo
"</blockquote>";
* checks if we have a client
* @param string $gDBIDX GLOBAL ARRAY INDEX OF DB OBJECT
* @param bool $debug SHOW DEBUG INFO
* @global array $OCSP_OBJ
function dbSave($debug=
False) {
$this->setError("NO CLIENT SET (CLI_ID)");
return False; // each CLI_STAFF needs a client
$this->setDBField('CST_CHANGEDBY',$OCSP_OBJ['USER']->getId());
return parent::dbSave($debug);
* inserts a new row to the table and set the creator
* @param bool $debug show debug info
* @global array $OCSP_OBJ
* @return int returns the autoIncFld ID if exists or 1 on success
* updates change fields an call parent::dbReplace
* @param boolean $ignorPopulated
function dbReplace($debug=
False,$ignorPopulated=
False)
return parent::dbReplace($debug,$ignorPopulated);
* deletes the row from the database
* @param boolean $backupData
function dbDelete($backupData=
True,$debug=
False) {
$s_query=
"SELECT CLP_TABLE FROM T_CLI_PROFILES WHERE CLP_KEYTABLE='".
$this->myTable.
"'";
if ($cursor=
$this->myDBObj->query($s_query)) {
while($row=
$cursor->fetchArrayFld()) {
$s_cmd=
"DELETE FROM ".
$row['CLP_TABLE'].
" WHERE CST_ID=".
$this->getId();
if ($debug) echo
"<p>$s_cmd</p>";
$this->myDBObj->executeCmd($s_cmd,$debug);
$s_query =
"SELECT * FROM T_CLI_USER WHERE CLI_ID=".
$this->getCliId();
$s_query.=
" AND CST_ID=".
$this->getId();
if ($o_usrCursor=
$this->myDBObj->query($s_query)) {
while($a_usr=
$o_usrCursor->fetchArrayFld()) {
$query=
"SELECT CLP_TABLE FROM T_CLI_PROFILES WHERE CLP_KEYTABLE='T_SYS_USER'";
if ($cursor=
$this->myDBObj->query($query)) {
while($row=
$cursor->fetchArrayFld()) {
$cmd=
"DELETE FROM ".
$row['CLP_TABLE'].
" WHERE USR_ID=".
$a_usr['USR_ID'];
$this->myDBObj->executeCmd($cmd,$debug);
$cmd=
"DELETE FROM T_SYS_GROUPMEMBER WHERE USR_ID=".
$a_usr['USR_ID'];
$this->myDBObj->executeCmd($cmd,$debug);
$cmd=
"DELETE FROM T_SYS_USER WHERE USR_ID=".
$a_usr['USR_ID'];
$this->myDBObj->executeCmd($cmd,$debug);
return parent::dbDelete($backupData,$debug);
// #############################################################################
// #############################################################################
* @param mixed $formIdName
* @param param boolean $debug
* @requires CLI_FORM.phpclass
function getAdminForm($frmMode=
FRM_MODE_READONLY,$formIdName=
NULL,$debug=
False)
return $this->getForm($frmMode,$formIdName,'CLI_STAFF_FORM',$debug);
$obj_form->setMyTblObj($this,$debug);
$obj_form->setFrmMode($frmMode);
return $this->getForm($frmMode,NULL,'CLI_FORM',$debug);
* @param boolean $frmMode
* @param string $frmName default form if no type form is found
* sets post array with form checks
* @param DBMS_FORM $frmObj a formObj as ref
* @param array $dbVal array with data
* @param boolean $asPopulate
* @param boolean $strict only set columns of $this->myTable and "OBJVALS_".$this->myTable
* @todo sometimes CST_CREATOR is overwritten witch current user check why
function setFORMPOST(&$frmObj,$dbval,$debug=
False,$asPopulate=
True,$strict=
False) {
if (intval($this->getDBField['CST_CREATOR'])) { // workaround for bug
$dbval['CST_CREATOR'] =
$this->getDBField('CST_CREATOR');
$dbval['CST_CREATION'] =
$this->getDBField('CST_CREATION');
return parent::setFORMPOST($frmObj,$dbval,$debug,$asPopulate,$strict);
// #############################################################################
// #############################################################################
* sets the client values to according staff values
* each CLI_xxx is set to CST_xxx
* and ADR_ID is set to CLI_DEFAULTADDR
$this->getClient($debug); // ensure $this->myClient is set
$this->setDBField('ADR_ID',$a_cliVal['CLI_DEFAULTADDR']);
unset
($a_cliVal['CLI_ID']); // to avoid overwriting the ID
unset
($a_cliVal['ADR_ID']); // we alread have it set
foreach($a_cliVal as $s_key =>
$s_val) {
* if the new value differs from $this->myClient->getId()
* $this->myClient is set to NULL
* returns the client object
* if $this->myClient is not an object a new one is created
$this->setCliId($aClient->getId(),$debug);
* returns the type id of the client
if ($debug) echo
"<p><b>CLI_STAFF::getClientType()</b> (".
get_class($this).
")</p>";
// #############################################################################
// #############################################################################
* returns the address object for the staff
* if the staff has no address assigned
* the default address of the client is returned
return $this->getClient()->getDefaultAddress($debug);
// #############################################################################
// #############################################################################
return $this->myDBObj->getOne("SELECT USR_ID FROM T_CLI_USER WHERE CST_ID=".
$this->getId());
* sets the user id and updates the Client user Table
if ($debug) echoDebug(__FILE__
,"<p><b>CLI_STAFF::setUSR_ID($aId,$debug)</b> (".
get_class($this).
")</p>",0);
if (!$this->getId()) return False;
$query=
"REPLACE INTO T_CLI_USER(CLI_ID,CST_ID,USR_ID) SELECT ".
$this->getCliId().
",".
$this->getId().
",USR_ID FROM T_SYS_USER WHERE USR_ID=".
intval($aId);
// select USR_ID form T_SYS_USER to ensure user exists
// use REPLACE to avoid errors if done twice
// and to keep old values
if ($debug) echoDebug(__FILE__
,"<blockquote><p>$query</p></blockquote>",2);
return $GLOBALS[$this->gDBIDX]->executeCmd($query);
* removes a user from the staff
if (!$this->getId()) return False;
$s_cmd=
"DELETE FROM T_CLI_USER WHERE USR_ID=".
intval($aId).
" AND CST_ID=".
$this->getId();
return $GLOBALS[$this->get_gDBIDX()]->executeCmd($s_cmd);
* generates a user for the client
* and returns the user ID or False in case of error
* @param boolean $enabled
function createUser($login,$pwd,$enabled=
True,$groups=
NULL,$debug=
False,$defaultGrp=
0) {
if ($debug) echoDebug(__FILE__
,"<p><b>CLI_STAFF::createUser($login,*****,....)</b> (".
get_class($this).
")</p>",0);
if (empty($login) ||
empty($pwd)) {
if (!$GLOBALS['USER']->isPublic() &&
!$GLOBALS['USER']->canEditClient($this->getCliId())) {
//the current user is not allowed to edit the client
$query=
"SELECT COUNT(*) FROM T_SYS_USER WHERE UPPER(USR_LOGIN)=UPPER(".
$GLOBALS[$this->get_gDBIDX()]->qs_getSlashedValue($login).
")";
if (intval($GLOBALS[$this->gDBIDX]->quickQuery($query,0))) {
// the login already exists ->
if ($debug) echoDebug(__FILE__
,"<p>Login exists</p>");
// the login is not in use
$a_usrVals['USR_LOGIN'] =
$login;
$a_usrVals['USR_PWD'] =
$pwd; // the system also accepts clear text passwords
$a_usrVals['USR_ENABLED'] =
intval($enabled);
$a_usrVals['USR_CREATION'] =
"CURRENT_TIMESTAMP";
$a_usrVals['USR_MD5PWD'] =
md5($pwd);
if (!is_array($groups)) $groups=
array();
if (intval($defaultGrp) >
0) {
if ($GLOBALS['USER']->isPublic()) {
$s_query=
"SELECT GRP_SELFSELECT FROM T_SYS_GROUP WHERE GRP_ID=".
intval($defaultGrp);
if (intval($GLOBALS['USRDB']->quickQuery($s_query,0))) {
$a_usrVals['GRP_ID']=
intval($defaultGrp);
} else { // another user creates a user
if ($GLOBALS['USER']->isGroupAdmin($defaultGrp)) {
$a_usrVals['GRP_ID']=
intval($defaultGrp);
if ($GLOBALS[$this->get_gDBIDX()]->insertArray("T_SYS_USER",$a_usrVals)) {
$query=
"SELECT USR_ID FROM T_SYS_USER WHERE USR_LOGIN=".
$GLOBALS[$this->gDBIDX]->qs_getSlashedValue($login);
if (!($i_usrId=
$GLOBALS[$this->gDBIDX]->quickQuery($query,0))) { // the user was not created
if (!$this->setUSR_ID($i_usrId,$debug)) { // undo insert and return False
$GLOBALS[$this->gDBIDX]->executeCmd("DELETE FROM T_SYS_USER WHERE usrId=".
$i_usrId);
if (isset
($a_usrVals['GRP_ID'])) $groups[]=
intval($a_usrVals['GRP_ID']);
foreach($groups as $i_grp) {
$a_grpVals=
array('GRP_ID'=>
intval($i_grp),'USR_ID'=>
$i_usrId);
$GLOBALS[$this->get_gDBIDX()]->replaceArray('T_SYS_GROUPMEMBER',$a_grpVals);
* creates a user from post values
* @param DBMS_FORM $frmObj
* @param int $usrId becomes the userId
if (!isset
($_POST['DBMSFORMID']) ||
!intval($_POST['DBMSFORMID'])) {
$s_arrName=
(isset
($_POST['FRMARRAYNAME']) ?
$_POST['FRMARRAYNAME'] :
"DBVAL");
if ($a_postVals=
$frmObj->getValueArray($_POST[$s_arrName],"",$s_arrName)) {
$b_enabled =
(isset
($a_postVals['USR_ENABLED']) ?
intval($a_postVals['USR_ENABLED']) :
True);
$i_defaultGrp =
(isset
($a_postVals['GRP_ID']) ?
intval($a_postVals['GRP_ID']) :
0);
if ($usrId=
$this->createUser($a_postVals['USR_LOGIN'],$a_postVals['USR_PWD'],$b_enabled,NULL,$debug,$i_defaultGrp)) {
if ($frmObj->usesTable('T_CLI_USER')) {
$s_query=
"SELECT * FROM T_CLI_USER WHERE UPPER USR_ID=".
$usrId.
" AND CST_ID=".
$this->getId().
" AND CLI_ID=".
$this->getCliId();
$a_cliUsr=
$GLOBALS[$this->get_gDBIDX()]->quickQuery($s_query);
foreach($a_cliUsr as $s_key =>
$m_val) {
if (isset
($a_postVals[$s_key])) {
$a_cliUsr=
$a_postVals[$s_key];
$GLOBALS[$this->get_gDBIDX()]->replaceArray('T_CLI_USER',$a_cliUsr);
$frmObj->setError(array('LABEL'=>
"Login",'MSG'=>
"Benutzername bereits vorhanden"));
$this->getTypeObj(); // ensure $this->myTypeObj is set
$this->getClient($debug); // ensure $this->myClient is set
$s_query =
"SELECT COUNT(*) FROM T_CLI_USER ";
$s_query.=
" WHERE CLI_ID=".
$this->getCliId();
$s_query.=
" AND CST_ID=".
$this->getId();
$s_query.=
" AND USR_ID=".
intval($aId);
if (intval($GLOBALS[$this->get_gDBIDX()]->quickQuery($s_query,0))) {
$o_user=
new USER($this->get_gDBIDX(),False,$debug,False);
$o_user->loadUser($aId,$debug);
return $o_user->deleteUser();
// ------------------------------------------------------
// ------------------------------------------------------
// ------------------------------------------------------
// ------------------------------------------------------
* returns if the current user can show the client data
// empty staff can be viewed by every one :-)
// user is client admin no need to proceed with checks
if ($this->getTypeObj()->userCanShowStaff($debug))
* returns if the current user can edit the client data
// empty or new clients can be edited by every one as they are not in the DB
if ($GLOBALS['USER']->isGroupMember($GLOBALS['GROUPS']['CLIENT-ADMIN'])) {
// user is client admin no need to proceed with checks
$this->getTypeObj(); // to ensure $this->myTypeObj is set
// finaly check if the client is staff of the user
$s_query =
"SELECT COUNT(*) FROM T_CLI_USER WHERE CLI_ID=".
$this->getCliId().
" AND USR_ID=".
$GLOBALS['USER']->getId();
$s_query.=
" AND CST_ID=".
$this->getId();
if ($i_count=
intval($GLOBALS[$this->get_gDBIDX()])->quickQuery($s_query,0)) return True;
* returns if the current user can edit the client data
if ($GLOBALS['USER']->isGroupMember($GLOBALS['GROUPS']['CLIENT-ADMIN'])) {
// user is client admin no need to proceed with checks
$this->getTypeObj(); // to ensure $this->myTypeObj is set
Documentation generated on Thu, 08 Jan 2009 17:38:18 +0100 by phpDocumentor 1.4.0a2