1<?php
2// BC hack
3if (!defined('PATH_SEPARATOR')) {
4    if (defined('DIRECTORY_SEPARATOR') && DIRECTORY_SEPARATOR == "\\") {
5        define('PATH_SEPARATOR', ';');
6    } else {
7        define('PATH_SEPARATOR', ':');
8    }
9}
10
11error_reporting(E_ALL);
12
13// right definitions
14define('READ_TESTS', 1);
15define('WRITE_TESTS', 2);
16define('ACCESS', 3);
17define('LAUNCH_ATOMIC_BOMB', 4);
18define('FLY_ALIEN_SPACE_CRAFT', 5);
19define('MAKE_COFFEE', 6);
20define('DRINK_COFFEE', 7);
21
22// set this to the path in which the directory for liveuser resides
23// more remove the following two lines to test LiveUser in the standard
24// PEAR directory
25//$path_to_liveuser_dir = './pear/'.PATH_SEPARATOR;
26//ini_set('include_path', $path_to_liveuser_dir.ini_get('include_path'));
27
28// Data Source Name (DSN)
29$dsn = 'mysql://root@localhost/liveuser_admin_test_example3';
30
31$liveuserConfig = array(
32    'session'           => array('name' => 'PHPSESSID','varname' => 'loginInfo'),
33    'logout'            => array('destroy'  => true),
34    'cookie'            => array(
35        'name' => 'loginInfo',
36        'path' => null,
37        'domain' => null,
38        'secure' => false,
39        'lifetime' => 30,
40        'secret' => 'mysecretkey',
41        'savedir' => '.',
42    ),
43    'authContainers'    => array(
44        'DB' => array(
45            'type'          => 'MDB2',
46            'expireTime'   => 0,
47            'idleTime'     => 0,
48            'passwordEncryptionMode' => 'PLAIN',
49            'storage' => array(
50                'dsn' => $dsn,
51                'alias' => array(
52                    'auth_user_id' => 'authuserid',
53                    'lastlogin' => 'lastlogin',
54                    'is_active' => 'isactive',
55                ),
56                'fields' => array(
57                    'lastlogin' => 'timestamp',
58                    'is_active' => 'boolean',
59                ),
60                'tables' => array(
61                    'users' => array(
62                        'fields' => array(
63                            'lastlogin' => false,
64                            'is_active' => false,
65                        ),
66                    ),
67                ),
68            )
69        )
70    ),
71    'permContainer' => array(
72        'type'  => 'Medium',
73        'storage' => array(
74            'MDB2' => array(
75                'dsn' => $dsn,
76                'prefix' => 'liveuser_',
77                'alias' => array(),
78                'tables' => array(),
79                'fields' => array(),
80            ),
81        ),
82    ),
83);
84
85// Get LiveUser class definition
86require_once 'LiveUser.php';
87
88// The error handling stuff is not needed and used only for debugging
89// while LiveUser is not yet mature
90PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, 'eHandler');
91
92function eHandler($errObj)
93{
94    echo('<hr /><span style="color: red;">' . $errObj->getMessage() . ':<br />' . $errObj->getUserInfo() . '</span><hr />');
95    $debug_backtrace = debug_backtrace();
96    array_shift($debug_backtrace);
97    $message= 'Debug backtrace:'."\n";
98
99    foreach ($debug_backtrace as $trace_item) {
100        $message.= "\t" . '    @ ';
101        if (array_key_exists('file', $trace_item)) {
102            $message.= basename($trace_item['file']) . ':' . $trace_item['line'];
103        } else {
104            $message.= '- PHP inner-code - ';
105        }
106        $message.= ' -- ';
107        if (array_key_exists('class', $trace_item)) {
108            $message.= $trace_item['class'] . $trace_item['type'];
109        }
110        $message.= $trace_item['function'];
111
112        if (array_key_exists('args', $trace_item) && is_array($trace_item['args'])) {
113            $message.= '('.@implode(', ', $trace_item['args']).')';
114        } else {
115            $message.= '()';
116        }
117        $message.= "\n";
118    }
119    echo "<pre>$message</pre>";
120}
121
122// Create new LiveUser object
123$LU =& LiveUser::factory($liveuserConfig);
124
125if (!$LU->init()) {
126    var_dump($LU->getErrors());
127    die();
128}
129
130$handle = (array_key_exists('handle', $_REQUEST)) ? $_REQUEST['handle'] : null;
131$passwd = (array_key_exists('passwd', $_REQUEST)) ? $_REQUEST['passwd'] : null;
132$logout = (array_key_exists('logout', $_REQUEST)) ? $_REQUEST['logout'] : false;
133$remember = (array_key_exists('rememberMe', $_REQUEST)) ? $_REQUEST['rememberMe'] : false;
134if ($logout) {
135    $LU->logout(true);
136} elseif(!$LU->isLoggedIn() || ($handle && $LU->getProperty('handle') != $handle)) {
137    if (!$handle) {
138        $LU->login(null, null, true);
139    } else {
140        $LU->login($handle, $passwd, $remember);
141    }
142}
143
144require_once 'LiveUser/Admin.php';
145
146$luadmin =& LiveUser_Admin::factory($liveuserConfig);
147$luadmin->init();
148
149$language_selected = array_key_exists('language', $_GET) ? $_GET['language'] : 'de';
150