<?PHP

ob_start();

session_start();

include 'connect.php';

if(isset($_SESSION['adminemail']))

{

$user=$_SESSION['adminemail'];



$gtp=mysql_query("select * from admin where username='$user'");

$gtp1=mysql_fetch_array($gtp);



include 'top.php';

?>







			<div class="main-content">

				<div class="main-content-inner">

					<div class="breadcrumbs ace-save-state" id="breadcrumbs">

						<ul class="breadcrumb">

							<li>

								<i class="ace-icon fa fa-home home-icon"></i>

								<a href="#">Home</a>

							</li>

							<li class="active">Supplier</li>

						</ul><!-- /.breadcrumb -->

					</div>



					<div class="page-content">

			



						<div class="page-header">

                        

<?php



$aca=mysql_query("select * from financial where user='$user' order by ID desc");

$aca1=mysql_fetch_array($aca);



$financial=$aca1['financial'];



?>

                        

                        <table style="width:100%;">

                        

                        <tr><td style="width:50%;">

                        

							<h1>

								Supplier

							</h1>

                            

                            </td>

                            

                            <td style="width:50%; text-align:right; padding-right:15px; font-size:15px;">

                            

                            <i class="fa fa-calendar"></i>&nbsp; <?php echo $financial; ?>

                            

                            </td></tr></table>

                            

						</div><!-- /.page-header -->



						<div class="row">

							<div class="col-xs-12">

                            

								<!-- PAGE CONTENT BEGINS -->





<script src="assets/js/jquery.js"></script>



<script>

	

jQuery(function($){

		   

	// simple jQuery validation script

	$('#course').submit(function(){

		

		var valid = true;

		var errormsg = 'This field is required!';

		var errorcn = 'error';

		

		$('.' + errorcn, this).remove();			

		

		$('#required', this).each(function(){

			var parent = $(this).parent();

			if( $(this).val() == '' ){

				var msg = $(this).attr('title');

				msg = (msg != '') ? msg : errormsg;

				$('<span style="font-size:13px;color:#FF0000; padding-left:3px;" class="'+ errorcn +'">'+ msg +'</span>')

					.appendTo(parent)

					.fadeIn('fast')

					.click(function(){ $(this).remove(); });

				valid = false;

			};

		});

		

		return valid;

		

		$('button:submit').prop('disabled', true);

		

	});

	

});	



</script>







<?php



if(isset($_GET['id']))

{



$id=$_GET['id'];



if(isset($_POST['submit']))

{



$id=$_POST['id'];



$name = $_POST['name'];



$address = $_POST['address'];



$phone = $_POST['phone'];



$mail=$_POST['mail'];



$gst=$_POST['gst'];



$state=$_POST['state'];



$code=$_POST['code'];



// now we insert it into the database



$date=date('Y-m-d',strtotime($date));



if($name)

{ 



$in= "update supplier set name='$name',address='$address',phone='$phone',email='$mail',gst='$gst',state='$state',code='$code' where ID='$id'";

$in1 = mysql_query($in) or die(mysql_error());



if($in1)

{



 header("location:viewsupplier.php?s=1");



}



}



else

{



 header("location:viewsupplier.php?s=2");



}



}



else

{



$ex=mysql_query("select * from supplier where ID='".$id."'");

$ex1=mysql_fetch_array($ex);



echo'<form id="course" action="viewsupplier.php?id='.$id.'" method="post">



<input type="hidden" name="id" value="'.$id.'" />



<table width="70%" style="margin:auto; line-height:35px;">



<tr><td width="32%">Name <span class="red">*</span></td><td width="11">:</td><td><input type="text" name="name" id="required" title="*" value="'.$ex1['name'].'" autocomplete="off" /></td></tr>



<tr><td>Address <span class="red">*</span></td><td>:</td><td><textarea name="address" id="required" title="*" style="width:220px; height:75px;">'.$ex1['address'].'</textarea></td></tr>



<tr><td>Contact </td><td>:</td><td><input autocomplete="off" type="text" name="phone" value="'.$ex1['phone'].'" autocomplete="off" /></td></tr>



<tr><td>Email </td><td>:</td><td><input autocomplete="off" type="text" name="mail" value="'.$ex1['email'].'" autocomplete="off" /></td></tr>



<tr><td>GST No. </td><td>:</td><td><input autocomplete="off" type="text" name="gst" value="'.$ex1['gst'].'" autocomplete="off" /></td></tr>



<tr><td>State <span class="red">*</span></td><td>:</td><td><input autocomplete="off" type="text" name="state" id="required" title="*" value="'.$ex1['state'].'" autocomplete="off" /></td></tr>



<tr><td>State Code <span class="red">*</span></td><td>:</td><td><input autocomplete="off" type="text" name="code" id="required" title="*" value="'.$ex1['code'].'" autocomplete="off" /></td></tr>



<tr><td colspan="3" style="text-align:center; padding-top:7px;"><button type="submit" name="submit" class="btn btn-sm btn-primary">Submit</button></td></tr>



</table>



</form>';



}



}



else

	{

		

	

		

		

	if (isset($_GET['s'])) 	

	{

	 $status=$_GET['s'];

		

		 if($status=='1')

		 {

			 echo'<div class="alert alert-block alert-success">

									<button type="button" class="close" data-dismiss="alert">

										<i class="ace-icon fa fa-times"></i>

									</button>

						Values Edited Successfully.

				  </div>';				  

		 }

		 if($status=='7')

		 {

			 echo'<div class="alert alert-block alert-success">

									<button type="button" class="close" data-dismiss="alert">

										<i class="ace-icon fa fa-times"></i>

									</button>

						Values Deleted Successfully.

				  </div>';				  

		 }

	}		





echo'<table style="width:99%; margin:11px auto 10px auto;">

                                        

                                        <tr><td style="width:20%;">

                                        <a href="supplier.php"><button class="btn btn-minier btn-info">+ Add Supplier</button></a>

                                        </td>

                                        

                                        <td style="width:50%;"></td>

                                        

                                        <td style="width:30%;">

                                        

                                        </td>

                                        

                                        </tr>

                                        

                                        </table>';



	echo"<table id='dynamic-table' class='table table-striped table-bordered table-hover'>



	<thead><th width='20%'>Name</th><th width='30%'>Address</th><th>Contact</th><th width='15%'>GST No.</th><th style='width:10%;'>Edit</th></thead>";



	$getsite3="select * from supplier order by name asc";

	$getsite4=mysql_query($getsite3) or die("Could not get");

	$sno=0;

	while($getsite5=mysql_fetch_array($getsite4))

	{

		$sno=$sno+1;

		

		echo"<tr><td>".$getsite5['name']."</td><td>".$getsite5['address']."</td>

		<td>".$getsite5['phone']."</td><td>".$getsite5['gst']."</td><td>

		

														<div class='hidden-sm hidden-xs btn-group'>";

																

															if($gtp1['type']!='staff')

															{

															echo"<a href='viewsupplier.php?id=".$getsite5['ID']."' title='Edit'>

																<i class='ace-icon fa fa-pencil bigger-100 green'></i></a> &nbsp;

																

															<a href='del.php?id=".$getsite5['ID']."&desc=supplier' title='Delete'>

																<i class='ace-icon fa fa-trash-o bigger-100 grey'></i></a>";

															}

															

														 echo"</div>					  

		</td></tr>";



		}



		echo "</table>";



	}



?>



                                            

                                            							



										<!-- PAGE CONTENT ENDS -->

									</div><!-- /.col -->

								</div><!-- /.row -->

							</div><!-- /.page-content -->

						</div>

					</div><!-- /.main-content -->





<?php

include 'bottom.php';

}

else

{



 header("location:login.php");

}

ob_flush();

?>

