Subversion Repositories Applications.bazar

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
5 florian 1
<?php
2
/** baz_valeur_template() - Renvoi des valeurs inscrite dans le fichier de template
3
*
4
* @param   string nom du fichier de template
5
*
6
* @return   mixed  tableau contenant les champs du fichier template
7
*/
8
function baz_valeurs_template($fichier_template) {
9
	//Parcours du fichier de templates, pour mettre les champs spécifiques
10
	$nblignes=0;
11
	$fichier=file_get_contents(BAZ_CHEMIN_APPLI.'templates/'.$fichier_template);
12
	$chaine = explode ("\n", $fichier);
13
	array_pop($chaine);
14
	foreach ($chaine as $ligne)  {
15
		$souschaine = explode ("***", $ligne) ;
16
		$tableau[$nblignes]['type'] = trim($souschaine[0]) ;
17
		if (isset($souschaine[1])) {$tableau[$nblignes]['nom_bdd'] = trim($souschaine[1]);}
18
		else {$tableau[$nblignes]['nom_bdd'] ='';}
19
		if (isset($souschaine[2])) $tableau[$nblignes]['label'] = trim($souschaine[2]);
20
		else {$tableau[$nblignes]['label'] ='';}
21
		if (isset($souschaine[3])) $tableau[$nblignes]['limite1'] = trim($souschaine[3]);
22
		else {$tableau[$nblignes]['limite1'] ='';}
23
		if (isset($souschaine[4])) $tableau[$nblignes]['limite2'] = trim($souschaine[4]);
24
		else {$tableau[$nblignes]['limite2'] ='';}
25
		if (isset($souschaine[5])) $tableau[$nblignes]['defaut'] = trim($souschaine[5]);
26
		else {$tableau[$nblignes]['defaut'] ='';}
27
		if (isset($souschaine[6])) $tableau[$nblignes]['table_source'] = trim($souschaine[6]);
28
		else {$tableau[$nblignes]['table_source'] ='';}
29
		if (isset($souschaine[7])) $tableau[$nblignes]['id_source'] = trim($souschaine[7]);
30
		else {$tableau[$nblignes]['id_source'] ='';}
31
		if (isset($souschaine[8])) $tableau[$nblignes]['obligatoire'] = trim($souschaine[8]);
32
		else {$tableau[$nblignes]['obligatoire'] ='';}
33
		$nblignes++;
34
	}
35
	return $tableau;
36
}
37
 
38
 
39
/**  baz_voir_fiche() - Permet de visualiser en détail une fiche  au format XHTML
40
*
41
* @global boolean Rajoute des informations internes à l'application (date de modification, lien vers la page de départ de l'appli) si à 1
42
* @global integer Identifiant de la fiche à afficher
43
*
44
* @return   string  HTML
45
*/
46
function baz_voir_fiche($danslappli, $idfiche='') {
47
	$res = '';
48
	if (isset($_GET['id_fiche'])) $GLOBALS['_BAZAR_']['id_fiche']=$_GET['id_fiche'];
49
	if ($idfiche!='') $GLOBALS['_BAZAR_']['id_fiche']=$idfiche;
50
 
51
	//on cherche le type d'annonce
52
	$requete = 'SELECT bn_label_nature FROM bazar_fiche, bazar_nature WHERE bn_id_nature=bf_ce_nature AND bf_id_fiche='.$GLOBALS['_BAZAR_']['id_fiche'];
53
	$resultat = $GLOBALS['_BAZAR_']['db']->query($requete) ;
54
	if (DB::isError($resultat)) {
55
		die ($resultat->getMessage().$resultat->getDebugInfo()) ;
56
	}
57
	while ($ligne = $resultat->fetchRow(DB_FETCHMODE_ASSOC)) {
58
		$GLOBALS['_BAZAR_']['typeannonce']=$ligne['bn_label_nature'];
59
	}
60
	$res = '<div id="BAZ_cadre_fiche">'."\n";
61
	$res .= '<div id="BAZ_cadre_fiche_haut">'."\n";
62
	$res .= '&nbsp;</div>'."\n";
63
	$res .= '<div id="BAZ_cadre_fiche_corps">'."\n";
64
 
65
	//si le template existe, on génère le template
66
	if ((file_exists(BAZ_CHEMIN_APPLI.'templates/'.$GLOBALS['_BAZAR_']['typeannonce'].'-fiche.php'))) {
67
		include_once(BAZ_CHEMIN_APPLI.'templates/'.$GLOBALS['_BAZAR_']['typeannonce'].'-fiche.php');
68
		$res .=genere_fiche($GLOBALS['_BAZAR_']['id_fiche'],$danslappli);
69
	}
70
	//on affiche ligne par ligne sinon
71
	else {
72
		$requete = 'SELECT * FROM bazar_fiche WHERE bf_id_fiche='.$GLOBALS['_BAZAR_']['id_fiche'];
73
		$resultat = $GLOBALS['_BAZAR_']['db']->query($requete) ;
74
		if (DB::isError ($resultat)) {
75
			die ($resultat->getMessage().'<br />'.$resultat->getDebugInfo()) ;
76
		}
77
		$ligne = $resultat->fetchRow(DB_FETCHMODE_ASSOC) ;
78
 
79
		if (isset($ligne['bf_url_image'])) $res .= '<img src="'.'http://'.$_SERVER['HTTP_HOST'].'/client/bazar/images/'.$ligne['bf_url_image'].'" border=0 alt="'.BAZ_TEXTE_IMG_ALTERNATIF.'" align="left" style="padding:0 10px 5px 0;" />'."\n";
80
		$res .= '<h2>'.$ligne['bf_titre'].'</h2>'."\n" ;
81
		if (isset($ligne['bf_description'])) $res .= '<br />'.$ligne['bf_description'].'<br /><br />'."\n";
82
 
83
		$tableau=baz_valeurs_template($GLOBALS['_BAZAR_']['typeannonce'].'.tpl');
84
		for ($i=0; $i<count($tableau); $i++) {
85
			if (isset($ligne[$tableau[$i]['nom_bdd']])) {
86
				//pour les champs renseignés par une liste, on va chercher le label de la liste, plutot que l'id
87
				if ($tableau[$i]['type']=='liste') {
88
					$requete = 'SELECT '.$tableau[$i]['table_source'].'.* FROM bazar_fiche, '.$tableau[$i]['table_source'].
89
					' WHERE '.$tableau[$i]['nom_bdd'].'='.$tableau[$i]['id_source'].' AND bf_id_fiche='.$GLOBALS['_BAZAR_']['id_fiche'];
90
					$resultat = $GLOBALS['_BAZAR_']['db']->query($requete) ;
91
					if (DB::isError ($resultat)) {
92
						die ($resultat->getMessage().'<br />'.$resultat->getDebugInfo()) ;
93
					}
94
					while ($tab = $resultat->fetchRow()) {
95
						$val=encoderChaine($tab[1]);
96
					}
97
				}
98
				else {
99
					$val=encoderChaine($ligne[$tableau[$i]['nom_bdd']]);
100
				}
101
				if (($tableau[$i]['nom_bdd']!='bf_titre')and($tableau[$i]['nom_bdd']!='bf_description')) {
102
					if ($val!='') $res .= '<br /><strong>'.constant($tableau[$i]['label']).':</strong> '.$val.'<br />'."\n";
103
				}
104
			}
105
		}
106
 
107
		//afficher les liens pour l'annonce
108
		$requete = 'SELECT  bu_url, bu_descriptif_url FROM bazar_url WHERE bu_ce_fiche='.$GLOBALS['_BAZAR_']['id_fiche'];
109
		$resultat = $GLOBALS['_BAZAR_']['db']->query($requete) ;
110
		if (DB::isError($resultat)) {
111
			die ($resultat->getMessage().$resultat->getDebugInfo()) ;
112
		}
113
		if ($resultat->numRows()>0) {
114
			$res .= '<br /><strong>'.BAZ_LIEN_INTERNET.':</strong>'."\n";
115
			$res .= '<ul>'."\n";
116
			while ($ligne = $resultat->fetchRow(DB_FETCHMODE_ASSOC)) {
117
				$res .= '<li><a href="'.$ligne['bu_url'].'" target="_blank">'.$ligne['bu_descriptif_url'].'</a></li>'."\n";
118
			}
119
			$res .= '</ul>'."\n";
120
		}
121
 
122
		//afficher les fichiers pour l'annonce
123
		$requete = 'SELECT  bfj_description, bfj_fichier FROM bazar_fichier_joint WHERE bfj_ce_fiche='.$GLOBALS['_BAZAR_']['id_fiche'];
124
		$resultat = $GLOBALS['_BAZAR_']['db']->query($requete) ;
125
		if (DB::isError($resultat)) {
126
			die ($resultat->getMessage().$resultat->getDebugInfo()) ;
127
		}
128
		if ($resultat->numRows()>0) {
129
			$res .= '<br /><strong>'.BAZ_LISTE_FICHIERS_JOINTS.':</strong>'."\n";
130
			$res .= '<ul>'."\n";
131
			while ($ligne = $resultat->fetchRow(DB_FETCHMODE_ASSOC)) {
132
				$res .= '<li><a href="http://'.$_SERVER['HTTP_HOST'].'/client/bazar/upload/'.$ligne['bfj_fichier'].'">'.$ligne['bfj_description'].'</a></li>'."\n";
133
			}
134
			$res .= '</ul>'."\n";
135
		}
136
 
137
		//informations complémentaires (id fiche, état publication,... )
138
		if ($danslappli==1) {
139
			$res .= '<br /><br /><strong>'.BAZ_NUM_FICHE.':</strong> '.$GLOBALS['_BAZAR_']['id_fiche'];
140
			$res .= '<br /><strong>'.BAZ_NATURE.':</strong> '.$GLOBALS['_BAZAR_']['typeannonce'];
141
			if ($ligne['bf_statut_fiche']==1) {
142
				$res .= '<br /><strong>'.BAZ_PUBLIEE.':</strong> '.BAZ_OUI;
143
			}
144
			else {
145
				$res .= '<br /><strong>'.BAZ_PUBLIEE.':</strong> '.BAZ_NON;
146
			}
147
			$res .= '<br /><strong>'.BAZ_DATE_CREATION.':</strong> '.$ligne['bf_date_creation_fiche'];
148
			$res .= '<br /><strong>'.BAZ_DATE_MAJ.':</strong> '.$ligne['bf_date_maj_fiche'];
149
			$res .='<ul><li><a href="Javascript:history.go(-1)">'.BAZ_RETOUR.'</a></li></ul>'."\n";
150
		}
151
	}
152
	$res .= '</div>'."\n";
153
	$res .= '<div id="BAZ_cadre_fiche_bas">'."\n";
154
	$res .= '&nbsp;</div>'."\n";
155
	$res .= '</div>'."\n";
156
	return $res ;
157
}
158
 
159
 
160
/** RSSversHTML () transforme un flux RSS (en XML) en page HTML
161
*
162
*   On passe en paramètre le contenu du flux RSS, on affiche ou non la description,
163
*   et on choisit de format de la date à l'affichage. On a en sortie du code HTML à afficher
164
*
165
*   @param  string   le contenu du flux RSS
166
*   @param  boolean  afficher ou non la description
167
*   @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
168
*
169
*   @return  string    le code HTML
170
*/
171
 
172
function RSSversHTML($rss, $voirdesc, $formatdate) {
173
	if ($rss!='') {
174
		$res='';
175
		if( eregi('<item>(.*)</item>', $rss, $rawitems ) ) {
176
			$items = explode('<item>', $rawitems[0]);
177
			$res.='<ul>'."\n";
178
			for( $i = 0; $i < count($items)-1; $i++ ) {
179
				eregi('<title>(.*)</title>',$items[$i+1], $title );
180
				eregi('<link>(.*)</link>',$items[$i+1], $url );
181
				eregi('<description>(.*)</description>',$items[$i+1], $cat);
182
				eregi('<pubDate>(.*)</pubDate>',$items[$i+1], $date);
183
				$res.='<li>';
184
				if ($formatdate=='jm') {$res.=strftime('%d.%m',strtotime($date[1])).': ';}
185
				if ($formatdate=='jma') {$res.=strftime('%d.%m.%Y',strtotime($date[1])).': ';}
186
				if ($formatdate=='jmh') {$res.=strftime('%d.%m %H:%M',strtotime($date[1])).': ';}
187
				if ($formatdate=='jmah') {$res.=strftime('%d.%m.%Y %H:%M',strtotime($date[1])).': ';}
188
				$res.='<a href="'.preg_replace ('/&amp;/', '&', $url[1]).'">'.$title[1].'</a><br />';
189
				if ($voirdesc) {$res.=$cat[1];}
190
				$res.='</li>'."\n";
191
			}
192
			$res.='</ul>'."\n";
193
		}
194
	}
195
	else $res = BAZ_PAS_D_ANNONCES;
196
	return $res;
197
}
198
 
199
/** gen_RSS() - générer un fichier de flux RSS par type d'annonce
200
*
201
* @param   string Le type de l'annonce (laisser vide pour tout type d'annonce)
202
* @param   integer Le nombre d'annonces a regrouper dans le fichier XML (laisser vide pour toutes)
203
* @param   integer L'identifiant de l'emetteur (laisser vide pour tous)
204
* @param   integer L'état de validation de l'annonce (laisser 1 pour les annonces validées, 0 pour les non-validées)
205
* @param   string La requète SQL personnalisée
206
*
207
* @return  string Le code du flux RSS
208
*/
209
function gen_RSS($typeannonce='', $nbitem='', $emetteur='', $valide=1, $requeteSQL='') {
210
	// génération de la requete MySQL personnalisée
211
	$requete = 'SELECT DISTINCT bf_id_fiche, bf_titre, bf_date_debut_validite_fiche, bn_label_nature FROM bazar_fiche, bazar_nature';
212
	$requete .= ' WHERE bf_statut_fiche='.$valide;
213
	$nomflux=BAZ_DERNIERE_ACTU;
214
	if (($typeannonce!='')and($typeannonce!='toutes')) {
215
		$requete .= ' AND bn_label_nature="'.$typeannonce.'"';
216
		//le nom du flux devient le type d'annonce
217
		$nomflux = $typeannonce;
218
	}
219
	if ($valide!=0) $requete .= ' AND bf_date_debut_validite_fiche<=NOW() AND bf_date_fin_validite_fiche>=NOW() AND bn_id_nature=bf_ce_nature';
220
	else $nomflux .= BAZ_A_MODERER;
221
	if (($emetteur!='')and($emetteur!='tous')) {
222
		$requete .= ' AND bf_ce_utilisateur='.$emetteur;
223
		//requete pour afficher le nom de la structure
224
		$requetenom = 'SELECT '.BAZ_CHAMPS_NOM.', '.BAZ_CHAMPS_PRENOM.' FROM '.BAZ_ANNUAIRE.' WHERE '.BAZ_CHAMPS_ID.'='.$emetteur;
225
		$resultat = $GLOBALS['_BAZAR_']['db']->query($requetenom) ;
226
		if (DB::isError($resultat)) {
227
			die ($resultat->getMessage().$resultat->getDebugInfo()) ;
228
		}
229
		$ligne = $resultat->fetchRow(DB_FETCHMODE_ASSOC);
230
		$nomflux .= ' ('.$ligne[BAZ_CHAMPS_NOM].' '.$ligne[BAZ_CHAMPS_PRENOM].')';
231
	}
232
	if ($requeteSQL!='') $requete .= ' AND ('.$requeteSQL.')';
233
	$requete .= ' ORDER BY  bf_date_debut_validite_fiche, bf_date_fin_validite_fiche, bf_date_maj_fiche DESC';
234
	if ($nbitem!='') {$requete .= ' LIMIT 0,'.$nbitem;}
235
	$resultat = $GLOBALS['_BAZAR_']['db']->query($requete) ;
236
	if (DB::isError($resultat)) {
237
		die ($GLOBALS['_BAZAR_']['db']->getMessage().$GLOBALS["db"]->getDebugInfo()) ;
238
	}
239
	// En-tête du flux RSS version 2.0
240
	$xml = '<?xml version="1.0" encoding="ISO-8859-1"?>'."\n".'<rss version="2.0">'."\n";
241
	$xml .= '<channel>'."\n".'<title>'.$nomflux.'</title>'."\n".'<link>'.BAZ_RSS_ADRESSESITE.'</link>'."\n";
242
	$xml .= '<description>'.BAZ_RSS_DESCRIPTIONSITE.'</description>'."\n".'<language>fr-FR</language>'."\n".
243
	'<copyright>Copyright 2005 '.BAZ_RSS_NOMSITE.'</copyright>'."\n";
244
	// Ajout de la date actuelle de publication (suivant la DTD RSS)
245
	$xml .= '<lastBuildDate>'.strftime('%d %b %Y %H:%M:%S GMT').'</lastBuildDate>'."\n";
246
	// En-tête suite et fin
247
	$xml .= '<docs>http://www.stervinou.com/projets/rss/</docs>'."\n".'<category>'.BAZ_RSS_CATEGORIE.'</category>'."\n".
248
	'<managingEditor>'.BAZ_RSS_MANAGINGEDITOR.'</managingEditor>'."\n".'<webMaster>'.BAZ_RSS_WEBMASTER.'</webMaster>'."\n";
249
	$xml .= '<ttl>60</ttl>'."\n".'<image>'."\n".'<title>'.BAZ_RSS_NOMSITE.'</title>'."\n".'<url>'.BAZ_RSS_LOGOSITE.'</url>'."\n".
250
	'<link>'.BAZ_RSS_ADRESSESITE.'</link>'."\n".'</image>'."\n";
251
	if ($resultat->numRows()>0) {
252
		// Creation des items : titre + lien + description + date de publication
253
		while ($ligne = $resultat->fetchRow(DB_FETCHMODE_ASSOC)) {
254
			$xml .= '<item>'."\n";
255
			$xml .= '<title>'.$ligne['bf_titre'].'</title>'."\n";
256
			$lien=$GLOBALS['_BAZAR_']['url'];
257
			$lien->addQueryString('action', BAZ_VOIR_FICHE);
258
			$lien->addQueryString('id_fiche', $ligne['bf_id_fiche']);
259
			$xml .= '<link>'.str_replace ('&', '&amp;', $lien->getURL()).'</link>'."\n";
260
			$xml .= '<description>'."\n".'<![CDATA['.baz_voir_fiche(0,$ligne['bf_id_fiche']).']]>'."\n".'</description>'."\n";
261
			$xml .= '<pubDate>'.strftime('%d %b %Y %H:%M:%S GMT',strtotime($ligne['bf_date_debut_validite_fiche'])).'</pubDate>'."\n";
262
			$xml .= '</item>'."\n";
263
		}
264
	}
265
	else {//pas d'annonces
266
		$xml .= '<item>'."\n";
267
		$xml .= '<title>&nbsp;</title>'."\n";
268
		$xml .= '<link>http://test.educ-envir.org</link>'."\n";
269
		$xml .= '<description>&nbsp;</description>'."\n";
270
		$xml .= '<pubDate>'.strftime('%d %b %Y %H:%M:%S GMT',strtotime('12/12/2004')).'</pubDate>'."\n";
271
		$xml .= '</item>'."\n";
272
	}
273
	$xml .= '</channel>'."\n".'</rss>'."\n";
274
	return $xml;
275
}
276
 
277
 
278
/** baz_liste() Formate la liste de toutes les annonces actuelles
279
*
280
*   @return  string    le code HTML à afficher
281
*/
282
function baz_liste($typeannonce='toutes') {
283
	if ($typeannonce=='toutes') $res= '<h2>'.BAZ_TOUTES_LES_ANNONCES.'</h2>'."\n";
284
	else $res= '<h2>'.BAZ_TOUTES_LES_ANNONCES_DE_TYPE.$typeannonce.'</h2>'."\n";
285
	$res.=RSSversHTML(gen_RSS($typeannonce, '', '', 1, ''), 0, 'jm') ;
286
	return $res;
287
}
288
 
289
?>