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 1823 2012-11-20 17:36:55Z Luisehahne $
13
 * @filesource		$HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/admin/users/index.php $
14
 * @lastmodified    $Date: 2012-11-20 18:36:55 +0100 (Tue, 20 Nov 2012) $
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
		global $MESSAGE;
37
		$database = WbDatabase::getInstance();
38

    
39
        $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
        $action = (isset($aActionRequest['save_back']) ? 'save'   : $action );
48
        $action = (isset($aActionRequest['modify']) ? 'modify' : $action );
49
        $action = (isset($aActionRequest['delete']) ? 'delete' : $action );
50
        $action = (isset($aActionRequest['delete_outdated']) ? 'delete_outdated' : $action );
51

    
52
		switch($action) :
53
			case 'delete': // delete the user
54
    			$admin = new admin('Access', 'users_delete',false);
55

    
56
				include($sAdminPath.'/delete.php');
57
    			$output = delete_user($admin,$aActionRequest);
58

    
59
        		if( ($msg = msgQueue::getError()) != '')
60
        		{
61
        		}
62

    
63
                $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

    
102
    			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

    
108
    			$admin = new admin('Access', 'users_modify');
109

    
110
    			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

    
136
				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

    
146
		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

    
155
		print $output;
156
        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
		$admin->print_footer();
168

    
169
    }
170

    
171
	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

    
181
    $requestMethod = '_'.strtoupper($_SERVER['REQUEST_METHOD']);
182
    $aActionRequest = (isset(${$requestMethod})) ? ${$requestMethod} : null;
183

    
184
	admin_users_index($aActionRequest);
185
	exit;
186
// end of file
(4-4/7)