<?php

class EventoController extends AdminController {
	
	public function leercarpetaAction(){
		
		$fichero = 'simple.tif';
		$barra = AppHerramienta::getBarraDirectorio();
		/*
		$origen = APPLICATION_PATH.$barra.'ficheros'.$barra.'sinprocesar'.$barra.'1\1-2'.$barra.$fichero;
		$destino = APPLICATION_PATH.$barra.'ficheros'.$barra.'procesados'.$barra.'1\1-2'.$barra.$fichero;
		AppHerramienta::copiarFichero($origen, $destino);
		
		*/
		
		$origen = APPLICATION_PATH.$barra.'ficheros'.$barra.'sinprocesar'.$barra.'1\1-2'.$barra;
		$destino = APPLICATION_PATH.$barra.'ficheros'.$barra.'procesados'.$barra.'1\1-2'.$barra;
		AppHerramienta::copiarDirectorios($destino);
		
//		$ficheros = AppHerramienta::getFicherosDeCarpeta($directorio);
		
		//print_r($ficheros);
		die();
	} 
	
	public function fechaAction(){
		

		$fecha = '05/12/2004';
		echo $fecha;
		$fm = AppHerramienta::fechaHumanaAMysql($fecha);
		echo $fm;
		die();
	}
	
	public function evAction(){
		
		$ev = new EVAjax($evento);
		
	}
	
	public function cargaAction(){
		
		
		$caja = new VstCaja('carga');
		
		$caja = '<div id="carga"  style="width:100%;height:550px;padding:20px;background-color:#45f45d">JAmones cuadrados</div>';
		
		$button = '<button id="btcargar"  type="button" class="btn btn-default"><span class="glyphicon glyphicon-zoom-in"></span> Cargar</button>';
		
		$bt2 = '<a href="'.PUBLICURL.'/index.php/evento/index" role="button" class="btn btn-default" data-toggle="modal"
data-target="#carga">Launch modal</a>';
		
		$this->regionContenido->addElement($caja);
		$this->regionContenido->addElement($button);
		$this->regionContenido->addElement($bt2);
		
		$html =<<<HTML

				<script>
	$(document).ready(function(){
		
		$("#btcargar").click(function () {
			$("#carga").load("/evento/index");
		});
				
	});
				</script>
				
HTML;
		
$ejem ='

 <script type="text/javascript">
            $(document).ready(function() {
                $("#boton").click(function(event) {
                    $("#capa").load("'.PUBLICURL.'/index.php/evento/editar/id/3",{valor1:\'primer valor\', valor2:\'segundo valor\'}, function(response, status, xhr) {
                          if (status == "error") {
                            var msg = "Error!, algo ha sucedido: ";
                            $("#capa").html(msg + xhr.status + " " + xhr.statusText);
                          }
                        });
                });
            });            
        </script>
    <div id="capa" style="padding:20px;background-color:#45f45d" >Pulsa Actualizar capa y este texto se actualizará</div>
    <br>
       <input name="boton" id="boton" type="button" value="Actualizar capa" />

';
		
		
		
	$this->regionContenido->addElement($ejem);
		
	}
	
	public function probarvisorAction(){
		
		$fichero = APPLICATION_PATH.'/ficheros/de100.TIF';
		$numeroPagina = 90;
		
		/*$visor = new vstVisorTiff($fichero, $numeroPagina);
		$this->regionContenido->addElement($visor);
		*/
		
		AppHerramientasImagen::tiffToPng($fichero, $numeroPagina);
		
		
	}

	public function probarvisor1Action(){
		$barra = AppHerramienta::getBarraDirectorio();
		$fichero = $barra.'ficheros'.$barra.'de100.TIF';
		$visor = new vstVisorTiff($fichero, 400);
		
		$fila = new VstFila();
		$fila->addElemento($visor,6);
		$layout =  $this->getLayout();
		if ($layout instanceof LYTSmartadmin){				
		}
		$layout->reg_contenido->addElement($fila);
	
	//	AppHerramientasImagen::tiffToPng($fichero, $numeroPagina);
	
	}
	
	
	public function vertiffAction() {
		$ruta = APPLICATION_PATH.'/ficheros/de100.TIF[90]';
		$rutaCopia = APPLICATION_PATH.'/ficheros/simple.png';
		try {
			//if (!file_exists($ruta)) die('No existe el fichero 2');
		$im = new Imagick($ruta);
		$im->setimageformat('png');
		//$im->setCompression(Imagick::COMPRESSION_ZIP);
		//$im->setCompressionQuality(1);
		} catch (Excepcion $e){
			die($e);
		}
		//$im->writeimage($rutaCopia);
		
		header('Content-type:image/png');
		echo $im->getimageblob();
		//echo $im;
		die();
		
	}  
	
	public function editarAction(){
		
		/*$us = new Usuario(2);
		print_r($us);
		die();
		*/
		//echo 'EDITAR<br><br>';
/*
		$select = Evento::selectObjeto();
		$res = Evento::selectExecute($select,null, true);
		$obj = Evento::resultadoToObjeto($res);
		*/
		/*
		$url = 'http://kustomskis.com/es/configurador.html?esqui=13&modelo_esqui=37&id_product=62&disenyo=598';
		echo $url;
		echo '<br>';
		$urlc =  urlencode($url);
		echo $urlc;
		die();
		*/
		
		if ($tt==66) echo 'bien'; else echo 'mal';
		if ($tt==66) echo 'bien'; else echo 'mal';
		if ($tt==66) echo 'bien'; else echo 'mal';
		if ($tt==66) echo 'bien'; else echo 'mal';
		
		$idEvento = $this->getParametro('id');
		$evento = new Evento($idEvento);
		//print_r($evento);
		$form = new FRMEvento2c($evento);
		
		$layout =  $this->getLayout();
		
		$layout->reg_contenido->addElement($form);
		$boton = new VstBoton('/evento/editar/id/3', BASEURL, 'prueba', 'prueba');
		
		$layout->reg_contenido->addElement($boton);
		
	
	}
	
	public function indexAction() {
		//echo 'HOLA<br><br>';
		
		$usuario = usuario::UsuarioLoqueado();	

		$form = new FRMEventoBuscador();
		//$this->regionContenido->addElement($form);
		
		$lista = new LSTEvento();
		$lista->setClase('Evento');
		$lista->setMetodo('getTodos');
		//$lista->setPoderPaginar(false);
		$lista->setFiltro($form);
		$layout = $this->getLayout();
		
		/*
		/* Lsitado html
		 */
		/*
		$tabla ='
		<div class="widget-body no-padding">
			<div class="widget-body-toolbar">
			</div>
		
			<div id="dt_basic_wrapper" class="dataTables_wrapper form-inline" role="grid">
				<div class="dt-top-row">
					<div id="dt_basic_length" class="dataTables_length">
						<span class="smart-form">
							<label class="select" style="width:60px">
								<select size="1" name="dt_basic_length" aria-controls="dt_basic">
									<option value="10" selected="selected">10</option>
									<option value="25">25</option>
									<option value="50">50</option>
									<option value="100">100</option>
								</select>
								<i></i>
							</label>
						</span>
					</div>
					<div class="dataTables_filter" id="dt_basic_filter">
						<div class="input-group">
							<span class="input-group-addon"><i class="fa fa-search"></i></span>
							<input class="form-control" placeholder="Filter" type="text" aria-controls="dt_basic">
						</div>
					</div>
				</div>
			</div>
			<div class="dt-wrapper">
				<table id="dt_basic" class="table table-striped table-bordered table-hover dataTable" aria-describedby="dt_basic_info">
					<thead>
					<tr role="row"><th class="sorting_asc" role="columnheader" tabindex="0" aria-controls="dt_basic" rowspan="1" colspan="1" aria-sort="ascending" aria-label="ID: activate to sort column descending" style="width: 22px;">ID</th><th class="sorting" role="columnheader" tabindex="0" aria-controls="dt_basic" rowspan="1" colspan="1" aria-label="Name: activate to sort column ascending" style="width: 84px;">Name</th><th class="sorting" role="columnheader" tabindex="0" aria-controls="dt_basic" rowspan="1" colspan="1" aria-label="Phone: activate to sort column ascending" style="width: 104px;">Phone</th><th class="sorting" role="columnheader" tabindex="0" aria-controls="dt_basic" rowspan="1" colspan="1" aria-label="Company: activate to sort column ascending" style="width: 293px;">Company</th><th class="sorting" role="columnheader" tabindex="0" aria-controls="dt_basic" rowspan="1" colspan="1" aria-label="Zip: activate to sort column ascending" style="width: 67px;">Zip</th><th class="sorting" role="columnheader" tabindex="0" aria-controls="dt_basic" rowspan="1" colspan="1" aria-label="City: activate to sort column ascending" style="width: 178px;">City</th><th class="sorting" role="columnheader" tabindex="0" aria-controls="dt_basic" rowspan="1" colspan="1" aria-label="Date: activate to sort column ascending" style="width: 59px;">Date</th></tr>
					</thead>
						
					<tbody role="alert" aria-live="polite" aria-relevant="all">
					<tr class="odd">
					<td class=" sorting_1">1</td>
					<td class=" ">Jennifer</td>
					<td class=" ">1-342-463-8341</td>
					<td class=" ">Et Rutrum Non Associates</td>
					<td class=" ">35728</td>
					<td class=" ">Fogo</td>
					<td class=" ">03/04/14</td>
					</tr><tr class="even">
					<td class=" sorting_1">2</td>
					<td class=" ">Clark</td>
					<td class=" ">1-516-859-1120</td>
					<td class=" ">Nam Ac Inc.</td>
					<td class=" ">7162</td>
					<td class=" ">Machelen</td>
					<td class=" ">03/23/13</td>
					</tr><tr class="odd">
					<td class=" sorting_1">10</td>
					<td class=" ">Cassady</td>
					<td class=" ">1-212-965-8381</td>
					<td class=" ">Vitae Erat Vel Company</td>
					<td class=" ">5898</td>
					<td class=" ">Huntly</td>
					<td class=" ">10/07/13</td>
					</tr></tbody>
				</table>
			</div>
			<div class="dt-row dt-bottom-row">
				<div class="row">
					<div class="col-sm-6">
						<div class="dataTables_info" id="dt_basic_info">Showing 1 to 10 of 100 entries</div>
					</div>
					<div class="col-sm-6 text-right">
						<div class="dataTables_paginate paging_bootstrap_full">
							<ul class="pagination">
								<li class="first disabled"><a href="#">First</a></li>
								<li class="prev disabled"><a href="#">Previous</a></li>
								<li class="active"><a href="#">1</a></li>
								<li><a href="#">2</a></li>
								<li><a href="#">3</a></li>
								<li class="next"><a href="#">Next</a></li>
								<li class="last"><a href="#">Last</a></li>
							</ul>
						</div>
					</div>
				</div>
			</div>
		</div>
		';
		*/
		
		
		$fila = new VstFila();
		$fila->addElemento($form, 3);
		$fila->addElemento($lista);
		$layout->reg_contenido->addElement($fila);
		$cajavacia = new VstCaja('formulario_edicion');
		$layout->reg_contenido->addElement($cajavacia);
		//$layout->reg_contenido->addElement($lista);
		
		$boton = new VstBoton('/evento/index', BASEURL, 'prueba', 'prueba');
		
		$layout->reg_contenido->addElement($boton);
		/* 
		 * Pruebas de AppObjeto
		 * 
		 * 
		$ev = new Evento(1);
		
		$select = Evento::selectObjeto();
		echo $select;
		$parametros = array();
		$parametros['listado']='1';
		$res = Evento::selectExecute($select, $parametros);
		$res->setClass('Evento');
		print_r($res);
		$res2 = Evento::selectExecute($select, $parametros);
		$res->setClass('Evento');
		print_r($res2);
		$res->mergeListadosResultados('eventos_hijos', $res2, 'idEvento', 'idEvento');
		print_r($res);
			
		$res->setClass('Evento');
		$obj = $res->toObjeto();
		print_r($res);
		print_r($obj);

		$ev = new Evento(1);
		$ev->remove();
		$ev->setNombre('Victoria');
		$ev->setFecha('05/08/2014');
		print_r($ev);
		$ev->save();
		print_r($ev);
		die();
		*/
		
		
	}
	
	
	public function indexcrudAction() {
		$lista = new LSTEventoCrud();
		$lista->setClase('Evento');
		$lista->setMetodo('getTodos');

		$botonera = new VstCaja('botonera');
		$boton = new VstBoton('/evento/editarcrud');
		$boton->setTexto('Nuevo');
		$boton->setClase('btn-primary btn');
		$boton->setModal(true);
		$boton->setDestino('#formulario_edicion');
		
		$botonera->addElement($boton);
		$cajavacia = new VstCaja('formulario_edicion');
		$evento = new EVCargaDinamica('#formulario_edicion', '/evento/editarcrud');
		
		$layout = $this->getLayout();
		$layout->reg_contenido->addElement($botonera);
		$layout->reg_contenido->addElement($lista);
		$layout->reg_contenido->addElement($cajavacia);
		//$layout->reg_contenido->addElement($lista);
	
	
	
	
	
	}
	
	public function editarcrudAction(){
	
		$idEvento = $this->getParametro('id');
		$evento = new Evento($idEvento);
	
		$form = new FRMEvento2cCrud($evento);
		

		$layout =  $this->getLayout();
		$layout->reg_contenido->addElement($form);
	
	}
	public function eliminarAction(){
		$id = (int) $this->_request->getParam('id', -1);
		
		$elemento = new Evento($id);
		try {
			$elemento->remove();
			AppAjax::setAccion('refrescar');
		} catch (Exception $e) {
			AppAjax::setMensajeError('grid', (string)$e);
		}
		
	}
	
}