Subversion Repositories Applications.bazar

Rev

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