Project

General

Profile

1
<?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: delete.php 2076 2014-01-06 23:30:25Z darkviper $
14
 * @filesource		$HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/admin/users/delete.php $
15
 * @lastmodified    $Date: 2014-01-07 00:30:25 +0100 (Tue, 07 Jan 2014) $
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
	$mLang = Translate::getInstance();
30
    $aUserID = array();
31
    $bRetVal = false;
32

    
33
    $action = 'default';
34
    $action = (isset($aActionRequest['delete']) ? 'delete' : $action );
35
    $action = (isset($aActionRequest['delete_outdated']) ? 'delete_outdated'   : $action );
36
    $action = (isset($aActionRequest['enable_outdated']) ? 'enable_outdated' : $action );
37

    
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
    	    }
47
    		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
		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
		default: // show userlist with empty modify mask
67
	endswitch; // end of switch
68

    
69
//    if(isset($aActionRequest['activation_user_id'])) {
70
//		if(!is_array($aActionRequest['activation_user_id'])) {
71
//
72
//	        $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
//
80
//		        $aUserID[] = $aActionRequest['user_id'];
81
//		    } else {
82
//		        $aUserID = $aActionRequest['user_id'];
83
//		    }
84
//	    }
85
//    }
86

    
87

    
88
    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
			msgQueue::add($mLang->MESSAGE_GENERIC_FORGOT_OPTIONS );
102
            return $bRetVal;
103
        }
104

    
105
		if( ($user_id < 2 ) )
106
		{
107
			// if($admin_header) { $admin->print_header(); }
108
			msgQueue::add($mLang->MESSAGE_GENERIC_SECURITY_ACCESS );
109
            return $bRetVal;
110
		}
111

    
112
		if( ($msg = msgQueue::getError()) == '')
113
		{
114

    
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
                    }
131
                }
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

    
147

    
148
            			$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
                    }
154
                    $bRetVal = true;
155
                }
156
                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
    if(isset($aActionRequest['clearmsg'])) { msgQueue::clear();  }
164
    return $bRetVal;
165
}
166

    
167
if(!isset($aActionRequest)) {
168
    $requestMethod = '_'.strtoupper($_SERVER['REQUEST_METHOD']);
169
    $aActionRequest = (isset(${$requestMethod})) ? ${$requestMethod} : null;
170
    $aActionRequest['clearmsg'] = true;
171
}
(2-2/7)