Source for file OCSP_GROUPTREE.phpclass
Documentation is available at OCSP_GROUPTREE.phpclass
* Class file OCSP_GROUPTREE.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: OCSP_GROUPTREE.phpclass,v 1.13 2008/12/02 07:36:22 pitlinz Exp $
require_once __OCSP_PHPINCPATH__ .
"common" .
_OCSP_DIRSEP_ .
"OCSP_OBJ.phpclass";
require_once dirname(__FILE__
) .
_OCSP_DIRSEP_ .
"OCSP_USER.phpclass";
* Constants for system group id's
define('_OCSP_GROUP_PUBLIC_',0);
define('_OCSP_GROUP_LOGGEDIN_',-
1);
define('_OCSP_GROUP_ITEMAUTHOR_',-
2);
define('_OCSP_GROUP_PROJ_ADMINGRP_',-
80);
define('_OCSP_GROUP_PROJ_EDITOR_GRP_',-
81);
define('_OCSP_GROUP_PROJ_AUTHOR_GRP_',-
82);
define('_OCSP_GROUP_PROJ_USER_GRP_',-
83);
define('_OCSP_GROUP_NOTLOGGEDIN_',-
99);
define('_OCSP_GROUP_SYSTEMJOB_',-
98);
define('_OCSP_GROUP_TERMINATOR_',-
89); // don't check parents lower then this
define('_OCSP_GROUP_ADMIN_',1);
define('_OCSP_GROUP_DBMS_',2);
define('_OCSP_GROUP_CMSADMIN_',3);
define('_OCSP_GROUP_CMSEDITOR_',5);
define('_OCSP_GROUP_CMSAUTHOR_',6);
define('_OCSP_GROUP_PRODUCTS_',7);
define('_OCSP_GROUP_TEMPLATE_',4);
define('_OCSP_GROUP_CLIADMIN_',10);
define('_OCSP_GROUPRIGHTS_INSERT',32);
define('_OCSP_GROUPRIGHTS_EDIT',64);
define('_OCSP_GROUPRIGHTS_DELETE',96);
* @project Open CSP-Management
* @author Peter Krebs <pitlinz@users.sourceforge.net>
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
* @version $Id: OCSP_GROUPTREE.phpclass,v 1.13 2008/12/02 07:36:22 pitlinz Exp $
/*** class constants --------------------------------------------- */
* @constant string CLASS_SRC_FILE
/*** class variables --------------------------------------------- */
* @var OCSP_GROUPTREE $instance
private static $instance;
/*** attrubtes --------------------------------------------- */
* @var array $groupChildren
* array with already seen group members
* @var array $myGroupMembers
* array with already seen group admins
* @var array $myGroupAdmins
* flag to notice if the class attributes has changed
* @var boolean $hasChanged
* array with checked groups for a user
* $this->checkedgroups[M|A][usrId][grpId] = True
* @var array $checkedgroups
* returns the object instance
self::$instance =
new OCSP_GROUPTREE();
if ($debug) echoDebugMethod(__FILE__
,get_class($this),"OCSP_GROUPTREE::populateGroups();");
$str_query =
"SELECT * FROM T_SYS_GROUP ORDER BY GRP_PARENT";
if ($obj_cursor =
$obj_db->query($str_query))
while($arr_row =
$obj_cursor->fetchArrayFld())
$this->myGroups[$arr_row['GRP_ID']]=
$arr_row;
$this->myChildTree[$arr_row['GRP_PARENT']][] =
$arr_row['GRP_ID'];
* returns a group row also for system groups
return array('GRP_ID'=>
0,'GRP_NAME'=>
'[Public]');
return array('GRP_ID'=>
$aId,'GRP_NAME'=>
'[Systemgruppe]','GRP_PARENT'=>
_OCSP_GROUP_ADMIN_);
return array('GRP_ID'=>
$aId,'GRP_NAME'=>
$this->myGroups[$aId]['GRP_NAME']);
return $arr_row['GRP_NAME'];
* appends a child tree to $retArr
* @param string $keyPrepend
if ($debug) echoDebugMethod(__FILE__
,get_class($this),"OCSP_GROUPTREE::_addChildGroupArray(Parent: " .
$parentId .
")");
if (!($int_idx =
intval($this->myGroups[$int_grpId]['GRP_SORTORDER'])))
while(isset
($retArr[$keyPrepend .
sprintf("%04d",$int_idx)]))
$retArr[$keyPrepend .
sprintf("%04d",$int_idx)] =
$this->myGroups[$int_grpId];
* returns an array with all groups
* @param boolean $withSystemGroups
if (!($int_idx =
intval($this->myGroups[$int_grpId]['GRP_SORTORDER'])))
while(isset
($arr_ret[sprintf("%04d",$int_idx)]))
* returns an array with the 1st level children of a group
$arr_ret[$int_grpId] =
$this->myGroups[$int_grpId];
* returns an array with all children (including childrens of children) of a group
* @param array $setGroups already set groups to avoid loops on misconfigured groups
foreach($arr_ret as $grp_id =>
$arr_grps)
if (!isset
($setGroups[$grp_id]))
if (!$arr_groups[$int_parent]['SHOW'])
$arr_groups[$int_parent]['SHOW']=
True;
* returns the group tree with additional informations for the current user
* the return array looks like:
* - TREEIDX (0001.0001. ...)
* - ROW (the database row of the group)
* - MEMBER (the user is member of the group)
* - ADMIN (the user is admin of the group)
* - SHOW (the group is on the pass to a group the user is member or admin)
foreach($arr_grps as $str_key =>
$arr_row)
$arr_ret[$arr_row['GRP_ID']]['TREEIDX'] =
$str_key;
$arr_ret[$arr_row['GRP_ID']]['ROW'] =
$arr_row;
$arr_ret[$arr_row['GRP_ID']]['MEMBER']=
True;
$arr_ret[$arr_row['GRP_ID']]['MEMBER']=
false;
$arr_ret[$arr_row['GRP_ID']]['ADMIN']=
True;
$arr_ret[$arr_row['GRP_ID']]['ADMIN']=
false;
if ($arr_ret[$arr_row['GRP_ID']]['MEMBER'] ||
$arr_ret[$arr_row['GRP_ID']]['ADMIN'])
$arr_ret[$arr_row['GRP_ID']]['SHOW']=
True;
$arr_ret[$arr_row['GRP_ID']]['SHOW']=
false;
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* returns if a user is member of a group
* - an entry in T_SYS_GROUPMEMBER is found
* - the user is member of a parent group
* - GRP_PASSDOWN_RIGHTS = 1 and user is member of a direct children
* @param boolean $withAdmin (include group admins)
public function userIsMember($grpId,$usrId,$withAdmin=
false,$debug=
false)
if ($debug) echoDebugMethod(__FILE__
,get_class($this),"OCSP_GROUPTREE::userIsMember(".
$grpId.
",".
$usrId.
"," .
($withAdmin ?
"True" :
"False") .
")");
if (!($grpId =
intval($grpId)))
return True; // everybody is member of puplic
if (!($usrId)) // <pk-08-03-29>
if ($debug) echoDebugLine(__FILE__
,__LINE__
,"group {$grpId} already checked");
// nothing cached here ask the user for direct assignment
$arr_usrGrps =
$obj_user->getDirectAssignedGroups(false,$debug);
if ($debug) echoDebugLine(__FILE__
,__LINE__
,"Exception: " .
$e->getMessage());
foreach($arr_usrGrps as $int_grpId)
if ($int_grpId ==
$grpId)
$arr_adminGrps =
$obj_user->getDirectAssignedAdminGroups(false,$debug);
if ($debug) echoDebugLine(__FILE__
,__LINE__
,"Exception: " .
$e->getMessage());
foreach($arr_adminGrps as $int_grpId)
if ($int_grpId ==
$grpId)
// no direct assignment -> check children
if ($this->userIsMember($int_grpId,$usrId,$withAdmin,$debug))
$checkedGroups[$int_grpId] =
True;
// no direct assignment -> check parents
if (($int_parentId =
intval($this->myGroups[$grpId]['GRP_PARENT'])) &&
($int_parentId >
0))
if ($debug) echoDebugLine(__FILE__
,__LINE__
,"checking parent group: {$int_parentId}");
if ($this->userIsMember($int_parentId,$usrId,$withAdmin,$debug))
// finaly check for admin
if ($withAdmin &&
$int_admGrp =
intval($this->myGroups[$grpId]['GRP_PARENT']))
* returns if a user is admin of $grpId
* @global array $OCSP_OBJ
public function userIsAdmin($grpId,$usrId,$debug=
false)
if (!($usrId)) // <pk-08-03-29>
// nothing cached here ask the user for direct assignment
$arr_adminGrps =
$obj_user->getDirectAssignedAdminGroups(false,$debug);
if ($debug) echoDebugLine(__FILE__
,__LINE__
,"Exception: " .
$e->getMessage());
foreach($arr_adminGrps as $int_grpId)
if ($int_grpId ==
$grpId)
if ($debug) echo
"<p>checking admingroup " .
$int_admGrp .
" for " .
$grpId .
"</p>";
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* @param boolean $readOnlay
* @param boolean $asAdmin
public function addUserToGroup($usrId,$grpId,$readOnlay=
False,$asAdmin=
False,$debug=
False)
'GRP_ISADMIN' =>
($asAdmin ?
1 :
0),
'GRP_READONLY' =>
($readOnly ?
1 :
0)
return $obj_db->replaceArray('T_SYS_GROUPMEMBER',$arr_row);
throw
new Exception('_OCSP_EXCEP_NORIGHTS_');
* removes a user from a group
$str_cmd =
"DELETE FROM T_SYS_GROUPMEMBER ";
$str_cmd .=
" WHERE GRP_ID=" .
intval($grpId);
$str_cmd .=
" AND USR_ID=" .
intval($usrId);
$obj_db->executeCmd($str_cmd);
throw
new Exception('_OCSP_EXCEP_NORIGHTS_');
* sets a users admin flag
* @param boolean $asAdmin
if ($debug) echoDebugMethod(__FILE__
,get_class($this),"OCSP_GROUPTREE::setUsersAdminFlag({$usrId},{$grpId}," .
($asAdimn ?
"True" :
"False").
")");
$str_cmd =
"UPDATE T_SYS_GROUPMEMBER ";
$str_cmd .=
" SET GRP_ISADMIN=" .
($asAdmin ?
"1" :
"0");
$str_cmd .=
" WHERE GRP_ID=" .
intval($grpId);
$str_cmd .=
" AND USR_ID=" .
intval($usrId);
$obj_db->executeCmd($str_cmd);
if ($debug) echoDebugLine(__FILE__
,__LINE__
,"Command: " .
$str_cmd);
if (isset
($arr_keys[$usrId]))
throw
new Exception('_OCSP_EXCEP_NORIGHTS_');
throw
new Exception('_OCSP_EXCEP_NORIGHTS_');
* sets a users read only flag
* @param boolean $asAdmin
if ($debug) echoDebugMethod(__FILE__
,get_class($this),"OCSP_GROUPTREE::setUsersAdminFlag({$usrId},{$grpId}," .
($readOnly ?
"True" :
"False").
")");
$str_cmd =
"UPDATE T_SYS_GROUPMEMBER ";
$str_cmd .=
" SET GRP_READONLY=" .
($readOnly ?
"1" :
"0");
$str_cmd .=
" WHERE GRP_ID=" .
intval($grpId);
$str_cmd .=
" AND USR_ID=" .
intval($usrId);
$obj_db->executeCmd($str_cmd);
if ($debug) echoDebugLine(__FILE__
,__LINE__
,"Command: " .
$str_cmd);
throw
new Exception('_OCSP_EXCEP_NORIGHTS_');
throw
new Exception('_OCSP_EXCEP_NORIGHTS_');
Documentation generated on Thu, 08 Jan 2009 17:46:49 +0100 by phpDocumentor 1.4.0a2