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


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



// Check HTTP-Parameters
$httpVars = array("statusMessage", "currentNavigationItem", "menuActiveByPageTitel", "deactivateMenu", "currReferer", "currHqSelection");
getSecHttpVars("1", $httpVars); 

if ($currReferer != "") :
   $currReferer = "../" . urldecode($currReferer);
else :
   $currReferer = "../admin/logout.php";
endif;

// Check authentication verifying emmployee an his/her costcenter- and customer-association
$usrAccessArray["hq"] = "1";
if (!authCheckForAccess($hq_id, $usr_id, $emp_id, "", $customerId, $cscIdRoot, $cscIdActual) || $currHqSelection == "" || !is_numeric($currHqSelection)) :
   header("Location: ../admin/logout.php");
endif;

// Check for authentication access and granted rights
;


// After check of the current user try to set new session parameters according to the selected user
$empHqList = getParameterValue("0", "HEADQUARTERS_MULTIPLE_ACCESS_EMPLOYEES", "0");
$outHqSelection = "";
if ($empHqList != "") :
   $showMultipleHqSelection = isInParameterString($emp_id, $empHqList);
   if ($showMultipleHqSelection) :
      $usrId = getFieldValueFromId("employee","emp_id",$emp_id,"usr_id");
      $hq_mnemonic = getFieldValueFromId("headquarters","hq_id",$currHqSelection,"hq_mnemonic");
      if ($hq_mnemonic != "") :

         // Return-Wert ist ungleich '', name/pass ist gültig
         if (phpversion() < '4.1.0'):
           // bis auschl. PHP 4.1.0.
           session_register("usr_id","hq_id","emp_id");
           $HTTP_SESSION_VARS["hq_id"] = $currHqSelection;
         else:
           // ab einschl. PHP 4.1.0.
           $_SESSION['hq_id'] = $currHqSelection;
         endif;

         header("Location: " . $currReferer);
         exit();
      else :
         header("Location: ../admin/logout.php");
      endif;
   else :
      header("Location: ../admin/logout.php");
   endif;

else :
   header("Location: ../admin/logout.php");
endif;

// Referer
header("Location: ../admin/logout.php");
?>
