[SPIP] ~2.1.12 -->2.1.25
[velocampus/web/www.git] / www / ecrire / exec / recherche.php
1 <?php
2
3 /***************************************************************************\
4 * SPIP, Systeme de publication pour l'internet *
5 * *
6 * Copyright (c) 2001-2014 *
7 * Arnaud Martin, Antoine Pitrou, Philippe Riviere, Emmanuel Saint-James *
8 * *
9 * Ce programme est un logiciel libre distribue sous licence GNU/GPL. *
10 * Pour plus de details voir le fichier COPYING.txt ou l'aide en ligne. *
11 \***************************************************************************/
12
13 if (!defined('_ECRIRE_INC_VERSION')) return;
14 include_spip('inc/presentation');
15
16 // http://doc.spip.org/@exec_recherche_dist
17 function exec_recherche_dist() {
18
19 $recherche = _request('recherche');
20 $recherche_aff = entites_html($recherche);
21
22 $commencer_page = charger_fonction('commencer_page', 'inc');
23 echo $commencer_page(_T('titre_page_recherche', array('recherche' => $recherche_aff)));
24
25 if (strlen($recherche)) {
26 include_spip('inc/rechercher');
27 include_spip('base/abstract_sql');
28
29 $tables = liste_des_champs();
30 //unset($tables['document']);
31 unset($tables['forum']);
32 unset($tables['syndic_article']);
33
34 $results = recherche_en_base($recherche, $tables, array('jointures' => true, 'score' => false)); // true => a gerer dans l'affichage, autant faire un squelette
35
36 /* $modifier = false;
37 foreach ($results as $table => $r) {
38 foreach ($r as $id => $x) {
39 $modifier |= autoriser('modifier', $table, $id);
40 }
41 }
42 */
43
44 // Ajouter la recherche par identifiant
45 if (preg_match(',^[0-9]+$,', $recherche)
46 AND $id = intval($recherche))
47 foreach ($tables as $table => $x) {
48 $t = sql_countsel(table_objet_sql($table), id_table_objet($table)."=".sql_quote($id));
49 if ($t
50 AND autoriser('voir', $table, $id)
51 AND !isset($results[$table][$id]))
52 $results[$table][$id] = array();
53 }
54
55 }
56
57 echo debut_grand_cadre(true);
58
59 echo formulaire_recherche("recherche");
60
61 /*
62 // Si on est autorise a modifier, proposer le choix de REMPLACER
63 // Il faudra aussi pouvoir indiquer sur quels elements on veut effectuer le remplacement...
64 if ($modifier) {
65 echo '<br /><input type="text" size="10" value="'.entites_html(_request('remplacer')).'" name="remplacer" class="spip_recherche" />';
66 }
67 */
68
69 if ($results) {
70 echo "<span class='verdana1'><b>"._T('info_resultat_recherche')."</b></span><br />";
71 echo "<h1>$recherche_aff</h1>";
72 include_spip('inc/afficher_objets');
73
74 foreach($results as $table => $r) {
75 switch ($table) {
76 case 'article':
77 $titre = _T('info_articles_trouves');
78 $order = 'date DESC';
79 break;
80 case 'breve':
81 $titre = _T('info_breves_touvees');
82 $order = 'date_heure DESC';
83 break;
84 case 'rubrique':
85 $titre = _T('info_rubriques_trouvees');
86 $order = 'date DESC';
87 break;
88 case 'site':
89 $titre = _T('info_sites_trouves');
90 $order = 'date DESC';
91 break;
92 case 'auteur':
93 $titre = _T('info_auteurs_trouves');
94 $order = 'nom';
95 break;
96 case 'mot':
97 $titre = _T('titre_page_mots_tous');
98 $order = 'titre';
99 break;
100 case 'document':
101 $titre = _T('titre_documents_joints');
102 $order = "id_$table";
103 break;
104 case 'groupes_mot':
105 $titre = _T('titre_groupe_mots');
106 $order = 'titre';
107 break;
108 default:
109 $titre = _T("autres");
110 $order = "id_$table";
111 break;
112 }
113
114 echo afficher_objets($table,$titre,
115 array(
116 // gasp: la requete spip_articles exige AS articles...
117 'FROM' => table_objet_sql($table).' AS '.table_objet($table),
118 'WHERE' => sql_in(
119 table_objet($table).'.'.id_table_objet($table),
120 array_keys($r)
121 ),
122 'ORDER BY' => $order
123 )
124 );
125 }
126
127 }
128 else
129 if (strlen($recherche))
130 echo "<p class='verdana1'>"._T('avis_aucun_resultat')."</p>";
131
132 echo fin_grand_cadre(true), fin_page();
133 }
134
135 ?>