<?php
/*=======================================================================
 *
 * push_autoranking.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 == 1)
  $javascript .= "alert('Zurückstellen in automatische Vermittlung nicht möglich: Auftrag ist bereits angenommen!');\n";
if ($jb_status == 2)
$jb_status = getFieldValueFromId("job", "jb_id", "$jb_id", "jb_status");
if ($jb_status != 1 && $jb_status != 2):
            // Update job
            $jbStatusString = " (jb_status = '9' OR jb_status = '0' OR jb_status = '8') ";
            $res = updateStmt("job", "jb_id", $jb_id, array("cr_id", "", "cr_id_order", "", "jb_status", "8", "cr_sid", "", "jb_globaljob", "0"), "(" . $jbStatusString . ")");
            writeToLogDB(54, $hq_id, $jb_id, $usr_id, "", "", "", "");
            deleteStmt("genericdatacontainer", "gdc_obj_type = 'jb' AND gdc_obj_id = " . $jb_id . " AND gdc_gen_fieldname = 'jb_ignore_fav_only'");
            if ($ignore_fav_only == "1") {
              insertStmt("genericdatacontainer", array("gdc_obj_type", "jb", "gdc_obj_id", $jb_id, "gdc_gen_fieldname", "jb_ignore_fav_only", "gdc_content", "1", "gdc_context", date("Y-m-d H:i:s")));
              writeToLogDB(144, $hq_id, $jb_id, $usr_id, "", "", "", "");
            }
  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;

?>
