<?php
#=
/****************************************************************************
Copyright 2002, Daniel Deycard, Jacques Messines, Alain Pomirol
(CATICE Académie de Bordeaux)

This file is part of GiBii/Melia.

GiBii/Melia is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

GiBii/Melia is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with GiBii/Melia; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

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

include("../include/vars_adm.php");
include("../include/util.inc.php");
include("../include/utiljs.php");
include("../sadmin/table_index.inc.php");

opensession('Sadmin',false);
if ($sess_login=='admstats') {
	aneantir_session();
	goto("./index.php");
	}
connecte($host, $user, $mdp,$db);


?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
<title>Vérification des index</title>
<link rel="stylesheet" href="../include/general.css" />
</head><body class="arial_sadmin">

<?php
set_time_limit(600);
foreach($liste as $table => $indexes) {
	if (!table_dans_base($table,$db)) continue; //notamment pour la table divers, créée à la volée 
    //retrouver les index
    $aff1=$aff2='';
    $res=mysql_query("SHOW INDEX FROM $table");
    while($row=mysql_fetch_array($res)) {
        print ".";
        $nom=$row['Key_name'];
        //les supprimer
        if ($nom=='PRIMARY') continue; //on ne supprime pas les PRIMARY
        if ($row['Seq_in_index']!=1) continue; //on ne supprime l'index que la première fois (sinon, erreur)
        $suffixe="INDEX $nom";
        $aff1.="$nom, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ";
        query("ALTER TABLE $table DROP $suffixe");
        }
    //les recréer
    for ($i=0;$i<count($indexes);$i++) {
        print ".";
        $index=$indexes[$i];
        $nom=$index['nom'];
        $colonnes=$index['col'];
        $unique=$index['unique'];
        $aff2.="[$nom] : <b>$colonnes</b> <i>$unique</i> ,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ";
        query("ALTER TABLE $table ADD $unique INDEX $nom $colonnes");
        }
    if ($aff1 || $aff2) print "<h3>Table $table</h3>";
    if ($aff1) print '<b>Suppressions : </b>'.$aff1."<br />\n";
    if ($aff2) print '<b>Créations : </b>'.$aff2."<br />\n";
    superflush();
    }
mysql_free_result($res);
print "<br />";
retour('../sadmin/choix_verif.form.php');
?>
</body></html>