<?php

ini_set('display_errors', 1);

global $db;

require_once("../../common/lib.php");

require_once("../../common/define.php");



if(!isset($_SESSION['user'])){

    header("Location: login.php");

    exit();

}


get_tree(23,'vente',1);


function get_tree($product,$type,$link)
{
global $db;

if($type == "achat"){
	$table = "pm_produitsachat";
}else{
	$table = "pm_produits";
}

$query = "SELECT id,famille from ".$table." where id =".$product ;

echo $query ."<br>";

$result = @$db->query($query);


if($result !== false){

	foreach($result as $row){
		$sous_famille = $row["famille"];

		$query_2 = "SELECT famille_classe from pm_famille where id =".$row["famille"];
		echo $query_2 ."<br>";

		$result_2 = @$db->query($query_2);
		if($result_2 !== false){
			foreach($result_2 as $row_2){
				$famille = $row_2["famille_classe"];
				// echo "==========<br>";
			}
			
		}	

	} 
	
	if($link == 1){
		return $sous_famille ;
	}else{
		return $famille ;
	}

	// echo "Famille = ".$famille." / Sous famille = ".$sous_famille ."<br>";

}	

}

?>