<?php
	
	class sysTemplate {

	  var $template;

	  function sysTemplate ( $ts, $tpl ) {

      ( @file_exists ( $tpl ) ) ? $this->template = @file_get_contents ( $tpl ) : die ( $this->getErrorTemp ( "Si &egrave; verificato un errore!<br /><br />Il file &quot;" . $tpl . "&quot; non &egrave; presente" ) );
      
      $this->parserT ( $ts );

  	}

  	function parserT ( $ts ) {
    	
    	if ( @count ( $ts ) > 0 ) {
      
      	foreach( $ts as $t => $d ) {
        
        	$d = ( @file_exists ( $d ) ) ? $this->getFile ( $d ) : $d;
        
        	$this->template = @str_replace ( "{" . $t . "}", $d, $this->template );
      	
      	}

    	} else {
      
      	die ( $this->getErrorTemp ( "Attenzione: impossibile eseguire il replace dei tags." ) );
    	
    	}
  	
  	}

  	function getFile ( $doc ) {
    	
    	@ob_start();
    	
    	include( $doc );
    
    	$contenuto = @ob_get_contents();
    	
    	@ob_end_clean();
    	
    	return $contenuto;
  	
  	}
  	
  	function getErrorTemp( $t_err ) {
  	
  		$err_mex = $t_err;
  	
  		@include( $_SERVER['DOCUMENT_ROOT'] . "/graphic/pages/errore.php" );
  		 
  		$messaggio = $err_tpl;
  		 
  		return $messaggio;
  	
  	}

  	function show() {
    
    	return $this->template;
  	
  	}
	
	}

?> 
