Project

General

Profile

1 1815 Luisehahne
<?php
2
3
/**
4
 *
5
 * @category        admin
6
 * @package         pages
7
 * @author          Ryan Djurovich (2004-2009), WebsiteBaker Project
8
 * @copyright       2009-2012, WebsiteBaker Org. e.V.
9
 * @link			http://www.websitebaker2.org/
10
 * @license         http://www.gnu.org/licenses/gpl.html
11
 * @platform        WebsiteBaker 2.8.x
12
 * @requirements    PHP 5.2.2 and higher
13
 * @version         $Id$
14
 * @filesource		$HeadURL$
15
 * @lastmodified    $Date$
16
 *
17
 */
18
19
/* -------------------------------------------------------- */
20
// Must include code to stop this file being accessed directly
21
if(!defined('WB_URL')) {
22
	require_once(dirname(dirname(dirname(__FILE__))).'/framework/globalExceptionHandler.php');
23
	throw new IllegalFileException();
24
}
25
/* -------------------------------------------------------- */
26 2098 darkviper
function delete_user($admin, $aActionRequest)
27 1815 Luisehahne
{
28 2098 darkviper
	$oDb = WbDatabase::getInstance();
29
	$oTrans = Translate::getInstance();
30 2100 darkviper
    $oTrans->enableAddon('admin\\users');
31 1815 Luisehahne
    $aUserID = array();
32
    $bRetVal = false;
33
34 2065 Luisehahne
    $action = 'default';
35
    $action = (isset($aActionRequest['delete']) ? 'delete' : $action );
36 2076 darkviper
    $action = (isset($aActionRequest['delete_outdated']) ? 'delete_outdated'   : $action );
37
    $action = (isset($aActionRequest['enable_outdated']) ? 'enable_outdated' : $action );
38 2065 Luisehahne
39
	switch($action) :
40
		case 'delete': // delete the user
41
    	    if(isset($aActionRequest['user_id'])) {
42
    			if(!is_array($aActionRequest['user_id'])) {
43
    		        $aUserID[] = $aActionRequest['user_id'];
44
    		    } else {
45
    		        $aUserID = $aActionRequest['user_id'];
46
    		    }
47 2076 darkviper
    	    }
48 2065 Luisehahne
    		break;
49
		case 'delete_outdated': // delete Users awaiting activation
50
            if(isset($aActionRequest['activation_user_id'])) {
51
        		if(!is_array($aActionRequest['activation_user_id'])) {
52
        	        $aUserID[] = $aActionRequest['activation_user_id'];
53
        	    } else {
54
        	        $aUserID = $aActionRequest['activation_user_id'];
55
        	    }
56
            }
57
    		break;
58 2076 darkviper
		case 'enable_outdated': // enable Users awaiting activation
59
            if(isset($aActionRequest['activation_user_id'])) {
60
        		if(!is_array($aActionRequest['activation_user_id'])) {
61
        	        $aUserID[] = $aActionRequest['activation_user_id'];
62
        	    } else {
63
        	        $aUserID = $aActionRequest['activation_user_id'];
64
        	    }
65
            }
66
    		break;
67 2065 Luisehahne
		default: // show userlist with empty modify mask
68
	endswitch; // end of switch
69 2076 darkviper
70 2065 Luisehahne
//    if(isset($aActionRequest['activation_user_id'])) {
71
//		if(!is_array($aActionRequest['activation_user_id'])) {
72 2076 darkviper
//
73 2065 Luisehahne
//	        $aUserID[] = $aActionRequest['activation_user_id'];
74
//	    } else {
75
//	        $aUserID = $aActionRequest['activation_user_id'];
76
//	    }
77
//    } else {
78
//	    if(isset($aActionRequest['user_id'])) {
79
//			if(!is_array($aActionRequest['user_id'])) {
80 2076 darkviper
//
81 2065 Luisehahne
//		        $aUserID[] = $aActionRequest['user_id'];
82
//		    } else {
83
//		        $aUserID = $aActionRequest['user_id'];
84
//		    }
85 2076 darkviper
//	    }
86
//    }
87 2065 Luisehahne
88 2076 darkviper
89 1815 Luisehahne
    foreach ( $aUserID AS $key => $value)
90
    {
91
        switch ($_SERVER['REQUEST_METHOD']) :
92
			case 'GET': // insert/update user
93
                $_GET['user_id'] =$aUserID[$key];
94
				break;
95
			default: // show userlist with empty modify mask
96
                $_POST['user_id'] =$aUserID[$key];
97
		endswitch; // end of switch
98
		$user_id = intval($admin->checkIDKEY('user_id', 0, $_SERVER['REQUEST_METHOD']));
99
100
		// Check if user id is a valid number and doesnt equal 1
101
		if($user_id == 0){
102 2098 darkviper
			msgQueue::add($oTrans->MESSAGE_GENERIC_FORGOT_OPTIONS );
103 1815 Luisehahne
            return $bRetVal;
104
        }
105
106
		if( ($user_id < 2 ) )
107
		{
108
			// if($admin_header) { $admin->print_header(); }
109 2098 darkviper
			msgQueue::add($oTrans->MESSAGE_GENERIC_SECURITY_ACCESS );
110 1815 Luisehahne
            return $bRetVal;
111
		}
112
113
		if( ($msg = msgQueue::getError()) == '')
114
		{
115 2076 darkviper
116
    	switch($action) :
117
    		case 'enable_outdated': // enable Users awaiting activation
118 2098 darkviper
    			$sql  = 'SELECT `display_name` FROM `'.$oDb->TablePrefix.'users` '.
119 2076 darkviper
                        'WHERE `user_id` = '.$user_id;
120 2098 darkviper
                if( ($sDisplayUser = $oDb->getOne($sql)) != null ) {
121
            		$sql = 'UPDATE `'.$oDb->TablePrefix.'users` '
122 2076 darkviper
            		     . 'SET `active`=1, '
123
            		     .     '`confirm_code`=\'\', '
124
            		     .     '`confirm_timeout`=0 '
125
            		     . 'WHERE `user_id`='.$user_id;
126 2098 darkviper
            		if($oDb->doQuery($sql)) {
127
                        msgQueue::add($oTrans->MESSAGE_USERS_ADDED.' ('.$sDisplayUser.')', true);
128 2076 darkviper
                        $bRetVal = true;
129
                    } else {
130 2098 darkviper
                        msgQueue::add($oTrans->TEXT_ENABLE.$oTrans->MESSAGE_GENERIC_NOT_COMPARE.' ('.$sDisplayUser.')');
131 1815 Luisehahne
                    }
132 2076 darkviper
                }
133
        		break;
134
    		default: // show userlist with empty modify mask
135 2098 darkviper
    			$sql  = 'SELECT `active` FROM `'.$oDb->TablePrefix.'users` '.
136 2076 darkviper
                        'WHERE `user_id` = '.$user_id;
137 2098 darkviper
                if( ($iDeleteUser = $oDb->getOne($sql)) != null ) {
138 2076 darkviper
                    if($iDeleteUser) {
139
        				// Deactivate the user
140 2098 darkviper
            			$sql  = 'UPDATE `'.$oDb->TablePrefix.'users` SET '.
141 2076 darkviper
                                '`active` = 0 '.
142
                                'WHERE `user_id` = '.$user_id;
143 2098 darkviper
                        if( $oDb->doQuery($sql) ) {
144
                            msgQueue::add($oTrans->TEXT_USERS_MARKED_DELETED, true);
145 2076 darkviper
                        }
146
                    } else {
147 2065 Luisehahne
148
149 2098 darkviper
            			$sql  = 'DELETE FROM `'.$oDb->TablePrefix.'users` '.
150 2076 darkviper
                                'WHERE `user_id` = '.$user_id;
151 2098 darkviper
                        if( $oDb->doQuery($sql) ) {
152
                            msgQueue::add($oTrans->MESSAGE_USERS_DELETED, true);
153 2076 darkviper
                        }
154 1815 Luisehahne
                    }
155 2076 darkviper
                    $bRetVal = true;
156 1815 Luisehahne
                }
157 2098 darkviper
                if($oDb->isError()) {
158
                    msgQueue::add( implode('<br />',explode(';',$oDb->getError())) );
159 2076 darkviper
                    $bRetVal = false;
160
               }
161
    	endswitch; // end of switch
162
		} // getError
163
    } // foreach users
164 1815 Luisehahne
    if(isset($aActionRequest['clearmsg'])) { msgQueue::clear();  }
165 1844 Luisehahne
    return $bRetVal;
166 1815 Luisehahne
}
167
168
if(!isset($aActionRequest)) {
169
    $requestMethod = '_'.strtoupper($_SERVER['REQUEST_METHOD']);
170
    $aActionRequest = (isset(${$requestMethod})) ? ${$requestMethod} : null;
171
    $aActionRequest['clearmsg'] = true;
172 2076 darkviper
}