<?php



$errors = array();
$info = array();
$info_success = array();

//check the id passed
if(isset($_POST['user_group']))
{
	$id =  $_POST['user_group'];
}




//validate the title
if(!empty($_POST['title']))
{
   $title = mysqli_real_escape_string($dbc, $_POST['title']);
   
   //collect code to fill the static form
   $_SESSION['title'] = $title;
 
}
else
{
   $errors[] = '<p> * </p>';
   
   
}







//collect the description
$description = (!empty($_POST['description']))? (mysqli_real_escape_string($dbc,$_POST['description'])): 
 NULL;
$_SESSION['description'] = $description;


//collect the header menu
$header_menu = (!empty($_POST['header_menu']))? (mysqli_real_escape_string($dbc,$_POST['header_menu'])): 
 NULL;
$_SESSION['header_menu'] = $header_menu;



//collect the toolbar menu
$toolbar_menu = (!empty($_POST['toolbar_menu']))? (mysqli_real_escape_string($dbc,$_POST['toolbar_menu'])): 
 NULL;
$_SESSION['toolbar_menu'] = $toolbar_menu;


//collect the home menu
$home_menu = (!empty($_POST['home_menu']))? (mysqli_real_escape_string($dbc,$_POST['home_menu'])): 
 NULL;
$_SESSION['home_menu'] = $home_menu;



//finaly get security id
$user_id = get_user_id();


$security_id = get_security_id($user_id);




 
 
 
if(empty($errors))
{		

		//destroy session if there is no error
		//destroy session if there is no error
		unset($_SESSION['title']);
		unset($_SESSION['description']);
		unset($_SESSION['header_menu']);
		unset($_SESSION['home_menu']);
		unset($_SESSION['toolbar_menu']);
		
	
	
	
	 //check if the query is for adding den add
	
	
		$q = "UPDATE `user_groups` SET `title`='$title',`description`='$description',`header_menu`='$header_menu',
			`toolbar_menu`='$toolbar_menu',`home_menu`='$home_menu', `date_modified`=NOW(), modified_by = '$security_id'
			 WHERE user_group_id = '$id'";
										
							
	$r = mysqli_query($dbc,$q);
	
	if($r)
	{
		$info_success['success'] = 'Updated Successfully!';
		header("Location: gateway.php?act=view_user_groups&is=".urlencode($info_success['success']).""); //is - info success
		
	}
	else
	{
		$errors['error'] =  'Details not updated due to a system error. We apologize for any inconvenience.';
										
		header("Location: gateway.php?act=view_user_groups&error=".urlencode($errors['error'])."");
	}
	
}
else
{//stay back in add_project form


	$errors['error'] =  'Details not updated, Please re-select and Fill the form appropriately, take note of <span class="ast">*</span>.';
										
	header("Location: gateway.php?act=view_user_groups&error=".urlencode($errors['error'])."");

}



?>