 <?php  
   
  $queryclose = mysqli_query($mysqli, "SELECT apertura FROM apertura_cierre where id = 1") 
or die('error: '.mysqli_error($mysqli));
$rows  = mysqli_num_rows($queryclose);
$data  = mysqli_fetch_assoc($queryclose);
$bandera = $data['apertura'];
/*print_r($bandera);
die();*/

if ($bandera == 'CERRADO') {
    echo '<script>
                alert("EL ALMACEN SE ENCUENTRA CERRADO POR INVENTARIO DEL SUPERVISOR");
                // Obtener el nombre del servidor y construir la URL base
                var serverUrl = "http://" + window.location.hostname;
                var url = serverUrl + "/main.php?module=closed";
                window.location = url;
          </script>';
    return;
} 

if ($_GET['form']=='add') { ?> 

  <section class="content-header">
    <h1>
      <i class="fa fa-edit icon-title"></i> Agregar correos
    </h1>
    <ol class="breadcrumb">
      <li><a href="?module=start"><i class="fa fa-home"></i> Inicio </a></li>
      <li><a href="?module=medicines"> correos </a></li>
      <li class="active"> Más </li>
    </ol>
  </section>

  <!-- Main content -->
  <section class="content">
    <div class="row">
      <div class="col-md-12">
        <div class="box box-primary">
          <!-- form start -->
          <form role="form" class="form-horizontal" action="modules/trade/catalogos/conf_correo/proses.php?act=insert" method="POST">
            <div class="box-body">
              <?php  
          
              $query_id = mysqli_query($mysqli, "SELECT id FROM envio
                                                ORDER BY id DESC LIMIT 1")
                                                or die('error '.mysqli_error($mysqli));

              $count = mysqli_num_rows($query_id);

              if ($count <> 0) {
            
                  $data_id = mysqli_fetch_assoc($query_id);
                  $id    = $data_id['id']+1;
              } else {
                  $id = 1;
              }


              $buat_id   = str_pad($id, 0, "0", STR_PAD_LEFT);
              $id = "$buat_id";
              ?>

              <div class="form-group">
                <label class="col-sm-2 control-label">id</label>
                <div class="col-sm-5">
                  <input type="text" class="form-control" name="id" value="<?php echo $id; ?>" readonly required>
                </div>
              </div>



              <div class="form-group">
                <label class="col-sm-2 control-label">HOST</label>
                <div class="col-sm-5">
                  <input type="text" class="form-control" name="host" required>
                </div>
				</div>
				
			  <div class="form-group">
                <label class="col-sm-2 control-label">PORT</label>
                <div class="col-sm-5">
                  <input type="text" class="form-control" name="port"  required>
                </div>
              </div>

			  <div class="form-group">
                <label class="col-sm-2 control-label">NOMBRE</label>
                <div class="col-sm-5">
                  <input type="text" class="form-control" name="nombre"  required>
                </div>
              </div>
			  <div class="form-group">
                <label class="col-sm-2 control-label">USUARIO</label>
                <div class="col-sm-5">
                  <input type="text" class="form-control" name="usuario"  required>
                </div>
              </div>
			  <div class="form-group">
                <label class="col-sm-2 control-label">PASSWORD</label>
                <div class="col-sm-5">
                  <input type="text" class="form-control" name="password"  required>
                </div>
              </div>

			  <div class="form-group">
                <label class="col-sm-2 control-label">SETNAME</label>
                <div class="col-sm-5">
                  <input type="text" class="form-control" name="setname"  required>
                </div>
              </div>
   
	
		

 


            </div><!-- /.box body -->

            <div class="box-footer">
              <div class="form-group">
                <div class="col-sm-offset-2 col-sm-10">
                  <input type="submit" class="btn btn-primary btn-submit" name="Guardar" value="Guardar">
                  <a href="?module=parametro_envio" class="btn btn-default btn-reset">Cancelar</a>
                </div>
              </div>
            </div><!-- /.box footer -->
          </form>
        </div><!-- /.box -->
      </div><!--/.col -->
    </div>   <!-- /.row -->
  </section><!-- /.content -->
<?php
}

elseif ($_GET['form']=='edit') { 
  if (isset($_GET['id'])) {

      $query = mysqli_query($mysqli, "SELECT * FROM envio WHERE id='$_GET[id]'") 
                                      or die('error: '.mysqli_error($mysqli));
      $data  = mysqli_fetch_assoc($query);
    }
?>

  <section class="content-header">
    <h1>
      <i class="fa fa-edit icon-title"></i> Modificar parametro de envio de correos
    </h1>
    <ol class="breadcrumb">
      <li><a href="?module=start"><i class="fa fa-home"></i> Inicio </a></li>
      <li><a href="?module=catalogo_correos"> correos </a></li>
      <li class="active"> Modificar </li>
    </ol>
  </section>

  <!-- Main content -->
  <section class="content">
    <div class="row">
      <div class="col-md-12">
        <div class="box box-primary">
          <!-- form start -->
          <form role="form" class="form-horizontal" action="modules/trade/catalogos/conf_correo/proses.php?act=update" method="POST">
            <div class="box-body">
              
              <div class="form-group">
                <label class="col-sm-2 control-label">id</label>
                <div class="col-sm-5">
                  <input type="text" class="form-control" name="id" value="<?php echo $data['id']; ?>" readonly required>
                </div>
              </div>


              <div class="form-group">
                <label class="col-sm-2 control-label">HOST</label>
                <div class="col-sm-5">
                  <input type="text" class="form-control" name="host" autocomplete="off" value="<?php echo $data['host']; ?>" required>
                </div>
				</div>
				
			  <div class="form-group">
                <label class="col-sm-2 control-label">PORT</label>
                <div class="col-sm-5">
                  <input type="text" class="form-control" name="port" autocomplete="off" value="<?php echo $data['port']; ?>" required>
                </div>
              </div>

			  <div class="form-group">
                <label class="col-sm-2 control-label">NOMBRE</label>
                <div class="col-sm-5">
                  <input type="text" class="form-control" name="nombre" autocomplete="off" value="<?php echo $data['nombre']; ?>" required>
                </div>
              </div>
			  <div class="form-group">
                <label class="col-sm-2 control-label">USUARIO</label>
                <div class="col-sm-5">
                  <input type="text" class="form-control" name="usuario" autocomplete="off" value="<?php echo $data['usuario']; ?>" required>
                </div>
              </div>
			  <div class="form-group">
                <label class="col-sm-2 control-label">PASSWORD</label>
                <div class="col-sm-5">
                  <input type="text" class="form-control" name="password" autocomplete="off" value="<?php echo $data['password']; ?>" required>
                </div>
              </div>
			  
			  <div class="form-group">
                <label class="col-sm-2 control-label">SETNAME</label>
                <div class="col-sm-5">
                  <input type="text" class="form-control" name="setname" autocomplete="off" value="<?php echo $data['setname']; ?>" required>
                </div>
              </div>

              </div>
			  
   




            </div><!-- /.box body -->

            <div class="box-footer">
              <div class="form-group">
                <div class="col-sm-offset-2 col-sm-10">
                  <input type="submit" class="btn btn-primary btn-submit" name="Guardar" value="Guardar">
                  <a href="?module=parametro_envio" class="btn btn-default btn-reset">Cancelar</a>
                </div>
              </div>
            </div><!-- /.box footer -->
          </form>
        </div><!-- /.box -->
      </div><!--/.col -->
    </div>   <!-- /.row -->
  </section><!-- /.content -->
<?php
}


