1
|
<?php
|
2
|
/**
|
3
|
* @category admin
|
4
|
* @package groups
|
5
|
* @author Independend-Software-Team
|
6
|
* @author WebsiteBaker Project
|
7
|
* @copyright 2009-2013, WebsiteBaker Org. e.V.
|
8
|
* @link http://www.websitebaker.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 2098 2014-02-11 01:37:03Z darkviper $
|
13
|
* @filesource $HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/admin/groups/delete.inc.php $
|
14
|
* @lastmodified $Date: 2014-02-11 02:37:03 +0100 (Tue, 11 Feb 2014) $
|
15
|
* @description all basic actions of this module, called by dispatcher only.
|
16
|
*/
|
17
|
|
18
|
/* *****************************************************************************
|
19
|
* Delete an existing group and remove existing group in user
|
20
|
* @access public
|
21
|
* @param object $admin: admin-object
|
22
|
* @param int $group_id: ID from group to delete
|
23
|
* @return bool: true or false
|
24
|
*/
|
25
|
function delete_group($admin, $iGroupId = 0)
|
26
|
{
|
27
|
$oDb = WbDatabase::getInstance();
|
28
|
$oLang = Translate::getInstance();
|
29
|
$oLang->enableAddon('admin\\groups');
|
30
|
|
31
|
// first check form-tan
|
32
|
if (!$admin->checkFTAN() || $iGroupId <= 1) {
|
33
|
msgQueue::add($oLang->MESSAGE_GENERIC_SECURITY_OFFENSE );
|
34
|
} else {
|
35
|
// if FTAN is successful checked and not Administrator group is seleced
|
36
|
$sql = 'SELECT GROUP_CONCAT(`username` ORDER BY `username` SEPARATOR \', \') '
|
37
|
. 'FROM `'.$oDb->TablePrefix.'users` '
|
38
|
. 'WHERE `groups_id`=\''.(string)$iGroupId.'\'';
|
39
|
if (($sUsers = $oDb->getOne($sql))) {
|
40
|
// sorry, this group has users which having this group as the only one group
|
41
|
msgQueue::add($oLang->MESSAGE_UNABLE_DELETE_GROUP . '<br />' . $sUsers);
|
42
|
} else {
|
43
|
$sql = 'UPDATE `'.$oDb->TablePrefix.'users` '
|
44
|
. 'SET `groups_id`=TRIM(BOTH \',\' FROM REPLACE(CONCAT(\',\',`groups_id`,\',\'),\','.$iGroupId.',\',\',\')) '
|
45
|
. 'WHERE FIND_IN_SET('.$iGroupId.', `groups_id`) AND `user_id`!=1';
|
46
|
// remove Group from Users
|
47
|
$oDb->doQuery($sql);
|
48
|
$sql = 'SELECT COUNT(*) '
|
49
|
. 'FROM `'.$oDb->TablePrefix.'users` '
|
50
|
. 'WHERE FIND_IN_SET('.$iGroupId.', `groups_id`) AND `user_id`!=1';
|
51
|
if ($oDb->getOne($sql)) {
|
52
|
// the group already has assigned users.
|
53
|
msgQueue::add($oLang->MESSAGE_RECORD_MODIFIED_FAILED );
|
54
|
} else {
|
55
|
$sql = 'DELETE FROM `'.$oDb->TablePrefix.'groups` '
|
56
|
. 'WHERE `group_id`='.$iGroupId;
|
57
|
// delete the group itself
|
58
|
$oDb->doQuery($sql);
|
59
|
msgQueue::add($oLang->MESSAGE_GROUPS_DELETED,true);
|
60
|
}
|
61
|
}
|
62
|
}
|
63
|
$admin->print_header();
|
64
|
return ;
|
65
|
}
|