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 2100 2014-02-11 15:13:12Z darkviper $
14
 * @filesource		$HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/admin/users/delete.php $
15
 * @lastmodified    $Date: 2014-02-11 16:13:12 +0100 (Tue, 11 Feb 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
	$oDb = WbDatabase::getInstance();
29
	$oTrans = Translate::getInstance();
30
    $oTrans->enableAddon('admin\\users');
31
    $aUserID = array();
32
    $bRetVal = false;
33

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

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

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

    
88

    
89
    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
			msgQueue::add($oTrans->MESSAGE_GENERIC_FORGOT_OPTIONS );
103
            return $bRetVal;
104
        }
105

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

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

    
116
    	switch($action) :
117
    		case 'enable_outdated': // enable Users awaiting activation
118
    			$sql  = 'SELECT `display_name` FROM `'.$oDb->TablePrefix.'users` '.
119
                        'WHERE `user_id` = '.$user_id;
120
                if( ($sDisplayUser = $oDb->getOne($sql)) != null ) {
121
            		$sql = 'UPDATE `'.$oDb->TablePrefix.'users` '
122
            		     . 'SET `active`=1, '
123
            		     .     '`confirm_code`=\'\', '
124
            		     .     '`confirm_timeout`=0 '
125
            		     . 'WHERE `user_id`='.$user_id;
126
            		if($oDb->doQuery($sql)) {
127
                        msgQueue::add($oTrans->MESSAGE_USERS_ADDED.' ('.$sDisplayUser.')', true);
128
                        $bRetVal = true;
129
                    } else {
130
                        msgQueue::add($oTrans->TEXT_ENABLE.$oTrans->MESSAGE_GENERIC_NOT_COMPARE.' ('.$sDisplayUser.')');
131
                    }
132
                }
133
        		break;
134
    		default: // show userlist with empty modify mask
135
    			$sql  = 'SELECT `active` FROM `'.$oDb->TablePrefix.'users` '.
136
                        'WHERE `user_id` = '.$user_id;
137
                if( ($iDeleteUser = $oDb->getOne($sql)) != null ) {
138
                    if($iDeleteUser) {
139
        				// Deactivate the user
140
            			$sql  = 'UPDATE `'.$oDb->TablePrefix.'users` SET '.
141
                                '`active` = 0 '.
142
                                'WHERE `user_id` = '.$user_id;
143
                        if( $oDb->doQuery($sql) ) {
144
                            msgQueue::add($oTrans->TEXT_USERS_MARKED_DELETED, true);
145
                        }
146
                    } else {
147

    
148

    
149
            			$sql  = 'DELETE FROM `'.$oDb->TablePrefix.'users` '.
150
                                'WHERE `user_id` = '.$user_id;
151
                        if( $oDb->doQuery($sql) ) {
152
                            msgQueue::add($oTrans->MESSAGE_USERS_DELETED, true);
153
                        }
154
                    }
155
                    $bRetVal = true;
156
                }
157
                if($oDb->isError()) {
158
                    msgQueue::add( implode('<br />',explode(';',$oDb->getError())) );
159
                    $bRetVal = false;
160
               }
161
    	endswitch; // end of switch
162
		} // getError
163
    } // foreach users
164
    if(isset($aActionRequest['clearmsg'])) { msgQueue::clear();  }
165
    return $bRetVal;
166
}
167

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