1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213
|
<?php
/*
Entete page
*/
echo'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">';
echo'<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" lang="fr">';
echo'<head>';
echo'<title>Recherche - Base documentaire </title>';
echo'<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
echo'<meta http-equiv="Content-Language" content="fr" />';
/*
JQUERY
*/
echo'<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>';
echo'</head>';
echo'<body>';
/*
Piwik
*/
echo'<script type="text/javascript">';
echo'var pkBaseURL = (("https:" == document.location.protocol) ? "https://bibliotheque/piwik/" : "http://bibliotheque/piwik/");';
echo'document.write(unescape("%3Cscript src=\'" + pkBaseURL + "piwik.js\' type=\'text/javascript\'%3E%3C/script%3E"));';
echo'</script>';
echo'<script type="text/javascript">';
echo'try {';
echo'var piwikTracker = Piwik.getTracker(pkBaseURL + "piwik.php", 1);';
echo'piwikTracker.trackPageView();';
echo'piwikTracker.enableLinkTracking();';
echo'} catch( err ) {}';
echo'</script>';
echo'<noscript><p><img src="http://bibliotheque/piwik/piwik.php?idsite=1" style="border:0" alt="" /></p></noscript>';
/*
CSS
*/
echo'<style>
table {
border:3px solid #6495ed;
border-collapse:collapse;
width:90%;
margin:auto;
}
thead, tfoot {
background-color:#D0E3FA;
border:5px solid #6495ed;
}
tbody {
background-color:#FFFFFF;
border:1px solid #6495ed;
}
th {
font-family:monospace;
border:1px dotted #6495ed;
padding:5px;
background-color:#EFF6FF;
//width:25%;
}
td {
font-family:sans-serif;
font-size:80%;
border:1px solid #6495ed;
padding:5px;
text-align:center;
}
caption {
font-family:sans-serif;
}
</style>';
/*
Connexion à la BDD
*/
mysql_connect('localhost','XXXX','XXXX');
mysql_select_db('ouvrage');
mysql_query("SET NAMES 'utf8'");
/*
Traitement
*/
echo '<a href="/Biblio/Test/biblio.php">Liste complète</a><br>';
//On determine l'expression a rechercher
if( isset( $_POST['recherche'] ) ){
$rec = htmlentities( $_POST['recherche'] );
}else{
$rec = '';
}
//On determine le type de recherche
if( isset( $_POST['type'] ) ){
if( $_POST['type']=='un' ){
//Un des mots
$type = 1;
}elseif( $_POST['type']=='tout' ){
//Tout les mots
$type = 2;
}else{
//L'expression exacte
$type = 3;
}
}else{
$type = 1;//type par defaut: L'expression exacte
}
echo'<form action="'.$_SERVER["PHP_SELF"].'" method="post" id="formRecherche">';
echo'Expression à rechercher: <input type="text" name="recherche" value="'.$rec.'" /><br />';
echo'Type de recherche: <input type="radio" name="type" value="un"'.(($type==1)?' checked="checked"':'').' />';
echo'Un des mots <input type="radio" name="type" value="tout"'.(($type==2)?' checked="checked"':'').' />';
echo'Expression exacte (titre)<br /><input type="submit" value="Rechercher" /><br />';
echo'<select name="liste_domaine" onchange="$(\'#formRecherche\').submit();">';
$selected = (($_POST["liste_domaine"]=='voirtout')?' selected="selected"':'');
echo'<option value="voirtout"'.$selected.'>--Tous les domaines--</option>';
$selected = (($_POST["liste_domaine"]=='domaine1')?' selected="selected"':'');
echo'<option value="domaine1"'.$selected.'>domaine1</option>';
$selected = (($_POST["liste_domaine"]=='domaine2')?' selected="selected"':'');
echo'<option value="domaine2"'.$selected.'>domaine2</option>';
$selected = (($_POST["liste_domaine"]=='domaine4')?' selected="selected"':'');
echo'<option value="domaine4"'.$selected.'>domaine4</option>';
$selected = (($_POST["liste_domaine"]=='domaine3')?' selected="selected"':'');
echo'<option value="domaine3"'.$selected.'>domaine3</option>';
$selected = (($_POST["liste_domaine"]=='domaine5')?' selected="selected"':'');
echo'<option value="domaine5"'.$selected.'>domaine5</option>';
echo'</select>';
echo'<input type="submit" value="Envoyer"><br/>';
echo'</form>';
/*
Traitement des résultats
*/
//On dertermine les informations des ouvrages
if(isset($_POST["liste_domaine"])){
if($_POST["liste_domaine"]=='voirtout'){
$resultat = @mysql_query("SELECT * FROM exemple");
}else{
$resultat = @mysql_query("SELECT * FROM exemple WHERE domaine ='".mysql_real_escape_string($_POST['liste_domaine'])."' ORDER BY id ASC");
}
}else{
$req= 'SELECT nom, prenom, editeur, titre, millesime, domaine, serie, ID FROM exemple';
$sCondition = '';
if( $type==1 ){
//ayant un des mots dans leurs informations
$mots = explode(' ',$rec);//On separe lexpression en mots cles
foreach( $mots as $mot ){
if($sCondition==''){
$sCondition.=' WHERE';
}else{
$sCondition.=' OR';
}
$sCondition .= ' titre LIKE "%'.$mot.'%" OR domaine LIKE "%'.$mot.'%" OR serie LIKE "%'.$mot.'%"';
}
}elseif( $type==2 ){
//ayant tout des mots dans leurs informations
$mots = explode(' ',$rec);//On separe lexpression en mots cles
foreach( $mots as $mot ){
if($sCondition==''){
$sCondition.=' WHERE';
}else{
$sCondition.=' AND';
}
$sCondition .= ' titre LIKE "%'.$mot.'%"';
}
}else{
if($sCondition==''){
$sCondition.=' WHERE';
}
//ayant l'expression exacte dans leurs informations
$sCondition .= ' titre LIKE "%'.$rec.'%"';
}
//Les utilisateur seront ranges par domaine en ordre croissant
$req .= $sCondition.' order by domaine asc';
$resultat = @mysql_query($req);
}
if( $resultat ){
if( mysql_num_rows($resultat)>0 ){
echo'<h2>Résultats</h2>';
echo'<div style="text-align:center">
<table>
<tr>
<th>Titre</th>
<th>Editeur</th>
<th>Millésime</th>
<th>Nom</th>
<th>Domaine</th>
</tr>';
//On affiche les resultats
while( $row = mysql_fetch_object($resultat) ){
echo'<tr>
<td>'.$row->titre.'</td>
<td>'.$row->editeur.'</td>
<td>'.$row->millesime.'</td>
<td>'.$row->nom.'</td>
<td>'.$row->domaine.'</td>
</tr>';
}
echo'</table>
</div>';
}else{
echo'<p>Aucun résultat ne correspond à votre recherche</p>';
}
}else{
echo'<p>Erreur de requête</p>';
}
echo'</body>
</html>';
?> |
Partager