Project

General

Profile

1
<?php
2
/**
3
 *
4
 * @category        admin
5
 * @package         users
6
 * @author          Ryan Djurovich, WebsiteBaker Project
7
 * @copyright       2009-2012, WebsiteBaker Org. e.V.
8
 * @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: index.php 2099 2014-02-11 11:46:08Z darkviper $
13
 * @filesource		$HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/admin/users/index.php $
14
 * @lastmodified    $Date: 2014-02-11 12:46:08 +0100 (Tue, 11 Feb 2014) $
15
 *
16
 */
17

    
18
    /**
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
        $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
    }
33

    
34
	function admin_users_index($aActionRequest)
35
	{
36
        $oReg = WbAdaptor::getInstance();
37
		$oDb = WbDatabase::getInstance();
38
		$oTrans = Translate::getInstance();
39
		$oTrans->enableAddon('admin\\users');
40

    
41
        $sModulePath = rtrim(dirname(str_replace('\\', '/', __FILE__)), '/').'/';
42
        $sAdminName = basename($sModulePath);
43
        $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
        $action = (isset($aActionRequest['save_back']) ? 'save'   : $action );
50
        $action = (isset($aActionRequest['modify']) ? 'modify' : $action );
51
        $action = (isset($aActionRequest['delete']) ? 'delete' : $action );
52
        $action = (isset($aActionRequest['delete_outdated']) ? 'delete_outdated' : $action );
53
        $action = (isset($aActionRequest['enable_outdated']) ? 'enable_outdated' : $action );
54

    
55
		switch($action) :
56
			case 'delete': // delete the user
57
			case 'delete_outdated': // delete Users awaiting activation
58
			case 'enable_outdated': // enable Users awaiting activation
59
    			$admin = new admin('Access', 'users_delete',false);
60
				include($sModulePath.'delete.php');
61
    			delete_user($admin,$aActionRequest);
62
                $aActionRequest['cancel_url'] = $oReg->AcpUrl.'access/index.php';
63
				$admin = new admin('Access', 'users');
64
				include($sModulePath.'user_list.php');
65
				$output .= show_userlist($admin, $aActionRequest);
66
				break;
67
			case 'add': // insert/update user
68
                $admin = new admin('Access', 'users_add',false);
69
				include($sModulePath.'add.php');
70
    			add_user($admin,$aActionRequest);
71
                $aActionRequest['cancel_url'] = $oReg->AcpUrl.'access/index.php';
72
				$admin = new admin('Access', 'users');
73
				include($sModulePath.'user_list.php');
74
				$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
     			include($sModulePath.'save.php');
85
                $user_id = save_user($admin, $aActionRequest);
86
    			$admin = new admin('Access', 'users_modify');
87
     			include($sModulePath.'user_form.php');
88
                $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
    				$admin = new admin('Access', 'users');
99
    				msgQueue::clear();
100
        			msgQueue::add($oTrans->MESSAGE_GENERIC_FORGOT_OPTIONS );
101
                    $aActionRequest['user_id'] = $user_id;
102
                    $aActionRequest['cancel_url'] = $oReg->AcpUrl.'access/index.php';
103
					include($sModulePath.'user_list.php');
104
					$output  = show_userlist($admin, $aActionRequest);
105
    				break;
106
                }
107

    
108
    			if( ($user_id == $admin->get_user_id() ) )
109
    			{
110
                    $sQueryString = (isset($_SERVER['QUERY_STRING'])&& ($_SERVER['QUERY_STRING']!='')) ? $_SERVER['QUERY_STRING'] :  'tool=uaerat';
111
                    $admin->send_header($oReg->AcpUrl.'preferences/index.php?'.$sQueryString);
112
    			}
113

    
114
    			$admin = new admin('Access', 'users_modify');
115

    
116
    			if( ($user_id < 2 ) )
117
    			{
118
    				// if($admin_header) { $admin->print_header(); }
119
    				msgQueue::add($oTrans->MESSAGE_GENERIC_SECURITY_ACCESS );
120
    			}
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
     			include($sModulePath.'user_form.php');
132
    			$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
                $aActionRequest['cancel_url'] = $oReg->AcpUrl.'access/index.php';
141
				if($user_id > 1) // prevent 'admin' [ID 1] from modify
142
				{
143
					include($sModulePath.'user_form.php');
144
					$output .= show_usermask($admin, $aActionRequest);
145
				} elseif($user_id == 0) { // if invalid UserID is called, fall back to 'show-mode'
146
					include($sModulePath.'user_list.php');
147
					$output  = show_userlist($admin, $aActionRequest);
148
				}
149
		endswitch; // end of switch
150

    
151
		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

    
160
		print $output;
161
        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
		$admin->print_footer();
173

    
174
    } // end of function admin_users_index()
175
/* ************************************************************************************ */
176
	if(!defined('WB_URL'))
177
	{
178
        $config_file = '../../config.php';
179
        if(is_readable($config_file)) {
180
        	require($config_file);
181
        } else {
182
            throw new Exception('unable to read config.php');
183
        }
184
    }
185

    
186
    $requestMethod = '_'.strtoupper($_SERVER['REQUEST_METHOD']);
187
    $aActionRequest = (isset(${$requestMethod})) ? ${$requestMethod} : null;
188

    
189
	admin_users_index($aActionRequest);
190
	exit;
191
// end of file
(4-4/7)