<?php

	session_start();
	include('config_inc.php'); 
	include('menu.php'); 
	
	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'];
	
	$connexion = mysql_connect($db_host,$db_user,$db_pass); 
	mysql_select_db($db_name, $connexion);
	
	$requete = "SELECT * FROM $table WHERE id_catalogue='$id' ";
	$result = mysql_query($requete);
	$data = mysql_fetch_array($result);
	
	$id_catalogue = $data['id_catalogue'];
	$designation = $data['designation'];
	$reference = $data['reference'];
	$marque = $data['marque']; 
	$fournisseur = $data['fournisseur']; 
	$garantie = $data['garantie']; 
	$prix_ttc = $data['prix_ttc']; 
	$prix_ht = $data['prix_ht']; 
	$remise = $data['remise']; 
	
	$tab_remise = explode(" ", $remise);
	//echo $tab_remise[0]; //= type 
	//echo $tab_remise[1]; //= montant
	
	$tva = $data['tva']; 
	$dispo = $data['dispo']; 
	$stock = $data['stock']; 
	$status = $data['status'];  
	
	$descriptif = $data['descriptif']; 
	$remarques = $data['remarques'];  
	$liens = $data['liens'];  
	
	   
	if(isset($_POST['valide']) && $_POST['valide'] == "ok")
 	  {									
					$id_catalogue = $_POST['id_catalogue'];
					$designation = $_POST['designation']; 
					$reference = $_POST['reference']; 
					$marque = $_POST['marque']; 
					$fournisseur = $_POST['fournisseur']; 
					$garantie = $_POST['garantie']; 
					$dispo = $_POST['dispo'];
					
					switch($dispo)
  					{
					  case 1 :
					          $dispo  = "24H";
					    	  break;
					  case 2 :
					          $dispo = "48H";
					    	  break;
					  case 3 :
					          $dispo = "72H";
					    	  break;  	  		  
					}	
					 
					$prix_ttc = $_POST['prix_ttc']; 
					$prix_ht = $_POST['prix_ht']; 					
					// remise
					$remise = $_POST['remise'];
					
						
					
					switch($remise)
  					{
					  case 1 :
					          
					          $remise = "aucune" ." 0.00"; 
					    	  
					    	  break;
					  case 2 :
					          
					          $remise = "pourcent" ." " .$_POST['valeur_remise'];
					    	  break;
					  case 3 :
					          $remise = "euro" ." " .$_POST['valeur_remise'];
					    	  break;  	  
					    	  		  
					}
					
					$tva = $_POST['tva'];	
					
					switch($tva)
  					{
					  case 1 :
					          $tva  = 19.60;
					    	  break;
					  case 2 :
					          $tva = 5.50;
					    	  break;		  
					}
					
					$stock = $_POST['stock'];
					$status = $_POST['status']; 
					
					switch($status)
  					{
					  case "a" :
					          $status  = "actif";
					    	  break;
					  case "c" :
					          $status = "hors catalogue";
					    	  break;		  
					}
							
					$descriptif = $_POST['descriptif']; 
					
	
					
					//$descriptif = addslashes($descriptif);		
															
					$remarques = $_POST['remarques']; 
					//$remarques = addslashes($remarques);	
					
					$liens = $_POST['liens']; 	
					//$liens = addslashes($liens);	
					
					
					
					
					$heure = date("H:i");
					$date = date("d-m-Y"); 
					
					

					/*$element = $_POST['categorie'];
					$requete = "SELECT * FROM categorie WHERE id='$element' ";
	   		        	$result = mysql_query($requete);
		                	$data = mysql_fetch_array($result);
					$table = $data['table'];*/

					//$connexion = mysql_connect($db_host,$db_user,$db_pass); 
					//mysql_select_db($db_name, $connexion);



		$sql = "UPDATE $table SET 
			id_catalogue = '$id_catalogue' ,
			designation = '$designation' ,
			reference = '$reference' ,
			marque = '$marque' ,
			fournisseur = '$fournisseur' ,
			garantie = '$garantie' ,
			dispo = '$dispo' ,
			prix_ttc = '$prix_ttc' ,
			prix_ht = '$prix_ht' ,
			remise = '$remise' ,
			tva = '$tva' ,
			stock = '$stock' ,
			status = '$status' ,
			remarques = '$remarques' ,
			descriptif = '$descriptif' ,
			liens = '$liens' ,
			heure = '$heure' ,
			date = '$date' WHERE id_catalogue='$id' ";

		//$sql = "UPDATE $table SET marque = '$marque' WHERE id_catalogue='$id' ";

//mysql_query("UPDATE membres SET email='anthony@fai.fr' , passe='zbdkdi' WHERE pseudo='test'");

	 //création de la requête SQL:
	 /*$sql = "INSERT INTO refrigerateur ( id, marque, id_catalogue, fournisseur, modele, dispo , prix_ttc, prix_ht, remise, tva, designation, stock, date, heure, status) 
 	  VALUES('', '$marque', '$id_catalogue', '$fournisseur' ,  '$modele', '$dispo' , '$prix_ttc', '$prix_ht','$remise','$tva','$designation','$stock','$date','$heure','$status')"; 
 */
    	$requete = mysql_query($sql);
       // header("Location: aaaaliste_article.php");
	
	$descriptif =  stripslashes($descriptif);
	$remarques =  stripslashes($remarques);
	$liens =  stripslashes($liens);

	   }	  
?>




<?php

$config['toolbar'] = array(
	array( 'Source', '-', 'Bold', 'Italic', 'Underline', 'Strike' , 'StrikeThrough','-','Subscript','Superscript'),
	array('Undo','Redo','-','Find','Replace','-','SelectAll','RemoveFormat'),
	array('Styles','Format','Font','FontSize'),
	array('TextColor','BGColor'),
	array('JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock'),
	array('NumberedList','BulletedList','OrderedList','UnorderedList','-','Outdent','Indent'),

);

$config['skin'] = 'v2';

$config['width'] = 600;			
$config['length'] = 200;	
$config['resize_enabled'] = false;	


include_once "ckeditor.php";
$CKEditor = new CKEditor();
$CKEditor->basePath = '../ckeditor/';

				$descriptif = strip_tags($descriptif);
				$descriptif = html_entity_decode($descriptif);
				$descriptif = preg_replace('~&#x([0-9a-f]+);~ei', 'chr(hexdec("\\1"))', $descriptif);
				$descriptif = preg_replace('~&#([0-9]+);~e', 'chr("\\1")', $descriptif);
				$descriptif = preg_replace('(\n|\r|\t)',' ',$descriptif);
				$descriptif = preg_replace('/\s\s+/', ' ', $descriptif); 

				$initialValue = $descriptif;






?>

<!--
		<!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">
  
		<link rel="stylesheet" href="default.css" type="text/css">
		<link rel="stylesheet" href="onglet.css" type="text/css" media="screen" />
		<link rel="stylesheet" href="theme.css" type="text/css">
		
		<script type="text/javascript" src="javascript.js"></script>
  
		</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>		
-->
		
		<script type="text/javascript" src="javascript.js"></script>

		<div class="heading">Edition du produit</div>

		<form action="" method="post" id="ajouter_produit" name="ajouter_produit" onsubmit="return descriptif();">

		<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">ID catalogue :</td>
		<td align="left" valign="middle" colspan="1">
		<input type="text" name="id_catalogue" size="70" maxlength="20" value="<?php echo $id_catalogue; ?>" id="" >&nbsp;</td>
		</tr>
		
		<input type="hidden" name="valide" id="valide" value="">
		
		<tr bgcolor="#FFFFFF">
		<td align="right" valign="top">Désignation :</td>
		<td align="left" valign="middle" colspan="1">
		<input type="text" name="designation" size="30" maxlength="40" value="<?php echo $designation; ?>" id="">&nbsp;</td>
		</tr>
		
		<tr bgcolor="#FFFFFF">
		<td align="right" valign="top">R&eacute;f&eacute;rence :</td>
		<td align="left" valign="middle" colspan="1">
		<input type="text" name="reference" size="30" maxlength="40" value="<?php echo $reference; ?>" id="">&nbsp;</td>
		</tr>
		
		<tr bgcolor="#FFFFFF">
		<td align="right" valign="top">Marque :</td>
		<td align="left" valign="middle" colspan="1">
		<input type="text" name="marque" size="30" maxlength="40" value="<?php echo $marque; ?>" id="">&nbsp;</td>
		</tr>
		
		<tr bgcolor="#FFFFFF">
		<td align="right" valign="top">Fournisseur :</td>
		<td align="left" valign="middle" colspan="1">
		<input type="text" name="fournisseur" size="30" maxlength="40" value="<?php echo $fournisseur; ?>" id="">&nbsp;</td>
		</tr>
		
		<tr bgcolor="#FFFFFF">
		<td align="right" valign="top">Garantie :</td>
		<td align="left" valign="middle" colspan="1">
		<input type="text" name="garantie" size="30" maxlength="40" value="<?php echo $garantie; ?>" id="">&nbsp;</td>
		</tr>
		
		<tr bgcolor="#FFFFFF">
		<td align="right">Disponibilité :</td>
		<td align="left">
		
		
		<?php
					
				
					if($dispo == "24H")
  				           {
					          echo "<select name=\"dispo\" size=\"1\">
					                <option value=\"1\"  selected=\"selected\">24H</option>
						  	<option value=\"2\">48H</option>
						  	<option value=\"3\">72H</option>
						  	</select> ";
					   }
				
					 if($dispo == "48H")
  				           {
					          echo "<select name=\"dispo\" size=\"1\">
					                <option value=\"1\">24H</option>
						  	<option value=\"2\" selected=\"selected\">48H</option>
						  	<option value=\"3\">72H</option>
						  	</select> ";
					   }
					   
					   
					 if($dispo == "72H")
  				           {
					          echo "<select name=\"dispo\" size=\"1\">
					                <option value=\"1\">24H</option>
						  	<option value=\"2\">48H</option>
						  	<option value=\"3\" selected=\"selected\">72H</option>
						  	</select> ";
					   }  
					 		
		
		?>
		
		</td>
		</tr>
		
		<tr bgcolor="#FFFFFF">
		<td align="right" valign="top">Prix TTC:</td>
		<td align="left" valign="middle" colspan="1">
		<input type="text" name="prix_ttc" size="10" maxlength="10" value="<?php echo $prix_ttc; ?>" id="">&nbsp;<b>&euro;</b>
		</td>
		</tr>
		
		<tr bgcolor="#FFFFFF">
		<td align="right" valign="top">Prix HT:</td>
		<td align="left" valign="middle" colspan="1">
		<input type="text" name="prix_ht" size="10" maxlength="10" value="<?php echo $prix_ht; ?>" id="">&nbsp;<b>&euro;</b>
		</td>
		</tr>
		
		<tr bgcolor="#FFFFFF">
		<td align="right">Remise :</td>
		<td align="left">
		<select name="remise" size="1">
		
		<?php
					
				
					if($tab_remise[0] == "aucune")
  				           { echo " <option value=\"1\" selected=\"selected\">Aucune</option>
						    <option value=\"2\">En % sur le prix TTC</option>
						    <option value=\"3\">En &euro; sur le prix TTC</option> ";
					   }
					if($tab_remise[0] == "pourcent")
  				           { echo " <option value=\"1\">Aucune</option>
						    <option value=\"2\" selected=\"selected\">En % sur le prix TTC</option>
						    <option value=\"3\">En &euro; sur le prix TTC</option> ";
					   }
					if($tab_remise[0] == "euro")
  				           { echo " <option value=\"1\">Aucune</option>
						    <option value=\"2\">En % sur le prix TTC</option>
						    <option value=\"3\" selected=\"selected\">En &euro; sur le prix TTC</option> ";
					   }      
					   
					   
		
		?>
		
		
		
		</select>&nbsp;
		
		<input type="text" name="valeur_remise" size="7" maxlength="12" value="<?php echo $tab_remise[1]; ?>" />
		<!-- <b class="green">Laissez vide ce champ si pas de remise</b> -->
		</td>
		</tr>
		
		<tr bgcolor="#FFFFFF">
		<td align="right">TVA :</td>
		<td align="left">
		<select name="tva" size="1">
		
		<?php
					
				
					if($tva == 5.50)
  				           { echo " <option value=\"1\" selected=\"selected\">5.50 % </option>
						    <option value=\"2\">19.60 %</option> ";
					   }
					if($tva == 19.60)
  				           { echo " <option value=\"1\">5.50 %</option>
					            <option value=\"2\" selected=\"selected\">19.60 %</option> ";
					   }   
		
		?>
		
		
		
		</select></td>
		</tr>
		<tr bgcolor="#FFFFFF">
		<td align="right" valign="top">Descriptif :</td>
		<td align="left" valign="middle" colspan="1">


<!--<textarea name="descriptif" rows="12" cols="90" id="">-->
		<?php 
		
//		$descriptif = str_replace('<b />', '\n', $descriptif);
//		echo $descriptif;
		$CKEditor->editor("editor1", $initialValue, $config);
		 ?>
		 
		 
		 
		
<!--		</textarea> -->
		</tr>
			
		<tr bgcolor="#FFFFFF">
		<td align="right" valign="top">Stock :</td>
		<td align="left" valign="middle" colspan="1">
		<input type="number" name="stock" size="5" maxlength="5" value="<?php echo $stock; ?>" id="">&nbsp;</td>
		</tr>
		
			
		<tr bgcolor="#FFFFFF">
		<td align="right">Status :</td>
		<td align="left">
		<select name="status">
		
		<?php
					
				
					if($status == "actif")
  				           { echo " <option value=\"a\" selected=\"selected\">Actif</option>
						    <option value=\"c\">Hors catalogue</option> ";
					   }
					if($status == "hors catalogue")
  				           { echo " <option value=\"a\">Produit actif</option>
					            <option value=\"c\" selected=\"selected\">Hors catalogue</option> ";
					   }   
		
		?>
		
		
		</select>
		</td>
		</tr>
			
			

		<tr bgcolor="#FFFFFF">
		<td align="right" valign="top">Remarques :</td>
		<td align="left" valign="middle" colspan="1"><textarea name="remarques" rows="12" cols="90" id="">
		<?php 
		
		$remarques = str_replace('<b />', '\n', $remarques);
		echo $remarques; ?>

		</textarea>&nbsp;</td>
		</tr>
			
			
		<tr bgcolor="#FFFFFF">
		<td align="right" valign="top">Liens :</td>
		<td align="left" valign="middle" colspan="1"><textarea name="liens" rows="12" cols="90" id="">
		<?php 
		
		$liens = str_replace('<b />', '\n', $liens);
		echo $liens; ?>
		
		</textarea>&nbsp;</td>
		</tr>	
				
		<tr bgcolor="#F1F3F5">
		<td colspan="2" align="center">
		<input type="submit" value="Valider" />
		
		
		</td>
		</tr>
		
		
		</table>
		</div>
		</div>
		
		</form>

		</body>
		</html>
		
<?php
//	phpinfo();
//get_magic_quotes_gpc
//mysql_real_escape_string
//htmlspecialchars() 
//mysql_escape_string

//$descriptif = nl2br($descriptif); 
		//echo htmlentities($descriptif);

//$descriptif = strtr($descriptif, "\", "");
	/*if(preg_match('`\x`', $descriptif))
 	 {  $descriptif = str_replace($motif_filtre, $remplacement, $descriptif); 
	 }*/
	//$descriptif =  stripslashes($descriptif);

?>		