<?php

class VstVisorTiff {
	
	protected $fichero;
	protected $altura;

	protected $name;
	
	public function __construct($fichero, $alto= 300) {
		//AppLibreria::addJs('tiff.js');
		//AppLibreria::addJs('visortiff.js');
		$this->fichero = $fichero;
		
		$this->altura = $alto;
		
		
		$microtime = '';
		$microtime = microtime(true);
		$microtime -= floor($microtime);
		$microtime *=1000000;
		$microtime = floor($microtime);
		$this->setName('visor_tiff_'. get_class($this). date('His').$microtime);
		
	}
	
	public function setName($nombre){
		$this->name = $nombre;
	}
	
	
	public function render(){
		$fichero = urlencode($this->fichero);
		$fichero = urlencode($fichero);
		
		$imagen =  BASEURL.'/file/dlfile/?fichero='.$fichero; 
		
		$parametros = array(
				'fichero'=> $imagen,
				'alto' => $this->altura
		);
		
		$html = '
				<div class="panel panel-default" id="'.$this->name.'">
			  		<div class="panel-heading" style="padding:5px 15px 0px 15px">
						<div class="row">
							<div class="col-sm-4" style="line-height:28px">
								VISOR DE FICHEROS
							</div>
							<div class="col-sm-4 text-right" style="line-height:28px">
								<p class="text-info info_vista" id="">Cargando...</p>
							</div>
							<div class="col-sm-4 text-right">
								<ul class="pagination no-margin"><li class="imprimir"><a  href="#"><span class="glyphicon glyphicon-print"></span> Imprimir</a></li></ul>
								<ul class="pagination no-margin"><li class="anterior"><a  href="#">«</a></li><li class="siguiente"><a  href="#">»</a></li></ul>
							</div>
						</div>
					</div>
			  		<div class="panel-body">
					</div>
				</div>';
		$html .= '
		<script>
			$(document).ready(function(){
				
				loadScript( \''.PUBLICURL.'/app/js/tiff.js\' , function(){
				loadScript( \''.PUBLICURL.'/app/js/visortiff.js\' , function(){ $(\'#'.$this->name.'\').visorTIFF('. json_encode($parametros) .');});
				});
			});
			</script>
		';

		return $html;
		
	}
	
}