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

//require_once("HTML/IT.php");
include_once("../include/caglobal.inc.php");
include_once("../include/global.inc.php");

// This page is called by job_edit.js in function "moveToTour"

// Javascript-Funktionen im temporären Fenster ändern die Adresswerte im Eingabeformular
$javascript = "var curTourNo = opener.getCurTourNo();\n";

// Kostenstellennummern von Start und Ziel sind Parameter
list ($csc_id1, $csc_id2) = getHttpVars(array("csc_id1", "csc_id2"));
if ($csc_id1 == "" && $csc_id2 == "") reportDie ("$PHP_SELF: Parameter 'csc_id1' und 'csc_id2' fehlen!", false);

// csc_id1:
if ($csc_id1 != ""):
  // Adress-ID und Hausnummer der Start-Kostenstelle holen
  list($von_ad_id, $von_ad_hsno, $von_comp, $von_remark, $von_person) =
    insertAddress("", "", "", $csc_id1);
  // Strasse, PLZ und Ort von Start holen
  list($von_ad_city, $von_ad_zipcode, $von_ad_street) = getFieldsValueFromId(
    "address", "ad_id", $von_ad_id, array("ad_city", "ad_zipcode", "ad_street"));
  // Sets the relevant openers of the current tour
  $javascript .= setJavascriptOpenerJobList("curTourNo",
    array(JL_TR_COMP => $von_comp, JL_TR_PERSON => $von_person,
      JL_AD_STREET => $von_ad_street, JL_TR_HSNO => $von_ad_hsno,
      JL_AD_ZIPCODE => $von_ad_zipcode, JL_AD_CITY => $von_ad_city,
      JL_TR_REMARK => $von_remark));
endif;

// csc_id2:
if ($csc_id2 != ""):
  list($nach_ad_id, $nach_ad_hsno, $nach_comp, $nach_remark, $nach_person) =
    insertAddress("", "", "", $csc_id2);
  list($nach_ad_city, $nach_ad_zipcode, $nach_ad_street) = getFieldsValueFromId(
    "address", "ad_id", $nach_ad_id, array("ad_city", "ad_zipcode", "ad_street"));
  $javascript .= setJavascriptOpenerJobList("curTourNo + 1",
    array(JL_TR_COMP => $nach_comp, JL_TR_PERSON => $nach_person,
      JL_AD_STREET => $nach_ad_street, JL_TR_HSNO => $nach_ad_hsno,
      JL_AD_ZIPCODE => $nach_ad_zipcode, JL_AD_CITY => $nach_ad_city,
      JL_TR_REMARK => $nach_remark));
endif;

$javascript .= javascriptOpenerRefreshAndClose();

// Inhalt des temporären Fensters erzeugen und ausgeben
//$tpl = new IntegratedTemplate();
//$tpl->loadTemplatefile(GETDATAHTMLTPL, true, true);
//$tpl->setCurrentBlock("javascript");
//$tpl->setVariable("_javascript_", $javascript);
//$tpl->parseCurrentBlock("javascript");
//$tpl->show();
$output = file_get_contents(GETDATAHTMLTPL);
$output = str_replace("{_javascript_}", $javascript, $output);
echo $output;
?>
