<?php


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


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





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



//validate the ip
if(!empty($_POST['ips']))
{
   $ips = mysqli_real_escape_string($dbc, $_POST['ips']);
   
   $_SESSION['ips'] = $ips;
 
}
else
{
   $errors[] = '<p> * </p>';
}

//collect the description
$description = mysqli_real_escape_string($dbc, $_POST['description']);
$_SESSION['description'] = $description;


	
//validate optional system_status
$system_status= (!empty($_POST['system_status']))? (mysqli_real_escape_string($dbc,$_POST['system_status'])): 
NULL;

$_SESSION['system_status'] =$system_status;






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



//modified_by 
$user_id = get_user_id();
$sid = get_security_id($user_id);





if(empty($errors))
{
	//destroy session if there is no error
	unset($_SESSION['title']);
	unset($_SESSION['ips']);
	unset($_SESSION['description']);
	unset($_SESSION['status']);
	unset($_SESSION['system_status']);

	
	
	 //check if the query is for adding den add
	
	$q = "UPDATE ip_filter SET title ='$title', ips = '$ips', description ='$description', status ='$status', activate = '$system_status', 
							date_modified = NOW(), modified_by = '$sid'
							
	      WHERE id = '$id'";
							
							
	$r = mysqli_query($dbc,$q);
	
	if($r)
	{
		$info_success['success'] = 'Updated successfully!';
		header("Location: gateway.php?act=view_ip_filter&is=".urlencode($info_success['success']).""); //is - info success
		
	}
	else
	{
		$errors['error'] =  'Not updated due to a system error. We apologize for any inconvenience.';
										
		header("Location: gateway.php?act=view_ip_filter&error=".urlencode($errors['error'])."");
	}
	
}
else
{//stay back in add form


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

}



?>