<?php
	require_once ('template.inc.php');
	require_once ('connect.inc.php');
	$login  = $_SESSION['login'];
	$password = $_SESSION['password'];
	function templatize($headerTemplate,$menuTemplate, $bodyTemplate,$footerTemplate) {
		templatizeWithVars($headerTemplate,$menuTemplate, $bodyTemplate,$footerTemplate, array());
	}
	
	function templatizeWithVars($headerTemplate,$menuTemplate, $bodyTemplate,$footerTemplate, $arrayVars) {
		
		/* calcul du nb de joueurs inscrits */
		global $dbconn, $login, $password;
		$recupNb=pg_query($dbconn,"select count(user_id) as nb from users");
		$ligne=pg_fetch_array($recupNb);
		$nb_insc=$ligne['nb'];
		
		
		/* calcul du nb de nouveau message */
		//Message à true
		if($login) {
		$newmess=pg_query($dbconn,"select user_id from users where user_login='$login' and user_pass='$password'");
		$id=pg_fetch_array($newmess);
		$idU =$id[0];
		//Message a true de l'utilisateur
		
		$nbmess=pg_query($dbconn,"select count (user_receive_id) from send where user_receive_id='$idU' and message_read='1'");
		$nbmess=pg_fetch_array($nbmess);
}
		
		/*debut creation template*/
		$template = new Template('.');
		
		$template->set_file(array(
			'HEADER'=>$headerTemplate,
			'MENU'=>$menuTemplate,
			'BODY'=>$bodyTemplate,
			'FOOTER'=>$footerTemplate));
		
		foreach($arrayVars as $index => $value) {
			$template->set_var($index, $value);
		}

		$template->set_var('NB_INSCRITS',$nb_insc);
		$template->set_var("NBMSG",$nbmess[0]);
		
		/*ici tous les liens du programme : A COMPLETER*/
		//$template->set_var('NB_INSCRITS',$nb_insc);
		$template->set_var('LINK_CONNECT','../connect/connect.php');
		$template->set_var('LINK_FAQ','../faq/faq.php');
		$template->set_var('LINK_GOODIES','../goodies/goodies.php');
		$template->set_var('LINK_INDEX','../index/index.php');
		$template->set_var('LINK_LOGIN','../login/login.php');
		$template->set_var('LINK_MAIN','../main/main.php');
		$template->set_var('LINK_VISITE','../visite/visite.php');
		$template->set_var('LINK_REGLES','../common/documents/regles.pdf');

		$template->set_var('LINK_INSCRIPTION','../inscription/inscription.php');
		$template->set_var('LINK_SUITEINSCRIPTION','../inscription/suiteInscription.php');
		$template->set_var('LINK_FININSCRIPTION','../inscription/finInscription.php');
		$template->set_var('LINK_COMPTE','../compte/compte.php');
		$template->set_var('LINK_MESSAGERIE','../connect/connect.php?file=messagerie');
		
		//(liens vers des pages encore manquantes)
		$template->set_var('LINK_TROC','../troc/troc.php');
		
		//Lien du terrier et descendant
		$template->set_var('LINK_TERRIER','../terrier/terrier.php');
		$template->set_var('LINK_FOIRE','../foire/foire.php');
		$template->set_var('LINK_BANQUE','../banque/banque.php');
		$template->set_var('LINK_REPOS','../repos/repos.php');
		$template->set_var('LINK_BOUTIQUE','../boutique/boutique.php');
		$template->set_var('LINK_ANNONCE','../annonce/annonces.php');
		
		/*affichage*/
		
		$template->parse('OUTPUT','HEADER',true);
		$template->parse('OUTPUT','MENU',true);
		$template->parse('OUTPUT','BODY',true);
		$template->parse('OUTPUT','FOOTER',true);

		$template->p('OUTPUT');

	}
?>
