<?php
/**
 * This is general file which contains
 * connection file, common function file, etc.,
 *
 * PHP version 5
 *
 * @category Admin_Tool
 * @package  Admin_Tool
 * @author   Aum Infosys <admin@auminfosys.com>
 * @license  ACE
 * @version  CVS:1.0.1
 * @link     http://auminfosys.com/
 * @filesource
 */
 
/**
 * This is general file which contains
 * connection file, common function file, etc.,
 *
 */
    require "../commonincludefiles.php";
	$arr = array();
	$total = 0;
 	$product_id=	$_SESSION["cCompany_id"];
	$k=0;

$inquiry_id= Escape($_POST['inquiry_id']);

if($inquiry_id !="") {
	
	$condition .= " AND inquiry_id='".$inquiry_id."'";
  
    $objInquiryMgmt = new InquiryMgmt();  

	$result = $objInquiryMgmt->getAllRecords(0,0,$condition,$order_field,$order_type) ;
	$num = dbRows($result);
	$i = 0;   
	while($mainrow = dbArray($result)){
		$product_ids = $mainrow['product_ids'];   
	}
	 $product_ids =explode(',',$product_ids);
	 
	 $objProductMgmt = new ProductMgmt();	
	 	
	 $where.=" And company_id= '".$_SESSION["cCompany_id"]."'";	
		
	 $rs = $objProductMgmt->getAllRecords($limit,$start,$where,$order_field,$order_type);
	 $total = $objProductMgmt->getCountRecords(0,0,$where,"","");
	// $arr = array("total" => $total, "data" => array());
	 if	(dbRows($rs) > 0) 
	 {
				$temparray = array();
				while($row = dbArray($rs)){
					
					$temparray["product_id"]  = $row["product_id"];
					$temparray["product_name"]   = $row["product_name"];
					$temparray["product_price"]  = $row["product_price"];
					$temparray["product_active"]   = $row["product_active"];
					$temparray["product_description"]   = $row["product_description"];
					if(in_array($row["product_id"],$product_ids))
					{
						$temparray["selected"]="true";
					}
					else
					{
						$temparray["selected"]="false";
					}
					$arr[$i] = $temparray;   
					$i++;
			}		
			echo '{"total":"'.$total.'","data":'.json_encode($arr).'}';				
		}
		
		 	 	 	 	
}
else
{
	$objProductMgmt = new ProductMgmt();		
		
		$where.=" And company_id= '".$_SESSION["cCompany_id"]."'";	
	$rs = $objProductMgmt->getAllRecords($limit,$start,$where,$order_field,$order_type);
	
	$total = $objProductMgmt->getCountRecords(0,0,$where,"","");;
	
	if($total > 0) {
		while($obj = dbObject($rs)) {
		 $arr[$k] = $obj;  
		 $k++;
		}
	}
	
echo '{"total":"'.$total.'","data":'.json_encode($arr).'}';
	
}	
?>