<?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";
	 }


	//$trouve_moi = ".";
  	// cherche la postion du '.'  
	//$position = strpos($image, $trouve_moi);
  	// enleve tout ce qui se trouve apres le '.' 
  	//$fichier_sans_extension = substr($image, 0, $position);

	
	
	  if(isset($_POST['valide']))
	      {
	     	        echo "****" .$_POST['valide'] ."****";
	     	        header("Location: pinpin.php");
	     	    
	     	  
	      }	    	

	
	  if(isset($_POST['soumettre']) && $_POST['soumettre'] == "Sauver")
	    {  
	    	
	        header("Location: pinpin.php");	
	       // insére une nouvelle catégorie
	       $nouvelle_categorie = $_POST['nom_categorie'];	
	       $connexion = mysql_connect($db_host,$db_user,$db_pass); 
	       mysql_select_db($db_name, $connexion);
	       $req = "INSERT INTO categorie (id,table_article,filtre,descriptif) VALUES('','$nouvelle_categorie','','')";
  	       mysql_query($req); 	  
	     
	       // on chercher les infos dans le descriptif de la categorie
	
		$connexion = mysql_connect($db_host,$db_user,$db_pass); 
	 	mysql_select_db($db_name, $connexion);
	 	$table = "lave_linge";
       	 	$requete = "SELECT * FROM categorie WHERE table_article = '".$table."' ";
	 	$result = mysql_query($requete);
	 	$datas = mysql_fetch_array($result);
	 	
	 	
	 	
		$infos_descriptif = $datas['descriptif'];
			
		//echo $infos_descriptif;		
			
		$morceau = explode(",", $infos_descriptif);
		
		$motif_titre = '(*)';
		$remplacement = "";
		
		//Métacaractères
		// regex
		//eregi("$cue";$ligne)
		
		$tableau = array();
		
		for($i=0; $i<=count($morceau)-1; $i++)
		  	{   // il s'agit d'un titre
		  		
		  		//if(preg_match("\*\",$morceau[$i]))
		  		
		  		//if (preg_match('`\$`', $morceau[$i]))
		  		// recherche le wildcard
		      	      if (preg_match('`\*`', $morceau[$i]))
			  	{  $str = str_replace($motif_titre, $remplacement, $morceau[$i]); 
			           echo $str;
			          echo "<br>";
			            $tableau[]= $str; 
			        }
		                 
		              
			}	
	     
	     	print_r($tableau);
	     	
	     	for($i=0; $i<=count($tableau)-1; $i++)
	           {  
	           	$champs = $tableau[$i] ." varchar(30) NOT NULL,";
	           	
	           	
	           }	
	        // faire le tri entre les options de filtrage et les infos 
	     
	     
	       // création de la table associée 	
	       
	       $requete= " CREATE TABLE $nouvelle_categorie (
  		 id tinyint(6) unsigned NOT NULL AUTO_INCREMENT,
  		 id_catalogue varchar(20) NOT NULL,
  		 designation varchar(50) NOT NULL DEFAULT '',
                 reference varchar(20) NOT NULL,
  		 marque varchar(20) NOT NULL,
  		 fournisseur varchar(20) NOT NULL,
  		 dispo varchar(20) NOT NULL,
  		 prix_ttc decimal(7,2) NOT NULL,
  		 prix_ht decimal(7,2) NOT NULL,
		 remise varchar(5,2) NOT NULL,
 		 tva decimal(5,2) NOT NULL,
   		 descriptif blob NOT NULL,
  		 stock int NOT NULL,
  		 status varchar(20) NOT NULL,
  		 image varchar(30) NOT NULL,
   		 heure varchar(50) NOT NULL,
		 date_calendrier varchar(50) NOT NULL,
  		 PRIMARY KEY (id)
		)" ;
	       
	        mysql_query($requete);
   		   
   		/* Supprimer la table*/
		//$requete = "DROP TABLE $table" ;

	       
	  	
	  }


		  

	  if( isset($_POST['selection_fichier']) && !empty($_POST['selection_fichier']) ) 
	   {    $nom = $_POST['selection_fichier'];
	   	 echo $nom ." boite";
	   	 echo "<script>initialize($nom)</script>";
	   }	


	if( isset($_SESSION['select_option']) && !empty($_SESSION['select_option']) ) 
	   {             echo "+++++++";
			 echo "<br>";
			 echo "+++++++";
			 echo "<br>";
			 print_r($_SESSION['select_option']);
			 echo "<br>";
			 echo "+++++++";
			 echo "<br>";
			 echo "+++++++";
			 echo "<br>";
	   }	


?>

		<!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="Content-Type" content="text/html; charset=iso-8859-1" />

  
		<link rel="stylesheet" href="default.css" type="text/css">

		<script type="text/javascript" src="ajax_select.js"></script>
		<script type="text/javascript" src="dynamic_select.js"></script>

	
  
		</head>
		
		<body>

		<div id="header"><h1>Administration</h1>
		<div class="membre">Vous Ãªtes connectÃ© en tant que <b><?php echo "cretin"; ?> </b></div>
		</div>		

		<?php include('menu.php'); ?>
		

		
		<div class="heading">Création d'une catégorie :</div>
		<div id="list">
		<table class="list">
	        <tr>
	        
	        
	        
	        
	        
	        <th align="center" width="1%">&nbsp;</th>
	        <th align="center" width="1%">&nbsp;</th>
	        <th align="center" width="1%">&nbsp;</th>
		<th width="*%" align="left">Nom du fichier</th>
		</tr>

<?php		
		$folder = "./";
		$dossier = opendir($folder);
	
		while($fichier = readdir($dossier))
	     	{
  	      		if($fichier != "." && $fichier != "..")
  	       		  {     
  	       		  	$extension=strrchr($fichier,'.');
				$extension=substr($extension,1) ;   
  	       		  	
  	       		  	if($extension == "txt")
    		 		  {	//$nomFichier = $folder."/".$Fichier;
    		 			//echo $nomFichier."<BR>";
		 			//echo $fichier."<BR>";
		 		
		 			echo "	
		       				<tr class=\"row2\" onmouseover=\"this.className='highlight'\" onmouseout=\"this.className='row2'\">
		       		
						<td align=\"center\">
						<a href=\"#\" onclick=\"initialize('$fichier')\">
						<img src=\"charger.png\" border=\"0\" alt=\"Charger\" title=\"Charger\" />
						</a>		
						</td>

						<td align=\"center\">
						<a href=\"edition.php\">
						<img src=\"../update.png\" border=\"0\" alt=\"Editer\" title=\"Editer\" />
						</a>
						</td>
		
						<td align=\"center\">
						<a href=\"envoi_email.php\">
						<img src=\"../email_send.png\" border=\"0\" alt=\"Effacer\" title=\"Effacer\" />
						</a>
						</td>

		 				<td align=\"left\" nowrap=\"nowrap\">$fichier</td> " ;
		 		}
  	       		  }
            	}
		
		
		
?>		
		
<?php
//		<div class="menu">
//		<img src="./images/add.png" alt="" title="" width="12" height="12" />&nbsp;
//		<a href="">Cr&eacute;er une cat&eacute;gorie</a>&nbsp;
//		<a href="?C1=CA&C2=CA&C3=insert">Editer une cat&eacute;gorie</a>&nbsp;
?>		
		
		
		
		</div>

		
		
		

		<form id="dynsel" name="dynsel" method="post" action="creer_categorie.php">

		

  		<table width="743" border="0" cellspacing="0" cellpadding="8">
    		
    				<br />
		<hr />

    		
    		<tr>
      		<td width="223">
        	<div align="center">
        	
        	
        	
          	<select name="select1" if="toolist"   size="10"  style="width:380px" style="height:250px"multiple onchange="selectoption();" >
            	<option></option>
          	</select>
        	</div></td>
		<td width="488">

         
		<input name="title" type="text" id="title"  value="" size="24"  />
		<input type="button" name="clear" value="X"  onclick='document.dynsel.title.value="";'  />
		<input type="button" name="add"  style="width:140px" value="Ajouter au select" onclick="addoption()"  />
		<br />
		<br  />
 
		<input type="button" name="del"  style="width:120px" value="Supprimer" onclick="deloption()"  />
		<span  style="margin-left:16px" >Supprimer l'option s&eacute;lectionn&eacute;e </span>

		<br />
		<br />

		<input type="button" name="del2"  style="width:120px" value="Remonter" onclick="moveup()"  />
		<span  style="margin-left:16px" >Remonter l'option dans la liste </span>
            
            	<br />
		<br />
            
		Nom du fichier :
		<input name="nom_fichier" type="text" id="nom_fichier"  value="" size="24"  /> 
		<br />
		<br  />
		
		Nom du la catégorie :
		<input name="nom_categorie" type="text" id="nom_categorie"  value="" size="24"  /> 
		<br />
		<br  />
		

		</td>
		</tr>
		
		
		</table>

  		<p>
  		<div align="center">
    		<input type="button" name="soumettre" value="Sauver" title="sauver" onclick="savelist(this)" />
    		</div>
  		</p>



		</form>

		<br />
		<hr />

<?php
/*
		<form action="creer_categorie.php" method="post" id="creer_categorie" name="creer_categorie" onsubmit="return mess();">
		  

		<table align="left" cellspacing="1" cellpadding="5" border="0" bgcolor="#D5D5D5" width="800">
		<tr bgcolor="#F1F3F5">
		<td colspan="2">&nbsp;</td>
		</tr>
		</tr>
		</td>
		</tr>
						
		<tr bgcolor="#FFFFFF">
		<td align="right" valign="top">Nom de la catégorie :</td>
		<td align="left" valign="middle" colspan="1">
		<input type="text" name="nom_categorie" size="30" maxlength="20" value="" id="nom_categorie" onChange="passe(this.value)" >&nbsp;</td>
		</tr>
		
		
		<input type="hidden" name="valide" id="valide" value="">
		
		<tr bgcolor="#FFFFFF">
		<td align="right" valign="top">Descriptif :</td>
		<td align="left" valign="middle" colspan="1">
		<input type="file" name="fichier_descriptif" />&nbsp;</td>
		</tr>
		
		<tr bgcolor="#FFFFFF">
		<td align="right" valign="top">Filtre :</td>
		<td align="left" valign="middle" colspan="1">
		<input type="file" name="fichier_filtre" />&nbsp;</td>
		</tr>
				
		<tr bgcolor="#F1F3F5">
		<td colspan="2" align="center">
		
		<input type="submit" name="soumettre" value="Valider" />
		
		
		</td>
		</tr>
		
		
		</table>
		</div>
		</div>
		
		</form>
	
*/
?>

</body></html>