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 1842 Luisehahne
			case 'delete_outdated': // delete Users awaiting activation
55 1815 Luisehahne
    			$admin = new admin('Access', 'users_delete',false);
56
				include($sAdminPath.'/delete.php');
57
    			$output = delete_user($admin,$aActionRequest);
58 1529 Luisehahne
59 1815 Luisehahne
        		if( ($msg = msgQueue::getError()) != '')
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 1492 Luisehahne
101 1815 Luisehahne
    			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 1492 Luisehahne
107 1815 Luisehahne
    			$admin = new admin('Access', 'users_modify');
108 1492 Luisehahne
109 1815 Luisehahne
    			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 1492 Luisehahne
135 1815 Luisehahne
				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 1823 Luisehahne
145 1815 Luisehahne
		if( ($msg = msgQueue::getSuccess()) != '')
146
		{
147
			$output = $admin->format_message($msg, 'ok').$output;
148
		}
149
		if( ($msg = msgQueue::getError()) != '')
150
		{
151
			$output = $admin->format_message($msg, 'error').$output;
152
		}
153 1823 Luisehahne
154 1815 Luisehahne
		print $output;
155 1823 Luisehahne
        if( isset($aActionRequest['BackLink']) && isset($aActionRequest['save_back']) ) {
156
            $sBackLink = $aActionRequest['BackLink'];
157
echo "<script type=\"text/javascript\">
158
<!--
159
// Get the location object
160
var locationObj = document.location;
161
// Set the value of the location object
162
document.location = '$sBackLink';
163
-->
164
</script>";
165
        }
166 1815 Luisehahne
		$admin->print_footer();
167 1823 Luisehahne
168 1815 Luisehahne
    }
169 1386 Luisehahne
170 1815 Luisehahne
	if(!defined('WB_URL'))
171
	{
172
        $config_file = realpath('../../config.php');
173
        if(file_exists($config_file) && !defined('WB_URL'))
174
        {
175
        	require($config_file);
176
        }
177
    }
178
    if(!class_exists('admin', false)){ include(WB_PATH.'/framework/class.admin.php'); }
179 1386 Luisehahne
180 1815 Luisehahne
    $requestMethod = '_'.strtoupper($_SERVER['REQUEST_METHOD']);
181
    $aActionRequest = (isset(${$requestMethod})) ? ${$requestMethod} : null;
182 1804 Luisehahne
183 1815 Luisehahne
	admin_users_index($aActionRequest);
184
	exit;
185
// end of file