<?php 
include('../include/session.php');

date_default_timezone_set('Africa/Gaborone');
$entryDate = date("Y-m-d H:i:s", time()); 

$list_num = $_POST['list_num'];
$subCat = $_POST['subCat'];

$i=0;
while ($i<$list_num) {
	$store_item_id = $_POST['store_item_id'.$i];
	$present_value = $_POST['price_text'.$i];
	$present2_value = $_POST['price2_text'.$i];
	$edit_value = $_POST['price_edit'.$i];
	$edit2_value = $_POST['price2_edit'.$i];
	
	

	if ($present_value!=$edit_value) {
	       	$table_name = $_SESSION['db_prefix']."_tracking_store";
			$trackingQuery = "INSERT INTO $table_name (entry_date, user, action, details_1, details_2, details_3, details_4) VALUES ('".$entryDate."' ,'".$_SESSION['username']."', '22', '".$store_item_id."' ,'','".$present_value."','".$edit_value."' )";
			$trackingResult = mySQL_query($trackingQuery);
			
		$table_name = $_SESSION['db_prefix']."_store_items";
		$price_query = "UPDATE $table_name SET price = '".$edit_value."' WHERE store_item_id = '".$store_item_id."' ";
		execsql($price_query);	
	}
			
	if ($present2_value!=$edit2_value) {
	       	$table_name = $_SESSION['db_prefix']."_tracking_store";
			$trackingQuery = "INSERT INTO $table_name (entry_date, user, action, details_1, details_2, details_3, details_4) VALUES ('".$entryDate."' ,'".$_SESSION['username']."', '26', '".$store_item_id."' ,'','".$present2_value."','".$edit2_value."' )";
			$trackingResult = mySQL_query($trackingQuery);
			
		$table_name = $_SESSION['db_prefix']."_store_items";
		$price_query = "UPDATE $table_name SET price_2 = '".$edit2_value."' WHERE store_item_id = '".$store_item_id."' ";
		execsql($price_query);		
	}
	
		
		
	
	$i++;
}


		if (isset($_POST['save_close_button']) )
	   { ?>
       <script>
	  window.location="../store/store_main.php";
		</script>
        <?php		 
	   }
	          
       if (isset($_POST['save_button']) )
	   {  ?>
       <script>
	    window.location="timber_price_edit.php?sub_cat=<?php echo $subCat?>"
	   </script>
        <?php		 
	   }
	   ?>

