<?php



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





//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 status
$status = (!empty($_POST['status']))? (mysqli_real_escape_string($dbc,$_POST['status'])): 
 NULL;
$_SESSION['status'] = $status;



//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
	unset($_SESSION['title']);
	unset($_SESSION['description']);
	unset($_SESSION['status']);
	
	 //check if the query is for adding den add
	
	
	$q = "INSERT INTO `roles`(`role_id`, `role_title`, `description`,`date_added`, `added_by`,`status`) 
	VALUES (NULL,'$title','$description',NOW(),'$security_id' ,'$status')";
							
							
	$r = mysqli_query($dbc,$q);
	
	if($r)
	{
		$info_success['success'] = 'Successfully added!';
		header("Location: gateway.php?act=view_roles&is=".urlencode($info_success['success']).""); //is - info success
		
	}
	else
	{
		$errors['error'] =  'details not added due to a system error. We apologize for any inconvenience.';
										
		header("Location: gateway.php?act=add_roles&error=".urlencode($errors['error'])."");
	}
	
}
else
{//stay back in add_project form


	$errors['error'] =  'Fill the form appropriately, take note of <span class="ast">*</span>.';
										
	header("Location: gateway.php?act=add_roles&error=".urlencode($errors['error'])."");

}



?>