<?php
/*=======================================================================
 *
 * import_SOAP_HHA.php
 *
 * Autor: Marc Vollmann
 *
 =======================================================================*/

include_once ("../import/import.php");
include_once ("../include/auth.inc.php");

// Execution-Time for script
set_time_limit(30000);

// Select user-type for mode of security check 
$userType = getFieldValueFromId("user","usr_id",$usr_id,"usr_type");
$userTypeName = getUserTypeName($userType);

// Check authentication verifying emmployee an his/her costcenter- and customer-association
if ( !( authCheckHQ($hq_id,$usr_id,$emp_id) || authCheck($hq_id,$usr_id,$emp_id,$cscIdRoot,$customerId,$cscIdActual) ) || $userTypeName == "" ) :
   die ("$PHP_SELF: Access denied!");
endif;

// Get the rights of the employee logged in and check the accessibility
// authCheckEmployeeRights($emp_id, "22", "1");

// Check HTTP-Parameters
getSecHttpVars("1",array("f_act"));


if ($f_act == "executeImport") :

   // Activate buffering
   ob_start();

   $path = getAbsoluteSystemPath();

   // Call script to import service unit master data
   writeToFile($mcDebugImportErrLogFile, "----------------------------------------------------------------------------------------------");
   writeToFile($mcDebugImportErrLogFile, "[HQ_ID:" . $hq_id . "] " . " [USR_ID:" . $usr_id . "]");
   writeToFile($mcDebugImportErrLogFile, "Import Stammdaten begonnen.");
   echo "Import Stammdaten.<br>"; ob_flush(); flush();
   $mcDebugImportErrLogFile = $path . "/log/soap_data_" . $hq_id . "_err.stdout+err";
   $cmd = "php " . $path . "/import/soap.php acapella7890 " . $hq_id . " 1" . " > " . $mcDebugImportErrLogFile . " 2>&1 &";
   system($cmd);
   writeToFile($mcDebugImportErrLogFile, "Import Stammdaten beendet.");
   // echo "Import Stammdaten beendet.<br>"; ob_flush(); flush();
   sleep(2);

   // Call script to import service unit status data
   writeToFile($mcDebugImportErrLogFile, "----------------------------------------------------------------------------------------------");
   writeToFile($mcDebugImportErrLogFile, "[HQ_ID:" . $hq_id . "] " . " [USR_ID:" . $usr_id . "]");
   writeToFile($mcDebugImportErrLogFile, "Import Statusdaten begonnen.");
   echo "Import Statusdaten.<br>";
   $mcDebugImportErrLogFile = $path . "/log/soap_data_" . $hq_id . "_err.stdout+err";
   $cmd = "php " . $path . "/import/soap.php acapella7890 " . $hq_id . " 0" . " > " . $mcDebugImportErrLogFile . " 2>&1 &";
   system($cmd);
   writeToFile($mcDebugImportErrLogFile, "Import Statusdaten beendet.");
   // echo "Import Statusdaten beendet.<br>"; ob_flush(); flush();
   // sleep(2);
   echo "Neuaufbau der Tourenplanungsliste im Hintergrund.<br>"; ob_flush(); flush();
   sleep(2);

   // Deactivate buffering and flush data
   ob_end_flush();
   sleep(2);
else :
   echo "Fehler, keine Verarbeitung!<br>";
endif;
echo $path . "/illt/servicejob.php?currentNavigationItem=serviceauftraege" . "<br>";
?>

<html>

<head>
<title><?php echo $pageTitel ?></title>

<style type="text/css">
  <?php include_once ("../css/navigation.css.php"); ?>
  .navfixed {position:fixed; top:0px; background-color: #DDDDDD; width: 100%;}
  .navlabel {width: 170px; height: 22px;}
</style>

<?php include_once ("../include/js_framework.inc.php"); ?>


<script type="text/javascript">
<!--
function finishPage(f_act) {
  document.forms[0].f_act.value = f_act;
  document.forms[0].submit();  
};

function sleep(ms) {
  return new Promise(resolve => setTimeout(resolve, ms));
}

function refreshOpener() { 
	opener.finishPage('');
  // opener.location.href = "<?php echo $path ?>/illt/servicejob.php?currentNavigationItem=serviceauftraege";
  sleep(5000);
  window.close();
};
-->
</script>

</head>

<body onLoad="refreshOpener();">
	
</body>

</html>

