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

include_once("../include/caglobal.inc.php");
include_once("../include/global.inc.php");
include_once ("../include/auth.inc.php");
//if ($phpVersion >= "7.0"):
//  require_once("../PEAR/HTML/Template/IT.php");
//else:
//  require_once("HTML/IT.php");
//endif;

getSecHttpVars("1", array("csc_id_orderer"));
list ($what_is_this, $reload_couriers) = getHttpVars(array("what_is_this", "reload_couriers"));
if ($csc_id_orderer == "" && $csc_id_orderer != '0') reportDie ("$PHP_SELF: Parameter 'csc_id_orderer' fehlt!", false);
if ($csc_id_orderer != '0'):
  // Kundenaufrag
  $cs_id = getFieldValueFromId("costcenter", "csc_id", "$csc_id_orderer", "cs_id");
  $cmp_id = getFieldValueFromId("customer", "cs_id", "$cs_id", "cmp_id");
  $cmp_comp = getFieldValueFromId("company", "cmp_id", "$cmp_id", "cmp_comp");
  $csc_name = getFieldValueFromId("costcenter", "csc_id", "$csc_id_orderer", "csc_name");
else:
  // Zentralenauftrag
  $hq_id = $HTTP_SESSION_VARS['hq_id'];
  $cmp_id = getFieldValueFromId("headquarters", "hq_id", "$hq_id", "cmp_id");
  $cmp_comp = getFieldValueFromId("company", "cmp_id", "$cmp_id", "cmp_comp");
  $csc_name = getFieldValueFromId("company", "cmp_id", "$cmp_id", "cmp_comp2");
endif;

//if ($phpVersion >= "7.0"):
//  $tpl = new HTML_Template_IT();
//else:
//  $tpl = new IntegratedTemplate();
//endif;
//$tpl->loadTemplatefile("job_header.tpl.htm", true, true);
$output = file_get_contents("job_header.tpl.htm");
//$tpl->setCurrentBlock("javascript");

// $reload_couriers ist nur beim ersten Aufruf nicht gesetzt
if ($reload_couriers == "1"):
  include_once("job_courier.inc.php");
  $output = str_replace("{_cr_id_order_list_}",
    "function updateCr_id_order_list(){\n" .
    "var cr_id_order_list = new Array();\n" .
    $cr_id_order_list . 
    "parent.job_options.cr_id_order_list = cr_id_order_list;\n" .
    "parent.job_options.when = \"" . date("H:i") . "\";\n" .
    "parent.job_options.whenString = \"(Stand: <span style=\\\"color:red\\\">" . date("H:i") . "</span> Uhr)<br><br>\\n\";\n" .
    "}\n", $output);
else:
  $output = str_replace("{_cr_id_order_list_}",
    "function updateCr_id_order_list(){\n" .
    "}\n", $output);
endif;

$output = str_replace("{_csc_id_orderer_}", ec($csc_id_orderer), $output);
$output = str_replace("{_what_is_this_}", $what_is_this, $output);
$output = str_replace("{_auto_refresh_}", MASK_AUTO_REFRESH, $output);
//$tpl->parseCurrentBlock("javascript");

$what_is_this_split = split(" ", $what_is_this);
if (trim($what_is_this_split[0]) == "Auftrags&auml;nderung" || trim($what_is_this_split[0]) == "Auftragsänderung")
  $what_is_this = "<span style=\"color:red\">" . $what_is_this . " $cmp_comp ($csc_name)" . "</span>";
else
  $what_is_this .= " $cmp_comp ($csc_name)";
//$tpl->setCurrentBlock("kundenname");
$output = str_replace("{_kundenname_}", $what_is_this, $output);
//$tpl->parseCurrentBlock("kundenname");
//$tpl->show();
echo $output;

?>
