Subversion Repositories Applications.papyrus

Rev

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

Rev Author Line No. Line
448 ddelon 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
//
1292 neiluj 13
// $Id: annuaire_backoffice.fonct.php,v 1.9 2007-04-06 08:35:46 neiluj Exp $
448 ddelon 14
 
15
 
16
/** function mkengine ()
17
*
18
*
19
*
20
*	@return
21
*/
22
 
1292 neiluj 23
include_once 'Pager/Pager.php' ;
24
include_once 'HTML/Table.php';
679 alexandre_ 25
 
448 ddelon 26
function mkengine()
27
  {
28
    global $nbr_total;
29
    global $bouton, $HTTP_POST_VARS ;
30
 
679 alexandre_ 31
    $requete = mkquery() ;
32
    $ret = '<div>'. $requete .'</div>';
33
    // Deux requetes, une avec tous les resultats, l'autre avec les résultats affichés
34
 
35
    $result_final = $GLOBALS['ins_db']->query($requete) ;
36
    if (DB::isError($result_final)) {
37
    	echo $result_final->getMessage().'<br />'.$requete ;
38
    }
39
    $nbr_final = $result_final->numRows() ;
40
 
41
    $_SESSION['requete_mail_tous'] = $requete ;
42
 
43
    $donnees = array();
44
	while ($ligne = $result_final->fetchRow(DB_FETCHMODE_ASSOC)) {
45
		$donnees[] = $ligne ;
46
	}
47
 
48
	if (!isset($_REQUEST['setPerPage'])) $_REQUEST['setPerPage'] = 50 ;
49
 
50
	$param_pager = array (
51
                    'mode' => 'Jumping',
52
                    'delta' => 5,
53
                    'itemData' => $donnees
54
             ) ;
55
    $pager = & Pager::factory($param_pager);
1292 neiluj 56
 
57
 
448 ddelon 58
    $mes_vars = array ("recherche", "nom", "ville", "mail" ,"dept", "prenom", "cotisant", "pays", "sort", "T_REPONSE", "lettre","statut") ;
1292 neiluj 59
 
448 ddelon 60
    // Deux cas , soit on a cliqué sur rechercher, soit on a cliqué sur un lien
61
    foreach ($mes_vars as $key=>$value) {
62
        if (!$bouton) {     // on a cliqué sur un lien
63
            if (empty($HTTP_POST_VARS[$value])) {
679 alexandre_ 64
 
448 ddelon 65
            }
66
        } else {
67
            // Si on clique sur le bouton rechercher
68
            if (empty ($HTTP_POST_VARS[$value])) {
69
                $$value = "" ;
70
            } else {
71
                $$value = $HTTP_POST_VARS[$value] ;
72
            }
73
        }
1292 neiluj 74
    }
75
    // Comptage du nombre total de données dans la table (hors CACHER = 1)
76
    $requete_nbre_inscrit = "select count(*) as CPT from ".INS_ANNUAIRE;
77
    $resultat_nbre_inscrit = $GLOBALS['ins_db']->query($requete_nbre_inscrit) ;
78
 
448 ddelon 79
 
1292 neiluj 80
  if ($resultat_nbre_inscrit->numRows() == 1) {
81
        $tmp_nb = $resultat_nbre_inscrit->fetchRow(DB_FETCHMODE_OBJECT);
82
        $nbr_total = $tmp_nb->CPT;
83
        if ($nbr_total > 0) $chaine = "parmi $nbr_total données";
84
        else die("<B>Erreur</B> lors du comptage des structures ($nbr_total trouvées) : $query");
85
    }
86
  else die("<B>Erreur</B> lors du comptage des structures : $query");
87
 
88
 
89
  // fin comptage
90
 
679 alexandre_ 91
  	$ret = '';
1292 neiluj 92
	$ret .= '<h1>'.AM_L_TITRE.' '.$chaine.'</h1>'."\n" ;
448 ddelon 93
  // construction du moteur de str
94
 
1292 neiluj 95
    $ret .= '<form action="'.$GLOBALS['ins_url']->getURL().'" method="post">'."\n";
96
    $ret .= '<table summary="recherche">'."\n";
679 alexandre_ 97
 
1292 neiluj 98
    // ligne de recherche
99
    $ret .= "<tr>\n";
100
    $ret .= "<td>".AM_L_RECHERCHER." :\n</td>\n<td>";
101
    $ret .= form_mk_chaineI(isset ($_REQUEST['recherche']) ? stripslashes($_REQUEST['recherche']) : '', "recherche")."&nbsp;";
102
    $ret .= '</td><td colspan="4">'.AM_L_PAYS." : \n" ;
679 alexandre_ 103
 
1292 neiluj 104
    // formulaire contenant les pays, avec par défaut soit le pays en cours
105
    // soit "tous les pays"
106
    $liste_pays = new ListeDePays($GLOBALS['ins_db']) ;
107
    $tableau_pays = $liste_pays->getListePays(INS_LANGUE_DEFAUT) ;
108
 
109
    $ret .= "<select name=\"pays\">\n" ;
110
    $ret .= "<option value=\"tous\">Tous les pays</option>\n" ;
111
    foreach ($tableau_pays as $codeIso => $labelPays) {
112
        $ret .= '<option value="'.$codeIso.'"' ;
113
        if (!empty($pays)) {
114
                if ($pays == $codeIso) $ret .= " selected" ;
115
        }
116
        $ret .= '>'.$labelPays.'</option>'."\n" ;
117
    }
118
    $ret .= "</select>\n" ;
119
    $ret .= "</td></tr>\n" ;
120
 
121
	$ret .= "<tr>\n";
122
    $ret .= "<td>".AM_L_NOM." :\n</td><td>";
123
    $ret .= form_mk_chaineI(isset ($_REQUEST['nom']) ? stripslashes($_REQUEST['nom']) : '', "nom")."&nbsp;</td>\n<td>" ;
124
    $ret .= AM_L_PRENOM."&nbsp;:</td>\n<td>".form_mk_chaineI(isset ($_REQUEST['prenom']) ? stripslashes($_REQUEST['prenom']) : '', "prenom")."&nbsp;</td>\n<td class=\"insLabel\">" ;
125
    $ret .= AM_L_VILLE."&nbsp;:</td>\n<td>".form_mk_chaineI(isset ($_REQUEST['ville']) ? stripslashes($_REQUEST['ville']) : '', "ville")."&nbsp;</td>" ;
126
    $ret .= "</tr><tr>\n" ;
127
    $ret .= "<td>".AM_L_DEPARTEMENT."&nbsp;: </td>\n<td>" ;
128
 
129
    // Construction du <select> des départements
130
    $requete_dpt = 'select '.INS_CHAMPS_ID_DEPARTEMENT.', '.INS_CHAMPS_NOM_DEPARTEMENT.' from '.INS_TABLE_DPT ;
131
    $resultat_dpt = $GLOBALS['ins_db']->query($requete_dpt) ;
132
    if (DB::isError($resultat_dpt)) {
133
    	echo 'Echec de la requete<br />'.$requete_dpt.'<br />'.$resultat_dpt->getMessage();
134
    }
135
    $ret .= "<select name=\"dept\">\n" ;
136
    $ret .= "<option value=\"tous\">tous</option>\n" ;
137
    while ($ligne_dpt = $resultat_dpt->fetchRow(DB_FETCHMODE_ASSOC)) {
138
        $ret .= '<option value="'.$ligne_dpt[INS_CHAMPS_ID_DEPARTEMENT].'"' ;
139
        if (isset ($_REQUEST['dept']) && $_REQUEST['dept'] == $ligne_dpt[INS_CHAMPS_ID_DEPARTEMENT]) $ret .= " selected" ;
140
        $ret .= '>'.$ligne_dpt[INS_CHAMPS_ID_DEPARTEMENT].' - '.$ligne_dpt[INS_CHAMPS_NOM_DEPARTEMENT].'</option>'."\n" ;
141
    }
142
    $ret .= "</select></td>\n" ;
143
 
144
    $ret .= '<td>'.AM_L_MAIL.'&nbsp;: </td><td colspan="3">'.form_mk_chaineI(isset ($_REQUEST['mail']) ? stripslashes($_REQUEST['mail']) : '', "mail")."</td>\n" ;
145
    $ret .= "</tr>" ;
146
 
147
    // Les statuts des inscrits
679 alexandre_ 148
 
1292 neiluj 149
    $ret .= "<tr>\n";
150
    $ret .= "<td>\n";
151
    $ret .= AM_L_GRP_RES." : </td>" ;
152
    $ret .= '<td>'.$pager->getperpageselectbox (50 , 200, 50 , false ,'%d').'</td>'."\n" ;
153
    $ret .= '<td colspan="4">'."\n";
154
    $ret .= "<input type=\"submit\" value=\"".AM_L_RECHERCHER."\" name =\"bouton\">\n";
155
    $ret .= "</td></tr></table></form>\n";
679 alexandre_ 156
 
1292 neiluj 157
    $ret .= "\n<div>" ;
158
 
679 alexandre_ 159
    // La liste des lettres de l'alphabet
160
    for ($i = 65 ; $i <91 ; $i++) {
161
    	$GLOBALS['ins_url']->addQueryString('lettre', chr($i)) ;
162
        $ret .= "\t<a href=\"".$GLOBALS['ins_url']->getURL();
163
        $ret .= '">';
164
        $ret .= chr($i) ;
165
        $ret .= "</a> \n";
166
	}
167
	$GLOBALS['ins_url']->addQueryString ('lettre', 'tous') ;
168
	$ret .= " <a href=\"".$GLOBALS['ins_url']->getURL().'">'.AM_L_TOUS."</a>\n" ;
169
    $ret .= "</div>\n" ;
1292 neiluj 170
    $ret .= '<div>'.$nbr_final.' résultat(s)</div>' ;
679 alexandre_ 171
    $GLOBALS['ins_url']->removeQueryString('lettre') ;
172
 
173
    // Menu Ajouter un inscrit
174
    $GLOBALS['ins_url']->addQueryString('ajouter', '1') ;
175
    $ret .= '<div><a href="'.$GLOBALS['ins_url']->getURL().'">'.INS_AJOUT_MEMBRE.'</a></div>'."\n";
176
	$data  = $pager->getPageData();
177
 
178
	$table = new HTML_Table(array ('class' => 'table_bazar')) ;
1292 neiluj 179
	$table->addRow(array(
180
				'<a href="'.$GLOBALS['ins_url']->getURL().'&amp;sort='.INS_CHAMPS_NOM.'">Identit&eacute;</a>',
181
				'<a href="'.$GLOBALS['ins_url']->getURL().'&amp;sort='.INS_CHAMPS_MAIL.'">Adresse mail</a>',
182
				'<a href="'.$GLOBALS['ins_url']->getURL().'&amp;sort='.INS_CHAMPS_VILLE.'">'.AM_L_VILLE.'</a>',
183
				'Pays ou Dpt (fr)'
679 alexandre_ 184
			), '', 'TH') ;
185
 
186
	$debut = isset($_REQUEST['pageID']) ? $_REQUEST['pageID'] : 1 ;
187
	for ($i = ($debut - 1) * $_REQUEST['setPerPage'];
188
				$i < $_REQUEST['setPerPage'] * $debut;
189
				$i++) {
190
		// On teste s'il y une valeur, si oui on ajoute la ligne
191
		if (isset ($data[$i])) {
192
			$urlPop = $GLOBALS['ins_url']->getURL().'&amp;'.INS_CHAMPS_ID.'='.$data[$i][INS_CHAMPS_ID];
1292 neiluj 193
			$ligne_inscrit = array ("<a href=\"$urlPop\">".$data[$i][INS_CHAMPS_NOM].' '.$data[$i][INS_CHAMPS_PRENOM].
679 alexandre_ 194
								'</a>', $data[$i][INS_CHAMPS_MAIL], $data[$i][INS_CHAMPS_VILLE]) ;
195
 
196
			// Pour la france on met le département, sinon on laisse le nom du pays
197
			if ($data[$i][INS_CHAMPS_PAYS] != 'fr') {
198
				array_push ($ligne_inscrit, $data[$i][INS_CHAMPS_LABEL_PAYS]);
199
			} else {
1292 neiluj 200
		        $req_dpt = 'select '.INS_CHAMPS_NOM_DEPARTEMENT.' from '.INS_TABLE_DEPARTEMENT.",".INS_ANNUAIRE.
201
							" where ".INS_ANNUAIRE.'.'.INS_CHAMPS_ID.'='.$data[$i][INS_CHAMPS_ID] ;
202
		        $req_dpt .= " and ".INS_ANNUAIRE.'.'.INS_CHAMPS_ID_DEPARTEMENT.'='.INS_TABLE_DEPARTEMENT.'.'
203
		        					.INS_CHAMPS_ID_DEPARTEMENT ;
204
		        $resultat_dpt = $GLOBALS['ins_db']->query($req_dpt) ;
205
		        $ligne_dpt = $resultat_dpt->fetchRow(DB_FETCHMODE_ASSOC) ;
206
				array_push ($ligne_inscrit, $ligne_dpt[INS_CHAMPS_NOM_DEPARTEMENT]) ;
679 alexandre_ 207
			}
208
 
209
			$table->addRow($ligne_inscrit) ;
210
		}
211
	}
212
	$ret .= $table->toHTML();
213
	$links = $pager->getLinks();
214
	$ret .= $links['all'] ;
215
 
216
    $ret .= '<div><a href="'.$GLOBALS['ins_url']->getURL().'&amp;action='.ANN_MAIL_TOUS
217
    			.'">'.AM_L_MAIL_SELECTION."</a></div>\n" ;
218
 
448 ddelon 219
    return $ret;
220
}
221
 
1292 neiluj 222
/** function form_mk_chaineI () Renvoie une balise de type <input>
223
*
224
*   @param  string  l'attribut value de la balise
225
*   @param  string  l'attibut name de la balise
226
*   @param  string  la classe CSS
227
*   @return string  HTML
228
*/
229
function form_mk_chaineI($value="", $name, $class="insInputForm")
230
{
231
    return "<input type=\"text\" size=\"15\" value=\"$value\" name=\"$name\" class=\"$class\">";
232
}
448 ddelon 233
 
1292 neiluj 234
function form_mk_select($value="", $name="", $class="insInputForm") {
235
	$res = "<select name=\"$name\" class=\"$class\">\n" ;
236
	$res .= "<option value=\"1\"" ;
237
	if ($value == 1) $res .= " selected" ;
238
	$res .= ">Cotisants</option>\n" ;
239
	$res .= "<option value=\"2\"" ;
240
	if ($value == 2) $res .= " selected" ;
241
	$res .= ">Non cotisants</option>\n" ;
242
	$res .= "<option value=\"3\"" ;
243
	if ($value == 3 || $value == "") $res .= " selected" ;
244
	$res .= ">Tous</option>\n" ;
245
	$res .= "</select>\n" ;
246
	return $res ;
247
  }
248
 
448 ddelon 249
function mkquery()
250
{
251
 
252
	// Requete sur l'annuaire pour extraire le nom, prénom, ville, nom du département (jointure),
253
	// l'état de la cotisation (jointure)
254
 
255
	// le tableau suivant contient tous les champs de la table annuaire_tela sur lesquels on peut effectuer une recherche
1292 neiluj 256
	$fields_annu = array("nom" => INS_CHAMPS_NOM, "prenom" => INS_CHAMPS_PRENOM , "mail" => INS_CHAMPS_MAIL , "ville" => INS_CHAMPS_VILLE,
257
			"dept" => INS_CHAMPS_DEPARTEMENT, "pays" => INS_CHAMPS_PAYS ) ;
448 ddelon 258
 
1292 neiluj 259
    $mes_vars = array ("recherche", "nom", "ville", "mail" ,"dept", "prenom", "cotisant", "pays", "sort", "T_REPONSE", "lettre","statut") ;
260
 
261
	$queries = "select ".INS_ANNUAIRE.".*" ;
679 alexandre_ 262
    $queries .= ", ".INS_TABLE_PAYS.'.'.INS_CHAMPS_LABEL_PAYS ;
1292 neiluj 263
	$queries .= " from ".INS_ANNUAIRE ;
679 alexandre_ 264
    $queries .= ",".INS_TABLE_PAYS ;
448 ddelon 265
 
266
	// Construction en fonction des champs saisies
267
 
268
	// juste le champs "rechercher", on regarde partout
679 alexandre_ 269
 
1292 neiluj 270
	$where = ' where ' ;
679 alexandre_ 271
    if (isset ($_REQUEST['recherche']) && $_REQUEST['recherche'] != "") {
272
        $where .= '('.INS_CHAMPS_NOM.' like "%'.$_REQUEST['recherche'].'%"' ; // le premier
273
        foreach($fields_annu as $key=>$value) {
274
			if ($key == "nom" || $key == 'dept') continue ;
275
            $where .= ($key == "pays" ?
276
                $_REQUEST['pays'] == "tous" ? ")" :
277
                ") and $value = '".$_REQUEST['pays']."'" : ' or '.$value.' like "%'.$_REQUEST['recherche'].'%"') ;	// les autres
278
        }
279
        if (isset ($_REQUEST['dept']) && $_REQUEST['dept'] != 'tous') {
280
        	$where .= 'and '.INS_CHAMPS_DEPARTEMENT.'="'.$_REQUEST['dept'].'"' ;
281
        }
282
	} else {
448 ddelon 283
 
679 alexandre_ 284
		// si un ou plusieurs autres champs ont été indiqué, on les rajoute ici
448 ddelon 285
 
679 alexandre_ 286
		$or_flag = false ;
287
		foreach($fields_annu as $key=>$valeur) {
288
            if ($key != "") {
289
                if ($key == "pays") {
290
                    if (!isset($_REQUEST[$key]) || $_REQUEST[$key] == "tous") {
1292 neiluj 291
                    	$where .= " and ".INS_CHAMPS_PAYS." like '%'";
448 ddelon 292
                    } else {
1292 neiluj 293
                    	$where .= " and $valeur like \"%".$_REQUEST[$key]."%\"" ;
679 alexandre_ 294
                    }
295
                } else {
296
                    if ($key == "dept") {
297
                        if (isset($_REQUEST[$key]) && $_REQUEST[$key] != "tous") {
298
                            $where .= " and ".INS_CHAMPS_DEPARTEMENT."=".$_REQUEST[$key] ;
299
                            if ($fields_annu["pays"] != "fr") $where .= " and ".INS_CHAMPS_PAYS."=\"fr\"" ;
300
                        }
301
 
302
                    } else {
303
                        if (isset ($_REQUEST[$key]) && $or_flag) {
1292 neiluj 304
                        	$where .= "$valeur like \"%".$_REQUEST[$key]."%\"" ;
448 ddelon 305
                        } else {
1292 neiluj 306
                        	$where .= "$valeur like \"%%\"" ;
307
                        }
308
                        if ($key != "ville") $where .= " and " ;
448 ddelon 309
                    }
310
                }
679 alexandre_ 311
                $or_flag = true ;
312
            }
313
		}
314
		// ici le cas ou rien n'a été saisie du tout, on affiche tout
315
		if (!$or_flag) {
316
				$where .= INS_CHAMPS_NOM." like '%')" ;
317
		}
448 ddelon 318
	}
679 alexandre_ 319
 
320
    if (isset($_REQUEST['lettre'])) {
321
    	if ($_REQUEST['lettre'] == 'tous') $_REQUEST['lettre'] = '';
1292 neiluj 322
    	$where = ' where '.INS_CHAMPS_NOM.' like "'.$_REQUEST['lettre'].'%"' ;
448 ddelon 323
    }
679 alexandre_ 324
    $where .= " and ".INS_ANNUAIRE.".".INS_CHAMPS_PAYS."=".INS_TABLE_PAYS.".".INS_CHAMPS_ID_PAYS."" ;
325
 
326
    if (isset($nom) && $nom != "") $where .= " and ".INS_CHAMPS_NOM." like \"%$nom%\"" ;
327
    if (isset($_REQUEST['prenom']) && $_REQUEST['prenom'] != "")
328
    				$where .= " and ".INS_CHAMPS_PRENOM.' like "%'.$_REQUEST['prenom'].'%"' ;
329
    if (isset($ville) && $ville != "") $where .= " and ".INS_CHAMPS_VILLE." like \"%$ville%\"" ;
330
    if (isset($mail) && $mail != "") $where .= " and ".INS_CHAMPS_MAIL." like \"%$mail%\"" ;
331
    $where .= ' and  gip_id_i18n like "%'.$GLOBALS['lang'].'%"' ;
332
 
333
	if (isset ($_REQUEST['lettre']) && $_REQUEST['lettre'] == "tous") $_REQUEST['lettre'] = "" ;
334
    if (!isset ($_REQUEST['lettre'])) $_REQUEST['lettre'] = '' ;
335
 
336
 
1292 neiluj 337
    $queries .= $where ;
679 alexandre_ 338
 
339
  if (isset($_REQUEST['sort']) && $_REQUEST['sort'] != "") $queries .= ' order by '.$_REQUEST['sort'] ;
448 ddelon 340
  return $queries;
341
}
342
 
343
 
679 alexandre_ 344
function ajouterInscrit() {
345
	$res = '';
346
	$GLOBALS['ins_url']->addQueryString ('ajouter', '1');
347
	$GLOBALS['ins_url']->addQueryString ('ajouter_v', '1');
348
	$formulaire = new HTML_formulaireInscription('inscription',  '',
349
						str_replace ('&amp;', '&', $GLOBALS['ins_url']->getURL()), '', '') ;
350
	$formulaire->construitFormulaire(str_replace ('&amp;', '&', $GLOBALS['ins_url']->getURL())) ;
351
 
352
	if (isset($_REQUEST['ajouter_v'])) {
353
		if ($formulaire->validate()) {
1292 neiluj 354
			insertion($formulaire->getSubmitValues()) ;
679 alexandre_ 355
			if (INS_CHAMPS_LETTRE != '' && isset ($valeurs['lettre'])) {
356
				inscription_lettre(INS_MAIL_INSCRIPTION_LISTE) ;
357
			}
358
		    return mkengine();
359
        }
448 ddelon 360
	}
679 alexandre_ 361
	return $formulaire->toHTML();
448 ddelon 362
}
1292 neiluj 363
?>