1
|
<?php
|
2
|
/**
|
3
|
* @category admin
|
4
|
* @package groups
|
5
|
* @author Independend-Software-Team
|
6
|
* @author WebsiteBaker Project
|
7
|
* @copyright 2009-2012, Website Baker Org. e.V.
|
8
|
* @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: delete.inc.php 1784 2012-10-11 21:59:45Z Luisehahne $
|
13
|
* @filesource $HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/admin/groups/delete.inc.php $
|
14
|
* @lastmodified $Date: 2012-10-11 23:59:45 +0200 (Thu, 11 Oct 2012) $
|
15
|
* @description all basic actions of this module, called by dispatcher only.
|
16
|
*/
|
17
|
|
18
|
// Must include code to stop this file being access directly
|
19
|
if(defined('WB_PATH') == false) { exit("Cannot access this file directly"); }
|
20
|
|
21
|
/* *****************************************************************************
|
22
|
* Delete an existing group and remove existing group in user
|
23
|
* @access public
|
24
|
* @param object $admin: admin-object
|
25
|
* @param int $group_id: ID from group to delete
|
26
|
* @return bool: true or false
|
27
|
*/
|
28
|
function delete_group($admin, $group_id = 0)
|
29
|
{
|
30
|
global $MESSAGE;
|
31
|
$database = WbDatabase::getInstance();
|
32
|
// first check form-tan
|
33
|
if($admin->checkFTAN())
|
34
|
{
|
35
|
if($group_id > 1) // prevent admin [ID 1] from being deleted
|
36
|
{
|
37
|
$sql = 'SELECT `name` FROM `'.TABLE_PREFIX.'groups` WHERE `group_id` = '.$group_id;
|
38
|
$groupname = ($database->get_one($sql));
|
39
|
// $sql = 'SELECT * FROM `'.TABLE_PREFIX.'groups` ';
|
40
|
$sql = 'DELETE FROM `'.TABLE_PREFIX.'groups` ';
|
41
|
$sql .= 'WHERE `group_id` = '.$group_id;
|
42
|
if($database->query($sql) != false)
|
43
|
{
|
44
|
// remove group from users groups_id
|
45
|
msgQueue :: add($MESSAGE['GROUPS_DELETED'],true);
|
46
|
$sql = 'SELECT `user_id`, `groups_id`, `home_folder` FROM `'.TABLE_PREFIX.'users` WHERE user_id != 1';
|
47
|
if(($res_users = $database->query($sql)) && ($res_users->numRows() > 0) )
|
48
|
{
|
49
|
while($rec_users = $res_users->fetchRow(MYSQL_ASSOC))
|
50
|
{
|
51
|
$user_id = $rec_users['user_id'];
|
52
|
$groups_id = explode(',',$rec_users['groups_id']);
|
53
|
|
54
|
if( is_numeric($x = array_search($group_id, $groups_id)) )
|
55
|
{
|
56
|
unset($groups_id[$x]);
|
57
|
$groups_id = (sizeof($groups_id) == 0) ? FRONTEND_SIGNUP : implode(',',$groups_id);
|
58
|
$groups_id = ( ($groups_id == 1) && (trim($rec_users['home_folder']) != '') ) ? FRONTEND_SIGNUP : $groups_id;
|
59
|
$sql = 'UPDATE `'.TABLE_PREFIX.'users` SET ';
|
60
|
$sql .= '`groups_id` = \''.$groups_id.'\' ';
|
61
|
$sql .= 'WHERE `user_id` = '.$user_id;
|
62
|
if( $database->query($sql) )
|
63
|
{
|
64
|
$sql_info = mysql_info($database->db_handle);
|
65
|
if(preg_match('/matched: *([1-9][0-9]*)/i', $sql_info) != 1)
|
66
|
{
|
67
|
msgQueue :: add($MESSAGE['RECORD_MODIFIED_FAILED']);
|
68
|
}
|
69
|
} else {
|
70
|
|
71
|
msgQueue :: add($database->get_error());
|
72
|
}
|
73
|
}
|
74
|
}
|
75
|
}
|
76
|
// $admin->print_success($msg);
|
77
|
} else {
|
78
|
msgQueue :: add($MESSAGE['RECORD_MODIFIED_FAILED']);
|
79
|
}
|
80
|
}
|
81
|
} else {
|
82
|
msgQueue :: add($MESSAGE['GENERIC_SECURITY_OFFENSE']);
|
83
|
}
|
84
|
$admin->print_header();
|
85
|
return ;
|
86
|
}
|