Subversion Repositories Sites.tela-botanica.org

Rev

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

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