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
function delete_user($admin, &$aActionRequest)
27
{
28
	$database = WbDatabase::getInstance();
29 2065 Luisehahne
	$mLang = Translate::getInstance();
30 1815 Luisehahne
    $aUserID = array();
31
    $bRetVal = false;
32
33 2065 Luisehahne
    $action = 'default';
34
    $action = (isset($aActionRequest['delete']) ? 'delete' : $action );
35 2076 darkviper
    $action = (isset($aActionRequest['delete_outdated']) ? 'delete_outdated'   : $action );
36
    $action = (isset($aActionRequest['enable_outdated']) ? 'enable_outdated' : $action );
37 2065 Luisehahne
38
	switch($action) :
39
		case 'delete': // delete the user
40
    	    if(isset($aActionRequest['user_id'])) {
41
    			if(!is_array($aActionRequest['user_id'])) {
42
    		        $aUserID[] = $aActionRequest['user_id'];
43
    		    } else {
44
    		        $aUserID = $aActionRequest['user_id'];
45
    		    }
46 2076 darkviper
    	    }
47 2065 Luisehahne
    		break;
48
		case 'delete_outdated': // delete Users awaiting activation
49
            if(isset($aActionRequest['activation_user_id'])) {
50
        		if(!is_array($aActionRequest['activation_user_id'])) {
51
        	        $aUserID[] = $aActionRequest['activation_user_id'];
52
        	    } else {
53
        	        $aUserID = $aActionRequest['activation_user_id'];
54
        	    }
55
            }
56
    		break;
57 2076 darkviper
		case 'enable_outdated': // enable Users awaiting activation
58
            if(isset($aActionRequest['activation_user_id'])) {
59
        		if(!is_array($aActionRequest['activation_user_id'])) {
60
        	        $aUserID[] = $aActionRequest['activation_user_id'];
61
        	    } else {
62
        	        $aUserID = $aActionRequest['activation_user_id'];
63
        	    }
64
            }
65
    		break;
66 2065 Luisehahne
		default: // show userlist with empty modify mask
67
	endswitch; // end of switch
68 2076 darkviper
69 2065 Luisehahne
//    if(isset($aActionRequest['activation_user_id'])) {
70
//		if(!is_array($aActionRequest['activation_user_id'])) {
71 2076 darkviper
//
72 2065 Luisehahne
//	        $aUserID[] = $aActionRequest['activation_user_id'];
73
//	    } else {
74
//	        $aUserID = $aActionRequest['activation_user_id'];
75
//	    }
76
//    } else {
77
//	    if(isset($aActionRequest['user_id'])) {
78
//			if(!is_array($aActionRequest['user_id'])) {
79 2076 darkviper
//
80 2065 Luisehahne
//		        $aUserID[] = $aActionRequest['user_id'];
81
//		    } else {
82
//		        $aUserID = $aActionRequest['user_id'];
83
//		    }
84 2076 darkviper
//	    }
85
//    }
86 2065 Luisehahne
87 2076 darkviper
88 1815 Luisehahne
    foreach ( $aUserID AS $key => $value)
89
    {
90
        switch ($_SERVER['REQUEST_METHOD']) :
91
			case 'GET': // insert/update user
92
                $_GET['user_id'] =$aUserID[$key];
93
				break;
94
			default: // show userlist with empty modify mask
95
                $_POST['user_id'] =$aUserID[$key];
96
		endswitch; // end of switch
97
		$user_id = intval($admin->checkIDKEY('user_id', 0, $_SERVER['REQUEST_METHOD']));
98
99
		// Check if user id is a valid number and doesnt equal 1
100
		if($user_id == 0){
101 2065 Luisehahne
			msgQueue::add($mLang->MESSAGE_GENERIC_FORGOT_OPTIONS );
102 1815 Luisehahne
            return $bRetVal;
103
        }
104
105
		if( ($user_id < 2 ) )
106
		{
107
			// if($admin_header) { $admin->print_header(); }
108 2065 Luisehahne
			msgQueue::add($mLang->MESSAGE_GENERIC_SECURITY_ACCESS );
109 1815 Luisehahne
            return $bRetVal;
110
		}
111
112
		if( ($msg = msgQueue::getError()) == '')
113
		{
114 2076 darkviper
115
    	switch($action) :
116
    		case 'enable_outdated': // enable Users awaiting activation
117
    			$sql  = 'SELECT `display_name` FROM `'.TABLE_PREFIX.'users` '.
118
                        'WHERE `user_id` = '.$user_id;
119
                if( ($sDisplayUser = $database->getOne($sql)) != null ) {
120
            		$sql = 'UPDATE `'.TABLE_PREFIX.'users` '
121
            		     . 'SET `active`=1, '
122
            		     .     '`confirm_code`=\'\', '
123
            		     .     '`confirm_timeout`=0 '
124
            		     . 'WHERE `user_id`='.$user_id;
125
            		if($database->query($sql)) {
126
                        msgQueue::add($mLang->MESSAGE_USERS_ADDED.' ('.$sDisplayUser.')', true);
127
                        $bRetVal = true;
128
                    } else {
129
                        msgQueue::add($mLang->TEXT_ENABLE.$mLang->MESSAGE_GENERIC_NOT_COMPARE.' ('.$sDisplayUser.')');
130 1815 Luisehahne
                    }
131 2076 darkviper
                }
132
        		break;
133
    		default: // show userlist with empty modify mask
134
    			$sql  = 'SELECT `active` FROM `'.TABLE_PREFIX.'users` '.
135
                        'WHERE `user_id` = '.$user_id;
136
                if( ($iDeleteUser = $database->get_one($sql)) != null ) {
137
                    if($iDeleteUser) {
138
        				// Deactivate the user
139
            			$sql  = 'UPDATE `'.TABLE_PREFIX.'users` SET '.
140
                                '`active` = 0 '.
141
                                'WHERE `user_id` = '.$user_id;
142
                        if( $database->query($sql) ) {
143
                            msgQueue::add($mLang->TEXT_USERS_MARKED_DELETED, true);
144
                        }
145
                    } else {
146 2065 Luisehahne
147
148 2076 darkviper
            			$sql  = 'DELETE FROM `'.TABLE_PREFIX.'users` '.
149
                                'WHERE `user_id` = '.$user_id;
150
                        if( $database->query($sql) ) {
151
                            msgQueue::add($mLang->MESSAGE_USERS_DELETED, true);
152
                        }
153 1815 Luisehahne
                    }
154 2076 darkviper
                    $bRetVal = true;
155 1815 Luisehahne
                }
156 2076 darkviper
                if($database->is_error()) {
157
                    msgQueue::add( implode('<br />',explode(';',$database->get_error())) );
158
                    $bRetVal = false;
159
               }
160
    	endswitch; // end of switch
161
		} // getError
162
    } // foreach users
163 1815 Luisehahne
    if(isset($aActionRequest['clearmsg'])) { msgQueue::clear();  }
164 1844 Luisehahne
    return $bRetVal;
165 1815 Luisehahne
}
166
167
if(!isset($aActionRequest)) {
168
    $requestMethod = '_'.strtoupper($_SERVER['REQUEST_METHOD']);
169
    $aActionRequest = (isset(${$requestMethod})) ? ${$requestMethod} : null;
170
    $aActionRequest['clearmsg'] = true;
171 2076 darkviper
}