<?php
/*=======================================================================
 *
 * push_manual.php
 *
 * Autor: Marc Vollmann, Carsten Annacker
 *
 =======================================================================*/

include_once ("../include/global.inc.php");
include_once ("../include/caglobal.inc.php");
include_once ("../include/dbconnect.inc.php");
include_once("../include/auth.inc.php");

list($jb_id, $ignore_fav_only) = getHttpVars(array("jb_id", "ignore_fav_only"));

// Update job
//updateStmt("job", "jb_id", $jb_id, array("cr_id_order", "", "jb_status", "8", "cr_sid", ""));

// Check for authentication access and granted rights
$usrAccessArray["hq"] = "1";
authCheckForAccess($hq_id, $usr_id, $emp_id, "1", $customerId, $cscIdRoot, $cscIdActual);

$javascript = "";
     
$jb_status = getFieldValueFromId("job", "jb_id", "$jb_id", "jb_status");
$jb_globaljob = getFieldValueFromId("job", "jb_id", "$jb_id", "jb_globaljob");
if ($jb_status != 2):
      $jbHqId = getFieldValueFromId("job","jb_id",$jb_id,"hq_id");
      $crIdCurrent = getFieldValueFromId("job","jb_id",$jb_id,"cr_id");
      $crIdOrderCurrent = getFieldValueFromId("job","jb_id",$jb_id,"cr_id_order");
            // Update job
            $res = updateStmt("job", "jb_id", $jb_id, array("cr_id", "", "cr_id_order", "", "jb_status", "9", "cr_sid", "", "jb_globaljob", "0"));
            writeToLogDB(185, $hq_id, $jb_id, $usr_id, "", "", "", "");

               // Insert PDA command to remove job (take cr_id/cr_id_order before changing)
               $currentTimePDA = getDateTime("datetime_plus_offset", array(0,0,30,0,0,0), $formatStr = "Y-m-d H:i:s");
//echo "jb_id = " . $jb_id . "<br>\n";
//echo "crIdCurrent = " .      $crIdCurrent . "<br>\n";
//echo "crIdOrderCurrent = " .     $crIdOrderCurrent . "<br>\n";
//echo "jbHqId = " . $jbHqId . "<br>\n";
//echo "currentTimePDA = " . $currentTimePDA . "<br>\n";
               if ($crIdCurrent != "" && $crIdCurrent != "0") :
                  insertPDACommand($jbHqId, $crIdCurrent, "4", "1", $jb_id, $currentTimePDA, "");
               endif;
               if ($crIdOrderCurrent != "" && $crIdOrderCurrent != "0" && $crIdOrderCurrent != $crIdCurrent) :
                  insertPDACommand($jbHqId, $crIdOrderCurrent, "4", "1", $jb_id, $currentTimePDA, "");
               endif;
  if ($jb_globaljob == 1)
    $javascript .= "alert('Auftrag war \"an alle\", ist jetzt aber wieder ein normaler Auftrag');\n";
endif;

$javascript .= 
"opener.close();\n" .
  "self.close();\n";
// Inhalt des temporären Fensters erzeugen und ausgeben
$output = file_get_contents(GETDATAHTMLTPL);
$output = str_replace("{_javascript_}", $javascript, $output);
echo $output;

?>
