<?php

include_once('admin/config.php');
$max_file = "2"; 							// Maximum file size in MB
$max_width = "300";							// Max width allowed for the large image
		
		function get_prices($pid){
		$result=mysql_query("select product_price from product where product_id=$pid");
		if($result ==true)
		{$row=mysql_fetch_array($result);
		return $row['product_price'];
		}
	}
	
function resizeImage($image,$width,$height,$scale) {
	list($imagewidth, $imageheight, $imageType) = getimagesize($image);
	$imageType = image_type_to_mime_type($imageType);
	$newImageWidth = ceil($width * $scale);
	$newImageHeight = ceil($height * $scale);
	$newImage = imagecreatetruecolor($newImageWidth,$newImageHeight);
	switch($imageType) {
		case "image/gif":
			$source=imagecreatefromgif($image); 
			break;
	    case "image/pjpeg":
		case "image/jpeg":
		case "image/jpg":
			$source=imagecreatefromjpeg($image); 
			break;
	    case "image/png":
		case "image/x-png":
			$source=imagecreatefrompng($image); 
			break;
  	}
	imagecopyresampled($newImage,$source,0,0,0,0,$newImageWidth,$newImageHeight,$width,$height);
	
	switch($imageType) {
		case "image/gif":
	  		imagegif($newImage,$image); 
			break;
      	case "image/pjpeg":
		case "image/jpeg":
		case "image/jpg":
	  		imagejpeg($newImage,$image,90); 
			break;
		case "image/png":
		case "image/x-png":
			imagepng($newImage,$image);  
			break;
    }
	
	//chmod($image, 0777);
	return $image;
}


//You do not need to alter these functions
function getHeight($image) {
	$size = getimagesize($image);
	$height = $size[1];
	return $height;
}
//You do not need to alter these functions
function getWidth($image) {
	$size = getimagesize($image);
	$width = $size[0];
	return $width;
}

////////////////

function resizeThumbnailImage($thumb_image_name, $image, $width, $height, $scale){
	list($imagewidth, $imageheight, $imageType) = getimagesize($image);
	$imageType = image_type_to_mime_type($imageType);
	
	$newImageWidth = ceil($width * $scale);
	$newImageHeight = ceil($height * $scale);
	$newImage = imagecreatetruecolor($newImageWidth,$newImageHeight);
	switch($imageType) {
		case "image/gif":
			$source=imagecreatefromgif($image); 
			break;
	    case "image/pjpeg":
		case "image/jpeg":
		case "image/jpg":
		case "image/JPG":
			$source=imagecreatefromjpeg($image); 
			break;
	    case "image/png":
		case "image/x-png":
			$source=imagecreatefrompng($image); 
			break;
  	}
	imagecopyresampled($newImage,$source,0,0,0,0,$newImageWidth,$newImageHeight,$width,$height);
	switch($imageType) {
		case "image/gif":
	  		imagegif($newImage,$thumb_image_name); 
			break;
      	case "image/pjpeg":
		case "image/jpeg":
		case "image/jpg":
		case "image/JPG":
		case "image/png":
	  		//imagejpeg($newImage,$thumb_image_name,90); 
			break;
		case "image/png":
		case "image/x-png":
			imagepng($newImage,$thumb_image_name);  
			break;
    }
	//chmod($thumb_image_name, 0777);
	return $thumb_image_name;
}


function authorize(){
session_start();
if (!isset($_SESSION['username'])) {
	header("location: index.html");
	echo "<h1>You are not Authorized to view this page. Please go and login.</h1>";
		
}
else{
	$username = $_SESSION['username'];
	$fname = $_SESSION['admin_name'];		
}
if (isset($_GET['logout'])){
	$logout = $_GET['logout'];
	if ($logout == "true"){
		unset($_SESSION['username']);
		unset($_SESSION['password']);
		unset($_SESSION['admin_name']);
	session_destroy();
	header("location: index.php");
	}
}

}

function authorize2(){
session_start();
if (isset($_GET['logout'])){
	$logout = $_GET['logout'];
	if ($logout == "true"){
		unset($_SESSION['username']);
		unset($_SESSION['password']);
		unset($_SESSION['admin_name']);
	session_destroy();
	header("location: index.php");
	}
}
}

function getphones(){
$result=mysql_query("select * from student");
$rsult=mysql_query("delete from msg");
		while($reply = mysql_fetch_array($result)){
			$ids=$reply['pphone'];
			
			$reslt=mysql_query("select * from msg");
			$rep = mysql_fetch_array($reslt);
			
			if($rep >0)
			{
				$mg=$rep['ph'];
				$phone=$mg.','.$ids;
				$resul1t1=mysql_query("update msg set ph='$phone'");
			}
			else{
				$results=mysql_query("insert into msg values('$ids')");
			}
	
		}
		nos();
		
}

function nos4(){
	$result=mysql_query("select * from assignment");
		$total = mysql_num_rows($result);
		return $total;
}
function nos(){
	$result=mysql_query("select * from student");
		$total = mysql_num_rows($result);
		return $total;
}
function nos2($link,$email){
	$sql="select * from registration where EMAIL='$email'";
	if($result=mysqli_query($link,$sql)){
		$total = mysqli_fetch_array($result);
		 return $total;
	}
	
}
function getstore($link){
	$sql="select * from store";
	if($result=mysqli_query($link,$sql)){
		$row = mysqli_fetch_array($result);
		$store=$row['name'];
		 return $store;
	}
	
}
//function nos2($email){
	//$sql="select * from registration where EMAIL='$email'";
	//if($result=mysql_query($sql)){
		//$total = mysql_fetch_array($result);
		 //return $total;
	//}
	
//}
function Referral($link,$refer){
	$result=mysqli_query($link,"select * from registration where REFERRAL='$refer'");
		$total = mysqli_num_rows($result);
		return $total;
}
//function Referral($refer){
	//$result=mysql_query("select * from registration where REFERRAL='$refer'");
		//$total = mysql_num_rows($result);
		//return $total;
//}
function authorep(){
	$sql="select * from login where usertype='reception' and status='YES'";
	$result = mysql_query($sql);
	if($result)
	{}
	else
	{
 
	header("location: index.php");
	}
	
}
function authoict(){
	$sql="select * from login where usertype='ict' and status='Yes'";
	$result = mysql_query($sql);
	if($result)
	{}
	else
	{
 
	header("location: index.php");
	}
	
}
function GetRadio(){
	
	$val=$_POST['radio'];
	if($val=="Yes")
	{
		$vals="Yes";
		return $vals;
	}
	else
	{
		$vals="No";
		return $vals;
	}
		
	
}
function GetAgreement(){
	
	$val=$_POST['radio1'];
	if($val=="Agreed")
	{
		$vals="Agreed";
		return $vals;
	}
	else
	{
		$vals="Disagreed";
		return $vals;
	}
		
	
}
	
if (isset($_POST['Register'])){
	//$gcode=rand(0,7729);
	$fullname =strtoupper($_POST['name']);
	$code= rand(0,7729);
	$date =date('Y-m-d');
	$raddress=$_POST['raddress'];
	$gender=$_POST['gender'];
	$age= $_POST['age'];
	$phone=$_POST['phone'];
	$state=$_POST['state'];
	$nation=$_POST['nation'];
	$email=$_POST['email'];
	$lga=$_POST['lga'];
	$occ=$_POST['occ'];
	$religion=$_POST['religion'];
	
	$offaddress=$_POST['officeaddress'];
	$branch=$_POST['branch'];
	$NOK=$_POST['nok'];
	$pwd=$_POST['password'];
	$cpwd=$_POST['cpassword'];
	$val2=GetAgreement();
	$rep=nos2($link,$email);
	
	$bcode=getBranchcode($link,$branch);
	$mcode=$bcode.$code;
	if($rep !=""){
		$rese = "<div class='error'>This Email Has Register Once</div>";} else if($val2=="Disagreed"){$rese = "<div class='error'>You Do Not Agreed With The Terms and Condition</div>";
			
		}
		
		$pixy = substr(md5(uniqid()), 0,10);
	
	
	$date = date('Y-m-d');
	$mon=date('m');
	$yr=date('Y');
	
	
	
	$events = "INSERT INTO registration(BranchCode,Date,MemberCode,Fullname,Age,Gender,Email,RAddress,Nationality,State,Lga,Occupation,Religion,OfficeAddress,Phone,BranchName,NOK,Pledge,Password,Picture,Status) values('$bcode','$date','$mcode','$fullname','$age','$gender','$email','$raddress','$nation','$state','$lga','$occ','$religion','$offaddress','$phone','$branch','$NOK','AGREED','$pwd','','NOT ACTIVATED')";
	
	
	$sqls="insert into login(BranchCode,MemberCode,Fullname,Username,Password,Usertype,Status) values('$bcode','$mcode','$fullname','$mcode','$pwd','Member','NO')";
	$results = mysqli_query($link,$sqls);
	//$results = mysql_query($sqls);
	
	//sendmail($phone,$email,$fullname,$gcode);
	$results_Event = mysqli_query($link,$events);
	if($results_Event){
				header("location: welcome.php?referral=$branch");} else {$rese = "<div class='error'>Registration not Succesfull. Try again</div>";};
				
		
		
	}	
//==================================================================================================	
	if (isset($_POST['upload'])){
	$title=$_POST['title'];
	$course=$_POST['courses'];
	$status=$_POST['status'];
	$days=$_POST['days'];
	
	if($title == "" || $title == "Enter your Course Title" || $course == ""){
		$rests = "<div class='error'>Some fields are empty</div>";} else {
	$pixy = substr(md5(uniqid()), 0,10);
	
	$userfile_name =$_FILES['books']['name'];
	$userfile_tmp = $_FILES['books']['tmp_name'];
	$userfile_size =$_FILES['books']['size'];
	$userfile_type = $_FILES['books']['type'];
	$filename = basename($_FILES['books']['name']);
	
	$gcode=rand(0,7729);
	
	
	$file_ext = strtolower(substr($filename, strrpos($filename, '.') + 1));
	
	$target_path = "material/";
	$my_path = "material/".$userfile_name;
	$target = "material/";
	$new1 = "material/image".$pixy.".".$file_ext;
	$target_path = $target_path . basename($_FILES['books']['name']); 
	(move_uploaded_file($_FILES['books']['tmp_name'], $target_path));
	$image = $new1;

	$pixcode = 	$pixy;
	
	
	$events = "INSERT INTO courseupload values('$title','$course','$status','$my_path','$days')";
	$results_Event = mysql_query($events);
	if($results_Event){
				$rests="Upoaded Succesfully";} else {$rests = "<div class='error'>Uploading not Succesfull. Try again</div>";};
		
		}
		
	}
//=======================================Video / Image upload=========================================================================	
if (isset($_POST['video'])){
	$title=$_POST['course'];
	
	if($title == "" || $title == "Enter Title"){
		$rese = "<div class='error'>Some fields are empty</div>";} else {
	$pixy = substr(md5(uniqid()), 0,10);
	
	
	$userfile_name =$_FILES['video']['name'];
	$userfile_tmp = $_FILES['video']['tmp_name'];
	$userfile_size =$_FILES['video']['size'];
	$userfile_type = $_FILES['video']['type'];
	$filename = basename($_FILES['video']['name']);
	
	$gcode=rand(0,7729);
	
	
	$file_ext = strtolower(substr($filename, strrpos($filename, '.') + 1));
	
	$my_path = "Video/".$userfile_name;
	$target_path = "Video/";
	$target = "Video/";
	$new1 = "Video/image".$pixy.".".$file_ext;
	$target_path = $target_path . basename($_FILES['video']['name']); 
	(move_uploaded_file($_FILES['video']['tmp_name'], $target_path));
	$image = $new1;

	$pixcode = 	$pixy;
	
	
	$events = "INSERT INTO otheruploads values('$title','$my_path')";
	$results_Event = mysql_query($events);
	if($results_Event){
				$rese="Uploaded Succesfully";} else {$rese = "<div class='error'>Uploading not Succesfull. Try again</div>";};
		
		}
		
	}
//=======================================================Assignment Upload=============================================================================
if (isset($_POST['assigns'])){
	$title=$_POST['assgntitlte'];
	$name=$_POST['name'];
	
	if($title == "" || $title == "Enter Title"){
		$ass = "<div class='error'>Some fields are empty</div>";} else {
	$pixy = substr(md5(uniqid()), 0,10);
	
	
	$userfile_name =$_FILES['assg']['name'];
	$userfile_tmp = $_FILES['assg']['tmp_name'];
	$userfile_size =$_FILES['assg']['size'];
	$userfile_type = $_FILES['assg']['type'];
	$filename = basename($_FILES['assg']['name']);
	
	$gcode=rand(0,7729);
	
	
	$file_ext = strtolower(substr($filename, strrpos($filename, '.') + 1));
	
	$my_path = "assignment/".$userfile_name;
	$target_path = "assignment/";
	$target = "assignment/";
	$new1 = "assignment/image".$pixy.".".$file_ext;
	$target_path = $target_path . basename($_FILES['assg']['name']); 
	(move_uploaded_file($_FILES['assg']['tmp_name'], $target_path));
	$image = $new1;

	$pixcode = 	$pixy;
	$session=getsession();
	
	$events = "INSERT INTO assignment values('$name','$title','$session','$my_path')";
	$results_Event = mysql_query($events);
	if($results_Event){
				$ass="Uploaded Succesfully";} else {$ass = "<div class='error'>Uploading not Succesfull. Try again</div>";};
		
		}
		
	}
//=========================================================================================================================================================
	if (isset($_POST['reg'])){
	//$class=$_POST['class'];
	$subject=strtoupper($_POST['course']);
	
	$events = "INSERT INTO course values('$subject')";
	
	
	
	$results_Event = mysql_query($events);
	if($results_Event){
				$result="Course Registered Succesfully";} else {$result = "<div class='error'>Course registration not Succesfull. Try again</div>";};
		
	}
//======================================================================================================================================================
function getRetailAmnt($link,$bcode){
		$sql = "SELECT * FROM items where BranchCode='$bcode'";
		$rst = mysqli_query($link,$sql);
		$bal=0;
		while($reply = mysqli_fetch_array($rst)){
			$qnt=$reply['quantity'];
			$price=$reply['nprice'];
			$amnt=$qnt * $price;
			$bal+=$amnt;
		}
		return $bal;
	}
	function getLarAmnt($link,$bcode){
		$sql = "SELECT * FROM items where BranchCode='$bcode'";
		$rst = mysqli_query($link,$sql);
		$bal=0;
		while($reply = mysqli_fetch_array($rst)){
			$qnt=$reply['quantity'];
			$price=$reply['lar'];
			$amnt=$qnt * $price;
			$bal+=$amnt;
		}
		return $bal;
	}function getVsmAmnt($link,$bcode){
		$sql = "SELECT * FROM items where BranchCode='$bcode'";
		$rst = mysqli_query($link,$sql);
		$bal=0;
		while($reply = mysqli_fetch_array($rst)){
			$qnt=$reply['quantity'];
			$price=$reply['vsm'];
			$amnt=$qnt * $price;
			$bal+=$amnt;
		}
		return $bal;
	}
	function getPsnAmnt($link,$bcode){
		$sql = "SELECT * FROM items where BranchCode='$bcode'";
		$rst = mysqli_query($link,$sql);
		$bal=0;
		while($reply = mysqli_fetch_array($rst)){
			$qnt=$reply['quantity'];
			$price=$reply['psn'];
			$amnt=$qnt * $price;
			$bal+=$amnt;
		}
		return $bal;
	}
//==============================================================================\
function getSRetailAmnt($link,$bcode,$date){
		$sql = "SELECT * FROM summary where BranchCode='$bcode' and date='$date'";
		$rst = mysqli_query($link,$sql);
		$bal=0;
		while($reply = mysqli_fetch_array($rst)){
				$qnt=$reply['quantity'];
			$price=$reply['nprice'];
			$amnt=$qnt * $price;
			$bal+=$amnt;
		}
		return $bal;
	}
	function getSLarAmnt($link,$bcode,$date){
		$sql = "SELECT * FROM summary where BranchCode='$bcode' and date='$date'";
		$rst = mysqli_query($link,$sql);
		$bal=0;
		while($reply = mysqli_fetch_array($rst)){
			$qnt=$reply['lquan'];
			$price=$reply['lar'];
			$amnt=$qnt * $price;
			$bal+=$amnt;
		}
		return $bal;
	}function getSVsmAmnt($link,$bcode,$date){
		$sql = "SELECT * FROM summary where BranchCode='$bcode' and date='$date'";
		$rst = mysqli_query($link,$sql);
		$bal=0;
		while($reply = mysqli_fetch_array($rst)){
			$qnt=$reply['vquan'];
			$price=$reply['vsm'];
			$amnt=$qnt * $price;
			$bal+=$amnt;
		}
		return $bal;
	}
	function getSPsnAmnt($link,$bcode,$date){
		$sql = "SELECT * FROM summary where BranchCode='$bcode' and date='$date'";
		$rst = mysqli_query($link,$sql);
		$bal=0;
		while($reply = mysqli_fetch_array($rst)){
			$qnt=$reply['pquan'];
			$price=$reply['psn'];
			$amnt=$qnt * $price;
			$bal+=$amnt;
		}
		return $bal;
	}
//======================================================================================================
function getBulkAmnt($link,$bcode){
		$sql = "SELECT * FROM items where BranchCode='$bcode'";
		$rst = mysqli_query($link,$sql);
		$bal=0;
		while($reply = mysqli_fetch_array($rst)){
			$qnt=$reply['quantity'];
			$price=$reply['price2'];
			$amnt=$qnt * $price;
			$bal+=$amnt;
		}
		return $bal;
	}
function getSalesAmnt($link,$bcode,$date){
		$sql = "SELECT * FROM invoice where BranchCode='$bcode' and  date='$date' order by id ASC";
		$rst = mysqli_query($link,$sql);
		$bal=0;
		while($reply = mysqli_fetch_array($rst)){
			$amnt=$reply['total'];
			$bal+=$amnt;
		}
		return $bal;
	}	
	
	function getpetrolSalesAmnt($link,$bcode,$dates,$dateto){
		$sql = "SELECT * FROM invoice where BranchCode='$bcode' and  date >'$dates' and date <='$dateto' order by id ASC";
		$rst = mysqli_query($link,$sql);
		$bal=0;
		while($reply = mysqli_fetch_array($rst)){
			$amnt=$reply['quantity'];
			$bal+=$amnt;
		}
		return $bal;
	}	
function getExcess($link,$bcode,$dates,$dateto){
		$sql = "SELECT * FROM excess where BranchCode='$bcode' and  date >'$dates' and date <='$dateto' order by id ASC";
		$rst = mysqli_query($link,$sql);
		$bal=0;
		while($reply = mysqli_fetch_array($rst)){
			$amnt=$reply['exces'];
			$bal+=$amnt;
		}
		return $bal;
	}	


function getCashAmnt($link,$bcode,$date){
		$sql = "SELECT * FROM cashbook where BranchCode='$bcode' and  date ='$date' order by id ASC";
		$rst = mysqli_query($link,$sql);
		$bal=0;
		while($reply = mysqli_fetch_array($rst)){
			$amnt=$reply['cash'];
			$bal+=$amnt;
		}
		return $bal;
	}	

function getBankAmnt($link,$bcode,$date){
		$sql = "SELECT * FROM cashbook where BranchCode='$bcode' and  date ='$date' order by id ASC";
		$rst = mysqli_query($link,$sql);
		$bal=0;
		while($reply = mysqli_fetch_array($rst)){
			$amnt=$reply['bank'];
			$bal+=$amnt;
		}
		return $bal;
	}	
	
	
function getCashBank($link,$bcode,$date){
		$sql = "SELECT * FROM cashbook where BranchCode='$bcode' and  date='$date' order by id ASC";
		$rst = mysqli_query($link,$sql);
		$bal=0;
		while($reply = mysqli_fetch_array($rst)){
			$amnt=$reply['cashbank'];
			$bal+=$amnt;
		}
		return $bal;
	}	

	
	
if (isset($_POST['fulls'])){
	session_start();
	$date=date('Y-m-d');
	$officer=$_SESSION['admin_name'];
	$bcode=$_SESSION['branchcode'];
	
		//$codes=$_POST['code'];
		$name=$_POST['name'];
		$quan=$_POST['quan'];
		$pric=$_POST['pric'];
		$lar=$_POST['lar'];
		$vsm=$_POST['vsm'];
		$psn=$_POST['psn'];
		$Cprice=$_POST['cprice'];
		$Cat=$_POST['cate'];
		
	//$name=getname($link,$codes,$bcode);
	//$credit= getPrev($link,$codes,$bcode);
	//$debit= getMemberDebitSavings($link,$codes,$bcode);
	$mon=date('m');
	$yr=date('Y');
	//$empty=InsertJournal($link,$teller,$bcode,$date,$dr,$cr,$amounts,$mon,$yr,$officer);
	
	//$debitcode=getAccCode($link,$dr);
		//$creditcode=getAccCode($link,$cr);
	
	$sql =$link->query("insert into items values(0, '$bcode','$name','$quan','$pric','$lar','$vsm','$psn','$Cprice','$Cat')");
	//$sql =$link->query("insert into items values(0, '001','$codes','$name','0','$pric','$Cprice',$Cat)");
	//$sql =$link->query("insert into items values(0, '002','$codes','$name','0','$pric','$Cprice',$Cat)");
	$ssql =$link->query("insert into stockentry values(0,'$bcode', '$date','$ticket','$name','$quan',$mon,$yr,'$officer')");
	
		echo "<script>alert('Product Registered Succesfully, Click Okay To Continue')</script>";
				header("location: addstockfull.php");
		
}
	
if (isset($_POST['empty'])){
	session_start();
	$date=date('Y-m-d');
	$officer=$_SESSION['admin_name'];
	$bcode=$_SESSION['branchcode'];
	
	for($i=1; $i<=5; $i++)
	{
		$codes=$_POST['code'.$i];
		$name=$_POST['name'.$i];
		$quan=$_POST['quan'.$i];

		if($codes=="")
		{}else{
	//$name=getname($link,$codes,$bcode);
	//$credit= getPrev($link,$codes,$bcode);
	//$debit= getMemberDebitSavings($link,$codes,$bcode);
	$mon=date('m');
	$yr=date('Y');
	//$empty=InsertJournal($link,$teller,$bcode,$date,$dr,$cr,$amounts,$mon,$yr,$officer);
	
	//$debitcode=getAccCode($link,$dr);
		//$creditcode=getAccCode($link,$cr);
	
	$sql =$link->query("insert into empty values(0, '$bcode','$codes','$name','$quan')");
	
		}
				header("location: addstockempties.php");
		
	}
}
	
//======================================================================================================================================================	
		function getMemberSharesBal($link,$type,$code,$bcode){
			if($type=='Long Term'){
		$result=mysqli_query($link,"select * from shares where MemberCode='$code' and BranchCode='$bcode'");
		$bal=0;
		while($reply = mysqli_fetch_array($result)){
			$amnt=$reply['Credit'];
			$bal+=$amnt;
		}
		return $bal;
		}else{
			$result=mysqli_query($link,"select * from shares where MemberCode='$code' and BranchCode='$bcode'");
		$bal=0;
		while($reply = mysqli_fetch_array($result)){
			$amnt=$reply['SCredit'];
			$bal+=$amnt;
		}
		return $bal;
		}
	}
	function getMemberSharesBal2($link,$type,$code,$bcode){
			if($type=='Long Term'){
		$result=mysqli_query($link,"select * from shares where MemberCode='$code' and BranchCode='$bcode'");
		$bal=0;
		while($reply = mysqli_fetch_array($result)){
			$amnt=$reply['Debit'];
			$bal+=$amnt;
		}
		return $bal;
		}else{
			$result=mysqli_query($link,"select * from shares where MemberCode='$code' and BranchCode='$bcode'");
		$bal=0;
		while($reply = mysqli_fetch_array($result)){
			$amnt=$reply['SDebit'];
			$bal+=$amnt;
		}
		return $bal;
		}
	}
	function getMemberTotalUnit($link,$type,$code,$bcode){
			if($type=='Long Term'){
		$result=mysqli_query($link,"select * from shares where MemberCode='$code' and BranchCode='$bcode'");
		$bal=0;
		while($reply = mysqli_fetch_array($result)){
			$tot=$reply['Unit'];
			$bal+=$tot;
		}
		return $bal;
		}else{
			$result=mysqli_query($link,"select * from shares where MemberCode='$code' and BranchCode='$bcode'");
		$bal=0;
		while($reply = mysqli_fetch_array($result)){
			$tot=$reply['SUnit'];
			$bal+=$tot;
		}
		return $bal;
		}
	}
	
	if (isset($_POST['Shares'])){
	session_start();
	$code=$_POST['code'];
	$date=date('Y-m-d');
	$amount=$_POST['amount'];
	$officer=$_SESSION['admin_name'];
	$unit=$_POST['unit'];
	$bcode=$_SESSION['branchcode'];
	$type=$_POST['type'];
	$debit=$_POST['debit'];
	$credit=$_POST['credit'];
	$transcode=$_POST['transcode'];
	$name=getname($link,$code,$bcode);
	$bl= getMemberSharesBal($link,$type,$code,$bcode);
	$bal=$bl+$amount;
	$ubal=getMemberTotalUnit($link,$type,$code,$bcode);
	$totunit=$ubal+$unit;
	$mon=date('m');
	$yr=date('Y');
	//$empty=InsertJournal($link,$code,$bcode,$date,$debit,$credit,$amount,$mon,$yr,$officer);
	
		$debitcode=getAccCode($link,$debit);
		$creditcode=getAccCode($link,$credit);
	
	$sql =$link->query("insert into journal values(0, '$date','$code','$bcode','$debitcode','$debit','$amount','0','$mon','$yr','$officer')");
	$ssql =$link->query("insert into journal values(0, '$date','$code','$bcode','$creditcode','$credit','0','$amount','$mon','$yr','$officer')");
	
	
	$empt=InsertCashbook($link,$bcode,$code,$date,'Member Shares Savings',$debitcode,'0',$amount,'0','0',$mon,$yr,$officer);
	if($type=='Long Term'){
	$events = "INSERT INTO shares(BranchCode,Date,Code,MemberCode,Fullname,Debit,Credit,Balance,LongTerm,Unit,Totalunit,SDebit,SCredit,SBalance,ShortTerm,SUnit,STotalunit,Month,Year,Officer) values('$bcode','$date','$transcode','$code','$name','0','$amount','$bal','LongTerm','$unit','$totunit','0','0','0','ShortTerm','0','0','$mon','$yr','$officer')";
	
	
	
	$results_Event = mysqli_query($link,$events);
	if($results_Event){
				header("location: comment.php");} else {$result = "<div class='error'>Savings not Succesfull. Try again</div>";};
		
	}else
	{
		$events = "INSERT INTO shares(BranchCode,Date,Code,MemberCode,Fullname,Debit,Credit,Balance,LongTerm,Unit,Totalunit,SDebit,SCredit,SBalance,ShortTerm,SUnit,STotalunit,Month,Year,Officer) values('$bcode','$date','$transcode','$code','$name','0','0','0','LongTerm','0','0','0','$amount','$bal','ShortTerm','$unit','$totunit','$mon','$yr','$officer')";
	
	
	
	$results_Event = mysqli_query($link,$events);
	if($results_Event){
				header("location: comment.php");} else {$result = "<div class='error'>Savings not Succesfull. Try again</div>";};
	}
}
if (isset($_POST['SellShares'])){
	session_start();
	$code=$_POST['code'];
	$date=date('Y-m-d');
	$amount=$_POST['amount'];
	$officer=$_SESSION['admin_name'];
	$unit=$_POST['unit'];
	$bcode=$_SESSION['branchcode'];
	$type=$_POST['type'];
	$debit=$_POST['debit'];
	$credit=$_POST['credit'];
	$transcode=$_POST['transcode'];
	$name=getname($link,$code,$bcode);
	$bl= getMemberSharesBal($link,$type,$code,$bcode);
	$bal=$bl-$amount;
	$ubal=getMemberTotalUnit($link,$type,$code,$bcode);
	$totunit=$ubal-$unit;
	$mon=date('m');
	$yr=date('Y');
	//$empty=InsertJournal($link,$code,$bcode,$date,$debit,$credit,$amount,$mon,$yr,$officer);
	//$empt=InsertCashbook($link,$bcode,$code,$date,'Member Shares Sold',$bankcode,'0',$amount,'0','0',$mon,$yr,$officer);
	if($type=='Long Term'){
	$events = "INSERT INTO shares(BranchCode,Date,Code,MemberCode,Fullname,Debit,Credit,Balance,LongTerm,Unit,Totalunit,SDebit,SCredit,SBalance,ShortTerm,SUnit,STotalunit,Month,Year,Officer) values('$bcode','$date','$transcode','$code','$name','$amount','0','$bal','LongTerm','$unit','$totunit','0','0','0','ShortTerm','0','0','$mon','$yr','$officer')";
	
	
	
	$results_Event = mysqli_query($link,$events);
	if($results_Event){
				header("location: comment.php");} else {$result = "<div class='error'>Savings not Succesfull. Try again</div>";};
		
	}else
	{
		$events = "INSERT INTO shares(BranchCode,Date,Code,MemberCode,Fullname,Debit,Credit,Balance,LongTerm,Unit,Totalunit,SDebit,SCredit,SBalance,ShortTerm,SUnit,STotalunit,Month,Year,Officer) values('$bcode','$date','$transcode','$code','$name','0','0','0','LongTerm','0','0','$amount','0','$bal','ShortTerm','$unit','$totunit','$mon','$yr','$officer')";
	
	
	
	$results_Event = mysqli_query($link,$events);
	if($results_Event){
				header("location: comment.php");} else {$result = "<div class='error'>Savings not Succesfull. Try again</div>";};
	}
}
//===============================================================================================================================================
function getStoreName($link){
		$result=mysqli_query($link,"select * from store");
		$reply = mysqli_fetch_array($result);
			$name=$reply['name'];
		return $name;
	}
	function getStoreAddress($link){
		$result=mysqli_query($link,"select * from store");
		$reply = mysqli_fetch_array($result);
			$name=$reply['address'];
		return $name;
	}
	function getStorePhone($link){
		$result=mysqli_query($link,"select * from store");
		$reply = mysqli_fetch_array($result);
			$name=$reply['phone'];
		return $name;
	}
function getMemberLoanRepay($link,$code,$bcode){
		$result=mysqli_query($link,"select * from loanapprove where MemberCode='$code' and BranchCode='$bcode' and Status='Approved'");
		$reply = mysqli_fetch_array($result);
			$amnt=$reply['TotalRepayment'];
		return $amnt;
	}
function getMemberTotpay($link,$code,$bcode){
		$result=mysqli_query($link,"select * from loanrepayment where MemberCode='$code' and BranchCode='$bcode' and Status='Active'");
		$bal=0;
		while($reply = mysqli_fetch_array($result)){
			$tot=$reply['AmountPaid'];
			$bal+=$tot;
		}
		return $bal;
	}
function getAutoMember($link,$teller,$date,$bcode,$amount,$mon,$yr,$officer,$acccode,$details){
		$result=mysqli_query($link,"select * from registration where BranchCode='$bcode' and Status='ACTIVATED'");
		$bal=0;
		while($reply = mysqli_fetch_array($result)){
			$code=$reply['MemberCode'];
			$name=$reply['Fullname'];
//=======================================================================================================================
$rest=mysqli_query($link,"select * from Deduction where BranchCode='$bcode' and MemberCode='$code' and AccountCode='$acccode' and Month='$mon' and Year='$yr'");
			$num=mysqli_num_rows($rest);
			if($num>0)
			{}else{
			$credit= getPrev($link,$code,$bcode);
			$debit= getMemberDebitSavings($link,$code,$bcode);
			$prev=$credit-$debit;
			$cbal=$prev-$amount;
			$bal+=$amount;
			$events = "INSERT INTO savings(BranchCode,TransCode,Date,MemberCode,Fullname,PrevBalance,Debit,Credit,Balance,Month,Year,Officer) values('$bcode','$teller','$date','$code','$name','$prev','$amount','0','$cbal','$mon','$yr','$officer')";
	$results_Event = mysqli_query($link,$events);
	
	$query = "INSERT INTO Deduction(BranchCode,TransCode,Date,AccountCode,MemberCode,Fullname,Details,Amount,Month,Year,Officer) 		values('$bcode','$teller','$date','$acccode','$code','$name','$details','$amount','$mon','$yr','$officer')";
		$res = mysqli_query($link,$query);
			}
		}
		return $bal;
}

if (isset($_POST['LoanRepay'])){
	session_start();
	$date=date('Y-m-d');
	$teller=rand(0,7729);
	$officer=$_SESSION['admin_name'];
	$bcode=$_SESSION['branchcode'];
	$dr=$_POST['debit'];
	$cr=$_POST['credit'];
	for($i=1; $i<=10; $i++)
	{
		$codes=$_POST['code'.$i];
		$amounts=$_POST['amount'.$i];
		if($codes=="")
		{}else{
	$name=getname($link,$codes,$bcode);
	$totrepay= getMemberTotpay($link,$codes,$bcode);
	$totloan= getMemberLoanRepay($link,$codes,$bcode);
	$bankcode=getAccCode($link,$dr);
	$tot=$totrepay+$amounts;
	$cbal=$totloan-$tot;
	$mon=date('m');
	$yr=date('Y');
	if($totloan ==$totrepay){
		
	}elseif($totloan ==$tot){
		
		//$empty=InsertJournal($link,$teller,$bcode,$date,$dr,$cr,$amounts,$mon,$yr,$officer);
		
		$debitcode=getAccCode($link,$dr);
		$creditcode=getAccCode($link,$cr);
	
	$sql =$link->query("insert into journal values(0, '$date','$teller','$bcode','$debitcode','$dr','$amounts','0','$mon','$yr','$officer')");
	$ssql =$link->query("insert into journal values(0, '$date','$teller','$bcode','$creditcode','$cr','0','$amounts','$mon','$yr','$officer')");
		
		
	$empt=InsertCashbook($link,$bcode,$teller,$date,'Loan Repayment',$bankcode,'0',$amounts,'0','0',$mon,$yr,$officer);
	$events = "INSERT INTO loanrepayment(BranchCode,TransCode,Date,MemberCode,Fullname,AmountPaid,Balance,Month,Year,Status,Officer) values('$bcode','$teller','$date','$codes','$name','$amounts','$cbal','$mon','$yr','Completed','$officer')";
	$results_Event = mysqli_query($link,$events);
				header("location: comment.php");
	}
	else{
	$empty=InsertJournal($link,$teller,$bcode,$date,$dr,$cr,$amounts,$mon,$yr,$officer);
	$empt=InsertCashbook($link,$bcode,$teller,$date,'Loan Repayment',$bankcode,'0',$amounts,'0','0',$mon,$yr,$officer);
	$events = "INSERT INTO loanrepayment(BranchCode,TransCode,Date,MemberCode,Fullname,AmountPaid,Balance,Month,Year,Status,Officer) values('$bcode','$teller','$date','$codes','$name','$amounts','$cbal','$mon','$yr','Active','$officer')";
	$results_Event = mysqli_query($link,$events);
	header("location: comment.php");
	}
	}
	}
	
}
//=================================================================================================================================================	
	
//================================================================================================================================
/*if (isset($_POST['Payment'])){
	session_start();
	$teller=$_POST['teller'];
	$date=date('Y-m-d');
	$amount=$_POST['amount'];
	$officer=$_SESSION['admin_name'];
	$details=$_POST['details'];
	$mode='Cash';
	$time=date("h:i a" );
	$debit=$_POST['debit'];
	$credit=$_POST['credit'];
	$brcode=$_POST['branch'];
	$branchcode=getBranchcode($link,$brcode);

	$mon=date('m');
	$yr=date('Y');
	$bankcode=getAccCode($link,$credit);
	
	//$empty=InsertJournal($link,$teller,$bcode,$date,$debit,$credit,$amount,$mon,$yr,$officer);
	$debitcode=getAccCode($link,$debit);
		$creditcode=getAccCode($link,$credit);
	
	$sq =$link->query("insert into expenses values(0, '$branchcode','$date','$teller','$details','Cash','0','$amount',$mon,$yr,'$officer')");
	$sql4 =$link->query("insert into cashbook values(0, '$branchcode','$date','$teller','$time','$details','0','0','0','$amount',$mon,$yr,'$officer')");
	$sql =$link->query("insert into journal values(0,'$branchcode','$date','$debitcode','$debit','$amount','0','$mon','$yr','$officer')");
	$ssql =$link->query("insert into journal values(0,'$branchcode', '$date','$creditcode','$credit','0','$amount','$mon','$yr','$officer')");
	echo "<script>location:Accdashboard.php</script>";
	
	
}*/
//===========================================Journal Entry=====================================================================================
if (isset($_POST['Journal'])){
	session_start();
	$teller=$_POST['teller'];
	$date=date('Y-m-d');
	$amount=$_POST['amount'];
	$officer=$_SESSION['admin_name'];
	$details=$_POST['details'];
	$mode=$_POST['mode'];
	$debit=$_POST['debit'];
	$credit=$_POST['credit'];
	$bcode=$_SESSION['branchcode'];
	$mon=date('m');
	$yr=date('Y');
	$bankcode=getAccCode($link,$debit);
	
	//$empty=InsertJournal($link,$teller,$bcode,$date,$debit,$credit,$amount,$mon,$yr,$officer);
		$debitcode=getAccCode($link,$debit);
		$creditcode=getAccCode($link,$credit);
	
	$sql =$link->query("insert into journal values(0, '$date','$teller','$bcode','$debitcode','$debit','$amount','0','$mon','$yr','$officer')");
	$ssql =$link->query("insert into journal values(0, '$date','$teller','$bcode','$creditcode','$credit','0','$amount','$mon','$yr','$officer')");
	
	$empt=InsertCashbook($link,$bcode,$teller,$date,$details,$bankcode,'0',$amount,'0','0',$mon,$yr,$officer);
	if($mode=='CASH')
	{
	$events = "INSERT INTO journalentry(Date,BranchCode,VoucherNo,Details,Mode,Amount,BankCode,AccountCode,Month,Year,Officer) values('$date','$bcode','$teller','$details','$mode','$amount','$debit','$credit','$mon','$yr','$officer')";
	$results_Event = mysqli_query($link,$events);
	if($results_Event){
				header("location: journalcoment.php");} else {$result = "<div class='error'>Savings not Succesfull. Try again</div>";};
	}
	
}
//==============================================================================================================================================
	function InsertJournal($link,$teller,$bcode,$date,$debit,$credit,$amount,$mon,$yr,$officer){
		$debitcode=getAccCode($link,$debit);
		$creditcode=getAccCode($link,$credit);
		$query = "INSERT INTO journal(Date,TransCode,BranchCode,AccCode,Details,Debit,Credit,Month,Year,Officer) 		values('$date','$teller','$bcode','$debitcode','$debit','$amount','0','$mon','$yr','$officer')";
		$res = mysqli_query($link,$query);
		
		$query2 = "INSERT INTO journal(Date,TransCode,BranchCode,AccCode,Details,Debit,Credit,Month,Year,Officer) 		values('$date','$teller','$bcode','$creditcode','$credit','0','$amount','$mon','$yr','$officer')";
		$res2 = mysqli_query($link,$query2);
	
	return "";
	}
//======================================Cashbook==============================================================================================
function InsertCashbook($link,$bcode,$teller,$date,$details,$bankcode,$cheque,$cash,$cashw,$casht,$mon,$yr,$officer){
		$query = "INSERT INTO cashbook(Date,BranchCode,Code,Details,BF,Cheque,Cash,CashWithdraw,CashTransfer,Month,Year,Bankcode,Officer) 		values('$date','$bcode','$teller','$details','0','$cheque','$cash','$cashw','$casht','$mon','$yr','$bankcode','$officer')";
		$res = mysqli_query($link,$query);
	return "";
	}
//==================================================================================================================================================
if (isset($_POST['Transfer'])){
	session_start();
	$teller=$_POST['teller'];
	$date=date('Y-m-d');
	$amount=$_POST['amount'];
	$officer=$_SESSION['admin_name'];
	$details=$_POST['details'];
	$mode='Cash';
	$time=date("h:i a" );
	$debit=$_POST['debit'];
	$credit=$_POST['credit'];
	$brcode=$_POST['branch'];
	$branchcode=getBranchcode($link,$brcode);

	$mon=date('m');
	$yr=date('Y');
	$bankcode=getAccCode($link,$credit);
	
	//$empty=InsertJournal($link,$teller,$bcode,$date,$debit,$credit,$amount,$mon,$yr,$officer);
	$debitcode=getAccCode($link,$debit);
	$creditcode=getAccCode($link,$credit);
	
	
	$sql4 =$link->query("insert into cashbook values(0, '$branchcode','$date','$teller','$time','$details','0','0','$amount','0',$mon,$yr,'$officer')");
	$sql6 =$link->query("insert into bcashbook values(0, '$branchcode','$date','$teller','$details','0','$amount','0',$mon,$yr,'$officer')");
	$sql =$link->query("insert into journal values(0,'$branchcode','$date','$debitcode','$debit','$amount','0','$mon','$yr','$officer')");
	$ssql =$link->query("insert into journal values(0,'$branchcode', '$date','$creditcode','$credit','0','$amount','$mon','$yr','$officer')");
	echo "<script>location:Accdashboard.php</script>";
}
if (isset($_POST['deduction'])){
	session_start();
	$date=date('Y-m-d');
	$teller=rand(0,7729);
	$amount=$_POST['amount'];
	$officer=$_SESSION['admin_name'];
	$details=$_POST['details'];
	$debit=$_POST['debit'];
	$credit=$_POST['credit'];
	$bcode=$_SESSION['branchcode'];
	$mon=date('m');
	$yr=date('Y');
	$crcode=getAccCode($link,$credit);
	$dbcode=getAccCode($link,$debit);
	$bal= getAutoMember($link,$teller,$date,$bcode,$amount,$mon,$yr,$officer,$dbcode,$details);
	//$empty=InsertJournal($link,$teller,$bcode,$date,$debit,$credit,$bal,$mon,$yr,$officer);
	
	$sql =$link->query("insert into journal values(0, '$date','$teller','$bcode','$dbcode','$debit','$amount','0','$mon','$yr','$officer')");
	$ssql =$link->query("insert into journal values(0, '$date','$teller','$bcode','$crcode','$credit','0','$amount','$mon','$yr','$officer')");
	
	$empt=InsertCashbook($link,$bcode,$teller,$date,$details,$crcode,'0',$bal,'0','0',$mon,$yr,$officer);
	
	header("location: comment.php");
}
if (isset($_POST['deductions'])){
	session_start();
	$date=date('Y-m-d');
	$amount=$_POST['amount'];
	$teller=rand(0,7729);
	$code=$_POST['code'];
	$officer=$_SESSION['admin_name'];
	$details=$_POST['details'];
	$debit=$_POST['debit'];
	$credit=$_POST['credit'];
	$bcode=$_SESSION['branchcode'];
	$mon=date('m');
	$yr=date('Y');
	$name=getname($link,$code,$bcode);
	$crcode=getAccCode($link,$credit);
	$dbcode=getAccCode($link,$debit);
	
		$sql =$link->query("insert into journal values(0, '$date','$teller','$bcode','$dbcode','$debit','$amount','0','$mon','$yr','$officer')");
	$ssql =$link->query("insert into journal values(0, '$date','$teller','$bcode','$crcode','$credit','0','$amount','$mon','$yr','$officer')");
	
	$empt=InsertCashbook($link,$bcode,$teller,$date,$details,$crcode,'0',$amount,'0','0',$mon,$yr,$officer);
	$query = "INSERT INTO Deduction(BranchCode,TransCode,Date,AccountCode,MemberCode,Fullname,Details,Amount,Month,Year,Officer) 		values('$bcode','$teller','$date','$dbcode','$code','$name','$details','$amount','$mon','$yr','$officer')";
		$res = mysqli_query($link,$query);
	header("location: comment.php");
}
//==============================Register User=======================================================
if (isset($_POST['Authenticate'])){
	$code=$_POST['code'];
	$name=$_POST['name'];
	$branch=$_POST['branch'];
	$status=$_POST['status'];
	$bcode= getBranchcode($link,$branch);
	$cod='000'.$code;
if($status=='UNIVERSAL'){
	$query = "INSERT INTO login(BranchCode,MemberCode,Fullname,Username,Password,Usertype,Status) values('000','$code','$name','$code','0000','$status','YES')";
		$res = mysqli_query($link,$query);
}else{
	$query = "INSERT INTO login(BranchCode,MemberCode,Fullname,Username,Password,Usertype,Status) values('$bcode','$code','$name','$code','0000','$status','YES')";
		$res = mysqli_query($link,$query);
}
}
//====================================================================================================
function getAuth($pin){
		$result=mysql_query("select authentication from pinuser where pin='$pin'");
		$row=mysql_fetch_array($result);
		$auth= $row['authentication'];
		return $auth;
	}
	function getname($link,$id,$bcode){
		$query = "SELECT  * FROM registration WHERE MemberCode= '$id' and BranchCode='$bcode'";
	$res = mysqli_query($link,$query);
	$row_login = mysqli_fetch_assoc($res);
	$name =$row_login['Fullname'];
	return $name;
	}
	function getgender($id){
		$result=mysql_query("select * from student where studentno='$id'");
		$row=mysql_fetch_array($result);
		$gender=$row['gender'];
		return $gender;
	}
	function getAccCode($link,$accname){
		$result=mysqli_query($link,"select * from chart where glname='$accname'");
		$row=mysqli_fetch_array($result);
		$code=$row['glcode'];
		return $code;
	}
	
	
	function gettotno($class){
		$result=mysql_query("select * from student where class='$class'");
		$total = mysql_num_rows($result);
		return $total;
	}
	
	function getsubclasses(){
		$result=mysql_query("select * from class");
		$row=mysql_fetch_array($result);
		$class=$row['class'];
		return $class;
	}
	
	function getpercentage($id,$term,$session){
		$result=mysql_query("select * from score where studentno='$id' and term='$term' and session='$session'");
		$total = mysql_num_rows($result);
		$tagg=$total * 100;
		$agg=getaggre($id,$term,$session);
		$per=$agg * 100;
		$percent= $per / $tagg;
		return $percent."%";
	}
	
	function getid($name){
		$result=mysql_query("select * from student where fullname='$name'");
		$row=mysql_fetch_array($result);
		$id=$row['Memid'];
		return $id;
	}
	
		function getSMSstatua($term){
		$result=mysql_query("select * from sms where term='$term'");
		$row=mysql_fetch_array($result);
		$sts=$row['status'];
		return $sts;
	}
	function  getmaterial($link,$name,$bcode,$id){
	$reslt=mysqli_query($link,"SELECT * FROM tickets where Admin='$name' and BranchCode='$bcode' and Ticket='$id'");
		$row=mysqli_fetch_array($reslt);
		$doc= $row['Document'];
	if($doc ==""){
	}
	else{
		echo " <div class=\"temp_list\">
				      		<ul>
						  		    <li>
									    
									<font color=\"#FFFFFF\">".$row['Document']."</font><br><embed src=\"".$row['Document']."\" type=\"doc/txt\" style=\"height:20px;  width:100px; \"/><a href=".$row['Document'].">download</a>
									</li>
						  			
				    		</ul>	
				      </div>";}
}

	if (isset($_POST['assign'])){
	$class=$_POST['class'];
	$teacher=$_POST['teacher'];
	$staffid=getteacherid($teacher);
	$sql1="select * from classteacher where class='$class'";
	$res = mysql_query($sql1);
	$ress=mysql_fetch_array($res);
	if($ress > 0)
	{
		$update="update classteacher set staffid='$staffid', name='$teacher' where class='$class'";
		$reslt_event = mysql_query($update);
		if($reslt_event){ $result="Class Teacher Updated Succesfully";} else {$result = "<div class='error'>Clas Teacher not updated. Try again							</div>";}
	}
	else
	{
	
	$sql ="insert into classteacher values('$staffid','$teacher','$class')";
	$result_event = mysql_query($sql);
	if($result_event){ $result="Class Teacher Created Succesfully";} else {$result = "<div class='error'>Clas Teacher not created. Try again</div>";}
	
	}
	
	
		
}
//=============================================================create Sub===================================
if (isset($_POST['createsub'])){
	$class=$_POST['classes'];
	$alpha=$_POST['alpha'];
	$sql1="select * from class where class='$class'";
	$res = mysql_query($sql1);
	$ress=mysql_fetch_array($res);
	if($class == "" || $alpha == "")
	{
		$result="Fields Required";
	}
	 else if($ress > 0)
	{
		$result="Class Already Exist";
	}
	else
	{
	
	$sql ="insert into class(class,alphabet)values('$class','$alpha')";
	$result_event = mysql_query($sql);
	if($result_event){ $result="Class Created Succesfully";} else {$result = "<div class='error'>Clas not created. Try again</div>";}
	
	}
	
	
		
}
//==========================================================================================================
if (isset($_POST['confirm'])){
	$class=$_POST['class'];
	$sql="select * from student where currentclass='$class'";
	$amnt=gettotalbill($class);
	$res = mysql_query($sql);
	while($reply = mysql_fetch_array($res)){
		$studntno=$reply['studentno'];
		$term=getterm();
		$session=getsession();
		
		$sq="select * from payment where studentno='$studntno' and term='$term' and session='$session'";
		$ress = mysql_query($sq);
		$result=mysql_fetch_array($ress);
		if($result >0)
		{
			
		}else{
		$sql1 ="insert into payment values('$studntno','$amnt','0','$amnt','$class','$term','$session')";
		$result_event = mysql_query($sql1);
		}
	
	}
	
	
		
}
	

//==================================Determine Position=========================================================================

function getCPosition($pos){
		$result=mysql_query("select * from pos where number='$pos'");
		$row=mysql_fetch_array($result);
		$cpos=$row['status'];
		return $cpos;
	}

function getStdposition($class,$term,$session){
		$result=mysql_query("select * from aggregate where class='$class' and term='$term' and session='$session' ORDER BY agg DESC");
		$id=0;
		while($reply = mysql_fetch_array($result)){
			$stdno=$reply['studentno'];
			$agg=$reply['agg'];
			$term=$reply['term'];
			$sess=$reply['session'];
			$id+=1;
			$reslt=mysql_query("select * from position where studentno='$stdno' and term='$term' and session='$session'");
			$resp=mysql_fetch_array($reslt);
			
			if($resp > 0)
			{
				$results=mysql_query("update position set position='$id' where studentno='$stdno' and term='$term' and session='$session')");
			}
			else{
			
				$results=mysql_query("insert into position values('$stdno','$id','$term','$session')");
			}
		}
	}

function getInsertaggre($studid,$term,$session){
		$result=mysql_query("select * from score where studentno='$studid' and term='$term' and session='$session'");
		$agg=0;
		while($reply = mysql_fetch_array($result)){
			$ids=$reply['total'];
			$agg+=$ids;
		}
		return $agg;
	}

if (isset($_POST['Position'])){
	$class=$_POST['class'];
	$term=getterm();
	$session=getsession();
	$sql="select * from student where class='$class' and session='$session'";
	$result = mysql_query($sql);
		while($row = mysql_fetch_array($result)){
			$studentno=$row['studentno'];
			$agg=getInsertaggre($studentno,$term,$session);
		
			$check="select * from aggregate where studentno='$studentno' and term='$term' and session='$session'";
			$results = mysql_query($check);
			$val= mysql_fetch_array($results);
			if($val > 0)
			{
				$update="updat aggregate set agg=$agg where studentno='$studentno' and term='$term' and session='$session'";
				$ress = mysql_query($update);
				if($ress){ $res="Updated Succesfully";} else {$res = "<div class='error'>Not updated. Try again							</div>";}
			}
			else
			{
				$sql1="insert into aggregate values('$studentno',$agg,'$term','$session','$class')";
				$res = mysql_query($sql1);
				if($res){ $res="Position made Succesfully";} else {$res = "<div class='error'>Position not made. Try again									</div>";}
			}
		}
	getStdposition($class,$term,$session);
}

//=================================POST EXAM SCORE=============================================================================
if (isset($_POST['postexam'])){
	$stid=$_POST['studentid'];
	$stname=getname($stid);
	$gender=getgender($stid);
	$subject=$_POST['subject'];
	$class=$_POST['class'];
	$ca=$_POST['ca'];
	$subclass=getsubclass($stid);
	$term=getterm();
	$session=getsession();
	$exam=$_POST['exam'];
	$total=$ca + $exam;
	$grade=getgrade($total);
	$sql1="select * from score where studentno='$stid' and subject='$subject' and class='$class' and term='$term' and session='$session'";
	$res = mysql_query($sql1);
	$reply = mysql_fetch_array($res);
	
	
	if($reply > 0)
	{
		$update="update score set ca='$ca', exam='$exam', total='$total', grade='$grade' where studentno='$stid' and subject='$subject' and class='$class' and term='$term' and session='$session'";
		$reslt_event = mysql_query($update);
		if($reslt_event){ $result="Class Teacher Updated Succesfully";} else {$result = "<div class='error'>Clas Teacher not updated. Try again							</div>";}
	}
	else
	{
	
	$sql ="insert into score values('$stid','$stname','$gender','$subject','$class','$subclass',$ca,$exam,$total,'$grade','$term','$session','')";
	$result_event = mysql_query($sql);
	if($result_event){header("location: result_postings.php");} else {$result = "<div class='error'>Score not Inserted. Try again</div>";}
	
	}
	
		
}
	

//==============================================================================================================


function gettotfee($studid){
		$result=mysql_query("select * from payment where studentno='$studid'");
		$tot=0;
		while($reply = mysql_fetch_array($result)){
			$ids=$reply['totfees'];
			$tot+=$ids;
		}
		return $tot;
	}
	function getstudentpics($studid){
	$sql = "SELECT * FROM student where studentno='$studid'";
	$result = mysql_query($sql);
	while($reply = mysql_fetch_array($result)){
		$pics=$reply['picture'];
		return $pics;
	}
	}
	function getpaid($studid){
		$result=mysql_query("select * from payment where studentno='$studid'");
		$pay=0;
		while($reply = mysql_fetch_array($result)){
			$ids=$reply['amountpaid'];
			$pay+=$ids;
		}
		return $pay;
	}
	
	function getDailyStockQnt($bcode,$name,$date,$link){
		$result=mysqli_query($link,"select * from dailystockreport where name='$name' and BranchCode='$bcode' and date='$date'");
		$row=mysqli_fetch_array($result);
		$quan=$row['addstock'];
		return $quan;
	}

	function getDailyStockQntE($bcode,$name,$date,$link){
		$result=mysqli_query($link,"select * from dailyemptystock where name='$name' and BranchCode='$bcode' and date='$date'");
		$row=mysqli_fetch_array($result);
		$quan=$row['StockIN'];
		return $quan;
	}
	
	
	function getProductName($bcode,$name,$link){
		$result=mysqli_query($link,"select * from items where name='$name' and BranchCode='$bcode'");
		$row=mysqli_fetch_array($result);
		$pname=$row['name'];
		return $pname;
	}
	
	function getProductQnt($bcode,$name,$link){
		$result=mysqli_query($link,"select * from items where name='$name' and BranchCode='$bcode'");
		$row=mysqli_fetch_array($result);
		$quan=$row['quantity'];
		return $quan;
	}
	function getProductQntE($bcode,$name,$link){
		$result=mysqli_query($link,"select * from empty where name='$name' and BranchCode='$bcode'");
		$row=mysqli_fetch_array($result);
		$quan=$row['Quantity'];
		return $quan;
	}
	function getMemberSavings($link,$code,$bcode){
		$result=mysqli_query($link,"select * from savings where MemberCode='$code' and BranchCode='$bcode'");
		$bal=0;
		while($reply = mysqli_fetch_array($result)){
			$amnt=$reply['Credit'];
			$bal+=$amnt;
		}
		return $bal;
	}
	
	function getPassword($link,$mcode){
		$result=mysqli_query($link,"select * from login where MemberCode='$mcode'");
		$row=mysqli_fetch_array($result);
		$psg=$row['Password'];
		return $psd;
}

function getTypeCode($link,$typename){
		$result=mysqli_query($link,"select * from typecode where TypeName='$typename'");
		$row=mysqli_fetch_array($result);
		$tcode=$row['TypeCode'];
		return $tcode;
}
function getmemberid($link,$name){
	$sql = "SELECT * FROM login where Fullname='$name'";
	$result = mysqli_query($link,$sql);
	while($reply = mysqli_fetch_array($result)){
		$memcode=$reply['MemberCode'];
		return $memcode;
	}
}

//============================================Gettotal Bill===================================================
function getBranchAdmin($link,$bcode){
	$sql = "SELECT * FROM login where Usertype='Admin' and BranchCode='$bcode'";
	$result = mysqli_query($link,$sql);
	while($reply = mysqli_fetch_array($result)){
		echo "<option value=\"".$reply['Fullname']."\">".$reply['Fullname']."</option>";
	}
}
function getCategory($link){
	$sql = "SELECT * FROM category";
	$result = mysqli_query($link,$sql);
	while($reply = mysqli_fetch_array($result)){
		echo "<option value=\"".$reply['CategoryName']."\">".$reply['CategoryName']."</option>";
	}
}
//============================================================================================================
function getAmount($link,$branch,$name){
	
		$result=mysqli_query($link,"select * from items where BranchCode='$branch' and name='$name'");
		$row=mysqli_fetch_array($result);
		$amnt=$row['price1'];
		return $amnt;
	
		
}
function getstatus($link,$branch,$name){
	
	
	$val=$_POST['radio'];
	if($val=="radio1")
	{
	
		return "retail";
	}
	else
	{
		return "bulk";
	}
		
}
function getProductcode($link,$branch,$itname){
		$result=mysqli_query($link,"select * from items where BranchCode='$branch' and name='$itname'");
		$row=mysqli_fetch_array($result);
		$bcode=$row['code'];
		return $bcode;
}
function getAllProducts($link,$bcode){
	$sql = "SELECT * FROM items where BranchCode='$bcode' order by name ASC";
	$result = mysqli_query($link,$sql);
	while($reply = mysqli_fetch_array($result)){
		echo "<option value=\"".$reply['name']."\">".$reply['name']."</option>";
	}
}

function getBranches($link){
	$sql = "SELECT * FROM branch";
	$result = mysqli_query($link,$sql);
	while($reply = mysqli_fetch_array($result)){
		echo "<option value=\"".$reply['BranchName']."\">".$reply['BranchName']."</option>";
	}
}
function getItems($link,$bcode){
	$sql = "SELECT * FROM items where BranchCode='$bcode' order by id";
	$result = mysqli_query($link,$sql);
	while($reply = mysqli_fetch_array($result)){
		echo "<option value=\"".$reply['name']."\">".$reply['name']."</option>";
	}
}
function getAllCharts($link,$bcode){
	$sql = "SELECT * FROM chart";
	$result = mysqli_query($link,$sql);
	while($reply = mysqli_fetch_array($result)){
		echo "<option value=\"".$reply['glname']."\">".$reply['glname']."</option>";
	}
}
function OpenUnit1($link,$date,$bcode){
  $date=date('Y-m-d');
$mon=date('m');
$yr=date('Y');

      $result=mysqli_query($link,"select * from empty where BranchCode='$bcode' order by id ASC");
          $prev=0;
          while($reply = mysqli_fetch_array($result)){
            $name=$reply['name'];
            $quan=$reply['Quantity'];
            
            $sql =$link->query("insert into dailyemptystock values(0,'$date','$bcode','$name','$quan','0','0')");
            
            
          }
          
}
function getAllAcc($link,$val,$bcode){
	$sql = "SELECT * FROM chart where gltypecode='$val' and BranchCode='$bcode'";
	$result = mysqli_query($link,$sql);
	while($reply = mysqli_fetch_array($result)){
		echo "<option value=\"".$reply['glname']."\">".$reply['glname']."</option>";
	}
}
function getBranchcode($link,$branch){
		$result=mysqli_query($link,"select * from branch where BranchName='$branch'");
		$row=mysqli_fetch_array($result);
		$bcode=$row['BranchCode'];
		return $bcode;
}
function getBranchname($link,$bcode){
		$result=mysqli_query($link,"select * from branch where BranchCode='$bcode'");
		$row=mysqli_fetch_array($result);
		$name=$row['BranchName'];
		return $name;
}
if (isset($_POST['login'])){
	$branch =$_POST['branch'];
	$user =$_POST['username'];
	$pword = $_POST['password'];
	$bcode=getBranchcode($link,$branch);
	//$customer = mysql_real_escape_string($_POST['customer']);
		
	$sql = "SELECT * FROM login WHERE BranchCode='$bcode' and username = '$user' AND password = '$pword' and status='YES'";
	$login = mysqli_query($link,$sql) or die(mysql_error());
	
	
	$row_login = mysqli_fetch_assoc($login);
	$usert =$row_login['usertype'];
	$name =$row_login['fullname'];
//=====================================================================================
	
	if ($user = $row_login['username'] && $pword = $row_login['password']){
					if($usert == 'Sales')
					{
						session_start();
							$_SESSION['username'] = $row_login['username'];
							$_SESSION['password'] = $row_login['password'];		
							$_SESSION['admin_name'] =  $row_login['fullname'];
							$_SESSION['usertype'] =  $row_login['usertype'];
							$_SESSION['branchcode'] =  $row_login['BranchCode'];
							$_SESSION['branch'] =  $branch;
						header("location: DashboardSales.php");
					}
					else if($usert =='Admin')
					{
						session_start();
							$_SESSION['username'] = $row_login['username'];
							$_SESSION['password'] = $row_login['password'];		
							$_SESSION['admin_name'] =  $row_login['fullname'];
							$_SESSION['usertype'] =  $row_login['usertype'];
							$_SESSION['branchcode'] =  $row_login['BranchCode'];
							$_SESSION['branch'] =  $branch;
						header("location: dashboard.php");
					}
					else if($usert =='Account')
					{
						session_start();
							$_SESSION['username'] = $row_login['username'];
							$_SESSION['password'] = $row_login['password'];		
							$_SESSION['admin_name'] =  $row_login['fullname'];
							$_SESSION['usertype'] =  $row_login['usertype'];
							$_SESSION['branchcode'] =  $row_login['BranchCode'];
							$_SESSION['branch'] =  $branch;
						header("location: Accdashboard.php");
					}
					else if($usert =='Petrol')
					{
						session_start();
							$_SESSION['username'] = $row_login['username'];
							$_SESSION['password'] = $row_login['password'];		
							$_SESSION['admin_name'] =  $row_login['fullname'];
							$_SESSION['usertype'] =  $row_login['usertype'];
							$_SESSION['branchcode'] =  $row_login['BranchCode'];
							$_SESSION['branch'] =  $branch;
						header("location: DashboardOilandGas.php");
					}
					else
					{
						$result = "<h5 class=\"error\">You Are Not Authorized To This Potal !!!</h5>";
					}
			
				
	
	}
	
	else{
		$result = "<h5 class=\"error\">Wrong Username OR Password !!!</h5>";
	}
	
}

/* -------------------------------------------------------------------------- */


/*-----------------------------------------------------------------------------------------*/

//==================================Update Password=====================================
function chanegepwd($name,$newpass){
	if($newpass !="")
	{
		$events = "UPDATE login set password='$newpass' WHERE fullname='$name'";
		$result_event = mysql_query($events);
		if($result_event)
				{
					return $rese = "Password Succefully Chanded";
				}
				else{return $rese = "Password not change";}
	}
	else
	{
		return $rese = "Empty record";
	}
}
//======================================================================================

/*----------------------------------------------------------------------------------------*/
if (isset($_POST['staff_edit'])){	
	$surname = mysql_real_escape_string($_POST['surname']);
	$othername = mysql_real_escape_string($_POST['othername']);
	$designation = mysql_real_escape_string($_POST['des']);
	
	$pixy = substr(md5(uniqid()), 0,10);
	
	$pic = $_POST['big'];
	$picthumb = $_POST['thumb'];
	$proid = $_GET['proid'];
	
	
	
		if($surname == "" || $proid == ""){
		$rese = "<div class='error'>Some fields are empty</div>";} else {
		$events = "UPDATE staff SET surname='$surname', othername='$othername',  designation='$designation' WHERE staffid='$proid'";

	$result_event = mysql_query($events);
	if($result_event){$rese = "Staff Updated Successfully ";} else {$rese = "<div class='error'>Staff not Update. Try again</div>";}
		}
	
}
//=========================================Assignment Posting=================================================
function postassgnment($name){	
	$class = $_POST['class'];
	$subject = $_POST['subject'];
	$assgn = $_POST['ass'];
	$term=getterm();
	$sess=getsession();
	
	
	
		if($assgn == ""){
		return $rese = "<div class='error'>Some fields are empty</div>";} else {
		$sql="insert into assignment(class,subject,ass,term,session,teachername) values('$class','$subject','$assgn','$term','$sess','$name')";
		$result_event=mysql_query($sql);

	if($result_event){return $rese = "<div class='error'>Assignment Posted Succesfully</div>";} else { return $rese = "<div class='error'>Assignment not post. Try again</div>";}
		}
	
}
//====================================Comment Posting Begins================================================================
function postcomment($name,$com){	
	$term=getterm();
	$sess=getsession();
	
	
		if($com == ""){
		return $rese = "<div class='error'>Some fields are empty</div>";} else {
		$sql="update score set comment='$com' where name='$name' and term='$term' and session='$sess'";
		$result_event=mysql_query($sql);

	if($result_event){return $rese = "<div class='error'>Comment Posted Succesfully</div>";} else { return $rese = "<div class='error'>Comment 		not post. Try again</div>";}
		}
	
}
//============================================================================================================================

if (isset($_POST['student_edit'])){	
	$surname = mysql_real_escape_string($_POST['surname']);
	$othername = mysql_real_escape_string($_POST['othername']);
	$class = mysql_real_escape_string($_POST['class']);
	
	$pixy = substr(md5(uniqid()), 0,10);
	
	$pic = $_POST['big'];
	$picthumb = $_POST['thumb'];
	$proid = $_GET['proid'];
	
	
	
		if($surname == "" || $proid == ""){
		$rese = "<div class='error'>Some fields are empty</div>";} else {
		$events = "UPDATE student SET surname='$surname', othernames='$othername',  currentclass='$class' WHERE studentno='$proid'";

	$result_event = mysql_query($events);
	if($result_event){$rese = "Student Updated Successfully ";} else {$rese = "<div class='error'>Student not Update. Try again</div>";}
		}
	
}
//=================================================List of Books===============================
if (isset($_POST['postbook'])){	
	$class = $_POST['class'];
	$subject = $_POST['subject'];
	$book = $_POST['books'];
	$session=getsession();
	
	
	
		if($book == ""){
		$rese = "<div class='error'>Some fields are empty</div>";} else {
			
			$sql="select * from books where session='$session' and class='$class' and subject='$subject'";
			$result= mysql_query($sql);
			if($result >0)
			{
				$sql2="update books set books='$book' where session='$session' and class='$class' and subject='$subject'";
				$result2= mysql_query($sql2);
				if($result2){$rese = "Updated Correctly ";} else {$rese = "<div class='error'>Not updated. Try again</div>";}
			}
			else
			{
			
			
				$events = "insert into books values('$class','$subject','$book','$session')";

				$result_event = mysql_query($events);
				if($result_event){$rese = "Correctly Saved ";} else {$rese = "<div class='error'>Not saved. Try again</div>";}
			}
		}
}
//========================================================Get Pin Code=====================================================================
if (isset($_POST['getpin'])){	
	$max=$_POST['pins'];
	$exp = '/^[A-Za-z._%-]+@[A-Za-z.-]+\.[A-Za-z]$/';
  if($max=="")
  {
	  $rests = "Fill All Empty Boxes ";
  }
  else if(preg_match($exp,$max))
  {
	   $rests = "Invalid Parameters ";
	 }
  else
  {
	
	for($i=0; $i<$max ;$i++)
	{
		$pincod =  strtoupper(substr(md5(uniqid()), 0,12));
		$events = "insert into pincard(pinno,status)values('$pincod','NO')";

		$result_event = mysql_query($events);
	}
				
	if($result_event){$rests = "$max Pins Succesfully Generated";} else {$rests = "<div class='error'>Not generated. Try again</div>";}
  }
}
//=============================================================================================================================================
/*------------------------------------------------------------------------------------------*/
if (isset($_POST['update']))
{
	$name = $_POST['name'];
	$cat = $_POST['cat'];
	
	$sql ="update login SET usertype='$cat' where fullname='$name'";
	$result = mysql_query($sql);
	
		if($result)
		{
			
				$rese = "Record  Updated Succefully";
			
		}
		else
		{
			$rese = "Record Not Updated ";
		}
	
}

if (isset($_POST['updates']))
{
	$stat = $_POST['stat'];
	$cat = $_POST['cat'];
	
	$sql ="update login SET status='$stat' where usertype='$cat'";
	$result = mysql_query($sql);
	
		if($result)
		{
			
				$rese = "Record  Updated Succefully";
			
		}
		else
		{
			$rese = "Record Not Updated ";
		}
	
}


if (isset($_POST['updateacc'])) 
{
	$id = mysql_real_escape_string($_POST['iesid']);
	$name = mysql_real_escape_string($_POST['bname']);
	$acc = mysql_real_escape_string($_POST['acc']);
	
		$sql = "update registration set bankname ='$name',bacc_no='$acc' where iesnew='$id'";
		
		$result = mysql_query($sql);
		if($result)
		{
			
				$rese = "Account Changed Succefully";
			
		}
		else
		{
			$rese = "Account Not Updated ";
		}
}
if (isset($_POST['delete_staff'])){
	$id = mysql_real_escape_string($_POST['id']);
	$pic = $_POST['big'];
	$picthumb = $_POST['thumb'];
	
	if(file_exists($pic)){ unlink($pic);}
	if(file_exists($picthumb)){ unlink($picthumb);} 
	
	
		
	$event = "DELETE FROM staff WHERE staffid ='$id'";
	$result_event = mysql_query($event);
	
	$events = "DELETE FROM login WHERE memid ='$id'";
	$result_events = mysql_query($events);
	
	if($result_event){$rese = "Content Deleted Successfully"; header("location: staff_view.php");} else {$rese = "<div class='error'>Content not Deleted. Try again</div>";}
		
	}


if (isset($_POST['suspend_staff'])){
	$id = mysql_real_escape_string($_POST['id']);
		
	$event = "update login set status='NO' WHERE memid ='$id'";
	$result_event = mysql_query($event);
	
	if($result_event){$rese = "Content Suspended Successfully"; header("location: staff_view.php");} else {$rese = "<div class='error'>Content not Deleted. Try again</div>";}
		
	}
//========================================staff Reliefed========================================================
	if (isset($_POST['relief_staff'])){
	$id = mysql_real_escape_string($_POST['id']);
	
	$event = "update login set status='YES' WHERE memid ='$id'";
	$result_event = mysql_query($event);
	$rese="YES";
	if($result_event){$rese = "Content Has Been Reliefed "; header("location: staff_view.php");} else {$rese = "<div class='error'>Content not Deleted. Try again</div>";}
		
	}
/*--------------------------------------------------------------------------------------------*/

function product_disp(){
	$sql = "SELECT * FROM product";
	$result = mysql_query($sql);
	while($reply = mysql_fetch_array($result)){
		echo "<li>
		<a href=\"#\"><img src=\"".$reply['picture_thumb']."\" alt=\"\" width=\"135\" /></a>
				    	<div class=\"product-info\">
				    	  <div class=\"product-desc\">
			    		    <p>".$reply['product_name']."</p>
				    		<strong class=\"price\">N ".$reply['product_price']."</strong>
							<p>Quatity: ".$reply['product_qty']."</p>
							<input type=\"button\" value=\"Add to Cart\" onclick=\"addtocart(".$reply['product_id'].")\" class=\"cart-btn\" />
				    		</div>
				    	</div>
			    	</li>";
	}
}

	

function category_form(){
$sql_cat="SELECT DISTINCT * FROM category";
$result_cat = mysql_query($sql_cat);
while($row3 = mysql_fetch_array($result_cat))
  {
  echo "<option value=\"".$row3['category_name']."\">".$row3['category_name']."</option>";
  }
}

function getsubjects(){
$sql_cat="SELECT DISTINCT * FROM subjects";
$result_cat = mysql_query($sql_cat);
while($row3 = mysql_fetch_array($result_cat))
  {
  echo "<option value=\"".$row3['subject']."\">".$row3['subject']."</option>";
  }
}


function getallsubject($class){
$sql_cat="SELECT  * FROM subject where class='$class'";
$result_cat = mysql_query($sql_cat);
while($row3 = mysql_fetch_array($result_cat))
  {
  echo "<option value=\"".$row3['subject']."\">".$row3['subject']."</option>";
  }
}


function category(){
	$sql = "SELECT * FROM category";
	$result = mysql_query($sql);
	while($reply = mysql_fetch_array($result)){
		$sql2 = "SELECT * FROM product WHERE product_category = '".$reply['category_name']."'";
		$result2 = mysql_query($sql2);
		$total = mysql_num_rows($result2);
		echo "<li><a href=\"#\">".$reply['category_name']." (".$total.")</a></li>";
	}
}


	function transactiondetails(){
	$studentid = $_POST['transid'];
	$name=getmemid($studentid);
	$sql = "SELECT * FROM payment WHERE studentno = '$studentid'";
	$result = mysql_query($sql);
		
	echo " <h3>Payment Details</h3>
              <h3>&nbsp;</h3>
              <table width=\"90%\" border=\"0\">
                <tr>
                  <td><h3>Student ID</h3></td>
                  <td><h3>Fullname</h3></td>
                  <td><h3>Total Amount</h3></td>
				  <td><h3>Amount Paid</h3></td>
				  <td><h3>Balance</h3></td>
				  <td><h3>Term</h3></td>
				   <td><h3>Session</h3></td>
                </tr>";
	
	while($reply = mysql_fetch_array($result)){
		
		
	echo" 
                <tr>
                  <td><b>".$reply['studentno']."</b></td>
                  <td><b>".$name."</b></td>
                  <td><b><font color=#CC0000>".$reply['totfees']."</font></b></td>
				   <td><b><font color=#CC0000>".$reply['amountpaid']."</font></b></td>
                  <td><b><font color=#CC0000>".$reply['balance']."</font></b></td>
				   <td><b>".$reply['term']."</b></td>
				    <td><b>".$reply['session']."</b></td>
				  
				 
                </tr>";
				
	}
     echo        " </table>
              
<p><a href=\"".$_SERVER['PHP_SELF']."?transid=".$studentid."&&status_change=true\" >Make Payment</a></p>";

}
//=============================================================Display Courses uploaded==========================================================
function  material_disp($name){
	$reslt=mysql_query("SELECT * FROM coursereg where name='$name' and status='YES'");
		$row=mysql_fetch_array($reslt);
		$course= $row['course'];
	if($course ==""){
	}
	else{
	$sql = "SELECT * FROM courseupload where course='$course' || status='Non General'";
	$result = mysql_query($sql);
	while($reply = mysql_fetch_array($result)){
		echo " <div class=\"temp_list\">
				      		<ul>
						  		    <li>
									    
									<font color=\"#FFFFFF\">".$reply['title']."</font><br><embed src=\"".$reply['material']."\" type=\"application/pdf\" style=\"height:20px;  width:100px; \"/><a href=".$reply['material'].">download</a>
									</li>
						  			
				    		</ul>	
				      </div>";}
	}
}

//=====================================Media Dispay==========================================================================================================
function media_disp($days){
	$sql = "SELECT * FROM courseupload where status='General' and days='$days'";
	$result = mysql_query($sql);
	while($reply = mysql_fetch_array($result)){
		echo " <table>
          <tbody>
            <tr>
              <td bgcolor=\"#FFFFFF\">".$reply['title']."</td>
              <td bgcolor=\"#000000\"><a href=" .$reply['material']. ">".$reply['material']."</a></td>
            </tr>
           
          </tbody>
        </table>";
	}
}
//===========================================================VIDEO======================================================================================
function mediavideo_disp(){
	$ext='/.mp4/';
	$sql = "SELECT * FROM courseupload where status='General'";
	$result = mysql_query($sql);
	while($reply = mysql_fetch_array($result)){
		$course= $reply['material'];
		 if(preg_match($ext,$course)){
		echo " <table>
          <tbody>
            <tr>
              <td bgcolor=\"#FFFFFF\">".$reply['title']."</td>
              <td bgcolor=\"#000000\"><a href=" .$reply['material']. ">".$reply['material']."</a></td>
            </tr>
           
          </tbody>
        </table>";
		 }
	}
}
//===========================================================================================================================================================
function uploads_disp(){
	$sql = "SELECT * FROM otheruploads";
	$result = mysql_query($sql);
	while($reply = mysql_fetch_array($result)){
		echo " <div class=\"temp_list\">
				      		<ul>
						  		    <li><video style=\"height:70px;  width:200px; autoplay><source src=\"".$reply['details']."\" type=\"video/mp4\"><source src=\"movie.ogg\" type=\"video/ogg\"></li>
						  			
				    		</ul>	
				      </div>";
	}
}
//==============================================================All Prayers=================================================================================


//========================================================================================================================================================
function changestatus(){
	if(isset($_GET['status_change'])){
		if($_GET['status_change'] == "true"){
	$studentno = $_GET['transid'];
	$term=getterm();
	$session=getsession();
	$sql = "SELECT  * FROM payment WHERE studentno = '$studentno' and term='$term' and session='$session'";
	$result = mysql_query($sql);
	
	echo "
	<form id=\"Status_Change_Form\" name=\"Status_Change_Form\" method=\"post\" action=\"\">
			        <h3>Transaction Details Status Change</h3>
			        <p>&nbsp;</p>
				      <table width=\"95%\" border=\"0\" style=\"padding: 3px; border: 1px solid #F00;\">
				        <tr>
				          <td width=\"70\">&nbsp;</td>
				          <td width=\"250\">Order ID </td>
				          <td>&nbsp;</td>
				          <td>&nbsp;</td>
			            </tr>";
	
	while($reply = mysql_fetch_array($result)){
			echo	        "<tr>
				          <td>&nbsp;</td>
				          <td>".$reply['studentno']. "  ". "<font color=#006633><b> Total Balance </b></font>"." <b><font color=#990000> " . get_payrep_total($reply['studentno'])."</font></b></td>
						   
				          <td><label for=\"status\"></label>
				            <select name=\"status\" id=\"status\">
				              <option selected=\"selected\">Select</option>
				              <option value=\"Part-Payment\">Part-Payment</option>
							  <option value=\"Full-Payment\">Full-Payment</option>
	                      </select></td>
						  <td><label for=\"BankName\"></label>
				            <select name=\"BankName\" id=\"BankName\">
				              <option value=\"SKY BANK\">SKY BANK</option>
				              <option value=\"ZENITH BANK\">ZENITH BANK</option>
				              <option value=\"ACCESS BANK\">ACCESS BANK</option>
							  <option value=\"ACCESS BANK\">CASH ACCOUNT</option>
							  <option value=\"ACCESS BANK\">GTB</option>
							  <option value=\"ACCESS BANK\">FCMB</option>
							  <option value=\"ACCESS BANK\">WEMA BANK</option>
							  <option value=\"ACCESS BANK\">FIRST BANK</option>
							  <option value=\"ACCESS BANK\">UBA</option>
							  <option value=\"ACCESS BANK\">ECO BANK</option>
							  
	                      </select></td>
						  <td>
						  
						  <input type=\"text\" name=\"teller\" id=\"teller\" value=\"Teller No\"/> 
						 <font color=#CC0000><input type=\"text\" name=\"pay\" id=\"pay\" value=\"Amount\"/>
						   <input type=\"submit\" name=\"Payment\" id=\"Payment\" value=\"Make Payment\"/></td>
						 
				          <td>
						  <input type=\"hidden\" name=\"orderid\" value=\"".$reply['studentno']."\" /></td>
						  <input type=\"submit\" name=\"status_change\" id=\"status_change\" value=\"Change Status\" /></td>
						   
			            </tr>";
	}
				        
		     echo       "</table>
			        
		      </form>";
		}
	}else{ echo ""; }
}

		
?>