Subversion Repositories Applications.bazar

Rev

Rev 123 | Rev 126 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
5 florian 1
<?php
125 alexandre_ 2
/*vim: set expandtab tabstop=4 shiftwidth=4: */
3
// +------------------------------------------------------------------------------------------------------+
4
// | PHP version 4.1                                                                                      |
5
// +------------------------------------------------------------------------------------------------------+
6
// | Copyright (C) 2004 Tela Botanica (accueil@tela-botanica.org)                                         |
7
// +------------------------------------------------------------------------------------------------------+
8
// | This library is free software; you can redistribute it and/or                                        |
9
// | modify it under the terms of the GNU Lesser General Public                                           |
10
// | License as published by the Free Software Foundation; either                                         |
11
// | version 2.1 of the License, or (at your option) any later version.                                   |
12
// |                                                                                                      |
13
// | This library is distributed in the hope that it will be useful,                                      |
14
// | but WITHOUT ANY WARRANTY; without even the implied warranty of                                       |
15
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU                                    |
16
// | Lesser General Public License for more details.                                                      |
17
// |                                                                                                      |
18
// | You should have received a copy of the GNU Lesser General Public                                     |
19
// | License along with this library; if not, write to the Free Software                                  |
20
// | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA                            |
21
// +------------------------------------------------------------------------------------------------------+
22
// CVS : $Id: bazar.fonct.rss.php,v 1.48 2006-05-17 09:50:13 alexandre_tb Exp $
23
/**
24
*
25
*@package bazar
26
//Auteur original :
27
*@author        Alexandre GRANIER <alexandre@tela-botanica.org>
28
*@author        Florian Schmitt <florian@ecole-et-nature.org>
29
//Autres auteurs :
30
*@copyright     Tela-Botanica 2000-2006
31
*@version       $Revision: 1.48 $
32
// +------------------------------------------------------------------------------------------------------+
33
*/
116 florian 34
 
125 alexandre_ 35
// +------------------------------------------------------------------------------------------------------+
36
// |                                            ENTETE du PROGRAMME                                       |
37
// +------------------------------------------------------------------------------------------------------+
38
 
116 florian 39
require_once BAZ_CHEMIN_APPLI.'bibliotheque/bazar.class.php';
40
require_once BAZ_CHEMIN_APPLI.'bibliotheque/bazar.fonct.php';
41
 
125 alexandre_ 42
 
5 florian 43
/** baz_valeur_template() - Renvoi des valeurs inscrite dans le fichier de template
44
*
68 florian 45
* @param   string valeur du template de bazar_nature
5 florian 46
*
47
* @return   mixed  tableau contenant les champs du fichier template
48
*/
68 florian 49
function baz_valeurs_template($valeur_template) {
5 florian 50
	//Parcours du fichier de templates, pour mettre les champs spécifiques
51
	$nblignes=0;
68 florian 52
	$chaine = explode ("\n", $valeur_template);
5 florian 53
	array_pop($chaine);
54
	foreach ($chaine as $ligne)  {
55
		$souschaine = explode ("***", $ligne) ;
56
		$tableau[$nblignes]['type'] = trim($souschaine[0]) ;
57
		if (isset($souschaine[1])) {$tableau[$nblignes]['nom_bdd'] = trim($souschaine[1]);}
58
		else {$tableau[$nblignes]['nom_bdd'] ='';}
59
		if (isset($souschaine[2])) $tableau[$nblignes]['label'] = trim($souschaine[2]);
60
		else {$tableau[$nblignes]['label'] ='';}
61
		if (isset($souschaine[3])) $tableau[$nblignes]['limite1'] = trim($souschaine[3]);
62
		else {$tableau[$nblignes]['limite1'] ='';}
63
		if (isset($souschaine[4])) $tableau[$nblignes]['limite2'] = trim($souschaine[4]);
64
		else {$tableau[$nblignes]['limite2'] ='';}
65
		if (isset($souschaine[5])) $tableau[$nblignes]['defaut'] = trim($souschaine[5]);
66
		else {$tableau[$nblignes]['defaut'] ='';}
67
		if (isset($souschaine[6])) $tableau[$nblignes]['table_source'] = trim($souschaine[6]);
68
		else {$tableau[$nblignes]['table_source'] ='';}
69
		if (isset($souschaine[7])) $tableau[$nblignes]['id_source'] = trim($souschaine[7]);
70
		else {$tableau[$nblignes]['id_source'] ='';}
71
		if (isset($souschaine[8])) $tableau[$nblignes]['obligatoire'] = trim($souschaine[8]);
72
		else {$tableau[$nblignes]['obligatoire'] ='';}
88 alexandre_ 73
		if (isset($souschaine[9])) $tableau[$nblignes]['recherche'] = trim($souschaine[9]);
64 florian 74
		else {$tableau[$nblignes]['recherche'] ='';}
67 alexandre_ 75
 
76
 
77
		// traitement des cases à cocher, dans ce cas la, on a une table de jointure entre la table
78
		// de liste et la table bazar_fiche (elle porte un nom du genre bazar_ont_***)
79
		// dans le template, à la place d'un nom de champs dans 'nom_bdd', on a un nom de table
80
		// et 2 noms de champs séparés par un virgule ex : bazar_ont_theme,bot_id_theme,bot_id_fiche
81
 
82
		if (isset($tableau[$nblignes]['nom_bdd']) && preg_match('/,/', $tableau[$nblignes]['nom_bdd'])) {
83
			$tableau_info_jointe = explode (',', $tableau[$nblignes]['nom_bdd']) ;
84
			$tableau[$nblignes]['table_jointe'] = $tableau_info_jointe[0] ;
85
			$tableau[$nblignes]['champs_id_fiche'] = $tableau_info_jointe[1] ;
86
			$tableau[$nblignes]['champs_id_table_jointe'] = $tableau_info_jointe[2] ;
87
		}
5 florian 88
		$nblignes++;
89
	}
90
	return $tableau;
91
}
92
 
33 ddelon 93
/**  baz_voir_fiches() - Permet de visualiser en detail une liste de fiche  au format XHTML
94
*
95
* @global boolean Rajoute des informations internes à l'application (date de modification, lien vers la page de départ de l'appli)
96
* @global integer Tableau d(Identifiant des fiches à afficher
97
*
98
* @return   string  HTML
99
*/
100
function baz_voir_fiches($danslappli, $idfiches=array()) {
101
	$res='';
102
	foreach($idfiches as $idfiche) {
103
			$res.=baz_voir_fiche($danslappli, $idfiche);
104
	}
105
	return $res;
106
}
54 florian 107
 
108
 
118 florian 109
/**  baz_voir_fiche() - Permet de visualiser en detail une fiche  au format XHTML
5 florian 110
*
118 florian 111
* @global boolean Rajoute des informations internes a l'application (date de modification, lien vers la page de départ de l'appli) si a 1
112
* @global integer Identifiant de la fiche a afficher
5 florian 113
*
114
* @return   string  HTML
115
*/
116
function baz_voir_fiche($danslappli, $idfiche='') {
55 florian 117
	$res='';
5 florian 118
	if (isset($_GET['id_fiche'])) $GLOBALS['_BAZAR_']['id_fiche']=$_GET['id_fiche'];
118 florian 119
	if ($idfiche!='') $GLOBALS['_BAZAR_']['id_fiche']=$idfiche;
9 florian 120
	$url= $GLOBALS['_BAZAR_']['url'];
121
	$url->addQueryString('action', BAZ_VOIR_FICHE);
122
	$url->addQueryString('id_fiche', $GLOBALS['_BAZAR_']['id_fiche']);
123
	$url = preg_replace ('/&amp;/', '&', $url->getURL()) ;
7 florian 124
 
118 florian 125
	//cas ou la fiche a été validee
126
	if (isset($_GET['publiee'])) {
127
		publier_fiche($_GET['publiee']);
128
	}
129
 
130
	//cas on une structure s'approprie une ressource
131
	if (isset($_GET['appropriation'])) {
132
		if ($_GET['appropriation']==1) {
133
			$requete = 'INSERT INTO bazar_appropriation VALUES ('.$GLOBALS['_BAZAR_']['id_fiche'].', '.$GLOBALS['AUTH']->getAuthData(BAZ_CHAMPS_ID).')';
134
			$resultat = $GLOBALS['_BAZAR_']['db']->query($requete) ;
135
		}
136
		elseif ($_GET['appropriation']==0) {
137
			$requete = 'DELETE FROM bazar_appropriation WHERE  ba_ce_id_fiche='.$GLOBALS['_BAZAR_']['id_fiche'].' AND ba_ce_id_structure='.$GLOBALS['AUTH']->getAuthData(BAZ_CHAMPS_ID);
138
			$resultat = $GLOBALS['_BAZAR_']['db']->query($requete) ;
139
		}
140
	}
141
 
142
	//cas ou un commentaire a été entre
9 florian 143
	if (isset($_POST['Nom'])) {
38 alexandre_ 144
		$requete = 'INSERT INTO bazar_commentaires VALUES ('.
145
					baz_nextid('bazar_commentaires', 'bc_id_commentaire', $GLOBALS['_BAZAR_']['db']).
146
					', '.$GLOBALS['_BAZAR_']['id_fiche'].', "'.$_POST['Nom'].'", "'.$_POST['Commentaire'].
147
					'", NOW() )';
9 florian 148
		$resultat = $GLOBALS['_BAZAR_']['db']->query($requete) ;
149
	}
54 florian 150
	//cas ou un commentaire va etre supprime
15 florian 151
	elseif (isset($_GET['id_commentaire'])) {
152
		$requete = 'DELETE FROM bazar_commentaires WHERE bc_id_commentaire='.$_GET['id_commentaire'].' LIMIT 1';
9 florian 153
		$resultat = $GLOBALS['_BAZAR_']['db']->query($requete) ;
154
	}
15 florian 155
	else {
156
		if (isset($_GET['action'])) {
157
			if ($_GET['action']==BAZ_VOIR_FICHE) {
54 florian 158
				//sinon on met a jour le nb de visites pour la fiche, puisque c'est une simple consultation
15 florian 159
				$requete = 'UPDATE bazar_fiche SET bf_nb_consultations=bf_nb_consultations+1 WHERE bf_id_fiche='.$GLOBALS['_BAZAR_']['id_fiche'];
160
				$resultat = $GLOBALS['_BAZAR_']['db']->query($requete) ;
161
			}
162
		}
163
	}
9 florian 164
 
45 florian 165
	//on verifie si l'utilisateur est administrateur
9 florian 166
	$est_admin=0;
167
	if ($GLOBALS['AUTH']->getAuth()) {
168
		$requete='SELECT bn_id_nature FROM bazar_nature WHERE bn_label_nature="'.$GLOBALS['_BAZAR_']['typeannonce'].'"';
169
		$resultat = $GLOBALS['_BAZAR_']['db']->query($requete) ;
170
		if (DB::isError($resultat)) {
171
			die ($resultat->getMessage().$resultat->getDebugInfo()) ;
172
		}
173
		$result = $resultat->fetchRow(DB_FETCHMODE_ASSOC);
69 alexandre_ 174
		$id_nature = $result['bn_id_nature'];
9 florian 175
		if ((niveau_droit($result['bn_id_nature'],$GLOBALS['AUTH']->getAuthData(BAZ_CHAMPS_ID))=='administrateur')
176
		     or(niveau_droit('0',$GLOBALS['AUTH']->getAuthData(BAZ_CHAMPS_ID))=='superadministrateur'))
177
		{
178
		        $est_admin=1;
179
		}
180
	}
76 florian 181
	//affiche le titre sous forme d'image
87 alexandre_ 182
	if (isset ($GLOBALS['_BAZAR_']['image_titre']) && $GLOBALS['_BAZAR_']['image_titre']!='') {
56 florian 183
		$res .= '<img id="BAZ_img_titre" src="client/bazar/images/'.$GLOBALS['_BAZAR_']['image_titre'].'" alt="'.$GLOBALS['_BAZAR_']['typeannonce'].'" />'.'<br />'."\n";
55 florian 184
	}
56 florian 185
	//affiche le texte sinon
186
	else {
118 florian 187
		$res .= '<h2 class="BAZ_titre">'.$GLOBALS['_BAZAR_']['typeannonce'].'</h2>'."\n";
56 florian 188
	}
55 florian 189
	$res .= '<div class="BAZ_cadre_fiche">'."\n";
190
	$requete = 'SELECT * FROM bazar_fiche WHERE bf_id_fiche='.$GLOBALS['_BAZAR_']['id_fiche'];
123 alexandre_ 191
 
55 florian 192
	$resultat = $GLOBALS['_BAZAR_']['db']->query($requete) ;
123 alexandre_ 193
	(DB::isError($resultat)) ? die(BOG_afficherErreurSql(__FILE__, __LINE__, $resultat->getMessage(), $requete))
194
	    : '';
195
 
55 florian 196
	$ligne = $resultat->fetchRow(DB_FETCHMODE_ASSOC) ;
87 alexandre_ 197
	$GLOBALS['_BAZAR_']['annonceur'] = $ligne['bf_ce_utilisateur'] ;
45 florian 198
	//si le template existe, on genere le template
5 florian 199
	if ((file_exists(BAZ_CHEMIN_APPLI.'templates/'.$GLOBALS['_BAZAR_']['typeannonce'].'-fiche.php'))) {
200
		include_once(BAZ_CHEMIN_APPLI.'templates/'.$GLOBALS['_BAZAR_']['typeannonce'].'-fiche.php');
55 florian 201
		$res .=genere_fiche($ligne);
5 florian 202
	}
203
	//on affiche ligne par ligne sinon
83 alexandre_ 204
	else {
55 florian 205
		//cas d'une image personalisée
7 florian 206
		if (isset($ligne['bf_url_image'])) {
207
			$res .= '<div id="fiche_image">'."\n";
118 florian 208
			$res .= '<img src="client/bazar/upload/'.$ligne['bf_url_image'].'" border=0 alt="'.BAZ_TEXTE_IMG_ALTERNATIF.'" width="130" height="130"  />'."\n";
7 florian 209
			$res .= '</div>'."\n";
210
		}
55 florian 211
		//cas d'une image par défaut
87 alexandre_ 212
		elseif (isset ($GLOBALS['_BAZAR_']['image_logo']) && $GLOBALS['_BAZAR_']['image_logo']!='') {
55 florian 213
			$res .= '<div id="fiche_image">'."\n";
75 florian 214
			$res .= '<img src="client/bazar/images/'.$GLOBALS['_BAZAR_']['image_logo'].'" border=0 alt="'.BAZ_TEXTE_IMG_ALTERNATIF.'" width="130" height="130" />'."\n";
55 florian 215
			$res .= '</div>'."\n";
7 florian 216
		}
55 florian 217
		$res .= '<h1 id="fiche_titre">'.$ligne['bf_titre'].'</h1>'."\n";
122 florian 218
		$res .= '<div id="BAZ_description">'.nl2br($ligne['bf_description']).'</div>'."\n";
69 alexandre_ 219
		$tableau=baz_valeurs_template($GLOBALS['_BAZAR_']['template']);
5 florian 220
		for ($i=0; $i<count($tableau); $i++) {
118 florian 221
			if (isset($ligne[$tableau[$i]['nom_bdd']]) && ( $tableau[$i]['type']=='texte' || $tableau[$i]['type']=='textelong' ) ) {
87 alexandre_ 222
				$val=$tableau[$i]['nom_bdd'];
122 florian 223
				if (!in_array($val, array ('bf_titre', 'bf_description'))) {
224
					if ($ligne[$val] != '' and $ligne[$val] != BAZ_CHOISIR and $ligne[$val] != BAZ_NON_PRECISE) {
105 florian 225
						$res .= '<span class="rubrique">'.$tableau[$i]['label'].':</span>'."\n";
122 florian 226
						$res .= '<span class="description"> '.nl2br($ligne[$val]).'</span>'."\n".'<br />'."\n";
7 florian 227
					}
5 florian 228
				}
229
			}
118 florian 230
			elseif ( $tableau[$i]['type']=='liste' || $tableau[$i]['type']=='checkbox' ) {
75 florian 231
				//pour les champs renseignes par une liste, on va chercher le label de la liste, plutot que l'id
232
				$requete = 'SELECT blv_label FROM bazar_fiche_valeur_liste, bazar_liste_valeurs WHERE bfvl_ce_fiche='.$GLOBALS['_BAZAR_']['id_fiche'].
233
				' AND  bfvl_ce_liste='.$tableau[$i]['nom_bdd'].' AND bfvl_valeur=blv_valeur AND blv_ce_liste='.$tableau[$i]['nom_bdd'].' AND blv_ce_i18n="'.$GLOBALS['_BAZAR_']['langue'].'"';
234
				$resultat = $GLOBALS['_BAZAR_']['db']->query($requete) ;
235
				if (DB::isError ($resultat)) {
236
					die ($resultat->getMessage().'<br />'.$resultat->getDebugInfo()) ;
237
				}
76 florian 238
				$val='';$nb=0;
75 florian 239
				while ($tab = $resultat->fetchRow()) {
76 florian 240
					if ($nb>0) $val .= ', ';
241
					$val .= $tab[0];
242
					$nb++;
75 florian 243
				}
122 florian 244
				if ($val != '' and $val != BAZ_CHOISIR and $val != BAZ_NON_PRECISE) {
245
					$res .= '<span class="rubrique">'.$tableau[$i]['label'].':</span>'."\n";
246
					$res .= '<span class="description"> '.$val.'</span>'."\n".'<br />'."\n";
247
				}
75 florian 248
			}
122 florian 249
			elseif ( $tableau[$i]['type']=='listedatedeb' || $tableau[$i]['type']=='listedatefin' ) {
250
				$val=$tableau[$i]['nom_bdd'];
251
				if (!in_array($val, array ('bf_date_debut_validite_fiche', 'bf_date_fin_validite_fiche'))) {
252
					if ($ligne[$val] != '') {
253
						$res .= '<span class="rubrique">'.$tableau[$i]['label'].':</span>'."\n";
254
						$res .= '<span class="description"> '.strftime('%d.%m.%Y',strtotime($ligne[$val])).'</span>'."\n".'<br />'."\n";
255
					}
256
				}
257
			}
5 florian 258
		}
7 florian 259
	//afficher les liens pour l'annonce
260
	$requete = 'SELECT  bu_url, bu_descriptif_url FROM bazar_url WHERE bu_ce_fiche='.$GLOBALS['_BAZAR_']['id_fiche'];
261
	$resultat = $GLOBALS['_BAZAR_']['db']->query($requete) ;
262
	if (DB::isError($resultat)) {
263
		die ($resultat->getMessage().$resultat->getDebugInfo()) ;
264
	}
265
	if ($resultat->numRows()>0) {
266
		$res .= '<span class="rubrique">'.BAZ_LIEN_INTERNET.':</span>'."\n";
267
		$res .= '<span class="description">'."\n";
268
		$res .= '<ul>'."\n";
269
		while ($ligne1 = $resultat->fetchRow(DB_FETCHMODE_ASSOC)) {
270
			$res .= '<li><a href="'.$ligne1['bu_url'].'" target="_blank">'.$ligne1['bu_descriptif_url'].'</a></li>'."\n";
5 florian 271
		}
7 florian 272
		$res .= '</ul></span>'."\n";
273
	}
274
 
275
	//afficher les fichiers pour l'annonce
276
	$requete = 'SELECT  bfj_description, bfj_fichier FROM bazar_fichier_joint WHERE bfj_ce_fiche='.$GLOBALS['_BAZAR_']['id_fiche'];
277
	$resultat = $GLOBALS['_BAZAR_']['db']->query($requete) ;
278
	if (DB::isError($resultat)) {
279
		die ($resultat->getMessage().$resultat->getDebugInfo()) ;
280
	}
281
	if ($resultat->numRows()>0) {
282
		$res .= '<span class="rubrique">'.BAZ_LISTE_FICHIERS_JOINTS.':</span>'."\n";
283
		$res .= '<span class="description">'."\n";
284
		$res .= '<ul>'."\n";
285
		while ($ligne2 = $resultat->fetchRow(DB_FETCHMODE_ASSOC)) {
118 florian 286
			$res .= '<li><a href="client/bazar/upload/'.$ligne2['bfj_fichier'].'">'.$ligne2['bfj_description'].'</a></li>'."\n";
7 florian 287
		}
288
		$res .= '</ul></span>'."\n";
289
	}
9 florian 290
	$res .= '<div class="bulle_haut">&nbsp;</div>'."\n";
291
	$res .= '<div class="bulle_corps">'."\n";
7 florian 292
 
45 florian 293
	//affichage du redacteur de la fiche
69 alexandre_ 294
	$requete = 'SELECT '.BAZ_CHAMPS_NOM.', '.BAZ_CHAMPS_PRENOM.', '.BAZ_CHAMPS_EMAIL.
295
					' FROM '.BAZ_ANNUAIRE.' WHERE '.BAZ_CHAMPS_ID.'='.$ligne['bf_ce_utilisateur'];
7 florian 296
	$resultat = $GLOBALS['_BAZAR_']['db']->query($requete) ;
297
	if (DB::isError($resultat)) {
298
		die ($resultat->getMessage().$resultat->getDebugInfo()) ;
299
	}
300
	while ($redacteur = $resultat->fetchRow(DB_FETCHMODE_ASSOC)) {
301
		$res .= BAZ_FICHE_ECRITE.'<a href="mailto:'.$redacteur[BAZ_CHAMPS_EMAIL].'">'.$redacteur[BAZ_CHAMPS_PRENOM].' '.$redacteur[BAZ_CHAMPS_NOM].'</a><br />'."\n";
302
	}
76 florian 303
	$res .= BAZ_NB_VUS.'<strong>'.$ligne['bf_nb_consultations'].'</strong>'.BAZ_FOIS.'<br />'."\n";
7 florian 304
	$res .= '</div>'."\n";
9 florian 305
	$res .= '<div class="bulle_bas">&nbsp;</div>'."\n";
7 florian 306
	$res .= '<div id="BAZ_bas_page">';
55 florian 307
	}
9 florian 308
 
45 florian 309
	//informations complementaires (id fiche, etat publication,... )
118 florian 310
	if ($danslappli==1) {
311
		if ($ligne['bf_statut_fiche']==1 && $GLOBALS['_BAZAR_']['appropriation']!=1 ) {
55 florian 312
			$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 313
		}
118 florian 314
		elseif ($GLOBALS['_BAZAR_']['appropriation']!=1 || $ligne['bf_statut_fiche']!=1) {
315
			$res .= '<span class="rubrique">'.BAZ_PUBLIEE.':</span> '.BAZ_NON;
316
			if ( $est_admin ) {
317
				$res .= '&nbsp;&nbsp;&nbsp;<strong>'.BAZ_VALIDER_PUBLICATION.'&nbsp;:&nbsp;</strong>'."\n";
318
				$lien_publie = &$GLOBALS['_BAZAR_']['url'];
319
				$lien_publie->addQueryString('action', BAZ_VOIR_FICHE);
320
				$lien_publie->addQueryString('id_fiche', $GLOBALS['_BAZAR_']['id_fiche']);
321
				$lien_publie->addQueryString('typeannonce', $ligne['bf_ce_nature']);
322
				$lien_publie->addQueryString('publiee', 1);
323
				$res .= '<a href="'.$lien_publie->getURL().'">'.BAZ_OUI.'</a>&nbsp;/&nbsp;';
324
				$lien_publie->removeQueryString('publiee');
325
				$lien_publie->addQueryString('publiee', 0);
326
				$res .='<a href="'.$lien_publie->getURL().'">'.BAZ_NON.'</a>'."\n";
327
				$lien_publie->removeQueryString('publiee');
328
			}
329
			$res .= '<br />'."\n";
7 florian 330
		}
118 florian 331
		//affichage des infos pouvant interesser les admins
332
		if ( $est_admin ) {
333
			$res .= '<span class="rubrique">'.BAZ_NUM_FICHE.':</span> '.$GLOBALS['_BAZAR_']['id_fiche'].'<br />'."\n";
334
			$res .= '<span class="rubrique">'.BAZ_DATE_CREATION.' :</span> '.strftime('%d.%m.%Y &agrave; %H:%M',strtotime($ligne['bf_date_creation_fiche'])).'<br />'."\n";
335
		}
336
		//affichage des infos et du lien pour la mise a jour de la fiche
337
		if ( $est_admin || $GLOBALS['_BAZAR_']['annonceur']==$GLOBALS['AUTH']->getAuthData(BAZ_CHAMPS_ID) ) {
338
			$res .= '<span class="rubrique">'.BAZ_DATE_MAJ.' :</span> '.strftime('%d.%m.%Y &agrave; %H:%M',strtotime($ligne['bf_date_maj_fiche']))."\n";
9 florian 339
			$lien_modifier=$GLOBALS['_BAZAR_']['url'];
340
			$lien_modifier->addQueryString('action', BAZ_ACTION_MODIFIER);
341
			$lien_modifier->addQueryString('id_fiche', $GLOBALS['_BAZAR_']['id_fiche']);
69 alexandre_ 342
			$lien_modifier->addQueryString('typeannonce', $ligne['bf_ce_nature']);
118 florian 343
			$res .= '&nbsp;&nbsp;&nbsp;<a href="'.$lien_modifier->getURL().'">'.BAZ_MODIFIER_LA_FICHE.'</a>'."\n";
5 florian 344
		}
7 florian 345
	}
346
	$res .= '</div>'."\n";
347
	$res .= '</div>'."\n";
348
 
39 florian 349
	//on ajoute les appropriations, s'il le faut
350
	if (($danslappli==1)and($GLOBALS['_BAZAR_']['appropriation']==1)) {
351
		$res .= '<br />'."\n".'<div class="BAZ_cadre_fiche">'."\n";
118 florian 352
		$res .= '<h3>'.BAZ_LES_STRUCTURES_POSSEDANT_UNE_RESSOURCE.'</h3>'."\n";
40 florian 353
		$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';
354
		$resultat = $GLOBALS['_BAZAR_']['db']->query($requete) ;
355
		if (DB::isError ($resultat)) {
356
			die ($resultat->getMessage().'<br />'.$resultat->getDebugInfo()) ;
357
		}
118 florian 358
		$possede_ressource=0;
40 florian 359
		if ($resultat->numRows()>0) {
360
			$res .= BAZ_IL_Y_A.$resultat->numRows().' ';
118 florian 361
			if ($resultat->numRows()==1) $res .= BAZ_STRUCTURE_POSSEDANT.'<br />'."\n";
362
			else $res .= BAZ_STRUCTURES_POSSEDANT.'<br />'."\n";
363
			$res .= '<ul>'."\n";
40 florian 364
			while ($ligne = $resultat->fetchRow(DB_FETCHMODE_ASSOC)) {
118 florian 365
				$res .= '<li><a href="'.BAZ_URL_ANNUAIRE.'&amp;voir_fiche='.$ligne[BAZ_CHAMPS_ID].'" onclick="javascript:window.open(this.href);return false;">'.$ligne[BAZ_CHAMPS_NOM].'</a></li>'."\n";
366
				if ($GLOBALS['AUTH']->getAuth() && $GLOBALS['AUTH']->getAuthData(BAZ_CHAMPS_ID)==$ligne[BAZ_CHAMPS_ID]) $possede_ressource=1;
40 florian 367
			}
118 florian 368
			$res .= '</ul><br />'."\n";
40 florian 369
		}
370
		else $res .= BAZ_PAS_D_APPROPRIATION.'<br /><br />'."\n";
118 florian 371
		$res .='<p class="bulle_corps">'."\n";
372
		$lien_appropriation = $GLOBALS['_BAZAR_']['url'];
373
		$lien_appropriation->addQueryString('action', BAZ_VOIR_FICHE);
374
		$lien_appropriation->addQueryString('id_fiche', $GLOBALS['_BAZAR_']['id_fiche']);
375
		if ($possede_ressource) {
376
			$lien_appropriation->addQueryString('appropriation', 0);
377
			$res .= BAZ_POSSEDE_DEJA_RESSOURCE.'<br />'."\n".'<a href="'.$lien_appropriation->getURL().'">'.BAZ_CLIQUER_POUR_VOUS_ENLEVER.'</a>'."\n";
378
			$lien_appropriation->removeQueryString('appropriation');
379
		}
380
		elseif ($GLOBALS['AUTH']->getAuth() && $GLOBALS['AUTH']->getAuthData(BAZ_CHAMPS_EST_STRUCTURE)) {
381
			$lien_appropriation->addQueryString('appropriation', 1);
382
			$res .= BAZ_SI_POSSEDE_RESSOURCE.'<br />'."\n".'<a href="'.$lien_appropriation->getURL().'">'.BAZ_CLIQUER_POUR_APPARAITRE.'</a>'."\n";
383
			$lien_appropriation->removeQueryString('appropriation');
384
		}
385
		elseif ($GLOBALS['AUTH']->getAuth() && !$GLOBALS['AUTH']->getAuthData(BAZ_CHAMPS_EST_STRUCTURE)) {
386
			$res .= BAZ_IL_FAUT_ETRE_STRUCTURE."\n";
387
		}
388
		elseif (!$GLOBALS['AUTH']->getAuth()) {
389
			$res .= BAZ_IL_FAUT_ETRE_IDENTIFIE_STRUCTURE."\n";
390
		}
391
		$res .='</p>'."\n";
39 florian 392
		$res .= '</div>'."\n";
393
	}
394
 
7 florian 395
	//on ajoute les commentaires, s'il le faut
22 florian 396
	if (($danslappli==1)and($GLOBALS['_BAZAR_']['commentaire']==1)) {
39 florian 397
		$res .= '<br />'."\n".'<div class="BAZ_cadre_fiche">'."\n";
7 florian 398
		$res .= '<h3>'.BAZ_LES_COMMENTAIRES.'</h3>'."\n";
399
		$requete = 'SELECT * FROM bazar_commentaires WHERE bc_ce_id_fiche='.$GLOBALS['_BAZAR_']['id_fiche'].' ORDER BY bc_date ASC';
5 florian 400
		$resultat = $GLOBALS['_BAZAR_']['db']->query($requete) ;
7 florian 401
		if (DB::isError ($resultat)) {
402
			die ($resultat->getMessage().'<br />'.$resultat->getDebugInfo()) ;
5 florian 403
		}
404
		if ($resultat->numRows()>0) {
9 florian 405
			$res .= BAZ_IL_Y_A.$resultat->numRows().' ';
406
			if ($resultat->numRows()==1) $res .= BAZ_COMMENTAIRE.'<br />'."\n";
407
			else $res .= BAZ_COMMENTAIRES.'<br />'."\n";
5 florian 408
			while ($ligne = $resultat->fetchRow(DB_FETCHMODE_ASSOC)) {
9 florian 409
				$res .= '<div class="bulle_haut">&nbsp;</div>'."\n";
410
				$res .= '<div class="bulle_corps">'."\n";
411
				//affichage du commentaire
412
				$res .= $ligne['bc_commentaire'].'<br />'."\n";
413
				$res .= '</div>'."\n";
414
				$res .= '<div class="bulle_bas">'."\n";
15 florian 415
				$res .= '<div style="font-size:9px;margin-left:10px;">'.BAZ_PAR.' : <strong>'.$ligne['bc_nom'].'</strong>'.BAZ_ECRIT_LE.$ligne['bc_date'].'</div>'."\n";
118 florian 416
				//pour les identifies seulement, administrateurs de la rubrique ou superadmins
9 florian 417
				if ($est_admin==1) {
418
					$url_comment= $GLOBALS['_BAZAR_']['url'];
419
					$url_comment->addQueryString('action', BAZ_VOIR_FICHE);
420
					$url_comment->addQueryString('id_fiche', $GLOBALS['_BAZAR_']['id_fiche']);
15 florian 421
					$url_comment->addQueryString('id_commentaire', $ligne['bc_id_commentaire']);
422
					$res .= '<a href="'.$url_comment->getURL().'" style="font-size:9px;float:right;">'.BAZ_SUPPRIMER.'</a>'."\n";
9 florian 423
				}
424
				$res .= '</div>'."\n";
5 florian 425
			}
426
		}
9 florian 427
		else $res .= BAZ_PAS_DE_COMMENTAIRES.'<br /><br />'."\n";
428
 
429
		//formulaire des commentaires
118 florian 430
		$form_commentaire = new HTML_QuickForm('bazar_commentaire', 'post', $url);
9 florian 431
		$squelette =& $form_commentaire->defaultRenderer();
432
		$squelette->setFormTemplate("\n".'<form {attributes}>'."\n".'{content}'."\n".'</form>'."\n");
118 florian 433
		$squelette->setElementTemplate( '<label style="width:200px;">{label}'.
434
										'<!-- BEGIN required --><span class="symbole_obligatoire">&nbsp;*</span><!-- END required -->'."\n".
435
									    '</label><br />'."\n".'{element}<br />'."\n");
436
		$squelette->setRequiredNoteTemplate("\n".'<span class="symbole_obligatoire"> *{requiredNote}</span>'."\n");
437
		$option=array('style'=>'width:300px;border:1px solid #000;', 'maxlength'=>100);
9 florian 438
		$form_commentaire->addElement('text', 'Nom', BAZ_ENTREZ_VOTRE_NOM, $option);
118 florian 439
		$option=array('style'=>'width:95%;height:100px;white-space: pre;padding:3px;border:1px solid #000;');
116 florian 440
		require_once PAP_CHEMIN_API_PEAR.'HTML/QuickForm/textarea.php';
9 florian 441
		$formtexte= new HTML_QuickForm_textarea('Commentaire', BAZ_ENTREZ_VOTRE_COMMENTAIRE, $option);
442
		$form_commentaire->addElement($formtexte) ;
118 florian 443
		$option=array('style'=>'border:1px solid #000;');
444
		$form_commentaire->addElement('submit', 'Envoyer', BAZ_ENVOYER, $option);
9 florian 445
		$form_commentaire->addRule('Nom', BAZ_NOM_REQUIS, 'required', '', 'client') ;
446
		$form_commentaire->addRule('Commentaire', BAZ_COMMENTAIRE_REQUIS, 'required', '', 'client') ;
447
		$form_commentaire->setRequiredNote(BAZ_CHAMPS_REQUIS) ;
448
		$res .= $form_commentaire->toHTML();
7 florian 449
		$res .= '</div>'."\n";
450
	}
451
 
5 florian 452
	return $res ;
453
}
454
 
455
 
456
/** RSSversHTML () transforme un flux RSS (en XML) en page HTML
457
*
458
*   On passe en paramètre le contenu du flux RSS, on affiche ou non la description,
459
*   et on choisit de format de la date à l'affichage. On a en sortie du code HTML à afficher
460
*
461
*   @param  string   le contenu du flux RSS
462
*   @param  boolean  afficher ou non la description
463
*   @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
464
*
465
*   @return  string    le code HTML
466
*/
64 florian 467
function RSSversHTML($rss, $voirdesc, $formatdate, $affichenb) {
5 florian 468
	if ($rss!='') {
54 florian 469
		$rawitems='';$title='';$url='';$cat='';$date='';
5 florian 470
		$res='';
471
		if( eregi('<item>(.*)</item>', $rss, $rawitems ) ) {
472
			$items = explode('<item>', $rawitems[0]);
83 alexandre_ 473
			$res.='<ul id="BAZ_liste_fiche">'."\n";
5 florian 474
			for( $i = 0; $i < count($items)-1; $i++ ) {
475
				eregi('<title>(.*)</title>',$items[$i+1], $title );
476
				eregi('<link>(.*)</link>',$items[$i+1], $url );
477
				eregi('<description>(.*)</description>',$items[$i+1], $cat);
478
				eregi('<pubDate>(.*)</pubDate>',$items[$i+1], $date);
479
				$res.='<li>';
480
				if ($formatdate=='jm') {$res.=strftime('%d.%m',strtotime($date[1])).': ';}
481
				if ($formatdate=='jma') {$res.=strftime('%d.%m.%Y',strtotime($date[1])).': ';}
482
				if ($formatdate=='jmh') {$res.=strftime('%d.%m %H:%M',strtotime($date[1])).': ';}
483
				if ($formatdate=='jmah') {$res.=strftime('%d.%m.%Y %H:%M',strtotime($date[1])).': ';}
72 alexandre_ 484
				$res.='<a href="'.preg_replace ('/&amp;/', '&', $url[1]).'">'.$title[1].'</a>';
5 florian 485
				if ($voirdesc) {$res.=$cat[1];}
72 alexandre_ 486
				// Ajout du bouton supprimer pour les superadministrateur
98 florian 487
				if (($GLOBALS['AUTH']->getAuth() && niveau_droit(0,$GLOBALS['AUTH']->getAuthData(BAZ_CHAMPS_ID))=='superadministrateur')and($url[1]!='#')) {
72 alexandre_ 488
					$mon_url = preg_replace ('/&amp;/', '&', $url[1]) ;
489
					$url_suppr = new Net_URL(preg_replace ('/&amp;/', '&', $mon_url)) ;
490
					$url_suppr->addQueryString('action', BAZ_ACTION_SUPPRESSION) ;
491
		        	$res .= ' ( <a href="'.$url_suppr->getURL().
492
							'" onclick="javascript:return confirm(\''.BAZ_SUPPRIMER.' ?\');">'.
493
							BAZ_SUPPRIMER.'</a> )'."\n" ;
494
					}
5 florian 495
				$res.='</li>'."\n";
496
			}
497
			$res.='</ul>'."\n";
64 florian 498
			if ($affichenb==1) {
499
				//une annonce trouvee, on accorde au singulier
500
				if (((count($items)-1)==1)and($title!=BAZ_PAS_D_ANNONCES)) {
501
					$res = '<br /><h4>'.BAZ_IL_Y_A.' 1 '.BAZ_FICHE_CORRESPONDANTE.'</h4><br />'."\n".$res;
502
				}
503
				//plusieures annonces trouvees, on accorde au pluriel
504
				else {
505
					$res = '<br /><h4>'.BAZ_IL_Y_A.(count($items)-1).' '.BAZ_FICHES_CORRESPONDANTES.'</h4><br />'."\n".$res;
506
				}
507
			}
508
			//cas des fiches pas trouvées
509
			if (((count($items)-1)==1)and($title[1]==BAZ_PAS_D_ANNONCES)) {
510
				$res = '<br /><h4>'.BAZ_PAS_D_ANNONCES.'</h4><br />'."\n";
511
			}
5 florian 512
		}
513
	}
514
	else $res = BAZ_PAS_D_ANNONCES;
125 alexandre_ 515
 
5 florian 516
	return $res;
517
}
518
 
83 alexandre_ 519
/** gen_RSS() - generer un fichier de flux RSS par type d'annonce
5 florian 520
*
521
* @param   string Le type de l'annonce (laisser vide pour tout type d'annonce)
522
* @param   integer Le nombre d'annonces a regrouper dans le fichier XML (laisser vide pour toutes)
523
* @param   integer L'identifiant de l'emetteur (laisser vide pour tous)
68 florian 524
* @param   integer L'etat de validation de l'annonce (laisser 1 pour les annonces validees, 0 pour les non-validees)
525
* @param   string La requete SQL personnalisee
5 florian 526
*
527
* @return  string Le code du flux RSS
528
*/
125 alexandre_ 529
function gen_RSS($typeannonce='', $nbitem='', $emetteur='', $valide=1, $requeteSQL='', $requeteSQLFrom = '', $requeteWhereListe = '') {
64 florian 530
	// generation de la requete MySQL personnalisee
531
	$req_where=0;
125 alexandre_ 532
	$requete = 'SELECT DISTINCT bf_id_fiche, bf_titre, bf_date_debut_validite_fiche, bf_description '.
533
				'FROM bazar_fiche, bazar_nature '.$requeteSQLFrom.' WHERE '.$requeteWhereListe;
64 florian 534
	if ($valide!=2) {
535
		$requete .= 'bf_statut_fiche='.$valide;
536
		$req_where=1;
537
	}
5 florian 538
	$nomflux=BAZ_DERNIERE_ACTU;
93 alexandre_ 539
	if (!is_array ($typeannonce) && $typeannonce!='' and $typeannonce!='toutes') {
64 florian 540
		if ($req_where==1) {$requete .= ' AND ';}
541
		$requete .= 'bf_ce_nature='.$typeannonce;
542
		$req_where=1;
5 florian 543
		//le nom du flux devient le type d'annonce
544
		$nomflux = $typeannonce;
545
	}
93 alexandre_ 546
	// Cas où il y plusieurs type d annonce demande
547
	if (is_array ($typeannonce)) {
548
		if ($req_where==1) {$requete .= ' AND ';}
549
		$requete .= 'bf_ce_nature IN (' ;
550
		$chaine = '';
551
		foreach ($typeannonce as $valeur) $chaine .= '"'.$valeur.'",' ;
552
		$requete .= substr ($chaine, 0, strlen ($chaine)-1) ;
95 alexandre_ 553
		$requete .= ') ';
93 alexandre_ 554
	}
111 alexandre_ 555
	$utilisateur = new Administrateur_bazar ($GLOBALS['AUTH']) ;
64 florian 556
	if ($valide!=0) {
96 alexandre_ 557
 
95 alexandre_ 558
		if ($utilisateur->isSuperAdmin()) {
96 alexandre_ 559
			$req_where=1;
83 alexandre_ 560
		} else {
96 alexandre_ 561
			if ($req_where==1) {
562
				$requete .= ' AND ';
563
			}
83 alexandre_ 564
			$requete .= '(bf_date_debut_validite_fiche<=NOW() or bf_date_debut_validite_fiche="0000-00-00")'.
565
						' AND (bf_date_fin_validite_fiche>=NOW() or bf_date_fin_validite_fiche="0000-00-00") AND bn_id_nature=bf_ce_nature';
566
		}
64 florian 567
	}
5 florian 568
	else $nomflux .= BAZ_A_MODERER;
69 alexandre_ 569
	if ($emetteur!='' && $emetteur!='tous') {
64 florian 570
		if ($req_where==1) {$requete .= ' AND ';}
571
		$requete .= 'bf_ce_utilisateur='.$emetteur;
572
		$req_where=1;
5 florian 573
		//requete pour afficher le nom de la structure
69 alexandre_ 574
		$requetenom = 'SELECT '.BAZ_CHAMPS_NOM.', '.BAZ_CHAMPS_PRENOM.' FROM '.
575
						BAZ_ANNUAIRE.' WHERE '.BAZ_CHAMPS_ID.'='.$emetteur;
5 florian 576
		$resultat = $GLOBALS['_BAZAR_']['db']->query($requetenom) ;
577
		if (DB::isError($resultat)) {
118 florian 578
			die ($resultat->getMessage().$resultat->getDebugInfo()) ;
5 florian 579
		}
580
		$ligne = $resultat->fetchRow(DB_FETCHMODE_ASSOC);
581
		$nomflux .= ' ('.$ligne[BAZ_CHAMPS_NOM].' '.$ligne[BAZ_CHAMPS_PRENOM].')';
582
	}
64 florian 583
	if ($requeteSQL!='') {
584
		if ($req_where==1) {$requete .= ' AND ';}
585
		$requete .= '('.$requeteSQL.')';
586
		$req_where=1;
587
	}
22 florian 588
	$requete .= ' ORDER BY  bf_date_debut_validite_fiche DESC, bf_date_fin_validite_fiche DESC, bf_date_maj_fiche DESC';
5 florian 589
	if ($nbitem!='') {$requete .= ' LIMIT 0,'.$nbitem;}
590
	$resultat = $GLOBALS['_BAZAR_']['db']->query($requete) ;
591
	if (DB::isError($resultat)) {
83 alexandre_ 592
		die ($resultat->getMessage().$resultat->getDebugInfo()) ;
5 florian 593
	}
64 florian 594
	// En-tete du flux RSS version 2.0
5 florian 595
	$xml = '<?xml version="1.0" encoding="ISO-8859-1"?>'."\n".'<rss version="2.0">'."\n";
596
	$xml .= '<channel>'."\n".'<title>'.$nomflux.'</title>'."\n".'<link>'.BAZ_RSS_ADRESSESITE.'</link>'."\n";
597
	$xml .= '<description>'.BAZ_RSS_DESCRIPTIONSITE.'</description>'."\n".'<language>fr-FR</language>'."\n".
598
	'<copyright>Copyright 2005 '.BAZ_RSS_NOMSITE.'</copyright>'."\n";
599
	// Ajout de la date actuelle de publication (suivant la DTD RSS)
600
	$xml .= '<lastBuildDate>'.strftime('%d %b %Y %H:%M:%S GMT').'</lastBuildDate>'."\n";
64 florian 601
	// En-tete suite et fin
5 florian 602
	$xml .= '<docs>http://www.stervinou.com/projets/rss/</docs>'."\n".'<category>'.BAZ_RSS_CATEGORIE.'</category>'."\n".
603
	'<managingEditor>'.BAZ_RSS_MANAGINGEDITOR.'</managingEditor>'."\n".'<webMaster>'.BAZ_RSS_WEBMASTER.'</webMaster>'."\n";
604
	$xml .= '<ttl>60</ttl>'."\n".'<image>'."\n".'<title>'.BAZ_RSS_NOMSITE.'</title>'."\n".'<url>'.BAZ_RSS_LOGOSITE.'</url>'."\n".
605
	'<link>'.BAZ_RSS_ADRESSESITE.'</link>'."\n".'</image>'."\n";
606
	if ($resultat->numRows()>0) {
607
		// Creation des items : titre + lien + description + date de publication
608
		while ($ligne = $resultat->fetchRow(DB_FETCHMODE_ASSOC)) {
609
			$xml .= '<item>'."\n";
610
			$xml .= '<title>'.$ligne['bf_titre'].'</title>'."\n";
611
			$lien=$GLOBALS['_BAZAR_']['url'];
612
			$lien->addQueryString('action', BAZ_VOIR_FICHE);
613
			$lien->addQueryString('id_fiche', $ligne['bf_id_fiche']);
614
			$xml .= '<link>'.str_replace ('&', '&amp;', $lien->getURL()).'</link>'."\n";
87 alexandre_ 615
			$xml .= '<description>'."\n".'<![CDATA[' ;
616
			if ($_GET['action'] != BAZ_VOIR_TOUTES_ANNONCES) {
125 alexandre_ 617
				//$xml .= baz_voir_fiche(0,$ligne['bf_id_fiche']) ;
618
				$xml .= $ligne['bf_description'] ;
87 alexandre_ 619
			}
620
			$xml .= ']]>'."\n".'</description>'."\n";
5 florian 621
			$xml .= '<pubDate>'.strftime('%d %b %Y %H:%M:%S GMT',strtotime($ligne['bf_date_debut_validite_fiche'])).'</pubDate>'."\n";
622
			$xml .= '</item>'."\n";
623
		}
624
	}
625
	else {//pas d'annonces
626
		$xml .= '<item>'."\n";
10 ddelon 627
		$xml .= '<title>'.BAZ_PAS_D_ANNONCES.'</title>'."\n";
22 florian 628
		$xml .= '<link>#</link>'."\n";
10 ddelon 629
		$xml .= '<description>'.BAZ_PAS_D_ANNONCES.'</description>'."\n";
5 florian 630
		$xml .= '<pubDate>'.strftime('%d %b %Y %H:%M:%S GMT',strtotime('12/12/2004')).'</pubDate>'."\n";
631
		$xml .= '</item>'."\n";
632
	}
633
	$xml .= '</channel>'."\n".'</rss>'."\n";
634
	return $xml;
635
}
636
 
637
 
638
/** baz_liste() Formate la liste de toutes les annonces actuelles
639
*
64 florian 640
*   @return  string    le code HTML a afficher
5 florian 641
*/
642
function baz_liste($typeannonce='toutes') {
45 florian 643
	//creation du lien pour le formulaire de recherche
22 florian 644
	$GLOBALS['_BAZAR_']['url']->addQueryString('action', BAZ_VOIR_TOUTES_ANNONCES);
93 alexandre_ 645
	$lien_formulaire = preg_replace ('/&amp;/', '&', $GLOBALS['_BAZAR_']['url']->getURL()) ;
22 florian 646
	$formtemplate = new HTML_QuickForm('formulaire', 'post', $lien_formulaire) ;
93 alexandre_ 647
	$squelette = &$formtemplate->defaultRenderer();
648
	$squelette->setFormTemplate("\n".'<form{attributes}>'."\n".'<ul style="padding:0;margin:0;">'."\n".
649
								'{content}'."\n".'</ul>'."\n".'</form>'."\n");
39 florian 650
	$squelette->setElementTemplate( '<li class="enligne">'."\n".'{element}'."\n".'</li>'."\n");
64 florian 651
 
652
	//cas du formulaire de recherche proposant de chercher parmis tous les types d'annonces
93 alexandre_ 653
	//requete pour obtenir l'id et le label des types d'annonces
654
	$requete = 'SELECT bn_id_nature, bn_label_nature '.
113 alexandre_ 655
	           'FROM bazar_nature WHERE bn_ce_id_menu='.$GLOBALS['_BAZAR_']['filtre'].' '.
93 alexandre_ 656
			   'ORDER BY bn_label_nature ASC';
657
	$resultat = $GLOBALS['_BAZAR_']['db']->query($requete) ;
658
	if (DB::isError($resultat)) {
659
		die ($resultat->getMessage().$resultat->getDebugInfo()) ;
660
	}
661
	$type_annonce_select['toutes']=BAZ_TOUS_TYPES_FICHES;
662
	while ($ligne = $resultat->fetchRow(DB_FETCHMODE_ASSOC)) {
105 florian 663
		$type_annonce_select[$ligne['bn_id_nature']] = $ligne['bn_label_nature'];
93 alexandre_ 664
		$tableau_typeannonces[] = $ligne['bn_id_nature'] ;
665
	}
68 florian 666
	if ($GLOBALS['_BAZAR_']['typeannonce']=='toutes') {
64 florian 667
		$res= '<h2>'.BAZ_TOUTES_LES_ANNONCES.'</h2><br />'."\n";
115 alexandre_ 668
		$option=array('style'=>'border:1px solid #000;width: 140px;font:12px Myriad, Arial, sans-serif;',
669
						'onchange' => 'javascript:this.form.submit();');
64 florian 670
		$formtemplate->addElement ('select', 'nature', BAZ_TYPEANNONCE, $type_annonce_select, $option) ;
22 florian 671
	}
64 florian 672
	//cas du type d'annonces prédéfini
673
	else {
105 florian 674
		$res = '<h2>'.BAZ_TOUTES_LES_ANNONCES_DE_TYPE.' '.$GLOBALS['_BAZAR_']['typeannonce'].'</h2>'."\n";
22 florian 675
	}
83 alexandre_ 676
 
677
 
64 florian 678
	//requete pour obtenir l'id, le nom et prenom de toutes les personnes ayant depose une fiche
93 alexandre_ 679
	// dans le but de construire l'élément de formulaire select avec les noms des émetteurs de fiche
680
 
681
	if (BAZ_RECHERCHE_PAR_EMETTEUR) {
682
		$requete = 'SELECT '.BAZ_CHAMPS_ID.', '.BAZ_CHAMPS_NOM.', '.BAZ_CHAMPS_PRENOM.' '.
683
		           'FROM bazar_fiche,'.BAZ_ANNUAIRE.' where' ;
684
 
685
		$requete .= ' bf_date_debut_validite_fiche<=NOW() AND bf_date_fin_validite_fiche>=NOW() and';
686
 
687
		$requete .= ' bf_ce_utilisateur='.BAZ_CHAMPS_ID.' ';
688
	    if (!isset($_REQUEST['nature'])) {
689
	    	if (isset($GLOBALS['_BAZAR_']['id_typeannonce'])) {
690
	    		$requete .= 'AND bf_ce_nature="'.$GLOBALS['_BAZAR_']['id_typeannonce'].'" ';
691
	    	}
692
	    }
693
	    else {
694
	    	if ($_REQUEST['nature']!='toutes') {
695
	    		$requete .= 'AND bf_ce_nature='.$_REQUEST['nature'].' ';
696
	    	}
697
	    }
698
 
699
	    $requete .= 'ORDER BY '.BAZ_CHAMPS_NOM.' ASC';
700
		$resultat = $GLOBALS['_BAZAR_']['db']->query($requete) ;
701
		if (DB::isError($resultat)) {
702
			die ($resultat->getMessage().$resultat->getDebugInfo()) ;
703
		}
704
		$personnes_select['tous']=BAZ_TOUS_LES_EMETTEURS;
705
		while ($ligne = $resultat->fetchRow(DB_FETCHMODE_ASSOC)) {
706
			$personnes_select[$ligne[BAZ_CHAMPS_ID]] = $ligne[BAZ_CHAMPS_NOM]." ".$ligne[BAZ_CHAMPS_PRENOM] ;
707
		}
708
		$option=array('style'=>'border:1px solid #000;width: 140px;font:12px Myriad, Arial, sans-serif;');
709
		$formtemplate->addElement ('select', 'personnes', BAZ_EMETTEUR, $personnes_select, $option) ;
710
	} else {
711
		$formtemplate->addElement ('hidden', 'personnes', 'tous') ;
22 florian 712
	}
93 alexandre_ 713
 
83 alexandre_ 714
		//pour les super-administrateurs, on peut voir les annonces non validées
64 florian 715
	//on verifie si l'utilisateur est administrateur
111 alexandre_ 716
	$utilisateur = new Administrateur_bazar($GLOBALS['AUTH']) ;
83 alexandre_ 717
 
93 alexandre_ 718
	if ($utilisateur->isSuperAdmin()) {
64 florian 719
		$option=array('style'=>'border:1px solid #000;width: 60px;font:12px Myriad, Arial, sans-serif;');
720
		$valide_select[0] = BAZ_FICHES_PAS_VALIDEES;
721
		$valide_select[1] = BAZ_FICHES_VALIDEES;
722
		$valide_select[2] = BAZ_LES_DEUX;
723
		$formtemplate->addElement ('select', 'valides', BAZ_VALIDE, $valide_select, $option) ;
98 florian 724
		$defauts=array('valides'=>1);
64 florian 725
		$formtemplate->setDefaults($defauts);
726
	}
727
 
728
	//champs texte pour entrer les mots cles
729
	$option=array('maxlength'=>60,'style'=>'border:1px solid #000;width:100px;font:12px Myriad, Arial, sans-serif;');
22 florian 730
	$formtemplate->addElement('text', 'recherche_mots_cles', BAZ_MOT_CLE, $option) ;
731
	$defauts=array('recherche_mots_cles'=>BAZ_MOT_CLE);
732
	$formtemplate->setDefaults($defauts);
64 florian 733
 
734
	//option cachee pour savoir si le formulaire a ete appele deja
735
	$formtemplate->addElement('hidden', 'recherche_effectuee', 1) ;
125 alexandre_ 736
 
737
	// Ajout des options si un type de fiche a ete choisie
738
	if ((isset($_REQUEST['nature']) && $_REQUEST['nature'] != 'toutes') || isset($GLOBALS['_BAZAR_']['categorie_nature'])) {
739
		if ($GLOBALS['_BAZAR_']['categorie_nature'] != '') {
740
			$champs_requete = 'bn_id_nature' ;
741
			if (!isset($_REQUEST['nature']) || $_REQUEST['nature'] == '') {
742
				$_REQUEST['nature'] = $GLOBALS['_BAZAR_']['categorie_nature'];
743
				$champs_requete = 'bn_ce_id_menu' ;
744
			}
745
		} else {
746
			$champs_requete = 'bn_id_nature' ;
747
		}
748
		// Récupération du template
749
		$requete = 'select bn_template from bazar_nature where '.$champs_requete.'="'.$_REQUEST['nature'].'"';
750
		$resultat = $GLOBALS['_BAZAR_']['db']->getOne($requete) ;
751
		if (DB::isError($resultat)) {
752
			die ($resultat->getMessage().$resultat->getDebugInfo()) ;
753
		}
754
 
755
		$tableau = baz_valeurs_template($resultat) ;
756
 
757
		for ($i=0; $i<count($tableau); $i++) {
758
			if (($tableau[$i]['type'] == 'liste' || $tableau[$i]['type'] == 'checkbox') && $tableau[$i]['recherche'] == 1) {
759
				if ($tableau[$i]['type'] == 'checkbox') {
760
					$formtemplate->addElement ('html', '<br />'.$tableau[$i]['label'].'<br />') ;
761
				}
762
				$tableau[$i]['type']($formtemplate, $tableau[$i]['nom_bdd'], $tableau[$i]['label'], $tableau[$i]['limite1'],
763
		                         $tableau[$i]['limite2'], $tableau[$i]['defaut'], $tableau[$i]['table_source'], $tableau[$i]['obligatoire']) ;
764
			}
765
		 }
766
	}
22 florian 767
	//Bouton de validation du formulaire
107 florian 768
	$option=array('style'=>'border:1px solid #000;width:80px;font:12px Myriad, Arial, sans-serif;');
769
	$bouton[] = &HTML_QuickForm::createElement('submit', 'rechercher', BAZ_RECHERCHER, $option);
22 florian 770
	$formtemplate->addGroup($bouton, null, null, '');
64 florian 771
 
772
	//affichage du formulaire
23 florian 773
	$res.=$formtemplate->toHTML()."\n";
64 florian 774
 
125 alexandre_ 775
 
115 alexandre_ 776
	// Ajout de la table bazar_fiche_liste_valeur dans le from de la requete
777
	$case_coche = false ;
778
	$requeteFrom = '' ;
779
	$requeteWhere = '' ;
780
	$requeteWhereListe = '' ;
781
 
125 alexandre_ 782
 	for ($i = 0; $i < count ($tableau); $i++) {
783
		if ($tableau[$i]['type'] == 'checkbox' || $tableau[$i]['type'] == 'liste') {
784
			$nom_liste = $tableau[$i]['type'].$tableau[$i]['nom_bdd'] ;
785
 
786
			if (is_array($_REQUEST[$nom_liste])) {
787
				foreach ($_REQUEST[$nom_liste] as $cle =>$valeur) {
788
					if ($valeur == 1) {
789
						$case_coche = true ;
790
						$requeteWhereListe .= ' AND bfvl_ce_liste='.$tableau[$i]['nom_bdd'] ; // Numéro de la liste
791
 
792
					}
793
				}
794
			} else {
795
 
796
				if (isset ($_REQUEST[$nom_liste])) {
797
					$requeteWhereListe .= ' AND bfvl_ce_liste='.$tableau[$i]['nom_bdd'].' AND ' ; // Numéro de la liste
798
					$requeteWhereListe .= ' bfvl_valeur='.$_REQUEST[$nom_liste].' AND ';
799
					$case_coche = true;
800
				}
801
			}
802
		}
803
	}
804
	if ($case_coche) {
805
		$requeteFrom = ', bazar_fiche_valeur_liste ' ;
806
		//$requeteWhereListe .= ' AND bfvl_valeur IN ()' ;
807
		$requeteWhere = ' bfvl_ce_fiche=bf_id_fiche'.$requeteWhereListe;
808
	}
809
	if (isset($_REQUEST['nature'])) {
810
		$requeteWhere = 'bf_ce_nature="'.$_REQUEST['nature'].'" AND '.$requeteWhere;
811
	}
812
 
64 florian 813
	//affichage des resultats de la recherche si le formulaire a ete envoye
87 alexandre_ 814
	$requeteSQL='';
64 florian 815
	if (isset($_REQUEST['recherche_effectuee'])) {
816
		//preparation de la requete pour trouver les mots cles
125 alexandre_ 817
		if (($_REQUEST['recherche_mots_cles']!='')and($_REQUEST['recherche_mots_cles']!=BAZ_MOT_CLE)) {
64 florian 818
			//decoupage des mots cles
125 alexandre_ 819
			$recherche = split(' ', $_REQUEST['recherche_mots_cles']) ;
64 florian 820
			$nbmots=count($recherche);
821
			$requeteSQL='';
22 florian 822
			for ($i=0; $i<$nbmots; $i++) {
823
				if ($i>0) $requeteSQL.=' OR ';
824
				$requeteSQL.='bf_titre LIKE "%'.$recherche[$i].'%" OR bf_description LIKE "%'.$recherche[$i].'%" ';
825
			}
826
		}
93 alexandre_ 827
		if (!isset($_REQUEST['nature'])) {
828
			if (!isset ($GLOBALS['_BAZAR_']['id_nature'])) $typedefiches = $tableau_typeannonces;
829
			else $typedefiches = $GLOBALS['_BAZAR_']['id_nature'] ;
830
		} else {
831
			$typedefiches = $_REQUEST['nature'] ;
832
			if ($typedefiches == 'toutes') $typedefiches = $tableau_typeannonces ;
833
		}
97 florian 834
		if ($typeannonce!='toutes') $typedefiches=$typeannonce;
125 alexandre_ 835
		if (isset($_REQUEST['valides'])) {$valides=$_REQUEST['valides'];}
64 florian 836
		else {$valides=1;}
837
		//generation de la liste de flux a afficher
125 alexandre_ 838
		$res .= baz_liste_pagine_HTML($typedefiche, '', $_REQUEST['personne'], $valides, $requeteSQL, $requeteFrom, $requeteWhere);
839
		/*
840
		$res .= RSSversHTML(gen_RSS($typedefiches, '', $_REQUEST['personnes'], $valides, $requeteSQL, $requeteFrom, $requeteWhere),
107 florian 841
							 0, BAZ_TYPE_AFFICHAGE_LISTE, 1) ;
125 alexandre_ 842
		*/
22 florian 843
	}
844
	else {
23 florian 845
		//on affiche toutes les annonces
107 florian 846
		$res .= '<br /><p class="zone_info">'."\n".BAZ_ENTRER_VOS_CRITERES_DE_RECHERCHE.'</p>'."\n";
847
		$GLOBALS['_BAZAR_']['url']->removeQueryString('action');
848
		$GLOBALS['_BAZAR_']['url']->addQueryString('action', BAZ_VOIR_FLUX_RSS);
849
		$GLOBALS['_BAZAR_']['url']->addQueryString('annonce', 'toutes');
850
		$res .= '{{Syndication titre="Les derni&egrave;res fiches enregistrées" url="'.$GLOBALS['_BAZAR_']['url']->getURL().'" nb=10 nouvellefenetre=0 formatdate="'.BAZ_TYPE_AFFICHAGE_LISTE.'"}}';
22 florian 851
	}
5 florian 852
	return $res;
853
}
125 alexandre_ 854
 
855
/**
856
 * Cette fonction renvoie du HTML
857
 */
858
function baz_liste_pagine_HTML($typeannonce, $nbitem, $emetteur, $valide, $requeteSQL = '', $requeteFrom = '', $requeteWhere = '') {
859
	// generation de la requete MySQL personnalisee
860
	$req_where=0;
861
	$requete = 'SELECT DISTINCT bf_id_fiche, bf_titre, bf_date_debut_validite_fiche '.
862
				'FROM bazar_fiche, bazar_nature '.$requeteFrom.' WHERE '.$requeteWhere;
863
	if ($valide!=2) {
864
		$requete .= 'bf_statut_fiche='.$valide;
865
		$req_where=1;
866
	}
867
 
868
	if (!is_array ($typeannonce) && $typeannonce!='' and $typeannonce!='toutes') {
869
		if ($req_where==1) {$requete .= ' AND ';}
870
		$requete .= 'bf_ce_nature='.$typeannonce;
871
		$req_where=1;
872
		//le nom du flux devient le type d'annonce
873
		$nomflux = $typeannonce;
874
	}
875
	// Cas où il y plusieurs type d annonce demande
876
	if (is_array ($typeannonce)) {
877
		if ($req_where==1) {$requete .= ' AND ';}
878
		$requete .= 'bf_ce_nature IN (' ;
879
		$chaine = '';
880
		foreach ($typeannonce as $valeur) $chaine .= '"'.$valeur.'",' ;
881
		$requete .= substr ($chaine, 0, strlen ($chaine)-1) ;
882
		$requete .= ') ';
883
	}
884
	$utilisateur = new Administrateur_bazar ($GLOBALS['AUTH']) ;
885
	if ($valide!=0) {
886
 
887
		if ($utilisateur->isSuperAdmin()) {
888
			$req_where=1;
889
		} else {
890
			if ($req_where==1) {
891
				$requete .= ' AND ';
892
			}
893
			$requete .= '(bf_date_debut_validite_fiche<=NOW() or bf_date_debut_validite_fiche="0000-00-00")'.
894
						' AND (bf_date_fin_validite_fiche>=NOW() or bf_date_fin_validite_fiche="0000-00-00") AND bn_id_nature=bf_ce_nature';
895
		}
896
	}
897
	else $nomflux .= BAZ_A_MODERER;
898
	if ($emetteur!='' && $emetteur!='tous') {
899
		if ($req_where==1) {$requete .= ' AND ';}
900
		$requete .= 'bf_ce_utilisateur='.$emetteur;
901
		$req_where=1;
902
		//requete pour afficher le nom de la structure
903
		$requetenom = 'SELECT '.BAZ_CHAMPS_NOM.', '.BAZ_CHAMPS_PRENOM.' FROM '.
904
						BAZ_ANNUAIRE.' WHERE '.BAZ_CHAMPS_ID.'='.$emetteur;
905
		$resultat = $GLOBALS['_BAZAR_']['db']->query($requetenom) ;
906
		if (DB::isError($resultat)) {
907
			die ($resultat->getMessage().$resultat->getDebugInfo()) ;
908
		}
909
		$ligne = $resultat->fetchRow(DB_FETCHMODE_ASSOC);
910
		$nomflux .= ' ('.$ligne[BAZ_CHAMPS_NOM].' '.$ligne[BAZ_CHAMPS_PRENOM].')';
911
	}
912
	if ($requeteSQL!='') {
913
		if ($req_where==1) {$requete .= ' AND ';}
914
		$requete .= '('.$requeteSQL.')';
915
		$req_where=1;
916
	}
917
	$requete .= ' ORDER BY  bf_date_debut_validite_fiche DESC, bf_date_fin_validite_fiche DESC, bf_date_maj_fiche DESC';
918
	if ($nbitem!='') {$requete .= ' LIMIT 0,'.$nbitem;}
919
	$resultat = $GLOBALS['_BAZAR_']['db']->query($requete) ;
920
	if (DB::isError($resultat)) {
921
		die ($resultat->getMessage().$resultat->getDebugInfo()) ;
922
	}
923
	$res = '<br /><h4>'.BAZ_IL_Y_A.($resultat->numRows()).' '.BAZ_FICHES_CORRESPONDANTES.'</h4><br />'."\n";
924
	$res .= '<ul>' ;
925
	$GLOBALS['_BAZAR_']['url']->addQueryString('action', BAZ_VOIR_FICHE);
926
 
927
	$donnees = array();
928
	while ($ligne = $resultat->fetchRow(DB_FETCHMODE_OBJECT)) {
929
		$GLOBALS['_BAZAR_']['url']->addQueryString('id_fiche', $ligne->bf_id_fiche) ;
930
		array_push ($donnees, array ($ligne->bf_id_fiche,$ligne->bf_titre));
931
		//$res .= '<li><a href="'.$GLOBALS['_BAZAR_']['url']->getURL().'">'.$ligne->bf_titre.'</a></li>'."\n" ;
932
	}
933
	// Mise en place du Pager
934
	include_once 'Pager/Pager.php';
935
	$params = array(
936
    'mode'       => BAZ_MODE_DIVISION,
937
    'perPage'    => BAZ_NOMBRE_RES_PAR_PAGE,
938
    'delta'      => BAZ_DELTA,
939
    'httpMethod' => 'GET',
940
    'extraVars' => $_REQUEST,
941
    'altNext' => BAZ_SUIVANT,
942
    'altPrev' => BAZ_PRECEDENT,
943
    'nextImg' => BAZ_SUIVANT,
944
    'prevImg' => BAZ_PRECEDENT,
945
    'itemData'   => $donnees
946
	);
947
	$pager = & Pager::factory($params);
948
	$data  = $pager->getPageData();
949
	$links = $pager->getLinks();
950
 
951
	foreach ($data as $valeur) {
952
		$GLOBALS['_BAZAR_']['url']->addQueryString('id_fiche', $valeur[0]) ;
953
		$res .= '<li><a href="'.$GLOBALS['_BAZAR_']['url']->getURL().'">'.$valeur[1].'</a></li>'."\n" ;
954
	}
955
	$res .= '</ul>';
956
	$res .= $pager->links;
957
 
958
	return $res ;
959
}
960
 
961
/* +--Fin du code ----------------------------------------------------------------------------------------+
962
*
963
* $Log: not supported by cvs2svn $
964
* +-- Fin du code ----------------------------------------------------------------------------------------+
965
*/
23 florian 966
?>