| 1 | 1710 | Luisehahne | <?php
 | 
      
        | 2 |  |  | /**
 | 
      
        | 3 |  |  |  * @category        admin
 | 
      
        | 4 |  |  |  * @package         groups
 | 
      
        | 5 |  |  |  * @author          Independend-Software-Team
 | 
      
        | 6 |  |  |  * @author          WebsiteBaker Project
 | 
      
        | 7 | 1907 | Luisehahne |  * @copyright       2009-2013, WebsiteBaker Org. e.V.
 | 
      
        | 8 |  |  |  * @link            http://www.websitebaker.org/
 | 
      
        | 9 | 1710 | Luisehahne |  * @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$
 | 
      
        | 13 | 1907 | Luisehahne |  * @filesource      $HeadURL$
 | 
      
        | 14 | 1710 | Luisehahne |  * @lastmodified    $Date$
 | 
      
        | 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 | 2013 | darkviper | 	function delete_group($admin, $iGroupId = 0)
 | 
      
        | 26 | 1710 | Luisehahne | 	{
 | 
      
        | 27 | 2013 | darkviper | 		$oDb = WbDatabase::getInstance();
 | 
      
        | 28 |  |  | 		$oLang = Translate::getInstance();
 | 
      
        | 29 | 2098 | darkviper |   		$oLang->enableAddon('admin\\groups');
 | 
      
        | 30 |  |  | 
 | 
      
        | 31 | 1710 | Luisehahne | 	// first check form-tan
 | 
      
        | 32 | 2013 | darkviper | 		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 | 1710 | Luisehahne | 				} else {
 | 
      
        | 55 | 2013 | darkviper | 					$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 | 1710 | Luisehahne | 				}
 | 
      
        | 61 |  |  | 			}
 | 
      
        | 62 |  |  | 		}
 | 
      
        | 63 | 1784 | Luisehahne | 		$admin->print_header();
 | 
      
        | 64 |  |  | 		return ;
 | 
      
        | 65 |  |  |     }
 |