<?php
#####Class For Adding User Group Management ######
class UsergroupReg extends MysqlFns{
/* class constructor */
function UsergroupReg(){
$this->LDDisplayPath= $config['SiteGlobalPath']."class.UsergroupReg.php";
global $config;
global $objSmarty,$config;
$tbl = $config['DBPrefix'];
$this->MysqlFns();
$this->Limit = 20;
$usrgroup_id = base64_decode($_GET["group_id"]);
 } 

 
 /*******************Check Duplicate User Group Name*******************************/
function ChkDuplicateUserGroup($ug_no)
{
global $objSmarty,$config,$_POST;
$tbl = $config['DBPrefix'];
$SelQuery	= 'SELECT * FROM `user_group_master` WHERE `usergroupName` = "'.$ug_no.'" and status="1" Limit 0,1';
$UGDetail = $this->ExecuteQuery($SelQuery, 'select');
if(!empty($UGDetail) && is_array($UGDetail))
return false;
else
return true;
}
/*************************************************Insert Group/***************************************************************/
function InsertUserGroup($objArray="")
{
global $objSmarty,$config;
$tbl = $config['DBPrefix'];
if(!$objArray['usergroupName']){
$objSmarty->assign('ErrorMessage', 'Group Name should not be blank');
return false;
}
if($this->ChkDuplicateUserGroup(trim(addslashes($objArray['usergroupName'])))){
$InsQuery = 'INSERT INTO `user_group_master`
(`usergroupName`,
`isActive`,
`status`,
`createdBy`) 
VALUES
("'.trim(addslashes($objArray['usergroupName'])).'",
"'.trim(addslashes($objArray['checkVal'])).'",
"1",
"'.trim(addslashes($objArray['created_by'])).'")';
$this->ExecuteQuery($InsQuery, 'insert');

$SelQuery = 'select * from `user_group_master` where slNo=(SELECT LAST_INSERT_ID())';
$sView = $this->ExecuteQuery($SelQuery, "select");
$objSmarty->assign('sView', $sView);
$arrs = $objArray["dexam16"];
	 
foreach($arrs as $key=>$value)
{
$SelQuery = 'SELECT * FROM `user_role_master` WHERE slNo="'.$value.'"';
$ListView = $this->ExecuteQuery($SelQuery, "select");
$objSmarty->assign('ListView', $ListView);

 $InsQuery = 'INSERT INTO `user_group_mapping`(
 `groupName`,
 `menuName`,
 `menuType`,
 `faIcon`,
 `url`,
 `priority`,
 `isActive`) 
VALUES(
"'.$sView[0]['slNo'].'",
"'.$value.'",
"'.$ListView[0]['menuType'].'",
"'.$ListView[0]['faIcon'].'",
"'.$ListView[0]['url'].'",
"'.$ListView[0]['priority'].'",
"1")';
$this->ExecuteQuery($InsQuery, 'insert');
}
header('Location:userGroupList.php?success_msg_for_insert');  
}
}
/****************************************Update User Group*****************************************************************/
function UpdateUserGroup($objArray)
 {
global $objSmarty,$config;
$tbl = $config['DBPrefix'];
 $UpQuery = 'UPDATE 
`user_group_master` 
SET 
`usergroupName` = "'.trim($objArray['usergroupName']).'",
`status` = "1",
`isActive` = "'.trim($objArray['checkVal']).'",
`createdBy` = "'.trim($objArray['created_by']).'"
WHERE 
`slNo` ="'.trim($objArray['group']).'"';
$this->ExecuteQuery($UpQuery, 'update');

$DelQuery = 'DELETE FROM `user_group_mapping` WHERE `groupName` ="'.trim($objArray['group']).'"';
$this->ExecuteQuery($DelQuery, 'delete');
$objSmarty->assign('SuccessMessage', 'Group Deleted Successfully');
	//print_r($objArray["dexam16"]);
$arrs = $objArray["dexam16"];//print_r($arrs);exit;

$SelQuery = 'select * from `user_group_master` where slNo="'.trim($objArray['group']).'"';
$sView = $this->ExecuteQuery($SelQuery, "select");
$objSmarty->assign('sView', $sView);
	 
foreach($arrs as $key=>$value)
{
 $SelQuery = 'SELECT * FROM `user_role_master` WHERE slNo="'.$value.'"';
$ListView = $this->ExecuteQuery($SelQuery, "select");
$objSmarty->assign('ListView', $ListView);

 $InsQuery = 'INSERT INTO `user_group_mapping`(
 `groupName`,
 `menuName`,
 `menuType`,
 `faIcon`,
 `url`,
 `priority`,
 `isActive`) 
VALUES(
"'.trim($objArray['group']).'",
"'.$value.'",
"'.$ListView[0]['menuType'].'",
"'.$ListView[0]['faIcon'].'",
"'.$ListView[0]['url'].'",
"'.$ListView[0]['priority'].'",
"1")';
$this->ExecuteQuery($InsQuery, 'insert');
}	
header('Location:userGroupList.php?success_msg_for_update');  
}
 /*************************************************List Group/***************************************************************/
function ListGroup($objArray)
 {
global $objSmarty,$config;
	$tbl = $config['DBPrefix'];
	/*$SelQuery = 'SELECT  * FROM `user_master` WHERE status = "1" ';
	$ListView = $this->ExecuteQuery($SelQuery, "select");
	$objSmarty->assign('ListView', $ListView);*/
	$i=$_SESSION['USER_GROUP'];
	/*******************      Accession List              **************/
	        if($_POST['table_search'] <> '')
			{
			$SelQuery='SELECT  * FROM `user_group_master` WHERE status = "1" AND (usergroupName like "%'.$_POST['table_search'].'%") ORDER BY usergroupName DESC';
			}
			else
			{
			$SelQuery = 'SELECT  * FROM `user_group_master` WHERE status = "1"';
			}	 
			//echo $SelQuery;
		/*	$listing_split = new MsplitPageResults($SelQuery, $this->Limit);
            if ( ($listing_split->number_of_rows > 0) )  
  		    {
   $objSmarty->assign('Contact_List_LinkPage',$listing_split->display_count(TEXT_DISPLAY_NUMBER_OF_RESULT));
   $objSmarty->assign('Contact_List_PerPageNavigation',TEXT_RESULT_PAGE1 . ' ' . $listing_split->display_links($this->Limit, get_all_get_params(array('page', 'info', 'x', 'y')))); 
			$ListView = $this->ExecuteQuery($listing_split->sql_query, 'selectassoc');
		    }
			if(!empty($ListView) && is_array($ListView))
			foreach($ListView as $key=>$value)
			{
			$ListView[$key]['Cid'] = stripslashes($ListView[$key]['customer_id']);
			}		
			$objSmarty->assign('i', $listing_split->i);*/
			$ListView = $this->ExecuteQuery($SelQuery, "select");
			$objSmarty->assign('ListView', $ListView);//print_r($ListView);exit;
			return $ListView;
 }	
/*************************************************Edit Group Page***************************************************************/
function GroupDetailview($objArray)
{
global $objSmarty,$config;
$tbl = $config['DBPrefix'];
$SelQuery = 'SELECT * FROM `user_group_master` WHERE slNo="'.$_GET['groupId'].'"';
$ListEditView = $this->ExecuteQuery($SelQuery, "select");
$objSmarty->assign('ListEditView', $ListEditView);

//$SelQuery = 'SELECT * FROM `user_group_mapping` WHERE groupName="'.$_GET['groupId'].'" ORDER BY menuName' ;
$SelQuery = 'SELECT user_group_mapping.menuType,user_group_mapping.url,user_group_mapping.menuName as slNo,user_group_mapping.faIcon,user_role_master.menuName FROM `user_group_mapping`,`user_role_master` WHERE groupName="'.$_GET['groupId'].'" AND user_group_mapping.menuName= user_role_master.slNo ORDER BY user_group_mapping.menuName' ;
$groupMapping		= $this->ExecuteQuery($SelQuery, "select");
$objSmarty->assign('groupMapping',$groupMapping);

 $SelQuery1 = 'SELECT DISTINCT slNo,menuName FROM user_role_master where slNo not in(SELECT menuName FROM user_group_mapping where groupName="'.$_GET['groupId'].'") order by user_role_master.menuName';
$uRoleList = $this->ExecuteQuery($SelQuery1, 'selectassoc');
$objSmarty->assign('uRoleList',$uRoleList);

return $uRoleList;
}
   /*************************************************Add Roles To Group Reg Page***************************************************************/
function AddGroupRoles($objArray)
 {global $objSmarty,$config;
$tbl = $config['DBPrefix'];
$usrgroup_id = base64_decode($_GET["group_id"]);
			$SelQuery = 'SELECT * FROM `role_master` ';
			$ListRoles = $this->ExecuteQuery($SelQuery, "select");
			$objSmarty->assign('ListRoles', $ListRoles);
			return $ListRoles;
 }
/*************************************Delete/********************************************************************/
function DeleteMaster($CatIdent)
{
global $objSmarty,$config;
$tbl = $config['DBPrefix'];
$DelQuery = 'update `user_group_master` set `status` = 0 WHERE `slNo` ="'.$CatIdent.'"';
$this->ExecuteQuery($DelQuery, 'update');
header('Location:' .$_SERVER['PHP_SELF'].'?succs_msg_for_del');  
}
/************************************Roles/**************************************************************************************/
function RoleList($objArray="")
{
global $objSmarty,$config;
$tbl = $config['DBPrefix'];
$SelQuery = 'SELECT  * FROM `user_role_master` WHERE isActive = "1"';
$RoleList = $this->ExecuteQuery($SelQuery, "select");
$objSmarty->assign('RoleList', $RoleList);
return $RoleList;
}
}
?>


