Major changes with LiveSupport local storageServer module.
This commit is contained in:
parent
53e7a3d8cc
commit
37f30a7efd
28 changed files with 3024 additions and 1217 deletions
139
livesupport/modules/alib/Makefile
Normal file
139
livesupport/modules/alib/Makefile
Normal file
|
@ -0,0 +1,139 @@
|
||||||
|
#-------------------------------------------------------------------------------
|
||||||
|
# Alib - authentication and authorizaction component
|
||||||
|
# Copyright (c) 2004 Media Development Loan Fund
|
||||||
|
#
|
||||||
|
# This file is part of the LiveSupport project.
|
||||||
|
#
|
||||||
|
# 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/Attic/Makefile,v $
|
||||||
|
#
|
||||||
|
# @configure_input@
|
||||||
|
#-------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#-------------------------------------------------------------------------------
|
||||||
|
# General command definitions
|
||||||
|
#-------------------------------------------------------------------------------
|
||||||
|
MKDIR = mkdir -p
|
||||||
|
RM = rm -f
|
||||||
|
RMDIR = rm -rf
|
||||||
|
DOXYGEN = doxygen
|
||||||
|
|
||||||
|
#-------------------------------------------------------------------------------
|
||||||
|
# Misc
|
||||||
|
#-------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
MODULE_NAME = alib
|
||||||
|
TAR_C = tar -cj --exclude CVS --exclude '*~' -C ${BASE_DIR} -f
|
||||||
|
DIST_EXT = .tgz
|
||||||
|
DATE = `date +%y%m%d`
|
||||||
|
|
||||||
|
#-------------------------------------------------------------------------------
|
||||||
|
# Basic directory and file definitions
|
||||||
|
#-------------------------------------------------------------------------------
|
||||||
|
#BASE_DIR = @builddir@
|
||||||
|
BASE_DIR = .
|
||||||
|
DOC_DIR = ${BASE_DIR}/doc
|
||||||
|
DOXYGEN_DIR = ${DOC_DIR}/doxygen
|
||||||
|
ETC_DIR = ${BASE_DIR}/etc
|
||||||
|
INCLUDE_DIR = ${BASE_DIR}/include
|
||||||
|
LIB_DIR = ${BASE_DIR}/lib
|
||||||
|
SRC_DIR = ${BASE_DIR}/src
|
||||||
|
TMP_DIR = ${BASE_DIR}/tmp
|
||||||
|
|
||||||
|
USR_DIR = ${BASE_DIR}/../../usr
|
||||||
|
USR_INCLUDE_DIR = ${USR_DIR}/include
|
||||||
|
USR_LIB_DIR = ${USR_DIR}/lib
|
||||||
|
|
||||||
|
DOXYGEN_CONFIG = ${ETC_DIR}/doxygen.config
|
||||||
|
|
||||||
|
PHP_DIR = ${BASE_DIR}/var
|
||||||
|
TEST_RUNNER = ${PHP_DIR}/tests/index.php
|
||||||
|
|
||||||
|
#-------------------------------------------------------------------------------
|
||||||
|
# Configuration parameters
|
||||||
|
#-------------------------------------------------------------------------------
|
||||||
|
#CPPFLAGS = @CPPFLAGS@
|
||||||
|
#CXXFLAGS = @CXXFLAGS@ @DEFS@ -I${USR_INCLUDE_DIR} -I${INCLUDE_DIR} -I${TMP_DIR}\
|
||||||
|
# -pedantic -Wall
|
||||||
|
#LDFLAGS = @LDFLAGS@ -L${USR_LIB_DIR} -L${LIB_DIR}
|
||||||
|
|
||||||
|
|
||||||
|
#-------------------------------------------------------------------------------
|
||||||
|
# Dependencies
|
||||||
|
#-------------------------------------------------------------------------------
|
||||||
|
#HELLO_LIB_OBJS = ${TMP_DIR}/Hello.o
|
||||||
|
#TEST_RUNNER_OBJS = ${TMP_DIR}/HelloTest.o ${TMP_DIR}/TestRunner.o
|
||||||
|
|
||||||
|
|
||||||
|
#-------------------------------------------------------------------------------
|
||||||
|
# Targets
|
||||||
|
#-------------------------------------------------------------------------------
|
||||||
|
.PHONY: all dir_setup doc clean docclean depclean distclean dist db_init db_clean
|
||||||
|
|
||||||
|
all: dir_setup db_init
|
||||||
|
|
||||||
|
#dir_setup: ${TMP_DIR} ${DOXYGEN_DIR}
|
||||||
|
dir_setup: ${DOXYGEN_DIR}
|
||||||
|
|
||||||
|
doc:
|
||||||
|
${DOXYGEN} ${DOXYGEN_CONFIG}
|
||||||
|
|
||||||
|
clean: db_clean
|
||||||
|
# ${RM} ...
|
||||||
|
|
||||||
|
docclean:
|
||||||
|
${RMDIR} ${DOXYGEN_DIR}/html
|
||||||
|
|
||||||
|
depclean: clean
|
||||||
|
|
||||||
|
dist: all
|
||||||
|
${TAR_C} ${MODULE_NAME}${DATE}${DIST_EXT} *
|
||||||
|
|
||||||
|
distclean: clean docclean
|
||||||
|
# ${RMDIR} ${TMP_DIR}/config* ${TMP_DIR}/autom4te*
|
||||||
|
|
||||||
|
check: all ${TEST_RUNNER}
|
||||||
|
${TEST_RUNNER}
|
||||||
|
|
||||||
|
#-------------------------------------------------------------------------------
|
||||||
|
# Specific targets
|
||||||
|
#-------------------------------------------------------------------------------
|
||||||
|
# IMPORTANT: db_init and db_clean are commented out only for Livesupport,
|
||||||
|
# where alib is installed through storage modules
|
||||||
|
|
||||||
|
db_init:
|
||||||
|
# cd var/install; php -q install.php
|
||||||
|
|
||||||
|
db_clean:
|
||||||
|
# cd var/install; php -q uninstall.php
|
||||||
|
|
||||||
|
${TMP_DIR}:
|
||||||
|
${MKDIR} ${TMP_DIR}
|
||||||
|
|
||||||
|
${DOXYGEN_DIR}:
|
||||||
|
${MKDIR} ${DOXYGEN_DIR}
|
||||||
|
|
||||||
|
${TEST_RUNNER}:
|
||||||
|
|
||||||
|
#-------------------------------------------------------------------------------
|
||||||
|
# Pattern rules
|
||||||
|
#-------------------------------------------------------------------------------
|
||||||
|
#${TMP_DIR}/%.o : ${SRC_DIR}/%.cxx
|
||||||
|
# ${CXX} ${CPPFLAGS} ${CXXFLAGS} -c -o $@ $<
|
||||||
|
|
|
@ -1,244 +0,0 @@
|
||||||
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<meta content="text/html; charset=UTF-8" http-equiv="content-type">
|
|
||||||
<title>Auth library</title>
|
|
||||||
<meta content="Tomas Hlava - $Author: tomas $" name="author">
|
|
||||||
<style type="text/css"><!--
|
|
||||||
* { font-family: 'Arial CE', 'Helvetica CE', Arial, sans-serif; font-size: 10pt; }
|
|
||||||
body { padding: 1em; }
|
|
||||||
h1 { font-size: 14pt; padding:1px; background-color: #66aaff; }
|
|
||||||
h2 { font-size: 11pt; padding:1px; padding-left:1ex; background-color: #aaccff; }
|
|
||||||
h3 { font-size: 10pt; padding:1px; padding-left:2ex; background-color: #aaffcc; }
|
|
||||||
p { width: 90%; text-indent: 1em; }
|
|
||||||
p#ps { clear: both; }
|
|
||||||
.center { text-align:center; }
|
|
||||||
.aart { width: 90%; font-family:monospace; }
|
|
||||||
.aart span{ font-family:monospace; padding:0ex 1ex; background-color: #eee; }
|
|
||||||
.aart div{ font-family:monospace; padding:0ex 1ex; }
|
|
||||||
code { font-family:monospace; font-weight:bold; background-color: #e4e4e4; }
|
|
||||||
.b { font-weight:bold; }
|
|
||||||
.ulg p { margin-bottom: 0px; }
|
|
||||||
.ulg ul,ol { margin-top: 0px; }
|
|
||||||
.ex { padding:1em; background-color:#f0f0f0; width:80%; overflow:auto; }
|
|
||||||
.bg { padding:2px 4px; background-color:#eaeaea; }
|
|
||||||
table { border: 2px solid black; border-collapse: collapse; }
|
|
||||||
table th { border: solid black; border-width: 2px 1px; }
|
|
||||||
table td { border: 1px solid black; text-align:center; }
|
|
||||||
hr { border:0px; border-bottom: 1px solid #66aaff; }
|
|
||||||
hr.hr2 { border:0px; border-bottom: 2px solid #66aaff; }
|
|
||||||
/*#date { float: left; width:30%; padding:1ex; }*/
|
|
||||||
/*#signature { float: right; width:30%; padding:1ex; text-align: right; }*/
|
|
||||||
#signature { float: left; width:30%; padding:1ex; }
|
|
||||||
--></style>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<h1>Preface</h1>
|
|
||||||
This document is part of the <a
|
|
||||||
href="http://livesupport.campware.org/">LiveSupport</a>
|
|
||||||
|
|
||||||
project, Copyright © 2004 <a href="http://www.mdlf.org/">Media
|
|
||||||
Development Loan Fund</a>, under the GNU <a
|
|
||||||
href="http://www.gnu.org/licenses/gpl.html">GPL</a>.<br>
|
|
||||||
<ul>
|
|
||||||
<li>Author: $Author: tomas $</li>
|
|
||||||
<li>Version: $Revision: 1.2 $</li>
|
|
||||||
<li>Location: $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/alib/doc/Attic/aarfc.html,v $</li>
|
|
||||||
|
|
||||||
</ul>
|
|
||||||
<h2>Scope</h2>
|
|
||||||
This document describes authentication and authorization component of the LiveSupport project.<br>
|
|
||||||
|
|
||||||
<h1>Auth module - request for comments</h1>
|
|
||||||
25.8.2004
|
|
||||||
<h2>Authentication & authorization</h2>
|
|
||||||
<p> <span class="b">Authentication</span> - as user's identity
|
|
||||||
checking - login call create and return auth token, client sends this token
|
|
||||||
with all subsequent calls, logout call make this token invalid<br>
|
|
||||||
</p>
|
|
||||||
<p> <span class="b">Authorization</span> - as checking user's
|
|
||||||
permission for called action on some object - that's main solved problem.
|
|
||||||
</p>
|
|
||||||
<h2>Basic model</h2>
|
|
||||||
<div class="aart center"><span>Subject --- Action ---> Object</span></div>
|
|
||||||
<div class="ulg">
|
|
||||||
<p>Where:</p>
|
|
||||||
<ul>
|
|
||||||
<li>Subject<br>
|
|
||||||
is one user or user group (or role - in this aproach group and role are the same)<br>
|
|
||||||
</li>
|
|
||||||
<li>Action<br>
|
|
||||||
is item from predefined action set
|
|
||||||
</li>
|
|
||||||
<li>Object<br>
|
|
||||||
is a object from tree or class of objects
|
|
||||||
</li>
|
|
||||||
</ul>
|
|
||||||
</div>
|
|
||||||
<h2>Subject implementation</h2>
|
|
||||||
<p> Subjects are divided into two types - users and groups. There is membership relation
|
|
||||||
(type N:M) from subjects table to itself with "linearization" feature - for
|
|
||||||
questions about it send me a mail please ;)<br>
|
|
||||||
This approach allows inserting user to group or group to group with quick
|
|
||||||
searching of direct and indirect membership.
|
|
||||||
</p>
|
|
||||||
<h2>Object implementation</h2>
|
|
||||||
<p> For simple use with existing projects, there would be a object tree
|
|
||||||
always separated from project's database tables. It would be implemented by
|
|
||||||
table of objects and information about parent/child (or other) relation
|
|
||||||
between objects.
|
|
||||||
</p>
|
|
||||||
<p>
|
|
||||||
There is also class table and N:M membership relation between objects and
|
|
||||||
classes.
|
|
||||||
</p>
|
|
||||||
<h3>Example:</h3>
|
|
||||||
<div class="ex">
|
|
||||||
<pre class="aart">
|
|
||||||
RootNode
|
|
||||||
|
|
|
||||||
|-> Publication_A(publication)
|
|
||||||
| \-> Issue_1(issue) <--\
|
|
||||||
| |-> Sport(section) | <--\
|
|
||||||
| \-> Politics(section) | |
|
|
||||||
\-> Publication_B(publication) | |
|
|
||||||
|-> Issue_1(issue) <--| |
|
|
||||||
| |-> Politics(section) | |
|
|
||||||
| |-> Sport(section) | <--|
|
|
||||||
| \-> Culture(section) | |
|
|
||||||
\-> Issue_2(issue) <--| |
|
|
||||||
|-> Culture(section) | |
|
|
||||||
\-> Politics(section) | |
|
|
||||||
| |
|
|
||||||
Class "Issues" -------------------------------------------/ |
|
|
||||||
Class "Sport sections" -------------------------------------------/
|
|
||||||
</pre>
|
|
||||||
|
|
||||||
<!--
|
|
||||||
Object table structure:<br>
|
|
||||||
<code><span class="b">[</span> id, name, type, parid, lft, rgt, level <span class="b">]</span></code><br>
|
|
||||||
class table structure:<br>
|
|
||||||
<code><span class="b">[</span> id, cname <span class="b">]</span></code><br>
|
|
||||||
and class membership table structure:<br>
|
|
||||||
<code><span class="b">[</span> objid, cid <span class="b">]</span></code><br>
|
|
||||||
-->
|
|
||||||
|
|
||||||
</div>
|
|
||||||
<h2>Permissions for actions</h2>
|
|
||||||
<p> There are several ways to handle permissions - I've used this:<br>
|
|
||||||
<span class="b">allow/deny</span> - all without allow
|
|
||||||
permission is denied, but more specified setting may overcome less
|
|
||||||
specified<br>
|
|
||||||
(e.g. group of users is allowed to do smth., but one specified group-member is
|
|
||||||
denied)
|
|
||||||
</p>
|
|
||||||
<p> Permissions are stored as triple <code class="bg"><span
|
|
||||||
class="b">[</span>subject, action, object<span class="b">]</span></code>
|
|
||||||
and <span class="b">allow/deny</span> flag.<br>
|
|
||||||
</p>
|
|
||||||
<div class="ulg">
|
|
||||||
<p>Procedure of permission checking:</p>
|
|
||||||
<ul>
|
|
||||||
<li>Select all permissions on corresponding object + all objects in tree path<br>
|
|
||||||
for actual user + all groups, where user have direct or indirect membership.
|
|
||||||
</li>
|
|
||||||
<li>Sort it by:<ol>
|
|
||||||
<li>diference in tree levels for object
|
|
||||||
<li>membership level for subject
|
|
||||||
<li>record with '_all' action have lower priority
|
|
||||||
<li>'deny' records have higher priority then 'allow'
|
|
||||||
</ol></li>
|
|
||||||
<li>If no record found then repeat similar query with class table instead of object tree table. (+ similar sorting)</li>
|
|
||||||
<li>If record on the top of sorted sequence have 'allow' type then return allow else deny</li>
|
|
||||||
</ul>
|
|
||||||
</div>
|
|
||||||
<p>Rem.: Some cache system for authorization decisions would be good ...
|
|
||||||
</p>
|
|
||||||
<h2>Auth system usage</h2>
|
|
||||||
<div class="ulg">
|
|
||||||
<p>There are 3 main types of usage:</p>
|
|
||||||
<ol>
|
|
||||||
<li>authorization of called action</li>
|
|
||||||
<li>automatic modification of user interface in dependence on user
|
|
||||||
permissions</li>
|
|
||||||
<li>automatic generation of admin interface for permissions settings</li>
|
|
||||||
</ol>
|
|
||||||
</div>
|
|
||||||
<h2>Important part of API:</h2>
|
|
||||||
<div class="ulg">
|
|
||||||
<ul>
|
|
||||||
<li>function <code>Alib(&$dbc, $config)</code> returns object<br>
|
|
||||||
constructor
|
|
||||||
</li>
|
|
||||||
<li>function <code>login($login, $pass)</code> returns token<br>
|
|
||||||
</li>
|
|
||||||
<li>function <code>logout($sessid)</code> returns boolean<br>
|
|
||||||
</li>
|
|
||||||
<li>function <code>checkToken($sessid)</code> returns boolean<br>
|
|
||||||
check validity of the token
|
|
||||||
</li>
|
|
||||||
<li>function <code>addObj($name, $type, $parid, $aftid, $param)</code> returns int<br>
|
|
||||||
adds object to tree as child of object with id=$parid after object with id=$aftid
|
|
||||||
</li>
|
|
||||||
<li>function <code>removeObj($id)</code> returns boolean<br>
|
|
||||||
</li>
|
|
||||||
<li>function <code>addSubj($login, $pass)</code> returns int<br>
|
|
||||||
add user (or group - with $pass=null)
|
|
||||||
</li>
|
|
||||||
<li>function <code>removeSubj($login)</code> returns boolean<br>
|
|
||||||
</li>
|
|
||||||
<li>function <code>addPerm($sid, $action, $oid, $type)</code> returns int<br>
|
|
||||||
add permission record - type is A(allow) or D(deny)
|
|
||||||
</li>
|
|
||||||
<li>function <code>removePerm($permid, $subj, $obj)</code> returns null<br>
|
|
||||||
remove permission record
|
|
||||||
</li>
|
|
||||||
<li>function <code>checkPerm($sid, $action, $oid)</code> returns boolean<br>
|
|
||||||
check permission for action on object with id=$oid for subject with id=$sid
|
|
||||||
</li>
|
|
||||||
|
|
||||||
<li>function <code>copyObj($id, $newParid, $after)</code> returns int<br>
|
|
||||||
</li>
|
|
||||||
<li>function <code>renameObj($id, $newName)</code> returns boolean<br>
|
|
||||||
</li>
|
|
||||||
<li>function <code>getParent($oid)</code> returns string<br>
|
|
||||||
</li>
|
|
||||||
<li>function <code>getPath($id, $flds)</code> returns array<br>
|
|
||||||
</li>
|
|
||||||
<li>function <code>getDir($id, $flds, $order)</code> returns array<br>
|
|
||||||
</li>
|
|
||||||
|
|
||||||
<li>function <code>addClass($cname)</code> returns int<br>
|
|
||||||
</li>
|
|
||||||
<li>function <code>removeClass($cname)</code> returns boolean<br>
|
|
||||||
</li>
|
|
||||||
<li>function <code>addObj2Class($cid, $oid)</code> returns boolean<br>
|
|
||||||
</li>
|
|
||||||
<li>function <code>removeObjFromClass($oid, $cid)</code> returns boolean<br>
|
|
||||||
</li>
|
|
||||||
|
|
||||||
<li>function <code>addSubj2Gr($login, $gname)</code> returns int<br>
|
|
||||||
</li>
|
|
||||||
<li>function <code>removeSubjFromGr($login, $gname)</code> returns boolean<br>
|
|
||||||
</li>
|
|
||||||
<li>function <code>isGroup($gid)</code> returns boolean<br>
|
|
||||||
</li>
|
|
||||||
<li>function <code>listGroup($gid)</code> returns array<br>
|
|
||||||
</li>
|
|
||||||
</ul>
|
|
||||||
<p>All methods may return PEAR::error object if fails ...</p>
|
|
||||||
</div>
|
|
||||||
<h2>Connection to existing applications</h2>
|
|
||||||
<p> PHP applications could include Alib class and call API methods
|
|
||||||
directly.<br>
|
|
||||||
Other programming platforms should call XMLRPC or HTTP layer above this API.
|
|
||||||
</p>
|
|
||||||
<hr class="hr2">
|
|
||||||
<div id="footer">
|
|
||||||
<div id="signature"> Tomas Hlava<br>
|
|
||||||
<a href="mailto:th@red2head.com">th@red2head.com</a><br>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<p id="ps">P.S.: sorry for my English ... ;)</p>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
|
@ -1,78 +0,0 @@
|
||||||
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<meta content="text/html; charset=UTF-8" http-equiv="content-type">
|
|
||||||
<title>Alib reference</title>
|
|
||||||
<meta content="$Author: tomas $" name="author">
|
|
||||||
<style type="text/css">
|
|
||||||
<!--
|
|
||||||
* { font-family: 'Arial CE', 'Helvetica CE', Arial, sans-serif; font-size: 10pt; }
|
|
||||||
body { padding: 1em; }
|
|
||||||
h1 { font-size: 14pt; padding:1px; background-color: #66aaff; }
|
|
||||||
h2 { font-size: 11pt; padding:1px; padding-left:1ex; background-color: #aaccff; }
|
|
||||||
h3 { font-size: 10pt; padding:1px; padding-left:2ex; background-color: #aaffcc; }
|
|
||||||
p { width: 90%; text-indent: 1em; }
|
|
||||||
pre { border: 1px dashed grey; padding:1em; }
|
|
||||||
p:first-letter { padding-left:2em; }
|
|
||||||
.center { text-align:center; }
|
|
||||||
.aart { width: 90%; font-family:monospace; }
|
|
||||||
.aart span{ font-family:monospace; padding:0ex 1ex; background-color: #eee; }
|
|
||||||
.aart div{ font-family:monospace; padding:0ex 1ex; }
|
|
||||||
code { font-family:monospace; }
|
|
||||||
.b { font-weight:bold; }
|
|
||||||
-->
|
|
||||||
</style>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<h1>Preface</h1>
|
|
||||||
This document is part of the <a
|
|
||||||
href="http://livesupport.campware.org/">LiveSupport</a>
|
|
||||||
|
|
||||||
project, Copyright © 2004 <a href="http://www.mdlf.org/">Media
|
|
||||||
Development Loan Fund</a>, under the GNU <a
|
|
||||||
href="http://www.gnu.org/licenses/gpl.html">GPL</a>.<br>
|
|
||||||
<ul>
|
|
||||||
<li>Author: $Author: tomas $</li>
|
|
||||||
<li>Version: $Revision: 1.2 $</li>
|
|
||||||
<li>Location: $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/alib/doc/Attic/reference.html,v $</li>
|
|
||||||
|
|
||||||
</ul>
|
|
||||||
<h1>Alib reference</h1>
|
|
||||||
in construction - sorry ;)
|
|
||||||
|
|
||||||
<h2>Scope</h2>
|
|
||||||
This document describes authentication and authorization component of the LiveSupport project.<br>
|
|
||||||
|
|
||||||
<a name="contents"></a>
|
|
||||||
<h2>Contents</h2>
|
|
||||||
<ol>
|
|
||||||
<li><a href="#subjs">Subjects</a></li>
|
|
||||||
<li><a href="#perms">Perms</a></li>
|
|
||||||
<li><a href="#objs">Objects</a></li>
|
|
||||||
<li><a href="#classes">Classes</a></li>
|
|
||||||
<li><a href="#dbstr">DB structure</a></li>
|
|
||||||
</ol>
|
|
||||||
|
|
||||||
<a name="subjs"></a>
|
|
||||||
<h2>Subjects</h2>
|
|
||||||
|
|
||||||
<a name="perms"></a>
|
|
||||||
<h2>Perms</h2>
|
|
||||||
|
|
||||||
<a name="objects"></a>
|
|
||||||
<h2>Objects</h2>
|
|
||||||
|
|
||||||
<a name="classes"></a>
|
|
||||||
<h2>Classes</h2>
|
|
||||||
<p>Classes may be replaced by one branch in object tree ...</p>
|
|
||||||
|
|
||||||
<a name="dbstr"></a>
|
|
||||||
<h2>DB structure</h2>
|
|
||||||
<pre>
|
|
||||||
subjects < perms > objects/classes
|
|
||||||
< smemb
|
|
||||||
cmemb >
|
|
||||||
</pre>
|
|
||||||
|
|
||||||
|
|
||||||
</body></html>
|
|
|
@ -1,17 +0,0 @@
|
||||||
|
|
||||||
$Id: todo.txt,v 1.1 2004/07/23 00:22:13 tomas Exp $
|
|
||||||
|
|
||||||
* delete old sessions
|
|
||||||
* if user have 'classes' permission:
|
|
||||||
-> create new class ('X')
|
|
||||||
-> add '_all' perm on class 'X' to himself
|
|
||||||
-> insert RootNode to class 'X'
|
|
||||||
=> user have all perms ;)
|
|
||||||
* complete xmlrpc layer
|
|
||||||
|
|
||||||
---
|
|
||||||
partialy done:
|
|
||||||
|
|
||||||
. actions would have priority order (or set lower priority to '_all' action only),
|
|
||||||
temp hack: '_all' action is in string sort after all act names => with ASC order have '_all' lower prio ...
|
|
||||||
---
|
|
1144
livesupport/modules/alib/etc/doxygen.config
Normal file
1144
livesupport/modules/alib/etc/doxygen.config
Normal file
File diff suppressed because it is too large
Load diff
|
@ -1,27 +1,59 @@
|
||||||
<?php
|
<?php
|
||||||
// $Id: alib.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/alib.php,v $
|
||||||
|
|
||||||
|
------------------------------------------------------------------------------*/
|
||||||
|
require_once 'subj.php';
|
||||||
|
define('ALIBERR_NOTLOGGED', 30);
|
||||||
|
define('ALIBERR_NOTEXISTS', 31);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Alib class
|
* Alib class
|
||||||
*
|
*
|
||||||
* authentication/authorization class
|
* authentication/authorization class
|
||||||
**/
|
*
|
||||||
require_once 'subj.php';
|
* @author $Author: tomas $
|
||||||
define('ALIBERR_NOTLOGGED', 30);
|
* @version $Revision: 1.2 $
|
||||||
define('ALIBERR_NOTEXISTS', 31);
|
* @see Subjects
|
||||||
|
* @see GreenBox
|
||||||
|
*/
|
||||||
class Alib extends Subjects{
|
class Alib extends Subjects{
|
||||||
var $permTable;
|
var $permTable;
|
||||||
var $sessTable;
|
var $sessTable;
|
||||||
var $login=NULL;
|
var $login=NULL;
|
||||||
var $userid=NULL;
|
var $userid=NULL;
|
||||||
var $sessid=NULL;
|
var $sessid=NULL;
|
||||||
/** Alib - constructor
|
/**
|
||||||
|
* Constructor
|
||||||
*
|
*
|
||||||
* @param object DB
|
* @param dbc object, DB
|
||||||
* @param config array
|
* @param config array
|
||||||
* @return this
|
* @return this
|
||||||
**/
|
*/
|
||||||
function Alib(&$dbc, $config)
|
function Alib(&$dbc, $config)
|
||||||
{
|
{
|
||||||
parent::Subjects(&$dbc, $config);
|
parent::Subjects(&$dbc, $config);
|
||||||
|
@ -29,28 +61,31 @@ class Alib extends Subjects{
|
||||||
$this->sessTable = $config['tblNamePrefix'].'sess';
|
$this->sessTable = $config['tblNamePrefix'].'sess';
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ========== public methods: ========== */
|
/* ======================================================= public methods */
|
||||||
|
|
||||||
/* --- session/authentication --- */
|
/* ----------------------------------------------- session/authentication */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* login
|
* Authenticate and create session
|
||||||
*
|
*
|
||||||
* @param login string
|
* @param login string
|
||||||
* @param pass string
|
* @param pass string
|
||||||
* @return boolean/sessionId/err
|
* @return boolean/sessionId/err
|
||||||
**/
|
*/
|
||||||
function login($login, $pass)
|
function login($login, $pass)
|
||||||
{
|
{
|
||||||
if(FALSE === $this->authenticate($login, $pass)) return FALSE;
|
if(FALSE === $this->authenticate($login, $pass)) return FALSE;
|
||||||
for($c=1; $c>0;){
|
for($c=1; $c>0;){
|
||||||
$sessid = md5(uniqid(rand()));
|
$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;
|
if(PEAR::isError($c)) return $c;
|
||||||
}
|
}
|
||||||
$userid = $this->getSubjId($login);
|
$userid = $this->getSubjId($login);
|
||||||
$r = $this->dbc->query("INSERT INTO {$this->sessTable} (sessid, userid, login)
|
$r = $this->dbc->query("INSERT INTO {$this->sessTable}
|
||||||
VALUES ('$sessid', '$userid', '$login')");
|
(sessid, userid, login, ts)
|
||||||
|
VALUES
|
||||||
|
('$sessid', '$userid', '$login', now())");
|
||||||
if(PEAR::isError($r)) return $r;
|
if(PEAR::isError($r)) return $r;
|
||||||
$this->login = $login;
|
$this->login = $login;
|
||||||
$this->userid = $userid;
|
$this->userid = $userid;
|
||||||
|
@ -59,20 +94,22 @@ class Alib extends Subjects{
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* logout
|
* Logout and destroy session
|
||||||
*
|
*
|
||||||
* @param sessid string
|
* @param sessid string
|
||||||
* @return true/err
|
* @return true/err
|
||||||
**/
|
*/
|
||||||
function logout($sessid)
|
function logout($sessid)
|
||||||
{
|
{
|
||||||
$ct = $this->checkToken($sessid);
|
$ct = $this->checkToken($sessid);
|
||||||
if($ct === FALSE)
|
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))
|
elseif(PEAR::isError($ct))
|
||||||
return $ct;
|
return $ct;
|
||||||
else{
|
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;
|
if(PEAR::isError($r)) return $r;
|
||||||
$this->login = NULL;
|
$this->login = NULL;
|
||||||
$this->userid = NULL;
|
$this->userid = NULL;
|
||||||
|
@ -82,42 +119,44 @@ class Alib extends Subjects{
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* checkToken
|
* Return true if the token is valid
|
||||||
*
|
*
|
||||||
* @param sessid string
|
* @param sessid string
|
||||||
* @return boolean/err
|
* @return boolean/err
|
||||||
**/
|
*/
|
||||||
function checkToken($sessid)
|
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 ));
|
return ($c == 1 ? TRUE : (PEAR::isError($c) ? $c : FALSE ));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* setToken
|
* Set valid token in alib object
|
||||||
*
|
*
|
||||||
* @param sessid string
|
* @param sessid string
|
||||||
* @return boolean/err
|
* @return boolean/err
|
||||||
**/
|
*/
|
||||||
function setToken($sessid)
|
function setToken($sessid)
|
||||||
{
|
{
|
||||||
$r = checkToken($sessid);
|
$r = checkToken($sessid);
|
||||||
if(PEAR::isError($r)) return $r;
|
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;
|
$this->sessid = $sessid;
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* --- authorization --- */
|
/* -------------------------------------------------------- authorization */
|
||||||
/**
|
/**
|
||||||
* addPerm
|
* Insert permission record
|
||||||
*
|
*
|
||||||
* @param sid int
|
* @param sid int
|
||||||
* @param action string
|
* @param action string
|
||||||
* @param oid int
|
* @param oid int
|
||||||
* @param type char
|
* @param type char
|
||||||
* @return int/err
|
* @return int/err
|
||||||
**/
|
*/
|
||||||
function addPerm($sid, $action, $oid, $type='A')
|
function addPerm($sid, $action, $oid, $type='A')
|
||||||
{
|
{
|
||||||
$permid = $this->dbc->nextId("{$this->permTable}_id_seq");
|
$permid = $this->dbc->nextId("{$this->permTable}_id_seq");
|
||||||
|
@ -130,13 +169,13 @@ class Alib extends Subjects{
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* removePerm
|
* Remove permission record
|
||||||
*
|
*
|
||||||
* @param permid int OPT
|
* @param permid int OPT
|
||||||
* @param subj int OPT
|
* @param subj int OPT
|
||||||
* @param obj int OPT
|
* @param obj int OPT
|
||||||
* @return null/error
|
* @return null/error
|
||||||
**/
|
*/
|
||||||
function removePerm($permid=NULL, $subj=NULL, $obj=NULL)
|
function removePerm($permid=NULL, $subj=NULL, $obj=NULL)
|
||||||
{
|
{
|
||||||
return $this->dbc->query("DELETE FROM {$this->permTable} WHERE 1=1".
|
return $this->dbc->query("DELETE FROM {$this->permTable} WHERE 1=1".
|
||||||
|
@ -147,13 +186,15 @@ class Alib extends Subjects{
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* checkPerm
|
* 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 sid int
|
||||||
* @param action string
|
* @param action string
|
||||||
* @param oid int OPT
|
* @param oid int OPT
|
||||||
* @return boolean/err
|
* @return boolean/err
|
||||||
**/
|
*/
|
||||||
function checkPerm($sid, $action, $oid=NULL)
|
function checkPerm($sid, $action, $oid=NULL)
|
||||||
{
|
{
|
||||||
if(!is_numeric($sid)) return FALSE;
|
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_flds = "m.level as S_lvl, p.subj, s.login, action, p.type, p.obj";
|
||||||
$q_from = "{$this->subjTable} s, {$this->permTable} p";
|
$q_from = "{$this->subjTable} s, {$this->permTable} p";
|
||||||
$q_join = "LEFT JOIN {$this->smembTable} m ON p.subj=m.gid ";
|
$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_cond = "p.action in('_all', '$action') AND
|
||||||
$q_ordb = "ORDER BY S_lvl, action, p.type DESC"; // action ASC order is hack for lower priority of '_all'
|
(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;
|
$qc0 = $q_cond;
|
||||||
// test if object is class:
|
// 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){
|
if($iscls){
|
||||||
$q_from .= ", {$this->classTable} c";
|
$q_from .= ", {$this->classTable} c";
|
||||||
$q_cond .= " AND c.id=p.obj AND c.id=$oid";
|
$q_cond .= " AND c.id=p.obj AND c.id=$oid";
|
||||||
}else{
|
}else{
|
||||||
// object is normal node => path search => retrieve L/R values for 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");
|
$r1 = $this->dbc->getRow("SELECT lft, rgt, level
|
||||||
|
FROM {$this->treeTable} WHERE id=$oid");
|
||||||
if(is_null($r1))
|
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);
|
if(PEAR::isError($r1)) return($r1);
|
||||||
// fetch all path to oid + join with perms
|
// fetch all path to oid + join with perms
|
||||||
$q_flds .= ", t.name, ({$r1['level']}-t.level)as T_lvl";
|
$q_flds .= ", t.name, ({$r1['level']}-t.level)as T_lvl";
|
||||||
$q_from = "{$this->treeTable} t, ".$q_from;
|
$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_cond .= " AND t.id=p.obj AND t.lft<={$r1['lft']} AND
|
||||||
$q_ordb = "ORDER BY T_lvl, S_lvl, action, p.type DESC"; // action ASC order is hack for lower priority of '_all'
|
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";
|
$query="SELECT $q_flds FROM $q_from $q_join WHERE $q_cond $q_ordb";
|
||||||
$r2 = $this->dbc->getAll($query);
|
$r2 = $this->dbc->getAll($query);
|
||||||
|
@ -201,28 +250,29 @@ class Alib extends Subjects{
|
||||||
return (is_array($r2) && count($r2)>0 && $r2[0]['type']=='A');
|
return (is_array($r2) && count($r2)>0 && $r2[0]['type']=='A');
|
||||||
}
|
}
|
||||||
|
|
||||||
/* --- object tree --- */
|
/* ---------------------------------------------------------- object tree */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* removeObj
|
* Remove all permissions on object and then remove object itself
|
||||||
*
|
*
|
||||||
* @param id int
|
* @param id int
|
||||||
* @return void/error
|
* @return void/error
|
||||||
**/
|
*/
|
||||||
function removeObj($id)
|
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);
|
return parent::removeObj($id);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* --- users/groups --- */
|
/* --------------------------------------------------------- users/groups */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* removeSubj
|
* Remove all permissions of subject and then remove subject itself
|
||||||
*
|
*
|
||||||
* @param login string
|
* @param login string
|
||||||
* @return void/error
|
* @return void/error
|
||||||
**/
|
*/
|
||||||
function removeSubj($login)
|
function removeSubj($login)
|
||||||
{
|
{
|
||||||
$uid = $this->getSubjId($login); if(PEAR::isError($uid)) return $uid;
|
$uid = $this->getSubjId($login); if(PEAR::isError($uid)) return $uid;
|
||||||
|
@ -230,13 +280,13 @@ class Alib extends Subjects{
|
||||||
return parent::removeSubj($login, $uid);
|
return parent::removeSubj($login, $uid);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* --- sessions --- */
|
/* ------------------------------------------------------------- sessions */
|
||||||
/**
|
/**
|
||||||
* getSessLogin
|
* Get login from session id (token)
|
||||||
*
|
*
|
||||||
* @param sessid string
|
* @param sessid string
|
||||||
* @return string/error
|
* @return string/error
|
||||||
**/
|
*/
|
||||||
function getSessLogin($sessid)
|
function getSessLogin($sessid)
|
||||||
{
|
{
|
||||||
return $this->dbc->getOne("
|
return $this->dbc->getOne("
|
||||||
|
@ -244,24 +294,24 @@ class Alib extends Subjects{
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* getSessUserId
|
* Get user id from session id
|
||||||
*
|
*
|
||||||
* @param sessid string
|
* @param sessid string
|
||||||
* @return int/error
|
* @return int/error
|
||||||
**/
|
*/
|
||||||
function getSessUserId($sessid)
|
function getSessUserId($sessid)
|
||||||
{
|
{
|
||||||
return $this->dbc->getOne("
|
return $this->dbc->getOne("
|
||||||
SELECT userid FROM {$this->sessTable} WHERE sessid='$sessid'");
|
SELECT userid FROM {$this->sessTable} WHERE sessid='$sessid'");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* --- info methods: --- */
|
/* --------------------------------------------------------- info methods */
|
||||||
/**
|
/**
|
||||||
* getObjPerms
|
* Get all permissions on object
|
||||||
*
|
*
|
||||||
* @param id int
|
* @param id int
|
||||||
* @return array/null/err
|
* @return array/null/err
|
||||||
**/
|
*/
|
||||||
function getObjPerms($id)
|
function getObjPerms($id)
|
||||||
{
|
{
|
||||||
return $this->dbc->getAll("
|
return $this->dbc->getAll("
|
||||||
|
@ -270,62 +320,67 @@ class Alib extends Subjects{
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* getSubjPerms
|
* Get all permissions of subject
|
||||||
*
|
*
|
||||||
* @param sid int
|
* @param sid int
|
||||||
* @return array
|
* @return array
|
||||||
**/
|
*/
|
||||||
function getSubjPerms($sid)
|
function getSubjPerms($sid)
|
||||||
{
|
{
|
||||||
$a1 = $this->dbc->getAll("
|
$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");
|
WHERE t.id=p.obj AND p.subj=$sid");
|
||||||
if(PEAR::isError($a1)) return $a1;
|
if(PEAR::isError($a1)) return $a1;
|
||||||
$a2 = $this->dbc->getAll("
|
$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");
|
WHERE c.id=p.obj AND p.subj=$sid");
|
||||||
if(PEAR::isError($a2)) return $a2;
|
if(PEAR::isError($a2)) return $a2;
|
||||||
return array_merge($a1, $a2);
|
return array_merge($a1, $a2);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* --- info methods related to application structure: --- */
|
/* ------------------------ info methods related to application structure */
|
||||||
/* (this part should be added/rewritten to allow defining/modifying/using application structure) */
|
/* (this part should be added/rewritten to allow defining/modifying/using
|
||||||
/* (only very simple structure definition - in config - supported now) */
|
* application structure)
|
||||||
|
* (only very simple structure definition - in $config - supported now)
|
||||||
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* getAllActions
|
* Get all actions
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
**/
|
*/
|
||||||
function getAllActions()
|
function getAllActions()
|
||||||
{
|
{
|
||||||
return $this->config['allActions'];
|
return $this->config['allActions'];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* getAllowedActions
|
* Get all allowed actions on specified object type
|
||||||
*
|
*
|
||||||
* @param type string
|
* @param type string
|
||||||
* @return array
|
* @return array
|
||||||
**/
|
*/
|
||||||
function getAllowedActions($type)
|
function getAllowedActions($type)
|
||||||
{
|
{
|
||||||
return $this->config['allowedActions'][$type];
|
return $this->config['allowedActions'][$type];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* ========== test and debug methods: ========== */
|
/* =============================================== test and debug methods */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* dumpPerms
|
* Dump all permissions for debug
|
||||||
*
|
*
|
||||||
* @param indstr string // indentation string
|
* @param indstr string // indentation string
|
||||||
* @param ind string // aktual indentation
|
* @param ind string // aktual indentation
|
||||||
* @return string
|
* @return string
|
||||||
**/
|
*/
|
||||||
function dumpPerms($indstr=' ', $ind='')
|
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}")
|
$this->dbc->getAll("SELECT action, type FROM {$this->permTable}")
|
||||||
))."\n";
|
))."\n";
|
||||||
return $r;
|
return $r;
|
||||||
|
@ -335,17 +390,17 @@ class Alib extends Subjects{
|
||||||
* deleteData
|
* deleteData
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
**/
|
*/
|
||||||
function deleteData()
|
function deleteData()
|
||||||
{
|
{
|
||||||
$this->dbc->query("DELETE FROM {$this->permTable}");
|
$this->dbc->query("DELETE FROM {$this->permTable}");
|
||||||
parent::deleteData();
|
parent::deleteData();
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* testData
|
* Insert test permissions
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
**/
|
*/
|
||||||
function testData()
|
function testData()
|
||||||
{
|
{
|
||||||
parent::testData();
|
parent::testData();
|
||||||
|
@ -374,35 +429,46 @@ class Alib extends Subjects{
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* test
|
* Make basic test
|
||||||
*
|
*
|
||||||
* @return boolean/error
|
* @return boolean/error
|
||||||
**/
|
*/
|
||||||
function test()
|
function test()
|
||||||
{
|
{
|
||||||
if(PEAR::isError($p = parent::test())) return $p;
|
if(PEAR::isError($p = parent::test())) return $p;
|
||||||
$this->deleteData();
|
$this->deleteData();
|
||||||
$this->testData();
|
$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->test_dump = $this->dumpPerms().
|
||||||
($this->checkPerm($this->tdata['subjects'][1], 'edit', $this->tdata['tree'][7])? 'yes':'no').", ".
|
($this->checkPerm(
|
||||||
($this->checkPerm($this->tdata['subjects'][2], 'read', $this->tdata['tree'][5])? 'yes':'no')."\n"
|
$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'][1]);
|
||||||
$this->removePerm($this->tdata['perms'][3]);
|
$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->test_dump .= $this->dumpPerms();
|
||||||
$this->deleteData();
|
$this->deleteData();
|
||||||
if($this->test_dump==$this->test_correct){ $this->test_log.="alib: OK\n"; return TRUE; }
|
if($this->test_dump==$this->test_correct)
|
||||||
else return PEAR::raiseError('Alib::test', 1, PEAR_ERROR_DIE, '%s'.
|
{ $this->test_log.="alib: OK\n"; return TRUE;
|
||||||
"<pre>\ncorrect:\n{$this->test_correct}\ndump:\n{$this->test_dump}\n</pre>\n");
|
}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
|
* Create tables + initialize
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
**/
|
*/
|
||||||
function install()
|
function install()
|
||||||
{
|
{
|
||||||
parent::install();
|
parent::install();
|
||||||
|
@ -413,8 +479,10 @@ class Alib extends Subjects{
|
||||||
obj int,
|
obj int,
|
||||||
type char(1)
|
type char(1)
|
||||||
)");
|
)");
|
||||||
$this->dbc->query("CREATE UNIQUE INDEX {$this->permTable}_permid_idx on {$this->permTable} (permid)");
|
$this->dbc->query("CREATE UNIQUE INDEX {$this->permTable}_permid_idx
|
||||||
$this->dbc->query("CREATE INDEX {$this->permTable}_subj_obj_idx on {$this->permTable} (subj, obj)");
|
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->createSequence("{$this->permTable}_id_seq");
|
||||||
|
|
||||||
$this->dbc->query("CREATE TABLE {$this->sessTable} (
|
$this->dbc->query("CREATE TABLE {$this->sessTable} (
|
||||||
|
@ -423,16 +491,19 @@ class Alib extends Subjects{
|
||||||
login varchar(255),
|
login varchar(255),
|
||||||
ts timestamp
|
ts timestamp
|
||||||
)");
|
)");
|
||||||
$this->dbc->query("CREATE UNIQUE INDEX {$this->sessTable}_sessid_idx on {$this->sessTable} (sessid)");
|
$this->dbc->query("CREATE UNIQUE INDEX {$this->sessTable}_sessid_idx
|
||||||
$this->dbc->query("CREATE INDEX {$this->sessTable}_userid_idx on {$this->sessTable} (userid)");
|
ON {$this->sessTable} (sessid)");
|
||||||
$this->dbc->query("CREATE INDEX {$this->sessTable}_login_idx on {$this->sessTable} (login)");
|
$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
|
* Drop tables etc.
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
**/
|
*/
|
||||||
function uninstall()
|
function uninstall()
|
||||||
{
|
{
|
||||||
$this->dbc->query("DROP TABLE {$this->permTable}");
|
$this->dbc->query("DROP TABLE {$this->permTable}");
|
||||||
|
|
|
@ -1,23 +1,54 @@
|
||||||
<?php
|
<?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
|
* ObjClass class
|
||||||
*
|
*
|
||||||
* class for 'object classes' handling - i.e. groups of object in tree
|
* class for 'object classes' handling - i.e. groups of object in tree
|
||||||
* @parent Mtree
|
*
|
||||||
**/
|
* @author $Author: tomas $
|
||||||
require_once"mtree.php";
|
* @version $Revision: 1.2 $
|
||||||
|
* @see Mtree
|
||||||
|
* @see Subj
|
||||||
|
*/
|
||||||
class ObjClasses extends Mtree{
|
class ObjClasses extends Mtree{
|
||||||
var $classTable;
|
var $classTable;
|
||||||
var $cmembTable;
|
var $cmembTable;
|
||||||
/** ObjClasses - constructor
|
/**
|
||||||
|
* Constructor
|
||||||
*
|
*
|
||||||
* @param dbc object
|
* @param dbc object
|
||||||
* @param config array
|
* @param config array
|
||||||
* @return this
|
* @return this
|
||||||
**/
|
*/
|
||||||
function ObjClasses(&$dbc, $config)
|
function ObjClasses(&$dbc, $config)
|
||||||
{
|
{
|
||||||
parent::MTree(&$dbc, $config);
|
parent::MTree(&$dbc, $config);
|
||||||
|
@ -25,17 +56,18 @@ class ObjClasses extends Mtree{
|
||||||
$this->cmembTable = $config['tblNamePrefix'].'cmemb';
|
$this->cmembTable = $config['tblNamePrefix'].'cmemb';
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ========== public methods: ========== */
|
/* ======================================================= public methods */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* addClass
|
* Add new class of objects
|
||||||
*
|
*
|
||||||
* @param cname string
|
* @param cname string
|
||||||
* @return id/error
|
* @return id/error
|
||||||
**/
|
*/
|
||||||
function addClass($cname)
|
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("
|
$r = $this->dbc->query("
|
||||||
INSERT INTO {$this->classTable} (id, cname)
|
INSERT INTO {$this->classTable} (id, cname)
|
||||||
VALUES ($id, '$cname')
|
VALUES ($id, '$cname')
|
||||||
|
@ -45,146 +77,156 @@ class ObjClasses extends Mtree{
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* removeClass
|
* Remove class by name
|
||||||
*
|
*
|
||||||
* @param cname string
|
* @param cname string
|
||||||
* @return boolean/err
|
* @return boolean/err
|
||||||
**/
|
*/
|
||||||
function removeClass($cname)
|
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);
|
return $this->removeClassById($cid);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* removeClassById
|
* Remove class by id
|
||||||
*
|
*
|
||||||
* @param cid int
|
* @param cid int
|
||||||
* @return boolean/err
|
* @return boolean/err
|
||||||
**/
|
*/
|
||||||
function removeClassById($cid)
|
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;
|
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;
|
if(PEAR::isError($r)) return $r;
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* addObj2Class
|
* Add object to class
|
||||||
*
|
*
|
||||||
* @param cid int
|
* @param cid int
|
||||||
* @param oid int
|
* @param oid int
|
||||||
* @return boolean/err
|
* @return boolean/err
|
||||||
**/
|
*/
|
||||||
function addObj2Class($cid, $oid)
|
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;
|
if(PEAR::isError($r)) return $r;
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* removeObjFromClass
|
* Remove object from class
|
||||||
*
|
*
|
||||||
* @param oid int
|
* @param oid int
|
||||||
* @param cid int OPT // if not specified, remove obj from all classes
|
* @param cid int, optional, default: remove obj from all classes
|
||||||
* @return boolean/err
|
* @return boolean/err
|
||||||
**/
|
*/
|
||||||
function removeObjFromClass($oid, $cid=NULL)
|
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;
|
if(PEAR::isError($r)) return $r;
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* --- object tree --- */
|
/* ---------------------------------------------------------- object tree */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* removeObj
|
* Remove object from all classes and remove object itself
|
||||||
*
|
*
|
||||||
* @param id int
|
* @param id int
|
||||||
* @return boolean/err
|
* @return boolean/err
|
||||||
**/
|
*/
|
||||||
function removeObj($id)
|
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);
|
return parent::removeObj($id);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* --- info methods: --- */
|
/* --------------------------------------------------------- info methods */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* getClassId
|
* Get class id from name
|
||||||
*
|
*
|
||||||
* @param cname string
|
* @param cname string
|
||||||
* @return int/err
|
* @return int/err
|
||||||
**/
|
*/
|
||||||
function getClassId($cname)
|
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
|
* Get class name from id
|
||||||
*
|
*
|
||||||
* @param id int
|
* @param id int
|
||||||
* @return string/err
|
* @return string/err
|
||||||
**/
|
*/
|
||||||
function getClassName($id)
|
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
|
* Return true is object is class
|
||||||
*
|
*
|
||||||
* @param id int
|
* @param id int
|
||||||
* @return boolean/err
|
* @return boolean/err
|
||||||
**/
|
*/
|
||||||
function isClass($id)
|
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;
|
if(PEAR::isError($r)) return $r;
|
||||||
return ($r > 0);
|
return ($r > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* getClasses
|
* Return all classes
|
||||||
*
|
*
|
||||||
* @return array/err
|
* @return array/err
|
||||||
**/
|
*/
|
||||||
function getClasses()
|
function getClasses()
|
||||||
{
|
{
|
||||||
return $this->dbc->getAll("SELECT * FROM {$this->classTable}");
|
return $this->dbc->getAll("SELECT * FROM {$this->classTable}");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* listClass
|
* Return all objects in class
|
||||||
*
|
*
|
||||||
* @param id int
|
* @param id int
|
||||||
* @return array/err
|
* @return array/err
|
||||||
**/
|
*/
|
||||||
function listClass($id)
|
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");
|
WHERE cm.cid=$id AND cm.objid=t.id");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ========== test and debug methods: ========== */
|
/* =============================================== test and debug methods */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* dumpClasses
|
* Dump all classes fot debug
|
||||||
*
|
*
|
||||||
* @param id int
|
|
||||||
* @param indstr string // indentation string
|
* @param indstr string // indentation string
|
||||||
* @param ind string // aktual indentation
|
* @param ind string // aktual indentation
|
||||||
* @return string
|
* @return string
|
||||||
**/
|
*/
|
||||||
function dumpClasses($indstr=' ', $ind='')
|
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("
|
$this->dbc->getAll("
|
||||||
SELECT cname, count(cm.objid)as cnt FROM {$this->classTable} c
|
SELECT cname, count(cm.objid)as cnt FROM {$this->classTable} c
|
||||||
LEFT JOIN {$this->cmembTable} cm ON c.id=cm.cid
|
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()
|
function deleteData()
|
||||||
{
|
{
|
||||||
$this->dbc->query("DELETE FROM {$this->cmembTable}");
|
$this->dbc->query("DELETE FROM {$this->cmembTable}");
|
||||||
$this->dbc->query("DELETE FROM {$this->classTable}");
|
$this->dbc->query("DELETE FROM {$this->classTable}");
|
||||||
parent::deleteData();
|
parent::deleteData();
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* Insert test data
|
||||||
|
*
|
||||||
|
*/
|
||||||
function testData()
|
function testData()
|
||||||
{
|
{
|
||||||
parent::testData();
|
parent::testData();
|
||||||
|
@ -215,9 +261,9 @@ class ObjClasses extends Mtree{
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* test
|
* Make basic test
|
||||||
*
|
*
|
||||||
**/
|
*/
|
||||||
function test()
|
function test()
|
||||||
{
|
{
|
||||||
if(PEAR::isError($p = parent::test())) return $p;
|
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_correct = "Sections b (0), Class 2 (2)\n";
|
||||||
$this->test_dump = $this->dumpClasses();
|
$this->test_dump = $this->dumpClasses();
|
||||||
$this->removeClass('Sections b');
|
$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_correct .= "Class 2 (1)\n";
|
||||||
$this->test_dump .= $this->dumpClasses();
|
$this->test_dump .= $this->dumpClasses();
|
||||||
$this->deleteData();
|
$this->deleteData();
|
||||||
if($this->test_dump==$this->test_correct){ $this->test_log.="class: OK\n"; return TRUE; }
|
if($this->test_dump==$this->test_correct){
|
||||||
else return PEAR::raiseError('ObjClasses::test:', 1, PEAR_ERROR_DIE, '%s'.
|
$this->test_log.="class: OK\n"; return TRUE;
|
||||||
"<pre>\ncorrect:\n{$this->test_correct}\ndump:\n{$this->test_dump}\n</pre>\n");
|
}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()
|
function install()
|
||||||
{
|
{
|
||||||
parent::install();
|
parent::install();
|
||||||
|
@ -246,15 +296,22 @@ class ObjClasses extends Mtree{
|
||||||
id int not null,
|
id int not null,
|
||||||
cname varchar(20)
|
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}_id_idx
|
||||||
$this->dbc->query("CREATE UNIQUE INDEX {$this->classTable}_cname_idx on {$this->classTable} (cname)");
|
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} (
|
$this->dbc->query("CREATE TABLE {$this->cmembTable} (
|
||||||
objid int not null,
|
objid int not null,
|
||||||
cid 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()
|
function uninstall()
|
||||||
{
|
{
|
||||||
$this->dbc->query("DROP TABLE {$this->classTable}");
|
$this->dbc->query("DROP TABLE {$this->classTable}");
|
||||||
|
|
|
@ -1,5 +1,32 @@
|
||||||
<?php
|
<?php
|
||||||
// $Id: alibExCls.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/alibExCls.php,v $
|
||||||
|
|
||||||
|
------------------------------------------------------------------------------*/
|
||||||
require_once "alib_h.php";
|
require_once "alib_h.php";
|
||||||
require_once "alibExTestAuth.php";
|
require_once "alibExTestAuth.php";
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,32 @@
|
||||||
<?php
|
<?php
|
||||||
// $Id: alibExLogin.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/alibExLogin.php,v $
|
||||||
|
|
||||||
|
------------------------------------------------------------------------------*/
|
||||||
require_once "alib_h.php";
|
require_once "alib_h.php";
|
||||||
|
|
||||||
// prefill data structure for template
|
// prefill data structure for template
|
||||||
|
@ -100,7 +127,7 @@ Permission matrix for subject: <select name="subj">
|
||||||
|
|
||||||
<hr>
|
<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: ?>
|
<?php if($d['msg']){ //error message printing: ?>
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
|
|
|
@ -1,5 +1,32 @@
|
||||||
<?php
|
<?php
|
||||||
// $Id: alibExPList.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/alibExPList.php,v $
|
||||||
|
|
||||||
|
------------------------------------------------------------------------------*/
|
||||||
require_once "alib_h.php";
|
require_once "alib_h.php";
|
||||||
require_once "alibExTestAuth.php";
|
require_once "alibExTestAuth.php";
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,32 @@
|
||||||
<?php
|
<?php
|
||||||
// $Id: alibExPMatrix.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/alibExPMatrix.php,v $
|
||||||
|
|
||||||
|
------------------------------------------------------------------------------*/
|
||||||
require_once "alib_h.php";
|
require_once "alib_h.php";
|
||||||
|
|
||||||
$sid=$_GET['subj'];
|
$sid=$_GET['subj'];
|
||||||
|
|
|
@ -1,5 +1,32 @@
|
||||||
<?php
|
<?php
|
||||||
// $Id: alibExPerms.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/alibExPerms.php,v $
|
||||||
|
|
||||||
|
------------------------------------------------------------------------------*/
|
||||||
require_once "alib_h.php";
|
require_once "alib_h.php";
|
||||||
require_once "alibExTestAuth.php";
|
require_once "alibExTestAuth.php";
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,32 @@
|
||||||
<?php
|
<?php
|
||||||
// $Id: alibExSubj.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/alibExSubj.php,v $
|
||||||
|
|
||||||
|
------------------------------------------------------------------------------*/
|
||||||
require_once "alib_h.php";
|
require_once "alib_h.php";
|
||||||
require_once "alibExTestAuth.php";
|
require_once "alibExTestAuth.php";
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,32 @@
|
||||||
<?php
|
<?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']);
|
$login = $alib->getSessLogin($_REQUEST['alibsid']);
|
||||||
if(!isset($login)||$login==''){
|
if(!isset($login)||$login==''){
|
||||||
$_SESSION['alertMsg'] = "Login required";
|
$_SESSION['alertMsg'] = "Login required";
|
||||||
|
|
|
@ -1,5 +1,32 @@
|
||||||
<?php
|
<?php
|
||||||
// $Id: alibExTree.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/alibExTree.php,v $
|
||||||
|
|
||||||
|
------------------------------------------------------------------------------*/
|
||||||
require_once "alib_h.php";
|
require_once "alib_h.php";
|
||||||
require_once "alibExTestAuth.php";
|
require_once "alibExTestAuth.php";
|
||||||
|
|
||||||
|
@ -17,7 +44,7 @@ $d = array(
|
||||||
'id' => $id,
|
'id' => $id,
|
||||||
'loggedAs' => $login
|
'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:
|
// template follows:
|
||||||
|
|
|
@ -1,8 +1,35 @@
|
||||||
<?php
|
<?php
|
||||||
// $Id: alibHttp.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/alibHttp.php,v $
|
||||||
|
|
||||||
|
------------------------------------------------------------------------------*/
|
||||||
require_once "alib_h.php";
|
require_once "alib_h.php";
|
||||||
|
|
||||||
#header("Content-type: text/plain"); echo"GET:\n"; print_r($_GET); echo"POST:\n"; print_r($_POST); exit;
|
#echo"<pre>\nGET:\n"; print_r($_GET); echo"POST:\n"; print_r($_POST); exit;
|
||||||
|
|
||||||
function getPGval($vn, $dfl='')
|
function getPGval($vn, $dfl='')
|
||||||
{
|
{
|
||||||
|
@ -20,11 +47,15 @@ switch($act)
|
||||||
if($sessid = $alib->login($_POST['login'], $_POST['pass'])){
|
if($sessid = $alib->login($_POST['login'], $_POST['pass'])){
|
||||||
setcookie('alibsid', $sessid);
|
setcookie('alibsid', $sessid);
|
||||||
$redirUrl="alibExTree.php";
|
$redirUrl="alibExTree.php";
|
||||||
}else{ $redirUrl="alibExLogin.php"; $_SESSION['alertMsg']='Login failed.'; }
|
}else{
|
||||||
|
$redirUrl="alibExLogin.php"; $_SESSION['alertMsg']='Login failed.';
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case"logout";
|
case"logout";
|
||||||
$r = $alib->logout($_REQUEST['alibsid']);
|
$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', '');
|
setcookie('alibsid', '');
|
||||||
$redirUrl="alibExLogin.php";
|
$redirUrl="alibExLogin.php";
|
||||||
break;
|
break;
|
||||||
|
@ -33,8 +64,17 @@ switch($act)
|
||||||
&& $_POST['type']!=''
|
&& $_POST['type']!=''
|
||||||
&& $_POST['name']!=''
|
&& $_POST['name']!=''
|
||||||
){
|
){
|
||||||
$oid = $alib->addObj($_POST['name'], $_POST['type'], $_POST['id'], $_POST['position']);
|
$position = ($_POST['position']=='I' ? null : $_POST['position']);
|
||||||
$alib->addPerm($userid, '_all', $oid);
|
$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.';
|
}else $_SESSION['alertMsg']='Access denied.';
|
||||||
break;
|
break;
|
||||||
case"deleteNode";
|
case"deleteNode";
|
||||||
|
@ -45,10 +85,14 @@ switch($act)
|
||||||
case"addPerm";
|
case"addPerm";
|
||||||
$a = $alib->isClass($_POST['id']) ? 'classes':'editPerms';
|
$a = $alib->isClass($_POST['id']) ? 'classes':'editPerms';
|
||||||
$id = $alib->isClass($_POST['id']) ? '':$_POST['id'];
|
$id = $alib->isClass($_POST['id']) ? '':$_POST['id'];
|
||||||
if($alib->checkPerm($userid, $a, $id))
|
if($alib->checkPerm($userid, $a, $id)){
|
||||||
$alib->addPerm($_POST['subj'], $_POST['permAction'], $_POST['id'], $_POST['allowDeny']);
|
$alib->addPerm(
|
||||||
else $_SESSION['alertMsg']='Access denied.';
|
$_POST['subj'], $_POST['permAction'],
|
||||||
$redirUrl="alibExPerms.php".(($reid=getPGval('reid', '')) ? "?id=$reid":"");
|
$_POST['id'], $_POST['allowDeny']
|
||||||
|
);
|
||||||
|
}else $_SESSION['alertMsg']='Access denied.';
|
||||||
|
$redirUrl = "alibExPerms.php".
|
||||||
|
(($reid=getPGval('reid', '')) ? "?id=$reid":"");
|
||||||
break;
|
break;
|
||||||
case"removePerm";
|
case"removePerm";
|
||||||
$a = $alib->isClass($_REQUEST['oid']) ? 'classes':'editPerms';
|
$a = $alib->isClass($_REQUEST['oid']) ? 'classes':'editPerms';
|
||||||
|
@ -56,10 +100,14 @@ switch($act)
|
||||||
if($alib->checkPerm($userid, $a, $oid))
|
if($alib->checkPerm($userid, $a, $oid))
|
||||||
$alib->removePerm($_GET['permid']);
|
$alib->removePerm($_GET['permid']);
|
||||||
else $_SESSION['alertMsg']='Access denied.';
|
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;
|
break;
|
||||||
case"checkPerm";
|
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: ").
|
$_SESSION['alertMsg'] = ($res ? "permitted: ":"DENIED: ").
|
||||||
" {$_POST['permAction']} for ".$alib->getSubjName($_POST['subj']).
|
" {$_POST['permAction']} for ".$alib->getSubjName($_POST['subj']).
|
||||||
" on ".$alib->getObjName($_POST['obj']);
|
" on ".$alib->getObjName($_POST['obj']);
|
||||||
|
@ -94,13 +142,15 @@ switch($act)
|
||||||
if($alib->checkPerm($userid, 'subjects'))
|
if($alib->checkPerm($userid, 'subjects'))
|
||||||
$alib->addSubj2Gr($_POST['login'], $_POST['gname']);
|
$alib->addSubj2Gr($_POST['login'], $_POST['gname']);
|
||||||
else $_SESSION['alertMsg']='Access denied.';
|
else $_SESSION['alertMsg']='Access denied.';
|
||||||
$redirUrl="alibExSubj.php".(($id=getPGval('reid', '')) ? "?id=$reid":"");
|
$redirUrl = "alibExSubj.php".
|
||||||
|
(($id=getPGval('reid', '')) ? "?id=$reid":"");
|
||||||
break;
|
break;
|
||||||
case"removeSubjFromGr";
|
case"removeSubjFromGr";
|
||||||
if($alib->checkPerm($userid, 'subjects'))
|
if($alib->checkPerm($userid, 'subjects'))
|
||||||
$alib->removeSubjFromGr($_GET['login'], $_GET['gname']);
|
$alib->removeSubjFromGr($_GET['login'], $_GET['gname']);
|
||||||
else $_SESSION['alertMsg']='Access denied.';
|
else $_SESSION['alertMsg']='Access denied.';
|
||||||
$redirUrl="alibExSubj.php".(($id=getPGval('reid', '')) ? "?id=$reid":"");
|
$redirUrl = "alibExSubj.php".
|
||||||
|
(($id=getPGval('reid', '')) ? "?id=$reid":"");
|
||||||
break;
|
break;
|
||||||
case"addObj2Class";
|
case"addObj2Class";
|
||||||
if($alib->checkPerm($userid, 'classes'))
|
if($alib->checkPerm($userid, 'classes'))
|
||||||
|
|
|
@ -1,12 +1,40 @@
|
||||||
<?php
|
<?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(
|
$config = array(
|
||||||
'dsn' => array( // data source definition
|
'dsn' => array( // data source definition
|
||||||
'username' => 'tomash',
|
'username' => 'test',
|
||||||
'password' => '',
|
'password' => 'test',
|
||||||
'hostspec' => 'localhost',
|
'hostspec' => 'localhost',
|
||||||
'phptype' => 'pgsql',
|
'phptype' => 'pgsql',
|
||||||
'database' => 'mdlf'
|
'database' => 'LiveSupport-test'
|
||||||
),
|
),
|
||||||
'tblNamePrefix' => 'al_',
|
'tblNamePrefix' => 'al_',
|
||||||
# 'tblNamePrefix' => 'gb_',
|
# 'tblNamePrefix' => 'gb_',
|
||||||
|
@ -18,15 +46,23 @@ $config = array(
|
||||||
'Section' => array('Title', 'Image', 'Par')
|
'Section' => array('Title', 'Image', 'Par')
|
||||||
),
|
),
|
||||||
'allowedActions'=> array(
|
'allowedActions'=> array(
|
||||||
'RootNode' => array('addChilds', 'editPerms', 'read', 'edit', 'delete', 'classes', 'subjects'),
|
'RootNode' => array(
|
||||||
'Publication' => array('addChilds', 'editPerms', 'read', 'edit', 'delete'),
|
'addChilds', 'editPerms', 'read', 'edit', 'delete',
|
||||||
'Issue' => array('addChilds', 'editPerms', 'read', 'edit', 'delete'),
|
'classes', 'subjects'),
|
||||||
'Section' => array('addChilds', 'editPerms', 'read', 'edit', 'delete'),
|
'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'),
|
'Title' => array('editPerms', 'read', 'edit', 'delete'),
|
||||||
'Image' => array('editPerms', 'read', 'edit', 'delete'),
|
'Image' => array('editPerms', 'read', 'edit', 'delete'),
|
||||||
'Par' => 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')
|
||||||
);
|
);
|
||||||
?>
|
?>
|
|
@ -1,7 +1,38 @@
|
||||||
<?php
|
<?php
|
||||||
// $Id: index.php,v 1.1 2004/07/23 00:22:13 tomas Exp $
|
/*------------------------------------------------------------------------------
|
||||||
|
|
||||||
header ("location: install.php");
|
Copyright (c) 2004 Media Development Loan Fund
|
||||||
die;
|
|
||||||
|
|
||||||
|
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>
|
||||||
|
|
|
@ -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>
|
|
||||||
|
|
73
livesupport/modules/alib/var/install/install.php
Normal file
73
livesupport/modules/alib/var/install/install.php
Normal 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();
|
||||||
|
?>
|
61
livesupport/modules/alib/var/install/uninstall.php
Normal file
61
livesupport/modules/alib/var/install/uninstall.php
Normal 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();
|
||||||
|
?>
|
|
@ -1,13 +1,42 @@
|
||||||
<?php
|
<?php
|
||||||
// $Id: mtree.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/Attic/mtree.php,v $
|
||||||
|
|
||||||
|
------------------------------------------------------------------------------*/
|
||||||
|
define('ALIBERR_MTREE', 10);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Mtree class
|
* Mtree class
|
||||||
*
|
*
|
||||||
* class for tree hierarchy stored in db
|
* class for tree hierarchy stored in db
|
||||||
*
|
*
|
||||||
* example config: example/conf.php
|
* example config: example/conf.php<br>
|
||||||
* example minimal config:
|
* example minimal config:
|
||||||
|
* <pre><code>
|
||||||
* $config = array(
|
* $config = array(
|
||||||
* 'dsn' => array( // data source definition
|
* 'dsn' => array( // data source definition
|
||||||
* 'username' => DBUSER,
|
* 'username' => DBUSER,
|
||||||
|
@ -19,21 +48,22 @@
|
||||||
* 'tblNamePrefix' => 'al_',
|
* 'tblNamePrefix' => 'al_',
|
||||||
* 'RootNode' =>'RootNode',
|
* 'RootNode' =>'RootNode',
|
||||||
* );
|
* );
|
||||||
* (mysql phptype is tested too, but psql is recommended)
|
* </code></pre>
|
||||||
**/
|
* @author $Author: tomas $
|
||||||
define('ALIBERR_MTREE', 10);
|
* @version $Revision: 1.2 $
|
||||||
|
* @see ObjClasses
|
||||||
|
*/
|
||||||
class Mtree{
|
class Mtree{
|
||||||
var $dbc;
|
var $dbc;
|
||||||
var $config;
|
var $config;
|
||||||
var $treeTable;
|
var $treeTable;
|
||||||
var $rootNodeName;
|
var $rootNodeName;
|
||||||
/** Mtree - constructor
|
/** Constructor
|
||||||
*
|
*
|
||||||
* @param dbc object
|
* @param dbc object
|
||||||
* @param config array
|
* @param config array
|
||||||
* @return this
|
* @return this
|
||||||
**/
|
*/
|
||||||
function Mtree(&$dbc, $config)
|
function Mtree(&$dbc, $config)
|
||||||
{
|
{
|
||||||
$this->dbc =& $dbc;
|
$this->dbc =& $dbc;
|
||||||
|
@ -42,23 +72,26 @@ class Mtree{
|
||||||
$this->rootNodeName = $config['RootNode'];
|
$this->rootNodeName = $config['RootNode'];
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ========== public methods: ========== */
|
/* ======================================================= public methods */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* addObj
|
* Add new object of specified type to the tree under specified parent
|
||||||
|
* node as last child or after specified sibling
|
||||||
*
|
*
|
||||||
* @param name string
|
* @param name string
|
||||||
* @param type string
|
* @param type string
|
||||||
* @param parid int OPT // parent id
|
* @param parid int, optional, parent id
|
||||||
* @param aftid int OPT // after id
|
* @param aftid int, optional, after id
|
||||||
* @param param string OPT
|
* @return int/err - new id of inserted object or PEAR::error
|
||||||
* @return int/err // new id of inserted object
|
*/
|
||||||
**/
|
function addObj($name, $type, $parid=1, $aftid=NULL)
|
||||||
function addObj($name, $type, $parid=1, $aftid=NULL, $param='')
|
|
||||||
{
|
{
|
||||||
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");
|
$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:
|
// position resolving:
|
||||||
if(is_null($aftid)){ // add object as last child
|
if(is_null($aftid)){ // add object as last child
|
||||||
$after = $this->dbc->getOne("
|
$after = $this->dbc->getOne("
|
||||||
|
@ -78,20 +111,28 @@ class Mtree{
|
||||||
if(PEAR::isError($after)) return $this->_dbRollback($after);
|
if(PEAR::isError($after)) return $this->_dbRollback($after);
|
||||||
$after = intval($after);
|
$after = intval($after);
|
||||||
// tree level resolving:
|
// tree level resolving:
|
||||||
$level = $this->dbc->getOne("SELECT level FROM {$this->treeTable} WHERE id='$parid'");
|
$level = $this->dbc->getOne("SELECT level FROM {$this->treeTable}
|
||||||
if(is_null($level)) return $this->_dbRollback('addObj: parent does not exist');
|
WHERE id='$parid'");
|
||||||
|
if(is_null($level))
|
||||||
|
return $this->_dbRollback('addObj: parent does not exist');
|
||||||
if(PEAR::isError($level)) return $this->_dbRollback($level);
|
if(PEAR::isError($level)) return $this->_dbRollback($level);
|
||||||
$id = $this->dbc->nextId("{$this->treeTable}_id_seq");
|
$id = $this->dbc->nextId("{$this->treeTable}_id_seq");
|
||||||
if(PEAR::isError($id)) return $this->_dbRollback($id);
|
if(PEAR::isError($id)) return $this->_dbRollback($id);
|
||||||
// creating space in rgt/lft sequencies:
|
// 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);
|
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);
|
if(PEAR::isError($r)) return $this->_dbRollback($r);
|
||||||
// inserting object:
|
// inserting object:
|
||||||
$r = $this->dbc->query("
|
$r = $this->dbc->query("
|
||||||
INSERT INTO {$this->treeTable} (id, name, type, parid, level, lft, rgt, param)
|
INSERT INTO {$this->treeTable}
|
||||||
VALUES ('$id', '$name', '$type', $parid, ".($level+1).", ".($after+1).", ".($after+2).", '$param')
|
(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);
|
if(PEAR::isError($r)) return $this->_dbRollback($r);
|
||||||
$r = $this->dbc->query("COMMIT");
|
$r = $this->dbc->query("COMMIT");
|
||||||
|
@ -100,41 +141,45 @@ class Mtree{
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* copyObj
|
* Create copy of specified object and insert copy to new position
|
||||||
*
|
*
|
||||||
* @param id int
|
* @param id int, source object id
|
||||||
* @param newParid int
|
* @param newParid int, destination parent id
|
||||||
* @param after int OPT
|
* @param after int, optional, destinantion after id
|
||||||
* @return int/err
|
* @return int/err - new id of inserted object or PEAR::error
|
||||||
**/
|
*/
|
||||||
function copyObj($id, $newParid, $after=NULL)
|
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;
|
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;
|
return $nid;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* renameObj
|
* Rename of specified object
|
||||||
*
|
*
|
||||||
* @param id int
|
* @param id int, object id to rename
|
||||||
* @param newName string
|
* @param newName string, new name
|
||||||
* @return int/err
|
* @return boolean/err - True or PEAR::error
|
||||||
**/
|
*/
|
||||||
function renameObj($id, $newName)
|
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;
|
if(PEAR::isError($r)) return $r;
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* removeObj
|
* Remove of specified object
|
||||||
*
|
*
|
||||||
* @param id int
|
* @param id int, object id to remove
|
||||||
* @return boolean/err
|
* @return boolean/err - TRUE or PEAR::error
|
||||||
**/
|
*/
|
||||||
function removeObj($id)
|
function removeObj($id)
|
||||||
{
|
{
|
||||||
$dirarr = $this->getDir($id); if(PEAR::isError($dirarr)) return $dirarr;
|
$dirarr = $this->getDir($id); if(PEAR::isError($dirarr)) return $dirarr;
|
||||||
|
@ -143,86 +188,95 @@ class Mtree{
|
||||||
$this->removeObj($snod['id']);
|
$this->removeObj($snod['id']);
|
||||||
}
|
}
|
||||||
$this->dbc->query("BEGIN");
|
$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}");
|
||||||
$rgt = $this->dbc->getOne("SELECT rgt FROM {$this->treeTable} WHERE id='$id'");
|
if(PEAR::isError($r)) return $r;
|
||||||
if(is_null($rgt)) return $this->_dbRollback('removeObj: object not exists');
|
$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:
|
// deleting object:
|
||||||
$r = $this->dbc->query("DELETE FROM {$this->treeTable} WHERE id='$id'");
|
$r = $this->dbc->query("DELETE FROM {$this->treeTable} WHERE id='$id'");
|
||||||
if(PEAR::isError($r)) return $this->_dbRollback($r);
|
if(PEAR::isError($r)) return $this->_dbRollback($r);
|
||||||
// closing the space in rgt/lft sequencies:
|
// 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);
|
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);
|
if(PEAR::isError($r)) return $this->_dbRollback($r);
|
||||||
$r = $this->dbc->query("COMMIT");
|
$r = $this->dbc->query("COMMIT");
|
||||||
if(PEAR::isError($r)) return $this->_dbRollback($r);
|
if(PEAR::isError($r)) return $this->_dbRollback($r);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* --- info methods: --- */
|
/* --------------------------------------------------------- info methods */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* getObjId - search dir for object by name
|
* Search for child id by name
|
||||||
*
|
*
|
||||||
* @param name string
|
* @param name string, searched name
|
||||||
* @param parId int OPT
|
* @param parId int, optional, parent id (default is root node)
|
||||||
* @return int/err
|
* @return int/null/err - child id (if found) or null or PEAR::error
|
||||||
**/
|
*/
|
||||||
function getObjId($name, $parId=NULL)
|
function getObjId($name, $parId=NULL)
|
||||||
{
|
{
|
||||||
if($name=='' && is_null($parId)) $name = $this->rootNodeName;
|
if($name=='' && is_null($parId)) $name = $this->rootNodeName;
|
||||||
return $this->dbc->getOne(
|
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)
|
* Get one value for object (default: get name) by id
|
||||||
*
|
*
|
||||||
* @param oid int
|
* @param oid int
|
||||||
* @param fld string OPT
|
* @param fld string, optional, requested field (default: name)
|
||||||
* @return string/err
|
* @return string/err
|
||||||
**/
|
*/
|
||||||
function getObjName($oid, $fld='name')
|
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
|
* Get object type by id
|
||||||
*
|
*
|
||||||
* @param oid int
|
* @param oid int
|
||||||
* @return string/err
|
* @return string/err
|
||||||
**/
|
*/
|
||||||
function getObjType($oid)
|
function getObjType($oid)
|
||||||
{
|
{
|
||||||
return $this->getObjName($oid, 'type');
|
return $this->getObjName($oid, 'type');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* getParent
|
* Get parent id
|
||||||
*
|
*
|
||||||
* @param id int
|
* @param oid int
|
||||||
* @return string/err
|
* @return string/err
|
||||||
**/
|
*/
|
||||||
function getParent($oid)
|
function getParent($oid)
|
||||||
{
|
{
|
||||||
return $this->getObjName($oid, 'parid');
|
return $this->getObjName($oid, 'parid');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* getPath - get array of nodes in object's path
|
* Get array of nodes in object's path from root node
|
||||||
*
|
*
|
||||||
* @param id int
|
* @param id int
|
||||||
* @param flds string OPT
|
* @param flds string, optional
|
||||||
* @return array/err
|
* @return array/err
|
||||||
**/
|
*/
|
||||||
function getPath($id, $flds='id')
|
function getPath($id, $flds='id')
|
||||||
{
|
{
|
||||||
$this->dbc->query("BEGIN");
|
$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("
|
$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
|
ORDER by lft
|
||||||
");
|
");
|
||||||
$this->dbc->query("COMMIT");
|
$this->dbc->query("COMMIT");
|
||||||
|
@ -230,37 +284,41 @@ class Mtree{
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* getDir - get array of childnodes
|
* Get array of childnodes
|
||||||
*
|
*
|
||||||
* @param id int
|
* @param id int
|
||||||
* @param flds string OPT
|
* @param flds string, optional, comma separated list of requested fields
|
||||||
* @param order string OPT
|
* @param order string, optional, fieldname for order by clause
|
||||||
* @return array/err
|
* @return array/err
|
||||||
**/
|
*/
|
||||||
function getDir($id, $flds='id', $order='lft')
|
function getDir($id, $flds='id', $order='lft')
|
||||||
{
|
{
|
||||||
return $this->dbc->getAll("
|
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
|
* Get subtree of specified node
|
||||||
*
|
*
|
||||||
* @param id int OPT
|
* @param id int, optional, default: root node
|
||||||
* @param withRoot boolean OPT
|
* @param withRoot boolean, optional, include/exclude specified node
|
||||||
* @return array/err
|
* @return array/err
|
||||||
**/
|
*/
|
||||||
function getSubTree($id=NULL, $withRoot=FALSE)
|
function getSubTree($id=NULL, $withRoot=FALSE)
|
||||||
{
|
{
|
||||||
if(is_null($id)) $id = $this->getRootNode();
|
if(is_null($id)) $id = $this->getRootNode();
|
||||||
$r = array();
|
$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;
|
if(PEAR::isError($re)) return $re;
|
||||||
$dirarr = $this->getDir($id); if(PEAR::isError($dirarr)) return $dirarr;
|
$dirarr = $this->getDir($id); if(PEAR::isError($dirarr)) return $dirarr;
|
||||||
foreach($dirarr as $k=>$snod)
|
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;
|
if(PEAR::isError($re)) return $re;
|
||||||
$r = array_merge($r, $this->getSubTree($snod['id']));
|
$r = array_merge($r, $this->getSubTree($snod['id']));
|
||||||
}
|
}
|
||||||
|
@ -268,77 +326,93 @@ class Mtree{
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* getRootNode - get id of root node
|
* Get id of root node
|
||||||
*
|
*
|
||||||
* @return int/err
|
* @return int/err
|
||||||
**/
|
*/
|
||||||
function getRootNode()
|
function getRootNode()
|
||||||
{
|
{
|
||||||
return $this->getObjId($this->rootNodeName);
|
return $this->getObjId($this->rootNodeName);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* getAllObjects
|
* Get all objects in the tree
|
||||||
*
|
*
|
||||||
* @return array/err
|
* @return array/err
|
||||||
**/
|
*/
|
||||||
function getAllObjects()
|
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: --- */
|
/* ------------------------ info methods related to application structure */
|
||||||
/* (this part should be added/rewritten to allow defining/modifying/using application structure) */
|
/* (this part should be added/rewritten to allow defining/modifying/using
|
||||||
/* (only very simple structure definition - in config - supported now) */
|
* application structure)
|
||||||
|
* (only very simple structure definition - in $config - supported now)
|
||||||
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* getAllowedChildTypes
|
* Get child types allowed by application definition
|
||||||
*
|
*
|
||||||
* @param type string
|
* @param type string
|
||||||
* @return array
|
* @return array
|
||||||
**/
|
*/
|
||||||
function getAllowedChildTypes($type)
|
function getAllowedChildTypes($type)
|
||||||
{
|
{
|
||||||
return $this->config['objtypes'][$type];
|
return $this->config['objtypes'][$type];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* ========== "private" methods: ========== */
|
/* ==================================================== "private" methods */
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* _dbRollback
|
* Do SQL rollback and return PEAR::error
|
||||||
*
|
*
|
||||||
* @param r object/string
|
* @param r object/string
|
||||||
* @return err
|
* @return err
|
||||||
**/
|
*/
|
||||||
function _dbRollback($r)
|
function _dbRollback($r)
|
||||||
{
|
{
|
||||||
$this->dbc->query("ROLLBACK");
|
$this->dbc->query("ROLLBACK");
|
||||||
if(PEAR::isError($r)) return $r;
|
if(PEAR::isError($r)) return $r;
|
||||||
elseif(is_string($r)) return PEAR::raiseError("ERROR: ".get_class($this).": $r", ALIBERR_MTREE, PEAR_ERROR_RETURN);
|
elseif(is_string($r)) return PEAR::raiseError(
|
||||||
else return PEAR::raiseError("ERROR: ".get_class($this).": unknown error", ALIBERR_MTREE, PEAR_ERROR_RETURN);
|
"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
|
* Move subtree to another node without removing/adding
|
||||||
|
* Little bit complicated - sorry - it probably should be simlified ... ;)
|
||||||
*
|
*
|
||||||
* @param id int
|
* @param id int
|
||||||
* @param newParid int
|
* @param newParid int
|
||||||
* @param after int
|
* @param after int
|
||||||
* @return boolean/err
|
* @return boolean/err
|
||||||
**/
|
*/
|
||||||
function _relocateSubtree($id, $newParid, $after=NULL)
|
function _relocateSubtree($id, $newParid, $after=NULL)
|
||||||
{
|
{
|
||||||
$this->dbc->query("BEGIN");
|
$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:
|
// obtain values for source node:
|
||||||
$a1 = $this->dbc->getRow("SELECT lft, rgt, level FROM {$this->treeTable} WHERE id='$id'");
|
$a1 = $this->dbc->getRow("SELECT lft, rgt, level FROM {$this->treeTable}
|
||||||
if(is_null($a1)) return $this->_dbRollback('_relocateSubtree: object not exists');
|
WHERE id='$id'");
|
||||||
|
if(is_null($a1))
|
||||||
|
return $this->_dbRollback('_relocateSubtree: object not exists');
|
||||||
extract($a1);
|
extract($a1);
|
||||||
// values for destination node:
|
// values for destination node:
|
||||||
$a2 = $this->dbc->getRow("SELECT rgt, level FROM {$this->treeTable} WHERE id='$newParid'");
|
$a2 = $this->dbc->getRow("SELECT rgt, level FROM {$this->treeTable}
|
||||||
if(is_null($a2)) return $this->_dbRollback('_relocateSubtree: new parent not exists');
|
WHERE id='$newParid'");
|
||||||
|
if(is_null($a2))return $this->_dbRollback(
|
||||||
|
'_relocateSubtree: new parent not exists'
|
||||||
|
);
|
||||||
$nprgt = $a2['rgt']; $newLevel = $a2['level'];
|
$nprgt = $a2['rgt']; $newLevel = $a2['level'];
|
||||||
// calculate differencies:
|
// calculate differencies:
|
||||||
if(is_null($after)) $after = $nprgt-1;
|
if(is_null($after)) $after = $nprgt-1;
|
||||||
|
@ -346,35 +420,44 @@ class Mtree{
|
||||||
$dif2 = $after-$lft+1;
|
$dif2 = $after-$lft+1;
|
||||||
$dif3 = $newLevel-$level+1;
|
$dif3 = $newLevel-$level+1;
|
||||||
// relocate the object"
|
// 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(PEAR::isError($r)) return $this->_dbRollback($r);
|
||||||
if($after>$rgt){
|
if($after>$rgt){
|
||||||
// relocate subtree to the right:
|
// 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);
|
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);
|
if(PEAR::isError($r)) return $this->_dbRollback($r);
|
||||||
$r = $this->dbc->query("UPDATE {$this->treeTable}
|
$r = $this->dbc->query("UPDATE {$this->treeTable}
|
||||||
SET lft=lft+$dif2, rgt=rgt+$dif2, level=level+$dif3
|
SET lft=lft+$dif2, rgt=rgt+$dif2, level=level+$dif3
|
||||||
WHERE lft>=$lft AND rgt <=$rgt");
|
WHERE lft>=$lft AND rgt <=$rgt");
|
||||||
if(PEAR::isError($r)) return $this->_dbRollback($r);
|
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);
|
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);
|
if(PEAR::isError($r)) return $this->_dbRollback($r);
|
||||||
}else{
|
}else{
|
||||||
// relocate subtree to the left:
|
// 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);
|
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);
|
if(PEAR::isError($r)) return $this->_dbRollback($r);
|
||||||
$r = $this->dbc->query("UPDATE {$this->treeTable}
|
$r = $this->dbc->query("UPDATE {$this->treeTable}
|
||||||
SET lft=lft+$dif2-$dif1, rgt=rgt+$dif2-$dif1, level=level+$dif3
|
SET lft=lft+$dif2-$dif1, rgt=rgt+$dif2-$dif1, level=level+$dif3
|
||||||
WHERE lft>=$lft+$dif1 AND rgt <=$rgt+$dif1");
|
WHERE lft>=$lft+$dif1 AND rgt <=$rgt+$dif1");
|
||||||
if(PEAR::isError($r)) return $this->_dbRollback($r);
|
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);
|
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);
|
if(PEAR::isError($r)) return $this->_dbRollback($r);
|
||||||
}
|
}
|
||||||
$r = $this->dbc->query("COMMIT");
|
$r = $this->dbc->query("COMMIT");
|
||||||
|
@ -383,13 +466,13 @@ class Mtree{
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* _copySubtree - recursive copyObj
|
* Recursive copyObj - copy of whole subtree
|
||||||
*
|
*
|
||||||
* @param id int
|
* @param id int
|
||||||
* @param newParid int
|
* @param newParid int
|
||||||
* @param after int
|
* @param after int
|
||||||
* @return array
|
* @return array
|
||||||
**/
|
*/
|
||||||
function _copySubtree($id, $newParid, $after=NULL)
|
function _copySubtree($id, $newParid, $after=NULL)
|
||||||
{
|
{
|
||||||
$nid = $this->copyObj($id, $newParid, $after);
|
$nid = $this->copyObj($id, $newParid, $after);
|
||||||
|
@ -400,43 +483,46 @@ class Mtree{
|
||||||
$r = $this->_copySubtree($snod['id'], $nid);
|
$r = $this->_copySubtree($snod['id'], $nid);
|
||||||
if(PEAR::isError($r)) return $r;
|
if(PEAR::isError($r)) return $r;
|
||||||
}
|
}
|
||||||
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ========== test and debug methods: ========== */
|
/* =============================================== test and debug methods */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* dumpTree
|
* Human readable dump of subtree - for debug
|
||||||
*
|
*
|
||||||
* @param id int
|
* @param id int
|
||||||
* @param indstr string // indentation string
|
* @param indstr string, indentation string
|
||||||
* @param ind string // aktual indentation
|
* @param ind string, aktual indentation
|
||||||
* @return string
|
* @return string
|
||||||
**/
|
*/
|
||||||
function dumpTree($id=NULL, $indstr=' ', $ind='', $format='{name}', $withRoot=TRUE)
|
function dumpTree($id=NULL, $indstr=' ', $ind='',
|
||||||
|
$format='{name}', $withRoot=TRUE)
|
||||||
{
|
{
|
||||||
$r='';
|
$r='';
|
||||||
foreach($this->getSubTree($id, $withRoot) as $o)
|
foreach($this->getSubTree($id, $withRoot) as $o)
|
||||||
$r .= str_repeat($indstr, intval($o['level'])).
|
$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";
|
"\n";
|
||||||
return $r;
|
return $r;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* deleteData
|
* Delete all nodes except the root
|
||||||
*
|
*
|
||||||
**/
|
*/
|
||||||
function deleteData()
|
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
|
* Insert test data to the tree
|
||||||
*
|
*
|
||||||
* @param id int OPT
|
|
||||||
* @return array
|
* @return array
|
||||||
**/
|
*/
|
||||||
function testData()
|
function testData()
|
||||||
{
|
{
|
||||||
$o[] = $rootId = $this->getRootNode();
|
$o[] = $rootId = $this->getRootNode();
|
||||||
|
@ -454,29 +540,35 @@ class Mtree{
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* test
|
* Make basic test
|
||||||
*
|
*
|
||||||
**/
|
*/
|
||||||
function test()
|
function test()
|
||||||
{
|
{
|
||||||
$this->deleteData();
|
$this->deleteData();
|
||||||
$this->testData();
|
$this->testData();
|
||||||
$rootId = $this->getRootNode();
|
$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->test_dump = $this->dumpTree();
|
||||||
$this->removeObj($this->tdata['tree'][1]);
|
$this->removeObj($this->tdata['tree'][1]);
|
||||||
$this->removeObj($this->tdata['tree'][2]);
|
$this->removeObj($this->tdata['tree'][2]);
|
||||||
$this->test_dump .= $this->dumpTree();
|
$this->test_dump .= $this->dumpTree();
|
||||||
$this->deleteData();
|
$this->deleteData();
|
||||||
if($this->test_dump == $this->test_correct){ $this->test_log.="tree: OK\n"; return TRUE; }
|
if($this->test_dump == $this->test_correct){
|
||||||
else return PEAR::raiseError('Mtree::test:', 1, PEAR_ERROR_DIE, '%s'.
|
$this->test_log.="tree: OK\n"; return TRUE;
|
||||||
"<pre>\ncorrect:\n.{$this->test_correct}.\ndump:\n.{$this->test_dump}.\n</pre>\n");
|
}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()
|
function install()
|
||||||
{
|
{
|
||||||
$this->dbc->query("CREATE TABLE {$this->treeTable} (
|
$this->dbc->query("CREATE TABLE {$this->treeTable} (
|
||||||
|
@ -489,19 +581,23 @@ class Mtree{
|
||||||
type varchar(255) not null default'',
|
type varchar(255) not null default'',
|
||||||
param varchar(255)
|
param varchar(255)
|
||||||
)");
|
)");
|
||||||
$this->dbc->query("CREATE UNIQUE INDEX {$this->treeTable}_id_idx on {$this->treeTable} (id)");
|
$this->dbc->query("CREATE UNIQUE INDEX {$this->treeTable}_id_idx
|
||||||
$this->dbc->query("CREATE INDEX {$this->treeTable}_name_idx on {$this->treeTable} (name)");
|
ON {$this->treeTable} (id)");
|
||||||
|
$this->dbc->query("CREATE INDEX {$this->treeTable}_name_idx
|
||||||
|
ON {$this->treeTable} (name)");
|
||||||
$this->dbc->createSequence("{$this->treeTable}_id_seq");
|
$this->dbc->createSequence("{$this->treeTable}_id_seq");
|
||||||
|
|
||||||
$id = $this->dbc->nextId("{$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)
|
$this->dbc->query("INSERT INTO {$this->treeTable}
|
||||||
VALUES ($id, '{$this->rootNodeName}', NULL, 0, 1, 2, 'RootNode')");
|
(id, name, parid, level, lft, rgt, type)
|
||||||
|
VALUES
|
||||||
|
($id, '{$this->rootNodeName}', NULL, 0, 1, 2, 'RootNode')");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* uninstall
|
* Drop tables etc.
|
||||||
*
|
*
|
||||||
**/
|
*/
|
||||||
function uninstall()
|
function uninstall()
|
||||||
{
|
{
|
||||||
$this->dbc->query("DROP TABLE {$this->treeTable}");
|
$this->dbc->query("DROP TABLE {$this->treeTable}");
|
||||||
|
@ -509,9 +605,9 @@ class Mtree{
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* reinstall
|
* Uninstall and install
|
||||||
*
|
*
|
||||||
**/
|
*/
|
||||||
function reinstall()
|
function reinstall()
|
||||||
{
|
{
|
||||||
$this->uninstall();
|
$this->uninstall();
|
||||||
|
|
|
@ -1,5 +1,35 @@
|
||||||
<?php
|
<?php
|
||||||
// $Id: subj.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/subj.php,v $
|
||||||
|
|
||||||
|
------------------------------------------------------------------------------*/
|
||||||
|
require_once "class.php";
|
||||||
|
define('ALIBERR_NOTGR', 20);
|
||||||
|
define('ALIBERR_BADSMEMB', 21);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Subj class
|
* Subj class
|
||||||
|
@ -8,20 +38,21 @@
|
||||||
* with "linearized recursive membership" ;)
|
* with "linearized recursive membership" ;)
|
||||||
* (allow adding users to groups or groups to groups)
|
* (allow adding users to groups or groups to groups)
|
||||||
*
|
*
|
||||||
**/
|
* @author $Author: tomas $
|
||||||
require_once"class.php";
|
* @version $Revision: 1.2 $
|
||||||
define('ALIBERR_NOTGR', 20);
|
* @see ObjClasses
|
||||||
define('ALIBERR_BADSMEMB', 21);
|
* @see Alib
|
||||||
|
*/
|
||||||
class Subjects extends ObjClasses{
|
class Subjects extends ObjClasses{
|
||||||
var $subjTable;
|
var $subjTable;
|
||||||
var $smembTable;
|
var $smembTable;
|
||||||
/** Subjects - constructor
|
/**
|
||||||
|
* Constructor
|
||||||
*
|
*
|
||||||
* @param dbc object
|
* @param dbc object
|
||||||
* @param config array
|
* @param config array
|
||||||
* @return this
|
* @return this
|
||||||
**/
|
*/
|
||||||
function Subjects(&$dbc, $config)
|
function Subjects(&$dbc, $config)
|
||||||
{
|
{
|
||||||
parent::ObjClasses(&$dbc, $config);
|
parent::ObjClasses(&$dbc, $config);
|
||||||
|
@ -29,51 +60,55 @@ class Subjects extends ObjClasses{
|
||||||
$this->smembTable = $config['tblNamePrefix'].'smemb';
|
$this->smembTable = $config['tblNamePrefix'].'smemb';
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ========== public methods: ========== */
|
/* ======================================================= public methods */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* addSubj
|
* Add new subject
|
||||||
*
|
*
|
||||||
* @param login string
|
* @param login string
|
||||||
* @param pass string OPT
|
* @param pass string, optional
|
||||||
* @return int/err
|
* @return int/err
|
||||||
**/
|
*/
|
||||||
function addSubj($login, $pass=NULL)
|
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("
|
$r = $this->dbc->query("
|
||||||
INSERT INTO {$this->subjTable} (id, login, pass, type)
|
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;
|
if(PEAR::isError($r)) return $r;
|
||||||
return $id;
|
return $id;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* removeSubj
|
* Remove subject by uid or by login
|
||||||
*
|
*
|
||||||
* @param login string
|
* @param login string
|
||||||
* @param uid int OPT
|
* @param uid int, optional, default: null
|
||||||
* @return boolean/err
|
* @return boolean/err
|
||||||
**/
|
*/
|
||||||
function removeSubj($login, $uid=NULL)
|
function removeSubj($login, $uid=NULL)
|
||||||
{
|
{
|
||||||
if(is_null($uid)) $uid = $this->getSubjId($login);
|
if(is_null($uid)) $uid = $this->getSubjId($login);
|
||||||
if(PEAR::isError($uid)) return $uid;
|
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;
|
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;
|
if(PEAR::isError($r)) return $r;
|
||||||
return $this->_rebuildRels();
|
return $this->_rebuildRels();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* authenticate
|
* Check login and password
|
||||||
*
|
*
|
||||||
* @param login string
|
* @param login string
|
||||||
* @param pass string OPT
|
* @param pass string, optional
|
||||||
* @return boolean/int/err
|
* @return boolean/int/err
|
||||||
**/
|
*/
|
||||||
function authenticate($login, $pass='')
|
function authenticate($login, $pass='')
|
||||||
{
|
{
|
||||||
$cpass = md5($pass);
|
$cpass = md5($pass);
|
||||||
|
@ -85,44 +120,70 @@ class Subjects extends ObjClasses{
|
||||||
return (is_null($id) ? FALSE : $id);
|
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
|
* Add {login} and direct/indirect members to {gname} and to groups,
|
||||||
|
* where {gname} is [in]direct member
|
||||||
*
|
*
|
||||||
* @param login string
|
* @param login string
|
||||||
* @param gname string
|
* @param gname string
|
||||||
* @return int/err
|
* @return int/err
|
||||||
**/
|
*/
|
||||||
function addSubj2Gr($login, $gname)
|
function addSubj2Gr($login, $gname)
|
||||||
{
|
{
|
||||||
$uid = $this->getSubjId($login); if(PEAR::isError($uid)) return $uid;
|
$uid = $this->getSubjId($login); if(PEAR::isError($uid)) return $uid;
|
||||||
$gid = $this->getSubjId($gname); if(PEAR::isError($gid)) return $gid;
|
$gid = $this->getSubjId($gname); if(PEAR::isError($gid)) return $gid;
|
||||||
$isgr = $this->isGroup($gid); if(PEAR::isError($isgr)) return $isgr;
|
$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:
|
// 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:
|
// add it to all groups where $gname is [in]direct member:
|
||||||
$marr = $this->_listRMemb($gid); if(PEAR::isError($marr)) return $marr;
|
$marr = $this->_listRMemb($gid); if(PEAR::isError($marr)) return $marr;
|
||||||
foreach($marr as $k=>$v){
|
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;
|
if(PEAR::isError($r)) return $r;
|
||||||
}
|
}
|
||||||
return $mid;
|
return $mid;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* removeSubjFromGr
|
* Remove subject from group
|
||||||
*
|
*
|
||||||
* @param login string
|
* @param login string
|
||||||
* @param gname string
|
* @param gname string
|
||||||
* @return boolean/err
|
* @return boolean/err
|
||||||
**/
|
*/
|
||||||
function removeSubjFromGr($login, $gname)
|
function removeSubjFromGr($login, $gname)
|
||||||
{
|
{
|
||||||
$uid = $this->getSubjId($login); if(PEAR::isError($uid)) return $uid;
|
$uid = $this->getSubjId($login); if(PEAR::isError($uid)) return $uid;
|
||||||
$gid = $this->getSubjId($gname); if(PEAR::isError($gid)) return $gid;
|
$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(is_null($mid)) return FALSE;
|
||||||
if(PEAR::isError($mid)) return $mid;
|
if(PEAR::isError($mid)) return $mid;
|
||||||
// remove it:
|
// remove it:
|
||||||
|
@ -132,106 +193,121 @@ class Subjects extends ObjClasses{
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* --- info methods: --- */
|
/* --------------------------------------------------------- info methods */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* getSubjId
|
* Get subject id from login
|
||||||
*
|
*
|
||||||
* @param login string
|
* @param login string
|
||||||
* @return int/err
|
* @return int/err
|
||||||
**/
|
*/
|
||||||
function getSubjId($login)
|
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
|
* Get subject name (login) from id
|
||||||
*
|
*
|
||||||
* @param id int
|
* @param id int
|
||||||
* @param fld string
|
* @param fld string
|
||||||
* @return string/err
|
* @return string/err
|
||||||
**/
|
*/
|
||||||
function getSubjName($id, $fld='login')
|
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
|
* Get all subjects
|
||||||
*
|
*
|
||||||
* @param flds string OPT
|
* @param flds string, optional
|
||||||
* @return array/err
|
* @return array/err
|
||||||
**/
|
*/
|
||||||
function getSubjects($flds='id, login')
|
function getSubjects($flds='id, login')
|
||||||
{
|
{
|
||||||
return $this->dbc->getAll("SELECT $flds FROM {$this->subjTable}");
|
return $this->dbc->getAll("SELECT $flds FROM {$this->subjTable}");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* getSubjectsWCnt - get subjects with count of direct members
|
* Get subjects with count of direct members
|
||||||
*
|
*
|
||||||
* @return array/err
|
* @return array/err
|
||||||
**/
|
*/
|
||||||
function getSubjectsWCnt()
|
function getSubjectsWCnt()
|
||||||
{
|
{
|
||||||
return $this->dbc->getAll("SELECT count(m.uid)as cnt, s.id, s.login, s.type
|
return $this->dbc->getAll("
|
||||||
FROM {$this->subjTable} s LEFT JOIN {$this->smembTable} m ON m.gid=s.id
|
SELECT count(m.uid)as cnt, s.id, s.login, s.type
|
||||||
WHERE m.mid is null GROUP BY s.id, s.login, s.type ORDER BY s.id");
|
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
|
* Return true if subject is a group
|
||||||
*
|
*
|
||||||
* @param gid int
|
* @param gid int
|
||||||
* @return boolean/err
|
* @return boolean/err
|
||||||
**/
|
*/
|
||||||
function isGroup($gid)
|
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;
|
if(PEAR::isError($r)) return $r;
|
||||||
return ($r === 'G' );
|
return ($r === 'G' );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* listGroup - list direct members of group
|
* List direct members of group
|
||||||
*
|
*
|
||||||
* @param gid int
|
* @param gid int
|
||||||
* @return array/err
|
* @return array/err
|
||||||
**/
|
*/
|
||||||
function listGroup($gid)
|
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'");
|
WHERE m.uid=s.id AND m.mid is null AND m.gid='$gid'");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ========== "private" methods: ========== */
|
/* ==================================================== "private" methods */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* _addMemb - create membership record
|
* Create membership record
|
||||||
*
|
*
|
||||||
* @param uid int
|
* @param uid int
|
||||||
* @param gid int
|
* @param gid int
|
||||||
* @param level int OPT
|
* @param level int, optional
|
||||||
* @param mid int OPT
|
* @param mid int, optional
|
||||||
* @return int/err
|
* @return int/err
|
||||||
**/
|
*/
|
||||||
function _addMemb($uid, $gid, $level=0, $mid='null')
|
function _addMemb($uid, $gid, $level=0, $mid='null')
|
||||||
{
|
{
|
||||||
if($uid == $gid) return PEAR::raiseError("Subjects::_addMemb: uid==gid ($uid)", ALIBERR_BADSMEMB);
|
if($uid == $gid) return PEAR::raiseError(
|
||||||
$a = $this->dbc->getAll("SELECT id, level, mid FROM {$this->smembTable} WHERE uid='$uid' AND gid='$gid' ORDER BY level ASC");
|
"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(PEAR::isError($a)) return $a;
|
||||||
if(count($a)>0){
|
if(count($a)>0){
|
||||||
$a0 = $a[0];
|
$a0 = $a[0];
|
||||||
$id = $a0['id'];
|
$id = $a0['id'];
|
||||||
if($level < intval($a0['level'])){
|
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;
|
if(PEAR::isError($r)) return $r;
|
||||||
}
|
}
|
||||||
}else{
|
}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("
|
$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;
|
if(PEAR::isError($r)) return $r;
|
||||||
}
|
}
|
||||||
|
@ -239,77 +315,92 @@ class Subjects extends ObjClasses{
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* _removeMemb
|
* Remove membership record
|
||||||
*
|
*
|
||||||
* @param mid int
|
* @param mid int
|
||||||
* @return null/err
|
* @return null/err
|
||||||
**/
|
*/
|
||||||
function _removeMemb($mid)
|
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
|
* List [in]direct members of group
|
||||||
*
|
*
|
||||||
* @param gid int
|
* @param gid int
|
||||||
* @param uid int OPT
|
* @param uid int, optional
|
||||||
* @return array/err
|
* @return array/err
|
||||||
**/
|
*/
|
||||||
function _listMemb($gid, $uid=NULL)
|
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
|
* List groups where uid is [in]direct member
|
||||||
*
|
*
|
||||||
* @param gid int
|
* @param gid int
|
||||||
* @param uid int OPT
|
* @param uid int, optional
|
||||||
* @return array/err
|
* @return array/err
|
||||||
**/
|
*/
|
||||||
function _listRMemb($uid, $gid=NULL)
|
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
|
* Add uid and its [in]direct members to gid
|
||||||
*
|
*
|
||||||
* @param uid int
|
* @param uid int
|
||||||
* @param gid int
|
* @param gid int
|
||||||
* @param level int
|
* @param level int
|
||||||
* @param rmid int //
|
* @param rmid int //
|
||||||
* @return int/err
|
* @return int/err
|
||||||
**/
|
*/
|
||||||
function _plainAddSubj2Gr($uid, $gid, $level=0, $rmid='null')
|
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;
|
$marr = $this->_listMemb($uid); if(PEAR::isError($marr)) return $marr;
|
||||||
foreach($marr as $k=>$v){
|
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;
|
if(PEAR::isError($r)) return $r;
|
||||||
}
|
}
|
||||||
return $mid;
|
return $mid;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* _rebuildRels - rebuild indirect membership records
|
* Rebuild indirect membership records<br>
|
||||||
|
* it's probably more complicated to do removing without rebuild ...
|
||||||
*
|
*
|
||||||
* @return true/err
|
* @return true/err
|
||||||
**/
|
*/
|
||||||
function _rebuildRels()
|
function _rebuildRels()
|
||||||
{
|
{
|
||||||
$this->dbc->query("BEGIN");
|
$this->dbc->query("BEGIN");
|
||||||
$r = $this->dbc->query("LOCK TABLE {$this->smembTable}"); if(PEAR::isError($r)) return $r;
|
$r = $this->dbc->query("LOCK TABLE {$this->smembTable}");
|
||||||
$r = $this->dbc->query("DELETE FROM {$this->smembTable} WHERE mid is not null");
|
|
||||||
if(PEAR::isError($r)) return $r;
|
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;
|
if(PEAR::isError($arr)) return $arr;
|
||||||
foreach($arr as $it){
|
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){
|
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;
|
if(PEAR::isError($r)) return $r;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -317,27 +408,30 @@ class Subjects extends ObjClasses{
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ========== test and debug methods: ========== */
|
|
||||||
|
/* =============================================== test and debug methods */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* dumpSubjects
|
* Dump subjects for debug
|
||||||
*
|
*
|
||||||
* @param indstr string // indentation string
|
* @param indstr string // indentation string
|
||||||
* @param ind string // aktual indentation
|
* @param ind string // aktual indentation
|
||||||
* @return string
|
* @return string
|
||||||
**/
|
*/
|
||||||
function dumpSubjects($indstr=' ', $ind='')
|
function dumpSubjects($indstr=' ', $ind='')
|
||||||
{
|
{
|
||||||
# $r = $ind.join(', ', $this->dbc->getCol("SELECT login FROM {$this->subjTable}"))."\n";
|
$r = $ind.join(', ', array_map(
|
||||||
$r = $ind.join(', ', array_map(create_function('$v', 'return "{$v[\'login\']}({$v[\'cnt\']})";'), $this->getSubjectsWCnt()))."\n";
|
create_function('$v', 'return "{$v[\'login\']}({$v[\'cnt\']})";'),
|
||||||
|
$this->getSubjectsWCnt()
|
||||||
|
))."\n";
|
||||||
return $r;
|
return $r;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* deleteData
|
* Delete all subjects and membership records
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
**/
|
*/
|
||||||
function deleteData()
|
function deleteData()
|
||||||
{
|
{
|
||||||
$this->dbc->query("DELETE FROM {$this->subjTable}");
|
$this->dbc->query("DELETE FROM {$this->subjTable}");
|
||||||
|
@ -346,10 +440,10 @@ class Subjects extends ObjClasses{
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* testData
|
* Insert test data
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
**/
|
*/
|
||||||
function testData()
|
function testData()
|
||||||
{
|
{
|
||||||
parent::testData();
|
parent::testData();
|
||||||
|
@ -373,32 +467,38 @@ class Subjects extends ObjClasses{
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* test
|
* Make basic test
|
||||||
*
|
*
|
||||||
**/
|
*/
|
||||||
function test()
|
function test()
|
||||||
{
|
{
|
||||||
if(PEAR::isError($p = parent::test())) return $p;
|
if(PEAR::isError($p = parent::test())) return $p;
|
||||||
$this->deleteData();
|
$this->deleteData();
|
||||||
$this->testData();
|
$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->test_dump = $this->dumpSubjects();
|
||||||
$this->removeSubj('test1');
|
$this->removeSubj('test1');
|
||||||
$this->removeSubj('test3');
|
$this->removeSubj('test3');
|
||||||
$this->removeSubjFromGr('test2', 'gr1');
|
$this->removeSubjFromGr('test2', 'gr1');
|
||||||
$this->removeSubjFromGr('gr3', 'gr2');
|
$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->test_dump .= $this->dumpSubjects();
|
||||||
$this->deleteData();
|
$this->deleteData();
|
||||||
if($this->test_dump == $this->test_correct){ $this->test_log.="subj: OK\n"; return TRUE; }
|
if($this->test_dump == $this->test_correct)
|
||||||
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");
|
$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()
|
function install()
|
||||||
{
|
{
|
||||||
parent::install();
|
parent::install();
|
||||||
|
@ -408,8 +508,10 @@ class Subjects extends ObjClasses{
|
||||||
pass varchar(255) not null default'',
|
pass varchar(255) not null default'',
|
||||||
type char(1) not null default 'U'
|
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}_id_idx
|
||||||
$this->dbc->query("CREATE UNIQUE INDEX {$this->subjTable}_login_idx on {$this->subjTable} (login)");
|
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->createSequence("{$this->subjTable}_id_seq");
|
||||||
|
|
||||||
$this->dbc->query("CREATE TABLE {$this->smembTable} (
|
$this->dbc->query("CREATE TABLE {$this->smembTable} (
|
||||||
|
@ -419,16 +521,17 @@ class Subjects extends ObjClasses{
|
||||||
level int not null default 0,
|
level int not null default 0,
|
||||||
mid int
|
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");
|
$this->dbc->createSequence("{$this->smembTable}_id_seq");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* uninstall
|
* Drop tables etc.
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
**/
|
*/
|
||||||
function uninstall()
|
function uninstall()
|
||||||
{
|
{
|
||||||
$this->dbc->query("DROP TABLE {$this->subjTable}");
|
$this->dbc->query("DROP TABLE {$this->subjTable}");
|
||||||
|
|
|
@ -1,5 +1,32 @@
|
||||||
<?php
|
<?php
|
||||||
// $Id: alib_xr.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/alib_xr.php,v $
|
||||||
|
|
||||||
|
------------------------------------------------------------------------------*/
|
||||||
include_once "xmlrpc.inc";
|
include_once "xmlrpc.inc";
|
||||||
include_once "xmlrpcs.inc";
|
include_once "xmlrpcs.inc";
|
||||||
require_once "../example/alib_h.php";
|
require_once "../example/alib_h.php";
|
||||||
|
@ -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){
|
function xr_test($input){
|
||||||
$p1=$input->getParam(0);
|
$p1=$input->getParam(0);
|
||||||
if(isset($p1) && $p1->scalartyp()=="string") $s=$p1->scalarval();
|
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);
|
$p2=$input->getParam(1);
|
||||||
if(isset($p2) && $p2->scalartyp()=="string") $sessid=$p2->scalarval();
|
if(isset($p2) && $p2->scalartyp()=="string") $sessid=$p2->scalarval();
|
||||||
else return new xmlrpcresp(0, 801, "xr_login: wrong 2nd parameter, string expected.");
|
else return new xmlrpcresp(0, 801,
|
||||||
return new xmlrpcresp(v2xr(strtoupper($s)."_".$this->getSessLogin($sessid)."_".$sessid, false));
|
"xr_login: wrong 2nd parameter, string expected.");
|
||||||
|
return new xmlrpcresp(
|
||||||
|
v2xr(strtoupper($s)."_".$this->getSessLogin($sessid)."_".$sessid, false)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
function xr_login($input){
|
function xr_login($input){
|
||||||
$p1=$input->getParam(0);
|
$p1=$input->getParam(0);
|
||||||
if(isset($p1) && $p1->scalartyp()=="string") $login=$p1->scalarval();
|
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);
|
$p2=$input->getParam(1);
|
||||||
if(isset($p2) && $p2->scalartyp()=="string") $pass=$p2->scalarval();
|
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)))
|
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
|
else
|
||||||
return new xmlrpcresp(v2xr($res, false));
|
return new xmlrpcresp(v2xr($res, false));
|
||||||
}
|
}
|
||||||
function xr_logout($input){
|
function xr_logout($input){
|
||||||
$p1=$input->getParam(0);
|
$p1=$input->getParam(0);
|
||||||
if(isset($p1) && $p1->scalartyp()=="string") $sessid=$p1->scalarval();
|
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);
|
$res = $this->logout($sessid);
|
||||||
if(!PEAR::isError($res)) return new xmlrpcresp(v2xr('Bye', false));
|
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){
|
function xr_getDir($input){
|
||||||
$p1=$input->getParam(0);
|
$p1=$input->getParam(0);
|
||||||
if(isset($p1) && ($p1->scalartyp()=="int") && is_numeric($id=$p1->scalarval()));
|
if(isset($p1) && ($p1->scalartyp()=="int") &&
|
||||||
else return new xmlrpcresp(0, 801, "xr_getDir: wrong 1st parameter, int expected.");
|
is_numeric($id=$p1->scalarval()));
|
||||||
|
else return new xmlrpcresp(0, 801,
|
||||||
|
"xr_getDir: wrong 1st parameter, int expected.");
|
||||||
$res = $this->getDir($id, 'name');
|
$res = $this->getDir($id, 'name');
|
||||||
return new xmlrpcresp(v2xr($res, false));
|
return new xmlrpcresp(v2xr($res, false));
|
||||||
}
|
}
|
||||||
function xr_getPath($input){
|
function xr_getPath($input){
|
||||||
$p1=$input->getParam(0);
|
$p1=$input->getParam(0);
|
||||||
if(isset($p1) && ($p1->scalartyp()=="int") && is_numeric($id=$p1->scalarval()));
|
if(isset($p1) && ($p1->scalartyp()=="int") &&
|
||||||
else return new xmlrpcresp(0, 801, "xr_getPath: wrong 1st parameter, int expected.");
|
is_numeric($id=$p1->scalarval()));
|
||||||
|
else return new xmlrpcresp(0, 801,
|
||||||
|
"xr_getPath: wrong 1st parameter, int expected.");
|
||||||
$res = $this->getPath($id, 'id, name');
|
$res = $this->getPath($id, 'id, name');
|
||||||
return new xmlrpcresp(v2xr($res, false));
|
return new xmlrpcresp(v2xr($res, false));
|
||||||
}
|
}
|
||||||
|
@ -88,12 +137,10 @@ $s=new xmlrpc_server( array(
|
||||||
"alib.getPath" => array(
|
"alib.getPath" => array(
|
||||||
"function" => array(&$alib, 'xr_getPath'),
|
"function" => array(&$alib, 'xr_getPath'),
|
||||||
"signature" => array(array($xmlrpcArray, $xmlrpcInt)),
|
"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";
|
require_once"../example/alib_f.php";
|
||||||
?>
|
?>
|
|
@ -1,7 +1,33 @@
|
||||||
<?php
|
<?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");
|
header ("location: xr_cli_test.php");
|
||||||
die;
|
die;
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|
|
@ -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)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,32 @@
|
||||||
<?php
|
<?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");
|
include("xmlrpc.inc");
|
||||||
|
|
||||||
$host = "localhost";
|
$host = "localhost";
|
||||||
|
@ -17,11 +43,15 @@ switch($ak){
|
||||||
new xmlrpcval($_REQUEST['sessid'], "string")));
|
new xmlrpcval($_REQUEST['sessid'], "string")));
|
||||||
break;
|
break;
|
||||||
case"login":
|
case"login":
|
||||||
$f=new xmlrpcmsg('alib.login', array(new xmlrpcval($_REQUEST['login'], "string"),
|
$f=new xmlrpcmsg('alib.login',array(
|
||||||
new xmlrpcval($_REQUEST['pass'], "string")));
|
new xmlrpcval($_REQUEST['login'], "string"),
|
||||||
|
new xmlrpcval($_REQUEST['pass'], "string")
|
||||||
|
));
|
||||||
break;
|
break;
|
||||||
case"logout":
|
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;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,11 +66,15 @@ switch($ak){
|
||||||
$v=$r->value();
|
$v=$r->value();
|
||||||
$log = $v->serialize();
|
$log = $v->serialize();
|
||||||
if($ak=='test')
|
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=='login') $sessid = $v->scalarval();
|
||||||
if($ak=='logout') $sessid = '';
|
if($ak=='logout') $sessid = '';
|
||||||
} else {
|
} 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;
|
break;
|
||||||
}
|
}
|
||||||
|
|
82
livesupport/modules/alib/var/xmlrpc/xr_cli_test.py
Executable file
82
livesupport/modules/alib/var/xmlrpc/xr_cli_test.py
Executable 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)
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue