<?php 
    include("../../DMMYSQLG.php");   
?>
<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title>Permiso Grupo</title>
        
        <link href="../../css/crud/easyui.css" rel="stylesheet" type="text/css"/>
        <link href="../../css/crud/icon.css" rel="stylesheet" type="text/css"/>
        <link href="../../css/crud/color.css" rel="stylesheet" type="text/css"/>
        <link href="../../css/crud/general.css" rel="stylesheet" type="text/css"/>
        
        <script src="../../js/jquery.min.js" type="text/javascript"></script>
        <script src="../../js/jquery.easyui.min.js" type="text/javascript"></script>
         
    </head>
    <body>
        <p align="center"><img src="../../css/crud/icons/users.png" width="20px" height="20px"/> </p>
        <h2 style="text-align:center">Permiso Grupo</h2>
                
        <table id="dg" title="Permiso Grupo" class="easyui-datagrid" style="width:100%;height:380px"
               url="get_pgrupo.php"
               toolbar="#toolbar" pagination="true"
               rownumbers="true" fitColumns="true" singleSelect="true">
            <thead>
                <tr>
                    <th field="grupo_id" width="25">Grupo_Id</th>
                    <th field="modulo_url" width="50">URL</th>
                </tr>
            </thead>
        </table>
        <div id="toolbar">
            <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="newPGrupo()">Nuevo Permiso de Grupo</a>
            <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-edit" plain="true" onclick="editPGrupo()">Editar Permiso de Grupo</a>
            <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="destroyPGrupo()">Eliminar Permiso de Grupo</a>
        </div>

        <div id="dlg" class="easyui-dialog" style="width:420px;height:260px;padding:10px 20px"
             closed="true" buttons="#dlg-buttons">
            <div class="ftitle">Informacion de Permiso Grupo</div>
            <form id="fm" method="post" novalidate>
                <div class="fitem">
                    <label>Permiso Grupo:</label>
                    <select name="grupo_id" required="true">
                        <?php
                        $sql =  "SELECT * FROM cgrupo";
                        $result = mysqli_query($con ,$sql); 
//                        echo "<option selected="."selected".">";
//                        echo "Elige un grupo";
//                        echo "</option>";
                        while($row=  mysqli_fetch_array($result)){
                            echo "<option value=".$row['id'].">";
                            echo $row['nombre'];
                            echo "</option>";
                        } 
                        ?>  
                    </select>
                </div>
                <div class="fitem">
                    <label style="width:100px">URL:</label>
                    <select name="modulo_url" style="width:200px" required="true">
                        <?php
                        $sql1 =  "SELECT * FROM cmodulo order by servicio,order_parent,order_child";  
                        $result1 = mysqli_query($con ,$sql1); 
                        while($row=  mysqli_fetch_array($result1)){
                            echo "<option value=".$row['url'].">";
                            echo $row['nombre']." -> ".$row['modulo_parent']." -> ".$row['servicio'];
                            echo "</option>";
                        } 
                        ?>  
                    </select>
                </div>
            </form>
        </div>
        <div id="dlg-buttons">
            <a href="javascript:void(0)" class="easyui-linkbutton c6" iconCls="icon-ok" onclick="savePGrupo()" style="width:90px">Guardar</a>
            <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#dlg').dialog('close')" style="width:90px">Cancelar</a>
        </div>
        <script type="text/javascript">
            var url;
            function newPGrupo() {
                $('#dlg').dialog('open').dialog('setTitle', 'Nuevo Permiso de Grupo');
                $('#fm').form('clear');
                url = 'save_pgrupo.php';
            }
            function editPGrupo() {
                var row = $('#dg').datagrid('getSelected');
                if (row) {
                    $('#dlg').dialog('open').dialog('setTitle', 'Editar Permiso de Grupo');
                    $('#fm').form('load', row);
                    url = 'update_pgrupo.php?id=' + row.grupo_id + '&url=' + row.modulo_url;
                }
            }
            function savePGrupo() {
                $('#fm').form('submit', {
                    url: url,
                    onSubmit: function () {
                        return $(this).form('validate');
                    },
                    success: function (result) {
                        var result = eval('(' + result + ')');
                        if (result.errorMsg) {
                            $.messager.show({
                                title: 'Error',
                                msg: result.errorMsg
                            });
                        } else {
                            $('#dlg').dialog('close');		// close the dialog
                            $('#dg').datagrid('reload');	// reload the user data
                        }
                    }
                });
            }
            function destroyPGrupo() {
                var row = $('#dg').datagrid('getSelected');
                if (row) {
                    $.messager.confirm('Confirmar', 'Estas seguro que quieres eliminar este permiso de grupo?', function (r) {
                        if (r) {
                            $.post('destroy_pgrupo.php', {grupo_id: row.grupo_id, url: row.modulo_url}, function (result) {
                                if (result.success) {
                                    $('#dg').datagrid('reload');	// reload the user data
                                } else {
                                    $.messager.show({// show error message
                                        title: 'Error',
                                        msg: result.errorMsg
                                    });
                                }
                            }, 'json');
                        }
                    });
                }
            }
        </script>
        <style type="text/css">
            #fm{
                margin:0;
                padding:10px 30px;
            }
            .ftitle{
                font-size:14px;
                font-weight:bold;
                padding:5px 0;
                margin-bottom:10px;
                border-bottom:1px solid #ccc;
            }
            .fitem{
                margin-bottom:25px;
            }
            .fitem label{
                display:inline-block;
                width:150px;
            }
            .fitem input{
                width:160px;
            }

            .fitem1{
                margin-bottom:5px;
                margin-top:10px;
            }
            .fitem1 label{
                display:inline-block;
                width:80px;
            }
            .fitem1 input{
                width:30px;
                margin-left: 50px;
            }

        </style>
        <div align="center">
            <a href="../../grupos_CRUD/index.php" style="text-decoration:none">
                <img width="50" heigh="50" src="../../css/crud/icons/back.png">
           </a>    
       </div>
    </body>
</html>
