<?php 
//this page temporarily updates school fee payment in the database


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


//collect the qlk to pass it for fliping
if(isset($_POST['qlk']))
{
	$qlk = $_POST['qlk'];
}

//colect iid from posted form
if(isset($_POST['iid']))
{
	$iid = $_POST['iid'];
	
	
}


//get current session
$sid = get_current_session($sid = '1');

//get invoice title
$invoice_title = get_invoice_title($iid);

//get invoice amount
$invoice_amount = get_invoice_amount($iid);


//get invoice payment method
//$invoice_payment_method = get_invoice_payment_method($iid);


//check if he / she has paid fee
if(has_paid_hostel_fee($user_id,$sid))
{
	
			$msg ="&nbsp;&nbsp;&nbsp;&nbsp;Hostel fee payment for this session has been made already .";
		 	header("Location: dashboard.php?act=view_invoices&info=".urlencode($msg)."&qlk=".md5(2)."&iid=".$iid);

	
}
else
{

		  
	$qry42="INSERT INTO `ug_hostel_fee_payments` (`student_id`, `session`, `payment_status`, `payment_method`, `invoice_id`, `title`, `amount`, `date_added`) 
			VALUES ('$user_id', '$sid', '1', 'nil for now', '$iid', '$invoice_title',  '$invoice_amount', NOW())";
	$rst42 =  mysqli_query($dbc, $qry42);
	
	if(mysqli_affected_rows($dbc))
	{//end of if update is successful
	
	
		  //query
		  $q = "UPDATE invoices SET payment_status = 1 WHERE invoice_id = '$iid'";
		  $r = mysqli_query($dbc, $q);
		  
		  if(mysqli_affected_rows($dbc))
		  {//end of if update is successful
		  	
			
			 $msg ="&nbsp;&nbsp;Payment has been successfully made, please click on payment history to access receipt.";
		 	 header("Location: dashboard.php?act=hostel_fee_payments&is=".urlencode($msg)."&qlk=".md5(2)."");

		  }
		  else
		  {
			 $msg =   '&nbsp;&nbsp;SERVER ERROR: Please try again 1.';
			header("Location: dashboard.php?act=view_invoices&error=".urlencode($msg)."&qlk=".md5(2)."&iid=".$iid);

		  }
	
	
	
		
	
	
	}
	else
	{
		$msg =   '&nbsp;&nbsp;SERVER ERROR: Please try again 2.';
			  
		header("Location: dashboard.php?act=view_invoices&error=".urlencode($msg)."&qlk=".md5(2)."&iid=".$iid);

	}
		
			  
			  
			  
		/*	  
		 
  */



}









?>