Subversion Repositories Applications.bazar

Rev

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