<?php
session_start();
$com = "A";
include("DMMYSQLG.php");
include("DSA3000.php");
include("JQUERY.inc");
?>
<html>
    <link rel="stylesheet" href="css/estilo1.css" type="text/css"/>
    <script type="text/javascript" language="JavaScript1.2" src="DSSCRIPT.js"></script>
    <style type="text/css">
        <!--
        .Estilo2 {
            font-family: Arial, Helvetica, sans-serif;
            font-weight: bold;
            font-size: 12px;
            color: #FFFFFF;
        }
        .Estilo4 {
            color: #000000;
            font-size: 14px;
        }
        -->
    </style>
    <body>
        <br>



        <div align="center">
            <select name="usuarios" id="users">
                <?php
                $query = "SELECT oper,nomb,apa,ama FROM dxopemaex";
                $rec = mysqli_query($con ,$query);

                while ($row = mysqli_fetch_array($rec)) {
                    echo "<option value='" . $row['oper'] . "'>";
                    echo $row['nomb'] . " " . $row["apa"] . " " . $row['ama'];
                    echo "</option>";
                }
                ?>
            </select>
        </div>
        <div id="formu1" style="display: none"> 
        <form name="frm1" method="post" action="">

            <table  align="center">

                <tr>
                    <th colspan="6" class=\"titulo\">


                    </th>
                </tr>
                <br><br>
                
                    <tr >
                        <th colspan="6" class=\"titulo\">
                            <div align="center" >AGREGAR VENDEDOR(A) / CAJERO(A)</div></th>
                    </tr>

                    <tr>
                        <td colspan="2" nowrap>Numero de Vendedor(a)/Cajero(a):</td>
                        <td colspan="2" nowrap><input name="t0" type="text" id="t0" tabindex="1"  <?php
                            if (isset($_REQUEST['t0'])) {
                                echo 'value="' . $_REQUEST['t0'] . '"';
                            }
                            ?>></td>
                        <td nowrap>Contrase&ntilde;a:</td>
                        <td nowrap><input name="t10" type="password" id="10" tabindex="2" onKeyPress="return validar(event)" onChange="javascript:document.frm1.submit();" <?php
                            if (isset($_POST['t10'])) {
                                $query = mysqli_query($con ,"select codigo from ctmeser");
                                while ($regc = mysqli_fetch_array($query)) {
                                    if ($_POST['t10'] == $regc['codigo'])
                                        $usua = 1;
                                }
                                $query2 = mysqli_query($con ,"select pasw from dgcatven");
                                while ($regc2 = mysqli_fetch_array($query2)) {
                                    if ($_POST['t10'] == $regc2['pasw'])
                                        $usua = 1;
                                }

                                if (isset($usua) && $usua == 1) {
                                    echo
                                    "<script type='text/javascript'>
				'¡¡¡¡¡¡LA CONTRASEÑA YA ES USADA POR OTRO USUARIO!!!!!'
				</script ";
                                } else {
                                    echo 'value="' . $_POST['t10'] . '"';
                                }
                            }
                            ?>></td>
                    </tr>
                    <tr>
                        <td nowrap>Nombre : </td>
                        <td nowrap><input class="nom" name="t1" type="text" id="t1" tabindex="3"<?php
                            if (isset($_REQUEST['t1'])) {
                                echo 'value="' . $_REQUEST['t1'] . '"';
                            }
                            ?>></td>
                        <td nowrap>Apellido Paterno: </td>
                        <td nowrap><input name="t2" type="text" id="t2" tabindex="4" <?php
                            if (isset($_REQUEST['t2'])) {
                                echo 'value="' . $_REQUEST['t2'] . '"';
                            }
                            ?>></td>
                        <td nowrap>Apellido Materno:</td>
                        <td nowrap><input name="t3" type="text" id="t3" tabindex="5"<?php
                            if (isset($_REQUEST['t3'])) {
                                echo 'value="' . $_REQUEST['t3'] . '"';
                            }
                            ?>></td>
                    </tr>
                    <tr style="display:none">
                        <tH colspan="6" nowrap><div align="center">DATOS PERSONALES  


                            </div></tH>
                    </tr>
                    <tr style="display:none">
                        <td nowrap>Direccion:</td>
                        <td colspan="3" nowrap><input name="t4" type="text" id="t4" tabindex="6" size="50" <?php
                            if (isset($_REQUEST['t4'])) {
                                echo 'value="' . $_REQUEST['t4'] . '"';
                            }
                            ?>></td>
                        <td nowrap>Telefono:</td>
                        <td nowrap><input name="t5" type="text" id="t5" tabindex="7"<?php
                            if (isset($_REQUEST['t5'])) {
                                echo 'value="' . $_REQUEST['t5'] . '"';
                            }
                            ?>></td>
                    </tr>
                    <tr style="display:none">
                        <td nowrap>RFC:</td>
                        <td nowrap><input name="t6" type="text" id="t6" tabindex="8"></td>
                        <td nowrap>Empresa : </td>
                        <td nowrap><input name="t7" type="text" id="t7" tabindex="9"></td>
                        <td nowrap>% de Comision:</td>
                        <td nowrap><input name="t8" type="text" id="t8" tabindex="10"></td>
                    </tr>
                    <tr style="display:none">
                        <th colspan="6" nowrap>DATOS GENERALES </th>
                    </tr>
                    <tr style="display:none">
                        <td nowrap>Tipo de Persona:</td>
                        <td colspan="2" nowrap><select name="tip_per" id="tip_per" tabindex="11">
                                <option value="C" >CAJERO(A)</option>
                                <option value="V" >VENDEDOR(A)</option>
                                <option value="VC" selected="selected">CAJERO(A)/VENDOR(A)</option>
                            </select></td>
                        <td colspan="3" nowrap><label>Tipo de Acceso: 
                                <select name="tip_acc" id="tip_acc" tabindex="12">
                                    <option value="P" >Personal</option>
                                    <option value="G" selected="selected">General</option>
                                </select>
                                Status:
                                <select name="sta" id="sta" tabindex="13">
                                    <option value="1" selected="selected">Activo</option>
                                    <option value="0" >Inactivo</option>
                                </select>
                            </label></td>
                    </tr>
                    <tr style="#CCCCCC">
                        <td colspan="6" nowrap><div align="center" class="tdeli" style="display:none" >Acceso a Ventas</div></td>
                    </tr>
                    <tr>
                        <td colspan="6" nowrap>
                            <div align="center" style="display:none">
                                <?php
                                @$sql = mysqli_query($con ,"select * from dgtipven");
                                $numTipVen = mysqli_num_rows($sql);
                                ?>
                                <select name="tip_ven[]" size="<?php echo $numTipVen; ?>" multiple id="tip_ven[]" tabindex="14" style="width:40%;">
                                    <?php
                                    while (@$reg = mysqli_fetch_array($sql)) {
                                        echo '<option value="' . $reg['tip_ven'] . '" selected>' . $reg['des_tipven'] . '</option>';
                                    }
                                    ?>
                                </select>
                            </div>      </td>
                    </tr>
                    <tr>
                        <td colspan="6"><div align="center">
                                <input type="button" name="Submit2" value="Agregar" onClick="openpage('cat_cajeros_AC.php', '_self')"/>
                                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                <input type="button" name="Submit2" value="Regresar" onClick="openpage('cat_cajeros_PR.php', '_self')"/>
                            </div></td>
                    </tr>
               

            </table>

        </form>
      </div>
        <script>
            $(function () {
                $("#users").change(function () {

                    var id = $('#users').val();


                    $.ajax({
                        // En data puedes utilizar un objeto JSON, un array o un query string
                        data: {"oper": id},
                        //Cambiar a type: POST si necesario
                        type: "POST",
                        // Formato de datos que se espera en la respuesta
                        dataType: "json",
                        // URL a la que se enviará la solicitud Ajax
                        url: "usuario_ws.php",
                        success: function (data)
                        {
                            $('#formu1').show(); //muestro mediante id
                            //document.getElementById('formu1').style.display ='block';
                            $('#t0').val(data.datos.oper);
                            $('#10').val(data.datos.clave);
                            $('.nom').val(data.datos.nomb);
                            $('#t2').val(data.datos.apa);
                            $('#t3').val(data.datos.ama);
                            console.log(data);
                            console.log(data.datos.nomb);
                        },
                        error: function (xhr, ajaxOptions, thrownError)
                        {
                            console.error(xhr.statusText);
                            console.error(xhr.responseText);
                            console.error(xhr.status);
                            console.error(thrownError);
                        }



                    });


                });
            });


        </script>
    </body>
</html>
