<?php
define( 'SF_ROOT_DIR', "../../" );
define( 'SF_APP',      'sys' );

require_once( SF_ROOT_DIR.DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR.'configGlobal.php' );

$o_DBConnect = Conexion::getConexion();
$o_Link = $o_DBConnect->getResource();

if( isset( $_POST['Control'] ) )
{
    if( $_POST['tipo'] == "cambiar_estado" )
    {
        $s_Sql = "UPDATE SEG_Menu SET Estado='".$_POST['valor']."' WHERE IdMenu='".$_POST['id_menu']."' AND IdTareaHijo='".$_POST['id_tarea_hijo']."';";
        mysql_query( $s_Sql, $o_Link );
    }
    if( $_POST['tipo'] == "cambiar_secuencia" )
    {
        $s_Sql = "UPDATE SEG_Menu SET Secuencia='".$_POST['valor']."' WHERE IdMenu='".$_POST['id_menu']."' AND IdTareaHijo='".$_POST['id_tarea_hijo']."';";
        mysql_query( $s_Sql, $o_Link );
    }
}

?>
<?php $dir_url = Constantes::ROOT_DIR_APP ?>

<body style="margin: 20px;">
<link rel="stylesheet" type="text/css" media="screen" href="<?php echo $dir_url ?>/web/css/jquery/default/main.css" />
<link rel="stylesheet" type="text/css" media="screen" href="<?php echo $dir_url ?>/web/css/jquery/default/grid.css" />
<link rel="stylesheet" type="text/css" media="screen" href="<?php echo $dir_url ?>/web/css/jquery/default/tab.css" />
          
<script type="text/javascript" src="<?php echo $dir_url ?>/web/js/jquery/jquery-1.10.2.js"></script>
<script type="text/javascript" src="<?php echo $dir_url ?>/web/js/jquery/ui-1.10.3/jquery-ui.js"></script>

<style>
.grid
{
    border: 1px solid #77d5f7;
    border-top-left-radius: 5px;
    border-top-right-radius: 5px;
    border-bottom-right-radius: 5px;
    border-bottom-left-radius: 5px;
}
.grid th 
{
    border-color: #77d5f7;
    background-color: #0a7db1;
    font-weight: normal;
    font-size: 11px;
    font-family: Verdana,Arial,sans-serif;
    height: 24px;
    padding: 0 2px;
}
.grid td 
{
    border-left: 0 none;
    border-right-color: #77d5f7;
    border-right-style: solid;
    border-right-width: 1px;
    border-bottom-color: #77d5f7;
    border-bottom-style: solid;
    border-bottom-width: 1px;
    padding: 0 2px;
    /*white-space: pre;*/
    height: 22px;
    /*border: 1px solid #77d5f7;*/
}
.grid td div
{
    overflow: hidden; white-space: nowrap; width: 150px; font-size: 10px;
}
</style>

<div class="titleBody descripProy">
    <ul>
        <li style="width:100% !important;">
            Listado Menu
        </li>
    </ul>
</div>

<script type="text/javascript">
pr = function( str )
{
    console.log( str );
}
ejecutarCambio = function( tipo, id_menu, id_tarea_hijo, valor )
{
    $( "#tipo" ).val( tipo );
    $( "#id_menu" ).val( id_menu );
    $( "#id_tarea_hijo" ).val( id_tarea_hijo );
    $( "#valor" ).val( valor );
    $( "#form1" ).submit();
}
capturarKeypress = function( e, id_menu, id_tarea_hijo )
{
    if( e.keyCode == 13 )
    {
        ejecutarCambio( 'cambiar_secuencia', id_menu, id_tarea_hijo, e.target.value );
    }
}
</script>

<form id="form1" name="form1" method="POST" enctype="multipart/form-data">
    <input type="hidden" name="Control" value="ok"/>
    <input type="hidden" name="tipo" id="tipo" value=""/>
    <input type="hidden" name="id_menu" id="id_menu" value=""/>
    <input type="hidden" name="id_tarea_hijo" id="id_tarea_hijo" value=""/>
    <input type="hidden" name="valor" id="valor" value=""/>

    <?php 
    $s_Sql = "
    SELECT
      S.IdSubSistema, SubSistemaDescripcion, SubSistemaDir, TareaPrefijo,
      ( SELECT IdTarea from SEG_Tarea T WHERE T.IdSubSistema=S.IdSubSistema AND TareaTipo='menu' AND ScriptId='menu.php' ) IdTarea,
      coalesce( ( SELECT Secuencia FROM SEG_Menu where IdMenu='mnu.main' and IdTareaHijo=( SELECT IdTarea from SEG_Tarea T WHERE T.IdSubSistema=S.IdSubSistema AND TareaTipo='menu' AND ScriptId='menu.php' ) ), '999' ) Secuencia
    FROM SEG_SubSistema S
    WHERE S.IdSubSistema NOT IN ('smnu')
    ORDER BY Secuencia;
    ";
    $o_Rs = mysql_query( $s_Sql, $o_Link );
    ?>
    <?php while( $a_Row = mysql_fetch_array( $o_Rs ) ){ ?>
    <table class="" style="background:#E3E9E2" width="100%" border="0" cellpadding="0" cellspacing="0">
        <tr>
            <td class="marco" width="50%"><div style="font-size: 15px;"><?=$a_Row['SubSistemaDescripcion']?></div></td>
            <td class="marco" width="50%"><div style="font-size: 15px;"><?=$a_Row['IdSubSistema']?></div></td>
        </tr>
    </table>
        <?php
        //IdTarea, TareaDescripcion, BotonTexto, TareaTipo, ScriptId, DeshabilitadoFlg, IdPatron, IdSubSistema, InicialPassthru, SeleccionFixed, SeleccionTemp, Settings, OrdenarPor, MantenerDatos, LogSqlQuery, ScreenRefresh, UsaHttps
        $s_Sql = "SELECT * FROM SEG_Tarea where IdSubSistema='{$a_Row['IdSubSistema']}' order by TareaTipo, ScriptId DESC;";
        $o_Rs2 = mysql_query( $s_Sql, $o_Link );
        ?>
        
        <table class="" style="" width="100%" border="0" cellpadding="0" cellspacing="0">
            <?php while( $a_Row2 = mysql_fetch_array( $o_Rs2 ) ){ ?>
            <tr>
                <td width="5%">&nbsp;</td>
                <td width="10%" class="marco" style="font-size: 15px;"><?=$a_Row2['IdTarea']?></td>
                <td width="10%" class="marco" style="font-size: 15px;"><?=$a_Row2['TareaDescripcion']?></td>
                <td width="10%" align="center" class="marco" style="font-size: 15px;"><?=$a_Row2['BotonTexto']?></td>
                <td width="10%" align="center" class="marco" style="font-size: 15px;"><?=$a_Row2['TareaTipo']?></td>
            </tr>
            <?php } ?>
        </table>
    <br>
    <?php } ?>

</form>