<?php
//call db for categories

$dataz = array('img' => 'assets/imgs/meats.jpg',"name" => "test","count" => "10", "id" => "1234");
$data = array(); 
array_push($data,$dataz);
$selectedcategory='';
$selectedcategorycount='';

if($resultofinfo){
    
$catsinfo = $queries -> getproductcategories("EXEC GetPrc_group_sp @p1= ".$_SESSION['uzi']." , @p2 = ".$_SESSION['pzi'].", @ucid = ".$_SESSION['ucid']);
}else{
  
$catsinfo = $queries -> getproductcategories("EXEC GetPrc_group_sp_nu");
}

$cat_dataz = array();
$cat_data = array();
if(is_array($catsinfo) && sizeof($catsinfo) > 0){
    
  $cninfo = $catsinfo[0]['catinfo'];
    
    if(is_array($cninfo) && sizeof($cninfo) > 0){
        
        for($i=0;$i<sizeof($cninfo);$i++){
             
             
            $images = '';
            $temp =array('img' => $images,"name" => $cninfo[$i]['name'],"count" => $cninfo[$i]['count'], "id" => $cninfo[$i]['id']);
            array_push($cat_dataz,$temp);
            
        }
        
        
    }
 
    
}


$categoriesname='';
if(is_array($cat_dataz) && (sizeof($cat_dataz) > 0)){
    
    
    for($i=0; $i<sizeof($cat_dataz);$i++){
        
        $w_id = $cat_dataz[$i]['id'];
        $w_name = $cat_dataz[$i]['name'];
        
        $categoriesname .= '<option class=" py-4" value="'.$w_id.'">'.$w_name.'</option> ';
        
    }
    
    
    
 
    
}

$getsearch= true;
$ultimateprodata= array();


if(isset($_GET['cat']) && isset($_GET['brands'])){
    
$getcat = $_GET['cat'];    
$getbrands = $_GET['brands'];    
 
if(!empty(trim($getcat)) && !empty(trim($getbrands))){
    
   //call db for data
    if($resultofinfo){
        $prodataz = $queries -> getPrcWithVer("EXEC GetPrcWithVer_cat_brand_sp @p1= ".$_SESSION['uzi']." , @p2 = ".$_SESSION['pzi'].", @ucid = ".$_SESSION['ucid'].", @ver = ".$getcat.", @ver2 = ".$getbrands);
        
    }else{
        $prodataz = $queries -> getPrcWithVer("EXEC GetPrcWithVer_cat_brand_sp_nu @ver = ".$getcat.", @ver2 = ".$getbrands);
    }
    
    if(is_array($prodataz) && sizeof($prodataz) > 0){
        
       $ultimateprodata = $prodataz[0]['getprcwithver']; 
        
                               
                       if(is_array($ultimateprodata) && (sizeof($ultimateprodata) > 0)){
                           
                                                  
                            $selectedcategory=$ultimateprodata[0]['kalagroup_nam'];
                            $selectedcategorycount= sizeof($ultimateprodata);
        
                           
                       }
        
       $getsearch= false; 
    }
    
 
    
    
}else{
    
   
    
}


}else if(isset($_GET['brands'])){
    
$getbrands = $_GET['brands'];    
 
if(!empty(trim($getbrands))){
    
   //call db for data
    if($resultofinfo){
        $prodataz = $queries -> getPrcWithVer("EXEC GetPrcWithVer_brand_sp @p1= ".$_SESSION['uzi']." , @p2 = ".$_SESSION['pzi'].", @ucid = ".$_SESSION['ucid'].", @ver = ".$getbrands);
        
    }else{
        $prodataz = $queries -> getPrcWithVer("EXEC GetPrcWithVer_brand_sp_nu @ver = ".$getbrands);
    }
    
    if(is_array($prodataz) && sizeof($prodataz) > 0){
        
       $ultimateprodata = $prodataz[0]['getprcwithver']; 
        
                               
                       if(is_array($ultimateprodata) && (sizeof($ultimateprodata) > 0)){
                           
                                                  
                            $selectedcategory=$ultimateprodata[0]['kalagroup_nam'];
                            $selectedcategorycount= sizeof($ultimateprodata);
        
                           
                       }
        
       $getsearch= false; 
    }
    
 
    
    
}else{
    
   
    
}


}else if(isset($_GET['cat'])){
    
$getcat = $_GET['cat'];    
 
if(!empty(trim($getcat))){
    
   //call db for data
    if($resultofinfo){
        $prodataz = $queries -> getPrcWithVer("EXEC GetPrcWithVer_cat_sp @p1= ".$_SESSION['uzi']." , @p2 = ".$_SESSION['pzi'].", @ucid = ".$_SESSION['ucid'].", @ver = ".$getcat);
        
    }else{
        $prodataz = $queries -> getPrcWithVer("EXEC GetPrcWithVer_cat_sp_nu @ver = ".$getcat);
    }
    
    if(is_array($prodataz) && sizeof($prodataz) > 0){
        
       $ultimateprodata = $prodataz[0]['getprcwithver']; 
        
                               
                       if(is_array($ultimateprodata) && (sizeof($ultimateprodata) > 0)){
                           
                                                  
                            $selectedcategory=$ultimateprodata[0]['kalagroup_nam'];
                            $selectedcategorycount= sizeof($ultimateprodata);
        
                           
                       }
        
       $getsearch= false; 
    }
    
 
    
    
}else{
    
   
    
}


}else{
    
}


if($_SESSION['alslaksdjpAydaq'] == "laskd23#*(%kj23(sSMq"){
            
    
         if($getsearch){
             
         

         if(isset($_POST['searchprosbtn'])){
            $asearchpros = $_POST['searchpros'];
            
            if(!empty(trim($asearchpros))){
                
                
                //call db for searched products
                       $asearchpros = str_replace('ی','ي',$asearchpros);
                      $asearchpros = str_replace('ک','ك',$asearchpros);
                $asearchpros = iconv( "UTF-8", "Windows-1256",$asearchpros);
 
                if($resultofinfo){
                     $prodataz = $queries -> getPrcWithVer("EXEC GetPrcWithVer_cat_search_sp @p1= ".$_SESSION['uzi']." , @p2 = ".$_SESSION['pzi'].", @ucid = ".$_SESSION['ucid'].", @sw = N'".$asearchpros."'"." , @catname = 0");
                }else{
                    
                    
                     $prodataz = $queries -> getPrcWithVer("EXEC GetPrcWithVer_cat_search_sp_nu @sw = N'".$asearchpros."'"." , @catname = 0");
                      
                }
                
 
             
                   if(is_array($prodataz) && sizeof($prodataz) > 0){
        
                    $ultimateprodata = $prodataz[0]['getprcwithver']; 
                       
                       if(is_array($ultimateprodata) && (sizeof($ultimateprodata) > 0)){
                           
                                                  
                            $selectedcategory=$ultimateprodata[0]['kalagroup_nam'];
                            $selectedcategorycount= sizeof($ultimateprodata);
        
                           
                       }

                  }
                
 
                
            }else{
                $checkstateoflogin = false;
            }
            
        }else{
                             //call db for data of first categories
             
              if($resultofinfo){
                  $prodataz = $queries -> getPrcWithVer("EXEC GetPrcWithVer_cat_top_sp @p1= ".$_SESSION['uzi']." , @p2 = ".$_SESSION['pzi'].", @ucid = ".$_SESSION['ucid'].", @ver = 0");
                  
             
              }else{
                  $prodataz = $queries -> getPrcWithVer("EXEC GetPrcWithVer_cat_top_sp_nu @ver = 0");
             
              }
             
              
                   if(is_array($prodataz) && sizeof($prodataz) > 0){
        
                    $ultimateprodata = $prodataz[0]['getprcwithver']; 
                       
                       if(is_array($ultimateprodata) && (sizeof($ultimateprodata) > 0)){
                           
                           
                            $selectedcategory=$ultimateprodata[0]['kalagroup_nam'];
                            $selectedcategorycount= sizeof($ultimateprodata);
                            $gotocat=$ultimateprodata[0]['GROUPID'];
                           
                            header("Location: index.php?cat=".$gotocat);
                           
                                                  
                             
                           
                       }

                  }
    
         }
          
             
        }else{
             

             
         }     
        }else{
            $checkstateoflogin=true;
        }
           



?>