<?php
/****************************************************************************************
SMI (Services Maintenance Interventions) est une gestion libre de maintenance et de SAV

Version 0.9.9

Copyright (C) 2006-2009  Sylvain FATOME
This program 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.

This program 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 this program
(in the directory docs); 
if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 
Boston, MA  02110-1301, USA.

Contact : galawa@free.fr

Web : http://smitst.homelinux.com
****************************************************************************************/

session_start(); 
if (!isset($_SESSION["lng"])) $_SESSION["lng"]="fr";
include_once("../lng/".$_SESSION["lng"].".inc.php"); // Paramètres de language
include_once("../inc/config.inc.php");
include_once("../inc/func_log.inc.php");
if (CheckURLLog(FALSE)==FALSE) header("Location: ../index.php");
if (CheckNivLog("9")==FALSE) header("Location: ../index.php");
include_once("../inc/func.inc.php");
include_once("../inc/func_date.inc.php");
include_once("../inc/func_geo.inc.php");
include_once("../inc/func_txt.inc.php");
Archivelog(@$_SESSION["code_log"]);

$typmaint = strip_tags(trim($_GET['td']));

$titre = $titlein_maint_mysql;

$maintok=FALSE;

if (($typmaint >= 1) AND ($typmaint <= 3))
{
	$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
	mysql_select_db(DBNAME);

	// Création du tableau des noms de tables
	$tables=array();
	$rech="SHOW TABLES FROM ".DBNAME;
	$rs = mysql_query($rech)or die(mysql_error());
	while ($row = mysql_fetch_row($rs))
	{
		$Tables[] = $row[0];
	}

	// Lancement de l'opération
	switch ($typmaint)
	{
		case 1 :
				$rech = "CHECK TABLE ";
			break;

		case 2 :
				$rech = "OPTIMIZE TABLE ";
			break;
			
		case 3 :
				$rech = "REPAIR TABLE ";
			break;
			
		default : break;
	}
	
	foreach($Tables as $key=>$value)
	{
		$rech .= " `$value`,";
	}
	$rech = substr($rech,0,strlen($rech)-1);
	$rs = mysql_query($rech)or die(mysql_error());

	// Création du tableau de résultats
	$tab_result=array();
	while ($row = mysql_fetch_array($rs, MYSQL_ASSOC))
	{
		$tab_result[$row["Table"]]=$row["Msg_text"];
	}

	// Validation de la maintenance
	switch ($typmaint)
	{
		case 1 :
				$msg = $txt_div_verifok;
				$maintok=TRUE;
			break;

		case 2 :
				$msg = $txt_div_optimok;
				$maintok=TRUE;
			break;
			
		case 3 :
				$msg = $txt_div_repok;
				$maintok=TRUE;
			break;
			
		default : break;
	}

	mysql_close($conn);
}
else
{
	header("Location: ../index.php");
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>SMI - <?PHP echo $title_esp_prive; ?> : <?PHP echo $title_maint; ?></title>

<!-- Feuille de style pour les affichages courants -->
<link href="../css/smi.css" rel="stylesheet" type="text/css">

<!-- Feuille de style & Script pour le menu -->

<script language="JavaScript" src="../jscript/coolmenus/coolmenus4.js"></script>

<!-- Scripts Javascript pour fenêtres -->
<script language="JavaScript" src="../jscript/fen.js"></script>

</head>

<body>

<?php 
include_once("../inc/entete.inc.php"); 
?>
<p align="center"> <span class="titrepage"><?PHP echo $titre ?></span></p>
<p align="center">&nbsp;</p>
<p align="center">
<?PHP if ($retourliste==FALSE)
	echo '<span class="alerte1">';
else
	echo '<span class="annot_std_gras">';
?>
<?PHP echo $msg ?>
</span>
</p>

<table class="Mtable" border="0" width="100%" cellpadding="0" cellspacing="0">     
<th><?PHP echo $tab_ent_table; ?></th>
<th><?PHP echo $tab_ent_result; ?></th>
<?PHP
		$i=0;
		foreach ($tab_result as $key => $value)
		{			
			// Couleurs alternées
			if($i%2 == 0)  
			   echo "<tr onmouseover=\"this.className='TRsel'\" onmouseout=\"this.className='TRalter1'\" class=\"TRalter1\">\n";
			else
			   echo "<tr onmouseover=\"this.className='TRsel'\" onmouseout=\"this.className='TRalter2'\" class=\"TRalter2\">\n";
			 echo "<td width=\"75%\">".$key."</td>\n";
			 echo "<td>".$value."</td>\n";
			 echo "</tr>";
			 $i++;
		}
?>
		</table>
		<p align="center">
		<input name="nul" type="button" class="bton_std" id="nul" value="<?PHP echo $but_lnkidx; ?>" onClick="javascript:; self.location.href=('index.php');"> 
		</p>
<?php 
include_once("pied.php");
?>
