Subversion Repositories Applications.bazar

Rev

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