<?php

	session_start();
	
	$_SESSION['database']="local";
	
	if($_SESSION['database']=="local")
	  {
	     $db_host    = "localhost";
	     $db_user   = "root";
	     $db_pass   = "";
     	     $db_name   = "boutique";

	 }
	
	if($_SESSION['database']=="public")
	  {
  	     $db_host    = "sql2";
   	     $db_user   = "analogde";
 	     $db_pass   = "rainbow";
    	     //$db_type   = "mysql";
	     $db_name   = "analogde";
	 }

	
	$id = $_GET['id'];
	$table= $_GET['table'];
	
	if(isset($_POST['soumettre']) && $_POST['soumettre'] == "Enregistrer")
	  { 
  	    		$connexion = mysql_connect($db_host,$db_user,$db_pass); 
	 		mysql_select_db($db_name, $connexion);
			$sql = "SELECT * FROM categorie WHERE table_article = '".$table."' ";
 			$requete = mysql_query( $sql, $connexion ) or die('Erreur SQL !<br>'.$sql.'<br>'.mysql_error()); 
			$result = mysql_fetch_assoc($requete);
			$infos_descriptif = $result['descriptif'];
			
			$morceau = explode(",", $infos_descriptif);
		
			for($i=0; $i<=count($morceau)-1; $i++)
		  	{   // il s'agit d'un titre
		      	     if( preg_match('/TITRE/',$morceau[$i]))
			  	{
			           $champs = $morceau[$i];
			    	   $saisie = "none";
			        }
			        
			      else{ // il s'agit d'une ligne de description
		       	     	    $nom = "description" .$i;
		       	     	    $champs = $morceau[$i];
		       	     	    $saisie = $_POST[$nom]; 
		       	     	    if($saisie == "")
		       	     	      { $saisie = "vide";
		       	     	      } 	
		                 }   
		                 
		              if($i == 0)
				  { $chaine = $champs ." & " .$saisie ;
				  }	

				if($i != 0)
				  { $chaine = $chaine ."," .$champs ." & " .$saisie ;
				  }   
			}	
	     	    	
	     	    	$chaine = addslashes($chaine);
	     	    	
	     	    	$sql = "UPDATE $table SET descriptif = '$chaine' WHERE id_catalogue = '".$id."' ";
 		        $requete = mysql_query($sql);
	  
	  }

?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html dir="ltr" lang="en">

<head>

<title>Administration - En cours de développement</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="Pragma" content="no-cache">
  
<link rel="stylesheet" href="default.css" type="text/css">
  
</head>
<body>

<div id="header"><h1>Administration</h1>
<div class="membre">Vous Ãªtes connectÃ© en tant que <b><?php echo $_SESSION['admin_identifiant']; ?> </b></div>
</div>
 
		<?php include('menu.php'); ?>
 
		<div class="heading">Descriptif de l'article</div><br>
		
		<form action="" method="post" id="decrire" name="decrire" onsubmit="return toto();">
		  
		<table align="left" cellspacing="1" cellpadding="5" border="0" bgcolor="#D5D5D5">

<?php	


		$connexion = mysql_connect($db_host,$db_user,$db_pass); 
	 	mysql_select_db($db_name, $connexion);
		$sql = "SELECT * FROM $table WHERE id_catalogue = '".$id."' ";
 		$requete = mysql_query( $sql, $connexion ) or die('Erreur SQL !<br>'.$sql.'<br>'.mysql_error()); 
		$result = mysql_fetch_assoc($requete);

		$motif_titre = 'TITRE';
		$remplacement = "";


		// decoupe en sous element
		$morceau = explode(",", $result['descriptif']);

		for($i=0; $i<=count($morceau)-1; $i++)
		  {   // il s'agit d'un titre
		      if( preg_match('/TITRE/',$morceau[$i]))
			  {     $tab = str_replace($motif_titre, $remplacement, $morceau[$i]); 
			  	$extraire = explode("&", $tab);
			    	$str = strtoupper($extraire[0]);
			     
			     echo " <tr bgcolor=\"#F1F3F5\">
			    	     <td colspan=\"2\" class=\"h1\" align=\"left\"> $str</td>
			             </tr> ";
			   }
		      
		       else{ // il s'agit d'une ligne de description
		       	     $extraire = explode("&", $morceau[$i]);
		       	     $nom = "description" .$i;
		       	     echo "   <tr bgcolor=\"#FFFFFF\">
			   	      <td align=\"right\" valign=\"top\">$extraire[0] :</td>
			    	      <td align=\"left\" valign=\"middle\" colspan=\"1\">
			              <input type=\"text\" id=\"$nom\" name=\"$nom\" size=\"30\" maxlength=\"30\" value=$extraire[1] id=\"\">&nbsp;</td>
		                      </tr> ";
		           
		           
		           
		           }
		}	

?>


		<input type="hidden" name="valide" id="valide" value="">
		
		
		<tr bgcolor="#F1F3F5">
		<td colspan="2" align="center">
		<input type="submit" name="soumettre" value="Enregistrer" />
		</td>
		</tr>
		
		</table>

		</form>
		</div>

</body></html>