<?php
/* 
----------------------------------------------------------
  MODULE :  AJAX SEARCH CLIENTS USING CALL NUMBERS 
  V1.0 / 2018
  AUTHOR : SGHAIER MAHMOUD  
----------------------------------------------------------
*/
 
require_once(__DIR__.'/../ssinclude/app-init.php');
require_once(__DIR__.'/../ssinclude/app-session.php');

//header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
//header("Cache-Control: post-check=0, pre-check=0", false);
//header("Pragma: no-cache");
//header('Content-Type: application/json');

$nb = verif_posted("nb");
 
if (  !empty($nb) )
{  
 
	try
     {
       //  search  client 
        $sql=" 
        SELECT * 
        FROM clients  
        WHERE 
        clients.mobile1 = :nb OR  
        clients.mobile2 = :nb  OR  
        clients.mobile3 = :nb  OR  
        clients.tel1 = :nb  OR  
        clients.tel2 = :nb  OR  
        clients.tel3 = :nb   " ;
        $db->setAttribute(PDO::ATTR_EMULATE_PREPARES, true);
        $pr = $db->prepare( $sql );
        $pr->bindParam(':nb', $nb, PDO::PARAM_STR );
        $pr->execute();
        $rs = $pr->fetchAll(PDO::FETCH_ASSOC);
        
        $resultJSON = json_encode( $rs);
        // output 
         echo ('[ { "success" : 1 , "data" :  '.$resultJSON.' } ]'); // true
		}           
			
	  catch (PDOException $e)
	  {
		$message =  $e->getMessage();
        echo ('{ "success" : 0 , "message" : "'.$message.'" }'); // false error 
	  }
}   
		
require_once(__DIR__.'/../ssinclude/app-close.php');?>