<?php

	
  class Med_functions{
   
	function getTableColumn($p_company_code= null,$p_table= null,$p_apps_code=null,$p_is_actice=null) {
		global $db;
/*		$sql="select   b.*
						from  ec_apps_tables a,
						     ec_apps_tables_description b,
						     ec_company_apps_tables c
						where c.company_code=".$p_company_code."
						  and a.apps_table_id=b.apps_table_id
						  and a.apps_table_id=c.apps_table_id
						  and a.language_id=1
						  and a.apps_code='".$p_apps_code."'
						  and a.table_name='".$p_table."'
						  and b.is_display=1
						  and b.IS_ACTIVE=".$p_is_actice."  ORDER BY b.display_seq";
*/	 
	$sql="CALL sp_l_getTableDescription(".$p_company_code.",'".$p_table."','".$p_apps_code."',".$p_is_actice.")";
	$result=$db->dbQuery($sql);
	return $result; 
	 	
        
       // $sql="CALL sp_l_getTableDescription(?,?,?,?)";
      //  $stmt= $db->prepare($sql);
      //  $stmt->bind_param("s",$p_company_code,"s",$p_table,"s",$p_apps_code,"n",$p_is_actice);
         
		 

	/*
		  $table = array();    
          if($result->num_rows > 0)    {        
          	$i = 0;        
          	while($table[$i] = $result->fetch_assoc()) {
          		$i++;
          	} 
          	unset($table[$i]);       		
         }      
                          		
       	$result->free();
        //$result->close();
       
       // print_r($table);
       
       // die();
        return $table;          
	*/
		      		
	}
	function getSingleRecord($p_record_id= null,$p_company_code= null ,$p_language_id=null){
		global $db;
  		$sql="call sp_rst_s_mc_facility(".$p_record_id.",".$p_company_code.",".$p_language_id.")";	
		$result=$db->dbQuery($sql);
  		 return $result; 
	}
	
  	function getTableData($p_facility_id ,$p_city=null,$p_state=null,$p_phone01=null,$p_company_code,$p_language=null){
  		//echo "facility_id: ".$p_facility_id."<br/>";
 		global $db;
 		if(empty($p_facility_id) || is_null($p_facility_id)){
 			$p_facility_id='null';
 		}
 			
 	
 			$sql="call sp_rst_m_mc_facility(".$p_facility_id.",'".$p_city."','".$p_state."','".$p_phone01."',".$p_company_code.",".$p_language .")";
 		
 		
  		
  		
  	  	//echo "<br/>";
  	  	//echo $sql;
  	  	//die();
		//$sql="SELECT fnc_dsql_factory(".$p_company_id.",".$p_language_id.",'".$p_table."') as v_statement";  		
  		$result=$db->dbQuery($sql);
  		 return $result;     
  		
  		//$db->mysqli_clean_connection();
  		
  	/*	$col= $result->fetch_row();
  	
  		$v_ware='';
  		if(!empty($p_facility_id)){
  			$v_ware=" where FACILITY_ID=".$p_facility_id;
  		}else {
  			$v_ware= "" ; //" where FACILITY_ID= 0";
  		}
  			$sql= $col[0]." ".$v_ware;
  		
        $result=$db->dbQuery($sql);
        */
             		
      
  	}
  	
  	
  	function getCodeValue($p_comp_code,$p_code_table){
  		
  		global $db;
 /* $sql="select av.attribute_value as ID ,av.attribute_value_desc as V_TEXT
		from   ec_setup_attributes   sa,
		       ec_attribute_values   av,
		       ec_company_attributes  ca
		where  sa.attribute_name=".$p_code_table."
		  and  sa.attribute_id=av.attribute_id
		  and  sa.attribute_id=ca.attribute_id
		  and  ca.company_code=".$p_comp_code."
		  and  ca.company_code=av.company_Code
		  and  ca.is_active=1
		  and  av.is_active=1
		  and  sa.is_active=1";
  */
  
  		$sql="CALL sp_l_getListvalue(".$p_comp_code.",'".$p_code_table."')";	
  		
  		
  		$result=$db->dbQuery($sql);
        
        return $result; 
	/*	  
          $table = array();    
          if($result->num_rows > 0)    {        
          	$i = 0;        
          	while($table[$i] = $result->fetch_row()) {
          		$i++;
          	} 
          	unset($table[$i]);       		
         }      
        $result->free();                   		
       $result->close();
      
            
        return $table;          
        */ 
  	}
  	
  	function getSetupTables(){

      global $db;
        $sql="SHOW FULL TABLES FROM medsysmagic
                  where tables_in_medsysmagic<>'ec_apps_tables_description'
                  and tables_in_medsysmagic<>'ec_apps_tables'
                  and tables_in_medsysmagic<>'ec_company_apps_tables'";
        $result=$db->dbQuery($sql);
      return $result;
      } 
      
    function getTableDescription($p_Table_name){
  		global $db;
  		$sql="SHOW COLUMNS FROM medsysmagic.".$p_Table_name;
  		$result=$db->dbQuery($sql);
  		$table= array();
  	    return $result;
  	}
  	
  	function getCompany(){
  		global $db;
  		$sql="SELECT * FROM ec_companies";
  		$result=$db->dbQuery($sql);
  				
  	    return $result;
  	}
  	
  	function getFacilityName(){
  		
  		global $db;
  		//$sql="CALL sp_rst_L_mc_facility(1,1)";
  		
  		$sql="select NULL as ID,'Select..' as id_name ,-1 as ord
			  union
			  select facility_id as id ,facility_name as id_name,display_seq as ord
			from mc_facility order by ord";

	//	$sql="select facility_id as id ,facility_name as id_name,display_seq as ord from mc_facility order by display_seq";
  		$result=$db->dbQuery($sql);
  		
  	    return $result;
  	}
}

?>