<?php
session_start();
include('../connexion.php');
if (!isset($_SESSION['celest']))
{
	header ('Location: index.php');
}
if (isset($_GET['W9mvyDvFWE5']))
{
	$chaiz=addslashes($_GET['W9mvyDvFWE5']);
	$id=addslashes($_GET['QYtgoGbhhd']);
	$active=$chaiz;
	
	$sql3='SELECT * FROM type WHERE lib_type="'.$chaiz.'"';
	$reponse3=$bdd-> query($sql3) or die('Erreur SQL !<br />'.$sql3.'<br />'.mysql_error());
	$data3=$reponse3->fetch();
	$id_table=$data3[0];

	$sql='SELECT * FROM information, type WHERE information.id_type=type.id_type AND id_information="'.$id.'"';
	$reponse=$bdd-> query($sql) or die('Erreur SQL !<br />'.$sql.'<br />'.mysql_error());
	$data=$reponse->fetch();
	$id_table=$data['id_type'];
	include('tete.php');
	if($developpeur==3 and $data['id_user']!=$_SESSION['celest'])
	{
		header('Location: gestionnaire-table.php?W9mvyDvFWE5='.$chaiz);
	}
	?>
    <link rel="stylesheet" type="text/css" href="style/style_admin.css" />
</head>
<body>
    <div id="wrapper">
    	<?php include('menu_admin.php'); ?>
        <div id="page-wrapper">
            <div class="row">
                <div class="col-lg-2 col-md-1"></div>
                <div class="col-lg-8 col-md-10 col-sm-11 col-xs-12" id="administration">
                    <div id="titro_admin">Modification <?php echo $chaiz ?></div>
                    <div id="afficher_admin">
                        <a class="btn btn-primary" href="ajouter-table.php?W9mvyDvFWE5=<?php echo $chaiz ?>">
                            <i class="fa fa-pencil"></i> Ajouter
                        </a>
                    </div>
					<div align="center">
						<?php
						if (isset($_POST['valider']))
						{
							$date_mise=date('Y-m-d H:i:s');
							
							$sql11='SELECT COUNT(*) FROM selection, champ WHERE champ.id_champ=selection.id_champ';
							$reponse11=$bdd-> query($sql11) or die('Erreur SQL !<br />'.$sql11.'<br />'.mysql_error());
							$data11=$reponse11->fetch();
							$nombre_champ=$data11[0];
							
							$sql11='SELECT COUNT(*) FROM equipement';
							$reponse11=$bdd-> query($sql11) or die('Erreur SQL !<br />'.$sql11.'<br />'.mysql_error());
							$data11=$reponse11->fetch();
							$nombre_equipement=$data11[0];

							$nombre_row=0;
							$nombre_date=0;
							$sql11='SELECT * FROM selection, champ WHERE champ.id_champ=selection.id_champ ORDER BY id_selection ASC';
							$reponse11=$bdd-> query($sql11) or die('Erreur SQL !<br />'.$sql11.'<br />'.mysql_error());
							while($data11=$reponse11->fetch())
							{
								$nbr_blocage=0;
								$nombre_row++;
								$sql12='SELECT * FROM selection_type, type, selection WHERE selection_type.id_selection=selection.id_selection AND type.id_type=selection_type.id_type AND lib_type="'.$chaiz.'"';
								$reponse12=$bdd-> query($sql12) or die('Erreur SQL !<br />'.$sql12.'<br />'.mysql_error());
								while($data12=$reponse12->fetch())
								{
									if($data12['lib_selection']==$data11['lib_selection'])
									{
										$nbr_blocage++;
									}
								}
								$locked=0;
								if($nbr_blocage!=0)
								{
									$sql13='SELECT * FROM selection_type, type, selection WHERE selection_type.id_selection=selection.id_selection AND type.id_type=selection_type.id_type AND lib_type="'.$chaiz.'" AND lib_selection="'.$data11['lib_selection'].'"';
									$reponse13=$bdd-> query($sql13) or die('Erreur SQL !<br />'.$sql13.'<br />'.mysql_error());
									$data13=$reponse13->fetch();
									switch($data11['lib_champ'])
									{
										case 'int':
										case 'varchar':
										case 'select':
										$champ=addslashes(($_POST[$data11['lib_selection']]));
										if($data13['obligation_type']==1)
										{
											if(empty($champ))
											{
												echo '<div class="alert alert-danger">Veuillez renseigner: '.$data11['afficher_selection'].'</div>';
												$locked++;
											}
										}
										break;
										case 'checkbox':
										$nbr_equipement=0;
										for ($n=0; $n<=($nombre_equipement-1); $n++)
										{
											if(isset($_POST[$data11['lib_selection'].($n+1)]))
											{
												$equipement=addslashes(($_POST[$data11['lib_selection'].($n+1)]));
												if (!empty($equipement))
												{
													$nbr_equipement++;
												}
											}
										}
										if($data13['obligation_type']==1)
										{
											if ($nbr_equipement<=0)
											{
												echo '<div class="alert alert-danger">Veuillez ajouter au moins 1: '.$data11['afficher_selection'].'</div>';
												$locked++;
											}
										}
										break;
										case 'text':
										$champ=addslashes(($_POST[$data11['lib_selection']]));
										if($data13['obligation_type']==1)
										{
											if(empty($champ))
											{
												echo '<div class="alert alert-danger">Veuillez renseigner: '.$data11['afficher_selection'].'</div>';
												$locked++;
											}
										}
										break;
										case 'video':
										$nbr_video=0;
										for ($n=0; $n<=($data3['nvideo_type']-1); $n++)
										{
											$video=addslashes(($_POST[$data11['lib_selection'].($n+1)]));
											if (!empty($video))
											{
												$nbr_video++;
											}
										}
										if($data13['obligation_type']==1)
										{
											if ($nbr_video<=0)
											{
												echo '<div class="alert alert-danger">Veuillez ajouter au moins 1: '.$data11['afficher_selection'].'</div>';
												$locked++;
											}
										}
										break;
										case 'date':
										$nombre_date++;
										$champ=addslashes(($_POST[$data11['lib_selection']]));
										/*$champ=str_replace("/", "-", $champ);
										$champ=date('Y-m-d H:i:s', strtotime($champ));*/
										
										$debut=addslashes(($_POST['debut']));
										$fin=addslashes(($_POST['fin']));
										
										/*$debut=str_replace("/", "-", "$debut");
										$fin=str_replace("/", "-", "$fin");*/
										
										$debut=date('Y-m-d', strtotime($debut));
										$fin=date('Y-m-d', strtotime($fin));
										
										if($champ=='1970-01-01 00:00:00')
										{
											if($data13['obligation_type']==1)
											{
												echo '<div class="alert alert-danger">Veuillez renseigner correctement: '.$data11['afficher_selection'].'</div>';
												$locked++;
											}
										}
										elseif ((strtotime($debut))>(strtotime($fin)))
										{
											if($data13['obligation_type']==1)
											{
												echo '<div class="alert alert-danger">Il faut que la <strong>date de fin '.$fin.'</strong> soit supérieur à la <strong>date de début '.$debut.'</strong></div>';
												$locked++;
											}
										}
										break;
									}
									if($locked>=1)
									{
										break;
									}
								}
							}
							
							
							if($locked==0 and ($nombre_champ==$nombre_row))
							{								
								$lib=addslashes(($_POST['lib']));
								$descrip=addslashes(($_POST['descrip']));
								$adresse=addslashes(($_POST['adresse']));
								$prix=addslashes(($_POST['prix']));
								$piece=addslashes(($_POST['piece']));
								$surface=addslashes(($_POST['surface']));

								$commune=addslashes(($_POST['commune']));
								$typeinfo=addslashes(($_POST['typeinfo']));
								$categorie=addslashes(($_POST['categorie']));
								$contrat=addslashes(($_POST['contrat']));
								
								if($commune=='')
								{
									$commune="NULL";
								}
								if($typeinfo=='')
								{
									$typeinfo="NULL";
								}
								if($categorie=='')
								{
									$categorie="NULL";
								}
								if($contrat=='')
								{
									$contrat="NULL";
								}
								$slider=addslashes(($_POST['slider']));
								$fa=addslashes(($_POST['fa']));
								$lien=addslashes(($_POST['lien']));
								//new 2T Multimédia
								$pourcentage=addslashes(($_POST['pourcentage']));
								$fonction=addslashes(($_POST['fonction']));
								$resume=addslashes(($_POST['resume']));
								$caracteristique=addslashes(($_POST['caracteristique']));
								$couleur=addslashes(($_POST['couleur']));
								$volet=addslashes(($_POST['volet']));
								$detail=addslashes(($_POST['detail']));

								// sie immobilier
								$etage=addslashes(($_POST['etage']));
								$sallebain=addslashes(($_POST['sallebain']));
								$wc=addslashes(($_POST['wc']));

								$salon=addslashes(($_POST['salon']));
								$devise=addslashes(($_POST['devise']));
								$reference=addslashes(($_POST['reference']));

								$charge=addslashes(($_POST['charge']));
								$garantie=addslashes(($_POST['garantie']));
								$honoraire=addslashes(($_POST['honoraire']));
								
								if($lien!='')
								{
									if (substr($lien,0,7)=='http://')
									{
										//$lien=addslashes($_POST['lien']);
									}
									elseif (substr($lien,0,8)=='https://')
									{
										//$lien=addslashes($_POST['lien']);
									}
									else
									{
										$lien='http://'.addslashes($_POST['lien']);
									}
								}
								$date=addslashes(($_POST['date']));
								$debut=addslashes(($_POST['debut']));
								$fin=addslashes(($_POST['fin']));
								
								$debut=str_replace("/", "-", "$debut");
								$fin=str_replace("/", "-", "$fin");
								$date=str_replace("/", "-", "$date");
								
								$debut=date('Y-m-d H:i:s', strtotime($debut));
								$fin=date('Y-m-d H:i:s', strtotime($fin));
								$date=date('Y-m-d H:i:s', strtotime($date));

								$url=strtolower(str_replace($suppression, $ajouter, $lib));
								$url=strtolower(str_replace($suppression, $ajouter, $lib));
								$req='UPDATE information SET lib_information="'.$lib.'", descrip_information="'.$descrip.'", lien_information="'.$lien.'", adresse_information="'.$adresse.'", prix_information="'.$prix.'", piece_information="'.$piece.'", surface_information="'.$surface.'", debut_information="'.$debut.'", fin_information="'.$fin.'", date_information="'.$date.'", id_commune='.$commune.', id_typeinfo='.$typeinfo.', slider_information="'.$slider.'", fa_information="'.$fa.'", url_information="'.$url.'", pourcentage_information="'.$pourcentage.'", fonction_information="'.$fonction.'", resume_information="'.$slider.'", caracteristique_information="'.$caracteristique.'", couleur_information="'.$couleur.'", volet_information="'.$volet.'", id_categorie='.$categorie.', detail_information="'.$detail.'", id_contrat='.$contrat.', etage_information="'.$etage.'", sallebain_information="'.$sallebain.'", wc_information="'.$wc.'", salon_information="'.$salon.'", reference_information="'.$reference.'", devise_information="'.$devise.'", charge_information="'.$charge.'", garantie_information="'.$garantie.'", honoraire_information="'.$honoraire.'" WHERE id_information='.$id.'';
								$reponse=$bdd-> query($req) or die('Erreur SQL !<br />'.$req.'<br />'.mysql_error());

								$req='DELETE FROM video WHERE id_information='.$id;
								$reponse=$bdd-> query($req) or die('Erreur SQL !<br />'.$req.'<br />'.mysql_error());
								
								$nbr_img=0;
								for ($n=0; $n<=3; $n++)
								{
									$name_img=$_FILES['tof'.($n+1)]['name'];
									$name_img=$_FILES['tof'.($n+1)]['name'];
									$type_img=$_FILES['tof'.($n+1)]['type'];
									$size_img=$_FILES['tof'.($n+1)]['size'];
									$temp_img=$_FILES['tof'.($n+1)]['tmp_name'];
									$error_img=$_FILES['tof'.($n+1)]['error'];
									$extension=strrchr($name_img,'.');
									if($error_img==0and($extension=='.jpg'or $extension=='.png'or $extension=='.jpeg'or $extension=='.gif' or $extension=='.bmp'or $extension=='.JPG'or $extension=='.PNG'or $extension=='.JPEG'or $extension=='.GIF'or $extension=='.BMP'))
									{
										$nbr_img++;
										$lien_img=$date_img.'777img_koben'.$nbr_img.$extension;
										move_uploaded_file($temp_img, "../upload/".$lien_img);
										$req='INSERT INTO image VALUES (NULL, "'.$lien_img.'", "'.$date_mise.'", '.$data[0].', 0)';
										$reponse=$bdd-> query($req) or die('Erreur SQL !<br />'.$req.'<br />'.mysql_error());
									}
								}

								$nbr_video=0;
								for ($n=0; $n<=($data3['nvideo_type']-1); $n++)
								{
									$video=addslashes(($_POST['video'.($n+1)]));
									if (!empty($video))
									{
										$nbr_video++;
										$req='INSERT INTO video VALUES (NULL, "'.$video.'", '.$data[0].', "'.$date_mise.'", "'.$date_mise.'")';
										$reponse=$bdd-> query($req) or die('Erreur SQL !<br />'.$req.'<br />'.mysql_error());
									}
								}

								$req='DELETE FROM information_equipement WHERE id_information='.$id;
								$reponse=$bdd-> query($req) or die('Erreur SQL !<br />'.$req.'<br />'.mysql_error());
								if($chaiz=='Bien')
								{
									$nbr_equipement=0;
									for ($n=0; $n<=($nombre_equipement-1); $n++)
									{
										if(isset($_POST['equipement'.($n+1)]))
										{
											$equipement=addslashes(($_POST['equipement'.($n+1)]));
											if (!empty($equipement))
											{
												$nbr_equipement++;
												$req='INSERT INTO information_equipement VALUES ('.$data[0].', '.$equipement.', "'.$date_mise.'")';
												$reponse=$bdd-> query($req) or die('Erreur SQL !<br />'.$req.'<br />'.mysql_error());
											}
										}
									}
								}
								
								$req='INSERT INTO modificateur (`id_modificateur`, `id_information`, `id_modif_user`, `date_modificateur`) VALUES (NULL, '.$id.', '.$_SESSION['celest'].', "'.$date_mise.'")';
									$reponse=$bdd-> query($req) or die('Erreur SQL !<br />'.$req.'<br />'.mysql_error());
								echo '<div class="alert alert-success"> Modification effectuée avec succès</div>';
								?>
								<script type="text/javascript">
								window.setTimeout("location=('modifier-table.php?W9mvyDvFWE5=<?php echo $chaiz; ?>&QYtgoGbhhd=<?php echo $id ?>');",4000);
								</script>
								<?php
							}
						}
						?>
					</div>
                    
					<form role="form" method="post" action="" enctype="multipart/form-data" name="form2">
						<?php
						$z=0;
						$y=0;
						$sql11='SELECT * FROM selection, champ WHERE champ.id_champ=selection.id_champ ORDER BY rang_selection ASC, id_selection ASC';
						$reponse11=$bdd-> query($sql11) or die('Erreur SQL !<br />'.$sql11.'<br />'.mysql_error());
						while($data11=$reponse11->fetch())
						{
							$z++;
							$nbr_blocage=0;
							$sql12='SELECT * FROM selection_type, type, selection WHERE selection_type.id_selection=selection.id_selection AND type.id_type=selection_type.id_type AND lib_type="'.$chaiz.'"';
							$reponse12=$bdd-> query($sql12) or die('Erreur SQL !<br />'.$sql12.'<br />'.mysql_error());
							while($data12=$reponse12->fetch())
							{
								if($data12['lib_selection']==$data11['lib_selection'])
								{
									$nbr_blocage++;
								}
							}
							if($nbr_blocage==0)
							{
								$blocage=' id="blocage"';
							}
							else
							{
								$blocage='';
							}
							$sql13='SELECT * FROM selection_type, type, selection WHERE selection_type.id_selection=selection.id_selection AND type.id_type=selection_type.id_type AND lib_type="'.$chaiz.'" AND selection.id_selection='.$data11['id_selection'].'';
							$reponse13=$bdd-> query($sql13) or die('Erreur SQL !<br />'.$sql13.'<br />'.mysql_error());
							$data13=$reponse13->fetch();
							if($data13['obligation_type']==1)
							{
								echo '<div id="obligatoire">*</div>';
							}
							switch($data11['lib_champ'])
							{
								case 'int':
								?>
								<div<?php echo $blocage ?>>
                                    <h5><?php echo $data11['afficher_selection']; ?></h5>
                                    <input placeholder="<?php echo $data11['lib_champ'] ?>" type="text" class="form-control" name="<?php echo $data11['lib_selection']; ?>" onKeypress="if(event.keyCode < 45 || event.keyCode > 57) event.returnValue = false;if(event.which < 45 || event.which > 57) return false;" value="<?php echo stripslashes($data[$data11['lib_selection'].'_information']) ?>">
                                </div>
                                <?php
								break;
								case 'varchar':
								?>
								<div<?php echo $blocage ?>>
                                    <h5><?php echo $data11['afficher_selection']; ?></h5>
                                    <input placeholder="<?php echo $data11['lib_champ'] ?>" type="text" class="form-control" name="<?php echo $data11['lib_selection']; ?>" value="<?php echo $data[$data11['lib_selection'].'_information'] ?>">
                                </div>
                                <?php
								break;
								
								case 'date':
								$y++;
								?>
								<div<?php echo $blocage ?>>
                                    <h5><?php echo $data11['afficher_selection']; ?></h5>
                                    <?php
                                    //include('datemodif'.$y.'.php');
									include('datetime_modif.php');
									?>
                                </div>
                                <?php
								break;
								case 'text'
								?>
								<div<?php echo $blocage ?>>
                                    <h5><?php echo $data11['afficher_selection']; ?></h5>
                                    <textarea class="form-control" id="<?php echo $data11['lib_selection']; ?>" name="<?php echo $data11['lib_selection']; ?>"><?php echo $data[$data11['lib_selection'].'_information'] ?></textarea>
                                    <script>
                                        CKEDITOR.replace('<?php echo $data11['lib_selection']; ?>');
                                    </script>
                                    <!--<script>
									  $(function(){
										$('#<?php //echo $data11['lib_selection']; ?>').editable({inlineMode: false})
									  });
									</script>-->
                                </div>
                                <?php
								break;

								case 'checkbox':
								?>
								<div<?php echo $blocage ?>>
                                    <h5><?php echo $data11['afficher_selection']?></h5>
                                    <?php
                                    $i=0;
                                    $sql13='SELECT * FROM '.$data11['lib_selection'].' ORDER BY lib_'.$data11['lib_selection'].' ASC';
									$reponse13=$bdd-> query($sql13) or die('Erreur SQL !<br />'.$sql13.'<br />'.mysql_error());
									while($data13=$reponse13->fetch())
                                    {
                                    	$i++;
                                    	$m=0;
										$sql3= 'SELECT * FROM equipement, information_equipement WHERE equipement.id_equipement=information_equipement.id_equipement AND id_information='.$id;
										$reponse3=$bdd->query($sql3) or die('Erreur SQL !<br />'.$sql3.'<br />'.mysql_error());
										while($data3=$reponse3->fetch())
										{
											$m++;
											if($data3['id_equipement']==$data13['id_equipement'])
											{
												$checked=' checked';
												break;
											}
											else
											{
												$checked='';
											}
										}
										if($m==0)
										{
											$checked='';
										}
                                        ?>
                                        <input <?php echo $checked; ?> type="checkbox" name="<?php echo $data11['lib_selection'].$i; ?>" class="checkbox-inline" value="<?php echo $data13[0]; ?>">
                                    	<?php
                                        echo $data13['lib_'.$data11['lib_selection'].''];
                                    }
                                    ?>
                                </div>
                                <?php
								break;
								
								case 'video':
								?>
								<div<?php echo $blocage ?>>
                                    <h5><?php echo $data11['afficher_selection']; ?></h5>
                                    <?php
                                    for($i=1; $i<=$data3['nvideo_type']; $i++)
                                    {
                                    	$sql2= 'SELECT * FROM video WHERE id_information='.$id;
                                        $reponse2=$bdd-> query($sql2) or die('Erreur SQL !<br />'.$sql2.'<br />'.mysql_error());
                                        $data2=$reponse2->fetch();
                                        ?>
                                        <input type="text" class="form-control" name="<?php echo $data11['lib_selection'].$i; ?>" value="<?php echo $data2['lib_video']; ?>">
                                    <?php
                                    }
                                    ?>
                                </div>
                                <?php
								break;

								case 'image':
								?>
								<div<?php echo $blocage ?>>
                                    <h5><?php echo $data11['afficher_selection']?> <span id="span">(Max 300 ko)</span></h5>
                                    <div class="row" id="publier-img">
                                        <div class="col-lg-4 col-md-4 col-sm-4 col-xs-12">
                                            <input class="form-control" type="file" name="tof1">
                                            <input class="form-control" type="file" name="tof2">
                                            <input class="form-control" type="file" name="tof3">
                                            <input class="form-control" type="file" name="tof4">
                                            <!-- <input class="form-control" type="file" name="tof5">
                                            <input class="form-control" type="file" name="tof6">
                                            <input class="form-control" type="file" name="tof7">
                                            <input class="form-control" type="file" name="tof8">
                                            <input class="form-control" type="file" name="tof9">
                                            <input class="form-control" type="file" name="tof10">
                                            <input class="form-control" type="file" name="tof11">
                                            <input class="form-control" type="file" name="tof12">
                                            <input class="form-control" type="file" name="tof13">
                                            <input class="form-control" type="file" name="tof14">
                                            <input class="form-control" type="file" name="tof15">
                                            <input class="form-control" type="file" name="tof16"> -->
                                        </div>
                                        <div class="col-lg-8 col-md-8 col-sm-8 col-xs-12">
                                            <?php
                                            if(isset($_GET['defaut']))
                                            {
                                                $defaut=addslashes(($_GET['defaut']));
                                                $req='UPDATE image SET defaut_image=0 WHERE id_information="'.$id.'"';
                                                $reponse=$bdd-> query($req) or die('Erreur SQL !<br />'.$req.'<br />'.mysql_error());
                                                
                                                $req='UPDATE image SET defaut_image=1 WHERE id_image="'.$defaut.'"';
                                                $reponse=$bdd-> query($req) or die('Erreur SQL !<br />'.$req.'<br />'.mysql_error());
                                                ?>
                                                <script type="text/javascript">window.setTimeout("location=('modifier-table?W9mvyDvFWE5=<?php echo $chaiz; ?>&QYtgoGbhhd=<?php echo $id; ?>#publier-img');",0);</script>
                                                <?php
                                            }
                                            $sql2= 'SELECT COUNT(*) FROM image WHERE id_information='.$id.'';
                                            $reponse2=$bdd-> query($sql2) or die('Erreur SQL !<br />'.$sql2.'<br />'.mysql_error());
                                            $data2=$reponse2->fetch();
                                            $nbr_image=$data2[0];
                                            $sql2= 'SELECT * FROM image WHERE id_information='.$id.' ORDER BY id_image ASC';
                                            $reponse2=$bdd-> query($sql2) or die('Erreur SQL !<br />'.$sql2.'<br />'.mysql_error());
                                            while($data2=$reponse2->fetch())
                                            {
                                                ?>
                                                <div id="aff_img">
                                                    <a href="?defaut=<?php echo $data2[0]?>&W9mvyDvFWE5=<?php echo $chaiz; ?>&QYtgoGbhhd=<?php echo $id ?>#publier-img">
                                                        <?php
                                                        if($data2['defaut_image']==1)
                                                        {
                                                            ?>
                                                            <i class="fa fa-thumbs-up"></i>
                                                            <?php
                                                        }
                                                        ?>
                                                        <img src="../upload/<?php echo $data2['lib_image'] ?>">
                                                    </a>
                                                </div>
                                                <?php
                                                if($nbr_image>1)
                                                {
                                                    ?>
                                                    <!--<a href="?delete=<?php echo $data2[0]?>&id=<?php echo $id ?>#publier-img" data-toggle="modal" data-target="#myModal">-->
                                                    <a href="?delete=<?php echo $data2[0]?>&W9mvyDvFWE5=<?php echo $chaiz; ?>&QYtgoGbhhd=<?php echo $id ?>#publier-img">
                                                        <img src="img/delete.png" width="18"> 
                                                    </a>
                                                    <?php
                                                }
                                            }
                                            if(isset($_GET['delete']))
                                            {
                                                $delete=addslashes(($_GET['delete']));
                                                $req2='SELECT * FROM image WHERE id_image='.$delete;
                                                $reponse2=$bdd-> query($req2) or die('Erreur SQL !<br />'.$req2.'<br />'.mysql_error());
                                                $data2=$reponse2->fetch()
                                                ?>
                                                <script type="text/javascript">
                                                    $(document).ready(function(){
                                                        $("#myModal").modal('show');
                                                    });
                                                </script>
                                                <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
                                                    <div class="modal-dialog" role="document">
                                                        <div class="modal-content">
                                                            <div class="modal-header">
                                                                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                                                                    <span aria-hidden="true">&times;</span>
                                                                </button>
                                                                <h4 class="modal-title" id="myModalLabel">Voulez vous supprimer cette image:</h4>
                                                            </div>
                                                            <div class="modal-body" align="center">
                                                                <img src="../upload/<?php echo $limg=$data2['lib_image'] ?>" width="250">
                                                                <p style="margin-top:10px;">
                                                                    <a href="?W9mvyDvFWE5=<?php echo $chaiz; ?>&QYtgoGbhhd=<?php echo $id; ?>&supimage=<?php echo $data2[0] ?>#publier-img" class="btn btn-primary">Oui</a>
                                                                    <a href="?W9mvyDvFWE5=<?php echo $chaiz; ?>&QYtgoGbhhd=<?php echo $id; ?>#publier-img">Non</a>
                                                                </p>
                                                            </div>
                                                            <div class="modal-footer">
                                                                <button type="button" class="btn btn-default" data-dismiss="modal">Fermer</button>
                                                            </div>
                                                        </div>
                                                    </div>
                                                </div>
                                                <?php
                                            }
                                            ?>
                                        </div>
                                    </div>
                                    <?php
                                    if(isset($_GET['supimage']))
                                    {
                                        $supimage=addslashes(($_GET['supimage']));
                                        $req2='SELECT * FROM image WHERE id_image='.$supimage;
                                        $reponse2=$bdd-> query($req2) or die('Erreur SQL !<br />'.$req2.'<br />'.mysql_error());
                                        $data2=$reponse2->fetch();
                                        unlink ('../upload/'.$data2['lib_image']);
                                        $req='DELETE FROM image WHERE id_image='.$supimage.'';
                                        $reponse=$bdd-> query($req) or die('Erreur SQL !<br />'.$req.'<br />'.mysql_error());
                                        
                                        $req2='SELECT COUNT(*) FROM image WHERE id_information='.$id.' AND defaut_image=1';
                                        $reponse2=$bdd-> query($req2) or die('Erreur SQL !<br />'.$req2.'<br />'.mysql_error());
                                        $data2=$reponse2->fetch();
                                        if($data2[0]==0)
                                        {
                                            $req3='SELECT * FROM image WHERE id_image='.$id.'';
                                            $reponse3=$bdd-> query($req3) or die('Erreur SQL !<br />'.$req3.'<br />'.mysql_error());
                                            $data3=$reponse3->fetch();
                                            $req='UPDATE image SET defaut_image=1 WHERE id_image='.$data3[0].'';
                                            $reponse=$bdd-> query($req) or die('Erreur SQL !<br />'.$req.'<br />'.mysql_error());
                                        }
                                        echo '<div class="alert alert-success" align="center"> Suppression effectuée avec succès </div>';
                                        ?> 
                                        <script type="text/javascript">window.setTimeout("location=('?W9mvyDvFWE5=<?php echo $chaiz; ?>&QYtgoGbhhd=<?php echo $id; ?>#publier-img');",2000);</script>
                                        <?php
                                    }
                                    ?>
                                </div>
                                <?php
								break;
								
								case 'select':
								?>
								<div<?php echo $blocage ?>>
                                    <?php
                                    if($data11['select_selection']=='classique')
                                    {
										if($developpeur!=3)
										{
											?>
											<h5><?php echo $data11['afficher_selection']; ?></h5>
                                            <select name="<?php echo $data11['lib_selection']; ?>" class="form-control">
                                                <?php if($data['id_typeinfo']==$data2[0]){ echo $cocher=' selected="selected"';}else{echo $cocher='';}?>
                                                <option<?php if($data['slider_information']=='oui'){ echo $cocher=' selected="selected"';}else{echo $cocher='';}?>>oui</option>
                                                <option<?php if($data['slider_information']=='non'){ echo $cocher=' selected="selected"';}else{echo $cocher='';}?>>non</option>
                                            </select>
											<?php
										}
										else
										{
											?>
											<input name="<?php echo $data11['lib_selection']; ?>" type="hidden" value="non">
											<?php
										}
                                    }
                                    else
                                    {
                                        $sql13='SELECT * FROM selection, privilege WHERE privilege.id_privilege=selection.id_privilege AND privilege.id_privilege='.$data11['id_privilege'].'';
                                        $reponse13=$bdd-> query($sql13) or die('Erreur SQL !<br />'.$sql13.'<br />'.mysql_error());
                                        $data13=$reponse13->fetch();
                                        ?>
                                        <h5><?php echo $data11['afficher_selection']; ?></h5>
                                        <select name="<?php echo $data11['lib_selection']; ?>" class="form-control">
                                            <option value="">--------------------------------------------------</option>
											<?php
                                            if($data11['lib_selection']!='typeinfo' and $data11['lib_selection']!='categorie')
                                            {
                                                $sql2 = 'SELECT * FROM '.$data11['lib_selection'].' ORDER BY lib_'.$data11['lib_selection'].' ASC';
                                            }
                                            else
                                            {
                                             	if($data11['lib_selection']=='typeinfo')
                                            	{
                                            		$sql2 = 'SELECT * FROM '.$data11['lib_selection'].', type WHERE type.id_type='.$data11['lib_selection'].'.id_type AND type.id_type="'.$id_table.'" ORDER BY lib_'.$data11['lib_selection'].' ASC';
												}
												else
												{
                                            		$sql2 = 'SELECT * FROM '.$data11['lib_selection'].', type, typeinfo WHERE typeinfo.id_typeinfo=categorie.id_typeinfo AND type.id_type='.$data11['lib_selection'].'.id_type AND type.id_type="'.$id_table.'" ORDER BY lib_typeinfo ASC, lib_'.$data11['lib_selection'].' ASC';
												}
                                            }
                                            $reponse2=$bdd-> query($sql2) or die('Erreur SQL !<br />'.$sql2.'<br />'.mysql_error());
                                            while ($data2=$reponse2->fetch())
                                            {
                                                if($data['id_'.$data11['lib_selection'].'']==$data2[0])
                                                {
                                                    $cocher=' selected="selected"';
                                                }
                                                else
                                                {
                                                    $cocher='';
                                                }
                                                //echo '<option'.$cocher.' value="'.$data2[0].'">'.$data2['lib_'.$data11['lib_selection'].''].'</option>';
												echo '
												<option'.$cocher.' value="'.$data2[0].'">';
													if($data11['lib_selection']=='categorie')
													{
														echo $data2['lib_typeinfo'].' / ';
													}
													echo $data2['lib_'.$data11['lib_selection'].''].'
												</option>';
                                            }
                                            ?>
                                        </select>
                                    	<?php
									}
									?>
                                </div>
                                <?php
								break;
							}
							?>
                        	<?php
						}
						?>
                        <div id="valider">
                            <input type="submit" class="btn btn-primary" value="Valider" name="valider">
                            &nbsp; <a href="gestionnaire-table.php?W9mvyDvFWE5=<?php echo $chaiz ?>"><i class="fa fa-reply"></i> Retour</a>
                        </div>
					</form>
                </div>
            </div>
        </div>
    </div>
</body>
</html>

<?php 
}
else
{
	header('Location: index.php');
}
?>