Fixed whitespace to standard coding conventions.
This commit is contained in:
parent
52fe579ce4
commit
8014f94c58
35 changed files with 6072 additions and 6070 deletions
262
backend/Alib.php
262
backend/Alib.php
|
@ -38,7 +38,7 @@ class Alib {
|
|||
}
|
||||
$userid = Subjects::GetSubjId($login);
|
||||
$sql = "INSERT INTO ".$CC_CONFIG['sessTable']." (sessid, userid, login, ts)"
|
||||
." VALUES('$sessid', '$userid', '$login', now())";
|
||||
." VALUES('$sessid', '$userid', '$login', now())";
|
||||
$r = $CC_DBC->query($sql);
|
||||
if (PEAR::isError($r)) {
|
||||
return $r;
|
||||
|
@ -60,12 +60,12 @@ class Alib {
|
|||
$ct = Alib::CheckAuthToken($sessid);
|
||||
if ($ct === FALSE) {
|
||||
return PEAR::raiseError("Alib::logout: not logged ($sessid)",
|
||||
ALIBERR_NOTLOGGED, PEAR_ERROR_RETURN);
|
||||
ALIBERR_NOTLOGGED, PEAR_ERROR_RETURN);
|
||||
} elseif (PEAR::isError($ct)) {
|
||||
return $ct;
|
||||
} else {
|
||||
$sql = "DELETE FROM ".$CC_CONFIG['sessTable']
|
||||
." WHERE sessid='$sessid'";
|
||||
." WHERE sessid='$sessid'";
|
||||
$r = $CC_DBC->query($sql);
|
||||
if (PEAR::isError($r)) {
|
||||
return $r;
|
||||
|
@ -85,7 +85,7 @@ class Alib {
|
|||
{
|
||||
global $CC_CONFIG, $CC_DBC;
|
||||
$sql = "SELECT count(*) as cnt FROM ".$CC_CONFIG['sessTable']
|
||||
." WHERE sessid='$sessid'";
|
||||
." WHERE sessid='$sessid'";
|
||||
$c = $CC_DBC->getOne($sql);
|
||||
return ($c == 1 ? TRUE : (PEAR::isError($c) ? $c : FALSE ));
|
||||
} //fn checkAuthToken
|
||||
|
@ -97,18 +97,18 @@ class Alib {
|
|||
* @param string $sessid
|
||||
* @return TRUE|PEAR_Error
|
||||
*/
|
||||
// public function setAuthToken($sessid)
|
||||
// {
|
||||
// $r = $this->checkAuthToken($sessid);
|
||||
// if (PEAR::isError($r)) {
|
||||
// return $r;
|
||||
// }
|
||||
// if (!$r) {
|
||||
// return PEAR::raiseError("ALib::setAuthToken: invalid token ($sessid)");
|
||||
// }
|
||||
// //$this->sessid = $sessid;
|
||||
// return TRUE;
|
||||
// } // fn setAuthToken
|
||||
// public function setAuthToken($sessid)
|
||||
// {
|
||||
// $r = $this->checkAuthToken($sessid);
|
||||
// if (PEAR::isError($r)) {
|
||||
// return $r;
|
||||
// }
|
||||
// if (!$r) {
|
||||
// return PEAR::raiseError("ALib::setAuthToken: invalid token ($sessid)");
|
||||
// }
|
||||
// //$this->sessid = $sessid;
|
||||
// return TRUE;
|
||||
// } // fn setAuthToken
|
||||
|
||||
|
||||
/* -------------------------------------------------------- authorization */
|
||||
|
@ -130,7 +130,7 @@ class Alib {
|
|||
global $CC_CONFIG, $CC_DBC;
|
||||
$permid = $CC_DBC->nextId($CC_CONFIG['permSequence']);
|
||||
$sql = "INSERT INTO ".$CC_CONFIG['permTable']." (permid, subj, action, obj, type)"
|
||||
." VALUES ($permid, $sid, '$action', $oid, '$type')";
|
||||
." VALUES ($permid, $sid, '$action', $oid, '$type')";
|
||||
$r = $CC_DBC->query($sql);
|
||||
if (PEAR::isError($r)) {
|
||||
return($r);
|
||||
|
@ -213,85 +213,85 @@ class Alib {
|
|||
*/
|
||||
public static function CheckPerm($sid, $action, $oid=NULL)
|
||||
{
|
||||
return TRUE;
|
||||
// global $CC_DBC;
|
||||
// global $CC_CONFIG;
|
||||
// if (!is_numeric($sid)) {
|
||||
// return FALSE;
|
||||
// }
|
||||
//// if (is_null($oid) or $oid=='') {
|
||||
//// $oid = M2tree::GetRootNode();
|
||||
//// }
|
||||
//// if (PEAR::isError($oid)) {
|
||||
//// return $oid;
|
||||
//// }
|
||||
// if (!is_numeric($oid)) {
|
||||
// return FALSE;
|
||||
// }
|
||||
// // query construction
|
||||
// // shortcuts:
|
||||
// // p: permTable,
|
||||
// // s: subjTable, m smembTable,
|
||||
// // t: treeTable ts: structTable,
|
||||
// // c: classTable, cm: cmembTable
|
||||
// // main query elements:
|
||||
// $q_flds = "m.level , p.subj, s.login, action, p.type, p.obj";
|
||||
// $q_from = $CC_CONFIG['permTable']." p ";
|
||||
// // joins for solving users/groups:
|
||||
// $q_join = "LEFT JOIN ".$CC_CONFIG['subjTable']." s ON s.id=p.subj ";
|
||||
// $q_join .= "LEFT JOIN ".$CC_CONFIG['smembTable']." m ON m.gid=p.subj ";
|
||||
// $q_cond = "p.action in('_all', '$action') AND
|
||||
// (s.id=$sid OR m.uid=$sid) ";
|
||||
// // coalesce -1 for higher priority of nongroup rows:
|
||||
// // action DESC order for lower priority of '_all':
|
||||
// $q_ordb = "ORDER BY coalesce(m.level,-1), action DESC, p.type DESC";
|
||||
// $q_flds0 = $q_flds;
|
||||
// $q_from0 = $q_from;
|
||||
// $q_join0 = $q_join;
|
||||
// $q_cond0 = $q_cond;
|
||||
// $q_ordb0 = $q_ordb;
|
||||
// // joins for solving object tree:
|
||||
// $q_flds .= ", t.name, ts.level as tlevel";
|
||||
// //$q_join .= "LEFT JOIN ".$CC_CONFIG['treeTable']." t ON t.id=p.obj ";
|
||||
// //$q_join .= "LEFT JOIN ".$CC_CONFIG['structTable']." ts ON ts.parid=p.obj ";
|
||||
// //$q_cond .= " AND (t.id=$oid OR ts.objid=$oid)";
|
||||
// // action DESC order is hack for lower priority of '_all':
|
||||
// $q_ordb = "ORDER BY coalesce(ts.level,0), m.level, action DESC, p.type DESC";
|
||||
// // query by tree:
|
||||
// $query1 = "SELECT $q_flds FROM $q_from $q_join WHERE $q_cond $q_ordb";
|
||||
// $r1 = $CC_DBC->getAll($query1);
|
||||
// if (PEAR::isError($r1)) {
|
||||
// return($r1);
|
||||
// }
|
||||
// // if there is row with type='A' on the top => permit
|
||||
// //$AllowedByTree =
|
||||
// // (is_array($r1) && count($r1)>0 && $r1[0]['type']=='A');
|
||||
// //$DeniedByTree =
|
||||
// // (is_array($r1) && count($r1)>0 && $r1[0]['type']=='D');
|
||||
//
|
||||
// if (!USE_ALIB_CLASSES) {
|
||||
// return $AllowedbyTree;
|
||||
// }
|
||||
//
|
||||
// // joins for solving object classes:
|
||||
// $q_flds = $q_flds0.", c.cname ";
|
||||
// $q_join = $q_join0."LEFT JOIN ".$CC_CONFIG['classTable']." c ON c.id=p.obj ";
|
||||
// $q_join .= "LEFT JOIN ".$CC_CONFIG['cmembTable']." cm ON cm.cid=p.obj ";
|
||||
// $q_cond = $q_cond0." AND (c.id=$oid OR cm.objid=$oid)";
|
||||
// $q_ordb = $q_ordb0;
|
||||
// // query by class:
|
||||
// $query2 = "SELECT $q_flds FROM $q_from $q_join WHERE $q_cond $q_ordb";
|
||||
// $r2 = $CC_DBC->getAll($query2);
|
||||
// if (PEAR::isError($r2)) {
|
||||
// return $r2;
|
||||
// }
|
||||
// $AllowedByClass =
|
||||
// (is_array($r2) && count($r2)>0 && $r2[0]['type']=='A');
|
||||
// // not used now:
|
||||
// // $DeniedByClass =
|
||||
// // (is_array($r2) && count($r2)>0 && $r2[0]['type']=='D');
|
||||
// $res = ($AllowedByTree || (!$DeniedByTree && $AllowedByClass));
|
||||
// return $res;
|
||||
return TRUE;
|
||||
// global $CC_DBC;
|
||||
// global $CC_CONFIG;
|
||||
// if (!is_numeric($sid)) {
|
||||
// return FALSE;
|
||||
// }
|
||||
//// if (is_null($oid) or $oid=='') {
|
||||
//// $oid = M2tree::GetRootNode();
|
||||
//// }
|
||||
//// if (PEAR::isError($oid)) {
|
||||
//// return $oid;
|
||||
//// }
|
||||
// if (!is_numeric($oid)) {
|
||||
// return FALSE;
|
||||
// }
|
||||
// // query construction
|
||||
// // shortcuts:
|
||||
// // p: permTable,
|
||||
// // s: subjTable, m smembTable,
|
||||
// // t: treeTable ts: structTable,
|
||||
// // c: classTable, cm: cmembTable
|
||||
// // main query elements:
|
||||
// $q_flds = "m.level , p.subj, s.login, action, p.type, p.obj";
|
||||
// $q_from = $CC_CONFIG['permTable']." p ";
|
||||
// // joins for solving users/groups:
|
||||
// $q_join = "LEFT JOIN ".$CC_CONFIG['subjTable']." s ON s.id=p.subj ";
|
||||
// $q_join .= "LEFT JOIN ".$CC_CONFIG['smembTable']." m ON m.gid=p.subj ";
|
||||
// $q_cond = "p.action in('_all', '$action') AND
|
||||
// (s.id=$sid OR m.uid=$sid) ";
|
||||
// // coalesce -1 for higher priority of nongroup rows:
|
||||
// // action DESC order for lower priority of '_all':
|
||||
// $q_ordb = "ORDER BY coalesce(m.level,-1), action DESC, p.type DESC";
|
||||
// $q_flds0 = $q_flds;
|
||||
// $q_from0 = $q_from;
|
||||
// $q_join0 = $q_join;
|
||||
// $q_cond0 = $q_cond;
|
||||
// $q_ordb0 = $q_ordb;
|
||||
// // joins for solving object tree:
|
||||
// $q_flds .= ", t.name, ts.level as tlevel";
|
||||
// //$q_join .= "LEFT JOIN ".$CC_CONFIG['treeTable']." t ON t.id=p.obj ";
|
||||
// //$q_join .= "LEFT JOIN ".$CC_CONFIG['structTable']." ts ON ts.parid=p.obj ";
|
||||
// //$q_cond .= " AND (t.id=$oid OR ts.objid=$oid)";
|
||||
// // action DESC order is hack for lower priority of '_all':
|
||||
// $q_ordb = "ORDER BY coalesce(ts.level,0), m.level, action DESC, p.type DESC";
|
||||
// // query by tree:
|
||||
// $query1 = "SELECT $q_flds FROM $q_from $q_join WHERE $q_cond $q_ordb";
|
||||
// $r1 = $CC_DBC->getAll($query1);
|
||||
// if (PEAR::isError($r1)) {
|
||||
// return($r1);
|
||||
// }
|
||||
// // if there is row with type='A' on the top => permit
|
||||
// //$AllowedByTree =
|
||||
// // (is_array($r1) && count($r1)>0 && $r1[0]['type']=='A');
|
||||
// //$DeniedByTree =
|
||||
// // (is_array($r1) && count($r1)>0 && $r1[0]['type']=='D');
|
||||
//
|
||||
// if (!USE_ALIB_CLASSES) {
|
||||
// return $AllowedbyTree;
|
||||
// }
|
||||
//
|
||||
// // joins for solving object classes:
|
||||
// $q_flds = $q_flds0.", c.cname ";
|
||||
// $q_join = $q_join0."LEFT JOIN ".$CC_CONFIG['classTable']." c ON c.id=p.obj ";
|
||||
// $q_join .= "LEFT JOIN ".$CC_CONFIG['cmembTable']." cm ON cm.cid=p.obj ";
|
||||
// $q_cond = $q_cond0." AND (c.id=$oid OR cm.objid=$oid)";
|
||||
// $q_ordb = $q_ordb0;
|
||||
// // query by class:
|
||||
// $query2 = "SELECT $q_flds FROM $q_from $q_join WHERE $q_cond $q_ordb";
|
||||
// $r2 = $CC_DBC->getAll($query2);
|
||||
// if (PEAR::isError($r2)) {
|
||||
// return $r2;
|
||||
// }
|
||||
// $AllowedByClass =
|
||||
// (is_array($r2) && count($r2)>0 && $r2[0]['type']=='A');
|
||||
// // not used now:
|
||||
// // $DeniedByClass =
|
||||
// // (is_array($r2) && count($r2)>0 && $r2[0]['type']=='D');
|
||||
// $res = ($AllowedByTree || (!$DeniedByTree && $AllowedByClass));
|
||||
// return $res;
|
||||
} // fn CheckPerm
|
||||
|
||||
|
||||
|
@ -326,7 +326,7 @@ class Alib {
|
|||
}
|
||||
if (is_null($uid)){
|
||||
return $CC_DBC->raiseError("Alib::removeSubj: Subj not found ($login)",
|
||||
ALIBERR_NOTEXISTS, PEAR_ERROR_RETURN);
|
||||
ALIBERR_NOTEXISTS, PEAR_ERROR_RETURN);
|
||||
}
|
||||
$r = Alib::RemovePerm(NULL, $uid);
|
||||
if (PEAR::isError($r)) {
|
||||
|
@ -354,7 +354,7 @@ class Alib {
|
|||
if (is_null($r)){
|
||||
return PEAR::raiseError("Alib::GetSessLogin:".
|
||||
" invalid session id ($sessid)",
|
||||
ALIBERR_NOTEXISTS, PEAR_ERROR_RETURN);
|
||||
ALIBERR_NOTEXISTS, PEAR_ERROR_RETURN);
|
||||
}
|
||||
return $r;
|
||||
} // fn GetSessLogin
|
||||
|
@ -377,7 +377,7 @@ class Alib {
|
|||
if (is_null($r)) {
|
||||
return PEAR::raiseError("Alib::getSessUserId:".
|
||||
" invalid session id ($p_sessid)",
|
||||
ALIBERR_NOTEXISTS, PEAR_ERROR_RETURN);
|
||||
ALIBERR_NOTEXISTS, PEAR_ERROR_RETURN);
|
||||
}
|
||||
return $r;
|
||||
} // fn getSessUserId
|
||||
|
@ -394,7 +394,7 @@ class Alib {
|
|||
{
|
||||
global $CC_CONFIG, $CC_DBC;
|
||||
$sql = "SELECT s.login, p.* FROM ".$CC_CONFIG['permTable']." p, ".$CC_CONFIG['subjTable']." s"
|
||||
." WHERE s.id=p.subj AND p.obj=$id";
|
||||
." WHERE s.id=p.subj AND p.obj=$id";
|
||||
return $CC_DBC->getAll($sql);
|
||||
} // fn GetObjPerms
|
||||
|
||||
|
@ -409,11 +409,11 @@ class Alib {
|
|||
{
|
||||
global $CC_CONFIG, $CC_DBC;
|
||||
$sql = "SELECT *"
|
||||
." FROM ".$CC_CONFIG['permTable']
|
||||
." WHERE p.subj=$sid";
|
||||
// $sql = "SELECT t.name, t.type as otype , p.*"
|
||||
// ." FROM ".$CC_CONFIG['permTable']." p, ".$CC_CONFIG['treeTable']." t"
|
||||
// ." WHERE t.id=p.obj AND p.subj=$sid";
|
||||
." FROM ".$CC_CONFIG['permTable']
|
||||
." WHERE p.subj=$sid";
|
||||
// $sql = "SELECT t.name, t.type as otype , p.*"
|
||||
// ." FROM ".$CC_CONFIG['permTable']." p, ".$CC_CONFIG['treeTable']." t"
|
||||
// ." WHERE t.id=p.obj AND p.subj=$sid";
|
||||
$a1 = $CC_DBC->getAll($sql);
|
||||
return $a1;
|
||||
} // fn GetSubjPerms
|
||||
|
@ -463,7 +463,7 @@ class Alib {
|
|||
for ($c = 1; $c > 0; ){
|
||||
$sessid = md5(uniqid(rand()));
|
||||
$sql = "SELECT count(*) FROM ".$CC_CONFIG['sessTable']
|
||||
." WHERE sessid='$sessid'";
|
||||
." WHERE sessid='$sessid'";
|
||||
$c = $CC_DBC->getOne($sql);
|
||||
if (PEAR::isError($c)) {
|
||||
return $c;
|
||||
|
@ -488,19 +488,19 @@ class Alib {
|
|||
{
|
||||
global $CC_CONFIG, $CC_DBC;
|
||||
$sql = "SELECT s.login, p.action, p.type"
|
||||
." FROM ".$CC_CONFIG['permTable']." p, ".$CC_CONFIG['subjTable']." s"
|
||||
." WHERE s.id=p.subj"
|
||||
." ORDER BY p.permid";
|
||||
." FROM ".$CC_CONFIG['permTable']." p, ".$CC_CONFIG['subjTable']." s"
|
||||
." WHERE s.id=p.subj"
|
||||
." ORDER BY p.permid";
|
||||
$arr = $CC_DBC->getAll($sql);
|
||||
if (PEAR::isError($arr)) {
|
||||
return $arr;
|
||||
}
|
||||
$r = $ind.join(', ', array_map(create_function('$v',
|
||||
'return "{$v[\'login\']}/{$v[\'action\']}/{$v[\'type\']}";'
|
||||
),
|
||||
$arr
|
||||
))."\n";
|
||||
return $r;
|
||||
),
|
||||
$arr
|
||||
))."\n";
|
||||
return $r;
|
||||
} // fn dumpPerms
|
||||
|
||||
|
||||
|
@ -532,16 +532,16 @@ class Alib {
|
|||
$s =& $tdata['subjects'];
|
||||
$CC_DBC->setErrorHandling(PEAR_ERROR_PRINT);
|
||||
$perms = array(
|
||||
array($s['root'], '_all', $t['root'], 'A'),
|
||||
array($s['test1'], '_all', $t['pa'], 'A'),
|
||||
array($s['test1'], 'read', $t['s2b'], 'D'),
|
||||
array($s['test2'], 'addChilds', $t['pa'], 'D'),
|
||||
array($s['test2'], 'read', $t['i2'], 'A'),
|
||||
array($s['test2'], 'edit', $t['s1a'], 'A'),
|
||||
array($s['test1'], 'addChilds', $t['s2a'], 'D'),
|
||||
array($s['test1'], 'addChilds', $t['s2c'], 'D'),
|
||||
array($s['gr2'], 'addChilds', $t['i2'], 'A'),
|
||||
array($s['test3'], '_all', $t['t1'], 'D'),
|
||||
array($s['root'], '_all', $t['root'], 'A'),
|
||||
array($s['test1'], '_all', $t['pa'], 'A'),
|
||||
array($s['test1'], 'read', $t['s2b'], 'D'),
|
||||
array($s['test2'], 'addChilds', $t['pa'], 'D'),
|
||||
array($s['test2'], 'read', $t['i2'], 'A'),
|
||||
array($s['test2'], 'edit', $t['s1a'], 'A'),
|
||||
array($s['test1'], 'addChilds', $t['s2a'], 'D'),
|
||||
array($s['test1'], 'addChilds', $t['s2c'], 'D'),
|
||||
array($s['gr2'], 'addChilds', $t['i2'], 'A'),
|
||||
array($s['test3'], '_all', $t['t1'], 'D'),
|
||||
);
|
||||
if (USE_ALIB_CLASSES){
|
||||
$perms[] = array($s['test3'], 'read', $c['cl_sa'], 'D');
|
||||
|
@ -587,14 +587,14 @@ class Alib {
|
|||
return $r;
|
||||
}
|
||||
$test_dump = $r.
|
||||
(Alib::CheckPerm(
|
||||
$tdata['subjects']['test1'], 'read',
|
||||
$tdata['tree']['t1']
|
||||
)? 'yes':'no').", ".
|
||||
(Alib::CheckPerm(
|
||||
$tdata['subjects']['test1'], 'addChilds',
|
||||
$tdata['tree']['i2']
|
||||
)? 'yes':'no')."\n"
|
||||
(Alib::CheckPerm(
|
||||
$tdata['subjects']['test1'], 'read',
|
||||
$tdata['tree']['t1']
|
||||
)? 'yes':'no').", ".
|
||||
(Alib::CheckPerm(
|
||||
$tdata['subjects']['test1'], 'addChilds',
|
||||
$tdata['tree']['i2']
|
||||
)? 'yes':'no')."\n"
|
||||
;
|
||||
Alib::RemovePerm($tdata['perms'][1]);
|
||||
Alib::RemovePerm($tdata['perms'][3]);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue