Subversion Repositories Applications.bazar

Rev

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