<?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 CurrentCoordinationObjPrint.php
*
* Ce fichier contient la classe CurrentCoordinationObjPrint
*
* @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 CurrentCoordinationObjPrint
* @docreview Tristan <tristan@initiance.com> | 30-10-2005
*/
if ( !defined('SYSTEM_IN') )
{
 die("Hacking attempt");
}

/**
* Classe CurrentCoordinationObjPrint
*<p>Cette classe permet la récupération de CurrentCoordinationObjPrint</p>
* @package object_printing
* @subpackage CurrentCoordinationObjPrint
*/

class CurrentCoordinationObjPrint extends Printing
{
/**
* Variable de remplacement pour le contenu de CurrentCoordinationObj
* @access private
*/
	var $alternateData = null;

/**
* Indique si la fonction __print a déjà été appelée.
* @access private
*/
	var $isPrint = false;

	//
	// Constructor
	//
/**
* Constructeur de la classe CurrentCoordinationObjPrint PHP4
* @access public
*/
	function CurrentCoordinationObjPrint()
	{
		$this->__construct();
	}

/**
* Constructeur de la classe CurrentCoordinationObjPrint PHP5
* @access public
*/
	function __construct()
	{
		parent::__construct("1.0", "Olivier DEVAINE", "Affichage de la NavigationNode");
	}

/**
* Spécifie un contenu par lequel le CurrentCoordinationObj sera remplacé
* @access public
*/
	function setAlternateData($data){
		if(!empty($data) && is_string($data)){
			$this->alternateData=$data;
			if($this->isPrint) $this->__print();
		}
	}

/**
* Remplace dans la template principale
* @access public
*/
	function __print()
	{
		$this->isPrint = True;
		if(is_null($this->alternateData)){
				$MaTemplate = new ModeliXeQware($GLOBALS['SYSTEM_TEMPLATE_PATH'].$GLOBALS['SYSTEM_TEMPLATE_DIR']."object_printing/currentcoordinationobjprint/main.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"];
				$url=$_SERVER['SCRIPT_NAME'];
				$url=addIdToUrl($url);
	
				/* Récupération du tree pour affichage de la barre d'emplacement */
				$node=$GLOBALS["SYSTEM_USER_SESSION"]->getNode(nid());
				$MaTemplate->MxText("TxtInfoEmplacement", getMessage("TxtInfoEmplacement"));
				if ($MaTemplate->IsMxBloc("PATH"))
				{
					/* génération du tableau des éléments */
					$tab=array();
					while ($node->getIdPere()!=0)
					{
						/* récuperation 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.gif";
						}
	
						if ($node->getLibelle($currentCode) != "")
							$name = $node->getLibelle($currentCode);
						else
							$name = $node->getLibelle($defaultCode);
	
// 						$name = eregi_replace("^[[:space:]]*[a-z]+[.)".chr(176)."][[:space:]]+", "", $name);
						$name = preg_replace("/^[[:space:]]*[a-z]+[.)".chr(176)."][[:space:]]+/i", "", $name);
						$urlToGo = formatUrlNode("navigationNode", $node->getId());
						$tab[]=array($name, $img, $urlToGo);
						if ($node->getId()==eid())
							break;
						$node=$GLOBALS["SYSTEM_USER_SESSION"]->getNode($node->getIdPere());
					}
	
					/* affichage de tt ca */
					for($i=(count($tab)-1); $i>=0; $i--)
					{
						$MaTemplate->MxText("PATH.name", htmlentitiesconv($tab[$i][0]));
						$MaTemplate->MxAttribut("PATH.url", htmlentitiesconv($tab[$i][2]));
						$MaTemplate->MxImage("PATH.picto", $tab[$i][1] ,htmlentitiesconv($tab[$i][0]),"");
						$MaTemplate->MxBloc("PATH", "loop");
					}
				}
				
				if (is_object($GLOBALS["SYSTEM_CONTROL"]->currentCoordinationObject)){
					/* recuperation de l'image de la langue courante */
					if (file_exists($GLOBALS['SYSTEM_TEMPLATE_PATH'].$GLOBALS['SYSTEM_TEMPLATE_DIR']."media/picto/object/".strtolower($GLOBALS["SYSTEM_CONTROL"]->currentCoordinationObject->getIcone())) && $GLOBALS["SYSTEM_CONTROL"]->currentCoordinationObject->getIcone() !="")
					{
						$img=$GLOBALS['SYSTEM_TEMPLATE_PATH'].$GLOBALS['SYSTEM_TEMPLATE_DIR']."media/picto/object/".strtolower($GLOBALS["SYSTEM_CONTROL"]->currentCoordinationObject->getIcone());
					}else{
						$img=$GLOBALS['SYSTEM_TEMPLATE_PATH'].$GLOBALS['SYSTEM_TEMPLATE_DIR']."media/picto/object/defaultobject.gif";
					}
		
					if ($GLOBALS["SYSTEM_CONTROL"]->currentCoordinationObject->getName($currentCode) != "")
						$name = $GLOBALS["SYSTEM_CONTROL"]->currentCoordinationObject->getName($currentCode);
					else
						$name = $GLOBALS["SYSTEM_CONTROL"]->currentCoordinationObject->getName($defaultCode);
				}else{
					$img=$GLOBALS['SYSTEM_TEMPLATE_PATH'].$GLOBALS['SYSTEM_TEMPLATE_DIR']."media/picto/object/defaultobject.gif";
					$name="";
				}
				/*Fonction permettant de supprimer les numéros, le point et l'espace à l'affichage*/
// 				$name = eregi_replace("^[[:space:]]*[a-z]+[.)".chr(176)."][[:space:]]+", "", $name);
				$name = preg_replace("/^[[:space:]]*[a-z]+[.)".chr(176)."][[:space:]]+/i", "", $name);
	
				if ($MaTemplate->isMxFlag("CoodinationObjPicto","image"))
				{
					$MaTemplate->MxImage("CoodinationObjPicto", $img ,htmlentitiesconv($name),"");
				}
				if ($MaTemplate->isMxFlag("CoodinationObjName","text"))
				{
					$MaTemplate->MxText("CoodinationObjName", htmlentitiesconv($name));
				}
				$MaTemplate->MxAttribut("CoodinationObjNameUrl", htmlentitiesconv($url));
				$data=$MaTemplate->MxWrite();
	
				$GLOBALS["SYSTEM_TEMPLATE"]->MxText("currentcoordinationobjprint", $data);
				$GLOBALS["SYSTEM_TEMPLATE"]->MxText("currentcoordinationtitle", htmlentitiesconv($GLOBALS["CONF_SITE_NAME"].$name));
				if (is_object($GLOBALS["SYSTEM_CONTROL"]->currentCoordinationObject)){
					$GLOBALS["SYSTEM_TEMPLATE"]->MxAttribut("CurrentCoordinationDescription", $GLOBALS["SYSTEM_CONTROL"]->currentCoordinationObject->getResume()." ");
					$GLOBALS["SYSTEM_TEMPLATE"]->MxAttribut("CurrentCoordinationKeysWords", $GLOBALS["SYSTEM_CONTROL"]->currentCoordinationObject->getKeyWord()." ");
				}
				return true;
		} else {
			$GLOBALS["SYSTEM_TEMPLATE"]->MxText("currentcoordinationobjprint", $this->alternateData);
		}
	}
}
?>
