Project

General

Profile

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 2013 2013-12-04 13:21:22Z darkviper $
13
 * @filesource      $HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/admin/groups/delete.inc.php $
14
 * @lastmodified    $Date: 2013-12-04 14:21:22 +0100 (Wed, 04 Dec 2013) $
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
	// first check form-tan
30
		if (!$admin->checkFTAN() || $iGroupId <= 1) {
31
			msgQueue::add($oLang->MESSAGE_GENERIC_SECURITY_OFFENSE );
32
		} else {
33
		// if FTAN is successful checked and not Administrator group is seleced
34
			$sql = 'SELECT GROUP_CONCAT(`username` ORDER BY `username` SEPARATOR \', \') '
35
			     . 'FROM `'.$oDb->TablePrefix.'users` '
36
				 . 'WHERE `groups_id`=\''.(string)$iGroupId.'\'';
37
			if (($sUsers = $oDb->getOne($sql))) {
38
			// sorry, this group has users which having this group as the only one group
39
				msgQueue::add($oLang->MESSAGE_UNABLE_DELETE_GROUP . '<br />' . $sUsers);
40
			} else {
41
				$sql = 'UPDATE `'.$oDb->TablePrefix.'users` '
42
					 . 'SET `groups_id`=TRIM(BOTH \',\' FROM REPLACE(CONCAT(\',\',`groups_id`,\',\'),\','.$iGroupId.',\',\',\')) '
43
					 . 'WHERE FIND_IN_SET('.$iGroupId.', `groups_id`) AND `user_id`!=1';
44
			//  remove Group from Users
45
				$oDb->doQuery($sql);
46
				$sql = 'SELECT COUNT(*) '
47
					 . 'FROM `'.$oDb->TablePrefix.'users` '
48
					 . 'WHERE FIND_IN_SET('.$iGroupId.', `groups_id`) AND `user_id`!=1';
49
				if ($oDb->getOne($sql)) {
50
				// the group already has assigned users.
51
					msgQueue::add($oLang->MESSAGE_RECORD_MODIFIED_FAILED );
52
				} else {
53
					$sql = 'DELETE FROM `'.$oDb->TablePrefix.'groups` '
54
						 . 'WHERE `group_id`='.$iGroupId;
55
				//  delete the group itself
56
					$oDb->doQuery($sql);
57
					msgQueue::add($oLang->MESSAGE_GROUPS_DELETED,true);
58
				}
59
			}
60
		}
61
		$admin->print_header();
62
		return ;
63
    }
(1-1/6)