Subversion Repositories Applications.bazar

Rev

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

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