Project

General

Profile

1 1386 Luisehahne
<?php
2
/**
3
 *
4
 * @category        admin
5
 * @package         users
6 1529 Luisehahne
 * @author          Ryan Djurovich, WebsiteBaker Project
7 1710 Luisehahne
 * @copyright       2009-2012, WebsiteBaker Org. e.V.
8 1386 Luisehahne
 * @link			http://www.websitebaker2.org/
9
 * @license         http://www.gnu.org/licenses/gpl.html
10
 * @platform        WebsiteBaker 2.8.x
11
 * @requirements    PHP 5.2.2 and higher
12
 * @version         $Id$
13
 * @filesource		$HeadURL$
14
 * @lastmodified    $Date$
15
 *
16 1804 Luisehahne
 */
17 1386 Luisehahne
18 1815 Luisehahne
    /**
19
     * checks if a given string is part of a line in a defined file
20
     * @param string $sString
21
     * @param string $sListFile
22
     * @return bool TRUE if at least one match is found, otherwise FALSE
23
     */
24
    function findStringInFileList( $sString, $sListFile)
25
    {
26 2098 darkviper
        $aMatch = array();
27
        if(is_readable($sListFile)) {
28
            $aList = file($sListFile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
29
            $aMatch = preg_grep('/'.preg_quote($sString, '/').'/i',$aList);
30
        }
31
        return (sizeof($aMatch)>0);
32 1815 Luisehahne
    }
33 1804 Luisehahne
34 1815 Luisehahne
	function admin_users_index($aActionRequest)
35
	{
36 2099 darkviper
        $oReg = WbAdaptor::getInstance();
37 2098 darkviper
		$oDb = WbDatabase::getInstance();
38
		$oTrans = Translate::getInstance();
39
		$oTrans->enableAddon('admin\\users');
40 1804 Luisehahne
41 2099 darkviper
        $sModulePath = rtrim(dirname(str_replace('\\', '/', __FILE__)), '/').'/';
42
        $sAdminName = basename($sModulePath);
43 1815 Luisehahne
        $output = '';
44
        $aActionRequest['requestMethod'] = '_'.strtoupper($_SERVER['REQUEST_METHOD']);
45
        $action = 'show';
46
        // Set parameter 'action' as alternative to javascript mechanism
47
        $action = (isset($aActionRequest['add'])    ? 'add'    : $action );
48
        $action = (isset($aActionRequest['save'])   ? 'save'   : $action );
49 1823 Luisehahne
        $action = (isset($aActionRequest['save_back']) ? 'save'   : $action );
50 1815 Luisehahne
        $action = (isset($aActionRequest['modify']) ? 'modify' : $action );
51
        $action = (isset($aActionRequest['delete']) ? 'delete' : $action );
52
        $action = (isset($aActionRequest['delete_outdated']) ? 'delete_outdated' : $action );
53 2076 darkviper
        $action = (isset($aActionRequest['enable_outdated']) ? 'enable_outdated' : $action );
54 1386 Luisehahne
55 1815 Luisehahne
		switch($action) :
56
			case 'delete': // delete the user
57 1842 Luisehahne
			case 'delete_outdated': // delete Users awaiting activation
58 2076 darkviper
			case 'enable_outdated': // enable Users awaiting activation
59 1815 Luisehahne
    			$admin = new admin('Access', 'users_delete',false);
60 2099 darkviper
				include($sModulePath.'delete.php');
61 1844 Luisehahne
    			delete_user($admin,$aActionRequest);
62 2099 darkviper
                $aActionRequest['cancel_url'] = $oReg->AcpUrl.'access/index.php';
63 1815 Luisehahne
				$admin = new admin('Access', 'users');
64 2099 darkviper
				include($sModulePath.'user_list.php');
65 1815 Luisehahne
				$output .= show_userlist($admin, $aActionRequest);
66
				break;
67
			case 'add': // insert/update user
68
                $admin = new admin('Access', 'users_add',false);
69 2099 darkviper
				include($sModulePath.'add.php');
70 1844 Luisehahne
    			add_user($admin,$aActionRequest);
71 2099 darkviper
                $aActionRequest['cancel_url'] = $oReg->AcpUrl.'access/index.php';
72 1815 Luisehahne
				$admin = new admin('Access', 'users');
73 2099 darkviper
				include($sModulePath.'user_list.php');
74 1815 Luisehahne
				$output .= show_userlist($admin, $aActionRequest);
75
				break;
76
			case 'save': // insert/update user
77
    			$admin = new admin('Access', 'users_modify',false);
78
// hold the cancel_url if request comes outside from users
79
                if(isset($aActionRequest['BackLink'])) {
80
                    $sBackLink = $aActionRequest['BackLink'];
81
                    $aActionRequest['cancel_url'] = $sBackLink;
82
                    $aActionRequest['BackLink'] = $sBackLink;
83
                }
84 2099 darkviper
     			include($sModulePath.'save.php');
85 1815 Luisehahne
                $user_id = save_user($admin, $aActionRequest);
86
    			$admin = new admin('Access', 'users_modify');
87 2099 darkviper
     			include($sModulePath.'user_form.php');
88 1815 Luisehahne
                $aActionRequest['user_id'] = $user_id;
89
    			$output = show_usermask($admin,$aActionRequest);
90
				break;
91
			case 'modify': // insert/update user
92
// first check acess to auth users can change his own preferences
93
    			$admin = new admin('Preferences', 'preferences_view',false);
94
    			$user_id = intval($admin->checkIDKEY('user_id', 0, $_SERVER['REQUEST_METHOD']));
95
// Check if user id is a valid number and doesnt equal 1
96
                $aActionRequest['user_id'] = $user_id;
97
    			if($user_id == 0){
98 2065 Luisehahne
    				$admin = new admin('Access', 'users');
99
    				msgQueue::clear();
100 2098 darkviper
        			msgQueue::add($oTrans->MESSAGE_GENERIC_FORGOT_OPTIONS );
101 2065 Luisehahne
                    $aActionRequest['user_id'] = $user_id;
102 2099 darkviper
                    $aActionRequest['cancel_url'] = $oReg->AcpUrl.'access/index.php';
103
					include($sModulePath.'user_list.php');
104 2065 Luisehahne
					$output  = show_userlist($admin, $aActionRequest);
105
    				break;
106 1815 Luisehahne
                }
107 1492 Luisehahne
108 1815 Luisehahne
    			if( ($user_id == $admin->get_user_id() ) )
109
    			{
110
                    $sQueryString = (isset($_SERVER['QUERY_STRING'])&& ($_SERVER['QUERY_STRING']!='')) ? $_SERVER['QUERY_STRING'] :  'tool=uaerat';
111 2099 darkviper
                    $admin->send_header($oReg->AcpUrl.'preferences/index.php?'.$sQueryString);
112 1815 Luisehahne
    			}
113 1492 Luisehahne
114 1815 Luisehahne
    			$admin = new admin('Access', 'users_modify');
115 1492 Luisehahne
116 1815 Luisehahne
    			if( ($user_id < 2 ) )
117
    			{
118
    				// if($admin_header) { $admin->print_header(); }
119 2098 darkviper
    				msgQueue::add($oTrans->MESSAGE_GENERIC_SECURITY_ACCESS );
120 1815 Luisehahne
    			}
121
                $admin_header = false;
122
                if(isset($aActionRequest['BackLink'])) {
123
                    $sBackLink = $aActionRequest['BackLink'];
124
                    $aActionRequest['cancel_url'] = $sBackLink;
125
                    $aActionRequest['BackLink']   = $sBackLink;
126
                } else {
127
                    $sBackLink = (isset($_SERVER['QUERY_STRING'])&& ($_SERVER['QUERY_STRING']!='')) ? $_SERVER['HTTP_REFERER'].'?'.$_SERVER['QUERY_STRING'] :  $_SERVER['HTTP_REFERER'];
128
                    $aActionRequest['cancel_url'] = $sBackLink;
129
                    $aActionRequest['BackLink']   = $sBackLink;
130
                }
131 2099 darkviper
     			include($sModulePath.'user_form.php');
132 1815 Luisehahne
    			$output = show_usermask($admin,$aActionRequest);
133
				break;
134
			default: // show userlist with empty modify mask
135
				$admin = new admin('Access', 'users');
136
				msgQueue::clear();
137
    			$user_id = intval($admin->checkIDKEY('user_id', 0, $_SERVER['REQUEST_METHOD']));
138
    			// Check if user id is a valid number and doesnt equal 1
139
                $aActionRequest['user_id'] = $user_id;
140 2099 darkviper
                $aActionRequest['cancel_url'] = $oReg->AcpUrl.'access/index.php';
141 1815 Luisehahne
				if($user_id > 1) // prevent 'admin' [ID 1] from modify
142
				{
143 2099 darkviper
					include($sModulePath.'user_form.php');
144 1815 Luisehahne
					$output .= show_usermask($admin, $aActionRequest);
145
				} elseif($user_id == 0) { // if invalid UserID is called, fall back to 'show-mode'
146 2099 darkviper
					include($sModulePath.'user_list.php');
147 1815 Luisehahne
					$output  = show_userlist($admin, $aActionRequest);
148
				}
149
		endswitch; // end of switch
150 1823 Luisehahne
151 1815 Luisehahne
		if( ($msg = msgQueue::getSuccess()) != '')
152
		{
153
			$output = $admin->format_message($msg, 'ok').$output;
154
		}
155
		if( ($msg = msgQueue::getError()) != '')
156
		{
157
			$output = $admin->format_message($msg, 'error').$output;
158
		}
159 1823 Luisehahne
160 1815 Luisehahne
		print $output;
161 1823 Luisehahne
        if( isset($aActionRequest['BackLink']) && isset($aActionRequest['save_back']) ) {
162
            $sBackLink = $aActionRequest['BackLink'];
163
echo "<script type=\"text/javascript\">
164
<!--
165
// Get the location object
166
var locationObj = document.location;
167
// Set the value of the location object
168
document.location = '$sBackLink';
169
-->
170
</script>";
171
        }
172 1815 Luisehahne
		$admin->print_footer();
173 1823 Luisehahne
174 2098 darkviper
    } // end of function admin_users_index()
175
/* ************************************************************************************ */
176 1815 Luisehahne
	if(!defined('WB_URL'))
177
	{
178 2098 darkviper
        $config_file = '../../config.php';
179
        if(is_readable($config_file)) {
180 1815 Luisehahne
        	require($config_file);
181 2098 darkviper
        } else {
182
            throw new Exception('unable to read config.php');
183 1815 Luisehahne
        }
184
    }
185 1386 Luisehahne
186 1815 Luisehahne
    $requestMethod = '_'.strtoupper($_SERVER['REQUEST_METHOD']);
187
    $aActionRequest = (isset(${$requestMethod})) ? ${$requestMethod} : null;
188 1804 Luisehahne
189 1815 Luisehahne
	admin_users_index($aActionRequest);
190
	exit;
191 2076 darkviper
// end of file