<?php
session_start();
if(!function_exists("_")){
  function _($text){
    return $text;
  }
}
require_once ("../../core/entity/ActiveLang.php");
require_once ("../../core/entity/Abandoned.php");
require_once ("../../core/utils/Utils.php");
require_once ("../../core/utils/Constants.php");
$utils = new Utils();
$lang = new ActiveLang();
$data = $_POST;
//unset($data[""])
$data = json_encode($_POST);
$abandoned = new Abandoned();
$abandoned->Salt = $utils->ReturnSessionVar("tmp");
$abandoned->FullData = $data;
if(count($abandoned->GetBySalt()) == 0){
  $abandoned->InsertRecord();
}else{
  $abandoned->UpdateRecord();
}
$current = json_decode($_SESSION["order"], true);
if($current == null){
    $current = array(
      "client" => "",
      "files" => 0,
      "type" => 0,
      "addon" => 0,
      "word" => "",
      "delivery" => "",
      "total-words" => "",
      "total" => 0,
    );
}

$price=0;

if($_POST["FromLang"]!="" && $_POST["ToLang"]!="" && $_POST["Words"]>0 ){
  $lang->Id = $_POST["FromLang"];
  $data = $lang->GetRecord();
  $from = $utils->getNameTranslation($data["LangName"]);
  $lang->Id = $_POST["ToLang"];
  $data = $lang->GetRecord();
  $to = $utils->getNameTranslation($data["LangName"]);
  $price = $lang->GetRecordPricing($_POST["FromLang"], $_POST["ToLang"], $_POST["Words"]);
}

$words = $_POST["Words"];
$cert = ($_POST["Certification"] == "1"? $CERTIFIED_COST:1);
$urg = (isset($_POST["Urgent"]) ? $URGENT_COST:1);
echo $price." * ".$cert." * ".$urg;
$total = round($price*$cert*$urg, 2);

$current = array(
  "client" => $_POST["FullName"],
  "files" => count($_POST["File"]),
  "type" => $_POST["Certification"],
  "addon" => (isset($_POST["Urgent"])?_("Trabajo urgente"):""),
  "delivery" => $_POST["Delivery"],
  "word" => $_POST["Words"]." "._("páginas")." (".$from." - ".$to.")",
  "total-words" => $_POST["Words"],
  "total" => $total,
  "only-quote" => ($price==-1)
);
$_SESSION["order"] = json_encode($current);
