<?php
 include ("emenux.php"); 
 require ("conecta.php");
 $filtro=$_POST['hdmod'] . $_POST['hdsubmod'];
 $modulo=$_POST['hdmod'];
 $smodulo=$_POST['hdsubmod'];
 $sw=$_POST['hdsw'];
 if ($sw=="grabar"){
  $programa=$_POST['hdprog'];
  $usuario=$_POST['hdusu'];
  $sqlbusca="select * from m06005 where programa='$programa' and usuario='$usuario';";
  $resbusca=mysql_query($sqlbusca,$con);
  if (mysql_num_rows($resbusca)==0){
   $sqlgraba="insert into m06005 
   (programa,usuario)
   values ('$programa','$usuario');";
   $resg=mysql_query($sqlgraba,$con) ;
   }//fin si busca
  $sw="";
  $modulo="";
  $smodulo="";
  $programa="";
  $usuario="";
}//fin grabar
if ($sw=="eliminar"){
 $programa=$_POST['hdprog'];
 $usuario=$_POST['hdusu'];
 $sqlel="delete from m06005 where programa='$programa' and usuario='$usuario';";
 $resel=mysql_query($sqlel,$con);
 $sw="";
 $modulo="";
 $smodulo="";
 $programa="";
 $usuario="";
}
?>
<!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>
<TITLE>Control de permisos</TITLE>
<script language="javascript" src="fstandar.js"></script>
<script language="javascript">
function ponemodulo(){
 document.form1.hdmod.value=document.form1.modulo.value;
// window.alert(document.form1.hdmod.value);
 document.form1.action="M0601010.php";
 document.form1.method="post";
 document.form1.submit();
 }
function ponesubmodulo(){
 document.form1.hdsubmod.value=document.form1.submodulo.value;
// window.alert(document.form1.hdsubmod.value);
 document.form1.action="M0601010.php";
 document.form1.method="post";
 document.form1.submit();
 }
 function poneprograma(){
 document.form1.hdprog.value=document.form1.programa.value;
 //window.alert(document.form1.hdprog.value);
 } 
 function poneusuario(){
 document.form1.hdusu.value=document.form1.usuario.value;
 
 //window.alert(document.form1.hdusu.value);
 } 
function grabar(){
 err=0;
 var uno=new String("");
 //window.alert(document.form1.modulo.options[document.form1.usuario.selectedIndex].text);
 uno=document.form1.modulo.options[document.form1.modulo.selectedIndex].text;
 var dos=new String("");
 dos=document.form1.submodulo.options[document.form1.submodulo.selectedIndex].text;
 var tres=new String("");
 tres=document.form1.programa.options[document.form1.programa.selectedIndex].text;
 var cuatro=new String("");
 cuatro=document.form1.usuario.options[document.form1.usuario.selectedIndex].text;
 errd="";
 if (cuatro.substr(cuatro,5)=="Selec"){
  err=1;
  errd+="\n usuario";
 } 
 if (tres.substr(tres,5)=="Selec"){
  err=1;
  errd+="\n programa";  
 }
 if (dos.substr(dos,5)=="Selec"){
  err=1;
  errd+="\n sub módulo";
 } 
 if (uno.substr(uno,5)=="Selec"){
  err=1;
  errd+="\n módulo";
 }
 if (err==0){//si*
  document.form1.hdsw.value="grabar";
  document.form1.action="M0601010.php";
  document.form1.method="post";
  document.form1.submit();
 }else{
  window.alert("debe seleccionar: " + errd);
 }//fin si*  
}//fin grabar
function eliminar(){
 if (window.confirm("seguro desea eliminar")==true){//si 1
  err=0;
  var uno=new String("");
  uno=document.form1.modulo.options[document.form1.modulo.selectedIndex].text;
  var dos=new String("");
  dos=document.form1.modulo.options[document.form1.submodulo.selectedIndex].text;
  var tres=new String("");
  tres=document.form1.modulo.options[document.form1.programa.selectedIndex].text;
  var cuatro=new String("");
  cuatro=document.form1.modulo.options[document.form1.usuario.selectedIndex].text;
  errd="";
  if (cuatro.substr(cuatro,5)=="Selec"){
   err=1;
   errd+="\n usuario";
  } 
  if (tres.substr(tres,5)=="Selec"){
   err=1;
   errd+="\n programa";  
  }
  if (dos.substr(dos,5)=="Selec"){
   err=1;
   errd+="\n sub módulo";
  } 
  if (uno.substr(uno,5)=="Selec"){
   err=1;
   errd+="\n módulo";
  }
  if (err==0){//si*
   document.form1.hdsw.value="eliminar";
   document.form1.action="M0601010.php";
   document.form1.method="post";
   document.form1.submit();
  }else{
   window.alert("debe seleccionar: " + errd);
  }//fin si*   
 }//fin si 1
}//fin eliminar 
</script>
<link rel="stylesheet" href="styles.css">
<style type="text/css">
<!--
#Layer1 {
	position:absolute;
	left:230px;
	top:100px;
	width:477px;
	height:229px;
	z-index:-1;
	visibility: hidden;
}
-->
</style>
</HEAD>
<BODY>
<TABLE height="100%" cellSpacing=0 cellPadding=0 width="100%" align=center 
border=0>
  <TBODY>
  <TR>
    <TD vAlign=center align=middle height="100%">
      <TABLE height=400 cellSpacing=0 cellPadding=0 width=718 border=0>
        <TBODY>
        <TR>
          <TD width="718" height=22>
            <TABLE height=22 cellSpacing=0 cellPadding=0 width="100%" 
              border=0><TBODY>
              <TR>
                <TD vAlign=top align=left width=24><A 
                  href="index.php"><IMG 
                  height=22 src="images/xc_left.gif" width=24 
                  border=0></A></TD>
                <TD vAlign=top align=left width="100%"><IMG height=22 
                  src="images/xc_center.gif" width="100%" 
                border=0></TD>
              <TD vAlign=top align=right width=24><IMG height=22 
                  src="images/xc_right.gif" width=24 
              border=0></TD></TR></TBODY></TABLE></TD></TR>
        <TR>
          <TD class=BottomTable vAlign=top 
          background=images/xc_stripes.gif height="100%">
            <TABLE class=IconsTable height=33 cellSpacing=0 cellPadding=0 
            width="100%" border=0>
              <TBODY>
              <TR>
                <TD height="32"><div align="right" class="larger">
                  <div align="right">Vemol</div>
                </div></TD>
                </TR></TBODY></TABLE>
            <TABLE cellSpacing=0 cellPadding=0 width="715" 
              border=0>
              <TBODY>
              <TR>
                <TD width=23 height=18>&nbsp;</TD>
                <TD vAlign=top align=left width=180 height=18>&nbsp;</TD>
                <TD width=12 height=18>&nbsp;</TD>
                <TD width="461" height=18 class=MainMenuHead>Permisos:</TD>
                <TD width=20 height=18>&nbsp;</TD></TR>
              <TR>
                <TD width=23 height="100%">&nbsp;</TD>
                <TD vAlign=top align=left width=180 height="100%">
                  <TABLE cellSpacing=0 cellPadding=0 width="150" border=0>
                    <TBODY>
                    <TR>
                      <TD width=10 valign="top"><IMG height=12 
                        src="images/xc_dotgrey.gif" width=10></TD>
                      <TD width=4>&nbsp;</TD>
                      <TD class=LeftMenu noWrap>Control de Permisos:<br />
                        <span class="LeftMenuHeaders">-&gt;Agregar.<br />
                        -&gt;Modificar.<br />
                        -&gt;Eliminar.</span></TD>
                    </TR>
                    <TR>
                      <TD width=10><IMG height=12 
                        src="images/xc_dotgrey.gif" width=10></TD>
                      <TD width=4>&nbsp;</TD>
                      <TD class=LeftMenu noWrap>&nbsp;</TD>
                    </TR>
                    <TR>
                      <TD width=10><IMG height=12 
                        src="images/xc_dotgrey.gif" width=10></TD>
                      <TD>&nbsp;</TD>
                      <TD class=LeftMenu noWrap>&nbsp;</TD>
                    </TR></TBODY></TABLE></TD>
                <TD width=12 height="100%">&nbsp;</TD>
                <TD class=contentcell vAlign=top align=middle width=461 
                height="100%"><table width="100%">
                    <tbody>
                      <tr>
                        <td><form action="" method="post" name="form1" id="form1">
                          <table width="100%" border="0" cellspacing="0" cellpadding="0">
                            <tr>
                              <th scope="col"><div align="right" class="Emphasize">M&oacute;dulo:</div></th>
                                  <th scope="col"><div align="left">
                                    <?php
									$sqlmod="select * from m06001 order by 2;";
									$resmod=mysql_query($sqlmod,$con) ;				
								?>
                                    <select name="modulo" id="modulo" onchange="ponemodulo()" >
                                      <option value="xxx">Seleccione un m&oacute;dulo</option>
                                      <?php 
									while ($filamod=mysql_fetch_row($resmod)){			
									 if ($modulo==$filamod[0]){
									  echo "<option value=$filamod[0] selected='selected'>$filamod[1]</option>";
									  }else{						
									 echo "<option value=$filamod[0]>$filamod[1]</option>";								 
									 }//fin si
									}
								?>
                                      </select>
                                    <input name="hdmod" type="hidden" id="hdmod" value="<?php echo $modulo ?>" />
                                    </div></th>
                                </tr>
                            <tr>
                              <th scope="row"><div align="right" class="Emphasize">Submodulo:</div></th>
                                  <td><?php
									$sqlsmod="select * from m06003 order by 2;";
									$ressmod=mysql_query($sqlsmod,$con) ;				
								?>
                                    <select name="submodulo" id="submodulo" onchange="ponesubmodulo()">
                                      <option value="xxx">Seleccione un programa</option>
                                      <?php 
									while ($filasmod=mysql_fetch_row($ressmod)){
									if ($smodulo==$filasmod[0]){
									 echo "<option value=$filasmod[0] selected='selected'>$filasmod[1]</option>";
									 }else{									
									 echo "<option value=$filasmod[0]>$filasmod[1]</option>";									
									 }//fin si
									}// fin while
								?>
                                      </select>
                                    <input name="hdsubmod" type="hidden" id="hdsubmod" value="<?php echo $smodulo ?>"/></td>
                                </tr>
                            <tr>
                              <th scope="row"><div align="right" class="Emphasize">Programa:</div></th>
                                  <td><?php
							   if (strlen($filtro)>0){
									$sqlpr="select * from m06004 where codigo like '$filtro%' order by 2;";
									}//fin si
									$respr=mysql_query($sqlpr,$con) ;				
								?>
                                    <select name="programa" id="programa" onchange="poneprograma()">
                                      <option value="xxx">Seleccione un programa</option>
                                      <?php 
									while ($filapr=mysql_fetch_row($respr)){									
									 echo "<option value=$filapr[0]>$filapr[1]</option>";									
									}
								?>
                                      </select>
                                    <input name="hdprog" type="hidden" id="hdprog"/></td>
                                </tr>
                            <tr>
                              <th scope="row"><div align="right" class="Emphasize">Usuario:</div></th>
                                  <td><div align="left">
                                    <?php
									$sqlus="select * from m06006 order by 2;";
									$resus=mysql_query($sqlus,$con) ;				
								?>
                                    <select name="usuario" id="usuario" onchange="poneusuario()">
                                      <option value="xxx">Seleccione un usuario</option>
                                      <?php 
									while ($filaus=mysql_fetch_row($resus)){									
									 echo "<option value=$filaus[0]>$filaus[0]</option>";									
									}
								?>
                                      </select>
                                    <input name="hdusu" type="hidden" id="hdusu"/>
                                    </div></td>
                                </tr>
                            <tr>
                              <th scope="row"><label> </label></th>
                                  <td>&nbsp;</td>
                                </tr>
                            <tr>
                              <th scope="row"><label> </label></th>
                                  <td><input name="hdsw" type="hidden" id="hdsw" value="ingreso" /></td>
                                </tr>
                            <tr>
                              <th scope="row"><label> </label></th>
                                  <td>&nbsp;</td>
                                </tr>
                            <tr>
                              <th scope="row"><label> </label></th>
                                  <td>&nbsp;</td>
                                </tr>
                            <tr>
                              <th scope="row"><div align="right"></div></th>
                                  <td>&nbsp;</td>
                                </tr>
                            <tr>
                              <th scope="row">&nbsp;</th>
                                  <td>&nbsp;</td>
                                </tr>
                            <tr>
                              <th scope="row">&nbsp;</th>
                                  <td>&nbsp;</td>
                                </tr>
                            <tr>
                              <th colspan="2" scope="row"><input name="cmdgra" type="button" id="cmdgra" value="Grabar" onclick="grabar()" />
                                <label></label>
                                &nbsp;&nbsp;
                                <label></label>
                                <label></label>
                                <label></label>
                                &nbsp;&nbsp;
                                <input name="cmdel" type="button" id="cmdel" value="Eliminar" onclick="eliminar()"/>                                </th>
                                </tr>
                            </table>
                          </form></td>
                        </tr>
                      </tbody>
                  </table></TD><TD width=20 height="100%">&nbsp;</TD></TR>
              <TR>
                <TD width=23 height=8>&nbsp;</TD>
                <TD width=180 height=8>&nbsp;</TD>
                <TD width=12 height=8>&nbsp;</TD>
                <TD width="461" height=8>&nbsp;</TD>
        <TD width=20 
      height=8>&nbsp;</TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE></TD></TR></TBODY>
<!-- /Footer -->
<script language="JavaScript" src="menu.js"></script>
<script language="JavaScript" src="menu_tpl.js"></script>
<script language="JavaScript">
	new menu (MENU_ITEMS, MENU_POS);
</script>
</TABLE>
</BODY>
<?php
	mysql_close($con);
?>
</HTML>