<!-- Content Wrapper. Contains page content -->
<div class="content-wrapper">
  <!-- Content Header (Page header) -->
  <section class="content-header">
    <h1>
      Gérer les
      <small>Utilisateurs</small>
    </h1>
    <ol class="breadcrumb">
      <li><a href="#"><i class="fa fa-dashboard"></i> Accueil</a></li>
      <li class="active">Utilisateurs</li>
    </ol>
  </section>

  <!-- Main content -->
  <section class="content">
    <!-- Small boxes (Stat box) -->
    <div class="row">
      <div class="col-md-12 col-xs-12">

        <?php if (session()->getFlashdata('success')): ?>
          <div class="alert alert-success alert-dismissible" role="alert">
            <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
            <?php echo session()->getFlashdata('success'); ?>
          </div>
        <?php elseif (session()->getFlashdata('error')): ?>
          <div class="alert alert-error alert-dismissible" role="alert">
            <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
            <?php echo session()->getFlashdata('error'); ?>
          </div>
        <?php endif; ?>

        <div class="box">
          <div class="box-header">
            <h3 class="box-title">Modifier l'utilisateur</h3>
          </div>
          <form role="form" action="<?php base_url('users/create') ?>" method="post">
            <div class="box-body">

              <?php if (isset($validation)): ?>
                <div class="alert alert-danger">
                  <ul>
                    <?php foreach ($validation->getErrors() as $error): ?>
                      <li><?= esc($error) ?></li>
                    <?php endforeach; ?>
                  </ul>
                </div>
              <?php endif; ?>

              <div class="form-group">
                <label for="groups">Rôle</label>
                <select class="form-control" id="groups" name="groups">
                  <option value="">Sélectionnez un rôle</option>
                  <?php foreach ($group_data as $k => $v): ?>
                    <option value="<?php echo $v['id'] ?>"
                      <?php if ($user_group['id'] == $v['id']) {
                        echo 'selected';
                      } ?>><?php echo $v['group_name'] ?></option>
                  <?php endforeach ?>
                </select>
              </div>

              <div class="form-group">
                <label for="username">Nom d'utilisateur</label>
                <input type="text" class="form-control" id="username" name="username" placeholder="Nom d'utilisateur" value="<?php echo $user_data['username'] ?>" autocomplete="off">
              </div>

              <div class="form-group">
                <label for="email">Email</label>
                <input type="email" class="form-control" id="email" name="email" placeholder="Email" value="<?php echo $user_data['email'] ?>" autocomplete="off">
              </div>

              <div class="form-group">
                <label for="fname">Nom</label>
                <input type="text" class="form-control" id="fname" name="fname" placeholder="Nom" value="<?php echo $user_data['firstname'] ?>" autocomplete="off">
              </div>

              <div class="form-group">
                <label for="lname">Prénom</label>
                <input type="text" class="form-control" id="lname" name="lname" placeholder="Prénom" value="<?php echo $user_data['lastname'] ?>" autocomplete="off">
              </div>

              <div class="form-group">
                <label for="phone">Téléphone</label>
                <input type="text" class="form-control" id="phone" name="phone" placeholder="Téléphone" value="<?php echo $user_data['phone'] ?>" autocomplete="off">
              </div>

              <div class="form-group">
                <label for="gender">Genre</label>
                <div class="radio">
                  <label>
                    <input type="radio" name="gender" id="male" value="1" <?php if ($user_data['gender'] == 1) {
                                                                            echo "checked";
                                                                          } ?>>
                    Homme
                  </label>
                  <label>
                    <input type="radio" name="gender" id="female" value="2" <?php if ($user_data['gender'] == 2) {
                                                                              echo "checked";
                                                                            } ?>>
                    Femme
                  </label>
                </div>
              </div>

              <div class="form-group">
                <div class="alert alert-info alert-dismissible" role="alert">
                  <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                  Laissez le champ du mot de passe vide si vous ne souhaitez pas le changer.
                </div>
              </div>

              <div class="form-group">
                <label for="password">Mot de passe</label>
                <input type="text" class="form-control" id="password" name="password" placeholder="Password" autocomplete="off">
              </div>

              <div class="form-group">
                <label for="cpassword">Confirmation mot de passe</label>
                <input type="password" class="form-control" id="cpassword" name="cpassword" placeholder="Confirm Password" autocomplete="off">
              </div>

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

            <div class="box-footer">
              <button type="submit" class="btn btn-primary">Enregistrer</button>
              <a href="<?php echo base_url('users/') ?>" class="btn btn-warning">Retour</a>
            </div>
          </form>
        </div>
        <!-- /.box -->
      </div>
      <!-- col-md-12 -->
    </div>
    <!-- /.row -->


  </section>
  <!-- /.content -->
</div>
<!-- /.content-wrapper -->

<script type="text/javascript">
  $(document).ready(function() {
    $("#groups").select2();

    $("#mainUserNav").addClass('active');
    $("#manageUserNav").addClass('active');
  });
</script>