<?php
	session_start();
	include("cls_conexion.php");$CNN=new ClsMySQL();include("conexion23.php");
	if(strlen($_SESSION['SYS_USER_ID'])==0){JsDir("login.php");	return;}
	/*/++++++++++++++++++++++++++++++++++++++/*
	if(strlen($_SESSION['SYS_USER_ID'])==0){
		JsDir("login.php");
		return;
	}
	*///++++++++++++++++++++++++++++++++++++++
	$IdUsuario=V($_GET['IdUser']);
	if(strlen($IdUsuario)==0){
			$IdUsuario=V($_POST['TxtId']);
	}
	if(strlen($IdUsuario)==0) $IdUsuario=0;
	$StrUser_NA=gs("nom","usuarios","id_usuario=$IdUsuario");
	$StrUser_FN=gs("nomape","usuarios","id_usuario=$IdUsuario");
	$StrUser_NA=$StrUser_NA." ( ".$StrUser_FN." ) ";
	$StrCmd=V($_POST['CmdG']);
	if($StrCmd=="Guardar configuracion"){
		ejt("DELETE FROM usuarios_menus WHERE id_usuario=$IdUsuario");
		$s="SELECT id,sm FROM menus ORDER BY id";
		$result = grs($s);		
		while ($row = $result->fetch_row()){
			$id=$row[0];
			$sm=$row[1];
			$Ok=V($_POST["CH_M_".$id]);
			if(strlen($Ok)==0) $Ok="0";
			$s="INSERT INTO usuarios_menus VALUES ($IdUsuario,$id,$Ok)";
			ejt($s);
			$LStrMsg="onload=\"alert('La configuracion ha sido guardada correctamente');\"";	
		}
	}
	
	
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/>
<title>Asignacion de Menus</title>
<script type="text/javascript" src="ja/funciones.js"></script>
<style type="text/css">   
a:link   
{   
 text-decoration:none;
 color:#FFF
}   
a:visited {
color:#FFF
}
a:hover {
color:#FDF000
}

</style>
<style type="text/css">
<!--
body {
	background-color: #CCC;
	background-image: url();
}
#Layer1 {
	position:absolute;
	left:345px;
	top:115px;
	width:123px;
	height:35px;
	z-index:1;
}
.centrarFrm{
	width:900px;
	height:700px;
	position:absolute;
	left:50%;
	top:50%;
	background-color:#346D98;
	margin:-350px 0 0 -450px;
}


.AB{
	position:absolute;
	z-index: 2;
	text-align: left;
	font-family: Arial, Helvetica, sans-serif;
	font-size: 12px;
	font-weight: bold;
	height: 18px;
	width:154px;
}
.TI{
	position:absolute;
	z-index: 2;
	text-align: left; 
	font-family: Arial, Helvetica, sans-serif; 
	font-size: 14px;
	font-weight: bold;
	color:#FF0;
	width:154px;
}
#Frm center #DivFRM #layer .Estilo1 strong {
	color: #900;
}
.Estilo2 {font-family: Arial, Helvetica, sans-serif; font-weight: bold; color: #FFFFFF; font-size: 12px; }
.AB1 {	position:absolute;
	z-index: 2;
	text-align: left;
	font-family: Arial, Helvetica, sans-serif;
	font-size: 12px;
	font-weight: bold;
	height: 18px;
	color:#FF0
}
-->
</style>

</head>
<body  <?php echo $LStrMsg;?>>
<form id="Frm" name="Frm" method="post" action="sys_menu_set.php">
<center> 
<div Id="DivFRM"  class="centrarFrm" >
<div id="layer5" style="left: 2px; top: 94px; width: 900px">
<div style=" position:absolute; left: 0px; top: 0px; width: 900px; height: 79px; background-color: #FFFFFF; layer-background-color: #FFFFFF; border: 1px none #000000; z-index: 0">
  <input type="hidden" name="TxtId" id="TxtId" value="<?php echo $IdUsuario;?>"/>  
</div>
<div style="left: 19px; top: 3px; width: 57px" class="AB"> <img src="img/almacen.jpg" width="71" height="72"/> </div>
<?php
	$BX=23;
	$BY=140;
	$BZ=184;
	$BS=22;
	$U_CO="";	
	$U_TO=$BX;
	$U_NL=0;
	$cols=gn("max(col)","menu","");
	$c=0;
	for($c=1;$c<=$cols;$c++){
		$l_m=$BX + (($c-1)*$BZ);		
		$t_m=$BY;
		$m_it=0;
		$s_m="SELECT nombre,ord,nl,id_menu FROM menu WHERE col=$c ORDER BY ord";
		$result_m = grs($s_m);		
		while ($row_m = $result_m->fetch_row()){			
			echo "<div ";
			echo "style=\"left:".($l_m+10)."px;top:".$t_m."px;\" class=\"TI\">" ;
			echo $row_m[0];
			echo "</div>";
			//
			$t_m=$t_m + (25* $row_m[2]);			
			//
			$id_menu=$row_m[3];
			$s="SELECT sm,url,nl,id FROM menus WHERE id_menu=$id_menu ORDER BY orden";
			$result = grs($s);		
			while ($row = $result->fetch_row()){
				$id=$row[3];
				$sm=$row[0];
				$ur=$row[1];
				$nl=$row[2];
				//
				echo "<div ";
				echo "style=\"left:".$l_m."px;top:".($t_m-3)."px\" class=\"AB\">";
				echo "<input type=\"checkbox\" ";
				echo "name=\"CH_M_".$id."\"  id=\"CH_M_".$id."\" value=\"1\"  ";
				$Ok=gn("valor","usuarios_menus","id_usuario=$IdUsuario AND id_sm=$id");
				if($Ok==1){
					echo "checked=\"checked\"";			
				}
				echo "/>";
				echo "</div>";
				echo "<div ";
				echo "style=\"left:".($l_m+20)."px;top:".$t_m."px\" class=\"AB\">";
				echo "<a href=\"javascript:void(0);\">$sm</a>";
				echo "</div>";
				//
				$t_m=$t_m + (18 * $nl);	
				
			}			
			//
			$t_m=$t_m + (30* $row_m[2]);			
		}
	}

?>
</div>
<div style="left: 30px; top: 88px; width: 182px" class="AB1">ASIGNANDO MENUS PARA :</div>
<div style="left: 229px; top: 88px; width: 335px; color: #FFF;" class="AB1">
<?php
	echo $StrUser_NA;
?>
</div>
<div id="layer39" style="position:absolute; left: 594px; top: 84px; width: 290px; height: 25px;">
<div align="left" class="Estilo2">
<input type="submit" name="CmdG" id="CmdG" value="Guardar configuracion" />
<input name="CmdB" type="button" id="CmdZ" 
value="Volver" 
onclick="fBuscar('usuarios.php?Id=<?php echo $IdUsuario;?>');"  
tabindex="22"/>
  </div>
</div>
</div>
</center>	
</form>
</body>
</html>
