1<?php
2/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
3
4/**
5 * A framework for authentication and authorization in PHP applications
6 *
7 * LiveUser is an authentication/permission framework designed
8 * to be flexible and easily extendable.
9 *
10 * Since it is impossible to have a
11 * "one size fits all" it takes a container
12 * approach which should enable it to
13 * be versatile enough to meet most needs.
14 *
15 * PHP version 4 and 5
16 *
17 * LICENSE: This library is free software; you can redistribute it and/or
18 * modify it under the terms of the GNU Lesser General Public
19 * License as published by the Free Software Foundation; either
20 * version 2.1 of the License, or (at your option) any later version.
21 *
22 * This library is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
25 * Lesser General Public License for more details.
26 *
27 * You should have received a copy of the GNU Lesser General Public
28 * License along with this library; if not, write to the Free Software
29 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
30 * MA  02111-1307  USA
31 *
32 *
33 * @category authentication
34 * @package LiveUser
35 * @author  Markus Wolff <wolff@21st.de>
36 * @author  Helgi �ormar �orbj�rnsson <dufuz@php.net>
37 * @author  Lukas Smith <smith@pooteeweet.org>
38 * @author  Arnaud Limbourg <arnaud@php.net>
39 * @author  Pierre-Alain Joye <pajoye@php.net>
40 * @author  Bjoern Kraus <krausbn@php.net>
41 * @copyright 2002-2006 Markus Wolff
42 * @license http://www.gnu.org/licenses/lgpl.txt
43 * @version CVS: $Id: Storage.php 304421 2010-10-15 13:30:56Z clockwerx $
44 * @link http://pear.php.net/LiveUser
45 */
46
47/**
48 * Abstraction class for all the storage containers
49 *
50 * @category authentication
51 * @package LiveUser
52 * @author  Lukas Smith <smith@pooteeweet.org>
53 * @author  Bjoern Kraus <krausbn@php.net>
54 * @copyright 2002-2006 Markus Wolff
55 * @license http://www.gnu.org/licenses/lgpl.txt
56 * @version Release: @package_version@
57 * @link http://pear.php.net/LiveUser
58 */
59class LiveUser_Perm_Storage
60{
61    /**
62     * Table configuration
63     *
64     * @var    array
65     * @access public
66     */
67    var $tables = array();
68
69    /**
70     * All fields with their types
71     *
72     * @var    array
73     * @access public
74     */
75    var $fields = array();
76
77    /**
78     * All fields with their alias
79     *
80     * @var    array
81     * @access public
82     */
83    var $alias = array();
84
85    /**
86     * Constructor
87     *
88     * @access protected
89     * @param  mixed      configuration array
90     * @return void
91     */
92    function LiveUser_Perm_Storage()
93    {
94        $this->stack = &PEAR_ErrorStack::singleton('LiveUser');
95    }
96
97    /**
98     * Initialize the storage container
99     *
100     * @param array Array with the storage configuration
101     * @return bool true on success, false on failure.
102     *
103     * @access public
104     */
105    function init(&$storageConf)
106    {
107        if (is_array($storageConf)) {
108            $keys = array_keys($storageConf);
109            foreach ($keys as $key) {
110                if (isset($this->$key)) {
111                    $this->$key =& $storageConf[$key];
112                }
113            }
114        }
115
116        require_once 'LiveUser/Perm/Storage/Globals.php';
117        if (empty($this->tables)) {
118            $this->tables = $GLOBALS['_LiveUser']['perm']['tables'];
119        } else {
120            $this->tables = LiveUser::arrayMergeClobber($GLOBALS['_LiveUser']['perm']['tables'], $this->tables);
121        }
122        if (empty($this->fields)) {
123            $this->fields = $GLOBALS['_LiveUser']['perm']['fields'];
124        } else {
125            $this->fields = LiveUser::arrayMergeClobber($GLOBALS['_LiveUser']['perm']['fields'], $this->fields);
126        }
127        if (empty($this->alias)) {
128            $this->alias = $GLOBALS['_LiveUser']['perm']['alias'];
129        } else {
130            $this->alias = LiveUser::arrayMergeClobber($GLOBALS['_LiveUser']['perm']['alias'], $this->alias);
131        }
132
133        return true;
134    }
135
136    /**
137     * map an auth user to a perm user
138     *
139     * @param int $auth_user_id
140     * @param string $containerName
141     * @return array requested data or false on failure
142     *
143     * @access public
144     */
145    function mapUser($auth_user_id, $containerName)
146    {
147        $this->stack->push(LIVEUSER_ERROR, 'error', array(),
148            __METHOD__.' is not implemented');
149        return false;
150    }
151
152    /**
153     * Reads all rights of current user into a
154     * two-dimensional associative array, having the
155     * area names as the key of the 1st dimension.
156     * Group rights and invididual rights are being merged
157     * in the process.
158     *
159     * @param int perm user id
160     * @return array requested data or false on failure
161     *
162     * @access public
163     */
164    function readUserRights($perm_user_id)
165    {
166        $this->stack->push(LIVEUSER_ERROR, 'error', array(),
167            __METHOD__.' is not implemented');
168        return false;
169    }
170
171    /**
172     * read the areas in which a user is an area admin
173     *
174     * @param int perm user id
175     * @return array requested data or false on failure
176     *
177     * @access public
178     */
179    function readAreaAdminAreas($perm_user_id)
180    {
181        $this->stack->push(LIVEUSER_ERROR, 'error', array(),
182            __METHOD__.' is not implemented');
183        return false;
184    }
185
186    /**
187     * Reads all the group ids in that the user is also a member of
188     * (all groups that are subgroups of these are also added recursively)
189     *
190     * @param int perm user id
191     * @return array requested data or false on failure
192     *
193     * @see    readRights()
194     * @access public
195     */
196    function readGroups($perm_user_id)
197    {
198        $this->stack->push(LIVEUSER_ERROR, 'error', array(),
199            __METHOD__.' is not implemented');
200        return false;
201    }
202
203    /**
204     * Reads the group rights
205     * and put them in the array
206     *
207     * right => 1
208     *
209     * @param int group ids
210     * @return array requested data or false on failure
211     *
212     * @access public
213     */
214    function readGroupRights($group_ids)
215    {
216        $this->stack->push(LIVEUSER_ERROR, 'error', array(),
217            __METHOD__.' is not implemented');
218        return false;
219    }
220
221    /**
222     * Read the sub groups of the new groups that are not part of the group ids
223     *
224     * @param array group ids
225     * @param array new group ids
226     * @return array requested data or false on failure
227     *
228     * @access public
229     */
230    function readSubGroups($group_ids, $newGroupIds)
231    {
232        $this->stack->push(LIVEUSER_ERROR, 'error', array(),
233            __METHOD__.' is not implemented');
234        return false;
235    }
236
237    /**
238     * Read out the rights from the userrights or grouprights table
239     * that imply other rights along with their level
240     *
241     * @param array right ids
242     * @param string name of the table
243     * @return array requested data or false on failure
244     *
245     * @access public
246     */
247    function readImplyingRights($rightIds, $table)
248    {
249        $this->stack->push(LIVEUSER_ERROR, 'error', array(),
250            __METHOD__.' is not implemented');
251        return false;
252    }
253
254    /**
255    * Read out the implied rights with a given level from the implied_rights table
256    *
257    * @param array current right ids
258    * @param string current level
259     * @return array requested data or false on failure
260    *
261    * @access public
262    */
263    function readImpliedRights($currentRights, $currentLevel)
264    {
265        $this->stack->push(LIVEUSER_ERROR, 'error', array(),
266            __METHOD__.' is not implemented');
267        return false;
268    }
269
270    /**
271     * store all properties in the session and return them as an array
272     *
273     * @param string name of the key to use inside the session
274     * @param array property values
275     * @return array containing the property values
276     *
277     * @access public
278     */
279    function freeze($sessionName, $propertyValues)
280    {
281        $_SESSION[$sessionName]['perm'] = $propertyValues;
282        return $propertyValues;
283    }
284
285    /**
286     * Reinitializes properties
287     *
288     * @param string name of the key to use inside the session
289     * @return array
290     *
291     * @access public
292     */
293    function unfreeze($sessionName)
294    {
295        return (array_key_exists('perm', $_SESSION[$sessionName])
296            && is_array($_SESSION[$sessionName]['perm']))
297                ? $_SESSION[$sessionName]['perm'] : array();
298    }
299
300    /**
301     * properly disconnect from resources
302     *
303     * @return bool true on success and false on failure
304     *
305     * @access public
306     */
307    function disconnect()
308    {
309    }
310}
311?>