<?php
include('../include/session.php');
date_default_timezone_set('Africa/Khartoum');
$entryDate = date("Y-m-d H:i:s",time()-3600); 


$supplier_id = $_POST['supplier_id_text'];


$table_name = $_SESSION['db_prefix']."_suppliers";
$saved_supplier_query = "SELECT * FROM $table_name WHERE supplier_id = '".$supplier_id."' ";
$saved_supplier_result = mySQL_query($saved_supplier_query);
$saved_supplier_num = mysql_num_rows($saved_supplier_result);

$account_name_saved = mysql_result($saved_supplier_result, 0, 'account_name');
$credit_cash_saved = mysql_result($saved_supplier_result, 0, 'credit_cash');
$post_address_saved = mysql_result($saved_supplier_result, 0, 'post_address');
$post_place_saved = mysql_result($saved_supplier_result, 0, 'post_place');
$phys_address_saved = mysql_result($saved_supplier_result, 0, 'phys_address');
$phys_place_saved = mysql_result($saved_supplier_result, 0, 'phys_place');
$country_saved = mysql_result($saved_supplier_result, 0, 'country');
$phone_saved = mysql_result($saved_supplier_result, 0, 'phone');
$fax_saved = mysql_result($saved_supplier_result, 0, 'fax');
$VAT_no_saved = mysql_result($saved_supplier_result, 0, 'VAT_no');
$contact1_saved = mysql_result($saved_supplier_result, 0, 'contact1');
$cell1_saved = mysql_result($saved_supplier_result, 0, 'cell1');
$email1_saved = mysql_result($saved_supplier_result, 0, 'email1');
$contact2_saved = mysql_result($saved_supplier_result, 0, 'contact2');
$cell2_saved = mysql_result($saved_supplier_result, 0, 'cell2');
$email2_saved = mysql_result($saved_supplier_result, 0, 'email2');
$web_site_saved = mysql_result($saved_supplier_result, 0, 'web_site');
$notes_saved = mysql_result($saved_supplier_result, 0, 'notes');


$account_name = $_POST['account_name_text'];
$credit_cash = $_POST['credit_cash_select'];
$post_address = $_POST['post_address_text'];
$post_place = $_POST['post_place_select'];
$phys_address = $_POST['phys_address_text'];
$phys_place = $_POST['phys_place_select'];
$country = $_POST['country_select'];
$phone = $_POST['phone_text'];
$fax = $_POST['fax_text'];
$VAT_no = $_POST['vat_text'];
$contact1 = $_POST['contact1_text'];
$cell1 = $_POST['cell1_text'];
$email1 = $_POST['email1_text'];
$contact2 = $_POST['contact2_text'];
$cell2 = $_POST['cell2_text'];
$email2 = $_POST['email2_text'];
$web_site = $_POST['web_site_text'];
$notes = $_POST['notes_text'];


$table_name = $_SESSION['db_prefix']."_suppliers";
$supplier_query = "UPDATE $table_name SET account_name = '".$account_name."', credit_cash = '".$credit_cash."', post_address = '".$post_address."', post_place = '".$post_place."', phys_address = '".$phys_address."', phys_place = '".$phys_place."', country = '".$country."', phone = '".$phone."', fax = '".$fax."', VAT_no = '".$VAT_no."', contact1 = '".$contact1."', cell1 = '".$cell1."', email1 = '".$email1."', contact2 = '".$contact2."', cell2 = '".$cell2."', email2 = '".$email2."', web_site = '".$web_site."', notes = '".$notes."' WHERE supplier_id = '".$supplier_id."' ";
execsql($supplier_query);



$table_name = $_SESSION['db_prefix']."_tracking_store";

if ($account_name_saved!=$account_name) {
	    $trackingQuery = "INSERT INTO $table_name (entry_date, user_name, action, details_1, details_2, details_3, details_4) VALUES ('".$entryDate."' ,'".$_SESSION['username']."', '23', '".$supplier_id."' ,'".$account_name_saved."','".$account_name."','Account name' )";
		//echo '<br>id_number'.$trackingQuery;
			$trackingResult = mySQL_query($trackingQuery);
}

if ($credit_cash_saved!=$credit_cash) {
		$trackingQuery = "INSERT INTO $table_name (entry_date, user_name, action, details_1, details_2, details_3, details_4) VALUES ('".$entryDate."' ,'".$_SESSION['username']."', '23', '".$supplier_id."' ,'".$credit_cash_saved."','".$credit_cash."','Status' )";
		//echo '<br>emp_first_name'.$trackingQuery;
			$trackingResult = mySQL_query($trackingQuery);
}

if ($post_address_saved!=$post_address) {
	    $trackingQuery = "INSERT INTO $table_name (entry_date, user_name, action, details_1, details_2, details_3, details_4) VALUES ('".$entryDate."' ,'".$_SESSION['username']."', '23', '".$supplier_id."' ,'".$post_address_saved."','".$post_address."','Post address' )";
		//echo '<br>emp_last_name'.$trackingQuery;
			$trackingResult = mySQL_query($trackingQuery);
}

if ($post_place_saved!=$post_place) {
	    $trackingQuery = "INSERT INTO $table_name (entry_date, user_name, action, details_1, details_2, details_3, details_4) VALUES ('".$entryDate."' ,'".$_SESSION['username']."', '23', '".$supplier_id."' ,'".$post_place_saved."','".$post_place."','Post place' )";
		//echo '<br>birth_date'.$trackingQuery;
			$trackingResult = mySQL_query($trackingQuery);
}

if ($phys_address_saved!=$phys_address) {
	    $trackingQuery = "INSERT INTO $table_name (entry_date, user_name, action, details_1, details_2, details_3, details_4) VALUES ('".$entryDate."' ,'".$_SESSION['username']."', '23', '".$supplier_id."' ,'".$phys_address_saved."','".$phys_address."','Physical address' )";
		//echo '<br>gender'.$trackingQuery;
			$trackingResult = mySQL_query($trackingQuery);
}

if ($phys_place_saved!=$phys_place) {
	    $trackingQuery = "INSERT INTO $table_name (entry_date, user_name, action, details_1, details_2, details_3, details_4) VALUES ('".$entryDate."' ,'".$_SESSION['username']."', '23', '".$supplier_id."' ,'".$phys_place_saved."','".$phys_place."','Physical place' )";
		//echo '<br>birth_date'.$trackingQuery;
			$trackingResult = mySQL_query($trackingQuery);
}

if ($country_saved!=$country) {
	    $trackingQuery = "INSERT INTO $table_name (entry_date, user_name, action, details_1, details_2, details_3, details_4) VALUES ('".$entryDate."' ,'".$_SESSION['username']."', '23', '".$supplier_id."' ,'".$country_saved."','".$country."','Country' )";
		//echo '<br>bag_box'.$trackingQuery;
			$trackingResult = mySQL_query($trackingQuery);
}

if ($phone_saved!=$phone) {
	    $trackingQuery = "INSERT INTO $table_name (entry_date, user_name, action, details_1, details_2, details_3, details_4) VALUES ('".$entryDate."' ,'".$_SESSION['username']."', '23', '".$supplier_id."' ,'".$phone_saved."','".$phone."','Phone' )";
		//echo '<br>box_no'.$trackingQuery;
			$trackingResult = mySQL_query($trackingQuery);
}

if ($fax_saved!=$fax) {
	    $trackingQuery = "INSERT INTO $table_name (entry_date, user_name, action, details_1, details_2, details_3, details_4) VALUES ('".$entryDate."' ,'".$_SESSION['username']."', '23', '".$supplier_id."' ,'".$fax_saved."','".$fax."','Fax' )";
		//echo '<br>postal_place'.$trackingQuery;
			$trackingResult = mySQL_query($trackingQuery);
}

if ($VAT_no_saved!=$VAT_no) {
	    $trackingQuery = "INSERT INTO $table_name (entry_date, user_name, action, details_1, details_2, details_3, details_4) VALUES ('".$entryDate."' ,'".$_SESSION['username']."', '23', '".$supplier_id."' ,'".$VAT_no_saved."','".$VAT_no."','VAT no' )";
		//echo '<br>phys_address'.$trackingQuery;
			$trackingResult = mySQL_query($trackingQuery);
}

if ($contact1_saved!=$contact1) {
	    $trackingQuery = "INSERT INTO $table_name (entry_date, user_name, action, details_1, details_2, details_3, details_4) VALUES ('".$entryDate."' ,'".$_SESSION['username']."', '23', '".$supplier_id."' ,'".$contact1_saved."','".$contact1."','Contact 1' )";
		//echo '<br>phys_place'.$trackingQuery;
			$trackingResult = mySQL_query($trackingQuery);
}

if ($cell1_saved!=$cell1) {
	    $trackingQuery = "INSERT INTO $table_name (entry_date, user_name, action, details_1, details_2, details_3, details_4) VALUES ('".$entryDate."' ,'".$_SESSION['username']."', '23', '".$supplier_id."' ,'".$cell1_saved."','".$cell1."','Cell 1' )";
		//echo '<br>emergency_name'.$trackingQuery;
			$trackingResult = mySQL_query($trackingQuery);
}

if ($email1_saved!=$email1) {
	    $trackingQuery = "INSERT INTO $table_name (entry_date, user_name, action, details_1, details_2, details_3, details_4) VALUES ('".$entryDate."' ,'".$_SESSION['username']."', '23', '".$supplier_id."' ,'".$email1_saved."','".$email1."','email 1' )";
		//echo '<br>emergency_phone'.$trackingQuery;
			$trackingResult = mySQL_query($trackingQuery);
}

if ($contact2_saved!=$contact2) {
	    $trackingQuery = "INSERT INTO $table_name (entry_date, user_name, action, details_1, details_2, details_3, details_4) VALUES ('".$entryDate."' ,'".$_SESSION['username']."', '23', '".$supplier_id."' ,'".$contact2_saved."','".$contact2."','Contact 2' )";
		//echo '<br>position'.$trackingQuery;
			$trackingResult = mySQL_query($trackingQuery);
}

if ($email2_saved!=$email2) {
	    $trackingQuery = "INSERT INTO $table_name (entry_date, user_name, action, details_1, details_2, details_3, details_4) VALUES ('".$entryDate."' ,'".$_SESSION['username']."', '23', '".$supplier_id."' ,'".$email2_saved."','".$email2."','email 2' )";
		//echo '<br>pay_period'.$trackingQuery;
			$trackingResult = mySQL_query($trackingQuery);
}

if ($cell2!=$cell2) {
	    $trackingQuery = "INSERT INTO $table_name (entry_date, user_name, action, details_1, details_2, details_3, details_4) VALUES ('".$entryDate."' ,'".$_SESSION['username']."', '23', '".$supplier_id."' ,'".$cell2_saved."','".$cell2."','Cell 2' )";
		//echo '<br>rate'.$trackingQuery;
			$trackingResult = mySQL_query($trackingQuery);
}

if ($web_site_saved!=$web_site) {
	    $trackingQuery = "INSERT INTO $table_name (entry_date, user_name, action, details_1, details_2, details_3, details_4) VALUES ('".$entryDate."' ,'".$_SESSION['username']."', '23', '".$supplier_id."' ,'".$web_site_saved."','".$web_site."','Web_site' )";
		//echo '<br>bank'.$trackingQuery;
			$trackingResult = mySQL_query($trackingQuery);
}

if ($notes_saved!=$notes) {
	    $trackingQuery = "INSERT INTO $table_name (entry_date, user_name, action, details_1, details_2, details_3, details_4) VALUES ('".$entryDate."' ,'".$_SESSION['username']."', '23', '".$supplier_id."' ,'".$notes_saved."','".$notes."','Notes' )";
		//echo '<br>bank_branch'.$trackingQuery;
			$trackingResult = mySQL_query($trackingQuery);
}


if (isset($_POST['save_close_button']) )
	   { ?>
       <script>
	 		 window.location="../store/store_main.php?date=&branch=&subCatSelect=Tiles";
		</script>
        <?php		 
	   }
	   
	if (isset($_POST['save_button']) )
	   {  ?>
       <script>
	          window.location="supplier_details_edit.php?supplier_id=<?php echo $supplier_id?>"
	   </script>
        <?php		 
	   }
	   ?>

