<?php
  $page_title = 'Editar Cuenta';
  require_once('../../includes/load.php');
  page_require_level(5);
?>
<?php
 //update user other info
  if(isset($_POST['update'])){
    $req_fields = array('name','username','last_name' );
    validate_fields($req_fields);
    if(empty($errors)){
             $id = (int)$_SESSION['user_id'];
           $name = remove_junk($db->escape($_POST['name']));
       $username = remove_junk($db->escape($_POST['username']));
       $last_name = remove_junk($db->escape($_POST['last_name']));
            $sql = "UPDATE users SET name ='{$name}', username ='{$username}', last_name ='{$last_name}' WHERE id='{$id}'";
    $result = $db->query($sql);
          if($result && $db->affected_rows() === 1){
            $session->msg('s',"Cuenta actualizada. ");
            redirect('edit_account.php', false);
          } else {
            $session->msg('d',' Lo siento, actualización fallo.');
            redirect('edit_account.php', false);
          }
    } else {
      $session->msg("d", $errors);
      redirect('edit_account.php',false);
    }
  }
?>
<?php include_once('../../layouts/header.php'); ?>
  <div class="col-md-12">
    <?php echo display_msg($msg); ?>
  </div>
  <div class="row col-md-16">
    <div class="panel panel-default">
          <form method="post" action="edit_account.php?id=<?php echo (int)$user['id'];?>" class="clearfix">
            <div class="container pt-1 mt-1 animated fadeIn">
              <div class="row pt-4">
                <div class="col-12 mb-3">
                  <p class="h1 text-center text-primary font-weight-bold"> Editar mi cuenta <i class="fas fa-user-alt"></i></p>
                </div>
              </div> 
              <div class="row"> 
                <div class="col-12">
                  <p class="h3 text-primary">Datos Generales <i class="fas fa-user-circle"></i></p>
                </div>
                <div class="col-12 col-lg-6"> 
                  <p class="text-primary mb-1">Nombres</p>
                  <div class="input-group mb-3"> 
                    <div class="input-group-prepend">
                      <span class="input-group-text"><i class="fas fa-user"></i></span>
                    </div>
                    <input type="text" class="form-control" name="name" value="<?php echo remove_junk(ucwords($user['name'])); ?>">  
                  </div>
                </div>  
                <div class="col-12 col-lg-6"> 
                  <p class="text-primary mb-1">Apellidos</p>
                  <div class="input-group mb-3"> 
                    <div class="input-group-prepend">
                      <span class="input-group-text"><i class="fas fa-user"></i></span>
                    </div>
                    <input type="text" class="form-control" name="last_name" value="<?php echo remove_junk(ucwords($user['last_name'])); ?>">  
                  </div>
                </div> 
                <div class="col-12 col-lg-6"> 
                  <p class="text-primary mb-1">DNI</p>
                  <div class="input-group mb-3"> 
                    <div class="input-group-prepend">
                      <span class="input-group-text"><i class="fas fa-id-card"></i></span>
                    </div>
                    <input type="text" class="form-control" name="username" value="<?php echo remove_junk(ucwords($user['username'])); ?>">  
                  </div>
                </div>        
              </div>
                <div class="row mb-12">
                  <div class="col-12">
                    <center>
                      <button type="submit" name="update" class="btn btn-info">Actualizar</button>
                      <a href="change_password.php" title="change password" class="btn btn-danger">Cambiar contraseña</a>
                    </center>
                  </div>
                </div>
          </div>
        </form>
     </div>
   </div>





<?php include_once('../../layouts/footer.php'); ?>

