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 1815 2012-11-11 00:19:38Z Luisehahne $
13
 * @filesource		$HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/admin/users/index.php $
14
 * @lastmodified    $Date: 2012-11-11 01:19:38 +0100 (Sun, 11 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['modify']) ? 'modify' : $action );
48
        $action = (isset($aActionRequest['delete']) ? 'delete' : $action );
49
        $action = (isset($aActionRequest['delete_outdated']) ? 'delete_outdated' : $action );
50

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

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

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

    
62
                $aActionRequest['cancel_url'] = ADMIN_URL.'/access/index.php';
63
				$admin = new admin('Access', 'users');
64
				include($sAdminPath.'/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($sAdminPath.'/add.php');
70
    			$output = add_user($admin,$aActionRequest);
71
                $aActionRequest['cancel_url'] = ADMIN_URL.'/access/index.php';
72
				$admin = new admin('Access', 'users');
73
				include($sAdminPath.'/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($sAdminPath.'/save.php');
85
                $user_id = save_user($admin, $aActionRequest);
86
    			$admin = new admin('Access', 'users_modify');
87
     			include($sAdminPath.'/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
        			msgQueue::add($MESSAGE['GENERIC_FORGOT_OPTIONS'] );
99
                }
100

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

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

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

    
135
				if($user_id > 1) // prevent 'admin' [ID 1] from modify
136
				{
137
					include($sAdminPath.'/user_form.php');
138
					$output .= show_usermask($admin, $aActionRequest);
139
				} elseif($user_id == 0) { // if invalid UserID is called, fall back to 'show-mode'
140
					include($sAdminPath.'/user_list.php');
141
					$output  = show_userlist($admin, $aActionRequest);
142
				}
143
		endswitch; // end of switch
144
		if( ($msg = msgQueue::getSuccess()) != '')
145
		{
146
			$output = $admin->format_message($msg, 'ok').$output;
147
		}
148
		if( ($msg = msgQueue::getError()) != '')
149
		{
150
			$output = $admin->format_message($msg, 'error').$output;
151
		}
152
		print $output;
153
		$admin->print_footer();
154
    }
155

    
156
	if(!defined('WB_URL'))
157
	{
158
        $config_file = realpath('../../config.php');
159
        if(file_exists($config_file) && !defined('WB_URL'))
160
        {
161
        	require($config_file);
162
        }
163
    }
164
    if(!class_exists('admin', false)){ include(WB_PATH.'/framework/class.admin.php'); }
165

    
166
    $requestMethod = '_'.strtoupper($_SERVER['REQUEST_METHOD']);
167
    $aActionRequest = (isset(${$requestMethod})) ? ${$requestMethod} : null;
168

    
169
	admin_users_index($aActionRequest);
170
	exit;
171
// end of file
(4-4/7)