<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<?php
 include("db.php");
   $get_id=$_GET['editID'];
    
   $table=$_GET['table'];
   
  $information_sql="select * from `$table` where id='$get_id'";
  $information_query= $db->query($information_sql);
  $information_row=$information_query->fetch_array();
  
  $retriveName=$information_row['name'];
  $retrive_fname=$information_row['fname'];
  $retriveidphone=$information_row['phone'];
  $retriveidaddress=$information_row['address'];
  $retriveiddescription=$information_row['description'];
  
?>  
<html>
<head>
	<title>ویرایش اطلاعات مشتری</title>
	 
	<link rel="stylesheet" type="text/css" href="../css/style.css">
   <script src="dist/sweetalert-dev.js"></script>
  <link rel="stylesheet" href="dist/sweetalert.css">  
</head>
<body>

	<div id="wrap">
		 
		<div id="contentt">
			 
			<div id="menu">
				<?php  //include("menu.php") ;   ?>
			</div>
		    <div id="matlab" >
			<div id="title"><p>ویرایش اطلاعات مشتری</p> </div>
			<div id="picture">
					<table border="0" width="400px">
						<tr>
							<td style="width:180px;"><img src="../img/customer_edit.png" width="150px" height="120px">  </td>
							<td > </td>
						</tr>
					</table>
			   </div>
		    	<form method="post" action="">
               <table border="0"   id="rgistera_cart" width="800px" class="font">
		    		<tr>
						<td style="width:190px">&nbsp;</td>
		    			<th style="width:150px">نام مشتری </th>
						<td style="width:250px" ><input type="text" name="customerName"   value='<?php  echo $retriveName;   ?>'></td>
						<td style="width:280px;">
							 
						 </td>
		    		</tr>
					<tr>
						<td style="width:190px">&nbsp;</td>
		    			<th style="width:150px">تخلص </th>
						<td style="width:250px" ><input type="text" name="fname"   value='<?php  echo $retrive_fname;   ?>'></td>
						<td style="width:280px;">
							 
						 </td>
		    		</tr>
					<tr>
						<td style="width:190px">&nbsp;</td>
		    			<th style="width:150px">شماره تماس </th>
						<td style="width:250px" ><input type="text" name="call"   value='<?php  echo $retriveidphone;   ?>'></td>
						<td style="width:280px;">
							 
						 </td>
		    		</tr>
					<tr>
						<td style="width:190px">&nbsp;</td>
		    			<th style="width:150px">آدرس </th>
						<td style="width:250px" ><input type="text" name="address"   value='<?php  echo $retriveidaddress;   ?>'></td>
						<td style="width:280px;">
							 
						 </td>
		    		</tr>
					 
					<tr>
						<td style="width:190px">&nbsp;</td>
		    			<th style="width:150px">توضیحات</th>
						<td style="width:250px"><textarea rows="3" cols="23"  name="description"  ><?php echo $retriveiddescription;  ?></textarea></td>
						<td style="width:280px;"> </td> 
		    		</tr>
					<tr>
						<td style="width:190px">&nbsp;</td>
		    			<th style="width:150px"> </th>
						<td style="width:230px"> 
						    <input type="submit" id="save"   name="save"  value="ذخیره">
							<input type="submit" id="back"   name="back"  value="انصراف">
							
						</td>
						<td style="width:300px;"> </td> 
		    		</tr>
                    
		    	</table>
		    	 
				</form>
		    </div>


		</div>
		 
	</div>
</body>
</html>
<?php
if($_POST['back']){
  header("location:../add_customer.php");
}
if($_POST['save']){
$customerName=$_POST['customerName'];
$fname=$_POST['fname'];
$call=$_POST['call'];
$address=$_POST['address'];
$description=$_POST['description'];
 
		if(strlen(trim($customerName))==0   ){
		echo' <script>
					sweetAlert("اخطار...", "لطفا نام را وارد کنید", "error");
			   </script>'; 
		die;


		}
	   //.....................................................Estimate
	   /* $checkExistingSql="select * from customers where name='$customerName'";
	   $checkExistingQuery=$db ->query($checkExistingSql);
	   $checkExistingRow=$checkExistingQuery ->fetch_array();
	   $checkExisting=$checkExistingRow['name'];
	 
		if(isset($checkExisting)){
	 
		echo' <script>
					sweetAlert("اخطار...", "اطلاعات وارده در سیستم موجود است", "error");
			   </script>'; 
			 die;
		} */
	   //....................................................End of Estimate
	   //....................................................Update Measure
	   $updateCustomer_sql="update `customers` set name='$customerName',fname='$fname',phone='$call',address='$address',description='$description' where id='$get_id'";
	   $updateCustomer_query= $db ->query($updateCustomer_sql);
	     		  
		 echo' <script>
					 
					
				   swal("ذخیره موفق!", "اطلاعات وارده با موفقیت ثبت سیستم شد", "success")
				</script>';
	   echo '<meta http-equiv="refresh" content ="1; url=../add_customer.php" >';
	  echo  "<span style='color: #FFF'>Your Change Done</span>";
	   die;
	   //..................................................................
		
	 
		 
}



?>