<?php

include_once ("../include/mcglobal.inc.php");
include_once ("../include/auth.inc.php");
include_once ("../include/html.inc.php");


// Check HTTP-Parameters
getSecHttpVars("1",array("f_act", "jbId", "jbHqId", "jbHqIdDispo", "jbHqIdExec", "jbHqIdSales"));

// Init
$pageTitel = "AUFTRAGS-ROLLEN SETZEN";


$hqArr = getColVectorFromDB2ArrayByClause("headquarters", "hq_mnemonic", "", "hq_id", "hq_mnemonic", "");
// Add zero element
$hqArr[0] = "KEINE";


// Store hq ids
if ($f_act == "set") :
   if ($jbId != "" && is_numeric($jbId) && $jbId > 0) :
      if ($jbHqId != "" && is_numeric($jbHqId)) :
         updateStmt("job","jb_id",$jbId,array("hq_id", $jbHqId));         
      endif;
      if ($jbHqIdDispo != "" && is_numeric($jbHqIdDispo)) :
         updateStmt("job","jb_id",$jbId,array("hq_id_dispo", $jbHqIdDispo));         
      endif;
      if ($jbHqIdExec != "" && is_numeric($jbHqIdExec)) :
         updateStmt("job","jb_id",$jbId,array("hq_id_exec", $jbHqIdExec));         
      endif;
      if ($jbHqIdSales != "" && is_numeric($jbHqIdSales)) :
         updateStmt("job","jb_id",$jbId,array("hq_id_sales", $jbHqIdSales));         
      endif;
   endif;
endif;

// Get current data
if ($jbId != "") :   
   $jbHqId      = getFieldValueFromId("job", "jb_id", $jbId, "hq_id");
   $jbHqIdDispo = getFieldValueFromId("job", "jb_id", $jbId, "hq_id_dispo");
   $jbHqIdExec  = getFieldValueFromId("job", "jb_id", $jbId, "hq_id_exec");
   $jbHqIdSales = getFieldValueFromId("job", "jb_id", $jbId, "hq_id_sales");
endif;

// echo "Erf.: " . $hqArr[$jbHqId] . "&nbsp;&nbsp;&nbsp;&nbsp;" . "Dsp = " . $hqArr[$jbHqIdDispo] . "&nbsp;&nbsp;&nbsp;&nbsp;" . "Aus = " . $hqArr[$jbHqIdExec] . "&nbsp;&nbsp;&nbsp;&nbsp;" . "Kds = " . $hqArr[$jbHqIdSales];
?>

<?php if (true) : ?>
<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>

<script type="text/javascript">
<!--
	function finishPage(f_act) {
	var doContinue = true;
	/*
  if (f_act == 'newValues' && !confirm('<?php echo "Neue Aufgaben generieren?" ?>')) {
     doContinue = false;
  }
  */
  if (doContinue) {
    document.forms[0].f_act.value = f_act;
    document.forms[0].submit();
  }
};
-->
</script>

</head>

<body>

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

<form name="history" action="../tools/jb_hq_set.php" method="post">

  <input type="hidden" name="f_act" value="">

  <br>
  <div>
   <table cellspacing="3" cellpadding="3" vspace="3" hspace="3">
     <?php // echo $out ?>     
     <tr>
     	<td>Auftrag:</td>
     	<td><input type="text" name="jbId" value="<?php echo $jbId ?>" size="10">&nbsp;&nbsp;<input type="button" name="job" value="Aktualisieren" onClick="finishPage('job');"></td>
     </tr>
     <tr>
     	<td>Erfassende NL:</td>
      <td><select name="jbHqId">"<?php echo addOptionsFromAssociativeArray($hqArr, $jbHqId); ?></select></td>
     </tr>
     <tr>
     	<td>Zuweisende NL:</td>
     	<td><select name="jbHqIdDispo">"<?php echo addOptionsFromAssociativeArray($hqArr, $jbHqIdDispo); ?></select></td>
     </tr>
     <tr>
     	<td>Ausführende NL:</td>
     	<td><select name="jbHqIdExec">"<?php echo addOptionsFromAssociativeArray($hqArr, $jbHqIdExec); ?></select></td>
     </tr>
     <tr>
     	<td>Kundenbetreuende NL:</td>
     	<td><select name="jbHqIdSales">"<?php echo addOptionsFromAssociativeArray($hqArr, $jbHqIdSales); ?></select></td>
     </tr>

     <tr>
     	<td colspan="2"><input type="button" name="store" value="Speichern" onClick="finishPage('set');"></td>
     </tr>
   </table>
  </div>
</form>
</div>
</body>

</html>
<?php endif; ?>