<?php
/*=======================================================================
 *
 * show_tracking_id_info.php
 *
 * Autor: Carsten Annacker
 *
 =======================================================================*/

include_once("../include/global.inc.php");
include_once("../include/auth.inc.php");
define("LOG_NAME", "show_tracking_id_info.php");
include_once("../tools/edi.inc.php");
$jb_ids_special = $jb_idA[$hq_id]["STBX_SAME"] . "," . $jb_idA[$hq_id]["STBX_TIMED"] . "," .  $jb_idA[$hq_id]["STBX_NEXT"];

list ($f_id, $jb_id) = getHttpVars(array("f_id","jb_id"));
if (trim($jb_id) == "")
  $jb_id = $jb_ids_special;

function get_name() {
  global $db, $f_id, $jb_id, $jb_ids_special, $usr_id;

  $retVal = "$f_id - ";
  $sqlquery = "SELECT tr.tr_sort, tr_comp, tr_comp2, tr_person, tr_phone, ad_street, tr_hsno, ad_zipcode, ad_city" .
    " FROM tourarticle AS ta, tour AS tr, address AS ad WHERE trat_serialno = '$f_id' AND ta.jb_id = tr.jb_id AND ta.jb_id IN ($jb_id) AND ta.tr_sort = tr.tr_sort AND ta.tr_sort > 1 AND tr.ad_id = ad.ad_id";
  $res = $db->query($sqlquery) or die($sqlquery);
  if (DB::isError($res)) die ("$PHP_SELF: [$sqlquery] " . $res->getMessage());
  if ($row = $res->fetch_assoc()):
    $retVal .= $row["tr_comp2"];    
    if ($jb_id == $jb_ids_special):
      $retVal .= " - lfd. Nr.: " . $row["tr_sort"];
    endif;
    $retVal .= "<br>\n<br>\n";
    $retVal .= $row["tr_comp"] . "<br>\n";
    if (trim($row["tr_person"]) != ""):
      $retVal .= $row["tr_person"] . "<br>\n";
    endif;
    $retVal .= $row["ad_street"] . " " . $row["tr_hsno"] . "<br>\n";
    $retVal .= $row["ad_zipcode"] . " " . $row["ad_city"] . "<br>\n<br>\n";
    if (trim($row["tr_phone"]) != ""):
      $retVal .= "Tel.: " . $row["tr_phone"] . "<br>\n<br>\n";
    endif;
  endif;
  $res->free();  
  
  $sqlquery = "SELECT ec_inv_no, ec_weight, ec_moa3, ec_dim FROM phoenix_log.edi_consignee WHERE ec_track_id = '$f_id'";
  $res = $db->query($sqlquery);
  if (DB::isError($res)) die ("$PHP_SELF: [$sqlquery] " . $res->getMessage());
  if ($row = $res->fetch_assoc()):
    $retVal .= $row["ec_inv_no"] . "<br>\n";
    $p = xml_parser_create();
    xml_parse_into_struct($p, $row["ec_moa3"], $vals, $index);
    xml_parser_free($p);
    if ($usr_id == 300001):
      $retVal .= "Wert (netto): " . $vals[5]["value"] . " &euro;<br>\n";
    endif;
    if (substr($row["ec_weight"], 0, 1) == "."):
      $row["ec_weight"] = "0" . $row["ec_weight"];
    endif;
    $retVal .= "Gewicht (brutto): " . str_replace(".", ",", $row["ec_weight"]) . " kg<br>\n";
    $p = xml_parser_create();
    xml_parse_into_struct($p, $row["ec_dim"], $vals, $index);
    xml_parser_free($p);
    $retVal .= "LxBxH (cm):" . str_replace(".", ",", $vals[8]["value"]) . "x" . str_replace(".", ",", $vals[11]["value"]) . "x" . str_replace(".", ",", $vals[14]["value"]) . "<br>\n";
  endif;
  $res->free();  

  if ($usr_id == 300001):
    $sqlquery = "SELECT ep_ven_no, ep_pci FROM phoenix_log.edi_consignee, phoenix_log.edi_package WHERE ec_track_id = '$f_id' AND phoenix_log.edi_consignee.ec_inv_no = phoenix_log.edi_package.ec_inv_no";
    $res = $db->query($sqlquery);
    if (DB::isError($res)) die ("$PHP_SELF: [$sqlquery] " . $res->getMessage());
    $retVal .= "<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" vspace=\"0\" hspace=\"0\">";
    while ($row = $res->fetch_assoc()):
      $p = xml_parser_create();
      xml_parse_into_struct($p, str_replace("&", "&amp;", $row["ep_pci"]), $vals, $index);
      xml_parser_free($p);
      $retVal .= "<tr><td valign=top>(" . str_replace(" ", "&nbsp;", trim($vals[5]["value"])) . "</td><td valign=top>&nbsp;<a href=http://www.amazon.de/s/field-keywords=" . $row["ep_ven_no"] . " target=_blank>" . $row["ep_ven_no"] . "</a></td>" .
      "<td align=right valign=top>&nbsp;" . trim($vals[14]["value"]) . "&nbsp;x</td><td align=right valign=top>&nbsp;" . trim($vals[20]["value"]) . "&nbsp;€&nbsp;=</td><td align=right valign=top>&nbsp;" . trim($vals[23]["value"]) . "&nbsp;€)</td></tr>";
    endwhile;
    $retVal .= "</table>";
    $res->free();
  endif;
  return $retVal;
}
?>

<html>

<head>
<title><?php echo $pageTitel ?></title>

<link rel="stylesheet" type="text/css" href="../css/phoenix.css">
<style type="text/css">
  <?php include_once ("../css/navigation.css.php"); ?>
</style>
</head>

<body>

<div class="maincontent" name="maincontent" id="maincontent">

  <?php echo htmlDivLineSpacer("15px"); ?>

  <div>
    <?php echo get_name(); ?>
    <br>
  </div>
  <?php echo htmlDivLineSpacer("5px"); ?>
  
  <div align=center>
    <input type="button" class="button_enabled" value="Schließen" onClick="self.close()" accesskey="s">&nbsp;
  </div>
  <?php echo htmlDivLineSpacer("15px"); ?>

</div>
</body>

</html>