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

 /*************************************************Role List /***************************************************************/
function ListUserRole($objArray)
{
global $objSmarty,$config;
$tbl = $config['DBPrefix'];
$i=$_SESSION['USER_GROUP'];
	/*******************      Role List              **************/
if($_POST['table_search'] <> '')
{
$SelQuery='SELECT  * FROM `user_role_master` WHERE status="1" AND (menuName like "%'.$_POST['table_search'].'%" OR menuType like "%'.$_POST['table_search'].'%" OR faIcon like "%'.$_POST['table_search'].'%" OR url like "%'.$_POST['table_search'].'%" OR priority like "%'.$_POST['table_search'].'%" OR isActive like "%'.$_POST['table_search'].'%") ORDER BY menuName DESC';
}
else
{
$SelQuery = 'SELECT  * FROM `user_role_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;
 }	
  /*************************************************View role***************************************************************/
function RoleDetailview($objArray)
{
global $objSmarty,$config;
$tbl = $config['DBPrefix'];
$SelQuery = 'SELECT * FROM `user_role_master` WHERE slNo="'.$_GET['roleId'].'" AND status="1"';
$ListEditView = $this->ExecuteQuery($SelQuery, "select");
$objSmarty->assign('ListEditView', $ListEditView);
return $ListEditView;
}

  /************************************************* Parent Menu List ***************************************************************/
function ParentMenuList()
{
global $objSmarty,$config;
$tbl = $config['DBPrefix'];
$SelQuery = 'SELECT * FROM `user_role_master` WHERE menuType="Main Menu" AND status="1" AND isActive="1"';
$ListparMenu = $this->ExecuteQuery($SelQuery, "select");
$objSmarty->assign('ListparMenu', $ListparMenu);
return $ListparMenu;
}
 /*************************************************Insert role/***************************************************************/
function InsertUserRole($objArray)
{
global $objSmarty,$config;
$tbl = $config['DBPrefix'];
if(!$objArray['menuName']){
$objSmarty->assign('ErrorMessage', 'Menu Name should not be blank');
return false;
}elseif((!$objArray['menuType'])){
$objSmarty->assign('ErrorMessage', 'Menu Type should not be blank');
return false;
}elseif(!$objArray['faIcon']){
$objSmarty->assign('ErrorMessage', 'Favourite Icon should not be blank');
return false;
}elseif(!$objArray['url']){
$objSmarty->assign('ErrorMessage', 'URL should not be blank');
return false;
}elseif(!$objArray['priority']){
$objSmarty->assign('ErrorMessage', 'Priority should not be blank');
return false;
}/*elseif(!$objArray['isActive']){
$objSmarty->assign('ErrorMessage', 'Is Active should not be blank');
return false;
}*/

$objSmarty->assign('menuName', $objArray['menuName']);
if($objArray['menuName'] && $objArray['menuType'])
{
 $InsQuery = 'INSERT INTO `user_role_master`(
`menuName`,
`menuType`,
`faIcon`,
`url`,
`priority`,
`parent_id`,
`isActive`,
`createdBy`) 
VALUES(
"'.trim(addslashes($objArray['menuName'])).'",
"'.trim(addslashes($objArray['menuType'])).'",
"'.trim(addslashes($objArray['faIcon'])).'",
"'.trim(addslashes($objArray['url'])).'",
"'.trim(addslashes($objArray['priority'])).'",
"'.trim(addslashes($objArray['parentMenu'])).'",
"'.trim(addslashes($objArray['checkVal'])).'",
"'.trim(addslashes($objArray['created_by'])).'")';
$this->ExecuteQuery($InsQuery, 'insert');
}
header('Location:userRoleList.php?succs_msg_for_insert');
}
/*************************************************Edit Role/***************************************************************/
 
function EditUserRole($objArray="")
{
global $objSmarty,$config;
$tbl = $config['DBPrefix'];
if(!$objArray['menuName']){
$objSmarty->assign('ErrorMessage', 'Menu Name should not be blank');
return false;
}elseif((!$objArray['menuType'])){
$objSmarty->assign('ErrorMessage', 'Menu Type should not be blank');
return false;
}elseif(!$objArray['faIcon']){
$objSmarty->assign('ErrorMessage', 'Favourite Icon should not be blank');
return false;
}elseif(!$objArray['url']){
$objSmarty->assign('ErrorMessage', 'URL should not be blank');
return false;
}elseif(!$objArray['priority']){
$objSmarty->assign('ErrorMessage', 'Priority should not be blank');
return false;
}/*elseif(!$objArray['isActive']){
$objSmarty->assign('ErrorMessage', 'Is Active should not be blank');
return false;
}*/
   $objSmarty->assign('roleId', $objArray['roleId']);
   if($objArray['roleId'] && $objArray['menuName']){
   	 $UpQuery = 'UPDATE 
	`user_role_master` 
	SET 
	`menuName` = "'.trim($objArray['menuName']).'", 
	`menuType` = "'.trim($objArray['menuType']).'", 
	`faIcon` = "'.trim($objArray['faIcon']).'",
	`url` = "'.trim($objArray['url']).'",
	`priority` = "'.trim($objArray['priority']).'",
	`parent_id` = "'.trim($objArray['parentMenu']).'",
	`isActive` = "'.trim($objArray['checkVal']).'",
	`createdBy` = "'.trim($objArray['created_by']).'"
	WHERE 
	`slNo` ="'.trim($objArray['roleId']).'"'; 
	$this->ExecuteQuery($UpQuery, 'update');
	
	 $UpQuery = 'UPDATE `user_group_mapping` SET  `menuType`="'.trim($objArray['menuType']).'",`faIcon`="'.trim($objArray['faIcon']).'",`url`="'.trim($objArray['url']).'",`priority`="'.trim($objArray['priority']).'",`isActive`="'.trim($objArray['checkVal']).'" WHERE `menuName` ="'.$_GET['roleId'].'"'; 
	$this->ExecuteQuery($UpQuery, 'update');

	}
	header('Location:userRoleList.php?success_msg_for_update');  

   }
/*************************************Delete role/********************************************************************/
function DeleteMaster($CatIdent)
{
global $objSmarty,$config;
$tbl = $config['DBPrefix'];
$DelQuery = 'update `user_role_master` set `isActive` = 0 ,`status` = 0 WHERE `slNo` ="'.$CatIdent.'"';
$this->ExecuteQuery($DelQuery, 'update');
header('Location:' .$_SERVER['PHP_SELF'].'?succs_msg_for_del');  
}

}
?>


