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

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


$new_ref_code = $_GET['ref_code_text'];
$store_item_id = $_GET['store_item_id_text'];


$table_name = $_SESSION['db_prefix']."_store_items";
$name_query = "SELECT  ref_code  FROM $table_name WHERE store_item_id = '".$store_item_id."' ";
$name_result = $con->query($name_query);
$row = mysqli_fetch_assoc($name_result);
$ref_code = $row['ref_code'];


$table_name = $_SESSION['db_prefix']."_store_items";
$update_query = "UPDATE $table_name SET ref_code = '".$new_ref_code."' WHERE store_item_id = '".$store_item_id."' ";
$update_result = $con->query($update_query);

$table_name = $_SESSION['db_prefix']."_tracking_store";
$tracking_query = "INSERT INTO $table_name (entry_date, user_name, action, details_1, details_2, details_3, details_4) VALUES ('".$entry_date."' ,'".$_SESSION['username']."', '19', '".$store_item_id."' , '".$ref_code."', '".$new_ref_code."', '' )";
$tracking_result = $con->query($tracking_query);


?>


<script language="javascript" type="text/javascript">
        window.location="../store/store_item_edit.php?store_item_id=<?php echo $store_item_id ?>&edit=0";
</script>