Subversion Repositories Applications.bazar

Rev

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

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