<?php
include("src/Dealhot.php");
include("config.php");

$msg = 'You can update this deal';
$titleHeader = 'Edit a deal';
$deleted = false;
$Dealhot = new Dealhot("","","");

if(@$_POST["submit"]=="Update"){
  $action = 'deal_edit';
  $id = $_POST['id'];
  $deal_type = $_POST['deal_type'];
  $start_date = $_POST['start_date'];
  $end_date = $_POST['end_date'];
  $title = $_POST['title'];
  $keyinfo = $_POST['keyinfo'];
  $des = $_POST['des'];
  $wty = $_POST['wty'];
  $price = $_POST['price'];
  $price_other = $_POST['price_other'];
  $ETA = $_POST['ETA'];
  $ini_quantity = $_POST['ini_quantity'];
  $qty_max = $_POST['qty_max'];
  if($deal_type=="" || $start_date=="" || $end_date=="" || $title=="" || $keyinfo=="" || $des=="" || $wty=="" || $price=="" || $price_other=="" || $ETA=="" || $ini_quantity=="" || $qty_max==""){
    $msg = 'You need to enter all required info for * field';
  }
  else{
    $rest_data = array(
     'productID'=>$id,
     'deal_type' => $deal_type,
     'start_date'=> $start_date,
     'end_date'=> $end_date,
     'title'=> $title,
     'keyinfo'=> $keyinfo,
     'des'=> $Dealhot->str_norm($des),
     'wty'=> $Dealhot->str_norm($wty),
     'price'=> $price,
     'price_other'=> $price_other,
     'ETA'=> $ETA,
     'ini_quantity'=> $ini_quantity,
     'qty_max'=> $qty_max
    ); 
    
    $Dealhot = new Dealhot($auth_arr,$action,$rest_data);
    $result_arr = $Dealhot->go();
    $go = true;
    
    if($result_arr["result"]=="success")
       $msg = 'You have updated the deal successfully';
    else if($result_arr["result"]=="fail")
       $msg = 'You have failed to update the deal. Reason: '.$result_arr["error"];
  }
}
?>