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

include ("tools/start.php");?>
<?php include ("tools/che.php");?>
<?php
$msg = 1;
$currentbasketdata = '';    
$currentbasketitemcounts = '';    
if(isset($_POST['cartitemscount'])){
            $cartitemscount = $_POST['cartitemscount'];
            $cartitemsid = $_POST['cartitemsid'];  
            $cartitemspri = $_POST['cartitemspri'];  
            $cartitemsname = $_POST['cartitemsname'];  
            
   if(!empty(trim($cartitemscount)) && !empty(trim($cartitemsid)) && !empty(trim($cartitemspri)) && !empty(trim($cartitemsname))){
                
                
                //call db to add products
 
       
        $queries -> addtempfactors($_SESSION['uzi'], $cartitemsid, $cartitemscount, $cartitemspri, '', $_SESSION['ucid']);
       
        
        $msg = 2; 
                
        
        $currentbasket = $queries -> gettempfactors("EXEC gettempfactors @p1= ".$_SESSION['uzi']." , @p2 = ".$_SESSION['pzi'].", @ucid = ".$_SESSION['ucid']);
       
       if(is_array($currentbasket) && sizeof($currentbasket)>0){
           
           $currentbasket = $currentbasket[0]['getfactors'];
           
               if(is_array($currentbasket) && sizeof($currentbasket) > 0){
                   
                       $currentbasketitemcounts = sizeof($currentbasket);
                           
                           
                   for($i=0;$i<sizeof($currentbasket);$i++){
                       
            
                       $currentz = $currentbasket[$i];
           

                       
//                        $currentbasketdatasdasdasdasdasd .= '<div class="col-12 mt-2"><div class="bg-white rad-10 p-2 cart-side-holder  rad-10 mx-1" style="border:1px solid #ffe38f;"><a href="products.php?cart='.$currentz['cod_kala'].'" class="text-decoration-none"><div class="cart-side-delete d-flex align-items-center justify-content-center"><i class="fa-trash fa"></i></div></a><div class="cart-side-info"><div class="text-right cart-side-items text-dark">'.$currentz['nam'].'</div><div class="text-right cart-side-sub mt-2 text-secondary"><span class="ml-2">تعداد: '.$currentz['numb'].'</span><span>قیمت: '.$currentz['price'].'</span></div></div></div></div>';
//                       
//                       
                                             
                                  
                        $currentbasketdata .= '<div class="col-12 mt-2"><div class="bg-white rounded p-2 cart-side-holder  rad-10  mx-2" style="borders:1px solid #ffe38f;"><a href="products.php?cart='.$currentz['cod_kala'].'"  class="text-decoration-none"><div class="cart-side-delete d-flex align-items-center justify-content-center"><i class="fa-trash fa"></i></div></a><div class="cart-side-info"><div class="text-right cart-side-items text-dark">'.$currentz['nam'].'</div><div class="text-right cart-side-sub mt-2 text-secondary"><span class="ml-2">تعداد: '.$currentz['numb'].'</span><span>قیمت: '.$currentz['price'].'</span></div></div></div></div>';
                       
            
                   }
        
        
               }
           
           
       }
       
       $cartitems = array('img' => '',"name" => $cartitemsname,"count" => $cartitemscount, "id" => $cartitemsid,"price" => $cartitemspri);
       $databack =  array("msg"=>$msg,"count" => $currentbasketdata,"data" => $cartitems,"cartcount" => $currentbasketitemcounts);
    
       $databack = json_encode($databack);
       echo $databack;
                
    }
            
}else{
$msg = 3;
    
$cartitems = array();
$databack =  array("msg"=>$msg,"count" => "0","data" => $cartitems);
    
$databack = json_encode($databack);
echo $databack;    
    
}
          
   

         

 




?>