<?php
//include "clase.conexion.php";
class clsMenu extends clsConexion{
	public $varTitulo = "MENU DEL SISTEMA";
	public $varMyTabla  = "_sys_menu";
	public $varMyID  	  = "id_menu";
	function FormuBusqueda() {
		$varTabla=array("id"=>"tabla", "name"=>"table", "tamano"=>"500", "clase"=>"FormTitulo", "titulo"=>$this->varTitulo." - BUSQUEDA",
						"formu"=>array("id"=>"form", "name"=>"form", "metodo"=>"POST", "onsubmit"=>"return false;"),						
						"ocult"=>array(array("tipo"=>"oculto", "id"=>"titu", "name"=>"titu", "valor"=>$this->varTitulo),
									   array("tipo"=>"oculto", "id"=>"opt", "name"=>"opt", "valor"=>$Opcion)
									  ),
						"conte"=>array(array("titulo"=>"Codigo :", "clase1"=>"FormCampo1", "clase2"=>"interior", "tamano"=>"100",
											 "campo" =>array("tipo"=>"texto", "id"=>"cod", "name"=>"cod", 
											 "alinear"=>"center","valor"=>$_POST["cod"], "ancho"=>"70")),
									   array("titulo"=>"Descripci&oacute;n :", "clase1"=>"FormCampo1", "clase2"=>"interior", 
											  "campo" =>array("tipo"=>"texto", "id"=>"nam", "name"=>"nam",
											  "valor"=>$_POST["nam"],  "ancho"=>"355"))
									 ),
					  "boton"=>array(array("tipo"=>"submit", "id"=>"bcon", "name"=>"bcon", "ancho"=>"100", "texto"=>"Buscar",
					  					   "clase"=>"boton_buscar", "click"=>"javascript:xBuscarJS()"),
									 array("tipo"=>"button", "id"=>"bexp", "name"=>"bexp", "ancho"=>"100", "texto"=>"Exportar",
									 	   "clase"=>"boton_exportar", "click"=>"javascript:xExportarJS()"),								
									 array("tipo"=>"button", "id"=>"bnew", "name"=>"bnew", "ancho"=>"100", "texto"=>"Nuevo", 
										   "clase"=>"boton_nuevo", "click"=>"javascript:FormuRegistroJS('', 'NEW')"),
									 )
					);
		return $this->setTablaForm($varTabla);
		}
 	function GridDatos($varForm  = NULL, 
					   $varField = NULL, 
					   $varOrder = NULL
					   ) {
		$varCod =  $varForm["cod"];
		$varNom =  $varForm["nam"];
		$varFie = (isset($varField) && $varField<>'')? "'$varField'":"NULL";
		$varOrd = (isset($varOrder) && $varOrder<>'')? "'$varOrder'":"NULL";
		
		$sql = "call spQuery_Sistema_Menu('$varCod','$varNom', $varFie, $varOrd)";
		$varTabla=array("id"=>"theTable", "name"=>"theTable", "tamano"=>"800", "sql_cab"=>$sql, "pages"=>50,
						"conte"=>array(array("titulo"=>"CMEN",	   	 "ancho"=>"40", "clase"=>"sortable-numeric", "tipo"=>"texto"), 
									   array("titulo"=>"ORD",      	"ancho"=>"40", "alinear"=>"center"), 
									   array("titulo"=>"DESCRIPCION","ancho"=>"300", "clase"  =>"sortable", "fijo"=>"SI", "funcion"=>array("contar")),
									   array("titulo"=>"OUT",   	 "ancho"=>"40", "clase"  =>"sortable", "alinear"=>"center"),
									   array("titulo"=>"OVER",  	 "ancho"=>"40", "clase"  =>"sortable", "alinear"=>"center"),
									   array("titulo"=>"LINK",   	 "ancho"=>"40", "clase"  =>"sortable", "alinear"=>"center"),
									   array("titulo"=>"FCREADO",  "ancho"=>"100", "oculto"=>"SI"),
									   array("titulo"=>"FUPDATE",  "ancho"=>"100", "oculto"=>"SI"),
									   array("titulo"=>"UCREADO",  "ancho"=>"100", "oculto"=>"SI"),
									   array("titulo"=>"UUPDATE",  "ancho"=>"100", "oculto"=>"SI")
									   ),
						"boton"=>array(array("tipo"=>"img", "id"=>"bbus", "name"=>"bbus", "img"=>"images/b_table_edit.png", 
											 "toltip"=>array(array("valor"=>"HAGA CLICK PARA <b>EDITAR</b> EL REGISTRO<br><b>"),
																 array("valor"=>0, "tipo"=>"INDEX"),
																 array("valor"=>" - "),
																 array("valor"=>2, "tipo"=>"INDEX"),
																 array("valor"=>"</b>")
																),
											 "click"=>array("funcion"=>"FormuRegistroJS",
															"param"=>array(array("valor"=>0, 	  "tipo"=>"INDEX"),
																		   array("valor"=>"EDIT", "tipo"=>"TEXTO")
																		  )
															)
											 
											),
									   array("tipo"=>"img", "id"=>"badd", "name"=>"badd", "img"=>"images/b_table_delete.png", 
											 "toltip"=>array(array("valor"=>"HAGA CLICK PARA <b>ELIMINAR</b> EL REGISTRO<br><b>"),
																 array("valor"=>0, "tipo"=>"INDEX"),
																 array("valor"=>" - "),
																 array("valor"=>2, "tipo"=>"INDEX"),
																 array("valor"=>"</b>")
																),
											 "click"=>array("funcion"=>"xEliminarJS",
															"param"=>array(array("valor"=>0, "tipo"=>"INDEX"),
																		   array("valor"=>1, "tipo"=>"INDEX"),
																		   array("valor"=>"this", "tipo"=>"NUM"),
																		   )
															)
											 )
									)
						);
		return $this->SetGridTabla2($varTabla);
		}
	function FormuRegistro($varCod=NULL,$varOpt=NULL) {
		if($varOpt=="NEW") {
			$SubTit = $this->varTitulo." - NUEVO";
			$Permite = $_SESSION["_FINS"];
			$varLock = "NO";
			$Fila = NULL;
			$Fila["CDEP"] = "14";
			$Fila["CPRO"] = "1401";
			$Fila["CDIS"] = "140101";
			}
		else {
			$SubTit =  $this->varTitulo." - EDITAR";
			$varLock = "SI";
			
			$sql = "select * from ".$this->varMyTabla." where ".$this->varMyID." = '$varCod'";
			$this->AbrirConexion();
			$rs = $this->Query($sql);
			$this->CerrarConexion();
			$Fila = $this->FetchArray($rs);
			}
		$sqltip = "select id_menu, nombre from _sys_menu where length(id_menu)=2;";
		$sqlfam = "select id_menu, nombre from _sys_menu where length(id_menu)=4 and substring(id_menu,1,2)=substring('".$Fila[0]."',1,2);";
		$varTabla=array("id"=>"tabla", "name"=>"table", "tamano"=>"450", "clase"=>"FormTitulo", "titulo"=>$SubTit,
						"formu"=>array("id"=>"form", "name"=>"form", "metodo"=>"POST", "onsubmit"=>"return false;"),						
						"ocult"=>array(array("tipo"=>"oculto", "id"=>"titu", "name"=>"titu", "valor"=>$this->varTitulo),
									   array("tipo"=>"oculto", "id"=>"opt", "name"=>"opt", "valor"=>$varOpt)
									  ),
						"conte"=>array(array("titulo"=>"Codigo :", "clase1"=>"FormCampo1", "clase2"=>"interior", "tamano"=>"100",
										 "campo" =>array("tipo"=>"texto", "id"=>"cod", "name"=>"cod", "clase"=>"inputDisable",
										 "valor"=>$Fila[$this->varMyID], "alinear"=>"center", "locked"=>"SI", "ancho"=>"70")),								   
								   array("titulo"=>"Nivel 1 :", "clase1"=>"FormCampo1", "clase2"=>"interior",
										 "campo"=>array("tipo"=>"select", "id"=>"niv1", "name"=>"niv1", "valor"=>substr($Fila["id_menu"],0,2),
														"combo"=>array("sql"=>$sqltip, "ancho"=>"300", "titulo"=>"--[[SELECCIONAR]]--",
																	   "locked"=>$varLock, "reload"=>"xajax_comboNivel2(this.value)"))),
								   array("titulo"=>"Nivel 2 :", "clase1"=>"FormCampo1", "clase2"=>"interior", "div"=>"divFam",
										 "campo"=>array("tipo"=>"select", "id"=>"niv2", "name"=>"niv2", "valor"=>substr($Fila["id_menu"],0,4),
														"combo"=>array("sql"=>$sqlfam, "ancho"=>"300",  "titulo"=>"--[[SELECCIONAR]]--", 
																	   "locked"=>$varLock, "sincod"=>"SI"))),
								   array("titulo"=>"Nombre :", "clase1"=>"FormCampo1", "clase2"=>"interior", 
										 "campo" =>array("tipo"=>"texto", "id"=>"nam", "name"=>"nam", "valor"=>$Fila["nombre"], "ancho"=>"300")),
								   array("titulo"=>"Icono Out :", "clase1"=>"FormCampo1", "clase2"=>"interior", 
										 "campo" =>array("tipo"=>"texto", "id"=>"iout", "name"=>"iout", "valor"=>$Fila["img_out"], "ancho"=>"200")),
								   array("titulo"=>"Icono Over :", "clase1"=>"FormCampo1", "clase2"=>"interior", 
										 "campo" =>array("tipo"=>"texto", "id"=>"iover", "name"=>"iover", "valor"=>$Fila["img_over"], "ancho"=>"200")),
								   array("titulo"=>"Link :", "clase1"=>"FormCampo1", "clase2"=>"interior", 
										 "campo" =>array("tipo"=>"texto", "id"=>"lnk", "name"=>"lnk", "valor"=>$Fila["link"], "ancho"=>"150")),
								   array("titulo"=>"Orden :", "clase1"=>"FormCampo1", "clase2"=>"interior", 
										 "campo" =>array("tipo"=>"texto", "id"=>"ord", "name"=>"ord", "valor"=>$Fila["orden"], "ancho"=>"150"))
								   ),
						"boton"=>array(array("tipo"=>"button", "id"=>"bsav", "name"=>"bsav", "ancho"=>"100",
											 "clase"=>"boton_guardar", "texto"=>"Grabar", "click"=>"javascrip:xGrabarJS()"),			  
									   array("tipo"=>"button", "id"=>"breg", "name"=>"breg", "ancho"=>"100",
											 "clase"=>"boton_cancelar", "texto"=>"Cancelar", "click"=>"javascrip:xajax_xRegresar()"),
									)
						);
		return $this->setTablaForm($varTabla);	
//		return $sql."<br>".$varOpt."<br>".$sqltip."<br>".$sqlfam;
		}
		
	function ProcesoGrabar($varForm = NULL) {
		$varUsr = (isset($_SESSION["_CUSE"]))?$_SESSION["_CUSE"]:1;
		$varOpt = ($varForm["opt"]=="")? "NULL" : $varForm[opt];
		$varCod = ($varForm["cod"]=="")? "NULL" : "'$varForm[cod]'";
		$varNam = ($varForm["nam"]=="")? "NULL" : "'$varForm[nam]'";
		$varNv1 = ($varForm["niv1"]=="Ninguno")?"NULL" : "'$varForm[niv1]'";
		$varNv2 = ($varForm["niv2"]=="Ninguno")?"NULL" : "'$varForm[niv2]'";
		$varOut = ($varForm["iout"]=="")? "NULL" : "'$varForm[iout]'";
		$varOve = ($varForm["iover"]=="")?"NULL" : "'$varForm[iover]'";
		$varLnk = ($varForm["lnk"]=="")? "NULL"  : "'$varForm[lnk]'";
		$varOrd = ($varForm["ord"]=="")? "NULL"  : $varForm[ord];
		
		$sql = "call spMante_Sistema_Menu('$varOpt', $varCod, $varNv1, $varNv2, $varNam, $varOut, $varOve, $varLnk, $varOrd, $varUsr);";
		$this->AbrirConexion();
		$this->Query($sql);
		$this->CerrarConexion();
		return "OK";
		}
	function ProcesoEliminar($varCod) {
		$varUsr = (isset($_SESSION["_CUSE"]))?$_SESSION["_CUSE"]:1;
		$sql = "update ".$this->varMyTabla." set _estado = 'X', _date_update=NOW(), _user_update=$varUsr where ".$this->varMyID."= '".$varCod."';";
		$this->AbrirConexion();
		$this->Query($sql);
		$this->CerrarConexion();
		}
	}
	
?>