<?php 


include("tools/header.php");?>
<?php
$whichrout = 2;
?>

<?php
if((isset($_GET['Authority'])) && (isset($_GET['gr']))){
    
$gw_auth = $_GET['Authority']; 
$gw_gr = $_GET['gr']; 
 
if((!empty(trim($gw_auth))) && (!empty(trim($gw_gr)))){
    
    
$gtwd = $queries -> getgatewaydate("EXEC handle_gateways  @p3 = '".$gw_gr."', @p5 = '".$gw_auth."'");
       
if((is_array($gtwd)) && (sizeof($gtwd) == 7)){
 
    
$gtwd_fid = $gtwd['fid'];
$gtwd_session = $gtwd['session'];
$gtwd_auth = $gtwd['auth']; 
$gtwd_rand = $gtwd['rand']; 
$so = $gtwd['name'];
$pa = $gtwd['yad'];
$ci = 'asdw_400';


    
$queries -> updateFactor("EXEC handle_gateways @p1 = ".$gtwd_fid.", @p2 = ".$gtwd_session.", @p3 = ".$gtwd_rand.", @p5 = ".$gtwd_auth.", @p6 = 34");       
    
$rez = $queries -> getuser("EXEC GetUsers_sp   @p1 =  '$so' , @p2 = '$pa' ,@p3= '$ci' ");
                
if ($rez){
                    
$res = $queries -> getCodeCast("EXEC Getcod_cast '$so' , @p2 = '$pa' ,@p3= '$ci' ");
                     
if($res !== 'none'){
                     
$c = strlen(trim($res));                    
if($c > 0){
 
$_SESSION['uzi'] = $so;
$_SESSION['pzi'] = $pa;
$_SESSION['czi'] = $res;
$_SESSION['ucid'] = $ci;
$_SESSION['trco'] =  $gtwd_session;     
$_SESSION['frco'] =  $gtwd_fid;                                             

$whichrout = 1;  
    
}else{
$whichrout = 3;  
}
                        
                        
}else{
$whichrout = 4;    
}
}else{
$whichrout = 5;  
}
   

}else{
$whichrout = 6;   
}   
      
    
}else{
$whichrout = 7;  
} 
    
}else{
$whichrout = 8;   
}
?>

<?php
if($whichrout == 1){
 
    
     header("Location: chsta.php?Authority=".$gw_auth);
    exit(); 
    
}else{
    
   header("Location: logout.php");
    exit();
}

?>