Major changes with LiveSupport local storageServer module.

This commit is contained in:
tomas 2004-09-12 21:55:51 +00:00
parent 53e7a3d8cc
commit 37f30a7efd
28 changed files with 3024 additions and 1217 deletions

View file

@ -1,27 +1,59 @@
<?php
// $Id: alib.php,v 1.1 2004/07/23 00:22:13 tomas Exp $
/*------------------------------------------------------------------------------
/**
* Alib class
*
* authentication/authorization class
**/
Copyright (c) 2004 Media Development Loan Fund
This file is part of the LiveSupport project.
http://livesupport.campware.org/
To report bugs, send an e-mail to bugs@campware.org
LiveSupport is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
LiveSupport is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with LiveSupport; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Author : $Author: tomas $
Version : $Revision: 1.2 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/alib/var/alib.php,v $
------------------------------------------------------------------------------*/
require_once 'subj.php';
define('ALIBERR_NOTLOGGED', 30);
define('ALIBERR_NOTEXISTS', 31);
/**
* Alib class
*
* authentication/authorization class
*
* @author $Author: tomas $
* @version $Revision: 1.2 $
* @see Subjects
* @see GreenBox
*/
class Alib extends Subjects{
var $permTable;
var $sessTable;
var $login=NULL;
var $userid=NULL;
var $sessid=NULL;
/** Alib - constructor
*
* @param object DB
* @param config array
* @return this
**/
/**
* Constructor
*
* @param dbc object, DB
* @param config array
* @return this
*/
function Alib(&$dbc, $config)
{
parent::Subjects(&$dbc, $config);
@ -29,28 +61,31 @@ class Alib extends Subjects{
$this->sessTable = $config['tblNamePrefix'].'sess';
}
/* ========== public methods: ========== */
/* ======================================================= public methods */
/* --- session/authentication --- */
/* ----------------------------------------------- session/authentication */
/**
* login
*
* @param login string
* @param pass string
* @return boolean/sessionId/err
**/
* Authenticate and create session
*
* @param login string
* @param pass string
* @return boolean/sessionId/err
*/
function login($login, $pass)
{
if(FALSE === $this->authenticate($login, $pass)) return FALSE;
for($c=1; $c>0;){
$sessid = md5(uniqid(rand()));
$c = $this->dbc->getOne("SELECT count(*) FROM {$this->sessTable} WHERE sessid='$sessid'");
$c = $this->dbc->getOne("SELECT count(*) FROM {$this->sessTable}
WHERE sessid='$sessid'");
if(PEAR::isError($c)) return $c;
}
$userid = $this->getSubjId($login);
$r = $this->dbc->query("INSERT INTO {$this->sessTable} (sessid, userid, login)
VALUES ('$sessid', '$userid', '$login')");
$r = $this->dbc->query("INSERT INTO {$this->sessTable}
(sessid, userid, login, ts)
VALUES
('$sessid', '$userid', '$login', now())");
if(PEAR::isError($r)) return $r;
$this->login = $login;
$this->userid = $userid;
@ -59,20 +94,22 @@ class Alib extends Subjects{
}
/**
* logout
*
* @param sessid string
* @return true/err
**/
* Logout and destroy session
*
* @param sessid string
* @return true/err
*/
function logout($sessid)
{
$ct = $this->checkToken($sessid);
if($ct === FALSE)
return PEAR::raiseError('Alib::logout: not logged ($ct)', ALIBERR_NOTLOGGED, PEAR_ERROR_RETURN);
return PEAR::raiseError('Alib::logout: not logged ($ct)',
ALIBERR_NOTLOGGED, PEAR_ERROR_RETURN);
elseif(PEAR::isError($ct))
return $ct;
else{
$r = $this->dbc->query("DELETE FROM {$this->sessTable} WHERE sessid='$sessid'");
$r = $this->dbc->query("DELETE FROM {$this->sessTable}
WHERE sessid='$sessid'");
if(PEAR::isError($r)) return $r;
$this->login = NULL;
$this->userid = NULL;
@ -82,42 +119,44 @@ class Alib extends Subjects{
}
/**
* checkToken
*
* @param sessid string
* @return boolean/err
**/
* Return true if the token is valid
*
* @param sessid string
* @return boolean/err
*/
function checkToken($sessid)
{
$c = $this->dbc->getOne("SELECT count(*) as cnt FROM {$this->sessTable} WHERE sessid='$sessid'");
$c = $this->dbc->getOne("SELECT count(*) as cnt FROM {$this->sessTable}
WHERE sessid='$sessid'");
return ($c == 1 ? TRUE : (PEAR::isError($c) ? $c : FALSE ));
}
/**
* setToken
*
* @param sessid string
* @return boolean/err
**/
* Set valid token in alib object
*
* @param sessid string
* @return boolean/err
*/
function setToken($sessid)
{
$r = checkToken($sessid);
if(PEAR::isError($r)) return $r;
if(!$r) return PEAR::raiseError("ALib::setToken: invalid token ($sessid)");
if(!$r)
return PEAR::raiseError("ALib::setToken: invalid token ($sessid)");
$this->sessid = $sessid;
return TRUE;
}
/* --- authorization --- */
/* -------------------------------------------------------- authorization */
/**
* addPerm
*
* @param sid int
* @param action string
* @param oid int
* @param type char
* @return int/err
**/
* Insert permission record
*
* @param sid int
* @param action string
* @param oid int
* @param type char
* @return int/err
*/
function addPerm($sid, $action, $oid, $type='A')
{
$permid = $this->dbc->nextId("{$this->permTable}_id_seq");
@ -130,13 +169,13 @@ class Alib extends Subjects{
}
/**
* removePerm
*
* @param permid int OPT
* @param subj int OPT
* @param obj int OPT
* @return null/error
**/
* Remove permission record
*
* @param permid int OPT
* @param subj int OPT
* @param obj int OPT
* @return null/error
*/
function removePerm($permid=NULL, $subj=NULL, $obj=NULL)
{
return $this->dbc->query("DELETE FROM {$this->permTable} WHERE 1=1".
@ -147,13 +186,15 @@ class Alib extends Subjects{
}
/**
* checkPerm
*
* @param sid int
* @param action string
* @param oid int OPT
* @return boolean/err
**/
* Check if specified subject have permission to specified action
* on specified object - huh ;)<br>
* One of the most important method in this class hierarchy ...
*
* @param sid int
* @param action string
* @param oid int OPT
* @return boolean/err
*/
function checkPerm($sid, $action, $oid=NULL)
{
if(!is_numeric($sid)) return FALSE;
@ -164,25 +205,33 @@ class Alib extends Subjects{
$q_flds = "m.level as S_lvl, p.subj, s.login, action, p.type, p.obj";
$q_from = "{$this->subjTable} s, {$this->permTable} p";
$q_join = "LEFT JOIN {$this->smembTable} m ON p.subj=m.gid ";
$q_cond = "p.action in('_all', '$action') AND (m.uid=$sid OR p.subj=$sid) AND s.id=p.subj";
$q_ordb = "ORDER BY S_lvl, action, p.type DESC"; // action ASC order is hack for lower priority of '_all'
$q_cond = "p.action in('_all', '$action') AND
(m.uid=$sid OR p.subj=$sid) AND s.id=p.subj";
// action ASC order is hack for lower priority of '_all':
$q_ordb = "ORDER BY S_lvl, action, p.type DESC";
$qc0 = $q_cond;
// test if object is class:
$iscls = $this->isClass($oid); if(PEAR::isError($iscls)) return $iscls;
$iscls = $this->isClass($oid);
if(PEAR::isError($iscls)) return $iscls;
if($iscls){
$q_from .= ", {$this->classTable} c";
$q_cond .= " AND c.id=p.obj AND c.id=$oid";
}else{
// object is normal node => path search => retrieve L/R values for oid:
$r1 = $this->dbc->getRow("SELECT lft, rgt, level FROM {$this->treeTable} WHERE id=$oid");
// obj is normal node => path search => retrieve L/R values for it:
$r1 = $this->dbc->getRow("SELECT lft, rgt, level
FROM {$this->treeTable} WHERE id=$oid");
if(is_null($r1))
return PEAR::raiseError('Alib::checkPerm: object not exists', ALIBERR_NOTEXISTS, PEAR_ERROR_RETURN);
return PEAR::raiseError('Alib::checkPerm: object not exists',
ALIBERR_NOTEXISTS, PEAR_ERROR_RETURN
);
if(PEAR::isError($r1)) return($r1);
// fetch all path to oid + join with perms
$q_flds .= ", t.name, ({$r1['level']}-t.level)as T_lvl";
$q_from = "{$this->treeTable} t, ".$q_from;
$q_cond .= " AND t.id=p.obj AND t.lft<={$r1['lft']} AND t.rgt>={$r1['rgt']}";
$q_ordb = "ORDER BY T_lvl, S_lvl, action, p.type DESC"; // action ASC order is hack for lower priority of '_all'
$q_cond .= " AND t.id=p.obj AND t.lft<={$r1['lft']} AND
t.rgt>={$r1['rgt']}";
// action ASC order is hack for lower priority of '_all':
$q_ordb = "ORDER BY T_lvl, S_lvl, action, p.type DESC";
}
$query="SELECT $q_flds FROM $q_from $q_join WHERE $q_cond $q_ordb";
$r2 = $this->dbc->getAll($query);
@ -201,28 +250,29 @@ class Alib extends Subjects{
return (is_array($r2) && count($r2)>0 && $r2[0]['type']=='A');
}
/* --- object tree --- */
/* ---------------------------------------------------------- object tree */
/**
* removeObj
*
* @param id int
* @return void/error
**/
* Remove all permissions on object and then remove object itself
*
* @param id int
* @return void/error
*/
function removeObj($id)
{
$r = $this->removePerm(NULL, NULL, $id); if(PEAR::isError($r)) return $r;
$r = $this->removePerm(NULL, NULL, $id);
if(PEAR::isError($r)) return $r;
return parent::removeObj($id);
}
/* --- users/groups --- */
/* --------------------------------------------------------- users/groups */
/**
* removeSubj
*
* @param login string
* @return void/error
**/
* Remove all permissions of subject and then remove subject itself
*
* @param login string
* @return void/error
*/
function removeSubj($login)
{
$uid = $this->getSubjId($login); if(PEAR::isError($uid)) return $uid;
@ -230,13 +280,13 @@ class Alib extends Subjects{
return parent::removeSubj($login, $uid);
}
/* --- sessions --- */
/* ------------------------------------------------------------- sessions */
/**
* getSessLogin
*
* @param sessid string
* @return string/error
**/
* Get login from session id (token)
*
* @param sessid string
* @return string/error
*/
function getSessLogin($sessid)
{
return $this->dbc->getOne("
@ -244,24 +294,24 @@ class Alib extends Subjects{
}
/**
* getSessUserId
*
* @param sessid string
* @return int/error
**/
* Get user id from session id
*
* @param sessid string
* @return int/error
*/
function getSessUserId($sessid)
{
return $this->dbc->getOne("
SELECT userid FROM {$this->sessTable} WHERE sessid='$sessid'");
}
/* --- info methods: --- */
/* --------------------------------------------------------- info methods */
/**
* getObjPerms
*
* @param id int
* @return array/null/err
**/
* Get all permissions on object
*
* @param id int
* @return array/null/err
*/
function getObjPerms($id)
{
return $this->dbc->getAll("
@ -270,82 +320,87 @@ class Alib extends Subjects{
}
/**
* getSubjPerms
*
* @param sid int
* @return array
**/
* Get all permissions of subject
*
* @param sid int
* @return array
*/
function getSubjPerms($sid)
{
$a1 = $this->dbc->getAll("
SELECT t.name, t.type as otype , p.* FROM {$this->permTable} p, {$this->treeTable} t
SELECT t.name, t.type as otype , p.*
FROM {$this->permTable} p, {$this->treeTable} t
WHERE t.id=p.obj AND p.subj=$sid");
if(PEAR::isError($a1)) return $a1;
$a2 = $this->dbc->getAll("
SELECT c.cname as name, 'C'as otype, p.* FROM {$this->permTable} p, {$this->classTable} c
SELECT c.cname as name, 'C'as otype, p.*
FROM {$this->permTable} p, {$this->classTable} c
WHERE c.id=p.obj AND p.subj=$sid");
if(PEAR::isError($a2)) return $a2;
return array_merge($a1, $a2);
}
/* --- info methods related to application structure: --- */
/* (this part should be added/rewritten to allow defining/modifying/using application structure) */
/* (only very simple structure definition - in config - supported now) */
/* ------------------------ info methods related to application structure */
/* (this part should be added/rewritten to allow defining/modifying/using
* application structure)
* (only very simple structure definition - in $config - supported now)
*/
/**
* getAllActions
*
* @return array
**/
* Get all actions
*
* @return array
*/
function getAllActions()
{
return $this->config['allActions'];
}
/**
* getAllowedActions
*
* @param type string
* @return array
**/
* Get all allowed actions on specified object type
*
* @param type string
* @return array
*/
function getAllowedActions($type)
{
return $this->config['allowedActions'][$type];
}
/* ========== test and debug methods: ========== */
/* =============================================== test and debug methods */
/**
* dumpPerms
*
* @param indstr string // indentation string
* @param ind string // aktual indentation
* @return string
**/
* Dump all permissions for debug
*
* @param indstr string // indentation string
* @param ind string // aktual indentation
* @return string
*/
function dumpPerms($indstr=' ', $ind='')
{
$r = $ind.join(', ', array_map(create_function('$v', 'return "{$v[\'action\']}/{$v[\'type\']}";'),
$r = $ind.join(', ', array_map(
create_function('$v', 'return "{$v[\'action\']}/{$v[\'type\']}";'),
$this->dbc->getAll("SELECT action, type FROM {$this->permTable}")
))."\n";
return $r;
}
/**
* deleteData
*
* @return void
**/
* deleteData
*
* @return void
*/
function deleteData()
{
$this->dbc->query("DELETE FROM {$this->permTable}");
parent::deleteData();
}
/**
* testData
*
* @return array
**/
* Insert test permissions
*
* @return array
*/
function testData()
{
parent::testData();
@ -374,35 +429,46 @@ class Alib extends Subjects{
}
/**
* test
*
* @return boolean/error
**/
* Make basic test
*
* @return boolean/error
*/
function test()
{
if(PEAR::isError($p = parent::test())) return $p;
$this->deleteData();
$this->testData();
$this->test_correct = "_all/A, _all/A, _all/D, read/A, edit/A, read/A, editPerms/A, editPerms/D, addChilds/A, addChilds/A, addChilds/A, addChilds/A, addChilds/A, addChilds/A, addChilds/A, addChilds/A\nno, yes\n";
$this->test_correct = "_all/A, _all/A, _all/D, read/A, edit/A, read/A,".
" editPerms/A, editPerms/D, addChilds/A, addChilds/A, addChilds/A,".
" addChilds/A, addChilds/A, addChilds/A, addChilds/A, addChilds/A".
"\nno, yes\n";
$this->test_dump = $this->dumpPerms().
($this->checkPerm($this->tdata['subjects'][1], 'edit', $this->tdata['tree'][7])? 'yes':'no').", ".
($this->checkPerm($this->tdata['subjects'][2], 'read', $this->tdata['tree'][5])? 'yes':'no')."\n"
($this->checkPerm(
$this->tdata['subjects'][1], 'edit', $this->tdata['tree'][7]
)? 'yes':'no').", ".
($this->checkPerm(
$this->tdata['subjects'][2], 'read', $this->tdata['tree'][5]
)? 'yes':'no')."\n"
;
$this->removePerm($this->tdata['perms'][1]);
$this->removePerm($this->tdata['perms'][3]);
$this->test_correct .= "_all/A, _all/D, edit/A, read/A, editPerms/A, editPerms/D, addChilds/A, addChilds/A, addChilds/A, addChilds/A, addChilds/A, addChilds/A, addChilds/A, addChilds/A\n";
$this->test_correct .= "_all/A, _all/D, edit/A, read/A, editPerms/A,".
" editPerms/D, addChilds/A, addChilds/A, addChilds/A, addChilds/A,".
" addChilds/A, addChilds/A, addChilds/A, addChilds/A\n";
$this->test_dump .= $this->dumpPerms();
$this->deleteData();
if($this->test_dump==$this->test_correct){ $this->test_log.="alib: OK\n"; return TRUE; }
else return PEAR::raiseError('Alib::test', 1, PEAR_ERROR_DIE, '%s'.
"<pre>\ncorrect:\n{$this->test_correct}\ndump:\n{$this->test_dump}\n</pre>\n");
if($this->test_dump==$this->test_correct)
{ $this->test_log.="alib: OK\n"; return TRUE;
}else return PEAR::raiseError('Alib::test', 1, PEAR_ERROR_DIE, '%s'.
"<pre>\ncorrect:\n{$this->test_correct}\n".
"dump:\n{$this->test_dump}\n</pre>\n");
}
/**
* install - create tables + initialize
*
* @return void
**/
* Create tables + initialize
*
* @return void
*/
function install()
{
parent::install();
@ -413,8 +479,10 @@ class Alib extends Subjects{
obj int,
type char(1)
)");
$this->dbc->query("CREATE UNIQUE INDEX {$this->permTable}_permid_idx on {$this->permTable} (permid)");
$this->dbc->query("CREATE INDEX {$this->permTable}_subj_obj_idx on {$this->permTable} (subj, obj)");
$this->dbc->query("CREATE UNIQUE INDEX {$this->permTable}_permid_idx
ON {$this->permTable} (permid)");
$this->dbc->query("CREATE INDEX {$this->permTable}_subj_obj_idx
ON {$this->permTable} (subj, obj)");
$this->dbc->createSequence("{$this->permTable}_id_seq");
$this->dbc->query("CREATE TABLE {$this->sessTable} (
@ -423,16 +491,19 @@ class Alib extends Subjects{
login varchar(255),
ts timestamp
)");
$this->dbc->query("CREATE UNIQUE INDEX {$this->sessTable}_sessid_idx on {$this->sessTable} (sessid)");
$this->dbc->query("CREATE INDEX {$this->sessTable}_userid_idx on {$this->sessTable} (userid)");
$this->dbc->query("CREATE INDEX {$this->sessTable}_login_idx on {$this->sessTable} (login)");
$this->dbc->query("CREATE UNIQUE INDEX {$this->sessTable}_sessid_idx
ON {$this->sessTable} (sessid)");
$this->dbc->query("CREATE INDEX {$this->sessTable}_userid_idx
ON {$this->sessTable} (userid)");
$this->dbc->query("CREATE INDEX {$this->sessTable}_login_idx
ON {$this->sessTable} (login)");
}
/**
* uninstall
*
* @return void
**/
* Drop tables etc.
*
* @return void
*/
function uninstall()
{
$this->dbc->query("DROP TABLE {$this->permTable}");

View file

@ -1,23 +1,54 @@
<?php
// $Id: class.php,v 1.1 2004/07/23 00:22:13 tomas Exp $
/*------------------------------------------------------------------------------
Copyright (c) 2004 Media Development Loan Fund
This file is part of the LiveSupport project.
http://livesupport.campware.org/
To report bugs, send an e-mail to bugs@campware.org
LiveSupport is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
LiveSupport is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with LiveSupport; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Author : $Author: tomas $
Version : $Revision: 1.2 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/alib/var/class.php,v $
------------------------------------------------------------------------------*/
require_once "mtree.php";
/**
* ObjClass class
*
* class for 'object classes' handling - i.e. groups of object in tree
* @parent Mtree
**/
require_once"mtree.php";
* ObjClass class
*
* class for 'object classes' handling - i.e. groups of object in tree
*
* @author $Author: tomas $
* @version $Revision: 1.2 $
* @see Mtree
* @see Subj
*/
class ObjClasses extends Mtree{
var $classTable;
var $cmembTable;
/** ObjClasses - constructor
*
* @param dbc object
* @param config array
* @return this
**/
/**
* Constructor
*
* @param dbc object
* @param config array
* @return this
*/
function ObjClasses(&$dbc, $config)
{
parent::MTree(&$dbc, $config);
@ -25,17 +56,18 @@ class ObjClasses extends Mtree{
$this->cmembTable = $config['tblNamePrefix'].'cmemb';
}
/* ========== public methods: ========== */
/* ======================================================= public methods */
/**
* addClass
*
* @param cname string
* @return id/error
**/
* Add new class of objects
*
* @param cname string
* @return id/error
*/
function addClass($cname)
{
$id = $this->dbc->nextId("{$this->treeTable}_id_seq"); if(PEAR::isError($id)) return $id;
$id = $this->dbc->nextId("{$this->treeTable}_id_seq");
if(PEAR::isError($id)) return $id;
$r = $this->dbc->query("
INSERT INTO {$this->classTable} (id, cname)
VALUES ($id, '$cname')
@ -45,146 +77,156 @@ class ObjClasses extends Mtree{
}
/**
* removeClass
*
* @param cname string
* @return boolean/err
**/
* Remove class by name
*
* @param cname string
* @return boolean/err
*/
function removeClass($cname)
{
$cid = $this->getClassId($cname); if(PEAR::isError($cid)) return($cid);
$cid = $this->getClassId($cname);
if(PEAR::isError($cid)) return($cid);
return $this->removeClassById($cid);
}
/**
* removeClassById
*
* @param cid int
* @return boolean/err
**/
* Remove class by id
*
* @param cid int
* @return boolean/err
*/
function removeClassById($cid)
{
$r = $this->dbc->query("DELETE FROM {$this->cmembTable} WHERE cid=$cid");
$r = $this->dbc->query("DELETE FROM {$this->cmembTable}
WHERE cid=$cid");
if(PEAR::isError($r)) return $r;
$r = $this->dbc->query("DELETE FROM {$this->classTable} WHERE id=$cid");
$r = $this->dbc->query("DELETE FROM {$this->classTable}
WHERE id=$cid");
if(PEAR::isError($r)) return $r;
return TRUE;
}
/**
* addObj2Class
*
* @param cid int
* @param oid int
* @return boolean/err
**/
* Add object to class
*
* @param cid int
* @param oid int
* @return boolean/err
*/
function addObj2Class($cid, $oid)
{
$r = $this->dbc->query("INSERT INTO {$this->cmembTable} (cid, objid) VALUES ($cid, $oid)");
$r = $this->dbc->query("INSERT INTO {$this->cmembTable} (cid, objid)
VALUES ($cid, $oid)");
if(PEAR::isError($r)) return $r;
return TRUE;
}
/**
* removeObjFromClass
*
* @param oid int
* @param cid int OPT // if not specified, remove obj from all classes
* @return boolean/err
**/
* Remove object from class
*
* @param oid int
* @param cid int, optional, default: remove obj from all classes
* @return boolean/err
*/
function removeObjFromClass($oid, $cid=NULL)
{
$r = $this->dbc->query("DELETE FROM {$this->cmembTable} WHERE objid=$oid".(is_null($cid)? '':" AND cid=$cid"));
$r = $this->dbc->query("DELETE FROM {$this->cmembTable}
WHERE objid=$oid".(is_null($cid)? '':" AND cid=$cid"));
if(PEAR::isError($r)) return $r;
return TRUE;
}
/* --- object tree --- */
/* ---------------------------------------------------------- object tree */
/**
* removeObj
*
* @param id int
* @return boolean/err
**/
* Remove object from all classes and remove object itself
*
* @param id int
* @return boolean/err
*/
function removeObj($id)
{
$r = $this->removeObjFromClass($id); if(PEAR::isError($r)) return $r;
$r = $this->removeObjFromClass($id);
if(PEAR::isError($r)) return $r;
return parent::removeObj($id);
}
/* --- info methods: --- */
/* --------------------------------------------------------- info methods */
/**
* getClassId
*
* @param cname string
* @return int/err
**/
* Get class id from name
*
* @param cname string
* @return int/err
*/
function getClassId($cname)
{
return $this->dbc->getOne($query = "SELECT id FROM {$this->classTable} WHERE cname='$cname'");
return $this->dbc->getOne($query = "SELECT id FROM {$this->classTable}
WHERE cname='$cname'");
}
/**
* getClassName
*
* @param id int
* @return string/err
**/
* Get class name from id
*
* @param id int
* @return string/err
*/
function getClassName($id)
{
return $this->dbc->getOne($query = "SELECT cname FROM {$this->classTable} WHERE id=$id");
return $this->dbc->getOne(
$query = "SELECT cname FROM {$this->classTable}WHERE id=$id");
}
/**
* isClass
*
* @param id int
* @return boolean/err
**/
* Return true is object is class
*
* @param id int
* @return boolean/err
*/
function isClass($id)
{
$r = $this->dbc->getOne("SELECT count(*) FROM {$this->classTable} WHERE id=$id");
$r = $this->dbc->getOne("SELECT count(*) FROM {$this->classTable}
WHERE id=$id");
if(PEAR::isError($r)) return $r;
return ($r > 0);
}
/**
* getClasses
*
* @return array/err
**/
* Return all classes
*
* @return array/err
*/
function getClasses()
{
return $this->dbc->getAll("SELECT * FROM {$this->classTable}");
}
/**
* listClass
*
* @param id int
* @return array/err
**/
* Return all objects in class
*
* @param id int
* @return array/err
*/
function listClass($id)
{
return $this->dbc->getAll("SELECT t.* FROM {$this->cmembTable} cm, {$this->treeTable} t
return $this->dbc->getAll("
SELECT t.* FROM {$this->cmembTable} cm, {$this->treeTable} t
WHERE cm.cid=$id AND cm.objid=t.id");
}
/* ========== test and debug methods: ========== */
/* =============================================== test and debug methods */
/**
* dumpClasses
*
* @param id int
* @param indstr string // indentation string
* @param ind string // aktual indentation
* @return string
**/
* Dump all classes fot debug
*
* @param indstr string // indentation string
* @param ind string // aktual indentation
* @return string
*/
function dumpClasses($indstr=' ', $ind='')
{
$r = $ind.join(', ', array_map(create_function('$v', 'return "{$v[\'cname\']} ({$v[\'cnt\']})";'),
$r = $ind.join(', ', array_map(
create_function('$v', 'return "{$v[\'cname\']} ({$v[\'cnt\']})";'),
$this->dbc->getAll("
SELECT cname, count(cm.objid)as cnt FROM {$this->classTable} c
LEFT JOIN {$this->cmembTable} cm ON c.id=cm.cid
@ -195,15 +237,19 @@ class ObjClasses extends Mtree{
}
/**
* testData
*
**/
* Delete all classes and membeship records
*
*/
function deleteData()
{
$this->dbc->query("DELETE FROM {$this->cmembTable}");
$this->dbc->query("DELETE FROM {$this->classTable}");
parent::deleteData();
}
/**
* Insert test data
*
*/
function testData()
{
parent::testData();
@ -215,9 +261,9 @@ class ObjClasses extends Mtree{
}
/**
* test
*
**/
* Make basic test
*
*/
function test()
{
if(PEAR::isError($p = parent::test())) return $p;
@ -226,19 +272,23 @@ class ObjClasses extends Mtree{
$this->test_correct = "Sections b (0), Class 2 (2)\n";
$this->test_dump = $this->dumpClasses();
$this->removeClass('Sections b');
$this->removeObjFromClass($this->tdata['tree'][4], $this->tdata['classes'][1]);
$this->removeObjFromClass($this->tdata['tree'][4],
$this->tdata['classes'][1]);
$this->test_correct .= "Class 2 (1)\n";
$this->test_dump .= $this->dumpClasses();
$this->deleteData();
if($this->test_dump==$this->test_correct){ $this->test_log.="class: OK\n"; return TRUE; }
else return PEAR::raiseError('ObjClasses::test:', 1, PEAR_ERROR_DIE, '%s'.
"<pre>\ncorrect:\n{$this->test_correct}\ndump:\n{$this->test_dump}\n</pre>\n");
if($this->test_dump==$this->test_correct){
$this->test_log.="class: OK\n"; return TRUE;
}else return PEAR::raiseError(
'ObjClasses::test:', 1, PEAR_ERROR_DIE, '%s'.
"<pre>\ncorrect:\n{$this->test_correct}\n".
"dump:\n{$this->test_dump}\n</pre>\n");
}
/**
* install - create tables + initialize
*
**/
* Create tables + initialize
*
*/
function install()
{
parent::install();
@ -246,15 +296,22 @@ class ObjClasses extends Mtree{
id int not null,
cname varchar(20)
)");
$this->dbc->query("CREATE UNIQUE INDEX {$this->classTable}_id_idx on {$this->classTable} (id)");
$this->dbc->query("CREATE UNIQUE INDEX {$this->classTable}_cname_idx on {$this->classTable} (cname)");
$this->dbc->query("CREATE UNIQUE INDEX {$this->classTable}_id_idx
ON {$this->classTable} (id)");
$this->dbc->query("CREATE UNIQUE INDEX {$this->classTable}_cname_idx
ON {$this->classTable} (cname)");
$this->dbc->query("CREATE TABLE {$this->cmembTable} (
objid int not null,
cid int not null
)");
$this->dbc->query("CREATE UNIQUE INDEX {$this->cmembTable}_idx on {$this->cmembTable} (objid, cid)");
$this->dbc->query("CREATE UNIQUE INDEX {$this->cmembTable}_idx
ON {$this->cmembTable} (objid, cid)");
}
/**
* Drop tables etc.
*
*/
function uninstall()
{
$this->dbc->query("DROP TABLE {$this->classTable}");

View file

@ -1,7 +1,34 @@
<?php
// $Id: alibExCls.php,v 1.1 2004/07/23 00:22:13 tomas Exp $
require_once"alib_h.php";
require_once"alibExTestAuth.php";
/*------------------------------------------------------------------------------
Copyright (c) 2004 Media Development Loan Fund
This file is part of the LiveSupport project.
http://livesupport.campware.org/
To report bugs, send an e-mail to bugs@campware.org
LiveSupport is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
LiveSupport is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with LiveSupport; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Author : $Author: tomas $
Version : $Revision: 1.2 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/alib/var/example/alibExCls.php,v $
------------------------------------------------------------------------------*/
require_once "alib_h.php";
require_once "alibExTestAuth.php";
if(isset($_GET['id']) && is_numeric($_GET['id'])){ $id = $_GET['id']; $list=false; }
else $list=true;
@ -24,7 +51,7 @@ if($list){
}
$d['msg'] = $_SESSION['alertMsg']; unset($_SESSION['alertMsg']);
require_once"alib_f.php";
require_once "alib_f.php";
// template follows:
?>
<html><head>

View file

@ -1,6 +1,33 @@
<?php
// $Id: alibExLogin.php,v 1.1 2004/07/23 00:22:13 tomas Exp $
require_once"alib_h.php";
/*------------------------------------------------------------------------------
Copyright (c) 2004 Media Development Loan Fund
This file is part of the LiveSupport project.
http://livesupport.campware.org/
To report bugs, send an e-mail to bugs@campware.org
LiveSupport is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
LiveSupport is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with LiveSupport; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Author : $Author: tomas $
Version : $Revision: 1.2 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/alib/var/example/alibExLogin.php,v $
------------------------------------------------------------------------------*/
require_once "alib_h.php";
// prefill data structure for template
$d = array(
@ -20,7 +47,7 @@ if(is_array($_SESSION['lastPost'])) $d = array_merge($d, array(
unset($_SESSION['lastPost']);
#header("Content-type: text/plain"); print_r($d); exit;
require_once"alib_f.php";
require_once "alib_f.php";
// template follows:
?>
<html><head>
@ -100,7 +127,7 @@ Permission matrix for subject: <select name="subj">
<hr>
<a href="../install.php?ak=inst">reset db + test all</a><br/>
<!--<a href="../install.php?ak=inst">reset db + test all</a><br/>-->
<?php if($d['msg']){ //error message printing: ?>
<script type="text/javascript">

View file

@ -1,7 +1,34 @@
<?php
// $Id: alibExPList.php,v 1.1 2004/07/23 00:22:13 tomas Exp $
require_once"alib_h.php";
require_once"alibExTestAuth.php";
/*------------------------------------------------------------------------------
Copyright (c) 2004 Media Development Loan Fund
This file is part of the LiveSupport project.
http://livesupport.campware.org/
To report bugs, send an e-mail to bugs@campware.org
LiveSupport is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
LiveSupport is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with LiveSupport; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Author : $Author: tomas $
Version : $Revision: 1.2 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/alib/var/example/alibExPList.php,v $
------------------------------------------------------------------------------*/
require_once "alib_h.php";
require_once "alibExTestAuth.php";
if(isset($_GET['id']) && is_numeric($_GET['id'])){ $id = $_GET['id']; }
else $id=1;
@ -16,7 +43,7 @@ else $id=1;
);
$d['msg'] = $_SESSION['alertMsg']; unset($_SESSION['alertMsg']);
require_once"alib_f.php";
require_once "alib_f.php";
// template follows:
?>
<html><head>

View file

@ -1,6 +1,33 @@
<?php
// $Id: alibExPMatrix.php,v 1.1 2004/07/23 00:22:13 tomas Exp $
require_once"alib_h.php";
/*------------------------------------------------------------------------------
Copyright (c) 2004 Media Development Loan Fund
This file is part of the LiveSupport project.
http://livesupport.campware.org/
To report bugs, send an e-mail to bugs@campware.org
LiveSupport is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
LiveSupport is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with LiveSupport; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Author : $Author: tomas $
Version : $Revision: 1.2 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/alib/var/example/alibExPMatrix.php,v $
------------------------------------------------------------------------------*/
require_once "alib_h.php";
$sid=$_GET['subj'];

View file

@ -1,7 +1,34 @@
<?php
// $Id: alibExPerms.php,v 1.1 2004/07/23 00:22:13 tomas Exp $
require_once"alib_h.php";
require_once"alibExTestAuth.php";
/*------------------------------------------------------------------------------
Copyright (c) 2004 Media Development Loan Fund
This file is part of the LiveSupport project.
http://livesupport.campware.org/
To report bugs, send an e-mail to bugs@campware.org
LiveSupport is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
LiveSupport is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with LiveSupport; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Author : $Author: tomas $
Version : $Revision: 1.2 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/alib/var/example/alibExPerms.php,v $
------------------------------------------------------------------------------*/
require_once "alib_h.php";
require_once "alibExTestAuth.php";
if(isset($_GET['id']) && is_numeric($_GET['id'])){
$id = $_GET['id'];
@ -32,7 +59,7 @@ if(!$alib->isClass($id)){
}
$d['msg'] = $_SESSION['alertMsg']; unset($_SESSION['alertMsg']);
require_once"alib_f.php";
require_once "alib_f.php";
// template follows:
?>
<html><head>

View file

@ -1,7 +1,34 @@
<?php
// $Id: alibExSubj.php,v 1.1 2004/07/23 00:22:13 tomas Exp $
require_once"alib_h.php";
require_once"alibExTestAuth.php";
/*------------------------------------------------------------------------------
Copyright (c) 2004 Media Development Loan Fund
This file is part of the LiveSupport project.
http://livesupport.campware.org/
To report bugs, send an e-mail to bugs@campware.org
LiveSupport is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
LiveSupport is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with LiveSupport; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Author : $Author: tomas $
Version : $Revision: 1.2 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/alib/var/example/alibExSubj.php,v $
------------------------------------------------------------------------------*/
require_once "alib_h.php";
require_once "alibExTestAuth.php";
if(isset($_GET['id']) && is_numeric($_GET['id'])){ $id = $_GET['id']; $list=false; }
else $list=true;
@ -23,7 +50,7 @@ if($list){
}
$d['msg'] = $_SESSION['alertMsg']; unset($_SESSION['alertMsg']);
require_once"alib_f.php";
require_once "alib_f.php";
// template follows:
?>
<html><head>

View file

@ -1,5 +1,32 @@
<?php
// $Id: alibExTestAuth.php,v 1.1 2004/07/23 00:22:13 tomas Exp $
/*------------------------------------------------------------------------------
Copyright (c) 2004 Media Development Loan Fund
This file is part of the LiveSupport project.
http://livesupport.campware.org/
To report bugs, send an e-mail to bugs@campware.org
LiveSupport is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
LiveSupport is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with LiveSupport; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Author : $Author: tomas $
Version : $Revision: 1.2 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/alib/var/example/alibExTestAuth.php,v $
------------------------------------------------------------------------------*/
$login = $alib->getSessLogin($_REQUEST['alibsid']);
if(!isset($login)||$login==''){
$_SESSION['alertMsg'] = "Login required";

View file

@ -1,7 +1,34 @@
<?php
// $Id: alibExTree.php,v 1.1 2004/07/23 00:22:13 tomas Exp $
require_once"alib_h.php";
require_once"alibExTestAuth.php";
/*------------------------------------------------------------------------------
Copyright (c) 2004 Media Development Loan Fund
This file is part of the LiveSupport project.
http://livesupport.campware.org/
To report bugs, send an e-mail to bugs@campware.org
LiveSupport is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
LiveSupport is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with LiveSupport; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Author : $Author: tomas $
Version : $Revision: 1.2 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/alib/var/example/alibExTree.php,v $
------------------------------------------------------------------------------*/
require_once "alib_h.php";
require_once "alibExTestAuth.php";
if(isset($_GET['id']) && is_numeric($_GET['id'])) $id = $_GET['id'];
else $id = $alib->getRootNode();
@ -17,9 +44,9 @@ $d = array(
'id' => $id,
'loggedAs' => $login
);
$d['msg'] = $_SESSION['alertMsg']; unset($_SESSION['alertMsg']);
$d['msg'] = preg_replace(array("|\n|","|'|"), array("\\n","\\'"), $_SESSION['alertMsg']); unset($_SESSION['alertMsg']);
require_once"alib_f.php";
require_once "alib_f.php";
// template follows:
?>
<html><head>

View file

@ -1,8 +1,35 @@
<?php
// $Id: alibHttp.php,v 1.1 2004/07/23 00:22:13 tomas Exp $
require_once"alib_h.php";
/*------------------------------------------------------------------------------
#header("Content-type: text/plain"); echo"GET:\n"; print_r($_GET); echo"POST:\n"; print_r($_POST); exit;
Copyright (c) 2004 Media Development Loan Fund
This file is part of the LiveSupport project.
http://livesupport.campware.org/
To report bugs, send an e-mail to bugs@campware.org
LiveSupport is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
LiveSupport is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with LiveSupport; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Author : $Author: tomas $
Version : $Revision: 1.2 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/alib/var/example/alibHttp.php,v $
------------------------------------------------------------------------------*/
require_once "alib_h.php";
#echo"<pre>\nGET:\n"; print_r($_GET); echo"POST:\n"; print_r($_POST); exit;
function getPGval($vn, $dfl='')
{
@ -20,11 +47,15 @@ switch($act)
if($sessid = $alib->login($_POST['login'], $_POST['pass'])){
setcookie('alibsid', $sessid);
$redirUrl="alibExTree.php";
}else{ $redirUrl="alibExLogin.php"; $_SESSION['alertMsg']='Login failed.'; }
}else{
$redirUrl="alibExLogin.php"; $_SESSION['alertMsg']='Login failed.';
}
break;
case"logout";
$r = $alib->logout($_REQUEST['alibsid']);
if(PEAR::isError($r)) $_SESSION['alertMsg'] = $r->getMessage().", ".$r->getUserInfo();
if(PEAR::isError($r)){
$_SESSION['alertMsg'] = $r->getMessage().", ".$r->getUserInfo();
}
setcookie('alibsid', '');
$redirUrl="alibExLogin.php";
break;
@ -33,8 +64,17 @@ switch($act)
&& $_POST['type']!=''
&& $_POST['name']!=''
){
$oid = $alib->addObj($_POST['name'], $_POST['type'], $_POST['id'], $_POST['position']);
$alib->addPerm($userid, '_all', $oid);
$position = ($_POST['position']=='I' ? null : $_POST['position']);
$oid = $alib->addObj(
$_POST['name'], $_POST['type'], $_POST['id'], $position
);
if(PEAR::isError($oid)){
$_SESSION['alertMsg'] =
$oid->getMessage().", ".$oid->getUserInfo();
}else $r = $alib->addPerm($userid, '_all', $oid);
if(PEAR::isError($r)){
$_SESSION['alertMsg'] = $r->getMessage().", ".$r->getUserInfo();
}
}else $_SESSION['alertMsg']='Access denied.';
break;
case"deleteNode";
@ -45,10 +85,14 @@ switch($act)
case"addPerm";
$a = $alib->isClass($_POST['id']) ? 'classes':'editPerms';
$id = $alib->isClass($_POST['id']) ? '':$_POST['id'];
if($alib->checkPerm($userid, $a, $id))
$alib->addPerm($_POST['subj'], $_POST['permAction'], $_POST['id'], $_POST['allowDeny']);
else $_SESSION['alertMsg']='Access denied.';
$redirUrl="alibExPerms.php".(($reid=getPGval('reid', '')) ? "?id=$reid":"");
if($alib->checkPerm($userid, $a, $id)){
$alib->addPerm(
$_POST['subj'], $_POST['permAction'],
$_POST['id'], $_POST['allowDeny']
);
}else $_SESSION['alertMsg']='Access denied.';
$redirUrl = "alibExPerms.php".
(($reid=getPGval('reid', '')) ? "?id=$reid":"");
break;
case"removePerm";
$a = $alib->isClass($_REQUEST['oid']) ? 'classes':'editPerms';
@ -56,10 +100,14 @@ switch($act)
if($alib->checkPerm($userid, $a, $oid))
$alib->removePerm($_GET['permid']);
else $_SESSION['alertMsg']='Access denied.';
$redirUrl=($_REQUEST['reurl']==plist ? "alibExPList.php":"alibExPerms.php").(($reid=getPGval('reid', '')) ? "?id=$reid":"");
$redirUrl =
($_REQUEST['reurl']==plist ? "alibExPList.php":"alibExPerms.php").
(($reid=getPGval('reid', '')) ? "?id=$reid":"");
break;
case"checkPerm";
$res = $alib->checkPerm($_POST['subj'], $_POST['permAction'], $_POST['obj']);
$res = $alib->checkPerm(
$_POST['subj'], $_POST['permAction'], $_POST['obj']
);
$_SESSION['alertMsg'] = ($res ? "permitted: ":"DENIED: ").
" {$_POST['permAction']} for ".$alib->getSubjName($_POST['subj']).
" on ".$alib->getObjName($_POST['obj']);
@ -94,13 +142,15 @@ switch($act)
if($alib->checkPerm($userid, 'subjects'))
$alib->addSubj2Gr($_POST['login'], $_POST['gname']);
else $_SESSION['alertMsg']='Access denied.';
$redirUrl="alibExSubj.php".(($id=getPGval('reid', '')) ? "?id=$reid":"");
$redirUrl = "alibExSubj.php".
(($id=getPGval('reid', '')) ? "?id=$reid":"");
break;
case"removeSubjFromGr";
if($alib->checkPerm($userid, 'subjects'))
$alib->removeSubjFromGr($_GET['login'], $_GET['gname']);
else $_SESSION['alertMsg']='Access denied.';
$redirUrl="alibExSubj.php".(($id=getPGval('reid', '')) ? "?id=$reid":"");
$redirUrl = "alibExSubj.php".
(($id=getPGval('reid', '')) ? "?id=$reid":"");
break;
case"addObj2Class";
if($alib->checkPerm($userid, 'classes'))

View file

@ -1,12 +1,40 @@
<?php
// $Id: conf.php,v 1.1 2004/07/23 00:22:13 tomas Exp $
/*------------------------------------------------------------------------------
Copyright (c) 2004 Media Development Loan Fund
This file is part of the LiveSupport project.
http://livesupport.campware.org/
To report bugs, send an e-mail to bugs@campware.org
LiveSupport is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
LiveSupport is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with LiveSupport; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Author : $Author: tomas $
Version : $Revision: 1.2 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/alib/var/example/conf.php,v $
------------------------------------------------------------------------------*/
$config = array(
'dsn' => array( // data source definition
'username' => 'tomash',
'password' => '',
'username' => 'test',
'password' => 'test',
'hostspec' => 'localhost',
'phptype' => 'pgsql',
'database' => 'mdlf'
'database' => 'LiveSupport-test'
),
'tblNamePrefix' => 'al_',
# 'tblNamePrefix' => 'gb_',
@ -18,15 +46,23 @@ $config = array(
'Section' => array('Title', 'Image', 'Par')
),
'allowedActions'=> array(
'RootNode' => array('addChilds', 'editPerms', 'read', 'edit', 'delete', 'classes', 'subjects'),
'Publication' => array('addChilds', 'editPerms', 'read', 'edit', 'delete'),
'Issue' => array('addChilds', 'editPerms', 'read', 'edit', 'delete'),
'Section' => array('addChilds', 'editPerms', 'read', 'edit', 'delete'),
'RootNode' => array(
'addChilds', 'editPerms', 'read', 'edit', 'delete',
'classes', 'subjects'),
'Publication' => array(
'addChilds', 'editPerms', 'read', 'edit', 'delete'),
'Issue' => array(
'addChilds', 'editPerms', 'read', 'edit', 'delete'),
'Section' => array(
'addChilds', 'editPerms', 'read', 'edit', 'delete'),
'Title' => array('editPerms', 'read', 'edit', 'delete'),
'Image' => array('editPerms', 'read', 'edit', 'delete'),
'Par' => array('editPerms', 'read', 'edit', 'delete'),
'_class' => array('addChilds', 'editPerms', 'read', 'edit', 'delete')
'_class' => array(
'addChilds', 'editPerms', 'read', 'edit', 'delete')
),
'allActions'=> array('editPerms', 'addChilds', 'read', 'edit', 'delete', 'classes', 'subjects')
'allActions'=> array(
'editPerms', 'addChilds', 'read', 'edit', 'delete',
'classes', 'subjects')
);
?>

View file

@ -1,7 +1,38 @@
<?php
// $Id: index.php,v 1.1 2004/07/23 00:22:13 tomas Exp $
/*------------------------------------------------------------------------------
header ("location: install.php");
die;
Copyright (c) 2004 Media Development Loan Fund
This file is part of the LiveSupport project.
http://livesupport.campware.org/
To report bugs, send an e-mail to bugs@campware.org
LiveSupport is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
LiveSupport is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with LiveSupport; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Author : $Author: tomas $
Version : $Revision: 1.2 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/alib/var/index.php,v $
------------------------------------------------------------------------------*/
?>
<html><head>
<title>ALib module</title>
<meta name="author" content="$Author: tomas $"/>
</head><body>
<h3>Alib</h3>
<a href="example/">Example</a><br>
<!--<a href="xmlrpc/">XmlRpc test</a>-->
</body></html>

View file

@ -1,65 +0,0 @@
<?
// $Id: install.php,v 1.1 2004/07/23 00:22:13 tomas Exp $
require_once 'example/conf.php';
require_once 'DB.php';
require_once 'alib.php';
function errCallback($err)
{
if(assert_options(ASSERT_ACTIVE)==1) return;
echo "<pre>\n";
echo "request: "; print_r($_REQUEST);
echo "gm:\n".$err->getMessage()."\ndi:\n".$err->getDebugInfo()."\nui:\n".$err->getUserInfo()."\n</pre>\n";
exit;
}
PEAR::setErrorHandling(PEAR_ERROR_PRINT, "%s<hr>\n");
$dbc = DB::connect($config['dsn'], TRUE);
if(PEAR::isError($dbc)){
echo "Database connection problem.\n";
echo "Create database '{$config['dsn']['database']}' or change 'dsn' values in conf.php.\n";
exit;
}
$dbc->setFetchMode(DB_FETCHMODE_ASSOC);
$alib =& new Alib($dbc, $config);
?>
<html><head>
<title>ALib install</title>
</head><body>
<h3>Alib install</h3>
<pre>
<?
if($_REQUEST['ak']=='inst'){
$dbc->setErrorHandling(PEAR_ERROR_RETURN);
# $dbc->setErrorHandling(PEAR_ERROR_PRINT, "%s<hr>\n");
echo "Trying to uninstall all ...\n";
$alib->uninstall();
$dbc->setErrorHandling(PEAR_ERROR_PRINT, "%s<hr>\n");
# $dbc->setErrorHandling(PEAR_ERROR_CALLBACK, 'errCallback');
echo "Install ...\n";
$alib->install();
echo "Testing ...\n";
$alib->test();
$log = $alib->test_log;
echo "TESTS:\n$log\n---\n";
echo "Reinstall + testdata insert ...\n";
$alib->reinstall();
$alib->testData();
echo "TREE DUMP:\n";
echo $alib->dumpTree();
echo "\n<b>Alib is probably installed OK</b>\n\n\n";
}
$dbc->disconnect();
?>
</pre>
<a href="install.php?ak=inst">Install/reinstall !</a><br>
<br>
<a href="example/">Example</a><br>
<a href="xmlrpc/">XmlRpc test</a>
</body></html>

View file

@ -0,0 +1,73 @@
<?
/*------------------------------------------------------------------------------
Copyright (c) 2004 Media Development Loan Fund
This file is part of the LiveSupport project.
http://livesupport.campware.org/
To report bugs, send an e-mail to bugs@campware.org
LiveSupport is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
LiveSupport is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with LiveSupport; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Author : $Author: tomas $
Version : $Revision: 1.1 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/alib/var/install/install.php,v $
------------------------------------------------------------------------------*/
require_once '../example/conf.php';
require_once 'DB.php';
require_once '../alib.php';
function errCallback($err)
{
if(assert_options(ASSERT_ACTIVE)==1) return;
echo "ERROR:\n";
echo "request: "; print_r($_REQUEST);
echo "gm:\n".$err->getMessage()."\ndi:\n".$err->getDebugInfo()."\nui:\n".$err->getUserInfo()."\n</pre>\n";
exit;
}
PEAR::setErrorHandling(PEAR_ERROR_PRINT, "%s<hr>\n");
$dbc = DB::connect($config['dsn'], TRUE);
if(PEAR::isError($dbc)){
echo "Database connection problem.\n";
echo "Check if database '{$config['dsn']['database']}' exists with corresponding permissions.\n";
echo "Database access is defined by 'dsn' values in conf.php.\n";
exit;
}
$dbc->setFetchMode(DB_FETCHMODE_ASSOC);
$alib =& new Alib($dbc, $config);
echo "Alib: Install ...\n";
$alib->install();
echo " Testing ...\n";
$alib->test();
$log = $alib->test_log;
echo " TESTS:\n$log\n---\n";
echo " Reinstall + testdata insert ...\n";
$alib->reinstall();
$alib->testData();
echo " TREE DUMP:\n";
echo $alib->dumpTree();
echo "\n Alib is probably installed OK\n";
$dbc->disconnect();
?>

View file

@ -0,0 +1,61 @@
<?
/*------------------------------------------------------------------------------
Copyright (c) 2004 Media Development Loan Fund
This file is part of the LiveSupport project.
http://livesupport.campware.org/
To report bugs, send an e-mail to bugs@campware.org
LiveSupport is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
LiveSupport is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with LiveSupport; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Author : $Author: tomas $
Version : $Revision: 1.1 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/alib/var/install/uninstall.php,v $
------------------------------------------------------------------------------*/
require_once '../example/conf.php';
require_once 'DB.php';
require_once '../alib.php';
function errCallback($err)
{
if(assert_options(ASSERT_ACTIVE)==1) return;
echo "ERROR:\n";
echo "request: "; print_r($_REQUEST);
echo "gm:\n".$err->getMessage()."\ndi:\n".$err->getDebugInfo()."\nui:\n".$err->getUserInfo()."\n</pre>\n";
exit;
}
PEAR::setErrorHandling(PEAR_ERROR_PRINT, "%s<hr>\n");
$dbc = DB::connect($config['dsn'], TRUE);
if(PEAR::isError($dbc)){
echo "Database connection problem.\n";
echo "Check if database '{$config['dsn']['database']}' exists with corresponding permissions.\n";
echo "Database access is defined by 'dsn' values in conf.php.\n";
exit;
}
$dbc->setFetchMode(DB_FETCHMODE_ASSOC);
$alib =& new Alib($dbc, $config);
# $dbc->setErrorHandling(PEAR_ERROR_RETURN);
echo "Trying to uninstall all ...\n";
$alib->uninstall();
$dbc->disconnect();
?>

View file

@ -1,39 +1,69 @@
<?php
// $Id: mtree.php,v 1.1 2004/07/23 00:22:13 tomas Exp $
/*------------------------------------------------------------------------------
/**
* Mtree class
*
* class for tree hierarchy stored in db
*
* example config: example/conf.php
* example minimal config:
* $config = array(
* 'dsn' => array( // data source definition
* 'username' => DBUSER,
* 'password' => DBPASSWORD,
* 'hostspec' => 'localhost',
* 'phptype' => 'pgsql',
* 'database' => DBNAME
* ),
* 'tblNamePrefix' => 'al_',
* 'RootNode' =>'RootNode',
* );
* (mysql phptype is tested too, but psql is recommended)
**/
Copyright (c) 2004 Media Development Loan Fund
This file is part of the LiveSupport project.
http://livesupport.campware.org/
To report bugs, send an e-mail to bugs@campware.org
LiveSupport is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
LiveSupport is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with LiveSupport; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Author : $Author: tomas $
Version : $Revision: 1.2 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/alib/var/Attic/mtree.php,v $
------------------------------------------------------------------------------*/
define('ALIBERR_MTREE', 10);
/**
* Mtree class
*
* class for tree hierarchy stored in db
*
* example config: example/conf.php<br>
* example minimal config:
* <pre><code>
* $config = array(
* 'dsn' => array( // data source definition
* 'username' => DBUSER,
* 'password' => DBPASSWORD,
* 'hostspec' => 'localhost',
* 'phptype' => 'pgsql',
* 'database' => DBNAME
* ),
* 'tblNamePrefix' => 'al_',
* 'RootNode' =>'RootNode',
* );
* </code></pre>
* @author $Author: tomas $
* @version $Revision: 1.2 $
* @see ObjClasses
*/
class Mtree{
var $dbc;
var $config;
var $treeTable;
var $rootNodeName;
/** Mtree - constructor
*
* @param dbc object
* @param config array
* @return this
**/
/** Constructor
*
* @param dbc object
* @param config array
* @return this
*/
function Mtree(&$dbc, $config)
{
$this->dbc =& $dbc;
@ -42,23 +72,26 @@ class Mtree{
$this->rootNodeName = $config['RootNode'];
}
/* ========== public methods: ========== */
/* ======================================================= public methods */
/**
* addObj
*
* @param name string
* @param type string
* @param parid int OPT // parent id
* @param aftid int OPT // after id
* @param param string OPT
* @return int/err // new id of inserted object
**/
function addObj($name, $type, $parid=1, $aftid=NULL, $param='')
* Add new object of specified type to the tree under specified parent
* node as last child or after specified sibling
*
* @param name string
* @param type string
* @param parid int, optional, parent id
* @param aftid int, optional, after id
* @return int/err - new id of inserted object or PEAR::error
*/
function addObj($name, $type, $parid=1, $aftid=NULL)
{
if($name=='' || $type=='') return PEAR::raiseError('Mtree::addObj: Wrong name or type', ALIBERR_MTREE);
if($name=='' || $type=='') return PEAR::raiseError(
'Mtree::addObj: Wrong name or type', ALIBERR_MTREE
);
$this->dbc->query("BEGIN");
$r = $this->dbc->query("LOCK TABLE {$this->treeTable}"); if(PEAR::isError($r)) return $r;
$r = $this->dbc->query("LOCK TABLE {$this->treeTable}");
if(PEAR::isError($r)) return $r;
// position resolving:
if(is_null($aftid)){ // add object as last child
$after = $this->dbc->getOne("
@ -70,7 +103,7 @@ class Mtree{
FROM {$this->treeTable} WHERE id='$aftid'");
}
if(PEAR::isError($after)) return $this->_dbRollback($after);
if(is_null($after)){ // position not specified - add as first child
if(is_null($after)){ // position not specified - add as first child
$after = $this->dbc->getOne("
SELECT lft FROM {$this->treeTable} WHERE id='$parid'
");
@ -78,20 +111,28 @@ class Mtree{
if(PEAR::isError($after)) return $this->_dbRollback($after);
$after = intval($after);
// tree level resolving:
$level = $this->dbc->getOne("SELECT level FROM {$this->treeTable} WHERE id='$parid'");
if(is_null($level)) return $this->_dbRollback('addObj: parent does not exist');
$level = $this->dbc->getOne("SELECT level FROM {$this->treeTable}
WHERE id='$parid'");
if(is_null($level))
return $this->_dbRollback('addObj: parent does not exist');
if(PEAR::isError($level)) return $this->_dbRollback($level);
$id = $this->dbc->nextId("{$this->treeTable}_id_seq");
if(PEAR::isError($id)) return $this->_dbRollback($id);
// creating space in rgt/lft sequencies:
$r = $this->dbc->query("UPDATE {$this->treeTable} SET rgt=rgt+2 WHERE rgt>$after");
$r = $this->dbc->query("UPDATE {$this->treeTable} SET rgt=rgt+2
WHERE rgt>$after");
if(PEAR::isError($r)) return $this->_dbRollback($r);
$r = $this->dbc->query("UPDATE {$this->treeTable} SET lft=lft+2 WHERE lft>$after");
$r = $this->dbc->query("UPDATE {$this->treeTable} SET lft=lft+2
WHERE lft>$after");
if(PEAR::isError($r)) return $this->_dbRollback($r);
// inserting object:
$r = $this->dbc->query("
INSERT INTO {$this->treeTable} (id, name, type, parid, level, lft, rgt, param)
VALUES ('$id', '$name', '$type', $parid, ".($level+1).", ".($after+1).", ".($after+2).", '$param')
INSERT INTO {$this->treeTable}
(id, name, type, parid, level, lft, rgt)
VALUES
('$id', '$name', '$type', $parid,
".($level+1).", ".($after+1).", ".($after+2)."
)
");
if(PEAR::isError($r)) return $this->_dbRollback($r);
$r = $this->dbc->query("COMMIT");
@ -100,41 +141,45 @@ class Mtree{
}
/**
* copyObj
*
* @param id int
* @param newParid int
* @param after int OPT
* @return int/err
**/
* Create copy of specified object and insert copy to new position
*
* @param id int, source object id
* @param newParid int, destination parent id
* @param after int, optional, destinantion after id
* @return int/err - new id of inserted object or PEAR::error
*/
function copyObj($id, $newParid, $after=NULL)
{
$o = $this->dbc->getRow("SELECT * FROM {$this->treeTable} WHERE id='$id'");
$o = $this->dbc->getRow("SELECT * FROM {$this->treeTable}
WHERE id='$id'");
if(PEAR::isError($o)) return $o;
$nid = $this->addObj($o['name'], $o['type'], $newParid, $after, $o['param']);
$nid = $this->addObj(
$o['name'], $o['type'], $newParid, $after, $o['param']
);
return $nid;
}
/**
* renameObj
*
* @param id int
* @param newName string
* @return int/err
**/
* Rename of specified object
*
* @param id int, object id to rename
* @param newName string, new name
* @return boolean/err - True or PEAR::error
*/
function renameObj($id, $newName)
{
$r = $this->dbc->query("UPDATE {$this->treeTable} SET name='$newName' WHERE id='$id'");
$r = $this->dbc->query("UPDATE {$this->treeTable} SET name='$newName'
WHERE id='$id'");
if(PEAR::isError($r)) return $r;
return TRUE;
}
/**
* removeObj
*
* @param id int
* @return boolean/err
**/
* Remove of specified object
*
* @param id int, object id to remove
* @return boolean/err - TRUE or PEAR::error
*/
function removeObj($id)
{
$dirarr = $this->getDir($id); if(PEAR::isError($dirarr)) return $dirarr;
@ -143,86 +188,95 @@ class Mtree{
$this->removeObj($snod['id']);
}
$this->dbc->query("BEGIN");
$r = $this->dbc->query("LOCK TABLE {$this->treeTable}"); if(PEAR::isError($r)) return $r;
$rgt = $this->dbc->getOne("SELECT rgt FROM {$this->treeTable} WHERE id='$id'");
if(is_null($rgt)) return $this->_dbRollback('removeObj: object not exists');
$r = $this->dbc->query("LOCK TABLE {$this->treeTable}");
if(PEAR::isError($r)) return $r;
$rgt = $this->dbc->getOne("SELECT rgt FROM {$this->treeTable}
WHERE id='$id'");
if(is_null($rgt))
return $this->_dbRollback('removeObj: object not exists');
// deleting object:
$r = $this->dbc->query("DELETE FROM {$this->treeTable} WHERE id='$id'");
if(PEAR::isError($r)) return $this->_dbRollback($r);
// closing the space in rgt/lft sequencies:
$r = $this->dbc->query("UPDATE {$this->treeTable} SET rgt=rgt-2 WHERE rgt>$rgt");
$r = $this->dbc->query("UPDATE {$this->treeTable} SET rgt=rgt-2
WHERE rgt>$rgt");
if(PEAR::isError($r)) return $this->_dbRollback($r);
$r = $this->dbc->query("UPDATE {$this->treeTable} SET lft=lft-2 WHERE lft>$rgt");
$r = $this->dbc->query("UPDATE {$this->treeTable} SET lft=lft-2
WHERE lft>$rgt");
if(PEAR::isError($r)) return $this->_dbRollback($r);
$r = $this->dbc->query("COMMIT");
if(PEAR::isError($r)) return $this->_dbRollback($r);
return TRUE;
}
/* --- info methods: --- */
/* --------------------------------------------------------- info methods */
/**
* getObjId - search dir for object by name
*
* @param name string
* @param parId int OPT
* @return int/err
**/
* Search for child id by name
*
* @param name string, searched name
* @param parId int, optional, parent id (default is root node)
* @return int/null/err - child id (if found) or null or PEAR::error
*/
function getObjId($name, $parId=NULL)
{
if($name=='' && is_null($parId)) $name = $this->rootNodeName;
return $this->dbc->getOne(
"SELECT id FROM {$this->treeTable} WHERE name='$name' and ".($parId ? "parid='$parId'":"parid is null")
"SELECT id FROM {$this->treeTable}
WHERE name='$name' and ".($parId ? "parid='$parId'":"parid is null")
);
}
/**
* getObjName - get one value for object (default: get name)
*
* @param oid int
* @param fld string OPT
* @return string/err
**/
* Get one value for object (default: get name) by id
*
* @param oid int
* @param fld string, optional, requested field (default: name)
* @return string/err
*/
function getObjName($oid, $fld='name')
{
return $this->dbc->getOne("SELECT $fld FROM {$this->treeTable} WHERE id='$oid'");
return $this->dbc->getOne("SELECT $fld FROM {$this->treeTable}
WHERE id='$oid'");
}
/**
* getObjType
*
* @param oid int
* @return string/err
**/
* Get object type by id
*
* @param oid int
* @return string/err
*/
function getObjType($oid)
{
return $this->getObjName($oid, 'type');
}
/**
* getParent
*
* @param id int
* @return string/err
**/
* Get parent id
*
* @param oid int
* @return string/err
*/
function getParent($oid)
{
return $this->getObjName($oid, 'parid');
}
/**
* getPath - get array of nodes in object's path
*
* @param id int
* @param flds string OPT
* @return array/err
**/
* Get array of nodes in object's path from root node
*
* @param id int
* @param flds string, optional
* @return array/err
*/
function getPath($id, $flds='id')
{
$this->dbc->query("BEGIN");
$a = $this->dbc->getRow("SELECT name, lft, rgt FROM {$this->treeTable} WHERE id='$id'");
$a = $this->dbc->getRow("SELECT name, lft, rgt FROM {$this->treeTable}
WHERE id='$id'");
$res = $this->dbc->getAll("
SELECT $flds FROM {$this->treeTable} WHERE lft<={$a['lft']} AND rgt>={$a['rgt']}
SELECT $flds FROM {$this->treeTable}
WHERE lft<={$a['lft']} AND rgt>={$a['rgt']}
ORDER by lft
");
$this->dbc->query("COMMIT");
@ -230,37 +284,41 @@ class Mtree{
}
/**
* getDir - get array of childnodes
*
* @param id int
* @param flds string OPT
* @param order string OPT
* @return array/err
**/
* Get array of childnodes
*
* @param id int
* @param flds string, optional, comma separated list of requested fields
* @param order string, optional, fieldname for order by clause
* @return array/err
*/
function getDir($id, $flds='id', $order='lft')
{
return $this->dbc->getAll("
SELECT $flds FROM {$this->treeTable} WHERE parid='$id' ORDER BY $order
SELECT $flds FROM {$this->treeTable}
WHERE parid='$id' ORDER BY $order
");
}
/**
* getSubTree
*
* @param id int OPT
* @param withRoot boolean OPT
* @return array/err
**/
* Get subtree of specified node
*
* @param id int, optional, default: root node
* @param withRoot boolean, optional, include/exclude specified node
* @return array/err
*/
function getSubTree($id=NULL, $withRoot=FALSE)
{
if(is_null($id)) $id = $this->getRootNode();
$r = array();
if($withRoot) $r[] = $re = $this->dbc->getRow("SELECT id, name, level FROM {$this->treeTable} WHERE id='$id'");
if($withRoot) $r[] = $re = $this->dbc->getRow(
"SELECT id, name, level FROM {$this->treeTable} WHERE id='$id'"
);
if(PEAR::isError($re)) return $re;
$dirarr = $this->getDir($id); if(PEAR::isError($dirarr)) return $dirarr;
foreach($dirarr as $k=>$snod)
{
$r[] = $re = $this->dbc->getRow("SELECT id, name, level FROM {$this->treeTable} WHERE id={$snod['id']}");
$r[] = $re = $this->dbc->getRow("SELECT id, name, level
FROM {$this->treeTable} WHERE id={$snod['id']}");
if(PEAR::isError($re)) return $re;
$r = array_merge($r, $this->getSubTree($snod['id']));
}
@ -268,77 +326,93 @@ class Mtree{
}
/**
* getRootNode - get id of root node
*
* @return int/err
**/
* Get id of root node
*
* @return int/err
*/
function getRootNode()
{
return $this->getObjId($this->rootNodeName);
}
/**
* getAllObjects
*
* @return array/err
**/
* Get all objects in the tree
*
* @return array/err
*/
function getAllObjects()
{
return $this->dbc->getAll("SELECT * FROM {$this->treeTable} ORDER BY lft");
return $this->dbc->getAll(
"SELECT * FROM {$this->treeTable} ORDER BY lft"
);
}
/* --- info methods related to application structure: --- */
/* (this part should be added/rewritten to allow defining/modifying/using application structure) */
/* (only very simple structure definition - in config - supported now) */
/* ------------------------ info methods related to application structure */
/* (this part should be added/rewritten to allow defining/modifying/using
* application structure)
* (only very simple structure definition - in $config - supported now)
*/
/**
* getAllowedChildTypes
*
* @param type string
* @return array
**/
* Get child types allowed by application definition
*
* @param type string
* @return array
*/
function getAllowedChildTypes($type)
{
return $this->config['objtypes'][$type];
}
/* ========== "private" methods: ========== */
/* ==================================================== "private" methods */
/**
* _dbRollback
*
* @param r object/string
* @return err
**/
* Do SQL rollback and return PEAR::error
*
* @param r object/string
* @return err
*/
function _dbRollback($r)
{
$this->dbc->query("ROLLBACK");
if(PEAR::isError($r)) return $r;
elseif(is_string($r)) return PEAR::raiseError("ERROR: ".get_class($this).": $r", ALIBERR_MTREE, PEAR_ERROR_RETURN);
else return PEAR::raiseError("ERROR: ".get_class($this).": unknown error", ALIBERR_MTREE, PEAR_ERROR_RETURN);
elseif(is_string($r)) return PEAR::raiseError(
"ERROR: ".get_class($this).": $r", ALIBERR_MTREE, PEAR_ERROR_RETURN
);
else return PEAR::raiseError(
"ERROR: ".get_class($this).": unknown error",
ALIBERR_MTREE, PEAR_ERROR_RETURN
);
}
/**
* _relocateSubtree - move subtree to another node without removing/adding
*
* @param id int
* @param newParid int
* @param after int
* @return boolean/err
**/
* Move subtree to another node without removing/adding
* Little bit complicated - sorry - it probably should be simlified ... ;)
*
* @param id int
* @param newParid int
* @param after int
* @return boolean/err
*/
function _relocateSubtree($id, $newParid, $after=NULL)
{
$this->dbc->query("BEGIN");
$r = $this->dbc->query("LOCK TABLE {$this->treeTable}"); if(PEAR::isError($r)) return $r;
$r = $this->dbc->query("LOCK TABLE {$this->treeTable}");
if(PEAR::isError($r)) return $r;
// obtain values for source node:
$a1 = $this->dbc->getRow("SELECT lft, rgt, level FROM {$this->treeTable} WHERE id='$id'");
if(is_null($a1)) return $this->_dbRollback('_relocateSubtree: object not exists');
$a1 = $this->dbc->getRow("SELECT lft, rgt, level FROM {$this->treeTable}
WHERE id='$id'");
if(is_null($a1))
return $this->_dbRollback('_relocateSubtree: object not exists');
extract($a1);
// values for destination node:
$a2 = $this->dbc->getRow("SELECT rgt, level FROM {$this->treeTable} WHERE id='$newParid'");
if(is_null($a2)) return $this->_dbRollback('_relocateSubtree: new parent not exists');
$a2 = $this->dbc->getRow("SELECT rgt, level FROM {$this->treeTable}
WHERE id='$newParid'");
if(is_null($a2))return $this->_dbRollback(
'_relocateSubtree: new parent not exists'
);
$nprgt = $a2['rgt']; $newLevel = $a2['level'];
// calculate differencies:
if(is_null($after)) $after = $nprgt-1;
@ -346,35 +420,44 @@ class Mtree{
$dif2 = $after-$lft+1;
$dif3 = $newLevel-$level+1;
// relocate the object"
$r = $this->dbc->query("UPDATE {$this->treeTable} SET parid='$newParid' WHERE id='$id'");
$r = $this->dbc->query(
"UPDATE {$this->treeTable} SET parid='$newParid' WHERE id='$id'");
if(PEAR::isError($r)) return $this->_dbRollback($r);
if($after>$rgt){
// relocate subtree to the right:
$r = $this->dbc->query("UPDATE {$this->treeTable} SET rgt=rgt+$dif1 WHERE rgt>$after");
$r = $this->dbc->query(
"UPDATE {$this->treeTable} SET rgt=rgt+$dif1 WHERE rgt>$after");
if(PEAR::isError($r)) return $this->_dbRollback($r);
$r = $this->dbc->query("UPDATE {$this->treeTable} SET lft=lft+$dif1 WHERE lft>$after");
$r = $this->dbc->query(
"UPDATE {$this->treeTable} SET lft=lft+$dif1 WHERE lft>$after");
if(PEAR::isError($r)) return $this->_dbRollback($r);
$r = $this->dbc->query("UPDATE {$this->treeTable}
SET lft=lft+$dif2, rgt=rgt+$dif2, level=level+$dif3
WHERE lft>=$lft AND rgt <=$rgt");
if(PEAR::isError($r)) return $this->_dbRollback($r);
$r = $this->dbc->query("UPDATE {$this->treeTable} SET rgt=rgt-$dif1 WHERE rgt>$rgt");
$r = $this->dbc->query(
"UPDATE {$this->treeTable} SET rgt=rgt-$dif1 WHERE rgt>$rgt");
if(PEAR::isError($r)) return $this->_dbRollback($r);
$r = $this->dbc->query("UPDATE {$this->treeTable} SET lft=lft-$dif1 WHERE lft>$rgt");
$r = $this->dbc->query(
"UPDATE {$this->treeTable} SET lft=lft-$dif1 WHERE lft>$rgt");
if(PEAR::isError($r)) return $this->_dbRollback($r);
}else{
// relocate subtree to the left:
$r = $this->dbc->query("UPDATE {$this->treeTable} SET rgt=rgt+$dif1 WHERE rgt>$after");
$r = $this->dbc->query(
"UPDATE {$this->treeTable} SET rgt=rgt+$dif1 WHERE rgt>$after");
if(PEAR::isError($r)) return $this->_dbRollback($r);
$r = $this->dbc->query("UPDATE {$this->treeTable} SET lft=lft+$dif1 WHERE lft>$after");
$r = $this->dbc->query(
"UPDATE {$this->treeTable} SET lft=lft+$dif1 WHERE lft>$after");
if(PEAR::isError($r)) return $this->_dbRollback($r);
$r = $this->dbc->query("UPDATE {$this->treeTable}
SET lft=lft+$dif2-$dif1, rgt=rgt+$dif2-$dif1, level=level+$dif3
WHERE lft>=$lft+$dif1 AND rgt <=$rgt+$dif1");
if(PEAR::isError($r)) return $this->_dbRollback($r);
$r = $this->dbc->query("UPDATE {$this->treeTable} SET rgt=rgt-$dif1 WHERE rgt>$rgt+$dif1");
$r = $this->dbc->query("UPDATE {$this->treeTable} SET rgt=rgt-$dif1
WHERE rgt>$rgt+$dif1");
if(PEAR::isError($r)) return $this->_dbRollback($r);
$r = $this->dbc->query("UPDATE {$this->treeTable} SET lft=lft-$dif1 WHERE lft>$rgt+$dif1");
$r = $this->dbc->query("UPDATE {$this->treeTable} SET lft=lft-$dif1
WHERE lft>$rgt+$dif1");
if(PEAR::isError($r)) return $this->_dbRollback($r);
}
$r = $this->dbc->query("COMMIT");
@ -383,13 +466,13 @@ class Mtree{
}
/**
* _copySubtree - recursive copyObj
*
* @param id int
* @param newParid int
* @param after int
* @return array
**/
* Recursive copyObj - copy of whole subtree
*
* @param id int
* @param newParid int
* @param after int
* @return array
*/
function _copySubtree($id, $newParid, $after=NULL)
{
$nid = $this->copyObj($id, $newParid, $after);
@ -400,52 +483,55 @@ class Mtree{
$r = $this->_copySubtree($snod['id'], $nid);
if(PEAR::isError($r)) return $r;
}
return TRUE;
}
/* ========== test and debug methods: ========== */
/* =============================================== test and debug methods */
/**
* dumpTree
*
* @param id int
* @param indstr string // indentation string
* @param ind string // aktual indentation
* @return string
**/
function dumpTree($id=NULL, $indstr=' ', $ind='', $format='{name}', $withRoot=TRUE)
* Human readable dump of subtree - for debug
*
* @param id int
* @param indstr string, indentation string
* @param ind string, aktual indentation
* @return string
*/
function dumpTree($id=NULL, $indstr=' ', $ind='',
$format='{name}', $withRoot=TRUE)
{
$r='';
foreach($this->getSubTree($id, $withRoot) as $o)
$r .= str_repeat($indstr, intval($o['level'])).
preg_replace(array('|\{name\}|', '|\{id\}|'), array($o['name'], $o['id']), $format).
preg_replace(array('|\{name\}|', '|\{id\}|'),
array($o['name'], $o['id']), $format).
"\n";
return $r;
}
/**
* deleteData
*
**/
* Delete all nodes except the root
*
*/
function deleteData()
{
$this->dbc->query("DELETE FROM {$this->treeTable} WHERE parid is not null");
$this->dbc->query("DELETE FROM {$this->treeTable}
WHERE parid is not null");
}
/**
* testData
*
* @param id int OPT
* @return array
**/
* Insert test data to the tree
*
* @return array
*/
function testData()
{
$o[] = $rootId = $this->getRootNode();
$o[] = $p1 = $this->addObj('Publication A', 'Publication', $rootId); // 1
$o[] = $p2 = $this->addObj('Publication B', 'Publication', $rootId); // 2
$o[] = $i1 = $this->addObj('Issue 1', 'Issue', $p1); // 3
$o[] = $i2 = $this->addObj('Issue 2', 'Issue', $p1); // 4
$o[] = $p1 = $this->addObj('Publication A', 'Publication', $rootId); //1
$o[] = $p2 = $this->addObj('Publication B', 'Publication', $rootId); //2
$o[] = $i1 = $this->addObj('Issue 1', 'Issue', $p1); //3
$o[] = $i2 = $this->addObj('Issue 2', 'Issue', $p1); //4
$o[] = $s1 = $this->addObj('Section a', 'Section', $i2);
$o[] = $s2 = $this->addObj('Section b', 'Section', $i2); // 6
$o[] = $s2 = $this->addObj('Section b', 'Section', $i2); //6
$o[] = $s3 = $this->addObj('Section c', 'Section', $i2);
$o[] = $t1 = $this->addObj('Title', 'Title', $s2);
$o[] = $s4 = $this->addObj('Section a', 'Section', $i1);
@ -454,29 +540,35 @@ class Mtree{
}
/**
* test
*
**/
* Make basic test
*
*/
function test()
{
$this->deleteData();
$this->testData();
$rootId = $this->getRootNode();
$this->test_correct ="RootNode\n Publication A\n Issue 1\n Section a\n Section b\n Issue 2\n Section a\n Section b\n Title\n Section c\n Publication B\nRootNode\n";
$this->test_correct ="RootNode\n Publication A\n Issue 1\n".
" Section a\n Section b\n Issue 2\n".
" Section a\n Section b\n".
" Title\n Section c\n Publication B\n".
"RootNode\n";
$this->test_dump = $this->dumpTree();
$this->removeObj($this->tdata['tree'][1]);
$this->removeObj($this->tdata['tree'][2]);
$this->test_dump .= $this->dumpTree();
$this->deleteData();
if($this->test_dump == $this->test_correct){ $this->test_log.="tree: OK\n"; return TRUE; }
else return PEAR::raiseError('Mtree::test:', 1, PEAR_ERROR_DIE, '%s'.
"<pre>\ncorrect:\n.{$this->test_correct}.\ndump:\n.{$this->test_dump}.\n</pre>\n");
if($this->test_dump == $this->test_correct){
$this->test_log.="tree: OK\n"; return TRUE;
}else return PEAR::raiseError('Mtree::test:', 1, PEAR_ERROR_DIE, '%s'.
"<pre>\ncorrect:\n.{$this->test_correct}.\n".
"dump:\n.{$this->test_dump}.\n</pre>\n");
}
/**
* install - create tables + initialize
*
**/
* Create tables + initialize
*
*/
function install()
{
$this->dbc->query("CREATE TABLE {$this->treeTable} (
@ -489,19 +581,23 @@ class Mtree{
type varchar(255) not null default'',
param varchar(255)
)");
$this->dbc->query("CREATE UNIQUE INDEX {$this->treeTable}_id_idx on {$this->treeTable} (id)");
$this->dbc->query("CREATE INDEX {$this->treeTable}_name_idx on {$this->treeTable} (name)");
$this->dbc->query("CREATE UNIQUE INDEX {$this->treeTable}_id_idx
ON {$this->treeTable} (id)");
$this->dbc->query("CREATE INDEX {$this->treeTable}_name_idx
ON {$this->treeTable} (name)");
$this->dbc->createSequence("{$this->treeTable}_id_seq");
$id = $this->dbc->nextId("{$this->treeTable}_id_seq");
$this->dbc->query("INSERT INTO {$this->treeTable} (id, name, parid, level, lft, rgt, type)
VALUES ($id, '{$this->rootNodeName}', NULL, 0, 1, 2, 'RootNode')");
$this->dbc->query("INSERT INTO {$this->treeTable}
(id, name, parid, level, lft, rgt, type)
VALUES
($id, '{$this->rootNodeName}', NULL, 0, 1, 2, 'RootNode')");
}
/**
* uninstall
*
**/
* Drop tables etc.
*
*/
function uninstall()
{
$this->dbc->query("DROP TABLE {$this->treeTable}");
@ -509,9 +605,9 @@ class Mtree{
}
/**
* reinstall
*
**/
* Uninstall and install
*
*/
function reinstall()
{
$this->uninstall();

View file

@ -1,27 +1,58 @@
<?php
// $Id: subj.php,v 1.1 2004/07/23 00:22:13 tomas Exp $
/*------------------------------------------------------------------------------
/**
* Subj class
*
* users + groups
* with "linearized recursive membership" ;)
* (allow adding users to groups or groups to groups)
*
**/
require_once"class.php";
Copyright (c) 2004 Media Development Loan Fund
This file is part of the LiveSupport project.
http://livesupport.campware.org/
To report bugs, send an e-mail to bugs@campware.org
LiveSupport is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
LiveSupport is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with LiveSupport; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Author : $Author: tomas $
Version : $Revision: 1.2 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/alib/var/subj.php,v $
------------------------------------------------------------------------------*/
require_once "class.php";
define('ALIBERR_NOTGR', 20);
define('ALIBERR_BADSMEMB', 21);
/**
* Subj class
*
* users + groups
* with "linearized recursive membership" ;)
* (allow adding users to groups or groups to groups)
*
* @author $Author: tomas $
* @version $Revision: 1.2 $
* @see ObjClasses
* @see Alib
*/
class Subjects extends ObjClasses{
var $subjTable;
var $smembTable;
/** Subjects - constructor
*
* @param dbc object
* @param config array
* @return this
**/
/**
* Constructor
*
* @param dbc object
* @param config array
* @return this
*/
function Subjects(&$dbc, $config)
{
parent::ObjClasses(&$dbc, $config);
@ -29,51 +60,55 @@ class Subjects extends ObjClasses{
$this->smembTable = $config['tblNamePrefix'].'smemb';
}
/* ========== public methods: ========== */
/* ======================================================= public methods */
/**
* addSubj
*
* @param login string
* @param pass string OPT
* @return int/err
**/
* Add new subject
*
* @param login string
* @param pass string, optional
* @return int/err
*/
function addSubj($login, $pass=NULL)
{
$id = $this->dbc->nextId("{$this->subjTable}_id_seq"); if(PEAR::isError($id)) return $id;
$id = $this->dbc->nextId("{$this->subjTable}_id_seq");
if(PEAR::isError($id)) return $id;
$r = $this->dbc->query("
INSERT INTO {$this->subjTable} (id, login, pass, type)
VALUES ($id, '$login', ".(is_null($pass) ? "'!', 'G'" : "'".md5($pass)."', 'U'").")
VALUES ($id, '$login', ".
(is_null($pass) ? "'!', 'G'" : "'".md5($pass)."', 'U'").")
");
if(PEAR::isError($r)) return $r;
return $id;
}
/**
* removeSubj
*
* @param login string
* @param uid int OPT
* @return boolean/err
**/
* Remove subject by uid or by login
*
* @param login string
* @param uid int, optional, default: null
* @return boolean/err
*/
function removeSubj($login, $uid=NULL)
{
if(is_null($uid)) $uid = $this->getSubjId($login);
if(PEAR::isError($uid)) return $uid;
$r = $this->dbc->query("DELETE FROM {$this->smembTable} WHERE (uid='$uid' OR gid='$uid') AND mid is null");
$r = $this->dbc->query("DELETE FROM {$this->smembTable}
WHERE (uid='$uid' OR gid='$uid') AND mid is null");
if(PEAR::isError($r)) return $r;
$r = $this->dbc->query("DELETE FROM {$this->subjTable} WHERE login='$login'");
$r = $this->dbc->query("DELETE FROM {$this->subjTable}
WHERE login='$login'");
if(PEAR::isError($r)) return $r;
return $this->_rebuildRels();
}
/**
* authenticate
*
* @param login string
* @param pass string OPT
* @return boolean/int/err
**/
* Check login and password
*
* @param login string
* @param pass string, optional
* @return boolean/int/err
*/
function authenticate($login, $pass='')
{
$cpass = md5($pass);
@ -85,44 +120,70 @@ class Subjects extends ObjClasses{
return (is_null($id) ? FALSE : $id);
}
/* --- groups --- */
/**
* Change user password
*
* @param login string
* @param oldpass string
* @param pass string, optional
* @return boolean/err
*/
function passwd($login, $oldpass, $pass='')
{
$cpass = md5($pass);
$oldcpass = md5($oldpass);
$this->dbc->query("
UPDATE {$this->subjTable} SET pass='$cpass'
WHERE login='$login' AND pass='$oldcpass' AND type='U'
");
if(PEAR::isError($id)) return $id;
return TRUE;
}
/* --------------------------------------------------------------- groups */
/**
* addSubj2Gr - add {login} and direct/indirect members to {gname} and to groups, where {gname} is [in]direct member
*
* @param login string
* @param gname string
* @return int/err
**/
* Add {login} and direct/indirect members to {gname} and to groups,
* where {gname} is [in]direct member
*
* @param login string
* @param gname string
* @return int/err
*/
function addSubj2Gr($login, $gname)
{
$uid = $this->getSubjId($login); if(PEAR::isError($uid)) return $uid;
$gid = $this->getSubjId($gname); if(PEAR::isError($gid)) return $gid;
$isgr = $this->isGroup($gid); if(PEAR::isError($isgr)) return $isgr;
if(!$isgr) return PEAR::raiseError("Subjects::addSubj2Gr: Not a group ($gname)", ALIBERR_NOTGR);
if(!$isgr) return PEAR::raiseError(
"Subjects::addSubj2Gr: Not a group ($gname)", ALIBERR_NOTGR
);
// add subject and all [in]direct members to group $gname:
$mid = $this->_plainAddSubj2Gr($uid, $gid); if(PEAR::isError($mid)) return $mid;
$mid = $this->_plainAddSubj2Gr($uid, $gid);
if(PEAR::isError($mid)) return $mid;
// add it to all groups where $gname is [in]direct member:
$marr = $this->_listRMemb($gid); if(PEAR::isError($marr)) return $marr;
foreach($marr as $k=>$v){
$r = $this->_plainAddSubj2Gr($uid, $v['gid'], intval($v['level'])+1, $v['id']);
$r = $this->_plainAddSubj2Gr(
$uid, $v['gid'], intval($v['level'])+1, $v['id']);
if(PEAR::isError($r)) return $r;
}
return $mid;
}
/**
* removeSubjFromGr
*
* @param login string
* @param gname string
* @return boolean/err
**/
* Remove subject from group
*
* @param login string
* @param gname string
* @return boolean/err
*/
function removeSubjFromGr($login, $gname)
{
$uid = $this->getSubjId($login); if(PEAR::isError($uid)) return $uid;
$gid = $this->getSubjId($gname); if(PEAR::isError($gid)) return $gid;
$mid = $this->dbc->getOne($q = "SELECT id FROM {$this->smembTable} WHERE uid='$uid' AND gid='$gid' AND mid is null");
$mid = $this->dbc->getOne($q = "SELECT id FROM {$this->smembTable}
WHERE uid='$uid' AND gid='$gid' AND mid is null");
if(is_null($mid)) return FALSE;
if(PEAR::isError($mid)) return $mid;
// remove it:
@ -132,106 +193,121 @@ class Subjects extends ObjClasses{
return TRUE;
}
/* --- info methods: --- */
/* --------------------------------------------------------- info methods */
/**
* getSubjId
*
* @param login string
* @return int/err
**/
* Get subject id from login
*
* @param login string
* @return int/err
*/
function getSubjId($login)
{
return $this->dbc->getOne("SELECT id FROM {$this->subjTable} WHERE login='$login'");
return $this->dbc->getOne("SELECT id FROM {$this->subjTable}
WHERE login='$login'");
}
/**
* getSubjName
*
* @param id int
* @param fld string
* @return string/err
**/
* Get subject name (login) from id
*
* @param id int
* @param fld string
* @return string/err
*/
function getSubjName($id, $fld='login')
{
return $this->dbc->getOne("SELECT $fld FROM {$this->subjTable} WHERE id='$id'");
return $this->dbc->getOne("SELECT $fld FROM {$this->subjTable}
WHERE id='$id'");
}
/**
* getSubjects
*
* @param flds string OPT
* @return array/err
**/
* Get all subjects
*
* @param flds string, optional
* @return array/err
*/
function getSubjects($flds='id, login')
{
return $this->dbc->getAll("SELECT $flds FROM {$this->subjTable}");
}
/**
* getSubjectsWCnt - get subjects with count of direct members
*
* @return array/err
**/
* Get subjects with count of direct members
*
* @return array/err
*/
function getSubjectsWCnt()
{
return $this->dbc->getAll("SELECT count(m.uid)as cnt, s.id, s.login, s.type
FROM {$this->subjTable} s LEFT JOIN {$this->smembTable} m ON m.gid=s.id
WHERE m.mid is null GROUP BY s.id, s.login, s.type ORDER BY s.id");
return $this->dbc->getAll("
SELECT count(m.uid)as cnt, s.id, s.login, s.type
FROM {$this->subjTable} s
LEFT JOIN {$this->smembTable} m ON m.gid=s.id
WHERE m.mid is null
GROUP BY s.id, s.login, s.type
ORDER BY s.id"
);
}
/**
* isGroup
*
* @param gid int
* @return boolean/err
**/
* Return true if subject is a group
*
* @param gid int
* @return boolean/err
*/
function isGroup($gid)
{
$r = $this->dbc->getOne("SELECT type FROM {$this->subjTable} WHERE id='$gid'");
$r = $this->dbc->getOne("SELECT type FROM {$this->subjTable}
WHERE id='$gid'");
if(PEAR::isError($r)) return $r;
return ($r === 'G' );
}
/**
* listGroup - list direct members of group
*
* @param gid int
* @return array/err
**/
* List direct members of group
*
* @param gid int
* @return array/err
*/
function listGroup($gid)
{
return $this->dbc->getAll("SELECT s.id, s.login, s.type FROM {$this->smembTable} m, {$this->subjTable} s
return $this->dbc->getAll("SELECT s.id, s.login, s.type
FROM {$this->smembTable} m, {$this->subjTable} s
WHERE m.uid=s.id AND m.mid is null AND m.gid='$gid'");
}
/* ========== "private" methods: ========== */
/* ==================================================== "private" methods */
/**
* _addMemb - create membership record
*
* @param uid int
* @param gid int
* @param level int OPT
* @param mid int OPT
* @return int/err
**/
* Create membership record
*
* @param uid int
* @param gid int
* @param level int, optional
* @param mid int, optional
* @return int/err
*/
function _addMemb($uid, $gid, $level=0, $mid='null')
{
if($uid == $gid) return PEAR::raiseError("Subjects::_addMemb: uid==gid ($uid)", ALIBERR_BADSMEMB);
$a = $this->dbc->getAll("SELECT id, level, mid FROM {$this->smembTable} WHERE uid='$uid' AND gid='$gid' ORDER BY level ASC");
if($uid == $gid) return PEAR::raiseError(
"Subjects::_addMemb: uid==gid ($uid)", ALIBERR_BADSMEMB
);
$a = $this->dbc->getAll("SELECT id, level, mid FROM {$this->smembTable}
WHERE uid='$uid' AND gid='$gid' ORDER BY level ASC");
if(PEAR::isError($a)) return $a;
if(count($a)>0){
$a0 = $a[0];
$id = $a0['id'];
if($level < intval($a0['level'])){
$r = $this->dbc->query("UPDATE {$this->smembTable} SET level='$level', mid='$mid' WHERE id='{$a0['id']}'");
$r = $this->dbc->query("UPDATE {$this->smembTable}
SET level='$level', mid='$mid' WHERE id='{$a0['id']}'");
if(PEAR::isError($r)) return $r;
}
}else{
$id = $this->dbc->nextId("{$this->smembTable}_id_seq"); if(PEAR::isError($id)) return $id;
$id = $this->dbc->nextId("{$this->smembTable}_id_seq");
if(PEAR::isError($id)) return $id;
$r = $this->dbc->query("
INSERT INTO {$this->smembTable} (id, uid, gid, level, mid) VALUES ($id, $uid, $gid, $level, $mid)
INSERT INTO {$this->smembTable} (id, uid, gid, level, mid)
VALUES ($id, $uid, $gid, $level, $mid)
");
if(PEAR::isError($r)) return $r;
}
@ -239,77 +315,92 @@ class Subjects extends ObjClasses{
}
/**
* _removeMemb
*
* @param mid int
* @return null/err
**/
* Remove membership record
*
* @param mid int
* @return null/err
*/
function _removeMemb($mid)
{
return $this->dbc->query("DELETE FROM {$this->smembTable} WHERE id='$mid'");
return $this->dbc->query("DELETE FROM {$this->smembTable}
WHERE id='$mid'");
}
/**
* _listMemb - list [in]direct members of group
*
* @param gid int
* @param uid int OPT
* @return array/err
**/
* List [in]direct members of group
*
* @param gid int
* @param uid int, optional
* @return array/err
*/
function _listMemb($gid, $uid=NULL)
{
return $this->dbc->getAll("SELECT id, uid, level FROM {$this->smembTable} WHERE gid='$gid'".(is_null($uid) ? '' : " AND uid='$uid'"));
return $this->dbc->getAll("
SELECT id, uid, level FROM {$this->smembTable}
WHERE gid='$gid'".(is_null($uid) ? '' : " AND uid='$uid'"));
}
/**
* _listRMemb - list groups where uid is [in]direct member
*
* @param gid int
* @param uid int OPT
* @return array/err
**/
* List groups where uid is [in]direct member
*
* @param gid int
* @param uid int, optional
* @return array/err
*/
function _listRMemb($uid, $gid=NULL)
{
return $this->dbc->getAll("SELECT id, gid, level FROM {$this->smembTable} WHERE uid='$uid'".(is_null($gid) ? '' : " AND gid='$gid'"));
return $this->dbc->getAll("
SELECT id, gid, level FROM {$this->smembTable}
WHERE uid='$uid'".(is_null($gid) ? '' : " AND gid='$gid'"));
}
/**
* _plainAddSubj2Gr - add uid and its [in]direct members to gid
*
* @param uid int
* @param gid int
* @param level int
* @param rmid int //
* @return int/err
**/
* Add uid and its [in]direct members to gid
*
* @param uid int
* @param gid int
* @param level int
* @param rmid int //
* @return int/err
*/
function _plainAddSubj2Gr($uid, $gid, $level=0, $rmid='null')
{
$mid = $this->_addMemb($uid, $gid, $level, $rmid); if(PEAR::isError($mid)) return $mid;
$mid = $this->_addMemb($uid, $gid, $level, $rmid);
if(PEAR::isError($mid)) return $mid;
$marr = $this->_listMemb($uid); if(PEAR::isError($marr)) return $marr;
foreach($marr as $k=>$v){
$r = $this->_addMemb($v['uid'], $gid, intval($v['level'])+$level+1, $mid);
$r = $this->_addMemb(
$v['uid'], $gid, intval($v['level'])+$level+1, $mid
);
if(PEAR::isError($r)) return $r;
}
return $mid;
}
/**
* _rebuildRels - rebuild indirect membership records
*
* @return true/err
**/
* Rebuild indirect membership records<br>
* it's probably more complicated to do removing without rebuild ...
*
* @return true/err
*/
function _rebuildRels()
{
$this->dbc->query("BEGIN");
$r = $this->dbc->query("LOCK TABLE {$this->smembTable}"); if(PEAR::isError($r)) return $r;
$r = $this->dbc->query("DELETE FROM {$this->smembTable} WHERE mid is not null");
$r = $this->dbc->query("LOCK TABLE {$this->smembTable}");
if(PEAR::isError($r)) return $r;
$arr = $this->dbc->getAll("SELECT uid, gid FROM {$this->smembTable}"); // WHERE mid is null
$r = $this->dbc->query("DELETE FROM {$this->smembTable}
WHERE mid is not null");
if(PEAR::isError($r)) return $r;
$arr = $this->dbc->getAll("SELECT uid, gid FROM {$this->smembTable}");
// WHERE mid is null
if(PEAR::isError($arr)) return $arr;
foreach($arr as $it){
$marr = $this->_listRMemb($it['gid']); if(PEAR::isError($marr)) return $marr;
$marr = $this->_listRMemb($it['gid']);
if(PEAR::isError($marr)) return $marr;
foreach($marr as $k=>$v){
$r = $this->_plainAddSubj2Gr($it['uid'], $v['gid'], intval($v['level'])+1, $v['id']);
$r = $this->_plainAddSubj2Gr(
$it['uid'], $v['gid'], intval($v['level'])+1, $v['id']
);
if(PEAR::isError($r)) return $r;
}
}
@ -317,27 +408,30 @@ class Subjects extends ObjClasses{
return TRUE;
}
/* ========== test and debug methods: ========== */
/* =============================================== test and debug methods */
/**
* dumpSubjects
*
* @param indstr string // indentation string
* @param ind string // aktual indentation
* @return string
**/
* Dump subjects for debug
*
* @param indstr string // indentation string
* @param ind string // aktual indentation
* @return string
*/
function dumpSubjects($indstr=' ', $ind='')
{
# $r = $ind.join(', ', $this->dbc->getCol("SELECT login FROM {$this->subjTable}"))."\n";
$r = $ind.join(', ', array_map(create_function('$v', 'return "{$v[\'login\']}({$v[\'cnt\']})";'), $this->getSubjectsWCnt()))."\n";
$r = $ind.join(', ', array_map(
create_function('$v', 'return "{$v[\'login\']}({$v[\'cnt\']})";'),
$this->getSubjectsWCnt()
))."\n";
return $r;
}
/**
* deleteData
*
* @return void
**/
* Delete all subjects and membership records
*
* @return void
*/
function deleteData()
{
$this->dbc->query("DELETE FROM {$this->subjTable}");
@ -346,10 +440,10 @@ class Subjects extends ObjClasses{
}
/**
* testData
*
* @return array
**/
* Insert test data
*
* @return array
*/
function testData()
{
parent::testData();
@ -373,32 +467,38 @@ class Subjects extends ObjClasses{
}
/**
* test
*
**/
* Make basic test
*
*/
function test()
{
if(PEAR::isError($p = parent::test())) return $p;
$this->deleteData();
$this->testData();
$this->test_correct = "root(0), test1(0), test2(0), test3(0), test4(0), gr1(3), gr2(2), gr3(2)\n";
$this->test_correct = "root(0), test1(0), test2(0), test3(0),".
" test4(0), gr1(3), gr2(2), gr3(2)\n";
$this->test_dump = $this->dumpSubjects();
$this->removeSubj('test1');
$this->removeSubj('test3');
$this->removeSubjFromGr('test2', 'gr1');
$this->removeSubjFromGr('gr3', 'gr2');
$this->test_correct .= "root(0), test2(0), test4(0), gr1(1), gr2(1), gr3(0)\n";
$this->test_correct .= "root(0), test2(0), test4(0), gr1(1),".
" gr2(1), gr3(0)\n";
$this->test_dump .= $this->dumpSubjects();
$this->deleteData();
if($this->test_dump == $this->test_correct){ $this->test_log.="subj: OK\n"; return TRUE; }
else return PEAR::raiseError('Subjects::test:', 1, PEAR_ERROR_DIE, '%s'.
"<pre>\ncorrect:\n{$this->test_correct}\ndump:\n{$this->test_dump}\n</pre>\n");
if($this->test_dump == $this->test_correct)
{
$this->test_log.="subj: OK\n"; return TRUE;
}else return PEAR::raiseError(
'Subjects::test:', 1, PEAR_ERROR_DIE, '%s'.
"<pre>\ncorrect:\n{$this->test_correct}\n".
"dump:\n{$this->test_dump}\n</pre>\n");
}
/**
* install - create tables + initialize
*
**/
* Create tables + initialize
*
*/
function install()
{
parent::install();
@ -408,8 +508,10 @@ class Subjects extends ObjClasses{
pass varchar(255) not null default'',
type char(1) not null default 'U'
)");
$this->dbc->query("CREATE UNIQUE INDEX {$this->subjTable}_id_idx on {$this->subjTable} (id)");
$this->dbc->query("CREATE UNIQUE INDEX {$this->subjTable}_login_idx on {$this->subjTable} (login)");
$this->dbc->query("CREATE UNIQUE INDEX {$this->subjTable}_id_idx
ON {$this->subjTable} (id)");
$this->dbc->query("CREATE UNIQUE INDEX {$this->subjTable}_login_idx
ON {$this->subjTable} (login)");
$this->dbc->createSequence("{$this->subjTable}_id_seq");
$this->dbc->query("CREATE TABLE {$this->smembTable} (
@ -419,16 +521,17 @@ class Subjects extends ObjClasses{
level int not null default 0,
mid int
)");
$this->dbc->query("CREATE UNIQUE INDEX {$this->smembTable}_id_idx on {$this->smembTable} (id)");
$this->dbc->query("CREATE UNIQUE INDEX {$this->smembTable}_id_idx
ON {$this->smembTable} (id)");
$this->dbc->createSequence("{$this->smembTable}_id_seq");
}
/**
* uninstall
*
* @return void
**/
* Drop tables etc.
*
* @return void
*/
function uninstall()
{
$this->dbc->query("DROP TABLE {$this->subjTable}");

View file

@ -1,14 +1,41 @@
<?php
// $Id: alib_xr.php,v 1.1 2004/07/23 00:22:13 tomas Exp $
include_once"xmlrpc.inc";
include_once"xmlrpcs.inc";
require_once"../example/alib_h.php";
/*------------------------------------------------------------------------------
Copyright (c) 2004 Media Development Loan Fund
This file is part of the LiveSupport project.
http://livesupport.campware.org/
To report bugs, send an e-mail to bugs@campware.org
LiveSupport is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
LiveSupport is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with LiveSupport; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Author : $Author: tomas $
Version : $Revision: 1.2 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/alib/var/xmlrpc/alib_xr.php,v $
------------------------------------------------------------------------------*/
include_once "xmlrpc.inc";
include_once "xmlrpcs.inc";
require_once "../example/alib_h.php";
function v2xr($var, $struct=true){
if(is_array($var)){
$r = array();
foreach($var as $k=>$v) if($struct) $r[$k]=v2xr($v); else $r[]=v2xr($v);
return new xmlrpcval($r, ($struct?"struct":"array"));
return new xmlrpcval($r, ($struct ? "struct":"array"));
}else if(is_int($var)){
return new xmlrpcval($var, "int");
}else{
@ -16,47 +43,69 @@ function v2xr($var, $struct=true){
}
}
class XR_Alib extends alib{
/**
* XMLRPC interface for Alib class<br>
* only for testing now (with example) - LiveSupport uses special interface
*
* @author $Author: tomas $
* @version $Revision: 1.2 $
* @see Subjects
* @see GreenBox
*/
class XR_Alib extends Alib{
function xr_test($input){
$p1=$input->getParam(0);
if(isset($p1) && $p1->scalartyp()=="string") $s=$p1->scalarval();
else return new xmlrpcresp(0, 801, "xr_login: wrong 1st parameter, string expected.");
else return new xmlrpcresp(0, 801,
"xr_login: wrong 1st parameter, string expected.");
$p2=$input->getParam(1);
if(isset($p2) && $p2->scalartyp()=="string") $sessid=$p2->scalarval();
else return new xmlrpcresp(0, 801, "xr_login: wrong 2nd parameter, string expected.");
return new xmlrpcresp(v2xr(strtoupper($s)."_".$this->getSessLogin($sessid)."_".$sessid, false));
else return new xmlrpcresp(0, 801,
"xr_login: wrong 2nd parameter, string expected.");
return new xmlrpcresp(
v2xr(strtoupper($s)."_".$this->getSessLogin($sessid)."_".$sessid, false)
);
}
function xr_login($input){
$p1=$input->getParam(0);
if(isset($p1) && $p1->scalartyp()=="string") $login=$p1->scalarval();
else return new xmlrpcresp(0, 801, "xr_login: wrong 1st parameter, string expected.");
else return new xmlrpcresp(0, 801,
"xr_login: wrong 1st parameter, string expected.");
$p2=$input->getParam(1);
if(isset($p2) && $p2->scalartyp()=="string") $pass=$p2->scalarval();
else return new xmlrpcresp(0, 801, "xr_login: wrong 2nd parameter, string expected.");
else return new xmlrpcresp(0, 801,
"xr_login: wrong 2nd parameter, string expected.");
if(!($res = $this->login($login, $pass)))
return new xmlrpcresp(0, 802, "xr_login: login failed - incorrect username or password.");
return new xmlrpcresp(0, 802,
"xr_login: login failed - incorrect username or password.");
else
return new xmlrpcresp(v2xr($res, false));
}
function xr_logout($input){
$p1=$input->getParam(0);
if(isset($p1) && $p1->scalartyp()=="string") $sessid=$p1->scalarval();
else return new xmlrpcresp(0, 801, "xr_login: wrong 2nd parameter, string expected.");
else return new xmlrpcresp(0, 801,
"xr_login: wrong 2nd parameter, string expected.");
$res = $this->logout($sessid);
if(!PEAR::isError($res)) return new xmlrpcresp(v2xr('Bye', false));
else return new xmlrpcresp(0, 803, "xr_logout: logout failed - not logged.");
else return new xmlrpcresp(0, 803,
"xr_logout: logout failed - not logged.");
}
function xr_getDir($input){
$p1=$input->getParam(0);
if(isset($p1) && ($p1->scalartyp()=="int") && is_numeric($id=$p1->scalarval()));
else return new xmlrpcresp(0, 801, "xr_getDir: wrong 1st parameter, int expected.");
if(isset($p1) && ($p1->scalartyp()=="int") &&
is_numeric($id=$p1->scalarval()));
else return new xmlrpcresp(0, 801,
"xr_getDir: wrong 1st parameter, int expected.");
$res = $this->getDir($id, 'name');
return new xmlrpcresp(v2xr($res, false));
}
function xr_getPath($input){
$p1=$input->getParam(0);
if(isset($p1) && ($p1->scalartyp()=="int") && is_numeric($id=$p1->scalarval()));
else return new xmlrpcresp(0, 801, "xr_getPath: wrong 1st parameter, int expected.");
if(isset($p1) && ($p1->scalartyp()=="int") &&
is_numeric($id=$p1->scalarval()));
else return new xmlrpcresp(0, 801,
"xr_getPath: wrong 1st parameter, int expected.");
$res = $this->getPath($id, 'id, name');
return new xmlrpcresp(v2xr($res, false));
}
@ -88,12 +137,10 @@ $s=new xmlrpc_server( array(
"alib.getPath" => array(
"function" => array(&$alib, 'xr_getPath'),
"signature" => array(array($xmlrpcArray, $xmlrpcInt)),
"docstring" => "returns listing of object in path from rootnode to object with given id"
"docstring" =>
"returns listing of object in path from rootnode to object with given id"
)
));
#header("Content-type: text/plain");
#print_r($dirlist = getDir());
require_once"../example/alib_f.php";
?>

View file

@ -1,7 +1,33 @@
<?php
// $Id: index.php,v 1.1 2004/07/23 00:22:13 tomas Exp $
/*------------------------------------------------------------------------------
Copyright (c) 2004 Media Development Loan Fund
This file is part of the LiveSupport project.
http://livesupport.campware.org/
To report bugs, send an e-mail to bugs@campware.org
LiveSupport is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
LiveSupport is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with LiveSupport; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Author : $Author: tomas $
Version : $Revision: 1.2 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/alib/var/xmlrpc/index.php,v $
------------------------------------------------------------------------------*/
header ("location: xr_cli_test.php");
die;
?>

View file

@ -1,55 +0,0 @@
#!/usr/bin/python
# $Id: xr_cli_pok.py,v 1.1 2004/07/23 00:22:13 tomas Exp $
from xmlrpclib import *
import sys
if len(sys.argv)<3:
print """
Usage: xr_cli_pok.py http://<server>/<path>/xmlrpc/alib_xr.php <command> <args>
commands and args:
test <teststring> [<sessin_id>]
login <username> <password>
logout <session_id>
"""
sys.exit(1)
elif sys.argv[2]=="test":
if len(sys.argv)>3:
tstr=sys.argv[3]
if len(sys.argv)>4:
sessid=sys.argv[4]
else:
sessid=''
path=sys.argv[1]
server = Server(path)
try:
r = server.alib.xrTest(tstr, sessid)
print r
except Error, v:
print "XML-RPC Error:",v
elif sys.argv[2]=="login":
login=sys.argv[3]
passwd=sys.argv[4]
path=sys.argv[1]
server = Server(path)
try:
r = server.alib.login(login, passwd)
print r
except Error, v:
print "XML-RPC Error:",v
elif sys.argv[2]=="logout":
sessid=sys.argv[3]
path=sys.argv[1]
server = Server(path)
try:
r = server.alib.logout(sessid)
print r
except Error, v:
print "XML-RPC Error:",v
else:
print "Unknown command: "+sys.argv[2]
sys.exit(1)

View file

@ -1,6 +1,32 @@
<?php
// $Id: xr_cli_test.php,v 1.1 2004/07/23 00:22:13 tomas Exp $
/*------------------------------------------------------------------------------
Copyright (c) 2004 Media Development Loan Fund
This file is part of the LiveSupport project.
http://livesupport.campware.org/
To report bugs, send an e-mail to bugs@campware.org
LiveSupport is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
LiveSupport is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with LiveSupport; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Author : $Author: tomas $
Version : $Revision: 1.2 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/alib/var/xmlrpc/xr_cli_test.php,v $
------------------------------------------------------------------------------*/
include("xmlrpc.inc");
$host = "localhost";
@ -17,11 +43,15 @@ switch($ak){
new xmlrpcval($_REQUEST['sessid'], "string")));
break;
case"login":
$f=new xmlrpcmsg('alib.login', array(new xmlrpcval($_REQUEST['login'], "string"),
new xmlrpcval($_REQUEST['pass'], "string")));
$f=new xmlrpcmsg('alib.login',array(
new xmlrpcval($_REQUEST['login'], "string"),
new xmlrpcval($_REQUEST['pass'], "string")
));
break;
case"logout":
$f=new xmlrpcmsg('alib.logout', array(new xmlrpcval($_REQUEST['sessid'], "string")));
$f=new xmlrpcmsg('alib.logout', array(
new xmlrpcval($_REQUEST['sessid'], "string")
));
break;
}
@ -36,11 +66,15 @@ switch($ak){
$v=$r->value();
$log = $v->serialize();
if($ak=='test')
{ $log = split('_',$log); $log="{$log[0]}\nusername: {$log[1]}\ntoken: {$log[2]}"; }
{
$log = split('_',$log);
$log="{$log[0]}\nusername: {$log[1]}\ntoken: {$log[2]}";
}
if($ak=='login') $sessid = $v->scalarval();
if($ak=='logout') $sessid = '';
} else {
$log = "Fault:\n Code: ".$r->faultCode()."\nReason:'".$r->faultString()."'<BR>\n";
$log = "Fault:\n Code: ".$r->faultCode()."\n".
"Reason:'".$r->faultString()."'<BR>\n";
}
break;
}

View file

@ -0,0 +1,82 @@
#!/usr/bin/python
#------------------------------------------------------------------------------
#
# Copyright (c) 2004 Media Development Loan Fund
#
# This file is part of the LiveSupport project.
# http://livesupport.campware.org/
# To report bugs, send an e-mail to bugs@campware.org
#
# LiveSupport is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# LiveSupport is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with LiveSupport; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
#
# Author : $Author: tomas $
# Version : $Revision: 1.1 $
# Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/alib/var/xmlrpc/xr_cli_test.py,v $
#
#------------------------------------------------------------------------------
from xmlrpclib import *
import sys
if len(sys.argv)<3:
print """
Usage: xr_cli_pok.py http://<server>/<path>/xmlrpc/alib_xr.php <command> <args>
commands and args:
test <teststring> [<sessin_id>]
login <username> <password>
logout <session_id>
"""
sys.exit(1)
elif sys.argv[2]=="test":
if len(sys.argv)>3:
tstr=sys.argv[3]
if len(sys.argv)>4:
sessid=sys.argv[4]
else:
sessid=''
path=sys.argv[1]
server = Server(path)
try:
r = server.alib.xrTest(tstr, sessid)
print r
except Error, v:
print "XML-RPC Error:",v
elif sys.argv[2]=="login":
login=sys.argv[3]
passwd=sys.argv[4]
path=sys.argv[1]
server = Server(path)
try:
r = server.alib.login(login, passwd)
print r
except Error, v:
print "XML-RPC Error:",v
elif sys.argv[2]=="logout":
sessid=sys.argv[3]
path=sys.argv[1]
server = Server(path)
try:
r = server.alib.logout(sessid)
print r
except Error, v:
print "XML-RPC Error:",v
else:
print "Unknown command: "+sys.argv[2]
sys.exit(1)