Subversion Repositories Applications.bazar

Rev

Rev 115 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
5 florian 1
<?php
116 florian 2
 
3
require_once BAZ_CHEMIN_APPLI.'bibliotheque/bazar.class.php';
4
require_once BAZ_CHEMIN_APPLI.'bibliotheque/bazar.fonct.php';
5
 
5 florian 6
/** baz_valeur_template() - Renvoi des valeurs inscrite dans le fichier de template
7
*
68 florian 8
* @param   string valeur du template de bazar_nature
5 florian 9
*
10
* @return   mixed  tableau contenant les champs du fichier template
11
*/
68 florian 12
function baz_valeurs_template($valeur_template) {
5 florian 13
	//Parcours du fichier de templates, pour mettre les champs spécifiques
14
	$nblignes=0;
68 florian 15
	$chaine = explode ("\n", $valeur_template);
5 florian 16
	array_pop($chaine);
17
	foreach ($chaine as $ligne)  {
18
		$souschaine = explode ("***", $ligne) ;
19
		$tableau[$nblignes]['type'] = trim($souschaine[0]) ;
20
		if (isset($souschaine[1])) {$tableau[$nblignes]['nom_bdd'] = trim($souschaine[1]);}
21
		else {$tableau[$nblignes]['nom_bdd'] ='';}
22
		if (isset($souschaine[2])) $tableau[$nblignes]['label'] = trim($souschaine[2]);
23
		else {$tableau[$nblignes]['label'] ='';}
24
		if (isset($souschaine[3])) $tableau[$nblignes]['limite1'] = trim($souschaine[3]);
25
		else {$tableau[$nblignes]['limite1'] ='';}
26
		if (isset($souschaine[4])) $tableau[$nblignes]['limite2'] = trim($souschaine[4]);
27
		else {$tableau[$nblignes]['limite2'] ='';}
28
		if (isset($souschaine[5])) $tableau[$nblignes]['defaut'] = trim($souschaine[5]);
29
		else {$tableau[$nblignes]['defaut'] ='';}
30
		if (isset($souschaine[6])) $tableau[$nblignes]['table_source'] = trim($souschaine[6]);
31
		else {$tableau[$nblignes]['table_source'] ='';}
32
		if (isset($souschaine[7])) $tableau[$nblignes]['id_source'] = trim($souschaine[7]);
33
		else {$tableau[$nblignes]['id_source'] ='';}
34
		if (isset($souschaine[8])) $tableau[$nblignes]['obligatoire'] = trim($souschaine[8]);
35
		else {$tableau[$nblignes]['obligatoire'] ='';}
88 alexandre_ 36
		if (isset($souschaine[9])) $tableau[$nblignes]['recherche'] = trim($souschaine[9]);
64 florian 37
		else {$tableau[$nblignes]['recherche'] ='';}
67 alexandre_ 38
 
39
 
40
		// traitement des cases à cocher, dans ce cas la, on a une table de jointure entre la table
41
		// de liste et la table bazar_fiche (elle porte un nom du genre bazar_ont_***)
42
		// dans le template, à la place d'un nom de champs dans 'nom_bdd', on a un nom de table
43
		// et 2 noms de champs séparés par un virgule ex : bazar_ont_theme,bot_id_theme,bot_id_fiche
44
 
45
		if (isset($tableau[$nblignes]['nom_bdd']) && preg_match('/,/', $tableau[$nblignes]['nom_bdd'])) {
46
			$tableau_info_jointe = explode (',', $tableau[$nblignes]['nom_bdd']) ;
47
			$tableau[$nblignes]['table_jointe'] = $tableau_info_jointe[0] ;
48
			$tableau[$nblignes]['champs_id_fiche'] = $tableau_info_jointe[1] ;
49
			$tableau[$nblignes]['champs_id_table_jointe'] = $tableau_info_jointe[2] ;
50
		}
5 florian 51
		$nblignes++;
52
	}
53
	return $tableau;
54
}
55
 
33 ddelon 56
/**  baz_voir_fiches() - Permet de visualiser en detail une liste de fiche  au format XHTML
57
*
58
* @global boolean Rajoute des informations internes à l'application (date de modification, lien vers la page de départ de l'appli)
59
* @global integer Tableau d(Identifiant des fiches à afficher
60
*
61
* @return   string  HTML
62
*/
63
function baz_voir_fiches($danslappli, $idfiches=array()) {
64
	$res='';
65
	foreach($idfiches as $idfiche) {
66
			$res.=baz_voir_fiche($danslappli, $idfiche);
67
	}
68
	return $res;
69
}
54 florian 70
 
71
 
5 florian 72
/**  baz_voir_fiche() - Permet de visualiser en détail une fiche  au format XHTML
73
*
74
* @global boolean Rajoute des informations internes à l'application (date de modification, lien vers la page de départ de l'appli) si à 1
75
* @global integer Identifiant de la fiche à afficher
76
*
77
* @return   string  HTML
78
*/
79
function baz_voir_fiche($danslappli, $idfiche='') {
55 florian 80
	$res='';
5 florian 81
	if (isset($_GET['id_fiche'])) $GLOBALS['_BAZAR_']['id_fiche']=$_GET['id_fiche'];
82
	if ($idfiche!='') $GLOBALS['_BAZAR_']['id_fiche']=$idfiche;
83
 
9 florian 84
	$url= $GLOBALS['_BAZAR_']['url'];
85
	$url->addQueryString('action', BAZ_VOIR_FICHE);
86
	$url->addQueryString('id_fiche', $GLOBALS['_BAZAR_']['id_fiche']);
87
	$url = preg_replace ('/&amp;/', '&', $url->getURL()) ;
7 florian 88
 
15 florian 89
	//cas ou un commentaire a été entré
9 florian 90
	if (isset($_POST['Nom'])) {
38 alexandre_ 91
		$requete = 'INSERT INTO bazar_commentaires VALUES ('.
92
					baz_nextid('bazar_commentaires', 'bc_id_commentaire', $GLOBALS['_BAZAR_']['db']).
93
					', '.$GLOBALS['_BAZAR_']['id_fiche'].', "'.$_POST['Nom'].'", "'.$_POST['Commentaire'].
94
					'", NOW() )';
9 florian 95
		$resultat = $GLOBALS['_BAZAR_']['db']->query($requete) ;
96
	}
54 florian 97
	//cas ou un commentaire va etre supprime
15 florian 98
	elseif (isset($_GET['id_commentaire'])) {
99
		$requete = 'DELETE FROM bazar_commentaires WHERE bc_id_commentaire='.$_GET['id_commentaire'].' LIMIT 1';
9 florian 100
		$resultat = $GLOBALS['_BAZAR_']['db']->query($requete) ;
101
	}
15 florian 102
	else {
103
		if (isset($_GET['action'])) {
104
			if ($_GET['action']==BAZ_VOIR_FICHE) {
54 florian 105
				//sinon on met a jour le nb de visites pour la fiche, puisque c'est une simple consultation
15 florian 106
				$requete = 'UPDATE bazar_fiche SET bf_nb_consultations=bf_nb_consultations+1 WHERE bf_id_fiche='.$GLOBALS['_BAZAR_']['id_fiche'];
107
				$resultat = $GLOBALS['_BAZAR_']['db']->query($requete) ;
108
			}
109
		}
110
	}
9 florian 111
 
45 florian 112
	//on verifie si l'utilisateur est administrateur
9 florian 113
	$est_admin=0;
114
	if ($GLOBALS['AUTH']->getAuth()) {
115
		$requete='SELECT bn_id_nature FROM bazar_nature WHERE bn_label_nature="'.$GLOBALS['_BAZAR_']['typeannonce'].'"';
116
		$resultat = $GLOBALS['_BAZAR_']['db']->query($requete) ;
117
		if (DB::isError($resultat)) {
118
			die ($resultat->getMessage().$resultat->getDebugInfo()) ;
119
		}
120
		$result = $resultat->fetchRow(DB_FETCHMODE_ASSOC);
69 alexandre_ 121
		$id_nature = $result['bn_id_nature'];
9 florian 122
		if ((niveau_droit($result['bn_id_nature'],$GLOBALS['AUTH']->getAuthData(BAZ_CHAMPS_ID))=='administrateur')
123
		     or(niveau_droit('0',$GLOBALS['AUTH']->getAuthData(BAZ_CHAMPS_ID))=='superadministrateur'))
124
		{
125
		        $est_admin=1;
126
		}
127
	}
76 florian 128
	//affiche le titre sous forme d'image
87 alexandre_ 129
	if (isset ($GLOBALS['_BAZAR_']['image_titre']) && $GLOBALS['_BAZAR_']['image_titre']!='') {
56 florian 130
		$res .= '<img id="BAZ_img_titre" src="client/bazar/images/'.$GLOBALS['_BAZAR_']['image_titre'].'" alt="'.$GLOBALS['_BAZAR_']['typeannonce'].'" />'.'<br />'."\n";
55 florian 131
	}
56 florian 132
	//affiche le texte sinon
133
	else {
105 florian 134
		$res .= '<h1 class="BAZ_titre">'.$GLOBALS['_BAZAR_']['typeannonce'].'</h1>'."\n";
56 florian 135
	}
55 florian 136
	$res .= '<div class="BAZ_cadre_fiche">'."\n";
7 florian 137
	$res .= '<div class="BAZ_cadre_fiche_haut">'."\n";
5 florian 138
	$res .= '&nbsp;</div>'."\n";
7 florian 139
	$res .= '<div class="BAZ_cadre_fiche_corps">'."\n";
55 florian 140
	$requete = 'SELECT * FROM bazar_fiche WHERE bf_id_fiche='.$GLOBALS['_BAZAR_']['id_fiche'];
141
	$resultat = $GLOBALS['_BAZAR_']['db']->query($requete) ;
142
	if (DB::isError ($resultat)) {
143
		die ($resultat->getMessage().'<br />'.$resultat->getDebugInfo()) ;
144
	}
145
	$ligne = $resultat->fetchRow(DB_FETCHMODE_ASSOC) ;
87 alexandre_ 146
	$GLOBALS['_BAZAR_']['annonceur'] = $ligne['bf_ce_utilisateur'] ;
45 florian 147
	//si le template existe, on genere le template
5 florian 148
	if ((file_exists(BAZ_CHEMIN_APPLI.'templates/'.$GLOBALS['_BAZAR_']['typeannonce'].'-fiche.php'))) {
149
		include_once(BAZ_CHEMIN_APPLI.'templates/'.$GLOBALS['_BAZAR_']['typeannonce'].'-fiche.php');
55 florian 150
		$res .=genere_fiche($ligne);
5 florian 151
	}
152
	//on affiche ligne par ligne sinon
83 alexandre_ 153
	else {
55 florian 154
		//cas d'une image personalisée
7 florian 155
		if (isset($ligne['bf_url_image'])) {
156
			$res .= '<div id="fiche_image">'."\n";
75 florian 157
			$res .= '<img src="client/bazar/images/'.$ligne['bf_url_image'].'" border=0 alt="'.BAZ_TEXTE_IMG_ALTERNATIF.'" width="130" height="130"  />'."\n";
7 florian 158
			$res .= '</div>'."\n";
159
		}
55 florian 160
		//cas d'une image par défaut
87 alexandre_ 161
		elseif (isset ($GLOBALS['_BAZAR_']['image_logo']) && $GLOBALS['_BAZAR_']['image_logo']!='') {
55 florian 162
			$res .= '<div id="fiche_image">'."\n";
75 florian 163
			$res .= '<img src="client/bazar/images/'.$GLOBALS['_BAZAR_']['image_logo'].'" border=0 alt="'.BAZ_TEXTE_IMG_ALTERNATIF.'" width="130" height="130" />'."\n";
55 florian 164
			$res .= '</div>'."\n";
7 florian 165
		}
55 florian 166
		$res .= '<h1 id="fiche_titre">'.$ligne['bf_titre'].'</h1>'."\n";
7 florian 167
		$res .= '<div id="BAZ_description">'.$ligne['bf_description'].'</div>'."\n";
69 alexandre_ 168
		$tableau=baz_valeurs_template($GLOBALS['_BAZAR_']['template']);
5 florian 169
		for ($i=0; $i<count($tableau); $i++) {
170
			if (isset($ligne[$tableau[$i]['nom_bdd']])) {
87 alexandre_ 171
				$val=$tableau[$i]['nom_bdd'];
83 alexandre_ 172
				if (!in_array($val, array ('bf_titre', 'bf_description', 'bf_date_debut_validite_fiche',
173
								'bf_date_fin_validite_fiche'))) {
174
					if ($val != '' and $val != BAZ_CHOISIR and $val != BAZ_NON_PRECISE) {
105 florian 175
						$res .= '<span class="rubrique">'.$tableau[$i]['label'].':</span>'."\n";
87 alexandre_ 176
						$res .= '<span class="description"> '.$ligne[$val].'</span>'."\n".'<br />'."\n";
7 florian 177
					}
5 florian 178
				}
179
			}
75 florian 180
			elseif (($tableau[$i]['type']=='liste')or($tableau[$i]['type']=='checkbox')) {
181
				//pour les champs renseignes par une liste, on va chercher le label de la liste, plutot que l'id
182
				$requete = 'SELECT blv_label FROM bazar_fiche_valeur_liste, bazar_liste_valeurs WHERE bfvl_ce_fiche='.$GLOBALS['_BAZAR_']['id_fiche'].
183
				' AND  bfvl_ce_liste='.$tableau[$i]['nom_bdd'].' AND bfvl_valeur=blv_valeur AND blv_ce_liste='.$tableau[$i]['nom_bdd'].' AND blv_ce_i18n="'.$GLOBALS['_BAZAR_']['langue'].'"';
184
				$resultat = $GLOBALS['_BAZAR_']['db']->query($requete) ;
185
				if (DB::isError ($resultat)) {
186
					die ($resultat->getMessage().'<br />'.$resultat->getDebugInfo()) ;
187
				}
76 florian 188
				$val='';$nb=0;
75 florian 189
				while ($tab = $resultat->fetchRow()) {
76 florian 190
					if ($nb>0) $val .= ', ';
191
					$val .= $tab[0];
192
					$nb++;
75 florian 193
				}
105 florian 194
				$res .= '<span class="rubrique">'.$tableau[$i]['label'].':</span>'."\n";
75 florian 195
				$res .= '<span class="description"> '.$val.'</span>'."\n".'<br />'."\n";
196
			}
5 florian 197
		}
7 florian 198
	//afficher les liens pour l'annonce
199
	$requete = 'SELECT  bu_url, bu_descriptif_url FROM bazar_url WHERE bu_ce_fiche='.$GLOBALS['_BAZAR_']['id_fiche'];
200
	$resultat = $GLOBALS['_BAZAR_']['db']->query($requete) ;
201
	if (DB::isError($resultat)) {
202
		die ($resultat->getMessage().$resultat->getDebugInfo()) ;
203
	}
204
	if ($resultat->numRows()>0) {
205
		$res .= '<span class="rubrique">'.BAZ_LIEN_INTERNET.':</span>'."\n";
206
		$res .= '<span class="description">'."\n";
207
		$res .= '<ul>'."\n";
208
		while ($ligne1 = $resultat->fetchRow(DB_FETCHMODE_ASSOC)) {
209
			$res .= '<li><a href="'.$ligne1['bu_url'].'" target="_blank">'.$ligne1['bu_descriptif_url'].'</a></li>'."\n";
5 florian 210
		}
7 florian 211
		$res .= '</ul></span>'."\n";
212
	}
213
 
214
	//afficher les fichiers pour l'annonce
215
	$requete = 'SELECT  bfj_description, bfj_fichier FROM bazar_fichier_joint WHERE bfj_ce_fiche='.$GLOBALS['_BAZAR_']['id_fiche'];
216
	$resultat = $GLOBALS['_BAZAR_']['db']->query($requete) ;
217
	if (DB::isError($resultat)) {
218
		die ($resultat->getMessage().$resultat->getDebugInfo()) ;
219
	}
220
	if ($resultat->numRows()>0) {
221
		$res .= '<span class="rubrique">'.BAZ_LISTE_FICHIERS_JOINTS.':</span>'."\n";
222
		$res .= '<span class="description">'."\n";
223
		$res .= '<ul>'."\n";
224
		while ($ligne2 = $resultat->fetchRow(DB_FETCHMODE_ASSOC)) {
225
			$res .= '<li><a href="http://'.$_SERVER['HTTP_HOST'].'/client/bazar/upload/'.$ligne2['bfj_fichier'].'">'.$ligne2['bfj_description'].'</a></li>'."\n";
226
		}
227
		$res .= '</ul></span>'."\n";
228
	}
9 florian 229
	$res .= '<div class="bulle_haut">&nbsp;</div>'."\n";
230
	$res .= '<div class="bulle_corps">'."\n";
7 florian 231
 
45 florian 232
	//affichage du redacteur de la fiche
69 alexandre_ 233
	$requete = 'SELECT '.BAZ_CHAMPS_NOM.', '.BAZ_CHAMPS_PRENOM.', '.BAZ_CHAMPS_EMAIL.
234
					' FROM '.BAZ_ANNUAIRE.' WHERE '.BAZ_CHAMPS_ID.'='.$ligne['bf_ce_utilisateur'];
7 florian 235
	$resultat = $GLOBALS['_BAZAR_']['db']->query($requete) ;
236
	if (DB::isError($resultat)) {
237
		die ($resultat->getMessage().$resultat->getDebugInfo()) ;
238
	}
239
	while ($redacteur = $resultat->fetchRow(DB_FETCHMODE_ASSOC)) {
240
		$res .= BAZ_FICHE_ECRITE.'<a href="mailto:'.$redacteur[BAZ_CHAMPS_EMAIL].'">'.$redacteur[BAZ_CHAMPS_PRENOM].' '.$redacteur[BAZ_CHAMPS_NOM].'</a><br />'."\n";
241
	}
76 florian 242
	$res .= BAZ_NB_VUS.'<strong>'.$ligne['bf_nb_consultations'].'</strong>'.BAZ_FOIS.'<br />'."\n";
7 florian 243
	$res .= '</div>'."\n";
9 florian 244
	$res .= '<div class="bulle_bas">&nbsp;</div>'."\n";
7 florian 245
	$res .= '<div id="BAZ_bas_page">';
55 florian 246
	}
9 florian 247
 
45 florian 248
	//informations complementaires (id fiche, etat publication,... )
7 florian 249
	if ($danslappli==1) {
250
		$res .= '<span class="rubrique">'.BAZ_NUM_FICHE.':</span> '.$GLOBALS['_BAZAR_']['id_fiche'].'<br />'."\n";
251
		if ($ligne['bf_statut_fiche']==1) {
55 florian 252
			$res .= '<span class="rubrique">'.BAZ_PUBLIEE.':</span> '.BAZ_DU.' '.strftime('%d.%m.%Y',strtotime($ligne['bf_date_debut_validite_fiche'])).' '.BAZ_AU.' '.strftime('%d.%m.%Y',strtotime($ligne['bf_date_fin_validite_fiche'])).'<br />'."\n";
7 florian 253
		}
254
		else {
255
			$res .= '<span class="rubrique">'.BAZ_PUBLIEE.':</span> '.BAZ_NON.'<br />'."\n";
256
		}
55 florian 257
		$res .= '<span class="rubrique">'.BAZ_DATE_CREATION.' :</span> '.strftime('%d.%m.%Y &agrave; %H:%M',strtotime($ligne['bf_date_creation_fiche'])).'<br />'."\n";
258
		$res .= '<span class="rubrique">'.BAZ_DATE_MAJ.' :</span> '.strftime('%d.%m.%Y &agrave; %H:%M',strtotime($ligne['bf_date_maj_fiche'])).'<br />'."\n";
259
 
87 alexandre_ 260
		if ($est_admin or
261
					$GLOBALS['_BAZAR_']['annonceur']==$GLOBALS['AUTH']->getAuthData(BAZ_CHAMPS_ID)) {
9 florian 262
			$lien_modifier=$GLOBALS['_BAZAR_']['url'];
263
			$lien_modifier->addQueryString('action', BAZ_ACTION_MODIFIER);
264
			$lien_modifier->addQueryString('id_fiche', $GLOBALS['_BAZAR_']['id_fiche']);
69 alexandre_ 265
			$lien_modifier->addQueryString('typeannonce', $ligne['bf_ce_nature']);
9 florian 266
			$res .= '&nbsp;<a href="'.$lien_modifier->getURL().'">'.BAZ_MODIFIER_LA_FICHE.'</a>'."\n";
5 florian 267
		}
7 florian 268
	}
269
	$res .= '</div>'."\n";
270
	$res .= '</div>'."\n";
271
	$res .= '<div class="BAZ_cadre_fiche_bas">&nbsp;</div>'."\n";
272
	$res .= '</div>'."\n";
273
 
39 florian 274
	//on ajoute les appropriations, s'il le faut
275
	if (($danslappli==1)and($GLOBALS['_BAZAR_']['appropriation']==1)) {
276
		$res .= '<br />'."\n".'<div class="BAZ_cadre_fiche">'."\n";
277
		$res .= '<div class="BAZ_cadre_fiche_haut">&nbsp;</div>'."\n";
278
		$res .= '<div class="BAZ_cadre_fiche_corps">'."\n";
279
		$res .= '<h3>'.BAZ_LES_STRUCTURES_POSSEDANT_UNE_RESSOURCE.'</h3>'."\n";
280
 
40 florian 281
		$requete = 'SELECT '.BAZ_CHAMPS_ID.', '.BAZ_CHAMPS_NOM.' FROM bazar_appropriation,'.BAZ_ANNUAIRE.' WHERE ba_ce_id_fiche='.$GLOBALS['_BAZAR_']['id_fiche'].' AND ba_ce_id_structure='.BAZ_CHAMPS_ID.' ORDER BY '.BAZ_CHAMPS_NOM.' ASC';
282
		$resultat = $GLOBALS['_BAZAR_']['db']->query($requete) ;
283
		if (DB::isError ($resultat)) {
284
			die ($resultat->getMessage().'<br />'.$resultat->getDebugInfo()) ;
285
		}
286
		if ($resultat->numRows()>0) {
287
			$res .= BAZ_IL_Y_A.$resultat->numRows().' ';
288
			if ($resultat->numRows()==1) $res .= BAZ_COMMENTAIRE.'<br />'."\n";
289
			else $res .= BAZ_COMMENTAIRES.'<br />'."\n";
290
			while ($ligne = $resultat->fetchRow(DB_FETCHMODE_ASSOC)) {
291
				$res .= '<div class="bulle_haut">&nbsp;</div>'."\n";
292
				$res .= '<div class="bulle_corps">'."\n";
293
				//affichage du commentaire
294
				$res .= $ligne['bc_commentaire'].'<br />'."\n";
295
				$res .= '</div>'."\n";
296
				$res .= '<div class="bulle_bas">'."\n";
297
				$res .= '<div style="font-size:9px;margin-left:10px;">'.BAZ_PAR.' : <strong>'.$ligne['bc_nom'].'</strong>'.BAZ_ECRIT_LE.$ligne['bc_date'].'</div>'."\n";
298
				//pour les identifiés seulement, administrateurs de la rubrique ou superadmins
299
				if ($est_admin==1) {
300
					$url_comment= $GLOBALS['_BAZAR_']['url'];
301
					$url_comment->addQueryString('action', BAZ_VOIR_FICHE);
302
					$url_comment->addQueryString('id_fiche', $GLOBALS['_BAZAR_']['id_fiche']);
303
					$url_comment->addQueryString('id_commentaire', $ligne['bc_id_commentaire']);
304
					$res .= '<a href="'.$url_comment->getURL().'" style="font-size:9px;float:right;">'.BAZ_SUPPRIMER.'</a>'."\n";
305
				}
306
				$res .= '</div>'."\n";
307
			}
308
		}
309
		else $res .= BAZ_PAS_D_APPROPRIATION.'<br /><br />'."\n";
310
 
39 florian 311
		$res .= '</div>'."\n";
312
		$res .= '<div class="BAZ_cadre_fiche_bas">&nbsp;</div>'."\n";
313
		$res .= '</div>'."\n";
314
	}
315
 
7 florian 316
	//on ajoute les commentaires, s'il le faut
22 florian 317
	if (($danslappli==1)and($GLOBALS['_BAZAR_']['commentaire']==1)) {
39 florian 318
		$res .= '<br />'."\n".'<div class="BAZ_cadre_fiche">'."\n";
7 florian 319
		$res .= '<div class="BAZ_cadre_fiche_haut">&nbsp;</div>'."\n";
320
		$res .= '<div class="BAZ_cadre_fiche_corps">'."\n";
321
		$res .= '<h3>'.BAZ_LES_COMMENTAIRES.'</h3>'."\n";
322
		$requete = 'SELECT * FROM bazar_commentaires WHERE bc_ce_id_fiche='.$GLOBALS['_BAZAR_']['id_fiche'].' ORDER BY bc_date ASC';
5 florian 323
		$resultat = $GLOBALS['_BAZAR_']['db']->query($requete) ;
7 florian 324
		if (DB::isError ($resultat)) {
325
			die ($resultat->getMessage().'<br />'.$resultat->getDebugInfo()) ;
5 florian 326
		}
327
		if ($resultat->numRows()>0) {
9 florian 328
			$res .= BAZ_IL_Y_A.$resultat->numRows().' ';
329
			if ($resultat->numRows()==1) $res .= BAZ_COMMENTAIRE.'<br />'."\n";
330
			else $res .= BAZ_COMMENTAIRES.'<br />'."\n";
5 florian 331
			while ($ligne = $resultat->fetchRow(DB_FETCHMODE_ASSOC)) {
9 florian 332
				$res .= '<div class="bulle_haut">&nbsp;</div>'."\n";
333
				$res .= '<div class="bulle_corps">'."\n";
334
				//affichage du commentaire
335
				$res .= $ligne['bc_commentaire'].'<br />'."\n";
336
				$res .= '</div>'."\n";
337
				$res .= '<div class="bulle_bas">'."\n";
15 florian 338
				$res .= '<div style="font-size:9px;margin-left:10px;">'.BAZ_PAR.' : <strong>'.$ligne['bc_nom'].'</strong>'.BAZ_ECRIT_LE.$ligne['bc_date'].'</div>'."\n";
9 florian 339
				//pour les identifiés seulement, administrateurs de la rubrique ou superadmins
340
				if ($est_admin==1) {
341
					$url_comment= $GLOBALS['_BAZAR_']['url'];
342
					$url_comment->addQueryString('action', BAZ_VOIR_FICHE);
343
					$url_comment->addQueryString('id_fiche', $GLOBALS['_BAZAR_']['id_fiche']);
15 florian 344
					$url_comment->addQueryString('id_commentaire', $ligne['bc_id_commentaire']);
345
					$res .= '<a href="'.$url_comment->getURL().'" style="font-size:9px;float:right;">'.BAZ_SUPPRIMER.'</a>'."\n";
9 florian 346
				}
347
				$res .= '</div>'."\n";
5 florian 348
			}
349
		}
9 florian 350
		else $res .= BAZ_PAS_DE_COMMENTAIRES.'<br /><br />'."\n";
351
 
352
		//formulaire des commentaires
353
		$form_commentaire = new HTML_QuickForm('commentaire', 'post', $url);
354
		$squelette =& $form_commentaire->defaultRenderer();
355
		$squelette->setFormTemplate("\n".'<form {attributes}>'."\n".'{content}'."\n".'</form>'."\n");
356
		$squelette->setElementTemplate( '<label style="width:200px;">{label}&nbsp;</label><br />'."\n".'{element}<br />'."\n");
357
		$squelette->setRequiredNoteTemplate("\n".'{requiredNote} '."\n");
358
		$option=array('style'=>'width:300px;', 'maxlength'=>100);
359
		$form_commentaire->addElement('text', 'Nom', BAZ_ENTREZ_VOTRE_NOM, $option);
360
		$option=array('style'=>'width:100%;height:100px;white-space: pre;padding:3px;');
116 florian 361
		require_once PAP_CHEMIN_API_PEAR.'HTML/QuickForm/textarea.php';
9 florian 362
		$formtexte= new HTML_QuickForm_textarea('Commentaire', BAZ_ENTREZ_VOTRE_COMMENTAIRE, $option);
363
		$form_commentaire->addElement($formtexte) ;
364
		$form_commentaire->addElement('submit', 'Envoyer', BAZ_ENVOYER);
365
		$form_commentaire->addRule('Nom', BAZ_NOM_REQUIS, 'required', '', 'client') ;
366
		$form_commentaire->addRule('Commentaire', BAZ_COMMENTAIRE_REQUIS, 'required', '', 'client') ;
367
		$form_commentaire->setRequiredNote(BAZ_CHAMPS_REQUIS) ;
368
		$res .= $form_commentaire->toHTML();
369
 
7 florian 370
		$res .= '</div>'."\n";
371
		$res .= '<div class="BAZ_cadre_fiche_bas">&nbsp;</div>'."\n";
372
		$res .= '</div>'."\n";
373
	}
374
 
5 florian 375
	return $res ;
376
}
377
 
378
 
379
/** RSSversHTML () transforme un flux RSS (en XML) en page HTML
380
*
381
*   On passe en paramètre le contenu du flux RSS, on affiche ou non la description,
382
*   et on choisit de format de la date à l'affichage. On a en sortie du code HTML à afficher
383
*
384
*   @param  string   le contenu du flux RSS
385
*   @param  boolean  afficher ou non la description
386
*   @param  string  choisir le format de date: jmah (12/02/2004 12h34) jmh (12/02 12h34) jma (12/02/2004) jm (12/02) ou rien
387
*
388
*   @return  string    le code HTML
389
*/
64 florian 390
function RSSversHTML($rss, $voirdesc, $formatdate, $affichenb) {
5 florian 391
	if ($rss!='') {
54 florian 392
		$rawitems='';$title='';$url='';$cat='';$date='';
5 florian 393
		$res='';
394
		if( eregi('<item>(.*)</item>', $rss, $rawitems ) ) {
395
			$items = explode('<item>', $rawitems[0]);
83 alexandre_ 396
			$res.='<ul id="BAZ_liste_fiche">'."\n";
5 florian 397
			for( $i = 0; $i < count($items)-1; $i++ ) {
398
				eregi('<title>(.*)</title>',$items[$i+1], $title );
399
				eregi('<link>(.*)</link>',$items[$i+1], $url );
400
				eregi('<description>(.*)</description>',$items[$i+1], $cat);
401
				eregi('<pubDate>(.*)</pubDate>',$items[$i+1], $date);
402
				$res.='<li>';
403
				if ($formatdate=='jm') {$res.=strftime('%d.%m',strtotime($date[1])).': ';}
404
				if ($formatdate=='jma') {$res.=strftime('%d.%m.%Y',strtotime($date[1])).': ';}
405
				if ($formatdate=='jmh') {$res.=strftime('%d.%m %H:%M',strtotime($date[1])).': ';}
406
				if ($formatdate=='jmah') {$res.=strftime('%d.%m.%Y %H:%M',strtotime($date[1])).': ';}
72 alexandre_ 407
				$res.='<a href="'.preg_replace ('/&amp;/', '&', $url[1]).'">'.$title[1].'</a>';
5 florian 408
				if ($voirdesc) {$res.=$cat[1];}
72 alexandre_ 409
				// Ajout du bouton supprimer pour les superadministrateur
98 florian 410
				if (($GLOBALS['AUTH']->getAuth() && niveau_droit(0,$GLOBALS['AUTH']->getAuthData(BAZ_CHAMPS_ID))=='superadministrateur')and($url[1]!='#')) {
72 alexandre_ 411
					$mon_url = preg_replace ('/&amp;/', '&', $url[1]) ;
412
					$url_suppr = new Net_URL(preg_replace ('/&amp;/', '&', $mon_url)) ;
413
					$url_suppr->addQueryString('action', BAZ_ACTION_SUPPRESSION) ;
414
		        	$res .= ' ( <a href="'.$url_suppr->getURL().
415
							'" onclick="javascript:return confirm(\''.BAZ_SUPPRIMER.' ?\');">'.
416
							BAZ_SUPPRIMER.'</a> )'."\n" ;
417
					}
5 florian 418
				$res.='</li>'."\n";
419
			}
420
			$res.='</ul>'."\n";
64 florian 421
			if ($affichenb==1) {
422
				//une annonce trouvee, on accorde au singulier
423
				if (((count($items)-1)==1)and($title!=BAZ_PAS_D_ANNONCES)) {
424
					$res = '<br /><h4>'.BAZ_IL_Y_A.' 1 '.BAZ_FICHE_CORRESPONDANTE.'</h4><br />'."\n".$res;
425
				}
426
				//plusieures annonces trouvees, on accorde au pluriel
427
				else {
428
					$res = '<br /><h4>'.BAZ_IL_Y_A.(count($items)-1).' '.BAZ_FICHES_CORRESPONDANTES.'</h4><br />'."\n".$res;
429
				}
430
			}
431
			//cas des fiches pas trouvées
432
			if (((count($items)-1)==1)and($title[1]==BAZ_PAS_D_ANNONCES)) {
433
				$res = '<br /><h4>'.BAZ_PAS_D_ANNONCES.'</h4><br />'."\n";
434
			}
5 florian 435
		}
436
	}
437
	else $res = BAZ_PAS_D_ANNONCES;
438
	return $res;
439
}
440
 
83 alexandre_ 441
/** gen_RSS() - generer un fichier de flux RSS par type d'annonce
5 florian 442
*
443
* @param   string Le type de l'annonce (laisser vide pour tout type d'annonce)
444
* @param   integer Le nombre d'annonces a regrouper dans le fichier XML (laisser vide pour toutes)
445
* @param   integer L'identifiant de l'emetteur (laisser vide pour tous)
68 florian 446
* @param   integer L'etat de validation de l'annonce (laisser 1 pour les annonces validees, 0 pour les non-validees)
447
* @param   string La requete SQL personnalisee
5 florian 448
*
449
* @return  string Le code du flux RSS
450
*/
115 alexandre_ 451
function gen_RSS($typeannonce='', $nbitem='', $emetteur='', $valide=1, $requeteSQL='', $requeteSQLFrom = '') {
64 florian 452
	// generation de la requete MySQL personnalisee
453
	$req_where=0;
83 alexandre_ 454
	$requete = 'SELECT DISTINCT bf_id_fiche, bf_titre, bf_date_debut_validite_fiche '.
115 alexandre_ 455
				'FROM bazar_fiche, bazar_nature '.$requeteSQLFrom.' WHERE ';
64 florian 456
	if ($valide!=2) {
457
		$requete .= 'bf_statut_fiche='.$valide;
458
		$req_where=1;
459
	}
5 florian 460
	$nomflux=BAZ_DERNIERE_ACTU;
93 alexandre_ 461
	if (!is_array ($typeannonce) && $typeannonce!='' and $typeannonce!='toutes') {
64 florian 462
		if ($req_where==1) {$requete .= ' AND ';}
463
		$requete .= 'bf_ce_nature='.$typeannonce;
464
		$req_where=1;
5 florian 465
		//le nom du flux devient le type d'annonce
466
		$nomflux = $typeannonce;
467
	}
93 alexandre_ 468
	// Cas où il y plusieurs type d annonce demande
469
	if (is_array ($typeannonce)) {
470
		if ($req_where==1) {$requete .= ' AND ';}
471
		$requete .= 'bf_ce_nature IN (' ;
472
		$chaine = '';
473
		foreach ($typeannonce as $valeur) $chaine .= '"'.$valeur.'",' ;
474
		$requete .= substr ($chaine, 0, strlen ($chaine)-1) ;
95 alexandre_ 475
		$requete .= ') ';
93 alexandre_ 476
	}
111 alexandre_ 477
	$utilisateur = new Administrateur_bazar ($GLOBALS['AUTH']) ;
64 florian 478
	if ($valide!=0) {
96 alexandre_ 479
 
95 alexandre_ 480
		if ($utilisateur->isSuperAdmin()) {
96 alexandre_ 481
			$req_where=1;
83 alexandre_ 482
		} else {
96 alexandre_ 483
			if ($req_where==1) {
484
				$requete .= ' AND ';
485
			}
83 alexandre_ 486
			$requete .= '(bf_date_debut_validite_fiche<=NOW() or bf_date_debut_validite_fiche="0000-00-00")'.
487
						' AND (bf_date_fin_validite_fiche>=NOW() or bf_date_fin_validite_fiche="0000-00-00") AND bn_id_nature=bf_ce_nature';
488
		}
64 florian 489
	}
5 florian 490
	else $nomflux .= BAZ_A_MODERER;
69 alexandre_ 491
	if ($emetteur!='' && $emetteur!='tous') {
64 florian 492
		if ($req_where==1) {$requete .= ' AND ';}
493
		$requete .= 'bf_ce_utilisateur='.$emetteur;
494
		$req_where=1;
5 florian 495
		//requete pour afficher le nom de la structure
69 alexandre_ 496
		$requetenom = 'SELECT '.BAZ_CHAMPS_NOM.', '.BAZ_CHAMPS_PRENOM.' FROM '.
497
						BAZ_ANNUAIRE.' WHERE '.BAZ_CHAMPS_ID.'='.$emetteur;
5 florian 498
		$resultat = $GLOBALS['_BAZAR_']['db']->query($requetenom) ;
499
		if (DB::isError($resultat)) {
69 alexandre_ 500
			echo ($resultat->getMessage().$resultat->getDebugInfo()) ;
5 florian 501
		}
502
		$ligne = $resultat->fetchRow(DB_FETCHMODE_ASSOC);
503
		$nomflux .= ' ('.$ligne[BAZ_CHAMPS_NOM].' '.$ligne[BAZ_CHAMPS_PRENOM].')';
504
	}
64 florian 505
	if ($requeteSQL!='') {
506
		if ($req_where==1) {$requete .= ' AND ';}
507
		$requete .= '('.$requeteSQL.')';
508
		$req_where=1;
509
	}
22 florian 510
	$requete .= ' ORDER BY  bf_date_debut_validite_fiche DESC, bf_date_fin_validite_fiche DESC, bf_date_maj_fiche DESC';
5 florian 511
	if ($nbitem!='') {$requete .= ' LIMIT 0,'.$nbitem;}
512
	$resultat = $GLOBALS['_BAZAR_']['db']->query($requete) ;
513
	if (DB::isError($resultat)) {
83 alexandre_ 514
		die ($resultat->getMessage().$resultat->getDebugInfo()) ;
5 florian 515
	}
64 florian 516
	// En-tete du flux RSS version 2.0
5 florian 517
	$xml = '<?xml version="1.0" encoding="ISO-8859-1"?>'."\n".'<rss version="2.0">'."\n";
518
	$xml .= '<channel>'."\n".'<title>'.$nomflux.'</title>'."\n".'<link>'.BAZ_RSS_ADRESSESITE.'</link>'."\n";
519
	$xml .= '<description>'.BAZ_RSS_DESCRIPTIONSITE.'</description>'."\n".'<language>fr-FR</language>'."\n".
520
	'<copyright>Copyright 2005 '.BAZ_RSS_NOMSITE.'</copyright>'."\n";
521
	// Ajout de la date actuelle de publication (suivant la DTD RSS)
522
	$xml .= '<lastBuildDate>'.strftime('%d %b %Y %H:%M:%S GMT').'</lastBuildDate>'."\n";
64 florian 523
	// En-tete suite et fin
5 florian 524
	$xml .= '<docs>http://www.stervinou.com/projets/rss/</docs>'."\n".'<category>'.BAZ_RSS_CATEGORIE.'</category>'."\n".
525
	'<managingEditor>'.BAZ_RSS_MANAGINGEDITOR.'</managingEditor>'."\n".'<webMaster>'.BAZ_RSS_WEBMASTER.'</webMaster>'."\n";
526
	$xml .= '<ttl>60</ttl>'."\n".'<image>'."\n".'<title>'.BAZ_RSS_NOMSITE.'</title>'."\n".'<url>'.BAZ_RSS_LOGOSITE.'</url>'."\n".
527
	'<link>'.BAZ_RSS_ADRESSESITE.'</link>'."\n".'</image>'."\n";
528
	if ($resultat->numRows()>0) {
529
		// Creation des items : titre + lien + description + date de publication
530
		while ($ligne = $resultat->fetchRow(DB_FETCHMODE_ASSOC)) {
531
			$xml .= '<item>'."\n";
532
			$xml .= '<title>'.$ligne['bf_titre'].'</title>'."\n";
533
			$lien=$GLOBALS['_BAZAR_']['url'];
534
			$lien->addQueryString('action', BAZ_VOIR_FICHE);
535
			$lien->addQueryString('id_fiche', $ligne['bf_id_fiche']);
536
			$xml .= '<link>'.str_replace ('&', '&amp;', $lien->getURL()).'</link>'."\n";
87 alexandre_ 537
			$xml .= '<description>'."\n".'<![CDATA[' ;
538
			if ($_GET['action'] != BAZ_VOIR_TOUTES_ANNONCES) {
539
				$xml .= baz_voir_fiche(0,$ligne['bf_id_fiche']) ;
540
			}
541
			$xml .= ']]>'."\n".'</description>'."\n";
5 florian 542
			$xml .= '<pubDate>'.strftime('%d %b %Y %H:%M:%S GMT',strtotime($ligne['bf_date_debut_validite_fiche'])).'</pubDate>'."\n";
543
			$xml .= '</item>'."\n";
544
		}
545
	}
546
	else {//pas d'annonces
547
		$xml .= '<item>'."\n";
10 ddelon 548
		$xml .= '<title>'.BAZ_PAS_D_ANNONCES.'</title>'."\n";
22 florian 549
		$xml .= '<link>#</link>'."\n";
10 ddelon 550
		$xml .= '<description>'.BAZ_PAS_D_ANNONCES.'</description>'."\n";
5 florian 551
		$xml .= '<pubDate>'.strftime('%d %b %Y %H:%M:%S GMT',strtotime('12/12/2004')).'</pubDate>'."\n";
552
		$xml .= '</item>'."\n";
553
	}
554
	$xml .= '</channel>'."\n".'</rss>'."\n";
555
	return $xml;
556
}
557
 
558
 
559
/** baz_liste() Formate la liste de toutes les annonces actuelles
560
*
64 florian 561
*   @return  string    le code HTML a afficher
5 florian 562
*/
563
function baz_liste($typeannonce='toutes') {
45 florian 564
	//creation du lien pour le formulaire de recherche
22 florian 565
	$GLOBALS['_BAZAR_']['url']->addQueryString('action', BAZ_VOIR_TOUTES_ANNONCES);
93 alexandre_ 566
	$lien_formulaire = preg_replace ('/&amp;/', '&', $GLOBALS['_BAZAR_']['url']->getURL()) ;
22 florian 567
	$formtemplate = new HTML_QuickForm('formulaire', 'post', $lien_formulaire) ;
93 alexandre_ 568
	$squelette = &$formtemplate->defaultRenderer();
569
	$squelette->setFormTemplate("\n".'<form{attributes}>'."\n".'<ul style="padding:0;margin:0;">'."\n".
570
								'{content}'."\n".'</ul>'."\n".'</form>'."\n");
39 florian 571
	$squelette->setElementTemplate( '<li class="enligne">'."\n".'{element}'."\n".'</li>'."\n");
64 florian 572
 
573
	//cas du formulaire de recherche proposant de chercher parmis tous les types d'annonces
93 alexandre_ 574
	//requete pour obtenir l'id et le label des types d'annonces
575
	$requete = 'SELECT bn_id_nature, bn_label_nature '.
113 alexandre_ 576
	           'FROM bazar_nature WHERE bn_ce_id_menu='.$GLOBALS['_BAZAR_']['filtre'].' '.
93 alexandre_ 577
			   'ORDER BY bn_label_nature ASC';
578
	$resultat = $GLOBALS['_BAZAR_']['db']->query($requete) ;
579
	if (DB::isError($resultat)) {
580
		die ($resultat->getMessage().$resultat->getDebugInfo()) ;
581
	}
582
	$type_annonce_select['toutes']=BAZ_TOUS_TYPES_FICHES;
583
	while ($ligne = $resultat->fetchRow(DB_FETCHMODE_ASSOC)) {
105 florian 584
		$type_annonce_select[$ligne['bn_id_nature']] = $ligne['bn_label_nature'];
93 alexandre_ 585
		$tableau_typeannonces[] = $ligne['bn_id_nature'] ;
586
	}
68 florian 587
	if ($GLOBALS['_BAZAR_']['typeannonce']=='toutes') {
64 florian 588
		$res= '<h2>'.BAZ_TOUTES_LES_ANNONCES.'</h2><br />'."\n";
115 alexandre_ 589
		$option=array('style'=>'border:1px solid #000;width: 140px;font:12px Myriad, Arial, sans-serif;',
590
						'onchange' => 'javascript:this.form.submit();');
64 florian 591
		$formtemplate->addElement ('select', 'nature', BAZ_TYPEANNONCE, $type_annonce_select, $option) ;
22 florian 592
	}
64 florian 593
	//cas du type d'annonces prédéfini
594
	else {
105 florian 595
		$res = '<h2>'.BAZ_TOUTES_LES_ANNONCES_DE_TYPE.' '.$GLOBALS['_BAZAR_']['typeannonce'].'</h2>'."\n";
22 florian 596
	}
83 alexandre_ 597
 
598
 
64 florian 599
	//requete pour obtenir l'id, le nom et prenom de toutes les personnes ayant depose une fiche
93 alexandre_ 600
	// dans le but de construire l'élément de formulaire select avec les noms des émetteurs de fiche
601
 
602
	if (BAZ_RECHERCHE_PAR_EMETTEUR) {
603
		$requete = 'SELECT '.BAZ_CHAMPS_ID.', '.BAZ_CHAMPS_NOM.', '.BAZ_CHAMPS_PRENOM.' '.
604
		           'FROM bazar_fiche,'.BAZ_ANNUAIRE.' where' ;
605
 
606
		$requete .= ' bf_date_debut_validite_fiche<=NOW() AND bf_date_fin_validite_fiche>=NOW() and';
607
 
608
		$requete .= ' bf_ce_utilisateur='.BAZ_CHAMPS_ID.' ';
609
	    if (!isset($_REQUEST['nature'])) {
610
	    	if (isset($GLOBALS['_BAZAR_']['id_typeannonce'])) {
611
	    		$requete .= 'AND bf_ce_nature="'.$GLOBALS['_BAZAR_']['id_typeannonce'].'" ';
612
	    	}
613
	    }
614
	    else {
615
	    	if ($_REQUEST['nature']!='toutes') {
616
	    		$requete .= 'AND bf_ce_nature='.$_REQUEST['nature'].' ';
617
	    	}
618
	    }
619
 
620
	    $requete .= 'ORDER BY '.BAZ_CHAMPS_NOM.' ASC';
621
		$resultat = $GLOBALS['_BAZAR_']['db']->query($requete) ;
622
		if (DB::isError($resultat)) {
623
			die ($resultat->getMessage().$resultat->getDebugInfo()) ;
624
		}
625
		$personnes_select['tous']=BAZ_TOUS_LES_EMETTEURS;
626
		while ($ligne = $resultat->fetchRow(DB_FETCHMODE_ASSOC)) {
627
			$personnes_select[$ligne[BAZ_CHAMPS_ID]] = $ligne[BAZ_CHAMPS_NOM]." ".$ligne[BAZ_CHAMPS_PRENOM] ;
628
		}
629
		$option=array('style'=>'border:1px solid #000;width: 140px;font:12px Myriad, Arial, sans-serif;');
630
		$formtemplate->addElement ('select', 'personnes', BAZ_EMETTEUR, $personnes_select, $option) ;
631
	} else {
632
		$formtemplate->addElement ('hidden', 'personnes', 'tous') ;
22 florian 633
	}
93 alexandre_ 634
 
83 alexandre_ 635
		//pour les super-administrateurs, on peut voir les annonces non validées
64 florian 636
	//on verifie si l'utilisateur est administrateur
111 alexandre_ 637
	$utilisateur = new Administrateur_bazar($GLOBALS['AUTH']) ;
83 alexandre_ 638
 
93 alexandre_ 639
	if ($utilisateur->isSuperAdmin()) {
64 florian 640
		$option=array('style'=>'border:1px solid #000;width: 60px;font:12px Myriad, Arial, sans-serif;');
641
		$valide_select[0] = BAZ_FICHES_PAS_VALIDEES;
642
		$valide_select[1] = BAZ_FICHES_VALIDEES;
643
		$valide_select[2] = BAZ_LES_DEUX;
644
		$formtemplate->addElement ('select', 'valides', BAZ_VALIDE, $valide_select, $option) ;
98 florian 645
		$defauts=array('valides'=>1);
64 florian 646
		$formtemplate->setDefaults($defauts);
647
	}
648
 
649
	//champs texte pour entrer les mots cles
650
	$option=array('maxlength'=>60,'style'=>'border:1px solid #000;width:100px;font:12px Myriad, Arial, sans-serif;');
22 florian 651
	$formtemplate->addElement('text', 'recherche_mots_cles', BAZ_MOT_CLE, $option) ;
652
	$defauts=array('recherche_mots_cles'=>BAZ_MOT_CLE);
653
	$formtemplate->setDefaults($defauts);
64 florian 654
 
655
	//option cachee pour savoir si le formulaire a ete appele deja
656
	$formtemplate->addElement('hidden', 'recherche_effectuee', 1) ;
657
 
115 alexandre_ 658
	// Ajout des options si un type de fiche a ete choisie
659
	if (isset($_POST['nature']) || isset($GLOBALS['_BAZAR_']['categorie_nature'])) {
660
		if ($GLOBALS['_BAZAR_']['categorie_nature'] != '') {
661
			$champs_requete = 'bn_ce_id_menu' ;
662
			$_POST['nature'] = $GLOBALS['_BAZAR_']['categorie_nature'];
663
		} else {
664
			$champs_requete = 'bn_id_nature' ;
665
		}
666
		// Récupération du template
667
		$requete = 'select bn_template from bazar_nature where '.$champs_requete.'='.$_POST['nature'];
668
		$resultat = $GLOBALS['_BAZAR_']['db']->getOne($requete) ;
669
		if (DB::isError($resultat)) {
670
			die ($resultat->getMessage().$resultat->getDebugInfo()) ;
671
		}
672
 
673
		$tableau = baz_valeurs_template($resultat) ;
674
 
675
		for ($i=0; $i<count($tableau); $i++) {
116 florian 676
			if (($tableau[$i]['type'] == 'liste' || $tableau[$i]['type'] == 'checkbox') && $tableau[$i]['recherche'] == 1) {
115 alexandre_ 677
				if ($tableau[$i]['type'] == 'checkbox') {
678
					$formtemplate->addElement ('html', '<br />'.$tableau[$i]['label'].'<br />') ;
679
				}
680
				$tableau[$i]['type']($formtemplate, $tableau[$i]['nom_bdd'], $tableau[$i]['label'], $tableau[$i]['limite1'],
681
		                         $tableau[$i]['limite2'], $tableau[$i]['defaut'], $tableau[$i]['table_source'], $tableau[$i]['obligatoire']) ;
682
			}
683
		 }
684
	}
22 florian 685
	//Bouton de validation du formulaire
107 florian 686
	$option=array('style'=>'border:1px solid #000;width:80px;font:12px Myriad, Arial, sans-serif;');
687
	$bouton[] = &HTML_QuickForm::createElement('submit', 'rechercher', BAZ_RECHERCHER, $option);
22 florian 688
	$formtemplate->addGroup($bouton, null, null, '');
64 florian 689
 
690
	//affichage du formulaire
23 florian 691
	$res.=$formtemplate->toHTML()."\n";
64 florian 692
 
115 alexandre_ 693
	// Ajout de la table bazar_fiche_liste_valeur dans le from de la requete
694
	$case_coche = false ;
695
	$requeteFrom = '' ;
696
	$requeteWhere = '' ;
697
	$requeteWhereListe = '' ;
698
 
699
 	for ($i = 0; $i < count ($tableau); $i++) {
700
		if ($tableau[$i]['type'] == 'checkbox' || $tableau[$i]['type'] == 'liste') {
701
			$nom_liste = $tableau[$i]['type'].$tableau[$i]['nom_bdd'] ;
702
 
703
			if (is_array($_POST[$nom_liste])) {
704
				foreach ($_POST[$nom_liste] as $cle =>$valeur) {
705
					echo  $valeur ;
706
					if ($valeur == 1) {
707
						$case_coche = true ;
708
						$requeteWhereListe .= ' AND bfvl_ce_liste='.$tableau[$i]['nom_bdd'] ; // Numéro de la liste
709
 
710
					}
711
				}
712
			}
713
		}
714
	}
715
	if ($case_coche) {
716
		$requeteFrom = ', bazar_fiche_valeur_liste ' ;
717
		$requeteWhereListe .= ' AND bfvl_valeur IN ()' ;
718
		$requeteWhere = ' bfvl_ce_fiche=bf_id_fiche'.$requeteWhereListe;
719
	}
720
 
64 florian 721
	//affichage des resultats de la recherche si le formulaire a ete envoye
87 alexandre_ 722
	$requeteSQL='';
64 florian 723
	if (isset($_REQUEST['recherche_effectuee'])) {
724
		//preparation de la requete pour trouver les mots cles
23 florian 725
		if (($_POST['recherche_mots_cles']!='')and($_POST['recherche_mots_cles']!=BAZ_MOT_CLE)) {
64 florian 726
			//decoupage des mots cles
22 florian 727
			$recherche = split(' ', $_POST['recherche_mots_cles']) ;
64 florian 728
			$nbmots=count($recherche);
729
			$requeteSQL='';
22 florian 730
			for ($i=0; $i<$nbmots; $i++) {
731
				if ($i>0) $requeteSQL.=' OR ';
732
				$requeteSQL.='bf_titre LIKE "%'.$recherche[$i].'%" OR bf_description LIKE "%'.$recherche[$i].'%" ';
733
			}
734
		}
93 alexandre_ 735
		if (!isset($_REQUEST['nature'])) {
736
			if (!isset ($GLOBALS['_BAZAR_']['id_nature'])) $typedefiches = $tableau_typeannonces;
737
			else $typedefiches = $GLOBALS['_BAZAR_']['id_nature'] ;
738
		} else {
739
			$typedefiches = $_REQUEST['nature'] ;
740
			if ($typedefiches == 'toutes') $typedefiches = $tableau_typeannonces ;
741
		}
97 florian 742
		if ($typeannonce!='toutes') $typedefiches=$typeannonce;
64 florian 743
		if (isset($_POST['valides'])) {$valides=$_POST['valides'];}
744
		else {$valides=1;}
745
		//generation de la liste de flux a afficher
69 alexandre_ 746
 
115 alexandre_ 747
		$res .= RSSversHTML(gen_RSS($typedefiches, '', $_POST['personnes'], $valides, $requeteSQL, $requeteFrom),
107 florian 748
							 0, BAZ_TYPE_AFFICHAGE_LISTE, 1) ;
22 florian 749
	}
750
	else {
23 florian 751
		//on affiche toutes les annonces
107 florian 752
		$res .= '<br /><p class="zone_info">'."\n".BAZ_ENTRER_VOS_CRITERES_DE_RECHERCHE.'</p>'."\n";
753
		$GLOBALS['_BAZAR_']['url']->removeQueryString('action');
754
		$GLOBALS['_BAZAR_']['url']->addQueryString('action', BAZ_VOIR_FLUX_RSS);
755
		$GLOBALS['_BAZAR_']['url']->addQueryString('annonce', 'toutes');
756
		$res .= '{{Syndication titre="Les derni&egrave;res fiches enregistrées" url="'.$GLOBALS['_BAZAR_']['url']->getURL().'" nb=10 nouvellefenetre=0 formatdate="'.BAZ_TYPE_AFFICHAGE_LISTE.'"}}';
22 florian 757
	}
5 florian 758
	return $res;
759
}
23 florian 760
?>