Subversion Repositories Applications.bazar

Rev

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