<?php
//include "clase.conexion.php";
class clsRoles extends clsConexion{
	public $varTitulo = "ROLES DEL SISTEMA";
	public $varMyTabla  = "_sys_rol";
	public $varMyID  	  = "id_rol";
	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 = (isset($varForm["cod"]) && $varForm["cod"]<>'')? $varForm["cod"]:"NULL";
		$varNom = $varForm["nam"];
		$varUsr = (isset($_SESSION["_CUSE"]))?$_SESSION["_CUSE"]:1;
		$varFie = (isset($varField) && $varField<>'')? "'$varField'":"NULL";
		$varOrd = (isset($varOrder) && $varOrder<>'')? "'$varOrder'":"NULL";
		
		$sql = "call spQuery_Sistema_Roles($_SESSION[_CSYS], $varCod,'$varNom', $varUsr, $varFie, $varOrd)";
		$varTabla=array("id"=>"theTable", "name"=>"theTable", "tamano"=>"800", "sql_cab"=>$sql, "pages"=>50,
						"conte"=>array(array("titulo"=>"CSIS",	   	 "ancho"=>"40", "oculto"=>"SI"), 
									   array("titulo"=>"CROL",	   	 "ancho"=>"40", "alinear"=>"center"), 									   
									   array("titulo"=>"DESCRIPCION","ancho"=>"300", "fijo"=>"SI", "funcion"=>array("contar")),
									   array("titulo"=>"CANT.",    "ancho"=>"40", "alinear"=>"center"), 
									   array("titulo"=>"FCREADO",  "ancho"=>"100", "fijo"=>"SI"),
									   array("titulo"=>"FUPDATE",  "ancho"=>"100", "fijo"=>"SI"),
									   array("titulo"=>"UCREADO",  "ancho"=>"100", "fijo"=>"SI", "alinear"=>"center"),
									   array("titulo"=>"UUPDATE",  "ancho"=>"100", "fijo"=>"SI", "alinear"=>"center")
									   ),
						"boton"=>array(array("tipo"=>"img", "id"=>"bbus", "name"=>"bbus", "img"=>"../images/16x16/table_edit.png", 
											 "toltip"=>array(array("valor"=>"HAGA CLICK PARA <b>EDITAR</b> EL REGISTRO<br><b>"),
																 array("valor"=>1, "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/16x16/table_delete.png", 
											 "toltip"=>array(array("valor"=>"HAGA CLICK PARA <b>ELIMINAR</b> EL REGISTRO<br><b>"),
																 array("valor"=>1, "tipo"=>"INDEX"),
																 array("valor"=>" - "),
																 array("valor"=>2, "tipo"=>"INDEX"),
																 array("valor"=>"</b>")
																),
											 "click"=>array("funcion"=>"xEliminarJS",
															"param"=>array(array("valor"=>1, "tipo"=>"INDEX"),
																		   array("valor"=>2, "tipo"=>"INDEX"),
																		   array("valor"=>"this", "tipo"=>"NUM"),
																		   )
															)
											 ),
									   array("tipo"=>"img", "id"=>"bbus", "name"=>"bbus", "img"=>"../images/16X16/user_go.png", 
											 "toltip"=>array(array("valor"=>"HAGA CLICK PARA <b>ASIGNAR PERMISOS</b> AL ROL<br><b>"),
																 array("valor"=>1, "tipo"=>"INDEX"),
																 array("valor"=>" - "),
																 array("valor"=>2, "tipo"=>"INDEX"),
																 array("valor"=>"</b>")
																),
											 "click"=>array("funcion"=>"FormuPermisoJS",
															"param"=>array(array("valor"=>1, 	  "tipo"=>"INDEX"))
															)
											 
											),
									)
						);
		return $this->SetGridTabla2($varTabla);
		}
	
	function FormuRegistro($varCod=NULL,$varOpt=NULL) {
		if($varOpt=="NEW") {
			$SubTit = $this->varTitulo." - NUEVO";
			$Permite = $_SESSION["_FINS"];
			$varLock = "NO";
			$Fila = NULL;			
			}
		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);
			}
		$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"=>"Nombre :", "clase1"=>"FormCampo1", "clase2"=>"interior", 
										 "campo" =>array("tipo"=>"texto", "id"=>"nam", "name"=>"nam", "valor"=>$Fila["nombre"], "ancho"=>"300"))
								   ),
						"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);	
		}
		
	function FormuPermiso($varCod=NULL) {
		$sql = "select * from ".$this->varMyTabla." where ".$this->varMyID." = '$varCod' and id_sistema = $_SESSION[_CSYS];";
		$this->AbrirConexion();
		$rs = $this->Query($sql);
		$this->CerrarConexion();
		$Fila = $this->FetchArray($rs);

		$varTabla=array("id"=>"tabla", "name"=>"table", "tamano"=>"450", "clase"=>"FormTitulo", "titulo"=>$this->varTitulo." - ASIGNACION DE PERMISOS",					
						"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"=>"Nombre :", "clase1"=>"FormCampo1", "clase2"=>"interior", 
										 "campo" =>array("tipo"=>"texto", "id"=>"nam", "name"=>"nam", "valor"=>$Fila["nombre"], "ancho"=>"300",
										 				 "clase"=>"inputDisable", "locked"=>"SI"))
								   ),
						"boton"=>array(array("tipo"=>"button", "id"=>"bsav", "name"=>"bsav", "ancho"=>"100",
											 "clase"=>"boton_guardar", "texto"=>"Grabar", "click"=>"javascrip:xGrabarAccesoJS()"),			  
									   array("tipo"=>"button", "id"=>"breg", "name"=>"breg", "ancho"=>"100",
											 "clase"=>"boton_cancelar", "texto"=>"Cancelar", "click"=>"javascrip:xajax_xRegresar()"),
									)
						);
		$varReturn = "<form id=\"form\" onsubmit=\"return false;\" method=\"POST\" name=\"form\">";
		$varReturn.= $this->setTablaForm($varTabla);
		
		$sql = "call spQuery_Sistema_Rol_Menu($_SESSION[_CSYS], $varCod, $_SESSION[_CUSE])";
		$varReturn.= "<br>";
		$varReturn.= "<table style=\"padding:0;margin-top:0px;border-collapse:collapse;\" ";
		$varReturn.= "width=600 align=center cellpadding=0 cellspacing=0>";
		$varReturn.= "<tr>";
		$varReturn.= "<td width=50  align=\"center\" class=\"FormTitulo\" height=22>CMENU</td>";
		$varReturn.= "<td width=300 align=\"center\" class=\"FormTitulo\">NOMBRE DEL MENU</td>";
		$varReturn.= "<td width=20  align=\"center\" class=\"FormTitulo\">OUT</td>";
		$varReturn.= "<td width=50  align=\"center\" class=\"FormTitulo\">OVER</td>";
		$varReturn.= "<td width=50  align=\"center\" class=\"FormTitulo\">PERMITE</td>";
		$varReturn.= "</tr>";
	
		$this->AbrirConexion();
		$rs = $this->Query($sql);
		$this->CerrarConexion();
		$j=0;
		$color1 = "#F5FAFA";
		$color2 = "#edf3f3";
		$colors = "#FFFF33";		
		$bgcolor1 = "bgcolor=$color1 onMouseOver=\"uno(this,'$colors')\"";
		$bgcolor1.= "onMouseOut=\"dos(this,'$color1')\"";		
		$bgcolor2 = "bgcolor=$color2 onMouseOver=\"uno(this,'$colors')\"";
		$bgcolor2.= "onMouseOut=\"dos(this,'$color2')\"";		
		while($fila = $this->FetchArray($rs)) {
			$j++;	
			if($j%2==0) $varReturn.= "<tr $bgcolor1>";
			else $varReturn.= "<tr $bgcolor2>";
			$varReturn.= "<td class=\"interior\" height=20><b>$fila[0]</b></td>";
			$varReturn.= "<td class=\"interior\">$fila[1]</td>";
			$varReturn.= "<td align=\"center\" class=\"interior\">$fila[2]</td>";
			$varReturn.= "<td align=\"center\" class=\"interior\">$fila[3]</td>";
			$varReturn.= "<td align=\"center\" class=\"interior\">";
			$Check = ($fila[4]=="S")? "checked=\"checked\"" : "";
			$varReturn.= "<input name=\"per[".$fila[0]."]\" id=\"per\" type=\"checkbox\" value=\"".$fila[0]."\" style=\"width:12px; height:12px\" $Check >";
			$varReturn.= "</td>";
			$varReturn.= "</tr>";
			}
		$varReturn.= "</table>";
		$varReturn.="</form>";
		return $varReturn;
		}
		
	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]'";
		
		$sql = "call spMante_Sistema_Rol('$varOpt', $_SESSION[_CSYS], $varCod, $varNam, $varUsr);";
		$this->AbrirConexion();
		$rs = $this->Query($sql);
		$this->CerrarConexion();
		$Fila = $this->FetchArray($rs);
		return $Fila[0];
		}
	
	function ProcesoGrabarAcceso($varForm = NULL) {
		$varUsr = (isset($_SESSION["_CUSE"]))?$_SESSION["_CUSE"]:1;
		$varSis = $_SESSION[_CSYS];
		$varRol = $varForm["cod"];
		$sql = "delete from _sys_rol_menu where id_rol = $varRol and id_sistema = $varSis;";
		foreach ($varForm['per'] as $Codigo) {
			if($varForm[per][$Codigo]) {
				$Menu = $varForm[per][$Codigo];
				$sql.= "call spMante_Sistema_Rol_Menu($varSis, $varRol, '$Menu',$varUsr);";
				}
			}			
		$this->AbrirConexion();
		$this->Query($sql);
		$this->CerrarConexion();
		}	
		
	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();
		}
	}
	
?>