<?
/*
 * MySQL Web Interface Version 0.8
 * -------------------------------
 * Developed By SooMin Kim (smkim@popeye.snu.ac.kr)
 * License : GNU Public License (GPL)
 * Homepage : http://popeye.snu.ac.kr/~smkim/mysql
 */

 
// OPTIMIZE TABLE
// REPAIR TABLE
// ANALYZE TABLE


 
	/**
	* Affiche la liste des societes
	* @access	public
	*/
	function listTables() {
		global $BDD, $PHP_SELF, $TBL, $gconnexionid, $db, $color1, $bdd_titre ;
		$dbc = new DB_Ganesha ;
	
		Title($bdd_titre['titre']);
		
		put('<table align="middle" width="100%" border="0" cellspacing="0" cellpadding="0">');
		put('<tr><td valign="top" width="50%">');
			SubTitle("BDD Ganesha : ".$BDD['name']);
			BeginBorder("90%",$color1);	
			put('<table align="middle" width="100%" border="0" cellspacing="0" cellpadding="5">');
			put('<tr>');
			put("<td><b>".$bdd_titre['nombdd']."</b></td>");
			put('<td><b>'.$bdd_titre['actions'].'</b></td>');		
			put('</tr>');
			put('<tr bgcolor="'.GetColor(0).'">');
			put("<td>".$BDD['name']."</td>");
			$schema	= '<a class="student" href="'.$PHP_SELF.'?action='.SHEMADB.'&connexion='.$gconnexionid.'">'.IMG_SCHEMA.'</a>';
			$dump 	= '<a class="student" href="'.$PHP_SELF.'?action='.DUMPDB.'&connexion='.$gconnexionid.'">'.IMG_DUMP.'</a>';		
			$pdf 	= '<a class="student" target="_blank" href="'.$PHP_SELF."?connexion=".$gconnexionid."&pdf_file=".$BDD['name'].'">'.IMG_PDF.'</a>';
			put('<td>'.$schema.' '.$dump.' '.$pdf.'</td>');
			put('</tr>');
			put('</table>');
			CloseBorder();
			BR(2);
			/*
			SubTitle("Restauration des donnees ");
			put('<form name="bdd" action="post">');
			put('&nbsp;&nbsp;<input type="hidden" class="bouton" name="MAX_FILE_SIZE" value="400000">');
			put('&nbsp;&nbsp;<input type="file" class="bouton" name="fichier" size="30" maxlength="250">');
			put('&nbsp;&nbsp;<input type="button" class="bouton" name="OK" value="Valider" onclick="ValiderFormMsg(this.form);">');	
			put ('</form>');			
			*/
			SubTitle($bdd_titre['forum']);
			BeginBorder("90%",$color1);	
			put('<table align="middle" width="100%" border="0" cellspacing="0" cellpadding="5">');
			put('<tr>');
			put("<td>&nbsp;</td>");
			put("<td><b>".$bdd_titre['nomtable']."</b></td>");
			put('<td><b>'.$bdd_titre['actions'].'</b></td>');		
			put('</tr>');
			$i = 0 ;
			$tablename = $TBL['forums'];
			$dbc->query("SELECT COUNT(*) FROM ".$tablename);
			$dbc->next_record();
			$nb = $dbc->f(0);
			$url = $PHP_SELF."?connexion=".$gconnexionid."&tablename=".$tablename."&action=" ;
			put('<tr bgcolor="'.GetColor($i).'">');
			put('<td>'.($i+1).'</td>');
			put('<td>'.$tablename.' ['.$nb.']</td>');
			$schema		= '<a class="student" href="'.$url.VIEWSHEMA.'">'.IMG_SCHEMA.'</a>';	
			$viewdata 	= '<a class="student" href="'.$url.VIEWDATA.'">'.IMG_DATA.'</a>';
			$dump 		= '<a class="student" href="'.$url.DUMPTABLE.'">'.IMG_DUMP.'</a>';		
			put('<td>'.$schema.' '.$viewdata.' '.$dump.'</td>');	
			put('</tr>');
			$db->query("SELECT id FROM ".$TBL['forums']);
			$i++;
			while ( $db->next_record() ) {
				$tablename = "g".$db->f(0);
				$dbc->query("SELECT COUNT(*) FROM ".$tablename);
				$dbc->next_record();
				$nb = $dbc->f(0);
				$url = $PHP_SELF."?connexion=".$gconnexionid."&tablename=".$tablename."&action=" ;
				put('<tr bgcolor="'.GetColor($i).'">');
				put('<td>'.($i+1).'</td>');
				put('<td>'.$tablename.' ['.$nb.']</td>');
				$schema		= '<a class="student" href="'.$url.VIEWSHEMA.'">'.IMG_SCHEMA.'</a>';			
				$viewdata 	= '<a class="student" href="'.$url.VIEWDATA.'">'.IMG_DATA.'</a>';
				$dump 		= '<a class="student" href="'.$url.DUMPTABLE.'">'.IMG_DUMP.'</a>';		
				put('<td>'.$schema.' '.$viewdata.' '.$dump.'</td>');	
				put('</tr>');
				$tablename.= "_bodies";
				$i++;
				$dbc->query("SELECT COUNT(*) FROM ".$tablename);
				$dbc->next_record();
				$nb = $dbc->f(0);
				$url = $PHP_SELF."?connexion=".$gconnexionid."&tablename=".$tablename."&action=" ;
				put('<tr bgcolor="'.GetColor($i).'">');
				put('<td>'.($i+1).'</td>');
				put('<td>'.$tablename.' ['.$nb.']</td>');
				$schema		= '<a class="student" href="'.$url.VIEWSHEMA.'">'.IMG_SCHEMA.'</a>';
				$viewdata 	= '<a class="student" href="'.$url.VIEWDATA.'">'.IMG_DATA.'</a>';
				$dump 		= '<a class="student" href="'.$url.DUMPTABLE.'">'.IMG_DUMP.'</a>';		
				put('<td>'.$schema.' '.$viewdata.' '.$dump.'</td>');	
				put('</tr>');
				$i++;
			}
			echo "</table>";
			CloseBorder();			
		put('</td>');
		put('<td width="50%">');
			$table = array_values($TBL);
			$num = count($table) - 1 ;
			SubTitle($bdd_titre['liste']." Ganesha [".$num."]");
			BeginBorder("90%",$color1);	
			put('<table align="middle" width="100%" border="0" cellspacing="0" cellpadding="5">');
			put('<tr>');
			put("<td>&nbsp;</td>");
			put("<td><b>".$bdd_titre['nomtable']."</b></td>");
			put('<td><b>'.$bdd_titre['actions'].'</b></td>');		
			put('</tr>');
			for( $i = 0; $i < $num; $i++ ) {
				$tablename = $table[$i];
				$db->query("SELECT COUNT(*) FROM ".$tablename);
				$db->next_record();
				$nb = $db->f(0);
				$url = $PHP_SELF."?connexion=".$gconnexionid."&tablename=".$tablename."&action=" ;
				put('<tr bgcolor="'.GetColor($i).'">');
				put('<td>'.($i+1).'</td>');
				put('<td>'.$tablename.' ['.$nb.']</td>');
				$schema		= '<a class="student" href="'.$url.VIEWSHEMA.'">'.IMG_SCHEMA.'</a>';			
				$viewdata 	= '<a class="student" href="'.$url.VIEWDATA.'">'.IMG_DATA.'</a>';
				$dump 		= '<a class="student" href="'.$url.DUMPTABLE.'">'.IMG_DUMP.'</a>';
				$vide 		= '<a class="student" href="#">'.IMG_VIDER.'</a>';
				put('<td>'.$schema.'&nbsp;&nbsp;'.$viewdata.'&nbsp;&nbsp;'.$dump.'&nbsp;&nbsp;'.$vide.'</td>');			
				put('</tr>');
			}
			echo "</table>";
			CloseBorder();
			BR();
		put('</td></tr>');
		put('<tr><td valign="top" width="50%">');
/*
			SubTitle($bdd_titre['module']);
			BeginBorder("90%",$color1);	
			put('<table align="middle" width="100%" border="0" cellspacing="0" cellpadding="5">');
			put('<tr>');
			put("<td>&nbsp;</td>");
			put("<td><b>".$bdd_titre['nomtable']."</b></td>");
			put('<td><b>'.$bdd_titre['actions'].'</b></td>');		
			put('</tr>');
			$db->query("SELECT module_id FROM ".$TBL['list_module']);
			$i = 1 ;
			while ( $db->next_record() ) {
				$tablename = $TBL['module'] ;
				$dbc->query("SELECT COUNT(*) FROM ".$TBL['module']." WHERE id_module=".$db->f(0));
				$dbc->next_record();
				$nb = $dbc->f(0);
				$url = $PHP_SELF."?connexion=".$gconnexionid."&tablename=".$tablename."&action=" ;
				put('<tr bgcolor="'.GetColor($i).'">');
				put('<td>'.($i++).'</td>');
				put('<td>'.$tablename.' ['.$nb.']</td>');
				$schema		= '<a href="'.$url.VIEWSHEMA.'">'.IMG_SCHEMA.'</a>';		
				$viewdata 	= '<a href="'.$url.VIEWDATA.'">'.IMG_DATA.'</a>';
				$dump 		= '<a href="'.$url.DUMPTABLE.'">'.IMG_DUMP.'</a>';		
				put('<td>'.$schema.' '.$viewdata.' '.$dump.'</td>');	
				put('</tr>');
			}
			echo "</table>";
			CloseBorder();
		put('</td>');
		put('<td width="50%">');
			SubTitle($bdd_titre['forum']);
			BeginBorder("90%",$color1);	
			put('<table align="middle" width="100%" border="0" cellspacing="0" cellpadding="5">');
			put('<tr>');
			put("<td>&nbsp;</td>");
			put("<td><b>".$bdd_titre['nomtable']."</b></td>");
			put('<td><b>'.$bdd_titre['actions'].'</b></td>');		
			put('</tr>');
			$i = 0 ;
			$tablename = $TBL['forums'];
			$dbc->query("SELECT COUNT(*) FROM ".$tablename);
			$dbc->next_record();
			$nb = $dbc->f(0);
			$url = $PHP_SELF."?connexion=".$gconnexionid."&tablename=".$tablename."&action=" ;
			put('<tr bgcolor="'.GetColor($i).'">');
			put('<td>'.($i+1).'</td>');
			put('<td>'.$tablename.' ['.$nb.']</td>');
			$schema		= '<a href="'.$url.VIEWSHEMA.'">'.IMG_SCHEMA.'</a>';	
			$viewdata 	= '<a href="'.$url.VIEWDATA.'">'.IMG_DATA.'</a>';
			$dump 		= '<a href="'.$url.DUMPTABLE.'">'.IMG_DUMP.'</a>';		
			put('<td>'.$schema.' '.$viewdata.' '.$dump.'</td>');	
			put('</tr>');
			$db->query("SELECT id FROM ".$TBL['forums']);
			$i++;
			while ( $db->next_record() ) {
				$tablename = "g".$db->f(0);
				$dbc->query("SELECT COUNT(*) FROM ".$tablename);
				$dbc->next_record();
				$nb = $dbc->f(0);
				$url = $PHP_SELF."?connexion=".$gconnexionid."&tablename=".$tablename."&action=" ;
				put('<tr bgcolor="'.GetColor($i).'">');
				put('<td>'.($i+1).'</td>');
				put('<td>'.$tablename.' ['.$nb.']</td>');
				$schema		= '<a href="'.$url.VIEWSHEMA.'">'.IMG_SCHEMA.'</a>';			
				$viewdata 	= '<a href="'.$url.VIEWDATA.'">'.IMG_DATA.'</a>';
				$dump 		= '<a href="'.$url.DUMPTABLE.'">'.IMG_DUMP.'</a>';		
				put('<td>'.$schema.' '.$viewdata.' '.$dump.'</td>');	
				put('</tr>');
				$tablename.= "_bodies";
				$i++;
				$dbc->query("SELECT COUNT(*) FROM ".$tablename);
				$dbc->next_record();
				$nb = $dbc->f(0);
				$url = $PHP_SELF."?connexion=".$gconnexionid."&tablename=".$tablename."&action=" ;
				put('<tr bgcolor="'.GetColor($i).'">');
				put('<td>'.($i+1).'</td>');
				put('<td>'.$tablename.' ['.$nb.']</td>');
				$schema		= '<a href="'.$url.VIEWSHEMA.'">'.IMG_SCHEMA.'</a>';
				$viewdata 	= '<a href="'.$url.VIEWDATA.'">'.IMG_DATA.'</a>';
				$dump 		= '<a href="'.$url.DUMPTABLE.'">'.IMG_DUMP.'</a>';		
				put('<td>'.$schema.' '.$viewdata.' '.$dump.'</td>');	
				put('</tr>');
				$i++;
			}
			echo "</table>";
			CloseBorder();
*/
		put('</td></tr>');
		put('</table>');
		BR(2);
		Footer();
		BR(2);		
	}


	/**
	* Affiche la liste des societes
	* @access	public
	*/
	function viewProperties($tablename) {
		global $color1,$bdd_titre ;
		$db = new DB_Ganesha ;
		$prop = array();
		
		$db->query("SHOW fields FROM ".$tablename);
		$prop['num'] = $db->num_rows();
		
		$found = false ;
		$db->query("show table status");
		while ( $db->next_record() ) {
			if ( $db->f("Name") == $tablename ) {
				$prop['Type'] = $db->f('Type') ;
				$prop['Row_format'] = $db->f('Row_format') ;
				$prop['Rows'] = $db->f('Rows') ;
				$prop['Avg_row_length'] = $db->f('Avg_row_length') ;
				$prop['Data_length'] = $db->f('Data_length') ;
				$prop['Max_data_length'] = $db->f('Max_data_length') ;
				$prop['Index_length'] = $db->f('Index_length') ;
				$prop['Data_free'] = $db->f('Data_free') ;
				$prop['Auto_increment'] = $db->f('Auto_increment') ;
				$prop['Create_time'] = $db->f('Create_time') ;
				$prop['Update_time'] = $db->f('Update_time') ;
				$prop['Check_time'] = $db->f('Check_time') ;
				$prop['Create_options'] = $db->f('Create_options') ;
				$prop['Comment'] = $db->f('Comment') ;
				break;
			}
		}
		BeginBorder("70%",$color1);
		put('<table align="center" width="100%" border="0" cellspacing="1" cellpadding="5">');
		put('<tr bgcolor="'.GetColor(0).'">');
		put('<td>'.$bdd_titre['format'].'</td>');
		put('<td>&nbsp;'.$prop['Row_format'].'</td>');
		put('</tr>');
		put('<tr bgcolor="'.GetColor(1).'">');
		put('<td>'.$bdd_titre['nbrchamp'].'</td>');
		put('<td>&nbsp;'.$prop['num'].'</td>');
		put('</tr>');
		put('<tr bgcolor="'.GetColor(2).'">');
		put('<td>'.$bdd_titre['enreg'].'</td>');
		put('<td>&nbsp;'.$prop['Rows'].'</td>');
		put('</tr>');
		put('<tr bgcolor="'.GetColor(3).'">');
		put('<td>'.$bdd_titre['autoincr'].'</td>');
		put('<td>&nbsp;'.$prop['Auto_increment'].'</td>');
		put('</tr>');
		put('<tr bgcolor="'.GetColor(4).'">');
		put('<td>'.$bdd_titre['longueur'].'</td>');
		put('<td>&nbsp;'.$prop['Avg_row_length'].' octets</td>');
		put('</tr>');
		put('<tr bgcolor="'.GetColor(5).'">');
		put('<td>'.$bdd_titre['donnee'].'</td>');
		put('<td>&nbsp;'.$prop['Data_length'].' octets</td>');
		put('</tr>');
		put('<tr bgcolor="'.GetColor(6).'">');
		put('<td>'.$bdd_titre['index'].'</td>');
		put('<td>&nbsp;'.$prop['Index_length'].' octets</td>');
		put('</tr>');
		put('</table>');
		CloseBorder();
	}

	/**
	* Affiche la liste des societes
	* @access	public
	*/
	function viewSchema($all=false) {
		global $tablename, $PHP_SELF, $color1, $gconnexionid, $bdd_titre ;
		$db = new DB_Ganesha ;
	
		$db->query("SHOW fields FROM ".$tablename);
		$num = $db->num_rows();
	
		if ( ! $all ) {
			Title($bdd_titre['titreview']);
		}
		SubTitle($bdd_titre['table']." ".$tablename);
	
		$url = $PHP_SELF."?connexion=".$gconnexionid."&pdf_file=".$tablename;
		$pdf = '<a class="student" href="'.$url.'" target="_blank" class="student">'.IMG_PDF.'</a>';	
		$url = $PHP_SELF."?connexion=".$gconnexionid."&tablename=".$tablename."&action=".VIEWDATA  ;
		$data = '<a class="student" href="'.$url.'" target="_blank" class="student">'.IMG_DATA.'</a>';	
		$url = $PHP_SELF."?connexion=".$gconnexionid."&tablename=".$tablename."&action=".DUMPTABLE  ;
		$dump = '<a class="student" href="'.$url.'" target="_blank" class="student">'.IMG_DUMP.'</a>';		
		put('&nbsp;&nbsp;'.$pdf.'&nbsp;'.$data.'&nbsp;'.$dump);
		
		put('<table width="95%" align="center" border="0" cellspacing="0" cellpadding="0">');
		put('<tr valign="top" ><td width="40%">');
			viewProperties($tablename);
		put('</td>');
		put('<td width="60%">');
			BeginBorder("90%",$color1);
			put('<table align="middle" width="100%" border="0" cellspacing="1" cellpadding="5">');
			echo "<tr>\n";
			echo "<th>&nbsp;</th>\n";
			echo "<th>".$bdd_titre['field']."</th>\n";
			echo "<th>".$bdd_titre['type']."</th>\n";
			echo "<th>".$bdd_titre['null']."</th>\n";
			echo "<th>".$bdd_titre['key']."</th>\n";
			echo "<th>".$bdd_titre['default']."</th>\n";
			echo "<th>".$bdd_titre['extra']."</th>\n";
			echo "</tr>\n";
	
			for( $i = 0; $i < $num; $i++ ) {
				$db->next_record();
				put('<tr bgcolor="'.GetColor($i).'">');
				echo "<td>&nbsp;".($i+1)."</td>\n";
				echo "<td>&nbsp;".$db->f("Field")."</td>\n";
				echo "<td>&nbsp;".$db->f("Type")."</td>\n";
				echo "<td>&nbsp;".$db->f("Null")."</td>\n";
				echo "<td>&nbsp;<b>".$db->f("Key")."</b></td>\n";
				echo "<td>&nbsp;".$db->f("Default")."</td>\n";
				if ( $db->f("Extra") == "auto_increment" ) {
					put('<td>&nbsp;<font color="red">'.$db->f("Extra").'</font></td>');
				} else {
					echo "<td>&nbsp;".$db->f("Extra")."</td>\n";
				}
				echo "</tr>\n";
			}
			echo "</table>\n";
			CloseBorder();
		put('</td></tr>');
		put('</table>');
		BR(2);
		if ( ! $all ) {
			BackWindow();
		}
	}

	/**
	* Affiche la liste des societes
	* @access	public
	*/	
	function viewSchemaDB() {
		global $TBL, $color1, $tablename, $bdd_titre ;
		$db = new DB_Ganesha ;
	
		Anchor("Top");
		Title($bdd_titre['titreview']);
		BR();
		SubTitle($bdd_titre['liste'],"400");
		BR();
		BeginBorder("90%",$color1);
		put('<table width="100%" border="0" cellspacing="0" cellpadding="0" bgcolor="#FFFFFF">');
		put('<tr><td valign="top" width="50%">');
			$table = array_values($TBL);
			$nb = count($table) - 1 ;
			SubTitle($bdd_titre['liste']." Ganesha");
			// Liste des tables
			// tables ganesha
			UL();
			for( $j = 0; $j < $nb; $j++ ) {
				$tablename = $table[$j];
				LI();
				LinkAnchor($tablename,$tablename);
				_LI();
			}
			_UL();
		put ('</td>');
/*		
		put ('<td valign="top" width="33%">');
			SubTitle($bdd_titre['module']);
			UL();
			// tables des modules
			$db->query("SELECT module_id FROM ".$TBL['list_module']);
			while ( $db->next_record() ) {
				$tablename = "module_".$db->f(0);
				LI();
				LinkAnchor($tablename,$tablename);
				_LI();
			}
			_UL();
		put ('</td>');
*/		
		put ('<td valign="top" width="50%">');
			SubTitle($bdd_titre['forum']);
			UL();
			// tables des forums
			$tablename = $TBL['forums'];
			LI();
			LinkAnchor($tablename,$tablename);
			_LI();
			$db->query("SELECT id FROM ".$TBL['forums']);
			while ( $db->next_record() ) {
				$tablename = "g".$db->f(0);
				LI();
				LinkAnchor($tablename,$tablename);
				_LI();
				$tablename.= "_bodies";
				LI();
				LinkAnchor($tablename,$tablename);
				_LI();
			}
			_UL();
		put ('</td>');
		put ('</tr>');
		put ('</table>');
		CloseBorder();
	
		// Affichage des shemas
		// tables ganesha
		BR(2);
		SubTitle($bdd_titre['table']." Ganesha","400");
		for( $j = 0; $j < $nb; $j++ ) {
			$tablename = $table[$j];
			BR(2);
			Anchor($tablename);
			viewSchema(true);
			LinkAnchor("Top","Top",true);
		}
		BR(2);
	
		// tables des modules
		/*
		SubTitle($bdd_titre['module'],"400");
		$db->query("SELECT module_id FROM ".$TBL['list_module']);
		while ( $db->next_record() ) {
			$tablename = "module_".$db->f(0);
			BR(2);
			Anchor($tablename);
			viewSchema(true);
			LinkAnchor("Top","Top",true);
		}
		BR(2);
		*/
		
		// tables des forums
		Title($bdd_titre['forum']);
		$db->query("SELECT id FROM ".$TBL['forums']);
		while ( $db->next_record() ) {
			$tablename = "g".$db->f(0);
			Anchor($tablename);
			viewSchema(true);
			LinkAnchor("Top","Top",true);
			$tablename.= "_bodies";
			BR(2);
			Anchor($tablename);
			viewSchema(true);
			LinkAnchor("Top","Top",true);
		}
	
		BackWindow();
	}

	/**
	* Affiche la liste des societes
	* @access	public
	*/	
	function viewData( $queryStr ) {
		global $tablename, $PHP_SELF, $orderby, $gconnexionid, $db, $color1, $bdd_titre;
	
		Title($bdd_titre['titredata']);
		BR(2);
		SubTitle("Table : ".$tablename);
	
		if ( $orderby != '' ) {
			$orderby = " ORDER BY ".$orderby ;
		}
		$db->query("SELECT * FROM ".$tablename.$orderby);
		$row = $db->num_rows();
	
		if( $row == 0 ) {
			echo $bdd_titre['nodata'];
			return;
		}
		
		$ret = $db->metadata($tablename,true);
	
		BeginBorder("80%",$color1);
		put('<TABLE align="middle" width="100%" border="0" cellspacing="0" cellpadding="2">');
		echo "<tr>\n";
		for( $i = 0; $i < $ret['num_fields']; $i++ ) {
			$ret[$i]["name"];
			put('<td>');
			$url = $PHP_SELF."?connexion=".$gconnexionid."&action=".VIEWDATA."&tablename=".$tablename."&";
			put('<a class="title2" href="'.$url.'orderby='.$ret[$i]["name"].'">'.$ret[$i]["name"].'</a>');
			echo "</td>\n";
		}
		echo "</tr>\n";
	
		$i = 0 ;
		while($db->next_record()) {
			put('  <tr bgcolor="'.GetColor($i++).'">');
			for( $j = 0; $j < $ret['num_fields']; $j++ ) {
				$data = $db->f($j) ;
				if( strlen( $data ) > 20 )
					$data = substr( $data, 0, 20 ) . "...";
				$data = htmlspecialchars( $data );
				echo "<td>\n";
				echo "$data\n";
				echo "</td>\n";
			}
			echo "</tr>\n";
		}
		echo "</table>\n";
		CloseBorder();
		BackWindow();
	
	}

	/**
	* Affiche la liste des societes
	* @access	public
	*/	
	function dump() {
		global $PHP_SELF, $USERNAME, $PASSWORD, $BDD, $tablename;
	
		if( ACTION == DUMPTABLE )
			$filename = $tablename;
		else
			$filename = $BDD['name'];
	
		header("Content-disposition: filename=$filename.sql");
		header("Content-type: application/octetstream");
		header("Pragma: no-cache");
		header("Expires: 0");
	
		$pResult = mysql_query( "show variables" );
		while( 1 ) {
			$rowArray = mysql_fetch_row( $pResult );
			if( $rowArray == false ) break;
			if( $rowArray[0] == "basedir" )
				$bindir = $rowArray[1]."bin/";
		}
	
		passthru( $bindir."mysqldump --user=".$USERNAME." --password=".$PASSWORD." ".$BDD['name']." ".$tablename );
	}


/*******************************************************************************
 **  PHPMYADMIN + Modif Bug sur le '#'                                        **
 *******************************************************************************/
 	/**
	* Affiche la liste des societes
	* @access	public
	*/
	function split_sql($sql) {
	    $sql = trim($sql);
	    if(substr($sql,1,1)=="#") {
	        $sql = ereg_replace("#[^\n]*\n", "", $sql);
	    }
	
	    $buffer = array();
	    $ret = array();
	    $in_string = false;
	
	    for($i=0; $i<strlen($sql)-1; $i++) {
	         if($sql[$i] == ";" && !$in_string) {
	            $ret[] = substr($sql, 0, $i);
	            $sql = substr($sql, $i + 1);
	            $i = 0;
	        }
	
	        if($in_string && ($sql[$i] == $in_string) && $buffer[0] != "\\") {
	             $in_string = false;
	        }
	        elseif(!$in_string && ($sql[$i]=="\"" || $sql[$i]=="'") && (!isset($buffer[0]) || $buffer[0]!="\\")){
	             $in_string = $sql[$i];
	        }
	        if(isset($buffer[1])) {
	            $buffer[0] = $buffer[1];
	        }
	        $buffer[1] = $sql[$i];
	     }
	
	    if(!empty($sql)){
	        $ret[] = $sql;
	    }
	    return($ret);
	}
	
/*******************************************************************************
 ** Creation de tables dans la bdd a partir de fichiers contenant des rqt SQL **
 ** Le fichier est passe en parametre : $sql_file                             **
 *******************************************************************************/	
	/**
	* Affiche la liste des societes
	* @access	public
	*/ 
	function InsertTable($sql_file){
	    $myfile = @fopen($sql_file,"r") 
			or die("<b>Can't open file : ".$sql_file." </b>".Retour()); 
		$sql_query = addslashes(fread($myfile, filesize($sql_file)));
		fclose($myfile);
		$pieces  = split_sql($sql_query);
		$nb=count($pieces);
		for ($i=0; $i<$nb; $i++){
			  $pieces[$i] = stripslashes(trim($pieces[$i]));
			  if(!empty($pieces[$i]) && $pieces[$i] != "#"){
				  $result = @mysql_query ( $pieces[$i]) 
					  or die("<b>Erreur insertion dans la base de donnees</b><br>
							  Rqt = ".$pieces[$i]." ".Retour()); 
			  }
		}
	}

?>