<?php
class GridCovensol{

	function GridCovensol($propiedades=array()){		
			/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
			// Function: correspondencia
			// Access: public (GridCovensol)
			// Description: Constructor de la Clase
			// Creado Por: Lic. Edgar A. Quintero
			// Fecha Creación: 17/08/2014 								
			// Fecha Última Modificación : 
			/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
			global $ruta;
			require_once("class_mensajes.php");			
			$this->msg=new class_mensajes();
			
			
	}
	
	function InitMarcoGrid($datos=array()){
			 $this->ParametrosGrid();
			 echo '<table width="'.($this->AnchoTotal + $this->cellspacing*2).'" border="0" align="center" cellpadding="0" cellspacing="'.$this->cellspacing.'" class="contorno">';	
			    echo '<tr>';
			        echo '<td>';
						echo '<table id="'.$this->IdGrid.'" width="'.$this->AnchoTotal.'" border="1" cellpadding="0" cellspacing=""  bordercolor="#CCCCCC" bgcolor="#FFFFFF" style="border-collapse:collapse">';
			 return true;
	}	
	
	function AddColumn($pos,$titulo,$ancho){
			 $this->anchoCol[$pos] = $ancho;
			 $this->tituloCol[$pos] = $titulo;
			 $this->idCol[$pos]=$pos;			 
			 return true;
	}	
	
	function ParametrosGrid($datos=array()){
			 $this->AnchoTotal = array_sum($this->anchoCol);
			 $this->CantidadColumnas = count($this->anchoCol);
			 $this->cellspacing = $this->cellspacing?$this->cellspacing:20;	
			 $this->PrefixCell = $this->IdGrid.'-cell-';
			 $this->DisabledGrid = $this->BloqGrid?' disabled ':"";
			 return true;
	}	
	
	function EncabezadoGrid(){			 
		 echo '<tr class="titulo-celda">';			 
		 for($pos=1;$pos<=$this->CantidadColumnas;$pos++){
			echo '<td width="'.$this->anchoCol[$pos].'" align="center">'.$this->tituloCol[$pos].'</td>';
		 }
		 echo '</tr>';
		 return true;
	}	
	
	function TituloGrid($titulo){			 
		 echo '<tr class="titulo-celda">';			 
		 echo '<td colspan="'.$this->CantidadColumnas.'" align="center" class="formato-azul">'.$titulo.'</td>';	
		 echo '</tr>';
		 return true;
	}	
	
	function AddDataCell($pos,$campo,$valor,$align,$tipo='html',$widthElem=35){
			 $this->DataCell[$pos] = $valor;
			 $this->alignCell[$pos] = $align;
			 $this->IdName[$pos] = $this->PrefixCell.$campo.$this->NroFila;	
			 $this->widthElem[$pos] = $widthElem;
			 $this->TipoForm[$pos] = $tipo;	
			 //$this->JsOnClickCell[$pos] = $this->OnClickCell;
			 //$this->JsOnClickComp[$pos] = $this->OnClickComp;	 
			 return true;
	}
	
	function FilaGrid(){			 
		 $init = '<tr id="filagrid" style="'.$this->EstiloRow.'" onClick="'.$this->JsOnClickRow.'">';
		 $fila="";			 
		 for($pos=1;$pos<=$this->CantidadColumnas;$pos++){
		    $this->posicion = $pos;
			$fila .= '<td width="'.$this->anchoCol[$pos].'" align="'.$this->alignCell[$pos].'" onClick="'.$this->JsOnClickCell[$pos].'" valign="top">';
			//$fila .= '<a href="#" "'.$this->OnClick.'">';
			$fila .= $this->FotmatDataCell();
			//$fila .= '</a>';
			$fila .= $this->CamposHidden;
			$fila .= '</td>';
		 }
		 $end  = '</tr>';
		 
		 $tr = $init.$fila.$end;
		 echo $tr;
	}	
	
	function FotmatDataCell($datos=array()){
		    
			switch($this->TipoForm[$this->posicion]){
					case 'cell':
						   $datosFormat = '<input type="text" 
						                         class="sin-borde" 
												 style="text-align:'.$this->alignCell[$pos].';"
												  size="'.$this->CaracteresCell[$this->posicion].'" 
												  name="'.$this->IdName[$this->posicion].'" 
												    id="'.$this->IdName[$this->posicion].'"  
												 value="'.$this->DataCell[$this->posicion].'" 
												 readonly />';
						   break;
					case 'cell_numeric':
						   $datosFormat = '<input type="text" 
						                         class="sin-borde" 
												 style="text-align:right; color:#000000; font-size:10px;" 
												  size="'.$this->CaracteresCell[$this->posicion].'" 
												  name="'.$this->IdName[$this->posicion].'" 
												    id="'.$this->IdName[$this->posicion].'"  
												 value="'.number_format($this->DataCell[$this->posicion],2,',','.').'" 
												 readonly />';
						   break;
					case 'html':
						   $datosFormat = $this->DataCell[$this->posicion];
						   break;  
				    case 'html_numeric':					
						   $datosFormat = number_format($this->DataCell[$this->posicion],2,',','.');
						   break;
				    case 'chk':
					       $checked = $this->Checked[$this->posicion]?" checked ":"";
						   $disabled = $this->DisabledComp[$this->posicion]?" disabled ":"";						   
						   $datosFormat = '<input type="checkbox" 
						                          name="'.$this->IdName[$this->posicion].'" 
												    id="'.$this->IdName[$this->posicion].'" 
											   onclick="'.$this->JsOnClickComp[$this->posicion].'" 
											     value="'.$this->DataCell[$this->posicion].'"
											           "'.$checked.'"
											           "'.$this->DisabledGrid.'"
													   '.$disabled.'
											/>';
						   break;
					case 'numericEdit':
						   $datosFormat = '<input type="text" 
												 class="sin-borde" 
												 style="text-align:right; color:#000000; font-size:10px;"
												  size="'.$this->widthElem[$this->posicion].'" 
												  name="'.$this->IdName[$this->posicion].'" 
													id="'.$this->IdName[$this->posicion].'"  
												 value="'.$this->DataCell[$this->posicion].'"
											   onclick="'.$this->JsOnClickComp[$this->posicion].'"
												onblur="'.$this->JsOnblurComp[$this->posicion].'"
											onKeyPress="'.$this->JsOnKeyPress[$this->posicion].'" 
											           "'.$this->DisabledGrid.'"
											/>';
						   break;	
			}
			
			return $datosFormat;
	}
	
	function AddCampoHidden($campo,$valor){		    	
		$this->CamposHidden .= '<input name="'.$this->PrefixCell.$campo.$this->NroFila.'" type="hidden" id="'.$this->PrefixCell.$campo.$this->NroFila.'"  value="'.$valor.'"  '.$DisabledChk.' />';
	}
	
	function InitRow(){
		$this->CamposHidden="";
	}
	
	function EndMarcoGrid($datos=array()){
						echo '</table>';
			 		echo '</td>';
			 	echo '</tr>';
			 echo '</table>';
			 return true;
	}

}

?>