Subversion Repositories Applications.bazar

Rev

Rev 22 | Rev 33 | 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
 
15 florian 55
	//cas ou un commentaire a été entré
9 florian 56
	if (isset($_POST['Nom'])) {
15 florian 57
		$requete = 'INSERT INTO bazar_commentaires VALUES ('.baz_nextid('bazar_commentaires', 'bc_id_commentaire', $GLOBALS['_BAZAR_']['db']).', '.$GLOBALS['_BAZAR_']['id_fiche'].', "'.$_POST['Nom'].'", "'.$_POST['Commentaire'].'", NOW() )';
9 florian 58
		$resultat = $GLOBALS['_BAZAR_']['db']->query($requete) ;
59
	}
22 florian 60
	//cas ou un commentaire va être supprimé
15 florian 61
	elseif (isset($_GET['id_commentaire'])) {
62
		$requete = 'DELETE FROM bazar_commentaires WHERE bc_id_commentaire='.$_GET['id_commentaire'].' LIMIT 1';
9 florian 63
		$resultat = $GLOBALS['_BAZAR_']['db']->query($requete) ;
64
	}
15 florian 65
	else {
66
		if (isset($_GET['action'])) {
67
			if ($_GET['action']==BAZ_VOIR_FICHE) {
68
				//sinon on met à jour le nb de visites pour la fiche, puisque c'est une simple consultation
69
				$requete = 'UPDATE bazar_fiche SET bf_nb_consultations=bf_nb_consultations+1 WHERE bf_id_fiche='.$GLOBALS['_BAZAR_']['id_fiche'];
70
				$resultat = $GLOBALS['_BAZAR_']['db']->query($requete) ;
71
			}
72
		}
73
	}
9 florian 74
 
7 florian 75
	//on cherche le type d'annonce, l'annonceur et les stats
76
	$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'];
77
	$resultat = $GLOBALS['_BAZAR_']['db']->query($requete) ;
5 florian 78
	if (DB::isError($resultat)) {
79
		die ($resultat->getMessage().$resultat->getDebugInfo()) ;
80
	}
81
	while ($ligne = $resultat->fetchRow(DB_FETCHMODE_ASSOC)) {
82
		$GLOBALS['_BAZAR_']['typeannonce']=$ligne['bn_label_nature'];
7 florian 83
		$GLOBALS['_BAZAR_']['commentaire']=$ligne['bn_commentaire'];
84
		$GLOBALS['_BAZAR_']['appropriation']=$ligne['bn_appropriation'];
85
		$GLOBALS['_BAZAR_']['annonceur']=$ligne['bf_ce_utilisateur'];
86
		$GLOBALS['_BAZAR_']['nb_consultations']=$ligne['bf_nb_consultations'];
5 florian 87
	}
9 florian 88
 
89
	//on vérifie si l'utilisateur est administrateur
90
	$est_admin=0;
91
	if ($GLOBALS['AUTH']->getAuth()) {
92
		$requete='SELECT bn_id_nature FROM bazar_nature WHERE bn_label_nature="'.$GLOBALS['_BAZAR_']['typeannonce'].'"';
93
		$resultat = $GLOBALS['_BAZAR_']['db']->query($requete) ;
94
		if (DB::isError($resultat)) {
95
			die ($resultat->getMessage().$resultat->getDebugInfo()) ;
96
		}
97
		$result = $resultat->fetchRow(DB_FETCHMODE_ASSOC);
98
		if ((niveau_droit($result['bn_id_nature'],$GLOBALS['AUTH']->getAuthData(BAZ_CHAMPS_ID))=='administrateur')
99
		     or(niveau_droit('0',$GLOBALS['AUTH']->getAuthData(BAZ_CHAMPS_ID))=='superadministrateur'))
100
		{
101
		        $est_admin=1;
102
		}
103
	}
104
 
7 florian 105
	$res = '<div class="BAZ_cadre_fiche">'."\n";
106
	$res .= '<div class="BAZ_cadre_fiche_haut">'."\n";
5 florian 107
	$res .= '&nbsp;</div>'."\n";
7 florian 108
	$res .= '<div class="BAZ_cadre_fiche_corps">'."\n";
5 florian 109
 
110
	//si le template existe, on génère le template
111
	if ((file_exists(BAZ_CHEMIN_APPLI.'templates/'.$GLOBALS['_BAZAR_']['typeannonce'].'-fiche.php'))) {
112
		include_once(BAZ_CHEMIN_APPLI.'templates/'.$GLOBALS['_BAZAR_']['typeannonce'].'-fiche.php');
7 florian 113
		$res .=genere_fiche($GLOBALS['_BAZAR_']['id_fiche']);
5 florian 114
	}
115
	//on affiche ligne par ligne sinon
116
	else {
117
		$requete = 'SELECT * FROM bazar_fiche WHERE bf_id_fiche='.$GLOBALS['_BAZAR_']['id_fiche'];
118
		$resultat = $GLOBALS['_BAZAR_']['db']->query($requete) ;
119
		if (DB::isError ($resultat)) {
120
			die ($resultat->getMessage().'<br />'.$resultat->getDebugInfo()) ;
121
		}
122
		$ligne = $resultat->fetchRow(DB_FETCHMODE_ASSOC) ;
123
 
7 florian 124
		if (isset($ligne['bf_url_image'])) {
125
			$res .= '<div id="fiche_image">'."\n";
126
			$res .= '<img src="'.'http://'.$_SERVER['HTTP_HOST'].'/client/bazar/images/'.$ligne['bf_url_image'].'" border=0 alt="'.BAZ_TEXTE_IMG_ALTERNATIF.'" />'."\n";
127
			$res .= '</div>'."\n";
128
			$res .= '<div id="fiche_titre_image">'.$ligne['bf_titre'];
129
		}
130
		else {
131
			$res .= '<div id="fiche_titre">'.$ligne['bf_titre'];
132
		}
133
		$res .= '</div>'."\n";
134
		$res .= '<div id="BAZ_description">'.$ligne['bf_description'].'</div>'."\n";
5 florian 135
		$tableau=baz_valeurs_template($GLOBALS['_BAZAR_']['typeannonce'].'.tpl');
136
		for ($i=0; $i<count($tableau); $i++) {
137
			if (isset($ligne[$tableau[$i]['nom_bdd']])) {
138
				//pour les champs renseignés par une liste, on va chercher le label de la liste, plutot que l'id
139
				if ($tableau[$i]['type']=='liste') {
140
					$requete = 'SELECT '.$tableau[$i]['table_source'].'.* FROM bazar_fiche, '.$tableau[$i]['table_source'].
141
					' WHERE '.$tableau[$i]['nom_bdd'].'='.$tableau[$i]['id_source'].' AND bf_id_fiche='.$GLOBALS['_BAZAR_']['id_fiche'];
142
					$resultat = $GLOBALS['_BAZAR_']['db']->query($requete) ;
143
					if (DB::isError ($resultat)) {
144
						die ($resultat->getMessage().'<br />'.$resultat->getDebugInfo()) ;
145
					}
146
					while ($tab = $resultat->fetchRow()) {
7 florian 147
						$val=$tab[1];
5 florian 148
					}
149
				}
150
				else {
7 florian 151
					$val=$ligne[$tableau[$i]['nom_bdd']];
5 florian 152
				}
153
				if (($tableau[$i]['nom_bdd']!='bf_titre')and($tableau[$i]['nom_bdd']!='bf_description')) {
7 florian 154
					if ($val!='') {
155
						$res .= '<span class="rubrique">'.constant($tableau[$i]['label']).':</span>'."\n";
156
						$res .= '<span class="description"> '.$val.'</span>'."\n".'<br />'."\n";
157
					}
5 florian 158
				}
159
			}
160
		}
7 florian 161
	}
162
	//afficher les liens pour l'annonce
163
	$requete = 'SELECT  bu_url, bu_descriptif_url FROM bazar_url WHERE bu_ce_fiche='.$GLOBALS['_BAZAR_']['id_fiche'];
164
	$resultat = $GLOBALS['_BAZAR_']['db']->query($requete) ;
165
	if (DB::isError($resultat)) {
166
		die ($resultat->getMessage().$resultat->getDebugInfo()) ;
167
	}
168
	if ($resultat->numRows()>0) {
169
		$res .= '<span class="rubrique">'.BAZ_LIEN_INTERNET.':</span>'."\n";
170
		$res .= '<span class="description">'."\n";
171
		$res .= '<ul>'."\n";
172
		while ($ligne1 = $resultat->fetchRow(DB_FETCHMODE_ASSOC)) {
173
			$res .= '<li><a href="'.$ligne1['bu_url'].'" target="_blank">'.$ligne1['bu_descriptif_url'].'</a></li>'."\n";
5 florian 174
		}
7 florian 175
		$res .= '</ul></span>'."\n";
176
	}
177
 
178
	//afficher les fichiers pour l'annonce
179
	$requete = 'SELECT  bfj_description, bfj_fichier FROM bazar_fichier_joint WHERE bfj_ce_fiche='.$GLOBALS['_BAZAR_']['id_fiche'];
180
	$resultat = $GLOBALS['_BAZAR_']['db']->query($requete) ;
181
	if (DB::isError($resultat)) {
182
		die ($resultat->getMessage().$resultat->getDebugInfo()) ;
183
	}
184
	if ($resultat->numRows()>0) {
185
		$res .= '<span class="rubrique">'.BAZ_LISTE_FICHIERS_JOINTS.':</span>'."\n";
186
		$res .= '<span class="description">'."\n";
187
		$res .= '<ul>'."\n";
188
		while ($ligne2 = $resultat->fetchRow(DB_FETCHMODE_ASSOC)) {
189
			$res .= '<li><a href="http://'.$_SERVER['HTTP_HOST'].'/client/bazar/upload/'.$ligne2['bfj_fichier'].'">'.$ligne2['bfj_description'].'</a></li>'."\n";
190
		}
191
		$res .= '</ul></span>'."\n";
192
	}
9 florian 193
	$res .= '<div class="bulle_haut">&nbsp;</div>'."\n";
194
	$res .= '<div class="bulle_corps">'."\n";
7 florian 195
 
196
	//affichage du rédacteur de la fiche
197
	$requete = 'SELECT '.BAZ_CHAMPS_NOM.', '.BAZ_CHAMPS_PRENOM.', '.BAZ_CHAMPS_EMAIL.' FROM '.BAZ_ANNUAIRE.' WHERE '.BAZ_CHAMPS_ID.'='.$GLOBALS['_BAZAR_']['annonceur'];
198
	$resultat = $GLOBALS['_BAZAR_']['db']->query($requete) ;
199
	if (DB::isError($resultat)) {
200
		die ($resultat->getMessage().$resultat->getDebugInfo()) ;
201
	}
202
	while ($redacteur = $resultat->fetchRow(DB_FETCHMODE_ASSOC)) {
203
		$res .= BAZ_FICHE_ECRITE.'<a href="mailto:'.$redacteur[BAZ_CHAMPS_EMAIL].'">'.$redacteur[BAZ_CHAMPS_PRENOM].' '.$redacteur[BAZ_CHAMPS_NOM].'</a><br />'."\n";
204
	}
205
	$res .= BAZ_NB_VUS.'<strong>'.$GLOBALS['_BAZAR_']['nb_consultations'].'</strong>'.BAZ_FOIS.'<br />'."\n";
206
	$res .= '</div>'."\n";
9 florian 207
	$res .= '<div class="bulle_bas">&nbsp;</div>'."\n";
7 florian 208
	$res .= '<div id="BAZ_bas_page">';
9 florian 209
 
7 florian 210
	//informations complémentaires (id fiche, état publication,... )
211
	if ($danslappli==1) {
212
		$res .= '<span class="rubrique">'.BAZ_NUM_FICHE.':</span> '.$GLOBALS['_BAZAR_']['id_fiche'].'<br />'."\n";
213
		$res .= '<span class="rubrique">'.BAZ_NATURE.':</span> '.$GLOBALS['_BAZAR_']['typeannonce'].'<br />'."\n";
214
		if ($ligne['bf_statut_fiche']==1) {
215
			$res .= '<span class="rubrique">'.BAZ_PUBLIEE.':</span> '.BAZ_OUI.'<br />'."\n";
216
		}
217
		else {
218
			$res .= '<span class="rubrique">'.BAZ_PUBLIEE.':</span> '.BAZ_NON.'<br />'."\n";
219
		}
220
		$res .= '<span class="rubrique">'.BAZ_DATE_CREATION.':</span> '.strftime('%d.%m.%Y &agrave; %H:%M',strtotime($ligne['bf_date_creation_fiche'])).'<br />'."\n";
221
		$res .= '<span class="rubrique">'.BAZ_DATE_MAJ.':</span> '.strftime('%d.%m.%Y &agrave; %H:%M',strtotime($ligne['bf_date_maj_fiche']));
9 florian 222
		if (($est_admin)or($GLOBALS['_BAZAR_']['annonceur']==$GLOBALS['AUTH']->getAuthData(BAZ_CHAMPS_ID))) {
223
			$lien_modifier=$GLOBALS['_BAZAR_']['url'];
224
			$lien_modifier->addQueryString('action', BAZ_ACTION_MODIFIER);
225
			$lien_modifier->addQueryString('id_fiche', $GLOBALS['_BAZAR_']['id_fiche']);
226
			$lien_modifier->addQueryString('typeannonce', $GLOBALS['_BAZAR_']['typeannonce']);
227
			$res .= '&nbsp;<a href="'.$lien_modifier->getURL().'">'.BAZ_MODIFIER_LA_FICHE.'</a>'."\n";
5 florian 228
		}
7 florian 229
	}
230
	$res .= '</div>'."\n";
231
	$res .= '</div>'."\n";
232
	$res .= '<div class="BAZ_cadre_fiche_bas">&nbsp;</div>'."\n";
233
	$res .= '</div>'."\n";
234
 
235
	//on ajoute les commentaires, s'il le faut
22 florian 236
	if (($danslappli==1)and($GLOBALS['_BAZAR_']['commentaire']==1)) {
7 florian 237
		$res .= '<div class="BAZ_cadre_fiche">'."\n";
238
		$res .= '<div class="BAZ_cadre_fiche_haut">&nbsp;</div>'."\n";
239
		$res .= '<div class="BAZ_cadre_fiche_corps">'."\n";
240
		$res .= '<h3>'.BAZ_LES_COMMENTAIRES.'</h3>'."\n";
241
		$requete = 'SELECT * FROM bazar_commentaires WHERE bc_ce_id_fiche='.$GLOBALS['_BAZAR_']['id_fiche'].' ORDER BY bc_date ASC';
5 florian 242
		$resultat = $GLOBALS['_BAZAR_']['db']->query($requete) ;
7 florian 243
		if (DB::isError ($resultat)) {
244
			die ($resultat->getMessage().'<br />'.$resultat->getDebugInfo()) ;
5 florian 245
		}
246
		if ($resultat->numRows()>0) {
9 florian 247
			$res .= BAZ_IL_Y_A.$resultat->numRows().' ';
248
			if ($resultat->numRows()==1) $res .= BAZ_COMMENTAIRE.'<br />'."\n";
249
			else $res .= BAZ_COMMENTAIRES.'<br />'."\n";
5 florian 250
			while ($ligne = $resultat->fetchRow(DB_FETCHMODE_ASSOC)) {
9 florian 251
				$res .= '<div class="bulle_haut">&nbsp;</div>'."\n";
252
				$res .= '<div class="bulle_corps">'."\n";
253
				//affichage du commentaire
254
				$res .= $ligne['bc_commentaire'].'<br />'."\n";
255
				$res .= '</div>'."\n";
256
				$res .= '<div class="bulle_bas">'."\n";
15 florian 257
				$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 258
				//pour les identifiés seulement, administrateurs de la rubrique ou superadmins
259
				if ($est_admin==1) {
260
					$url_comment= $GLOBALS['_BAZAR_']['url'];
261
					$url_comment->addQueryString('action', BAZ_VOIR_FICHE);
262
					$url_comment->addQueryString('id_fiche', $GLOBALS['_BAZAR_']['id_fiche']);
15 florian 263
					$url_comment->addQueryString('id_commentaire', $ligne['bc_id_commentaire']);
264
					$res .= '<a href="'.$url_comment->getURL().'" style="font-size:9px;float:right;">'.BAZ_SUPPRIMER.'</a>'."\n";
9 florian 265
				}
266
				$res .= '</div>'."\n";
5 florian 267
			}
268
		}
9 florian 269
		else $res .= BAZ_PAS_DE_COMMENTAIRES.'<br /><br />'."\n";
270
 
271
		//formulaire des commentaires
272
		$form_commentaire = new HTML_QuickForm('commentaire', 'post', $url);
273
		$squelette =& $form_commentaire->defaultRenderer();
274
		$squelette->setFormTemplate("\n".'<form {attributes}>'."\n".'{content}'."\n".'</form>'."\n");
275
		$squelette->setElementTemplate( '<label style="width:200px;">{label}&nbsp;</label><br />'."\n".'{element}<br />'."\n");
276
		$squelette->setRequiredNoteTemplate("\n".'{requiredNote} '."\n");
277
		$option=array('style'=>'width:300px;', 'maxlength'=>100);
278
		$form_commentaire->addElement('text', 'Nom', BAZ_ENTREZ_VOTRE_NOM, $option);
279
		$option=array('style'=>'width:100%;height:100px;white-space: pre;padding:3px;');
280
		require_once 'HTML/QuickForm/textarea.php';
281
		$formtexte= new HTML_QuickForm_textarea('Commentaire', BAZ_ENTREZ_VOTRE_COMMENTAIRE, $option);
282
		$form_commentaire->addElement($formtexte) ;
283
		$form_commentaire->addElement('submit', 'Envoyer', BAZ_ENVOYER);
284
		$form_commentaire->addRule('Nom', BAZ_NOM_REQUIS, 'required', '', 'client') ;
285
		$form_commentaire->addRule('Commentaire', BAZ_COMMENTAIRE_REQUIS, 'required', '', 'client') ;
286
		$form_commentaire->setRequiredNote(BAZ_CHAMPS_REQUIS) ;
287
		$res .= $form_commentaire->toHTML();
288
 
7 florian 289
		$res .= '</div>'."\n";
290
		$res .= '<div class="BAZ_cadre_fiche_bas">&nbsp;</div>'."\n";
291
		$res .= '</div>'."\n";
292
	}
293
 
294
	//on ajoute les appropriations, s'il le faut
22 florian 295
	if (($danslappli==1)and($GLOBALS['_BAZAR_']['appropriation']==1)) {
7 florian 296
		$res .= '<div class="BAZ_cadre_fiche">'."\n";
297
		$res .= '<div class="BAZ_cadre_fiche_haut">&nbsp;</div>'."\n";
298
		$res .= '<div class="BAZ_cadre_fiche_corps">'."\n";
5 florian 299
 
7 florian 300
		$res .= '</div>'."\n";
301
		$res .= '<div class="BAZ_cadre_fiche_bas">&nbsp;</div>'."\n";
302
		$res .= '</div>'."\n";
5 florian 303
	}
7 florian 304
 
5 florian 305
	return $res ;
306
}
307
 
308
 
309
/** RSSversHTML () transforme un flux RSS (en XML) en page HTML
310
*
311
*   On passe en paramètre le contenu du flux RSS, on affiche ou non la description,
312
*   et on choisit de format de la date à l'affichage. On a en sortie du code HTML à afficher
313
*
314
*   @param  string   le contenu du flux RSS
315
*   @param  boolean  afficher ou non la description
316
*   @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
317
*
318
*   @return  string    le code HTML
319
*/
320
 
321
function RSSversHTML($rss, $voirdesc, $formatdate) {
322
	if ($rss!='') {
323
		$res='';
324
		if( eregi('<item>(.*)</item>', $rss, $rawitems ) ) {
325
			$items = explode('<item>', $rawitems[0]);
326
			$res.='<ul>'."\n";
327
			for( $i = 0; $i < count($items)-1; $i++ ) {
328
				eregi('<title>(.*)</title>',$items[$i+1], $title );
329
				eregi('<link>(.*)</link>',$items[$i+1], $url );
330
				eregi('<description>(.*)</description>',$items[$i+1], $cat);
331
				eregi('<pubDate>(.*)</pubDate>',$items[$i+1], $date);
332
				$res.='<li>';
333
				if ($formatdate=='jm') {$res.=strftime('%d.%m',strtotime($date[1])).': ';}
334
				if ($formatdate=='jma') {$res.=strftime('%d.%m.%Y',strtotime($date[1])).': ';}
335
				if ($formatdate=='jmh') {$res.=strftime('%d.%m %H:%M',strtotime($date[1])).': ';}
336
				if ($formatdate=='jmah') {$res.=strftime('%d.%m.%Y %H:%M',strtotime($date[1])).': ';}
337
				$res.='<a href="'.preg_replace ('/&amp;/', '&', $url[1]).'">'.$title[1].'</a><br />';
338
				if ($voirdesc) {$res.=$cat[1];}
339
				$res.='</li>'."\n";
340
			}
341
			$res.='</ul>'."\n";
342
		}
343
	}
344
	else $res = BAZ_PAS_D_ANNONCES;
345
	return $res;
346
}
347
 
348
/** gen_RSS() - générer un fichier de flux RSS par type d'annonce
349
*
350
* @param   string Le type de l'annonce (laisser vide pour tout type d'annonce)
351
* @param   integer Le nombre d'annonces a regrouper dans le fichier XML (laisser vide pour toutes)
352
* @param   integer L'identifiant de l'emetteur (laisser vide pour tous)
353
* @param   integer L'état de validation de l'annonce (laisser 1 pour les annonces validées, 0 pour les non-validées)
15 florian 354
* @param   string La requête SQL personnalisée
5 florian 355
*
356
* @return  string Le code du flux RSS
357
*/
358
function gen_RSS($typeannonce='', $nbitem='', $emetteur='', $valide=1, $requeteSQL='') {
359
	// génération de la requete MySQL personnalisée
360
	$requete = 'SELECT DISTINCT bf_id_fiche, bf_titre, bf_date_debut_validite_fiche, bn_label_nature FROM bazar_fiche, bazar_nature';
22 florian 361
	$requete .= ' WHERE bn_ce_id_menu='.$GLOBALS['_GEN_commun']['info_menu']->gm_id_menu.' AND bf_statut_fiche='.$valide;
5 florian 362
	$nomflux=BAZ_DERNIERE_ACTU;
363
	if (($typeannonce!='')and($typeannonce!='toutes')) {
364
		$requete .= ' AND bn_label_nature="'.$typeannonce.'"';
365
		//le nom du flux devient le type d'annonce
366
		$nomflux = $typeannonce;
367
	}
13 alexandre_ 368
	if ($valide!=0) $requete .= ' AND (bf_date_debut_validite_fiche<=NOW() or bf_date_debut_validite_fiche="0000-00-00")'.
369
					' AND (bf_date_fin_validite_fiche>=NOW() or bf_date_fin_validite_fiche="0000-00-00") AND bn_id_nature=bf_ce_nature';
5 florian 370
	else $nomflux .= BAZ_A_MODERER;
371
	if (($emetteur!='')and($emetteur!='tous')) {
372
		$requete .= ' AND bf_ce_utilisateur='.$emetteur;
373
		//requete pour afficher le nom de la structure
374
		$requetenom = 'SELECT '.BAZ_CHAMPS_NOM.', '.BAZ_CHAMPS_PRENOM.' FROM '.BAZ_ANNUAIRE.' WHERE '.BAZ_CHAMPS_ID.'='.$emetteur;
375
		$resultat = $GLOBALS['_BAZAR_']['db']->query($requetenom) ;
376
		if (DB::isError($resultat)) {
377
			die ($resultat->getMessage().$resultat->getDebugInfo()) ;
378
		}
379
		$ligne = $resultat->fetchRow(DB_FETCHMODE_ASSOC);
380
		$nomflux .= ' ('.$ligne[BAZ_CHAMPS_NOM].' '.$ligne[BAZ_CHAMPS_PRENOM].')';
381
	}
382
	if ($requeteSQL!='') $requete .= ' AND ('.$requeteSQL.')';
22 florian 383
	$requete .= ' ORDER BY  bf_date_debut_validite_fiche DESC, bf_date_fin_validite_fiche DESC, bf_date_maj_fiche DESC';
5 florian 384
	if ($nbitem!='') {$requete .= ' LIMIT 0,'.$nbitem;}
385
	$resultat = $GLOBALS['_BAZAR_']['db']->query($requete) ;
386
	if (DB::isError($resultat)) {
387
		die ($GLOBALS['_BAZAR_']['db']->getMessage().$GLOBALS["db"]->getDebugInfo()) ;
388
	}
389
	// En-tête du flux RSS version 2.0
390
	$xml = '<?xml version="1.0" encoding="ISO-8859-1"?>'."\n".'<rss version="2.0">'."\n";
391
	$xml .= '<channel>'."\n".'<title>'.$nomflux.'</title>'."\n".'<link>'.BAZ_RSS_ADRESSESITE.'</link>'."\n";
392
	$xml .= '<description>'.BAZ_RSS_DESCRIPTIONSITE.'</description>'."\n".'<language>fr-FR</language>'."\n".
393
	'<copyright>Copyright 2005 '.BAZ_RSS_NOMSITE.'</copyright>'."\n";
394
	// Ajout de la date actuelle de publication (suivant la DTD RSS)
395
	$xml .= '<lastBuildDate>'.strftime('%d %b %Y %H:%M:%S GMT').'</lastBuildDate>'."\n";
396
	// En-tête suite et fin
397
	$xml .= '<docs>http://www.stervinou.com/projets/rss/</docs>'."\n".'<category>'.BAZ_RSS_CATEGORIE.'</category>'."\n".
398
	'<managingEditor>'.BAZ_RSS_MANAGINGEDITOR.'</managingEditor>'."\n".'<webMaster>'.BAZ_RSS_WEBMASTER.'</webMaster>'."\n";
399
	$xml .= '<ttl>60</ttl>'."\n".'<image>'."\n".'<title>'.BAZ_RSS_NOMSITE.'</title>'."\n".'<url>'.BAZ_RSS_LOGOSITE.'</url>'."\n".
400
	'<link>'.BAZ_RSS_ADRESSESITE.'</link>'."\n".'</image>'."\n";
401
	if ($resultat->numRows()>0) {
402
		// Creation des items : titre + lien + description + date de publication
403
		while ($ligne = $resultat->fetchRow(DB_FETCHMODE_ASSOC)) {
404
			$xml .= '<item>'."\n";
405
			$xml .= '<title>'.$ligne['bf_titre'].'</title>'."\n";
406
			$lien=$GLOBALS['_BAZAR_']['url'];
407
			$lien->addQueryString('action', BAZ_VOIR_FICHE);
408
			$lien->addQueryString('id_fiche', $ligne['bf_id_fiche']);
409
			$xml .= '<link>'.str_replace ('&', '&amp;', $lien->getURL()).'</link>'."\n";
410
			$xml .= '<description>'."\n".'<![CDATA['.baz_voir_fiche(0,$ligne['bf_id_fiche']).']]>'."\n".'</description>'."\n";
411
			$xml .= '<pubDate>'.strftime('%d %b %Y %H:%M:%S GMT',strtotime($ligne['bf_date_debut_validite_fiche'])).'</pubDate>'."\n";
412
			$xml .= '</item>'."\n";
413
		}
414
	}
415
	else {//pas d'annonces
416
		$xml .= '<item>'."\n";
10 ddelon 417
		$xml .= '<title>'.BAZ_PAS_D_ANNONCES.'</title>'."\n";
22 florian 418
		$xml .= '<link>#</link>'."\n";
10 ddelon 419
		$xml .= '<description>'.BAZ_PAS_D_ANNONCES.'</description>'."\n";
5 florian 420
		$xml .= '<pubDate>'.strftime('%d %b %Y %H:%M:%S GMT',strtotime('12/12/2004')).'</pubDate>'."\n";
421
		$xml .= '</item>'."\n";
422
	}
423
	$xml .= '</channel>'."\n".'</rss>'."\n";
424
	return $xml;
425
}
426
 
427
 
428
/** baz_liste() Formate la liste de toutes les annonces actuelles
429
*
430
*   @return  string    le code HTML à afficher
431
*/
432
function baz_liste($typeannonce='toutes') {
22 florian 433
 
434
	//titre
5 florian 435
	if ($typeannonce=='toutes') $res= '<h2>'.BAZ_TOUTES_LES_ANNONCES.'</h2>'."\n";
22 florian 436
	else $res = '<h2>'.BAZ_TOUTES_LES_ANNONCES_DE_TYPE.$typeannonce.'</h2>'."\n";
437
 
438
	//création du lien pour le formulaire de recherche
439
	$GLOBALS['_BAZAR_']['url']->addQueryString('action', BAZ_VOIR_TOUTES_ANNONCES);
440
	$lien_formulaire=preg_replace ('/&amp;/', '&', $GLOBALS['_BAZAR_']['url']->getURL()) ;
441
	$formtemplate = new HTML_QuickForm('formulaire', 'post', $lien_formulaire) ;
442
	$squelette =&$formtemplate->defaultRenderer();
443
    $squelette->setFormTemplate("\n".'<form{attributes}>'."\n".'<ul>'."\n".'{content}'."\n".'</ul>'."\n".'</form>'."\n");
444
    $squelette->setElementTemplate( '<li class="enligne">'."\n".'{element}'."\n".
445
                                    '</li>'."\n");
446
 
447
 
448
 
449
	//requete pour obtenir l'id et le label des types d'annonces
450
	$requete = 'SELECT bn_label_nature '.
451
	           'FROM bazar_nature WHERE bn_ce_id_menu='.$GLOBALS['_GEN_commun']['info_menu']->gm_id_menu.
452
		   '  or  bn_ce_id_menu=0 ORDER BY bn_label_nature ASC';
453
	$resultat = $GLOBALS['_BAZAR_']['db']->query($requete) ;
454
	if (DB::isError($resultat)) {
455
		die ($resultat->getMessage().$resultat->getDebugInfo()) ;
456
	}
457
	$type_annonce_select['toutes']=BAZ_TOUS_TYPES_FICHES;
458
	while ($ligne = $resultat->fetchRow(DB_FETCHMODE_ASSOC)) {
459
		$type_annonce_select[$ligne['bn_label_nature']] = $ligne['bn_label_nature'];
460
	}
461
	$option=array('style'=>'width: 130px;', 'onchange'=>'this.form.submit();');
462
	$formtemplate->addElement ('select', 'nature', BAZ_TYPEANNONCE, $type_annonce_select, $option) ;
463
 
464
	//requete pour obtenir l'id, le nom et prénom de toutes les personnes ayant une fiche publiée actuellement
465
	$requete = 'SELECT '.BAZ_CHAMPS_ID.', '.BAZ_CHAMPS_NOM.', '.BAZ_CHAMPS_PRENOM.' '.
466
	           'FROM bazar_fiche,'.BAZ_ANNUAIRE.' '.
467
		   'WHERE bf_statut_fiche=1 AND bf_date_debut_validite_fiche<=NOW() AND bf_date_fin_validite_fiche>=NOW() AND bf_ce_utilisateur='.BAZ_CHAMPS_ID.' '.
468
		   'ORDER BY '.BAZ_CHAMPS_NOM.' ASC';
469
	$resultat = $GLOBALS['_BAZAR_']['db']->query($requete) ;
470
	if (DB::isError($resultat)) {
471
		die ($resultat->getMessage().$resultat->getDebugInfo()) ;
472
	}
473
	$personnes_select['tous']=BAZ_TOUS_LES_EMETTEURS;
474
	while ($ligne = $resultat->fetchRow(DB_FETCHMODE_ASSOC)) {
475
		$personnes_select[$ligne[BAZ_CHAMPS_ID]] = $ligne[BAZ_CHAMPS_NOM]." ".$ligne[BAZ_CHAMPS_PRENOM] ;
476
	}
477
	$option=array('style'=>'width: 130px;', 'onchange'=>'this.form.submit();');
478
	$formtemplate->addElement ('select', 'personnes', BAZ_EMETTEUR, $personnes_select, $option) ;
479
 
480
	//champs texte pour entrer les mots clés
481
	$option=array('size'=>15,'maxlength'=>40);
482
	$formtemplate->addElement('text', 'recherche_mots_cles', BAZ_MOT_CLE, $option) ;
483
	$defauts=array('recherche_mots_cles'=>BAZ_MOT_CLE);
484
	$formtemplate->setDefaults($defauts);
485
	//Bouton de validation du formulaire
486
	$bouton[] = &HTML_QuickForm::createElement('submit', 'valider', BAZ_VALIDER);
487
	$formtemplate->addGroup($bouton, null, null, '');
23 florian 488
	$res.=$formtemplate->toHTML()."\n";
22 florian 489
	$requeteSQL='';
490
	//affichage des résultats de la recherche si le formulaire a été envoyé
491
	if (isset($_POST['nature'])) {
492
		//préparation de la requète pour trouver les mots clés
23 florian 493
		if (($_POST['recherche_mots_cles']!='')and($_POST['recherche_mots_cles']!=BAZ_MOT_CLE)) {
22 florian 494
			//découpage des mots clés
495
			$recherche = split(' ', $_POST['recherche_mots_cles']) ;
496
			$nbmots=count($recherche);
497
			for ($i=0; $i<$nbmots; $i++) {
498
				if ($i>0) $requeteSQL.=' OR ';
499
				$requeteSQL.='bf_titre LIKE "%'.$recherche[$i].'%" OR bf_description LIKE "%'.$recherche[$i].'%" ';
500
			}
501
		}
23 florian 502
		//génération de la liste de flux à afficher
22 florian 503
		$res.=RSSversHTML(gen_RSS($_POST['nature'], '', $_POST['personnes'], 1, $requeteSQL), 1, 'jm') ;
504
	}
505
	else {
23 florian 506
		//on affiche toutes les annonces
507
		$res .= RSSversHTML(gen_RSS($typeannonce, '', '', 1, ''), 0, 'jm') ;
22 florian 508
	}
5 florian 509
	return $res;
510
}
23 florian 511
?>