<?php
if(!defined('INDEX')) { header('Location: ../'); exit; }
$page = 'bugs';
$titre = 'Rapports de bugs';

if (!empty($_POST['page']) && !empty($_POST['description'])) {
	$pages = $_POST['page'];
	$description = $_POST['description'];
	$pseudo = $queryUser['pseudo'];
	$time = time();

	$bdd->connexion();
	$bdd->escape($pages);
	$bdd->escape($description);
	$bdd->query("INSERT INTO $table_bug (pseudo, temps, page, description) VALUES('$pseudo', '$time', '$pages', '$description');");
	$bdd->deconnexion();
	header('Location: ?p=bugs');
	exit;
}
elseif (isset($_GET['a']) && $_GET['a'] == 'del' && isset($_GET['i']) && $sess->values['auth_level'] > 2) {
	$i = $_GET['i'];
	$bdd->connexion();
	$bdd->escape($i);
	$bdd->query("DELETE FROM $table_bug WHERE id = $i;");
	$bdd->deconnexion();
	header('Location: ?p=bugs');
	exit;
}

$bdd->connexion();
$bugs = $bdd->query("SELECT id, pseudo, temps, page, description FROM $table_bug ORDER BY id DESC");
$bdd->deconnexion();
$TEMP_bugs = array();
for ($i = 0; $i < $bdd->num_rows; $i++) {
	$TEMP_bugs[] = array('<a href="?p=envoyer&d='.$bugs[$i]['pseudo'].'">'.$bugs[$i]['pseudo'].'</a>', date("d/m/y h:m:s", $bugs[$i]['temps']), $bugs[$i]['page'], nl2br(htmlspecialchars(str_replace('\\\'', '\'', $bugs[$i]['description']))), $bugs[$i]['id']);
}
$template->assign('bugs', $TEMP_bugs);
?>