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 2098 darkviper
		$oDb = WbDatabase::getInstance();
37
		$oTrans = Translate::getInstance();
38
		$oTrans->enableAddon('admin\\users');
39 1804 Luisehahne
40 1815 Luisehahne
        $sAdminPath = dirname(str_replace('\\', '/', __FILE__));
41
        $sAdminName = basename($sAdminPath);
42
        $output = '';
43
        $aActionRequest['requestMethod'] = '_'.strtoupper($_SERVER['REQUEST_METHOD']);
44
        $action = 'show';
45
        // Set parameter 'action' as alternative to javascript mechanism
46
        $action = (isset($aActionRequest['add'])    ? 'add'    : $action );
47
        $action = (isset($aActionRequest['save'])   ? 'save'   : $action );
48 1823 Luisehahne
        $action = (isset($aActionRequest['save_back']) ? 'save'   : $action );
49 1815 Luisehahne
        $action = (isset($aActionRequest['modify']) ? 'modify' : $action );
50
        $action = (isset($aActionRequest['delete']) ? 'delete' : $action );
51
        $action = (isset($aActionRequest['delete_outdated']) ? 'delete_outdated' : $action );
52 2076 darkviper
        $action = (isset($aActionRequest['enable_outdated']) ? 'enable_outdated' : $action );
53 1386 Luisehahne
54 1815 Luisehahne
		switch($action) :
55
			case 'delete': // delete the user
56 1842 Luisehahne
			case 'delete_outdated': // delete Users awaiting activation
57 2076 darkviper
			case 'enable_outdated': // enable Users awaiting activation
58 1815 Luisehahne
    			$admin = new admin('Access', 'users_delete',false);
59
				include($sAdminPath.'/delete.php');
60 1844 Luisehahne
    			delete_user($admin,$aActionRequest);
61 1815 Luisehahne
                $aActionRequest['cancel_url'] = ADMIN_URL.'/access/index.php';
62
				$admin = new admin('Access', 'users');
63
				include($sAdminPath.'/user_list.php');
64
				$output .= show_userlist($admin, $aActionRequest);
65
				break;
66
			case 'add': // insert/update user
67
                $admin = new admin('Access', 'users_add',false);
68
				include($sAdminPath.'/add.php');
69 1844 Luisehahne
    			add_user($admin,$aActionRequest);
70 1815 Luisehahne
                $aActionRequest['cancel_url'] = ADMIN_URL.'/access/index.php';
71
				$admin = new admin('Access', 'users');
72
				include($sAdminPath.'/user_list.php');
73
				$output .= show_userlist($admin, $aActionRequest);
74
				break;
75
			case 'save': // insert/update user
76
    			$admin = new admin('Access', 'users_modify',false);
77
// hold the cancel_url if request comes outside from users
78
                if(isset($aActionRequest['BackLink'])) {
79
                    $sBackLink = $aActionRequest['BackLink'];
80
                    $aActionRequest['cancel_url'] = $sBackLink;
81
                    $aActionRequest['BackLink'] = $sBackLink;
82
                }
83
     			include($sAdminPath.'/save.php');
84
                $user_id = save_user($admin, $aActionRequest);
85
    			$admin = new admin('Access', 'users_modify');
86
     			include($sAdminPath.'/user_form.php');
87
                $aActionRequest['user_id'] = $user_id;
88
    			$output = show_usermask($admin,$aActionRequest);
89
				break;
90
			case 'modify': // insert/update user
91
// first check acess to auth users can change his own preferences
92
    			$admin = new admin('Preferences', 'preferences_view',false);
93
    			$user_id = intval($admin->checkIDKEY('user_id', 0, $_SERVER['REQUEST_METHOD']));
94
// Check if user id is a valid number and doesnt equal 1
95
                $aActionRequest['user_id'] = $user_id;
96
    			if($user_id == 0){
97 2065 Luisehahne
    				$admin = new admin('Access', 'users');
98
    				msgQueue::clear();
99 2098 darkviper
        			msgQueue::add($oTrans->MESSAGE_GENERIC_FORGOT_OPTIONS );
100 2065 Luisehahne
                    $aActionRequest['user_id'] = $user_id;
101
                    $aActionRequest['cancel_url'] = ADMIN_URL.'/access/index.php';
102
					include($sAdminPath.'/user_list.php');
103
					$output  = show_userlist($admin, $aActionRequest);
104
    				break;
105 1815 Luisehahne
                }
106 1492 Luisehahne
107 1815 Luisehahne
    			if( ($user_id == $admin->get_user_id() ) )
108
    			{
109
                    $sQueryString = (isset($_SERVER['QUERY_STRING'])&& ($_SERVER['QUERY_STRING']!='')) ? $_SERVER['QUERY_STRING'] :  'tool=uaerat';
110
                    $admin->send_header(ADMIN_URL.'/preferences/index.php?'.$sQueryString);
111
    			}
112 1492 Luisehahne
113 1815 Luisehahne
    			$admin = new admin('Access', 'users_modify');
114 1492 Luisehahne
115 1815 Luisehahne
    			if( ($user_id < 2 ) )
116
    			{
117
    				// if($admin_header) { $admin->print_header(); }
118 2098 darkviper
    				msgQueue::add($oTrans->MESSAGE_GENERIC_SECURITY_ACCESS );
119 1815 Luisehahne
    			}
120
                $admin_header = false;
121
                if(isset($aActionRequest['BackLink'])) {
122
                    $sBackLink = $aActionRequest['BackLink'];
123
                    $aActionRequest['cancel_url'] = $sBackLink;
124
                    $aActionRequest['BackLink']   = $sBackLink;
125
                } else {
126
                    $sBackLink = (isset($_SERVER['QUERY_STRING'])&& ($_SERVER['QUERY_STRING']!='')) ? $_SERVER['HTTP_REFERER'].'?'.$_SERVER['QUERY_STRING'] :  $_SERVER['HTTP_REFERER'];
127
                    $aActionRequest['cancel_url'] = $sBackLink;
128
                    $aActionRequest['BackLink']   = $sBackLink;
129
                }
130
     			include($sAdminPath.'/user_form.php');
131
    			$output = show_usermask($admin,$aActionRequest);
132
				break;
133
			default: // show userlist with empty modify mask
134
				$admin = new admin('Access', 'users');
135
				msgQueue::clear();
136
    			$user_id = intval($admin->checkIDKEY('user_id', 0, $_SERVER['REQUEST_METHOD']));
137
    			// Check if user id is a valid number and doesnt equal 1
138
                $aActionRequest['user_id'] = $user_id;
139
                $aActionRequest['cancel_url'] = ADMIN_URL.'/access/index.php';
140
				if($user_id > 1) // prevent 'admin' [ID 1] from modify
141
				{
142
					include($sAdminPath.'/user_form.php');
143
					$output .= show_usermask($admin, $aActionRequest);
144
				} elseif($user_id == 0) { // if invalid UserID is called, fall back to 'show-mode'
145
					include($sAdminPath.'/user_list.php');
146
					$output  = show_userlist($admin, $aActionRequest);
147
				}
148
		endswitch; // end of switch
149 1823 Luisehahne
150 1815 Luisehahne
		if( ($msg = msgQueue::getSuccess()) != '')
151
		{
152
			$output = $admin->format_message($msg, 'ok').$output;
153
		}
154
		if( ($msg = msgQueue::getError()) != '')
155
		{
156
			$output = $admin->format_message($msg, 'error').$output;
157
		}
158 1823 Luisehahne
159 1815 Luisehahne
		print $output;
160 1823 Luisehahne
        if( isset($aActionRequest['BackLink']) && isset($aActionRequest['save_back']) ) {
161
            $sBackLink = $aActionRequest['BackLink'];
162
echo "<script type=\"text/javascript\">
163
<!--
164
// Get the location object
165
var locationObj = document.location;
166
// Set the value of the location object
167
document.location = '$sBackLink';
168
-->
169
</script>";
170
        }
171 1815 Luisehahne
		$admin->print_footer();
172 1823 Luisehahne
173 2098 darkviper
    } // end of function admin_users_index()
174
/* ************************************************************************************ */
175 1815 Luisehahne
	if(!defined('WB_URL'))
176
	{
177 2098 darkviper
        $config_file = '../../config.php';
178
        if(is_readable($config_file)) {
179 1815 Luisehahne
        	require($config_file);
180 2098 darkviper
        } else {
181
            throw new Exception('unable to read config.php');
182 1815 Luisehahne
        }
183
    }
184 1386 Luisehahne
185 1815 Luisehahne
    $requestMethod = '_'.strtoupper($_SERVER['REQUEST_METHOD']);
186
    $aActionRequest = (isset(${$requestMethod})) ? ${$requestMethod} : null;
187 1804 Luisehahne
188 1815 Luisehahne
	admin_users_index($aActionRequest);
189
	exit;
190 2076 darkviper
// end of file