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 1844 2012-12-28 06:03:26Z Luisehahne $
13
 * @filesource		$HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/admin/users/index.php $
14
 * @lastmodified    $Date: 2012-12-28 07:03:26 +0100 (Fri, 28 Dec 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
			case 'delete_outdated': // delete Users awaiting activation
55
    			$admin = new admin('Access', 'users_delete',false);
56
				include($sAdminPath.'/delete.php');
57
    			delete_user($admin,$aActionRequest);
58
                $aActionRequest['cancel_url'] = ADMIN_URL.'/access/index.php';
59
				$admin = new admin('Access', 'users');
60
				include($sAdminPath.'/user_list.php');
61
				$output .= show_userlist($admin, $aActionRequest);
62
				break;
63
			case 'add': // insert/update user
64
                $admin = new admin('Access', 'users_add',false);
65
				include($sAdminPath.'/add.php');
66
    			add_user($admin,$aActionRequest);
67
                $aActionRequest['cancel_url'] = ADMIN_URL.'/access/index.php';
68
				$admin = new admin('Access', 'users');
69
				include($sAdminPath.'/user_list.php');
70
				$output .= show_userlist($admin, $aActionRequest);
71
				break;
72
			case 'save': // insert/update user
73
    			$admin = new admin('Access', 'users_modify',false);
74
// hold the cancel_url if request comes outside from users
75
                if(isset($aActionRequest['BackLink'])) {
76
                    $sBackLink = $aActionRequest['BackLink'];
77
                    $aActionRequest['cancel_url'] = $sBackLink;
78
                    $aActionRequest['BackLink'] = $sBackLink;
79
                }
80
     			include($sAdminPath.'/save.php');
81
                $user_id = save_user($admin, $aActionRequest);
82
    			$admin = new admin('Access', 'users_modify');
83
     			include($sAdminPath.'/user_form.php');
84
                $aActionRequest['user_id'] = $user_id;
85
    			$output = show_usermask($admin,$aActionRequest);
86
				break;
87
			case 'modify': // insert/update user
88
// first check acess to auth users can change his own preferences
89
    			$admin = new admin('Preferences', 'preferences_view',false);
90
    			$user_id = intval($admin->checkIDKEY('user_id', 0, $_SERVER['REQUEST_METHOD']));
91
// Check if user id is a valid number and doesnt equal 1
92
                $aActionRequest['user_id'] = $user_id;
93
    			if($user_id == 0){
94
        			msgQueue::add($MESSAGE['GENERIC_FORGOT_OPTIONS'] );
95
                }
96

    
97
    			if( ($user_id == $admin->get_user_id() ) )
98
    			{
99
                    $sQueryString = (isset($_SERVER['QUERY_STRING'])&& ($_SERVER['QUERY_STRING']!='')) ? $_SERVER['QUERY_STRING'] :  'tool=uaerat';
100
                    $admin->send_header(ADMIN_URL.'/preferences/index.php?'.$sQueryString);
101
    			}
102

    
103
    			$admin = new admin('Access', 'users_modify');
104

    
105
    			if( ($user_id < 2 ) )
106
    			{
107
    				// if($admin_header) { $admin->print_header(); }
108
    				msgQueue::add($MESSAGE['GENERIC_SECURITY_ACCESS'] );
109
    			}
110
                $admin_header = false;
111
                if(isset($aActionRequest['BackLink'])) {
112
                    $sBackLink = $aActionRequest['BackLink'];
113
                    $aActionRequest['cancel_url'] = $sBackLink;
114
                    $aActionRequest['BackLink']   = $sBackLink;
115
                } else {
116
                    $sBackLink = (isset($_SERVER['QUERY_STRING'])&& ($_SERVER['QUERY_STRING']!='')) ? $_SERVER['HTTP_REFERER'].'?'.$_SERVER['QUERY_STRING'] :  $_SERVER['HTTP_REFERER'];
117
                    $aActionRequest['cancel_url'] = $sBackLink;
118
                    $aActionRequest['BackLink']   = $sBackLink;
119
                }
120
     			include($sAdminPath.'/user_form.php');
121
    			$output = show_usermask($admin,$aActionRequest);
122
				break;
123
			default: // show userlist with empty modify mask
124
				$admin = new admin('Access', 'users');
125
				msgQueue::clear();
126
    			$user_id = intval($admin->checkIDKEY('user_id', 0, $_SERVER['REQUEST_METHOD']));
127
    			// Check if user id is a valid number and doesnt equal 1
128
                $aActionRequest['user_id'] = $user_id;
129
                $aActionRequest['cancel_url'] = ADMIN_URL.'/access/index.php';
130

    
131
				if($user_id > 1) // prevent 'admin' [ID 1] from modify
132
				{
133
					include($sAdminPath.'/user_form.php');
134
					$output .= show_usermask($admin, $aActionRequest);
135
				} elseif($user_id == 0) { // if invalid UserID is called, fall back to 'show-mode'
136
					include($sAdminPath.'/user_list.php');
137
					$output  = show_userlist($admin, $aActionRequest);
138
				}
139
		endswitch; // end of switch
140

    
141
		if( ($msg = msgQueue::getSuccess()) != '')
142
		{
143
			$output = $admin->format_message($msg, 'ok').$output;
144
		}
145
		if( ($msg = msgQueue::getError()) != '')
146
		{
147
			$output = $admin->format_message($msg, 'error').$output;
148
		}
149

    
150
		print $output;
151
        if( isset($aActionRequest['BackLink']) && isset($aActionRequest['save_back']) ) {
152
            $sBackLink = $aActionRequest['BackLink'];
153
echo "<script type=\"text/javascript\">
154
<!--
155
// Get the location object
156
var locationObj = document.location;
157
// Set the value of the location object
158
document.location = '$sBackLink';
159
-->
160
</script>";
161
        }
162
		$admin->print_footer();
163

    
164
    }
165

    
166
	if(!defined('WB_URL'))
167
	{
168
        $config_file = realpath('../../config.php');
169
        if(file_exists($config_file) && !defined('WB_URL'))
170
        {
171
        	require($config_file);
172
        }
173
    }
174
    if(!class_exists('admin', false)){ include(WB_PATH.'/framework/class.admin.php'); }
175

    
176
    $requestMethod = '_'.strtoupper($_SERVER['REQUEST_METHOD']);
177
    $aActionRequest = (isset(${$requestMethod})) ? ${$requestMethod} : null;
178

    
179
	admin_users_index($aActionRequest);
180
	exit;
181
// end of file
(4-4/7)