Subversion Repositories Applications.bazar

Rev

Rev 9 | Rev 13 | 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
*
4
* @param   string nom du fichier de template
5
*
6
* @return   mixed  tableau contenant les champs du fichier template
7
*/
8
function baz_valeurs_template($fichier_template) {
9
	//Parcours du fichier de templates, pour mettre les champs spécifiques
10
	$nblignes=0;
11
	$fichier=file_get_contents(BAZ_CHEMIN_APPLI.'templates/'.$fichier_template);
12
	$chaine = explode ("\n", $fichier);
13
	array_pop($chaine);
14
	foreach ($chaine as $ligne)  {
15
		$souschaine = explode ("***", $ligne) ;
16
		$tableau[$nblignes]['type'] = trim($souschaine[0]) ;
17
		if (isset($souschaine[1])) {$tableau[$nblignes]['nom_bdd'] = trim($souschaine[1]);}
18
		else {$tableau[$nblignes]['nom_bdd'] ='';}
19
		if (isset($souschaine[2])) $tableau[$nblignes]['label'] = trim($souschaine[2]);
20
		else {$tableau[$nblignes]['label'] ='';}
21
		if (isset($souschaine[3])) $tableau[$nblignes]['limite1'] = trim($souschaine[3]);
22
		else {$tableau[$nblignes]['limite1'] ='';}
23
		if (isset($souschaine[4])) $tableau[$nblignes]['limite2'] = trim($souschaine[4]);
24
		else {$tableau[$nblignes]['limite2'] ='';}
25
		if (isset($souschaine[5])) $tableau[$nblignes]['defaut'] = trim($souschaine[5]);
26
		else {$tableau[$nblignes]['defaut'] ='';}
27
		if (isset($souschaine[6])) $tableau[$nblignes]['table_source'] = trim($souschaine[6]);
28
		else {$tableau[$nblignes]['table_source'] ='';}
29
		if (isset($souschaine[7])) $tableau[$nblignes]['id_source'] = trim($souschaine[7]);
30
		else {$tableau[$nblignes]['id_source'] ='';}
31
		if (isset($souschaine[8])) $tableau[$nblignes]['obligatoire'] = trim($souschaine[8]);
32
		else {$tableau[$nblignes]['obligatoire'] ='';}
33
		$nblignes++;
34
	}
35
	return $tableau;
36
}
37
 
38
 
39
/**  baz_voir_fiche() - Permet de visualiser en détail une fiche  au format XHTML
40
*
41
* @global boolean Rajoute des informations internes à l'application (date de modification, lien vers la page de départ de l'appli) si à 1
42
* @global integer Identifiant de la fiche à afficher
43
*
44
* @return   string  HTML
45
*/
46
function baz_voir_fiche($danslappli, $idfiche='') {
47
	if (isset($_GET['id_fiche'])) $GLOBALS['_BAZAR_']['id_fiche']=$_GET['id_fiche'];
48
	if ($idfiche!='') $GLOBALS['_BAZAR_']['id_fiche']=$idfiche;
49
 
9 florian 50
	$url= $GLOBALS['_BAZAR_']['url'];
51
	$url->addQueryString('action', BAZ_VOIR_FICHE);
52
	$url->addQueryString('id_fiche', $GLOBALS['_BAZAR_']['id_fiche']);
53
	$url = preg_replace ('/&amp;/', '&', $url->getURL()) ;
7 florian 54
 
9 florian 55
	//cas ou un commetaire a été entré
56
	if (isset($_POST['Nom'])) {
57
		$requete = 'INSERT INTO bazar_commentaires VALUES ('.$GLOBALS['_BAZAR_']['id_fiche'].', "'.$_POST['Nom'].'", "'.$_POST['Commentaire'].'", NOW() )';
58
		$resultat = $GLOBALS['_BAZAR_']['db']->query($requete) ;
59
	}
60
	else {
61
		//sinon on met à jour le nb de visites pour la fiche, puisque c'est une simple consultation
62
		$requete = 'UPDATE bazar_fiche SET bf_nb_consultations=bf_nb_consultations+1 WHERE bf_id_fiche='.$GLOBALS['_BAZAR_']['id_fiche'];
63
		$resultat = $GLOBALS['_BAZAR_']['db']->query($requete) ;
64
	}
65
 
7 florian 66
	//on cherche le type d'annonce, l'annonceur et les stats
67
	$requete = 'SELECT bn_label_nature, bn_commentaire, bn_appropriation, bf_ce_utilisateur,bf_nb_consultations  FROM bazar_fiche, bazar_nature WHERE bn_id_nature=bf_ce_nature AND bf_id_fiche='.$GLOBALS['_BAZAR_']['id_fiche'];
68
	$resultat = $GLOBALS['_BAZAR_']['db']->query($requete) ;
5 florian 69
	if (DB::isError($resultat)) {
70
		die ($resultat->getMessage().$resultat->getDebugInfo()) ;
71
	}
72
	while ($ligne = $resultat->fetchRow(DB_FETCHMODE_ASSOC)) {
73
		$GLOBALS['_BAZAR_']['typeannonce']=$ligne['bn_label_nature'];
7 florian 74
		$GLOBALS['_BAZAR_']['commentaire']=$ligne['bn_commentaire'];
75
		$GLOBALS['_BAZAR_']['appropriation']=$ligne['bn_appropriation'];
76
		$GLOBALS['_BAZAR_']['annonceur']=$ligne['bf_ce_utilisateur'];
77
		$GLOBALS['_BAZAR_']['nb_consultations']=$ligne['bf_nb_consultations'];
5 florian 78
	}
9 florian 79
 
80
	//on vérifie si l'utilisateur est administrateur
81
	$est_admin=0;
82
	if ($GLOBALS['AUTH']->getAuth()) {
83
		$requete='SELECT bn_id_nature FROM bazar_nature WHERE bn_label_nature="'.$GLOBALS['_BAZAR_']['typeannonce'].'"';
84
		$resultat = $GLOBALS['_BAZAR_']['db']->query($requete) ;
85
		if (DB::isError($resultat)) {
86
			die ($resultat->getMessage().$resultat->getDebugInfo()) ;
87
		}
88
		$result = $resultat->fetchRow(DB_FETCHMODE_ASSOC);
89
		if ((niveau_droit($result['bn_id_nature'],$GLOBALS['AUTH']->getAuthData(BAZ_CHAMPS_ID))=='administrateur')
90
		     or(niveau_droit('0',$GLOBALS['AUTH']->getAuthData(BAZ_CHAMPS_ID))=='superadministrateur'))
91
		{
92
		        $est_admin=1;
93
		}
94
	}
95
 
7 florian 96
	$res = '<div class="BAZ_cadre_fiche">'."\n";
97
	$res .= '<div class="BAZ_cadre_fiche_haut">'."\n";
5 florian 98
	$res .= '&nbsp;</div>'."\n";
7 florian 99
	$res .= '<div class="BAZ_cadre_fiche_corps">'."\n";
5 florian 100
 
101
	//si le template existe, on génère le template
102
	if ((file_exists(BAZ_CHEMIN_APPLI.'templates/'.$GLOBALS['_BAZAR_']['typeannonce'].'-fiche.php'))) {
103
		include_once(BAZ_CHEMIN_APPLI.'templates/'.$GLOBALS['_BAZAR_']['typeannonce'].'-fiche.php');
7 florian 104
		$res .=genere_fiche($GLOBALS['_BAZAR_']['id_fiche']);
5 florian 105
	}
106
	//on affiche ligne par ligne sinon
107
	else {
108
		$requete = 'SELECT * FROM bazar_fiche WHERE bf_id_fiche='.$GLOBALS['_BAZAR_']['id_fiche'];
109
		$resultat = $GLOBALS['_BAZAR_']['db']->query($requete) ;
110
		if (DB::isError ($resultat)) {
111
			die ($resultat->getMessage().'<br />'.$resultat->getDebugInfo()) ;
112
		}
113
		$ligne = $resultat->fetchRow(DB_FETCHMODE_ASSOC) ;
114
 
7 florian 115
		if (isset($ligne['bf_url_image'])) {
116
			$res .= '<div id="fiche_image">'."\n";
117
			$res .= '<img src="'.'http://'.$_SERVER['HTTP_HOST'].'/client/bazar/images/'.$ligne['bf_url_image'].'" border=0 alt="'.BAZ_TEXTE_IMG_ALTERNATIF.'" />'."\n";
118
			$res .= '</div>'."\n";
119
			$res .= '<div id="fiche_titre_image">'.$ligne['bf_titre'];
120
		}
121
		else {
122
			$res .= '<div id="fiche_titre">'.$ligne['bf_titre'];
123
		}
124
		$res .= '</div>'."\n";
125
		$res .= '<div id="BAZ_description">'.$ligne['bf_description'].'</div>'."\n";
5 florian 126
		$tableau=baz_valeurs_template($GLOBALS['_BAZAR_']['typeannonce'].'.tpl');
127
		for ($i=0; $i<count($tableau); $i++) {
128
			if (isset($ligne[$tableau[$i]['nom_bdd']])) {
129
				//pour les champs renseignés par une liste, on va chercher le label de la liste, plutot que l'id
130
				if ($tableau[$i]['type']=='liste') {
131
					$requete = 'SELECT '.$tableau[$i]['table_source'].'.* FROM bazar_fiche, '.$tableau[$i]['table_source'].
132
					' WHERE '.$tableau[$i]['nom_bdd'].'='.$tableau[$i]['id_source'].' AND bf_id_fiche='.$GLOBALS['_BAZAR_']['id_fiche'];
133
					$resultat = $GLOBALS['_BAZAR_']['db']->query($requete) ;
134
					if (DB::isError ($resultat)) {
135
						die ($resultat->getMessage().'<br />'.$resultat->getDebugInfo()) ;
136
					}
137
					while ($tab = $resultat->fetchRow()) {
7 florian 138
						$val=$tab[1];
5 florian 139
					}
140
				}
141
				else {
7 florian 142
					$val=$ligne[$tableau[$i]['nom_bdd']];
5 florian 143
				}
144
				if (($tableau[$i]['nom_bdd']!='bf_titre')and($tableau[$i]['nom_bdd']!='bf_description')) {
7 florian 145
					if ($val!='') {
146
						$res .= '<span class="rubrique">'.constant($tableau[$i]['label']).':</span>'."\n";
147
						$res .= '<span class="description"> '.$val.'</span>'."\n".'<br />'."\n";
148
					}
5 florian 149
				}
150
			}
151
		}
7 florian 152
	}
153
	//afficher les liens pour l'annonce
154
	$requete = 'SELECT  bu_url, bu_descriptif_url FROM bazar_url WHERE bu_ce_fiche='.$GLOBALS['_BAZAR_']['id_fiche'];
155
	$resultat = $GLOBALS['_BAZAR_']['db']->query($requete) ;
156
	if (DB::isError($resultat)) {
157
		die ($resultat->getMessage().$resultat->getDebugInfo()) ;
158
	}
159
	if ($resultat->numRows()>0) {
160
		$res .= '<span class="rubrique">'.BAZ_LIEN_INTERNET.':</span>'."\n";
161
		$res .= '<span class="description">'."\n";
162
		$res .= '<ul>'."\n";
163
		while ($ligne1 = $resultat->fetchRow(DB_FETCHMODE_ASSOC)) {
164
			$res .= '<li><a href="'.$ligne1['bu_url'].'" target="_blank">'.$ligne1['bu_descriptif_url'].'</a></li>'."\n";
5 florian 165
		}
7 florian 166
		$res .= '</ul></span>'."\n";
167
	}
168
 
169
	//afficher les fichiers pour l'annonce
170
	$requete = 'SELECT  bfj_description, bfj_fichier FROM bazar_fichier_joint WHERE bfj_ce_fiche='.$GLOBALS['_BAZAR_']['id_fiche'];
171
	$resultat = $GLOBALS['_BAZAR_']['db']->query($requete) ;
172
	if (DB::isError($resultat)) {
173
		die ($resultat->getMessage().$resultat->getDebugInfo()) ;
174
	}
175
	if ($resultat->numRows()>0) {
176
		$res .= '<span class="rubrique">'.BAZ_LISTE_FICHIERS_JOINTS.':</span>'."\n";
177
		$res .= '<span class="description">'."\n";
178
		$res .= '<ul>'."\n";
179
		while ($ligne2 = $resultat->fetchRow(DB_FETCHMODE_ASSOC)) {
180
			$res .= '<li><a href="http://'.$_SERVER['HTTP_HOST'].'/client/bazar/upload/'.$ligne2['bfj_fichier'].'">'.$ligne2['bfj_description'].'</a></li>'."\n";
181
		}
182
		$res .= '</ul></span>'."\n";
183
	}
9 florian 184
	$res .= '<div class="bulle_haut">&nbsp;</div>'."\n";
185
	$res .= '<div class="bulle_corps">'."\n";
7 florian 186
 
187
	//affichage du rédacteur de la fiche
188
	$requete = 'SELECT '.BAZ_CHAMPS_NOM.', '.BAZ_CHAMPS_PRENOM.', '.BAZ_CHAMPS_EMAIL.' FROM '.BAZ_ANNUAIRE.' WHERE '.BAZ_CHAMPS_ID.'='.$GLOBALS['_BAZAR_']['annonceur'];
189
	$resultat = $GLOBALS['_BAZAR_']['db']->query($requete) ;
190
	if (DB::isError($resultat)) {
191
		die ($resultat->getMessage().$resultat->getDebugInfo()) ;
192
	}
193
	while ($redacteur = $resultat->fetchRow(DB_FETCHMODE_ASSOC)) {
194
		$res .= BAZ_FICHE_ECRITE.'<a href="mailto:'.$redacteur[BAZ_CHAMPS_EMAIL].'">'.$redacteur[BAZ_CHAMPS_PRENOM].' '.$redacteur[BAZ_CHAMPS_NOM].'</a><br />'."\n";
195
	}
196
	$res .= BAZ_NB_VUS.'<strong>'.$GLOBALS['_BAZAR_']['nb_consultations'].'</strong>'.BAZ_FOIS.'<br />'."\n";
197
	$res .= '</div>'."\n";
9 florian 198
	$res .= '<div class="bulle_bas">&nbsp;</div>'."\n";
7 florian 199
	$res .= '<div id="BAZ_bas_page">';
9 florian 200
 
7 florian 201
	//informations complémentaires (id fiche, état publication,... )
202
	if ($danslappli==1) {
203
		$res .= '<span class="rubrique">'.BAZ_NUM_FICHE.':</span> '.$GLOBALS['_BAZAR_']['id_fiche'].'<br />'."\n";
204
		$res .= '<span class="rubrique">'.BAZ_NATURE.':</span> '.$GLOBALS['_BAZAR_']['typeannonce'].'<br />'."\n";
205
		if ($ligne['bf_statut_fiche']==1) {
206
			$res .= '<span class="rubrique">'.BAZ_PUBLIEE.':</span> '.BAZ_OUI.'<br />'."\n";
207
		}
208
		else {
209
			$res .= '<span class="rubrique">'.BAZ_PUBLIEE.':</span> '.BAZ_NON.'<br />'."\n";
210
		}
211
		$res .= '<span class="rubrique">'.BAZ_DATE_CREATION.':</span> '.strftime('%d.%m.%Y &agrave; %H:%M',strtotime($ligne['bf_date_creation_fiche'])).'<br />'."\n";
212
		$res .= '<span class="rubrique">'.BAZ_DATE_MAJ.':</span> '.strftime('%d.%m.%Y &agrave; %H:%M',strtotime($ligne['bf_date_maj_fiche']));
9 florian 213
		if (($est_admin)or($GLOBALS['_BAZAR_']['annonceur']==$GLOBALS['AUTH']->getAuthData(BAZ_CHAMPS_ID))) {
214
			$lien_modifier=$GLOBALS['_BAZAR_']['url'];
215
			$lien_modifier->addQueryString('action', BAZ_ACTION_MODIFIER);
216
			$lien_modifier->addQueryString('id_fiche', $GLOBALS['_BAZAR_']['id_fiche']);
217
			$lien_modifier->addQueryString('typeannonce', $GLOBALS['_BAZAR_']['typeannonce']);
218
			$res .= '&nbsp;<a href="'.$lien_modifier->getURL().'">'.BAZ_MODIFIER_LA_FICHE.'</a>'."\n";
5 florian 219
		}
7 florian 220
	}
221
	$res .= '</div>'."\n";
222
	$res .= '</div>'."\n";
223
	$res .= '<div class="BAZ_cadre_fiche_bas">&nbsp;</div>'."\n";
224
	$res .= '</div>'."\n";
225
 
226
	//on ajoute les commentaires, s'il le faut
227
	if ($GLOBALS['_BAZAR_']['commentaire']==1) {
228
		$res .= '<div class="BAZ_cadre_fiche">'."\n";
229
		$res .= '<div class="BAZ_cadre_fiche_haut">&nbsp;</div>'."\n";
230
		$res .= '<div class="BAZ_cadre_fiche_corps">'."\n";
231
		$res .= '<h3>'.BAZ_LES_COMMENTAIRES.'</h3>'."\n";
232
		$requete = 'SELECT * FROM bazar_commentaires WHERE bc_ce_id_fiche='.$GLOBALS['_BAZAR_']['id_fiche'].' ORDER BY bc_date ASC';
5 florian 233
		$resultat = $GLOBALS['_BAZAR_']['db']->query($requete) ;
7 florian 234
		if (DB::isError ($resultat)) {
235
			die ($resultat->getMessage().'<br />'.$resultat->getDebugInfo()) ;
5 florian 236
		}
237
		if ($resultat->numRows()>0) {
9 florian 238
			$res .= BAZ_IL_Y_A.$resultat->numRows().' ';
239
			if ($resultat->numRows()==1) $res .= BAZ_COMMENTAIRE.'<br />'."\n";
240
			else $res .= BAZ_COMMENTAIRES.'<br />'."\n";
5 florian 241
			while ($ligne = $resultat->fetchRow(DB_FETCHMODE_ASSOC)) {
9 florian 242
				$res .= '<div class="bulle_haut">&nbsp;</div>'."\n";
243
				$res .= '<div class="bulle_corps">'."\n";
244
				//affichage du commentaire
245
				$res .= $ligne['bc_commentaire'].'<br />'."\n";
246
				$res .= '</div>'."\n";
247
				$res .= '<div class="bulle_bas">'."\n";
248
				$res .= '<span style="font-size:9px;margin-left:10px;">'.BAZ_PAR.' : <strong>'.$ligne['bc_nom'].'</strong>'.BAZ_ECRIT_LE.$ligne['bc_date'].'</span>'."\n";
249
				//pour les identifiés seulement, administrateurs de la rubrique ou superadmins
250
				if ($est_admin==1) {
251
					$url_comment= $GLOBALS['_BAZAR_']['url'];
252
					$url_comment->addQueryString('action', BAZ_VOIR_FICHE);
253
					$url_comment->addQueryString('id_fiche', $GLOBALS['_BAZAR_']['id_fiche']);
254
					$url_comment->addQueryString('date', $ligne['bc_date']);
255
					$res .= '<span style="float:right;"><a href="'.$url_comment->getURL().'">'.BAZ_SUPPRIMER.'</a></span>'."\n";
256
				}
257
				$res .= '</div>'."\n";
5 florian 258
			}
259
		}
9 florian 260
		else $res .= BAZ_PAS_DE_COMMENTAIRES.'<br /><br />'."\n";
261
 
262
		//formulaire des commentaires
263
		$form_commentaire = new HTML_QuickForm('commentaire', 'post', $url);
264
		$squelette =& $form_commentaire->defaultRenderer();
265
		$squelette->setFormTemplate("\n".'<form {attributes}>'."\n".'{content}'."\n".'</form>'."\n");
266
		$squelette->setElementTemplate( '<label style="width:200px;">{label}&nbsp;</label><br />'."\n".'{element}<br />'."\n");
267
		$squelette->setRequiredNoteTemplate("\n".'{requiredNote} '."\n");
268
		$option=array('style'=>'width:300px;', 'maxlength'=>100);
269
		$form_commentaire->addElement('text', 'Nom', BAZ_ENTREZ_VOTRE_NOM, $option);
270
		$option=array('style'=>'width:100%;height:100px;white-space: pre;padding:3px;');
271
		require_once 'HTML/QuickForm/textarea.php';
272
		$formtexte= new HTML_QuickForm_textarea('Commentaire', BAZ_ENTREZ_VOTRE_COMMENTAIRE, $option);
273
		$form_commentaire->addElement($formtexte) ;
274
		$form_commentaire->addElement('submit', 'Envoyer', BAZ_ENVOYER);
275
		$form_commentaire->addRule('Nom', BAZ_NOM_REQUIS, 'required', '', 'client') ;
276
		$form_commentaire->addRule('Commentaire', BAZ_COMMENTAIRE_REQUIS, 'required', '', 'client') ;
277
		$form_commentaire->setRequiredNote(BAZ_CHAMPS_REQUIS) ;
278
		$res .= $form_commentaire->toHTML();
279
 
7 florian 280
		$res .= '</div>'."\n";
281
		$res .= '<div class="BAZ_cadre_fiche_bas">&nbsp;</div>'."\n";
282
		$res .= '</div>'."\n";
283
	}
284
 
285
	//on ajoute les appropriations, s'il le faut
286
	if ($GLOBALS['_BAZAR_']['appropriation']==1) {
287
		$res .= '<div class="BAZ_cadre_fiche">'."\n";
288
		$res .= '<div class="BAZ_cadre_fiche_haut">&nbsp;</div>'."\n";
289
		$res .= '<div class="BAZ_cadre_fiche_corps">'."\n";
5 florian 290
 
7 florian 291
		$res .= '</div>'."\n";
292
		$res .= '<div class="BAZ_cadre_fiche_bas">&nbsp;</div>'."\n";
293
		$res .= '</div>'."\n";
5 florian 294
	}
7 florian 295
 
5 florian 296
	return $res ;
297
}
298
 
299
 
300
/** RSSversHTML () transforme un flux RSS (en XML) en page HTML
301
*
302
*   On passe en paramètre le contenu du flux RSS, on affiche ou non la description,
303
*   et on choisit de format de la date à l'affichage. On a en sortie du code HTML à afficher
304
*
305
*   @param  string   le contenu du flux RSS
306
*   @param  boolean  afficher ou non la description
307
*   @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
308
*
309
*   @return  string    le code HTML
310
*/
311
 
312
function RSSversHTML($rss, $voirdesc, $formatdate) {
313
	if ($rss!='') {
314
		$res='';
315
		if( eregi('<item>(.*)</item>', $rss, $rawitems ) ) {
316
			$items = explode('<item>', $rawitems[0]);
317
			$res.='<ul>'."\n";
318
			for( $i = 0; $i < count($items)-1; $i++ ) {
319
				eregi('<title>(.*)</title>',$items[$i+1], $title );
320
				eregi('<link>(.*)</link>',$items[$i+1], $url );
321
				eregi('<description>(.*)</description>',$items[$i+1], $cat);
322
				eregi('<pubDate>(.*)</pubDate>',$items[$i+1], $date);
323
				$res.='<li>';
324
				if ($formatdate=='jm') {$res.=strftime('%d.%m',strtotime($date[1])).': ';}
325
				if ($formatdate=='jma') {$res.=strftime('%d.%m.%Y',strtotime($date[1])).': ';}
326
				if ($formatdate=='jmh') {$res.=strftime('%d.%m %H:%M',strtotime($date[1])).': ';}
327
				if ($formatdate=='jmah') {$res.=strftime('%d.%m.%Y %H:%M',strtotime($date[1])).': ';}
328
				$res.='<a href="'.preg_replace ('/&amp;/', '&', $url[1]).'">'.$title[1].'</a><br />';
329
				if ($voirdesc) {$res.=$cat[1];}
330
				$res.='</li>'."\n";
331
			}
332
			$res.='</ul>'."\n";
333
		}
334
	}
335
	else $res = BAZ_PAS_D_ANNONCES;
336
	return $res;
337
}
338
 
339
/** gen_RSS() - générer un fichier de flux RSS par type d'annonce
340
*
341
* @param   string Le type de l'annonce (laisser vide pour tout type d'annonce)
342
* @param   integer Le nombre d'annonces a regrouper dans le fichier XML (laisser vide pour toutes)
343
* @param   integer L'identifiant de l'emetteur (laisser vide pour tous)
344
* @param   integer L'état de validation de l'annonce (laisser 1 pour les annonces validées, 0 pour les non-validées)
345
* @param   string La requète SQL personnalisée
346
*
347
* @return  string Le code du flux RSS
348
*/
349
function gen_RSS($typeannonce='', $nbitem='', $emetteur='', $valide=1, $requeteSQL='') {
350
	// génération de la requete MySQL personnalisée
351
	$requete = 'SELECT DISTINCT bf_id_fiche, bf_titre, bf_date_debut_validite_fiche, bn_label_nature FROM bazar_fiche, bazar_nature';
352
	$requete .= ' WHERE bf_statut_fiche='.$valide;
353
	$nomflux=BAZ_DERNIERE_ACTU;
354
	if (($typeannonce!='')and($typeannonce!='toutes')) {
355
		$requete .= ' AND bn_label_nature="'.$typeannonce.'"';
356
		//le nom du flux devient le type d'annonce
357
		$nomflux = $typeannonce;
358
	}
359
	if ($valide!=0) $requete .= ' AND bf_date_debut_validite_fiche<=NOW() AND bf_date_fin_validite_fiche>=NOW() AND bn_id_nature=bf_ce_nature';
360
	else $nomflux .= BAZ_A_MODERER;
361
	if (($emetteur!='')and($emetteur!='tous')) {
362
		$requete .= ' AND bf_ce_utilisateur='.$emetteur;
363
		//requete pour afficher le nom de la structure
364
		$requetenom = 'SELECT '.BAZ_CHAMPS_NOM.', '.BAZ_CHAMPS_PRENOM.' FROM '.BAZ_ANNUAIRE.' WHERE '.BAZ_CHAMPS_ID.'='.$emetteur;
365
		$resultat = $GLOBALS['_BAZAR_']['db']->query($requetenom) ;
366
		if (DB::isError($resultat)) {
367
			die ($resultat->getMessage().$resultat->getDebugInfo()) ;
368
		}
369
		$ligne = $resultat->fetchRow(DB_FETCHMODE_ASSOC);
370
		$nomflux .= ' ('.$ligne[BAZ_CHAMPS_NOM].' '.$ligne[BAZ_CHAMPS_PRENOM].')';
371
	}
372
	if ($requeteSQL!='') $requete .= ' AND ('.$requeteSQL.')';
373
	$requete .= ' ORDER BY  bf_date_debut_validite_fiche, bf_date_fin_validite_fiche, bf_date_maj_fiche DESC';
374
	if ($nbitem!='') {$requete .= ' LIMIT 0,'.$nbitem;}
375
	$resultat = $GLOBALS['_BAZAR_']['db']->query($requete) ;
376
	if (DB::isError($resultat)) {
377
		die ($GLOBALS['_BAZAR_']['db']->getMessage().$GLOBALS["db"]->getDebugInfo()) ;
378
	}
379
	// En-tête du flux RSS version 2.0
380
	$xml = '<?xml version="1.0" encoding="ISO-8859-1"?>'."\n".'<rss version="2.0">'."\n";
381
	$xml .= '<channel>'."\n".'<title>'.$nomflux.'</title>'."\n".'<link>'.BAZ_RSS_ADRESSESITE.'</link>'."\n";
382
	$xml .= '<description>'.BAZ_RSS_DESCRIPTIONSITE.'</description>'."\n".'<language>fr-FR</language>'."\n".
383
	'<copyright>Copyright 2005 '.BAZ_RSS_NOMSITE.'</copyright>'."\n";
384
	// Ajout de la date actuelle de publication (suivant la DTD RSS)
385
	$xml .= '<lastBuildDate>'.strftime('%d %b %Y %H:%M:%S GMT').'</lastBuildDate>'."\n";
386
	// En-tête suite et fin
387
	$xml .= '<docs>http://www.stervinou.com/projets/rss/</docs>'."\n".'<category>'.BAZ_RSS_CATEGORIE.'</category>'."\n".
388
	'<managingEditor>'.BAZ_RSS_MANAGINGEDITOR.'</managingEditor>'."\n".'<webMaster>'.BAZ_RSS_WEBMASTER.'</webMaster>'."\n";
389
	$xml .= '<ttl>60</ttl>'."\n".'<image>'."\n".'<title>'.BAZ_RSS_NOMSITE.'</title>'."\n".'<url>'.BAZ_RSS_LOGOSITE.'</url>'."\n".
390
	'<link>'.BAZ_RSS_ADRESSESITE.'</link>'."\n".'</image>'."\n";
391
	if ($resultat->numRows()>0) {
392
		// Creation des items : titre + lien + description + date de publication
393
		while ($ligne = $resultat->fetchRow(DB_FETCHMODE_ASSOC)) {
394
			$xml .= '<item>'."\n";
395
			$xml .= '<title>'.$ligne['bf_titre'].'</title>'."\n";
396
			$lien=$GLOBALS['_BAZAR_']['url'];
397
			$lien->addQueryString('action', BAZ_VOIR_FICHE);
398
			$lien->addQueryString('id_fiche', $ligne['bf_id_fiche']);
399
			$xml .= '<link>'.str_replace ('&', '&amp;', $lien->getURL()).'</link>'."\n";
400
			$xml .= '<description>'."\n".'<![CDATA['.baz_voir_fiche(0,$ligne['bf_id_fiche']).']]>'."\n".'</description>'."\n";
401
			$xml .= '<pubDate>'.strftime('%d %b %Y %H:%M:%S GMT',strtotime($ligne['bf_date_debut_validite_fiche'])).'</pubDate>'."\n";
402
			$xml .= '</item>'."\n";
403
		}
404
	}
405
	else {//pas d'annonces
406
		$xml .= '<item>'."\n";
10 ddelon 407
		$xml .= '<title>'.BAZ_PAS_D_ANNONCES.'</title>'."\n";
408
		$xml .= '<link></link>'."\n";
409
		$xml .= '<description>'.BAZ_PAS_D_ANNONCES.'</description>'."\n";
5 florian 410
		$xml .= '<pubDate>'.strftime('%d %b %Y %H:%M:%S GMT',strtotime('12/12/2004')).'</pubDate>'."\n";
411
		$xml .= '</item>'."\n";
412
	}
413
	$xml .= '</channel>'."\n".'</rss>'."\n";
414
	return $xml;
415
}
416
 
417
 
418
/** baz_liste() Formate la liste de toutes les annonces actuelles
419
*
420
*   @return  string    le code HTML à afficher
421
*/
422
function baz_liste($typeannonce='toutes') {
423
	if ($typeannonce=='toutes') $res= '<h2>'.BAZ_TOUTES_LES_ANNONCES.'</h2>'."\n";
424
	else $res= '<h2>'.BAZ_TOUTES_LES_ANNONCES_DE_TYPE.$typeannonce.'</h2>'."\n";
425
	$res.=RSSversHTML(gen_RSS($typeannonce, '', '', 1, ''), 0, 'jm') ;
426
	return $res;
427
}
428
 
429
?>