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

$action = 'deal_add';
$msg = 'Please enter info for all * fields.';
$titleHeader = 'Post a new deal to Dealhot';
$go = false;
$Dealhot = new Dealhot("","","");

if(@$_POST["st"]=="go"){
  $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(
	 '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 posted a new deal successfully at: Dealhot';
	  header('location:deal_photo.php?photo_index=0&id='.$result_arr['productID']);
	}
	else if($result_arr["result"]=="fail"){
	  $msg = 'You have failed to post a new deal. Reason: '.$result_arr["error"];
	}
  }
}
?>