<?php header('Content-Type: text/html; charset=utf-8');?>
<?php


include("cnf.php");?>
<?php include("localsets.php");$queries = new DatabaseFunctions($db5);?>
<?php


if(isset($_POST['tu']) && isset($_POST['lk']) && isset($_POST['da'])
   && !empty(trim($_POST['tu'])) && !empty(trim($_POST['lk'])) && !empty(trim($_POST['da']))){

$us = $_POST['tu'];
$ps = $_POST['lk'];
$ver = $_POST['da'];
$res = json_decode($ver,true);
$res = $res["getresult"];
$data = array();
$datas=-1;    
    
if(!is_null($res) && is_array($res) && (sizeof($res)) > 0){
  
    
       $valdataCheck = $queries -> chkusevalstore($us, $ps);
        
       if(!is_null($valdataCheck) && is_array($valdataCheck) && (sizeof($valdataCheck) === 1)){
           
       
    
    
        for($i=0; $i<sizeof($res);$i++){
 
            
        if(!is_null($res[$i]["nam"]) && 
           !is_null($res[$i]["rowi"]) && !is_null($res[$i]["rowv"]) && !is_null($us) && !is_null($ps)){
            
            
                    if($res[$i]["rowv"] == "3" || $res[$i]["rowv"] == "2"){
						
						 $queries -> handleBrands($res[$i]["nam"],$res[$i]["rowi"],$us,$ps);
                        
                    }else if($res[$i]["rowv"] == "1"){
            
                    $queries ->deleteBrands($us,$ps,$res[$i]["rowi"]);
            
                    }else{
                            continue;
                    }
 
        
                    array_push($data, $res[$i]["rowi"]); 
 
        }    

      }
    
           
      }else{
           
           $datas = -3;
           
       }
}


    
if(sizeof($data) > 0){
   $datas = $data[sizeof($data)-1]; 
}

echo $datas;
    

}else{
    $datas=-13;
    echo $datas;
}

 
?>