<?php 
require_once('xconn.php');
session_start();
 
  if(!isset($_SESSION['d_usuario'])){
    header('Location: index.php');
    exit;
  }else{
    $iUsuario = $_SESSION['c_usuario'];
  }

  if ($conn ->connect_error) {
  die("Connection failed: " . $conn ->connect_error);
  }
  
  $dNombre = '';

  $result = mysqli_query($conn,"SELECT d_usuario, d_nombre FROM t_usuarios WHERE c_cliente='" . $iUsuario . "'");

  if($row = mysqli_fetch_array($result)){
      $dNombre = $row['d_nombre'];
  }else{
    //header("Location: dashboard.php");
    exit();
  }
?>
<html>
<head>
  <title>Diaso | Brokers</title>
  <!-- Required meta tags -->
  <meta charset="utf-8">
  <meta content="width=device-width, initial-scale=1.0" name="viewport" />
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
  <!--     Fonts and icons     -->
  <link rel="stylesheet" type="text/css" href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,700|Roboto+Slab:400,700|Material+Icons" />
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/latest/css/font-awesome.min.css">
  <!-- Material Kit CSS -->
  <link href="assets/css/material-dashboard.css?v=2.1.2" rel="stylesheet" />
  <script src="//code.jquery.com/jquery-1.11.2.min.js"></script>
  <script type="text/javascript">
    function valideKey(evt){
    
      // code is the decimal ASCII representation of the pressed key.
      var code = (evt.which) ? evt.which : evt.keyCode;
      
      if(code==8) { // backspace.
        return true;
      } else if(code>=48 && code<=57) { // is a number.
        return true;
      } else{ // other keys.
        return false;
      }
    }
  </script>
  <script type="text/javascript">
    $(document).ready(function(){
      $("#codigo_postal").on('focusout', function postinput(){
           var codigop = $(this).val(); // this.value
           //Estado
          $.ajax({ 
              url: 'xsources.php',
              data: { funciones: 'lFun_ObtenEstado', cp: codigop },
              type: 'post'
          }).done(function(responseData) {
              var select=document.getElementById("cbo_estado");
              for(var i=1;i<select.length;i++)
              {
                if(select.options[i].value==responseData)
                {
                  // seleccionamos el valor que coincide
                  select.selectedIndex=i;
                }
              }
          }).fail(function() {
              console.log('Failed');
          });

          //Municipio
          $.ajax({ 
              url: 'xsources.php',
              data: { funciones: 'lFun_ObtenMunicipio', cp: codigop },
              type: 'post'
          }).done(function(responseData) {
              var select=document.getElementById("cbo_municipio");
              var content = JSON.parse(responseData);
              var i,l = select.options.length-1;
              //console.log('Done: ', content.res.d_municipio);
              for(i = l; i >= 0; i--){
                select.remove(i);
              }

              for(var i = 0; i < content.res.d_municipio.length; i++){
                const option = document.createElement('option');
                option.value = content.res.c_municipio[i];
                option.text = content.res.d_municipio[i];
                select.appendChild(option);
              }
          }).fail(function() {
              console.log('Failed');
          });

          //Colonia
          $.ajax({ 
              url: 'xsources.php',
              data: { funciones: 'lFun_ObtenColonia', cp: codigop },
              type: 'post'
          }).done(function(responseData) {
              var content = JSON.parse(responseData);
              //console.log('Done: ', content.res.d_colonia);
              var select=document.getElementById("cbo_colonia");
              var i, L = select.options.length - 1;
               for(i = L; i >= 0; i--) {
                  select.remove(i);
               }

              for(var i=0;i<content.res.d_colonia.length;i++){
                const option = document.createElement('option');
                option.value = content.res.c_colonia[i];
                option.text = content.res.d_colonia[i];
                select.appendChild(option);
              }
              
          }).fail(function() {
              console.log('Failed');
          });
      });
    }); 
  </script>
</head>

<body>
  <div class="wrapper ">
    <div class="sidebar" data-color="azure" data-background-color="black">
      <!--
      Tip 1: You can change the color of the sidebar using: data-color="purple | azure | green | orange | danger"

      Tip 2: you can also add an image using data-image tag
  -->
      <div class="logo">
        <a href="https://diaso.com.mx/" class="simple-text logo-mini">
          Brokers -
          Diaso
        </a>
        <img src="img/logo.png" width="200" height="100"/>
      </div>
      <div class="sidebar-wrapper">
        <ul class="nav">
          <li class="nav-item">
            <a class="nav-link" href="dashboard.php">
              <i class="material-icons">dashboard</i>
              <p>Dashboard</p>
            </a>
          </li>
          <li class="nav-item active">
            <a class="nav-link" href="clientes.php">
              <i class="material-icons">dashboard</i>
              <p>Clientes</p>
            </a>
          </li>
          <li class="nav-item">
            <a class="nav-link" href="solicitudes.php">
              <i class="material-icons">dashboard</i>
              <p>Solicitudes</p>
            </a>
          </li>
          <li class="nav-item">
            <a class="nav-link" href="catalogos.php">
              <i class="material-icons">dashboard</i>
              <p>Catalogos</p>
            </a>
          </li>
          <li class="nav-item">
            <a class="nav-link" href="users.php">
              <i class="material-icons">dashboard</i>
              <p>Usuarios</p>
            </a>
          </li>
          
          <li class="nav-item active-pro ">
              <p>Disponible en: Web & Movil</p>
          </li>
          <!-- your sidebar here -->
        </ul>
      </div>
    </div>
    <div class="main-panel">
      <!-- Navbar -->
      <nav class="navbar navbar-expand-lg navbar-transparent navbar-absolute fixed-top ">
        <div class="container-fluid">
          <div class="navbar-wrapper">
            <a class="navbar-brand" href="javascript:;">Clientes</a>
          </div>
          <button class="navbar-toggler" type="button" data-toggle="collapse" aria-controls="navigation-index" aria-expanded="false" aria-label="Toggle navigation">
            <span class="sr-only">Toggle navigation</span>
            <span class="navbar-toggler-icon icon-bar"></span>
            <span class="navbar-toggler-icon icon-bar"></span>
            <span class="navbar-toggler-icon icon-bar"></span>
          </button>
          <div class="collapse navbar-collapse justify-content-end">
            <ul class="navbar-nav">
              <li class="nav-item">
                <a class="nav-link" href="javascript:;">
                  <i class="material-icons">notifications</i> Notificaciones
                </a>
              </li>
              <li class="nav-item dropdown">
                <a class="nav-link" href="javascript:;" id="navbarDropdownProfile" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                  <i class="material-icons">person</i>Hola <?php echo', ' . $_SESSION['d_usuario'] . '.'; ?>
                  <p class="d-lg-none d-md-block">
                    Hola, <?php 'Edgar Mejia'; ?>
                  </p>
                </a>
                <div class="dropdown-menu dropdown-menu-right" aria-labelledby="navbarDropdownProfile">
                  <a class="dropdown-item" href="profile.php">Perfil</a>
                  <a class="dropdown-item" href="configuration.php">Configuracion</a>
                  <div class="dropdown-divider"></div>
                  <a class="dropdown-item" href="xlogout.php">Salir</a>
                </div>
              </li>
              <!-- your navbar here -->
            </ul>
          </div>
        </div>
      </nav>
      
      <!-- End Navbar -->
      <div class="content">
        <div class="container-fluid">
          <div class="row">
            <div class="col-md-12">
            	<div class="card">
                <div class="card-header card-header-primary">
                  <h4 class="card-title">Alta</h4>
                  <p class="card-category">Llena todos los campos</p>
                </div>
                <div class="card-body">
                  <form action="registry_customer.php" method="POST">
                    <div class="row">
                      <div class="col-md-4">
                        <div class="form-group">
                          <label class="bmd-label-floating">Nombre</label>
                          <input type="text" class="form-control" name="txt_nombre">
                        </div>
                      </div>
                      <div class="col-md-4">
                        <div class="form-group">
                          <label class="bmd-label-floating">Apellido Paterno</label>
                          <input type="text" class="form-control" name="txt_appat">
                        </div>
                      </div>
                      <div class="col-md-4">
                        <div class="form-group">
                          <label class="bmd-label-floating">Apellido Materno</label>
                          <input type="text" class="form-control" name="txt_apmat">
                        </div>
                      </div>
                    </div>
                    <div class="row">
                      <div class="col-md-4">
                        <div class="form-group">
                          <label class="bmd-label-floating">Usuario</label>
                          <input type="text" class="form-control" name="txt_usuario">
                        </div>
                      </div>
                      <div class="col-md-4">
                        <div class="form-group">
                          <label class="bmd-label-floating">Password</label>
                          <input type="text" class="form-control" name="txt_password">
                        </div>
                      </div>
                      <div class="col-md-4">
                        <div class="form-group">
                          <label class="bmd-label-floating" id="mail">Correo</label>
                          <input type="email" class="form-control" name="txt_correo" id="email">
                        </div>
                      </div>
                      
                    </div>
                    <div class="row">
                      <div class="col-md-4">
                        <div class="form-group">
                          <label class="bmd-label-floating">Calle</label>
                          <input type="text" class="form-control" name="txt_calle">
                        </div>
                      </div>
                      <div class="col-md-4">
                        <div class="form-group">
                          <label class="bmd-label-floating">No. Ext</label>
                          <input type="text" class="form-control" name="txt_ext">
                        </div>
                      </div>
                      <div class="col-md-4">
                        <div class="form-group">
                          <label class="bmd-label-floating">No. Int</label>
                          <input type="text" class="form-control" name="txt_int">
                        </div>
                      </div>

                    </div>
                    <div class="row">
                      <div class="col-md-2">
                        <div class="form-group">
                          <label class="bmd-label-floating">Codigo Postal</label>
                          <input type="text" class="form-control" name="txt_cp" maxlength="5" id="codigo_postal">
                        </div>
                      </div>
                      <div class="col-md-5">
                        <div class="form-group">
                          <label class="bmd-label-floating">Colonia</label>
                          <select class="form-control" name="txt_colonia" id="cbo_colonia">
                            <option value="0">Seleccione</option>
                          </select>
                        </div>
                      </div>
                      <div class="col-md-5">
                        <div class="form-group">
                          <label class="bmd-label-floating">Municipio</label>
                          <select class="form-control" name="Cbo_Municipio" id="cbo_municipio" disabled>
                            <option value="0">Seleccione</option>
                          </select>
                        </div>
                      </div>
                    </div>
                    <div class="row">
                      <div class="col-md-4">
                        <div class="form-group">
                          <label class="bmd-label-floating">Estado</label>
                          <select class="form-control" name="txt_estado" id="cbo_estado" disabled>
                            <option value="0">Seleccione</option>
                            <?php
                              $result2 = mysqli_query($conn,"SELECT c_consec, d_descripcion FROM t_catalogoestado");
                              while ($valores = mysqli_fetch_array($result2)) {
                                echo '<option value="' .$valores['c_consec']. '">' .$valores['d_descripcion']. '</option>';
                              }
                            ?>
                          </select>
                        </div>
                      </div>
                      <div class="col-md-4">
                        <div class="form-group">
                          <label class="bmd-label-floating">Telefono</label>
                          <input type="text" class="form-control" name="txt_telefono" maxlength="10" onkeypress="return valideKey(event);">
                        </div>
                      </div>
                      <div class="col-md-4">
                        <div class="form-group">
                          <label class="bmd-label-floating">Fecha Nac</label>
                          <input type="date" class="form-control" name="txt_fechanac">
                        </div>
                      </div>
                    </div>
                    <div class="row">
                      <div class="col-md-4">
                        <div class="form-group">
                          <label class="bmd-label-floating">Edad</label>
                          <input type="text" class="form-control" name="txt_edad" maxlength="2" onkeypress="return valideKey(event);">
                        </div>
                      </div>
                      <div class="col-md-4">
                        <div class="form-group">
                          <label class="bmd-label-floating">Estado Civil</label>
                          <select class="form-control" name="txt_edociv">
                            <option value="0">Seleccione</option>
                            <?php
                              $result2 = mysqli_query($conn,"SELECT c_estado, d_nombre FROM t_catalogoestadocivil");
                              while ($valores = mysqli_fetch_array($result2)) {
                                echo '<option value="' .$valores['c_estado']. '">' .$valores['d_nombre']. '</option>';
                              }
                              
                            ?>
                          </select>
                        </div>
                      </div>
                      <div class="col-md-4">
                        <div class="form-group">
                          <label class="bmd-label-floating">Genero</label>
                          <select class="form-control" name="txt_genero">
                            <option value="0">Seleccione</option>
                            <?php
                              $result2 = mysqli_query($conn,"SELECT c_genero, d_genero FROM t_catalogogenero");
                              while ($valores = mysqli_fetch_array($result2)) {
                                echo '<option value="' .$valores['c_genero']. '">' .$valores['d_genero']. '</option>';
                              }
                              
                            ?>
                          </select>
                        </div>
                      </div>
                    </div>
                    <div class="row">
                      <div class="col-md-4">
                        <div class="form-group">
                          <label class="bmd-label-floating">Tipo Actividad</label>
                          <select class="form-control" name="txt_tipoact">
                            <option value="0">Seleccione</option>
                            <?php
                              $result2 = mysqli_query($conn,"SELECT c_actividad, d_tipoactividad FROM t_catalogotipoactividad");
                              while ($valores = mysqli_fetch_array($result2)) {
                                echo '<option value="' .$valores['c_actividad']. '">' .$valores['d_tipoactividad']. '</option>';
                              }
                              
                            ?>
                          </select>
                        </div>
                      </div>
                    </div>
                    <button type="submit" class="btn btn-primary pull-right">Dar de Alta</button>
                    <div class="clearfix"></div>
                  </form>
                </div>
              </div>
            </div>
            </div>
          </div>
        </div>
      </div>
      <footer class="footer">
        <div class="container-fluid">
          <nav class="float-left">
            <ul>
              <li>
                <a href="https://diaso.com.mx/">
                  Brokers
                </a>
              </li>
            </ul>
          </nav>
          <div class="copyright float-right">
            &copy;
            <script>
              document.write(new Date().getFullYear())
            </script>, Diaso.
            <a href="xlogout.php" class="btn btn-primary btn-round">Salir</a>
          </div>
          <!-- your footer here -->
        </div>
      </footer>
    </div>
  </div>

  <script src="assets/js/core/jquery.min.js"></script>
  <script src="assets/js/core/popper.min.js"></script>
  <script src="assets/js/core/bootstrap-material-design.min.js"></script>
  <script src="assets/js/plugins/perfect-scrollbar.jquery.min.js"></script>


</body>
</html>