<?
////////////////////////////////////////////////////
// Conciliación: gestión de conciliación de activos
// Version: 1.0
//
// Copyright (C) 2014  Eustotem Multimedia, S.L.
//
// License: MIT, see LICENSE
////////////////////////////////////////////////////


class Process{
	public $retorno;
	
	public function toUpperCase($param,$format=NULL){
		$this->retorno->content=mb_strtoupper($param,"utf-8");
		return $this->retorno;
	}
	
	public function toLowerCase($param,$format=NULL){
		$this->retorno->content=mb_strtolower($param,"utf-8");
		return $this->retorno;
	}
	
	public function nl2Br($param,$format=NULL){
		$this->retorno->content=nl2br($param);
		return $this->retorno;
	}
	
	public function dateFormat($date,$format){
		$this->retorno->content=date($format,strtotime($date));
		return $this->retorno;
	}
	
	public function numberFormat($num,$format){
		$params=explode(STR_SEPARATOR,$format);
		$decimals=$params[0];
		$dec_point=isset($params[1]) ? $params[1] : ".";
		$th_sep=isset($params[2]) ? $params[2] : ",";
		$this->retorno->content=number_format($num,$decimals,$dec_point,$th_sep);
		return $this->retorno;
	}
	
	public function getAttachedHTML($valor, $format=NULL){
		$temp=explode(".",$valor);
		$extension=array_pop($temp);
		$tipo="generic.png"; $rutaicono="../../assets/repository/"; $rutaarchivo="../../assets/activos/";
		$tipos=array(
			"calc.png"=>array("ods","xls","xlsx","csv","tab"),
			"doc.png"=>array("doc","docx","odt","txt","rtf"),
			"xml.png"=>array("xml","htm","html"),
			"pdf.png"=>array("pdf"),
			"zip.png"=>array("zip","rar","tar","gz"),
			"exe.png"=>array("exe","msi"),
			"img.png"=>array("jpg","jpeg","gif","png","tif","psd"),
			"vid.png"=>array("avi","mov","mpeg","mp4","flv","wmv"),
			"audio.png"=>array("mp3","ogg","wav","wma")
		);
		foreach($tipos as $key=>$value){
			if(in_array($extension,$value)){
				$tipo=$key;
				break;
			}
		}
		if($tipo=="img.png"){
			$tipo="th_{$valor}";
			$rutaicono="../../assets/activos/";	
		}
		$this->retorno->content="<a href='{$rutaarchivo}{$valor}' target='_blank'><img src='{$rutaicono}{$tipo}' align='absmiddle' /></a>";
		return $this->retorno;
	}
	
	public function booleanFormat($valor,$format){
		$params=explode(STR_SEPARATOR,$format);
		$valor= ($valor==true) ? $params[0] : $params[1];
		$this->retorno->content=$valor;
		return $this->retorno;
	}
	
	public function enumerate($valor,$enum){
		$params=explode(STR_SEPARATOR,$enum);
		$this->retorno->content=$params[$valor];
		return $this->retorno;
	}
	
	public function capitalize($param,$format=NULL){
		$this->retorno->content=mb_strtoupper(mb_substr($param, 0, 1)) . mb_substr($param, 1);
		return $this->retorno;
	}
	
	public function uncapitalize($param,$format=NULL){
		$param[0] = mb_strtolower($param[0]);
		$this->retorno->content=$param;
		return $this->retorno;
	}

	public function toYMD($param,$format=NULL){
		$this->retorno->content=$param;
		return $this->retorno;
	}
	
	public function image($param,$path){
		$img=str_replace(STR_SEPARATOR,$param,$path);
		if(file_exists($img)){
			$cadena="<img src='" . $img . "' />";
		}else{
			$cadena=$param;
		}
		$this->retorno->content=$cadena;
		return $this->retorno;
	}
}
?>