Location: PHPKode > projects > EmploiNet : a timetable web manager > EmploiNet/v0.8.0/Administration/ResetBase.php3
<?
/* Auteur : F. Nolot */
include("../BarreDeMenu.php3");
include("../Session/security.php");

// Entete
buildHeader("<font color=red> ATTENTION:</font><BR> Effacement d&eacute;finitif <br>de la base de donn&eacute;es <br> ");
// Verification de la session
$autorisation_list[0]=0; // Administrateur
$user_type = validateSession($id_session);
if ($user_type == -1 || !security($id_session,$autorisation_list)) print("Accès refusé");
else
{
  echo "<NOSCRIPT>";
  echo "<br><br><br><center><b>Vous devez activer javascript pour un fonctionnement correct!</b></center>";
  echo "</NOSCRIPT>";
  echo "<script LANGUAGE=\"JavaScript\">\n";
  /*		echo " var newwin;\n";
		echo "function ok() {\n";
		echo "	alert(\"Effacement effectué\");\n";
		echo "}\n";
		echo "function fermer() {\n";
		echo "	if (newwin.document) {newwin.close();}\n";
		echo "}\n";
		echo "function PopupCentrer(page,largeur,hauteur,options) {\n";
		echo "	var top=(screen.height-hauteur)/2;\n";
		echo "  var left=(screen.width-largeur)/2;\n";
		echo "  newwin = window.open(page,\"confirmer\",\"top=\"+top+\",left=\"+left+\",width=\"+largeur+\",height=\"+hauteur+\",\"+options);\n";
		echo " 	newwin.document.writeln(\"<HTML><HEAD><TITLE>Confirmation ?</TITLE></HEAD><BODY>\")\n";
		echo "  newwin.document.writeln('<center>Confirmez-vous l\'effacement de la base ?')\n";
		echo "  newwin.document.writeln('<form name=\"form2\" action=\"ResetBase.php3\" method=POST\">')\n";
		echo "  newwin.document.writeln('<input type=hidden name=\"confirmation\" value=\"confirmation ok\">')\n";
		echo "  newwin.document.writeln('<input type=hidden name=\"id_session\" value=\"$id_session\">')\n";
		echo "  newwin.document.writeln('<input type=button value=\"Confirmer\" onClick=\"window.opener.ok();window.opener.fermer()\">')\n";
		echo "  newwin.document.writeln('<input type=button value=\"Annuler\" onClick=\"window.opener.fermer()\">')\n";
		echo "  newwin.document.writeln('</form></center>')\n";
		echo "  newwin.document.close()\n";
		echo "	newwin.focus();\n";
		echo "}\n";*/
  echo "function open(v) {\n";
  echo "  document.form1.confirmer.value = v;\n";
  echo "	document.form1.submit();\n";
  echo "}\n";
  echo "</script>\n";
		
  // Barre de menu
  buildMenuBar($id_session,$user_type,"ResetBase.php3",false);
  // Determination du user_id
  $user_id = getUserID($id_session);
  // Ouverture de la connexion avec la base de donnees
  $connection = openConnection($databaseName);

  //*****************************************

    //**********Validation de la suppression********
    if (isset($passwd)) {
      $user_id=getUserID($id_session);
      $connection=openConnection(session);
      $QueryResult = mysql_query("SELECT * FROM user WHERE id='$user_id' and password='$passwd'",$connection);
      if ($QueryResult!=0 && mysql_num_rows($QueryResult)>0) { $confirmation=5; }
      else { $confirmation=0; $confirmer=0;}
    }
			
    if((isset($confirmation))&&($confirmation==5)){
      echo "<script LANGUAGE=\"JavaScript\">\n";
      echo "	alert(\"Effacement effectué\");";
      echo "</script>";
      $connection=openConnection($databaseName);
      //**********Valeur par defaut de la base*******
	mysql_query("TRUNCATE appartient ;");
	mysql_query("TRUNCATE associer ;");
	mysql_query("TRUNCATE associerchoixprojet ;");
	mysql_query("TRUNCATE absence ;");
	mysql_query("TRUNCATE absent ;");
	mysql_query(" TRUNCATE `associermatiereagroupematiere` ;");
	mysql_query(" TRUNCATE `assurer` ;");
	mysql_query(" TRUNCATE `avoirunenote` ;");
	mysql_query(" TRUNCATE `cgu` ;");
	mysql_query(" TRUNCATE `departement` ;");
	mysql_query(" TRUNCATE `diplome` ;");
	mysql_query(" TRUNCATE `dispenser` ;");
	mysql_query(" TRUNCATE `diviser` ;");
	mysql_query(" TRUNCATE `etudiant` ;");
	mysql_query(" TRUNCATE `fichiers` ;");
	mysql_query(" TRUNCATE `fichiers_destinataire` ;");
	mysql_query(" TRUNCATE `gerer` ;");
	mysql_query(" TRUNCATE `gestionnaire` ;");
	mysql_query(" TRUNCATE `global` ;");
	mysql_query(" TRUNCATE `grade` ;");
	mysql_query(" TRUNCATE `groupe` ;");
	mysql_query(" TRUNCATE `groupeetudiant` ;");
	mysql_query(" TRUNCATE `groupematiere` ;");
	mysql_query(" TRUNCATE `id` ;");
	mysql_query(" TRUNCATE `indisponibilite` ;");
	mysql_query(" TRUNCATE `indisponible` ;");
	mysql_query(" TRUNCATE `inscrit` ;");
	mysql_query(" TRUNCATE `joursferies` ;");
	mysql_query(" TRUNCATE `matiere` ;");
	mysql_query(" TRUNCATE `moyenne` ;");
	mysql_query(" TRUNCATE `moyennepromotion` ;");
	mysql_query(" TRUNCATE `news` ;");
	mysql_query(" TRUNCATE `news_destinataire` ;");
	mysql_query(" TRUNCATE `note` ;");
	mysql_query(" TRUNCATE `periode` ;");
	mysql_query(" TRUNCATE `plagehoraire` ;");
	mysql_query(" TRUNCATE `planifie` ;");
	mysql_query(" TRUNCATE `planifiegroupe` ;");
	mysql_query(" TRUNCATE `planifiepromotion` ;");
	mysql_query(" TRUNCATE `professeur` ;");
	mysql_query(" TRUNCATE `projet` ;");
	mysql_query(" TRUNCATE `promotion` ;");
	mysql_query(" TRUNCATE `reparti` ;");
	mysql_query(" TRUNCATE `repartigroupe` ;");
	mysql_query(" TRUNCATE `repartipromotion` ;");
	mysql_query(" TRUNCATE `requiert` ;");
	mysql_query(" TRUNCATE `salle` ;");
	mysql_query(" TRUNCATE `suivi` ;");
	mysql_query(" TRUNCATE `suivipargroupe` ;");
	mysql_query(" TRUNCATE `suiviparpromotion` ;");
	mysql_query(" TRUNCATE `suivisimultanement` ;");
	mysql_query(" TRUNCATE `suivrevacances` ;");
	mysql_query(" TRUNCATE `typebulletin` ;");
	mysql_query(" TRUNCATE `typegroupe` ;");
	mysql_query(" TRUNCATE `typenote` ;");
	mysql_query(" TRUNCATE `typesalle` ;");
	mysql_query(" TRUNCATE `typeseance` ;");
	mysql_query(" TRUNCATE `vacances` ;");
	mysql_query(" TRUNCATE `validerprojet` ;");

	mysql_query("INSERT INTO `diplome` VALUES (1, 'DEUG')");
	mysql_query("INSERT INTO `diplome` VALUES (2, 'DUT')");
	mysql_query("INSERT INTO `diplome` VALUES (3, 'Licence')");
	mysql_query("INSERT INTO `diplome` VALUES (4, 'Maîtrise')");
	mysql_query("INSERT INTO `diplome` VALUES (5, 'MST')");
	mysql_query("INSERT INTO `diplome` VALUES (6, 'DESS')");
	mysql_query("INSERT INTO `diplome` VALUES (7, 'DEA')");
	mysql_query("INSERT INTO `diplome` VALUES (8, 'Doctorat')");
	mysql_query("INSERT INTO `diplome` VALUES (9, 'DU')");
	mysql_query("INSERT INTO `diplome` VALUES (10, 'DRT')");
	mysql_query("INSERT INTO `diplome` VALUES (11, 'DEUST')");
	mysql_query("INSERT INTO `diplome` VALUES (12, 'Bac + 1')");
	mysql_query("INSERT INTO `diplome` VALUES (13, 'DUT')");

	mysql_query("INSERT INTO `grade` VALUES (1, 'ATER')");
	mysql_query("INSERT INTO `grade` VALUES (2, 'PRAG')");
	mysql_query("INSERT INTO `grade` VALUES (3, 'Moniteur CIES')");
	mysql_query("INSERT INTO `grade` VALUES (4, 'Etudiant')");
	mysql_query("INSERT INTO `grade` VALUES (5, 'Vacataire')");
	mysql_query("INSERT INTO `grade` VALUES (7, 'Maître de conférences')");
	mysql_query("INSERT INTO `grade` VALUES (8, 'Maître de conférences hors classe')");
	mysql_query("INSERT INTO `grade` VALUES (9, 'Professeur 2ème classe')");
	mysql_query("INSERT INTO `grade` VALUES (10, 'Professeur 1ère classe')");
	mysql_query("INSERT INTO `grade` VALUES (11, 'Professeur hors classe')");
	mysql_query("INSERT INTO `grade` VALUES (12, 'IATOS')");

	mysql_query("INSERT INTO `id` VALUES (0, 0, 0, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0, 12, 0, 0, 0, 0, 3, 0, 6, 0)");

	mysql_query("INSERT INTO `global` VALUES (36, 2003)");

	mysql_query("INSERT INTO `typegroupe` VALUES (6, 'Option')");
	mysql_query("INSERT INTO `typegroupe` VALUES (5, 'Examen')");
	mysql_query("INSERT INTO `typegroupe` VALUES (4, 'TP')");
	mysql_query("INSERT INTO `typegroupe` VALUES (3, 'TDm')");
	mysql_query("INSERT INTO `typegroupe` VALUES (2, 'TD')");
	mysql_query("INSERT INTO `typegroupe` VALUES (1, 'CM')");
    
	mysql_query("INSERT INTO `typeseance` VALUES (5, 'Examen')");
	mysql_query("INSERT INTO `typeseance` VALUES (4, 'TP')");
	mysql_query("INSERT INTO `typeseance` VALUES (3, 'TDm')");
	mysql_query("INSERT INTO `typeseance` VALUES (2, 'TD')");
	mysql_query("INSERT INTO `typeseance` VALUES (1, 'CM')");

	mysql_query("INSERT INTO `typesalle` VALUES (1, 'Amphi')");
	mysql_query("INSERT INTO `typesalle` VALUES (2, 'TD')");
	mysql_query("INSERT INTO `typesalle` VALUES (3, 'TP')");			

	$connection=openConnection(session);
	mysql_query("TRUNCATE `appartient`");
	mysql_query("TRUNCATE `rand`");
	mysql_query("TRUNCATE `session`");
	mysql_query("TRUNCATE `typeuser`");
	mysql_query("TRUNCATE `user`");
			
	mysql_query("INSERT INTO `appartient` (`login`, `id_type_user`, `id`) VALUES ('Administrateur', 0, 0)");
	mysql_query("INSERT INTO `typeuser` (`id_type_user`, `libelle`) VALUES (0, 'Administrateur')");
	mysql_query("INSERT INTO `typeuser` (`id_type_user`, `libelle`) VALUES (1, 'Professeur')");
	mysql_query("INSERT INTO `typeuser` (`id_type_user`, `libelle`) VALUES (2, 'Etudiant')");
	mysql_query("INSERT INTO `typeuser` (`id_type_user`, `libelle`) VALUES (3, 'Gestionnaire')");
	mysql_query("INSERT INTO `typeuser` (`id_type_user`, `libelle`) VALUES (4, 'Directeur de departement')");
	mysql_query("INSERT INTO `user` (`login`, `password`, `id_type_user`, `id`) VALUES ('Administrateur', 'toto', 0, 0)");
			
			
    }			
			
    // --- Presentation 
    if ($confirmer != 1) {
      print ("<center>Voulez-vous effacer la base de donnée et revenir à une base par défaut ?\n");
      print("<FORM name=\"form1\" action=\"ResetBase.php3\" method=POST>\n");
      print("<INPUT TYPE=HIDDEN NAME=\"id_session\" VALUE=\"$id_session\">\n");
      print("<INPUT TYPE=HIDDEN NAME=\"confirmer\" value=\"-1\"");
      print("<a href=\"javascript:open(1)\"><INPUT type=button value=\"Oui\"></a>\n");
      print("<a href=\"../index.php?id_session=$id_session\"><INPUT type=button value=\"Non\"></a>\n");
      print("</FORM></center>\n");
    }
    else {
      if ($confirmation!="confirmation ok") {
	print ("<center>Confirmation de l'effacement<br>Saisissez votre mot de passe et confirmer ?\n");
	print("<FORM name=\"form1\" action=\"ResetBase.php3\" method=POST>\n");
	print("<INPUT TYPE=HIDDEN NAME=\"id_session\" VALUE=\"$id_session\">\n");
	print("<INPUT TYPE=HIDDEN NAME=\"confirmer\" value=\"-1\">");
	print("Password : <INPUT TYPE=password NAME=\"passwd\"><br>");
	print("<INPUT type=submit value=\"Confirmer\">\n");
	print("<a href=\"javascript:open(0)\"><INPUT type=button value=\"Annuler\"></a>\n");
	print("</FORM>\n");
      }
    }
}
buildEndOfPage();
?>
Return current item: EmploiNet : a timetable web manager