<?php 
require_once(dirname(__DIR__, 1) . '/config.php');
require_once(BASE_PATH . '/db/idl_connect.php');
echo '<meta charset="utf-8" />';
		
if(isset($_SESSION['user_droits'])) {
	if($_SESSION['user_droits'][5]!="2")
	{
		echo '<p class="noaccess">'.NOMODULE.'<br><a href="../index.php">'.ACCUEIL.'</a></p>';
	}
	else {
		?><style type="text/css">
		#mda9 { background-color: #fff; }
		#mda9 td { border: 3px #086A87 solid; }
		#mda8 td { border: 0; }
		</style><?php
		echo DATAC_VIDE1.'
		<form method="POST" action="database.php?page=supprimer">'.DATAC_VIDE2;
		
		if(!isset($_POST['suppr'])&&!isset($_POST['suppr_confirm'])) {
			echo '<input class="bouton boutdb" type="submit" value="'.DATAC_VIDE3.'" name="suppr" />';
		}
		
		echo '</form>';
		
		if(isset($_POST['suppr'])) {
			echo '<p class="signal">'.DATAC_VIDE4.'</p>
			<form method="POST" action="database.php?page=supprimer">
			<input type="checkbox" name="input_save" id="input_save" checked /><label for="input_save"> '.DATAC_VIDE5.'</label><br> <br>';
			$result_tables = mysqli_query($bdd,"SHOW TABLE STATUS LIKE '".$prefix."_%'");
			$_SESSION['nb_tables'] = mysqli_num_rows($result_tables);
			if($result_tables && $result_tables->num_rows) {
				while($obj_table = mysqli_fetch_assoc($result_tables)) {
					echo '<input type="hidden" id="'.$obj_table['Name'].'" name="'.$obj_table['Name'].'" checked />';
				}
			}
			echo '<input type="hidden" name="hidden_save" id="input_save" checked />';
			echo '<input class="bouton boutdb" type="submit" value="'.DATAC_VIDE6.'" name="suppr_confirm" />
			</form>';
		}
		if(isset($_POST['suppr_confirm'])) {
			if(isset($_POST['input_save'])) {
				$_SESSION['save_auto']=1;
				include('./db/backup.php');
			}

			mysqli_query($bdd,"DELETE FROM ".$prefix."_eleves");
			mysqli_query($bdd,"DELETE FROM ".$prefix."_savele");
			mysqli_query($bdd,"DELETE FROM ".$prefix."_seqeleves");
			mysqli_query($bdd,"DELETE FROM ".$prefix."_groupele");
			
			echo DATAC_VIDE7.'
			
			<p style="font-size:1.5em;padding-left:100px;"><b><a href="database.php">'.BACK.'</a></b></p>';
		}
	}	
	
}
else {
	include('include/noaccess.php');
	echo '<br><a href="../index.php">'.ACCUEIL.'</a></p>';
}
?>
