<?php
	$Seccion      = 'Expositores';
	$NameSec      = 'Expositores';
	$SecLine      = array('Expositores', 'Editar');
	$Position   = '../';
	require_once($Position.'config/config.php');
  require_once($Position.'config/conexion.php');
  require_once($Position.'config/user.php');
  require_once($Position.'funciones/acces.php');
  require_once($Position.'funciones/logout.php');
  require_once($Position.'funciones/funciones.php');
  //require_once($Position.'funciones/extras.php');

	if ( $_POST['Save'] == "Ok" ) {

		$Nombre    = addslashes($_POST['Nombre']);
		$Apellidos = addslashes($_POST['Apellidos']);
		$Titulo    = addslashes($_POST['Titulo']);
		$Email     = addslashes($_POST['Email']);
		$Celular   = addslashes($_POST['Celular']);
		$Contenido = addslashes($_POST['Contenido']);
		$Activo    = $_POST['Activo'];

		$UsuarioDependiente	= $_POST['UsuarioDependiente'];

		// if( $_POST['Password'] == '0000000000' ){
	  //   $Pass     = '';
	  //   $PassEdit = '';
		// }else{
	  //   $Pass     = md5(addslashes($_POST['Password']));
	  //   $PassEdit = "Pass  = '$Pass',";
		// }
	}

	//Guardar Datos
	if ( $_POST['Save'] == "Ok" && $_POST['Action'] == "New" ) {

		//Insert Usuario
    $Query = "
			INSERT INTO CMS_Expositores
	    (
				Email, Celular,
				Nombre, Apellidos,
				Titulo, Contenido,
				Activo
			)VALUES(
				'$Email', '$Celular',
				'$Nombre', '$Apellidos',
				'$Titulo', '$Contenido',
				'$Activo'
			)
		";
    mysqli_query($mysqli, $Query );
    $Id = mysqli_insert_id($mysqli);

	}

	if ( $_POST['Save'] == "Ok" && $_POST['Id'] ) {

	    $Id = $_POST['Id'];
	    $Query = "
		    UPDATE CMS_Expositores SET
			    Nombre    = '$Nombre',
			    Apellidos = '$Apellidos',
					Titulo		= '$Titulo',
					Contenido	= '$Contenido',
					Email			= '$Email',
					Celular		= '$Celular',
			    Activo    = '$Activo'
		    WHERE Id  = '$Id'
	    ";
	    mysqli_query($mysqli, $Query );
	    $Save = 'Ok';

	}

	if ( $_POST['Save'] == "Ok" && $_POST['Action'] == "New" && $Id ) {
	   echo '<script type="text/javascript">document.location.href="edit.php?Id='.$Id.'&New=Ok"</script>';
	}

	//Usuario
	$Query = "
		SELECT
			usr.Id,
			usr.Email,
			usr.Celular,
			usr.Nombre, usr.Apellidos,
			usr.Titulo, usr.Contenido,
			usr.Activo
		FROM CMS_Expositores usr
		WHERE usr.Id = '$_GET[Id]'
	";
	$Result = mysqli_query($mysqli, $Query );
	$Expo = mysqli_fetch_assoc($Result);

?>

<!DOCTYPE html>
<html lang="en">

<?php require_once($Position.'head.php'); ?>

<body class="fix-sidebar fix-header card-no-border">

  <div class="preloader">
    <svg class="circular" viewBox="25 25 50 50">
    <circle class="path" cx="50" cy="50" r="20" fill="none" stroke-width="2" stroke-miterlimit="10" /> </svg>
  </div>

  <div id="main-wrapper">

    <?php require_once($Position.'header.php'); ?>
    <?php require_once($Position.'menu.php'); ?>

    <div class="page-wrapper">

      <div class="container-fluid">

        <form method="post" enctype="multipart/form-data" data-validate="parsley" role="form" id="FormPer">

          <div class="row page-titles page-titles-fixed">

              <?php require_once($Position.'title.php'); ?>

              <!-- Botones -->
              <div class="col-md-7 align-self-center text-right">
                <div class="btn-group" role="group" aria-label="Basic example">

									<!-- Btn Regresar -->
									<button
										type="button"
										class="btn btn-sm btn-secondary"
										onclick="window.location.href='index.php'"
									>
										Regresar
										<i class="fa fa-arrow-left m-l-10"></i>
									</button>
									<!-- End Btn Regresar -->

									<!-- Btn Guardar -->
									<button
										type="submit"
										class="btn btn-sm btn-success"
									>
										Guardar
										<i class="fa fa-check m-l-10"></i>
									</button>
									<!-- End Btn Guardar -->

                  <input type="hidden" name="Save" value="Ok">

                  <?php if( $Expo['Id'] ){ ?>
										<input name="Id" type="hidden" id="Id" value="<?php echo $Expo['Id']; ?>">
										<input name="Action" type="hidden" value="Edit">
									<?php }else{ ?>
										<input name="Action" type="hidden" value="New">
									<?php } ?>
                </div>
              </div>
              <!-- End Botones -->

          </div>

          <div class="row inner-fixed-content">
            <div class="col-12">

							<!-- Nav tabs -->
							<ul class="nav nav-tabs tabcontent-border" role="tablist">

								<!-- Información -->
								<li class="nav-item">
									<a class="nav-link active" data-toggle="tab" href="#Informacion" role="tab">
										<span class="hidden-sm-up"><i class="ti-user"></i></span>
										<span class="hidden-xs-down">Información</span>
									</a>
								</li>
								<!-- End Información -->

								<!-- Fotografía -->
								<li class="nav-item">
									<a class="nav-link" data-toggle="tab" href="#Foto" role="tab">
										<span class="hidden-sm-up"><i class="ti-user"></i></span>
										<span class="hidden-xs-down">Fotografía</span>
									</a>
								</li>
								<!-- End Fotografía -->

								<!-- Semblanza -->
								<li class="nav-item">
									<a class="nav-link" data-toggle="tab" href="#Semblanza" role="tab">
										<span class="hidden-sm-up"><i class="ti-user"></i></span>
										<span class="hidden-xs-down">Semblanza</span>
									</a>
								</li>
								<!-- End Semblanza -->

							</ul>
							<!-- End Nav tabs -->

							<!-- Tabs Content -->
							<div class="tab-content tabcontent-border">

								<!-- Tab Información -->
								<div class="tab-pane card-body active" id="Informacion" role="tabpanel">

									<div class="row">

										<!-- Titulo -->
										<div class="form-group col-sm-12">
											<label class="col-form-label">Titulo<span class="text-danger">*</span></label>
											<div class="">
												<input
													name="Titulo"
													type="text"
													class="form-control"
													value="<?php echo $Expo['Titulo'];?>"
													autocomplete="off"
													required="true"
												>
											</div>
										</div>
										<!-- End Titulo -->

										<!-- Nombre -->
										<div class="form-group col-sm-6">
											<label class="col-form-label">Nombre(s)<span class="text-danger">*</span></label>
											<div class="">
												<input
													name="Nombre"
													type="text"
													class="form-control"
													value="<?php echo $Expo['Nombre']; ?>"
													autocomplete="off"
													required="true"
												>
											</div>
										</div>
										<!-- End Nombre -->

										<!-- Apellidos -->
										<div class="form-group col-sm-6">
											<label class="col-form-label">Apellido(s)<span class="text-danger">*</span></label>
											<div class="">
												<input
													name="Apellidos"
													type="text"
													class="form-control"
													value="<?php echo $Expo['Apellidos'];?>"
													autocomplete="off"
													required="true"
												>
											</div>
										</div>
										<!-- End Apellidos -->

										<!-- Celular -->
										<div class="form-group col-sm-12">
											<label class="col-form-label">Teléfonos Celular<span class="text-danger">*</span></label>
											<div class="">
												<input class="form-control" id="Celular" name="Celular" value="<?php echo $Expo['Celular'];?>" autocomplete="off" parsley-trigger="change">
											</div>
										</div>
										<!-- End Celular -->

										<!-- Email -->
										<div class="form-group col-sm-12">
											<label class="col-form-label">Correo Electrónico<span class="text-danger">*</span></label>
											<div class="">
												<input type="email" class="form-control" id="email" name="Email" value="<?php echo $Expo['Email'];?>" autocomplete="off" parsley-trigger="change">
											</div>
										</div>
										<!-- End Email -->

										<!-- Status -->
										<div class="form-group col-sm-12">
											<label class="col-form-label">Status<span class="text-danger">*</span></label>
											<div class="">
												<select
													class="chosen-select"
													name="Activo"
													required
													data-validation-required-message="This field is required"
												>
													<option
														value="1"
														<?php
															if(
																( $Sta[Id] && $Expo[Activo] == 1 )
																||
																( !$Expo[Id] )
															){
														 		echo "selected='selected'";
															}
														?>
													>
														Activo
													</option>
													<option
														value="0"
														<?php
															if(
																$Sta[Id] && $Expo[Activo] == 0
															){
														 		echo "selected='selected'";
															}
														?>
													>
														Inactivo
													</option>
												</select>
											</div>
										</div>
										<!-- End Status -->

									</div>
								</div>
								<!-- End Tab Información -->

								<!-- Tab Foto -->
								<div class="tab-pane card-body" id="Foto" role="tabpanel">
									<div class="row">

									</div>
								</div>
								<!-- End Tab Foto -->

								<!-- Tab Semblanza -->
								<div class="tab-pane card-body" id="Semblanza" role="tabpanel">

									<div class="row">

										<!-- Semblanza -->
										<div class="form-group col-sm-12">
											<label class="col-form-label">Semblanza</label>
											<div class="">
												<textarea
													name="Contenido"
													class="form-control TextArea"
												><?php echo $Expo['Contenido'];?></textarea>
											</div>
										</div>
										<!-- End Titulo -->

									</div>

								</div>
								<!-- End Tab Semblanza -->

							</div>
							<!-- End Tabs Content -->

            </div>
          </div>

        </form>
      </div>

      <?php //require_once($Position.'footer.php'); ?>

    </div>

  </div>

  <?php require_once($Position.'scripts.php'); ?>
  <script>

  </script>
</body>

</html>
