Subversion Repositories Sites.gentiana.org

Rev

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

Rev Author Line No. Line
43 jpm 1
<?php
2
 
3
// +--------------------------------------------------------------------------------+
4
// | annuaire_moteur_fonction.php 		                      						|
5
// +--------------------------------------------------------------------------------+
6
// | Copyright (c) 2000 - 2003 Tela Botanica 							        	|
7
// +--------------------------------------------------------------------------------+
8
// | Les fonctions de annuaire_moteur.php                                           |
9
// +--------------------------------------------------------------------------------+
10
// | Auteur : Alexandre Granier <alexandre@tela-botanica.org> 		  		        |
11
// +--------------------------------------------------------------------------------+
12
//
13
// $Id: annuaire_moteur_fonction.php,v 1.1 2005/03/24 08:47:31 alex Exp $
14
 
15
 
16
include_once 'api/pear/HTML/QuickForm/select.php';
17
 
18
/** function mkengine ()
19
*
20
*
21
*
22
*	@return
23
*/
24
 
25
function mkengine()
26
  {
27
    global $label_bbota;
28
    global $nbr_total;
29
    global $bouton, $HTTP_POST_VARS ;
30
 
31
 
32
    $mes_vars = array ("recherche", "nom", "ville", "mail" ,"dept", "prenom", "cotisant", "pays", "sort", "T_REPONSE", "lettre","statut") ;
33
 
34
    // Deux cas , soit on a cliqué sur rechercher, soit on a cliqué sur un lien
35
    foreach ($mes_vars as $key=>$value) {
36
        if (!$bouton) {     // on a cliqué sur un lien
37
            if (empty($HTTP_POST_VARS[$value])) {
38
 
39
            }
40
        } else {
41
            // Si on clique sur le bouton rechercher
42
            if (empty ($HTTP_POST_VARS[$value])) {
43
                $$value = "" ;
44
            } else {
45
                $$value = $HTTP_POST_VARS[$value] ;
46
            }
47
        }
48
    }
49
 
50
    // Comptage du nombre total de données dans la table (hors CACHER = 1)
51
    $query = "select count(*) as CPT from ".ANN_ANNUAIRE;
52
    $result = $GLOBALS['ann_db']->query($query) ;
53
	if (DB::isError($result)) {
54
		return $result->getMessage().'<br />'.$result->getDebugInfo();
55
	}
56
 
57
	if ($result->numRows() == 1) {
58
	    $tmp_nb = $result->fetchRow(DB_FETCHMODE_OBJECT);
59
	    $nbr_total = $tmp_nb->CPT;
60
	    if ($nbr_total > 0) $chaine = "parmi $nbr_total données";
61
	    else die("<B>Erreur</B> lors du comptage des structures ($nbr_total trouvées) : $query");
62
    } else die("<B>Erreur</B> lors du comptage des structures : $query");
63
 
64
	$result->free();
65
  // fin comptage
66
 
67
	$ret = '<h1>'.AM_L_TITRE.'</h1>'."\n";
68
	$ret .= '<h2>'.AM_L_TITRE.' '.$chaine.'</h2>'."\n";
69
  // construction du moteur de str
70
 	$formulaire = new HTML_QuickForm('formulaire_recherche', 'post', str_replace('&amp;', '&', $GLOBALS['ann_url']->getURL()));
71
 
72
 	$squelette =& $formulaire->defaultRenderer();
73
    $squelette->setFormTemplate("\n".'<div id="annuaire_zone_recherche"><table id="annuaire_recherche"><form{attributes}>'."\n".'{content}'."\n".'</form></table></div>'."\n");
74
    $squelette->setElementTemplate(  '<tr>'."\n".
75
                                    '<td class="champ">{label}</td>'."\n".
76
                                    '<td class="valeur">{element}'.
77
                                    '<!-- BEGIN required --><span class="symbole_obligatoire">'.ADME_LG_FORM_SYMBOLE_CHP_OBLIGATOIRE.'</span><!-- END required -->'.
78
                                    '<!-- BEGIN error --><span class="erreur">{error}</span><!-- END error -->'.
79
                                    '</td>'."\n".
80
                                    '</tr>'."\n");
81
 
82
 	$formulaire->addElement('text', 'recherche', AM_L_RECHERCHER);
83
 
84
 	$requete = 'select GC_ID, GC_NAME from gen_COUNTRY where GC_LOCALE="fr"';
85
    $pays = &$GLOBALS['ann_db']->getAssoc ($requete);
86
 
87
    $pays = array_merge (array('tous' => 'Tous les pays'), $pays);
88
 
89
    if (DB::isError($pays)) {
90
		return $pays->getMessage().'<br />'.$pays->getDebugInfo();
91
	}
92
 
93
	$select = new HTML_QuickForm_select ('pays', AM_L_PAYS, $pays, array ('class' => 'projet_asso')) ;
94
	$formulaire->addElement($select) ;
95
	$formulaire->addElement('text', 'nom', AM_L_NOM);
96
	$formulaire->addElement('text', 'prenom', AM_L_PRENOM);
97
	$formulaire->addElement('text', 'ville', AM_L_VILLE);
98
 
99
	$departement = & $GLOBALS['ann_db']->getAssoc('select GFD_ID, CONCAT(GFD_ID,\' - \',GFD_NAME) as GFD_NAME from gen_FRENCH_DPT');
100
	$departement = array_merge (array ('tous' => 'Tous'), $departement);
101
 
102
	$select_dpt = new HTML_QuickForm_select ('departement', AM_L_DEPARTEMENT, $departement, array ('class' => 'projet_asso')) ;
103
	$formulaire->addElement($select_dpt);
104
 
105
	$formulaire->addElement('text', 'mail', AM_L_MAIL);
106
 
107
	$cotisant = array (1 => 'Tous', 2 => 'Cotisants', 3 => 'Non cotisants');
108
 
109
	$select_cotisant = new HTML_QuickForm_select ('cotisant', AM_L_COTISANTS, $cotisant, array ('class' => 'projet_asso')) ;
110
	$formulaire->addElement($select_cotisant);
111
 
112
	$requete = 'select distinct(YEAR(IC_DATE)) as annees from annuaire_COTISATION';
113
    $resultat_annee_cotisation = &$GLOBALS['ann_db']->query ($requete);
114
 
115
    if (DB::isError($resultat_annee_cotisation)) {
116
		return $resultat_annee_cotisation->getMessage().'<br />'.$resultat_annee_cotisation->getDebugInfo();
117
	}
118
	$tableau_annee_cotisation['Toutes'] = 'Toutes';
119
	while ($ligne_annee_cotisation = $resultat_annee_cotisation->fetchRow(DB_FETCHMODE_OBJECT)) {
120
    	$tableau_annee_cotisation[$ligne_annee_cotisation->annees] = $ligne_annee_cotisation->annees;
121
    }
122
 
123
	$select_annee = new HTML_QuickForm_select ('annee_cotisation', 'Année', $tableau_annee_cotisation, array ('class' => 'projet_asso')) ;
124
	$formulaire->addElement($select_annee);
125
 
126
	$grp = array(20 => 20, 50 => 50, 100 => 100) ;
127
	$select_grp = new HTML_QuickForm_select ('T_REPONSE', 'Résultat par', $grp, array ('class' => 'projet_asso')) ;
128
	$formulaire->addElement($select_grp);
129
	$formulaire->addElement('submit', 'bouton', AM_L_RECHERCHER);
130
	foreach ($mes_vars as $key=>$value) {
131
		if (isset($_POST[$value])) {
132
			$default[$value] = $_POST[$value] ;
133
		}
134
	}
135
	$formulaire->setDefaults($_POST);
136
 
137
    $ret .= '<br />'.$formulaire->toHTML();
138
    return $ret;
139
}
140
 
141
function mkquery()
142
{
143
    // définition des variables globales
144
	global $lettre ;
145
	global $bouton ;
146
 
147
	// Requete sur l'annuaire pour extraire le nom, prénom, ville, nom du département (jointure),
148
	// l'état de la cotisation (jointure)
149
 
150
	// le tableau suivant contient tous les champs de la table annuaire_tela sur lesquels on peut effectuer une recherche
151
	$fields_annu = array("nom" => ANN_CHAMPS_NOM, "prenom" => ANN_CHAMPS_PRENOM , "mail" => ANN_CHAMPS_MAIL , "ville" => ANN_CHAMPS_VILLE,
152
			"dept" => "U_FRENCH_DPT", "pays" => ANN_CHAMPS_PAYS  ) ;
153
 
154
    $mes_vars = array ("recherche", "nom", "ville", "mail" ,"dept",
155
						"prenom", "cotisant", "pays", "sort", "T_REPONSE",
156
						"lettre","statut", "annee_cotisation") ;
157
 
158
    foreach ($mes_vars as $key=>$value) {
159
        if (!$bouton) {
160
 
161
        } else {
162
            $lettre = "" ;
163
            if (empty ($_REQUEST[$value])) {
164
                $$value = "" ;
165
            } else {
166
                $$value = $_REQUEST[$value] ;
167
            }
168
        }
169
    }
170
    $queries = 'select '.ANN_CHAMPS_ID.','.ANN_CHAMPS_NOM.', '.ANN_CHAMPS_PRENOM.', '.
171
    				ANN_CHAMPS_PAYS.','.ANN_CHAMPS_MAIL.', '.ANN_CHAMPS_VILLE ;
172
    $queries .= ", ".ANN_TABLE_PAYS.".GC_NAME ";
173
	$queries .= "from ";
174
	$queries .= ANN_TABLE_PAYS.','.ANN_ANNUAIRE ;
175
	// On effectue une jointure gauche si l on veut tous les inscrits
176
	// y compris ce qui ne cotisent pas sinon pas de jointure gauche
177
	/*
178
	if (isset($cotisant) && $cotisant != 1) {
179
 
180
	} else {
181
		$queries .= ' left ' ;
182
	}
183
	$queries .= ' join annuaire_COTISATION on '.
184
    				ANN_ANNUAIRE.'.U_ID=annuaire_COTISATION.IC_ANNU_ID ';
185
 
186
    if (isset($annee_cotisation) && $annee_cotisation != 0) {
187
        	$queries .= ' and year(IC_DATE)='.$annee_cotisation ;
188
    } else {
189
    		$queries .= 'and year(IC_DATE)='.date('Y') ;
190
    }
191
 */
192
	// Construction en fonction des champs saisies
193
 
194
	// juste le champs "rechercher", on regarde partout
195
	$queries .= " where " ;
196
 
197
	if ($lettre == "") {
198
        if ($_REQUEST['recherche'] != '') {
199
            $queries .= '('.ANN_CHAMPS_NOM.' like "%'.$_REQUEST['recherche'].'%"' ; // le premier
200
                foreach($fields_annu as $key=>$value) {
201
					if ($key == "nom") continue ;
202
							$queries .= ($key == "pays" ?
203
                                    $pays == "tous" ? ")" :
204
                                    ") and $value = '$pays'" : " or $value like '%$recherche%'") ;	// les autres
205
                }
206
				$queries .= ' and ' ;
207
			} else {
208
 
209
			// si un ou plusieurs autres champs ont été indiqué, on les rajoute ici
210
 
211
			$or_flag = false ;
212
			foreach($fields_annu as $key=>$valeur) {
213
                if ($key != "") {
214
                    if ($key == "pays" && ($$key != 'tous' && $$key != '')) {
215
                        if ($$key != "tous") $queries .= ") and $valeur like \"%".$$key."%\"" ;
216
                    } else {
217
                        if ($key == "dept") {
218
                            if ($$key != "tous" && isset($HTTP_POST_VARS[$key])) {
219
                                $queries .= " and U_FRENCH_DPT=".$$key ;
220
                                if ($fields_annu["pays"] != "fr") $queries .= ' and '.ANN_CHAMPS_PAYS.'="fr"' ;
221
                            }
222
 
223
                        } else {
224
                            if ($$key != '' && $key != 'pays') {
225
                            	if (!$or_flag) $queries .= '(' ;
226
                            	$queries .= $valeur.' like "%'.$$key.'%"' ;
227
                            	if ($key != "ville") $queries .= " and " ;
228
                            }
229
 
230
                        }
231
                    }
232
                    $or_flag = true ;
233
                }
234
			}
235
			// ici le cas ou rien n'a été saisie du tout, on affiche tout
236
			if (!$or_flag) {
237
					$queries .= ANN_CHAMPS_NOM.' like "%")' ;
238
			}
239
	}
240
} else {
241
	if ($lettre == "tous") $lettre = "" ;
242
	$queries .= ANN_CHAMPS_NOM.' like "'.$lettre.'%" and ' ;
243
}
244
    $queries .= "" ;
245
    // jointure entre annuaire et table des pays annuaire_tela et gen_COUNTRY
246
	$queries .= "  ".ANN_ANNUAIRE.".".ANN_CHAMPS_PAYS."=".ANN_TABLE_PAYS.".GC_ID" ;
247
 
248
    if (isset($nom) && $nom != "") $queries .= " and ".ANN_CHAMPS_NOM." like \"%$nom%\"" ;
249
    if (isset($prenom) && $prenom != "") $queries .= " and ".ANN_CHAMPS_PRENOM." like \"%$prenom%\"" ;
250
    if (isset($ville) && $ville != "") $queries .= " and ".ANN_CHAMPS_VILLE." like \"%$ville%\"" ;
251
    if (isset($mail) && $mail != "") $queries .= " and ".ANN_CHAMPS_MAIL." like \"%$mail%\"" ;
252
  if (isset($_REQUEST['sort']) && $_REQUEST['sort'] != '') $queries .= ' order by '.$_REQUEST['sort'] ;
253
  return $queries;
254
}
255
 
256
function mkresu() {
257
 
258
    $requete = mkquery() ;
259
 
260
	// Requete sans le limit pour le nombre de resultat
261
	$resultat_nbr = $GLOBALS['ann_db']->query($requete) ;
262
    if (DB::isError($resultat_nbr)) {
263
		return $resultat_nbr->getMessage().'<br />'.$resultat_nbr->getDebugInfo().'<br />'.$requete ;
264
	}
265
	$nbr_final = $resultat_nbr->numRows() ;
266
	$resultat_nbr->free();
267
	$_SESSION['requete_mail_tous'] = $requete ;
268
 
269
	if (!isset($_REQUEST['T_REPONSE'])) $_REQUEST['T_REPONSE'] = 20 ;
270
	$debut = $_REQUEST['pageID'] * $_REQUEST['T_REPONSE'];
271
	$requete .= ' limit '.$debut.','.$_REQUEST['T_REPONSE'];
272
    // Requetes avec les résultats affichés
273
 
274
    $resultat = $GLOBALS['ann_db']->query($requete) ;
275
    if (DB::isError($resultat)) {
276
		return $resultat->getMessage().'<br />'.$resultat->getDebugInfo().'<br />'.$requete ;
277
	}
278
 
279
 
280
    $variables_a_supprimer = array ('username', 'password', 'connexion');
281
	foreach ($variables_a_supprimer as $var) if (isset($_POST[$var])) unset ($_POST[$var]) ;
282
 
283
 
284
	$variables = array_merge ($_POST, $_GET);
285
 
286
	foreach ($variables as $key => $var) if ($variables[$key] != '') $GLOBALS['ann_url']->addQueryString($key, $variables[$key]);
287
 
288
    $ret = "<table id=\"recherche_alphabetique\"><tr>" ;
289
 
290
    for ($i = 65 ; $i <91 ; $i++) {
291
        $ret .= "\t<td><a href=\"".$GLOBALS['ann_url']->getURL()."&lettre=";
292
        $ret .= chr($i)."\">";
293
        $ret .= chr($i) ;
294
        $ret .= "</a></td>\n";
295
	}
296
	$GLOBALS['ann_url']->addQueryString('lettre', 'tous');
297
    $ret .= '<td>&nbsp;&nbsp;<a href="'.$GLOBALS['ann_url']->getURL().'">'.AM_L_TOUS."</a></td>\n" ;
298
    $ret .= "<tr></table>\n" ;
299
 
300
    include_once 'api/pear/Pager/Pager.php';
301
 
302
	$params = array(
303
	    'mode'       => 'Jumping',
304
	    'perPage'    => $_REQUEST['T_REPONSE'],
305
	    'delta'      => 12,
306
	    'httpMethod' => 'GET',
307
	    'extraVars' => array_merge($_POST, $_GET),
308
	    'altNext' => 'Suivant',
309
	    'altPrev' => 'Précédent',
310
	    'nextImg' => 'Suivant',
311
	    'prevImg' => 'Précedent',
312
	    'totalItems'   => $nbr_final
313
		);
314
	$pager = & Pager::factory($params);
315
	$data  = $pager->getPageData();
316
	$links = $pager->getLinks();
317
	$range = $pager->getOffsetByPageId();
318
	$ret .= '<h2>'.$range[0].' - '.$range[1].' parmi '.$nbr_final.'</h2>';
319
	$ret .= '<div class="bazar_numero">'.$pager->links.'</div>'."\n";
320
	include_once 'api/pear/HTML/Table.php';
321
	$table = new HTML_Table(array("class" => "table_cadre"));
322
	$table->addRow(array("<a href=\"".$GLOBALS['ann_url']->getURL()."&amp;sort=".ANN_CHAMPS_NOM."\">Identit&eacute;</a>",
323
					"<a href=\"".$GLOBALS['ann_url']->getURL()."&amp;sort=".ANN_CHAMPS_MAIL."\">Adresse mail</a>",
324
					"<a href=\"".$GLOBALS['ann_url']->getURL()."&amp;sort=".ANN_CHAMPS_VILLE."\">".AM_L_VILLE, "Pays ou Dpt (fr)",
325
					"<a href=\"".$GLOBALS['ann_url']->getURL()."&amp;sort=U_COT\">Cotisant en ".date(Y)),'', 'TH') ;
326
	while ($valeur = $resultat->fetchRow(DB_FETCHMODE_ASSOC)) {
327
		$ligne_tableau = array();
328
		$montant = 0;
329
		// Le nom de l inscrit avec un lien dessus pour voir les details
330
		$GLOBALS['ann_url']->addQueryString('u_id', $valeur[ANN_CHAMPS_ID]);
331
		array_push ($ligne_tableau, '<a href="'.$GLOBALS['ann_url']->getURL().'">'.$valeur[ANN_CHAMPS_NOM].' '.$valeur[ANN_CHAMPS_PRENOM].'</a>');
332
 
333
		// l email
334
		array_push ($ligne_tableau, '<a href="mailto:'.$valeur[ANN_CHAMPS_MAIL].'">'.$valeur[ANN_CHAMPS_MAIL].'</a>');
335
		// La ville
336
		array_push ($ligne_tableau, $valeur[ANN_CHAMPS_VILLE]);
337
 
338
		// Le pays ou le departement si francais
339
		if ($valeur['U_COUNTRY'] != 'fr') {
340
			array_push ($ligne_tableau,  $valeur['GC_NAME']) ;
341
		} else {
342
	        $req_dpt = 'select GFD_NAME from '.ANN_TABLE_DEPARTEMENT.','.ANN_ANNUAIRE.
343
						' where '.ANN_ANNUAIRE.'.'.ANN_CHAMPS_ID.'='.$valeur[ANN_CHAMPS_ID] ;
344
	        $req_dpt .= " and ".ANN_ANNUAIRE.".U_FRENCH_DPT=".ANN_TABLE_DEPARTEMENT.".GFD_ID" ;
345
	        $resultat_dpt = $GLOBALS['ann_db']->query($req_dpt) ;
346
	        if (DB::isError($resultat_dpt)) {
347
	        	return $resultat_dpt->getMessage().'<br />'.$resultat_dpt->getDebugInfo().'<br />'.$req_dpt ;
348
	        }
349
	        $ligne_dpt = $resultat_dpt->fetchRow(DB_FETCHMODE_OBJECT) ;
350
			array_push ($ligne_tableau, $ligne_dpt->GFD_NAME) ;
351
		}
352
		// Si cotisant
353
		if ($valeur->IC_MONTANT != NULL) $montant = $valeur->IC_MONTANT.' &euro;';
354
		array_push ($ligne_tableau, $montant);
355
		$table->addRow($ligne_tableau);
356
	}
357
	$table->altRowAttributes(1, array("class" => "ligne_paire"), array("class" => "ligne_impaire"), true);
358
	$ret .= $table->toHTML();
359
	$GLOBALS['ann_url']->removeQueryString('u_id');
360
 
361
	$ret .= '<div class="bazar_numero">'.$pager->links.'</div>'."\n";
362
	$GLOBALS['ann_url']->addQueryString(ANN_VARIABLE_ACTION, ANN_ACTION_MAIL_TOUS);
363
	$ret .= "<div id=\"envoyer_selection\"><a href=\"".$GLOBALS['ann_url']->getURL()."\">".AM_L_MAIL_SELECTION."</a></div>\n" ;
364
	//$ret .= '<pre id="debogage">'.$requete.'</pre>';
365
  return $ret;
366
}
367
 
368
function resume_cotisation() {
369
 
370
	$res = '<h1>Etat des cotisations</h1>'."\n";
371
 
372
	$requete = 'select distinct(YEAR(IC_DATE)) as annees from annuaire_COTISATION';
373
    $tableau_annee_cotisation = &$GLOBALS['ann_db']->getCol ($requete);
374
    if (DB::isError($tableau_annee_cotisation)) {
375
		return $tableau_annee_cotisation->getMessage().'<br />'.$tableau_annee_cotisation->getDebugInfo();
376
	}
377
	$requete = 'select MC_ID,MC_LABEL from MODE_COTISATION order by MC_ID' ;
378
	$tableau_mode_cotisation = & $GLOBALS['ann_db']->getAssoc($requete);
379
	if (DB::isError($tableau_annee_cotisation)) {
380
		return $tableau_mode_cotisation->getMessage().'<br />'.$tableau_mode_cotisation->getDebugInfo();
381
	}
382
	// Initialisation de la table
383
	include_once 'api/pear/HTML/Table.php';
384
	$table = new HTML_Table(array('class' => 'table_cadre'));
385
	$table->addRow(array_merge (array('Année'), $tableau_mode_cotisation,
386
				array('Total', 'Nb cotisant', 'Nb inscrit', 'Ratio')), '', 'TH');
387
 
388
	foreach ($tableau_annee_cotisation as $annee) {
389
 
390
		// recherche du nombre d adherent de l annee
391
		$requete_nb_cotisant = 'select count(*) as nbr from annuaire_tela where U_DATE < "'.$annee.'-12-31" union'.
392
								' select count(*) as nbr from annuaire_COTISATION where year(IC_DATE)='.$annee;
393
		// La requete union renvoie une colonne appele nbr avec 2 lignes le nbre inscrit a tela et le nbre de cotisant
394
		// pour une année donnee
395
 
396
		$resultat = $GLOBALS['ann_db']->query($requete_nb_cotisant);
397
		if (DB::isError($resultat)) {
398
				return $resultat->getMessage().'<br />'.$rseultat->getDebugInfo();
399
		}
400
		$nb_inscrit_annee = $resultat->fetchRow(DB_FETCHMODE_OBJECT);
401
		$nb_cotisant_annee = $resultat->fetchRow(DB_FETCHMODE_OBJECT);
402
		$ratio = $nb_cotisant_annee->nbr / $nb_inscrit_annee->nbr * 100;
403
		$ligne_table = array();
404
 
405
		// On insere une premiere colone pour les annees
406
		array_push ($ligne_table, $annee);
407
		$somme_annee = 0;
408
		foreach ($tableau_mode_cotisation as $mode_id => $mode_label) {
409
			$requete = 'select sum(IC_MONTANT) as montant from annuaire_COTISATION where IC_MC_ID='.$mode_id.
410
						' and year(IC_DATE)='.$annee;
411
			$montant = $GLOBALS['ann_db']->getOne($requete);
412
			if (DB::isError($montant)) {
413
				return $montant->getMessage().'<br />'.$montant->getDebugInfo();
414
			}
415
			array_push ($ligne_table, $montant);
416
			$somme_annee += $montant;
417
		}
418
 
419
		array_push ($ligne_table, $somme_annee, $nb_cotisant_annee->nbr, $nb_inscrit_annee->nbr,substr((string)$ratio, 0, 5).' %');
420
 
421
		$table->addRow($ligne_table);
422
 
423
	}
424
	$res .= $table->toHTML();
425
	return $res;
426
}
427
/* +--Fin du code ----------------------------------------------------------------------------------------+
428
*
429
* $Log:$
430
* * +-- Fin du code ----------------------------------------------------------------------------------------+
431
*/
432
 
433
?>