<?PHP
require_once('core.php');
require_once('app/php/session.admin.php');
if($uti['rank'] < $ACCESS['badge'])
{
  header('Location: home');
  exit();
}
$erreur = false;
$post = false;
if(isset($_POST['supp']))
{
        $id = htmlspecialchars(trim($_POST['id']));
        if(!empty($_POST['id']))
        {
          $Select = $bdd->prepare('SELECT * FROM pluscms_boutique_badges WHERE id = ?');
          $Select->execute(array($id));
          if ($Select->rowCount() != 1) {
            $erreur = true;
            $message = "Impossible de trouver l'article.";
          }

        if ($erreur == false) {
        $DeleteArticles = $bdd->prepare('DELETE FROM pluscms_boutique_badges WHERE id = ?');
        $DeleteArticles->execute(array($id));
        $InsertLogs = $bdd->prepare('INSERT INTO pluscms_logstaff (pseudo, date, action) VALUES (?, ?, ?)');
        $InsertLogs->execute(array($uti['username'], time(), "Supprime un badge de la boutique."));
        $message = "Badge supprimé avec succès. Rechargement dans 3 secondes.";
        $post = true;
        header("Refresh: 3;URL=badges");
        }
    }
    else
    {
        $erreur = true;
        $message = "Merci de remplir tous les champs.";
    }
}

if (isset($_POST['add'])) {
  $code = htmlspecialchars(trim($_POST['code']));
  $type = htmlspecialchars(trim($_POST['type']));
  $prix = intval(trim($_POST['prix']));
  if ($code != "" && $type != "" && $prix != "") {
    $SelectBadges = $bdd->prepare('SELECT * FROM pluscms_boutique_badges WHERE code = ? LIMIT 1');
    $SelectBadges->execute(array($code));
    if ($SelectBadges->rowCount() == 1) {
    $erreur = true;
    $message = "Le badge est déjà en vente !";
    } else {
      $AddBadges = $bdd->prepare('INSERT INTO pluscms_boutique_badges (code, type, prix) VALUES (?,?,?)');
      $AddBadges->execute(array($code,$type,$prix));
      $InsertLogs = $bdd->prepare('INSERT INTO pluscms_logstaff (pseudo, date, action) VALUES (?, ?, ?)');
      $InsertLogs->execute(array($uti['username'], time(), "Ajout d'un badge dans boutique."));
      $message = "Badge ajouter avec succès. Rechargement dans 3 secondes.";
      $post = true;
      header("Refresh: 3;URL=badges");
    }
  } else {
    $message = "Merci de remplir tous les champs.";
    $erreur = true;
  }
}
?>
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <title><?PHP echo htmlentities($cms['nom_hotel']); ?> | Panel</title>
  <!-- Tell the browser to be responsive to screen width -->
  <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
  <!-- Bootstrap 3.3.7 -->
  <link rel="stylesheet" href="bower_components/bootstrap/dist/css/bootstrap.min.css">
  <!-- Font Awesome -->
  <link rel="stylesheet" href="bower_components/font-awesome/css/font-awesome.min.css">
  <!-- Ionicons -->
  <link rel="stylesheet" href="bower_components/Ionicons/css/ionicons.min.css">
  <!-- jvectormap -->
  <link rel="stylesheet" href="bower_components/jvectormap/jquery-jvectormap.css">
  <!-- Theme style -->
  <link rel="stylesheet" href="dist/css/AdminLTE.min.css">
  <!-- AdminLTE Skins. Choose a skin from the css/skins
       folder instead of downloading all of them to reduce the load. -->
  <link rel="stylesheet" href="dist/css/skins/_all-skins.min.css">

  <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
  <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
  <!--[if lt IE 9]>
  <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
  <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
  <![endif]-->

  <!-- Google Font -->
  <link rel="stylesheet"
        href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,600,700,300italic,400italic,600italic">
</head>
<body class="hold-transition skin-blue sidebar-mini" style="">
<div class="wrapper" style="">

  <header class="main-header">

    <!-- Logo -->
    <a href="home.php" class="logo">
      <!-- mini logo for sidebar mini 50x50 pixels -->
      <span class="logo-mini"><b>A</b>DM</span>
      <!-- logo for regular state and mobile devices -->
      <span class="logo-lg"><b>Admin</span>
    </a>

    <!-- Header Navbar: style can be found in header.less -->
    <nav class="navbar navbar-static-top">
      <!-- Sidebar toggle button-->
      <a href="#" class="sidebar-toggle" data-toggle="push-menu" role="button">
        <span class="sr-only">Toggle navigation</span>
      </a>
      <!-- Navbar Right Menu -->
      <div class="navbar-custom-menu">
        <ul class="nav navbar-nav">

          <!-- User Account: style can be found in dropdown.less -->
          <li class="dropdown user user-menu">
            <a href="#" class="dropdown-toggle" data-toggle="dropdown">
              <img src="https://www.habbo.de/habbo-imaging/avatarimage?figure=<?PHP echo htmlspecialchars(trim($uti['look'])); ?>&direction=2&head_direction=3&action=wav&size=m&gesture=sml&headonly=1" class="user-image" alt="User Image">
              <span class="hidden-xs"><?PHP echo htmlentities($uti['username']); ?></span>
            </a>
            <ul class="dropdown-menu">
              <!-- User image -->
              <li class="user-header">
                <img src="https://www.habbo.de/habbo-imaging/avatarimage?figure=<?PHP echo htmlspecialchars(trim($uti['look'])); ?>&direction=2&head_direction=3&action=wav&size=m&gesture=sml&headonly=1" class="img-circle" alt="User Image">

                <p>
                  <?PHP echo htmlentities($uti['username']); ?>
                  <small>Membre depuis <?PHP echo date('d.m.Y', $uti['account_created']); ?></small>
                </p>
              </li>
              <!-- Menu Body -->
              <!-- Menu Footer-->
              <li class="user-footer">
                <div class="pull-right">
                  <a href="logout.php" class="btn btn-default btn-flat">Déconnexion</a>
                </div>
              </li>
            </ul>
          </li>
        </ul>
      </div>

    </nav>
  </header>
  <!-- Left side column. contains the logo and sidebar -->
  <?PHP require_once('template/header.php'); ?>

  <!-- Content Wrapper. Contains page content -->
  <div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <section class="content-header">
      <h1>
        Boutique
      </h1>
      <ol class="breadcrumb">
        <li><a href="#"><i class="fa fa-cog"></i> Boutique</a></li>
        <li class="active">Badges</li>
      </ol>
    </section>

    <!-- Main content -->
    <section class="content">
      <!-- Info boxes -->

      <div class="row">
      <div class="col-md-12">
      <?PHP if($erreur == true) { ?>
      <div class="info-box bg-red" style="min-height: 0px;">
      <div class="info-box-content" style="margin-left: 0px;">
      <span class="info-box-text"><?PHP echo $message; ?></span>   
      </div>
      </div>
      <?PHP } ?>
      <?PHP if($post == true) { ?>
      <div class="info-box bg-green" style="min-height: 0px;">
      <div class="info-box-content" style="margin-left: 0px;">
      <span class="info-box-text"><?PHP echo $message; ?></span>   
      </div>
      </div>
      <?PHP } ?>
      </div>
      <div class="col-xs-12">
        <div class="box box-danger">
            <div class="box-header with-border">
              <h3 class="box-title">Different Width</h3>
            </div>
            <div class="box-body">
              <div class="row">
              <form method="post">
                <div class="col-xs-3">
                  <input type="text" class="form-control" name="code" placeholder="Code du badge ex: FR053">
                </div>
                <div class="col-xs-3">
                <select class="form-control" name="type">
                    <option value="BASIC">BASIC</option>
                    <option value="RARE">RARE</option>
                  </select>
                </div>
                <div class="col-xs-3">
                  <input type="text" class="form-control" name="prix" placeholder="Prix du badge ?">
                </div>
                <div class="col-xs-3">
                  <button type="submit" name="add" class="btn bg-olive btn-flat margin"><span class="fa fa-plus"></span> Ajouter le badge</button>
                </div>
              </form>
              </div>
            </div>
            <!-- /.box-body -->
          </div>
      </div>
      <div class="col-xs-12">
          <div class="box">
            <div class="box-header">
              <h3 class="box-title">Badge en vente</h3>
            </div>
            <!-- /.box-header -->
            <div class="box-body table-responsive no-padding">
              <table class="table table-hover">
                <tbody><tr>
                  <th>Badge</th>
                  <th>Code</th>
                  <th>Rareté</th>
                  <th>Prix</th>
                  <th></th>
                </tr>
                <?PHP if (isset($_POST['recherche'])) {
                  while($a = $SelectA->fetch()) {
                ?>
                <?PHP } } else {
                  $SelectA = $bdd->prepare('SELECT * FROM pluscms_boutique_badges ORDER BY id DESC');
                  $SelectA->execute();
                  while ($a = $SelectA->fetch()) {
                ?>
                <tr>
                  <td><img src="https://images.habbo.com/c_images/album1584/<?PHP echo htmlspecialchars(trim($a['code'])); ?>.gif"></td>
                  <td><?PHP echo htmlspecialchars_decode(trim($a['code'])); ?></td>
                  <td><?PHP echo htmlspecialchars_decode(trim($a['type'])); ?></td>
                  <td><?PHP echo htmlspecialchars(trim($a['prix'])); ?></td>
                  <td>
                  <form method="post">
                  <input name="id" style="display: none;" value="<?PHP echo htmlspecialchars(trim($a['id'])); ?>">
                  <button type="submit" name="supp" class="btn btn-app"><i class="fa fa-trash-o"></i>Supprimer</button>
                  </form>
                  </td>
                </tr>
                <?PHP } } ?>
              </tbody></table>
            </div>
            <!-- /.box-body -->
          </div>
          <!-- /.box -->
        </div>

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

  <footer class="main-footer">
    <div class="pull-right hidden-xs">
      <b>PlusCMS</b> 
    </div>
    <strong>Cette administration est conçu pour PlusCMS par Dodone.</strong>
  </footer>
  <!-- /.control-sidebar -->
  <!-- Add the sidebar's background. This div must be placed
       immediately after the control sidebar -->
  <div class="control-sidebar-bg"></div>

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

<!-- jQuery 3 -->
<script src="bower_components/jquery/dist/jquery.min.js"></script>
<!-- Bootstrap 3.3.7 -->
<script src="bower_components/bootstrap/dist/js/bootstrap.min.js"></script>
<!-- FastClick -->
<script src="bower_components/fastclick/lib/fastclick.js"></script>
<!-- AdminLTE App -->
<script src="dist/js/adminlte.min.js"></script>
<!-- Sparkline -->
<script src="bower_components/jquery-sparkline/dist/jquery.sparkline.min.js"></script>
<!-- jvectormap  -->
<script src="plugins/jvectormap/jquery-jvectormap-1.2.2.min.js"></script>
<script src="plugins/jvectormap/jquery-jvectormap-world-mill-en.js"></script>
<!-- SlimScroll -->
<script src="bower_components/jquery-slimscroll/jquery.slimscroll.min.js"></script>
<!-- ChartJS -->
<script src="bower_components/Chart.js/Chart.js"></script>
<!-- AdminLTE dashboard demo (This is only for demo purposes) -->
<script src="dist/js/pages/dashboard2.js"></script>
<!-- AdminLTE for demo purposes -->
<script src="dist/js/demo.js"></script>
<script src="bower_components/ckeditor/ckeditor.js"></script>
<script>
  $(function () {
    // Replace the <textarea id="editor1"> with a CKEditor
    // instance, using default configuration.
    CKEDITOR.replace('editor1')
    //bootstrap WYSIHTML5 - text editor
    $('.textarea').wysihtml5()
  })
</script>
</body>
</html>
