Subversion Repositories Applications.bazar

Rev

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