Subversion Repositories Applications.bazar

Rev

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