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