<?php
/**-----------------------------------------------
*
* Rooty, 2018 <rooty@rooty.me>
*
*
* This software is protected by copyright, please
* read the file COPYRIGHT.
* This program is distributed in the hope that it
* will be useful, but without any warranty; without
* even the implied warranty of merchantability or
* fitness for a particular purpose. Please
* read the file LICENCE.
*
* Fichier NavigationNodePrint.php
*
* Ce fichier contient la classe NavigationNodePrint
*
* @author Initiance <www.initiance.com|martial@initiance.com>
* @copyright Copyright &copy; 2009-2018, Rooty 
* @since 2004/06/07
* @version 0.3
* @link www.rooty.me
* @package object_printing
* @subpackage NavigationNodePrint 
*/

if ( !defined('SYSTEM_IN') )
{
 die("Hacking attempt");
}

/**
* Classe NavigationNodePrint
*<p>Cette classe permet la recuperation des NavigationNodePrint</p>
* @package object_printing
* @subpackage NavigationNodePrint 
*/

class NavigationNodePrint extends Printing
{
	//
	// Constructor
	//
/**
* Constructeur de la classe NavigationNodePrint
* @access public
*/
	function NavigationNodePrint()
	{
		$this->__construct();
	}

	function __construct()
	{
		parent::__construct("1.0", "Olivier DEVAINE", "Affichage de la NavigationNode");
	}

/**
* Remplace dans la template principale
* @access public
*/
	function __print()
	{
		/* gestion du lib en fonction de la langue courante */
		$currentCode=$GLOBALS["SYSTEM_USER_SESSION"]->langue->getCode();
		$defaultCode=$GLOBALS["SYSTEM_DEFAULT_LANGUAGE_CODE"];
		/* fin récupération des codes par defaut */

		$MaTemplate = new ModeliXeQware($GLOBALS['SYSTEM_TEMPLATE_PATH'].$GLOBALS['SYSTEM_TEMPLATE_DIR']."object_printing/navigationnodeprint/main.mxt");
		$MaTemplate->SetModeliXe(true);
		$MaTemplate->MxText("NavigationPrintName", getMessage("NavigationPrintName"));
		$Node	=$GLOBALS["SYSTEM_USER_SESSION"]->getNode($GLOBALS["SYSTEM_USER_SESSION"]->entryNodeId);

		/* recuperation de l'image de la langue courante */
		if (file_exists($GLOBALS['SYSTEM_TEMPLATE_PATH'].$GLOBALS['SYSTEM_TEMPLATE_DIR']."media/picto/node/".strtolower($Node->getIcone())) && ($Node->getIcone()!=""))
		{
			$img=$GLOBALS['SYSTEM_TEMPLATE_PATH'].$GLOBALS['SYSTEM_TEMPLATE_DIR']."media/picto/node/".strtolower($Node->getIcone());
		}else{
			$img=$GLOBALS['SYSTEM_TEMPLATE_PATH'].$GLOBALS['SYSTEM_TEMPLATE_DIR']."media/picto/node/defaultnode.png";
		}

		$urlToGo = formatUrlNode("navigationNode", $Node->getId());

		/* pour l'url */
		$MaTemplate->MxAttribut("nodeUrl", $urlToGo);
		$lib=$Node->getLibelle($currentCode);
		if ($lib=="")
		{
			$lib=$Node->getLibelle($defaultCode);
		}

		/*Fonction permettant de supprimer les numeros, le point et l'espace à l'affichage*/
		$lib = eregi_replace("^[[:space:]]*[a-z]+[.)".chr(176)."][[:space:]]+", "", $lib);
		$MaTemplate->MxImage("pictoNode", $img ,htmlentitiesconv($lib),"");
		
		/* objet en cours */
		if ($Node->getId()==nid())
			$MaTemplate->MxAttribut("style", "NavigationSelected");
		else
			$MaTemplate->MxAttribut("style", "Navigation");
		/* Fin des objets en cours */

		$MaTemplate->MxText("nodeName", htmlentitiesconv($lib));

		/* On affiche les noeuds suivants */
		$forNode=$this->printForNode($GLOBALS["SYSTEM_USER_SESSION"]->entryNodeId);
		$MaTemplate->MxText("Navigation", $forNode);
		$data=$MaTemplate->MxWrite();

		if ($forNode!="")
		{
			$GLOBALS["SYSTEM_TEMPLATE"]->MxText("navigationnodeprint", $data);
		}else{
			$GLOBALS["SYSTEM_TEMPLATE"]->MxText("navigationnodeprint", "");
		}
	}

/**
* affichage d'un noeud et de tous ses sous noeuds
* @access public
*/
	function printForNode($nodeId)
	{
		global $SERVER_NAME, $SCRIPT_NAME, $CONF_PERSISTANT_SECURE;
		$tabNode	=$this->getNodeSon($nodeId);

		if (count($tabNode)==0)
			return "";

		$MaTemplate = new ModeliXeQware($GLOBALS['SYSTEM_TEMPLATE_PATH'].$GLOBALS['SYSTEM_TEMPLATE_DIR']."object_printing/navigationnodeprint/navigationnode.mxt");
		$MaTemplate->SetModeliXe(true);

		/* gestion du lib en fonction de la langue courante */
		$currentCode=$GLOBALS["SYSTEM_USER_SESSION"]->langue->getCode();
		$defaultCode=$GLOBALS["SYSTEM_DEFAULT_LANGUAGE_CODE"];
		/* fin récupération des codes par defaut */

		for ($i=0; $i<count($tabNode);$i++)
		{
			$lib=$tabNode[$i]->getLibelle($currentCode);
			if ($lib=="")
			{
				$lib=$tabNode[$i]->getLibelle($defaultCode);
			}
			$tabName[$i]=$lib;
		}
		asort($tabName);
		reset($tabName);
		while (list($i, $lib) = each($tabName))
		{
			/* recuperation de l'image de la langue courante */
			if (file_exists($GLOBALS['SYSTEM_TEMPLATE_PATH'].$GLOBALS['SYSTEM_TEMPLATE_DIR']."media/picto/node/".strtolower($tabNode[$i]->getIcone())) && ($tabNode[$i]->getIcone()!=""))
			{
				$img=$GLOBALS['SYSTEM_TEMPLATE_PATH'].$GLOBALS['SYSTEM_TEMPLATE_DIR']."media/picto/node/".strtolower($tabNode[$i]->getIcone());
			}else{
				$img=$GLOBALS['SYSTEM_TEMPLATE_PATH'].$GLOBALS['SYSTEM_TEMPLATE_DIR']."media/picto/node/defaultnode.png";
			}

			$urlToGo = formatUrlNode("navigationNode", $tabNode[$i]->getId());

			/* pour l'url */
			$MaTemplate->MxAttribut("bloc1.nodeUrl", ($urlToGo));
			$lib=$tabNode[$i]->getLibelle($currentCode);

			if ($lib=="")
			{
				$lib=$tabNode[$i]->getLibelle($defaultCode);
			}

			/*Fonction permettant de supprimer les numeros, le point et l'espace à l'affichage*/
			$lib = eregi_replace("^[[:space:]]*[a-z]+[.)".chr(176)."][[:space:]]+", "", $lib);
			$MaTemplate->MxImage("bloc1.pictoNode", $img ,htmlentitiesconv($lib)," border='0'");
			/* objet en cours */
			if ($tabNode[$i]->getId()==nid())
				$MaTemplate->MxAttribut("bloc1.style", "NavigationSelected");
			else
				$MaTemplate->MxAttribut("bloc1.style", "Navigation");
			/* Fin des objets en cours */

			if (!isset($_GET['oid']))
			{
				if(isset($GLOBALS["SYSTEM_PRINTING"]["HelpPrint"])) $GLOBALS["SYSTEM_PRINTING"]["HelpPrint"]->desactivate();
			}

			$MaTemplate->MxText("bloc1.nodeName", htmlentitiesconv($lib));
			// on récupére les sous niveau...
			$ssLevel=$this->printForNode($tabNode[$i]->getId());
			$MaTemplate->MxText("bloc1.nodeDir", $ssLevel);
			$MaTemplate->MxBloc("bloc1", "loop");
		}
		$data=$MaTemplate->MxWrite();
		return $data;
	}

/**
* recupere les repertoires d'un noeud
* @access public
*/
	function getNodeSon($nodeId)
	{
		$tab=$GLOBALS["SYSTEM_USER_SESSION"]->getSonOfNodeAllowed($nodeId);
		return $tab;
	}
}
?>