root/alternc-stats/branches/INIT/admin/stat_dolist.php

Revision 1340, 30.8 kB (checked in by anonymous, 4 years ago)

Initial revision

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
<
Line 
1 <?php
2
3
4
5 require_once("../class/config.php");
6 require_once("stat_functions.php");
7
8 /* Affichage des variables : */
9 /*
10 reset($_POST);
11 while (list($k,$v)=each($_POST)) {
12   echo "$k = $v<br />";
13   if (is_array($v)) {
14     reset($v);
15     echo $k."[] = ";
16     while (list($k2,$v2)=each($v)) {
17       echo $v2.", ";
18     }
19   }
20 }
21 */
22
23
24 $tbl="";
25 $where="";
26 $fields="";
27 $order="";
28 $inner=array();
29
30
31 if ($pa=="d") {               // enfants
32   $tbl=" enfants u ";
33     $txt1="d'enfants";
34 }
35 if ($pa=="e") {               // etablissements
36   $tbl=" ets u ";
37     $txt1="d'etablissements";
38 }
39 if ($pa=="f") {               // universites
40   $tbl=" univ u ";
41     $txt1="d'universités";
42 }
43
44
45 if ($pa=="a") {               // salarie
46   $where=" AND u.typ=1 ";
47     $txt1="de salariés";
48 }
49 if ($pa=="b") {               // etudiants
50   $where=" AND u.typ=0";
51     $txt1="d'étudiants";
52 }
53
54
55
56
57
58 /* ************************************************************************* */
59 /*                        SALARIES ETUDIANTS OU LES 2                        */
60 /* ************************************************************************* */
61
62 if ($pa=="a" || $pa=="b" || $pa=="c") { 
63   $tbl=" users u ";
64     if ($pa=="c") $txt1="de salariés et étudiants";
65 }
66
67 // critere Geographique : pour tous
68 if ($q=="a") {                             // territoire
69   $where.=" AND u.tid='$qa' ";
70     list($ttt)=@mysql_fetch_array(mq("SELECT territoire FROM territoires WHERE id='$qa';"));
71     $txt2[]="sur le territoire ".$ttt;
72 }
73
74 if ($q=="b") {                             // région
75     list($ttt)=@mysql_fetch_array(mq("SELECT region FROM regions WHERE id='$qb';"));
76     $txt2[]="dans la région ".$ttt;
77   $where.=" AND t.region='$qb' ";
78     if (!$inner[territoires]) {
79       $tbl.=" INNER JOIN territoires t ON t.id=u.tid ";
80       $inner[territoires]=1;
81     }
82 }
83
84 if ($pa=="a" || $pa=="b" || $pa=="c") {   
85     $order="nom";
86
87   if ($o=="b" && is_array($ob)) {          // restriction par projets
88     if (!$inner[proj_users]) {
89       $tbl.=" INNER JOIN proj_users p ON p.eid=u.login ";
90       $inner[proj_users]=1;
91     }
92     $ttt2="";
93     for($i=0;$i<count($ob);$i++) {
94       if ($i!=0) $ttt2.=", ";
95       $ttt2.=substr($ob[$i],1);
96     }
97     $where.=" AND p.pid IN ($ttt2) ";
98     $ttt="";
99     $tt=mq("SELECT concat(nom,' (',ville,')') FROM projets WHERE id IN ($ttt2);");
100     while ($tt2=mysql_fetch_array($tt)) {
101         $ttt.=$tt2[0].", ";
102     }
103     $txt2[]="Lié à l'un des projets suivants : ".$ttt;
104   }
105   if ($o=="c" && $oc) {          // restriction par type de projet
106     if (!$inner[proj_users]) {
107       $tbl.=" INNER JOIN proj_users p ON p.eid=u.login ";
108       $inner[proj_users]=1;
109     }
110    if (!$inner[projets]) {
111      $tbl.=" INNER JOIN projets prj ON prj.id=p.pid ";
112      $inner[projets]=1;
113    }
114     $where.=" AND prj.type = '".substr($oc,1)."' ";
115     list($ttt)=@mysql_fetch_array(mq("SELECT data FROM type_actions WHERE id='".substr($oc,1)."';"));
116     $txt2[]="Lié à un projet du type : $ttt";
117   }
118
119   if ($nl) {
120     $nla=intval($nla); if (!$nla) $nla="0";
121     $nlb=intval($nlb); if (!$nlb) $nlb="0";
122     $where.=" AND birth < DATE_SUB(NOW(),INTERVAL $nla YEAR) AND birth > DATE_SUB(NOW(),INTERVAL $nlb YEAR) ";
123     $txt2[]="Dont l'âge est compris entre $nla et $nlb ans";
124   }
125   if ($nc) {
126     $where.=" AND u.nom LIKE '%$nc%' ";
127     $txt2[]="Dont le nom contient '$nc'";
128   }
129   if ($ncb) {
130     $where.=" AND u.adresse2 LIKE '%$ncb%' ";
131     $txt2[]="Dont l'adresse 2 contient '$ncb'";
132   }
133
134 } // salariés, étudiants ou les 2.
135
136
137 if ($pa=="b") { // etudiants critères spécifiques :
138
139   if ($s=="b" && $sb) {          // restriction par université
140     $where.=" AND u.univ = '".substr($sb,1)."' ";
141     list($ttt)=@mysql_fetch_array(mq("SELECT concat(nom,' (',ville,')') FROM univ WHERE id='".substr($sb,1)."';"));
142     $txt2[]="Etudiant à l'université : $ttt";
143   }
144
145   if ($na==1) {    $where.=" AND u.adherent=1 "; $txt2[]="Etudiant Adhérent"; }
146   if ($na==2) {    $where.=" AND u.adherent=0 "; $txt2[]="Etudiant NON Adhérent"; }
147   if ($nb==1) {    $where.=" AND u.referent=1 "; $txt2[]="Etudiant Référent"; }
148   if ($nb==2) {    $where.=" AND u.referent=0 "; $txt2[]="Etudiant NON Référent"; }
149
150   if ($nr) {   $where.=" AND u.filiere='$nr' ";
151     list($ttt)=@mysql_fetch_array(mq("SELECT data FROM type_filiere WHERE id='$nr';"));
152     $txt2[]="Etudiant dans la filière : $ttt";
153  }
154
155   if ($nd) { // niveau d'étude
156     $ttt="";
157     $where.=" AND u.niveau IN (";
158     for($i=0;$i<count($ne);$i++) {
159       if ($i!=0) $where.=", ";
160       $where.=$ne[$i];
161     $ttt.=" Bac+".$ne[$i].", ";
162     }
163     $where.=") ";
164     $txt2[]="De niveau d'étude $ttt";
165   }
166   if ($nf) { // statut de l'étudiant
167     $where.=" AND u.etusta='$nf' ";
168     $txt2[]="De statut : ".$a_sta_etu[$nf];
169   }
170   if ($ng==1) {    $where.=" AND u.voiture=1 "; $txt2[]="Ayant une voiture"; }
171   if ($ng==2) {    $where.=" AND u.voiture=0 "; $txt2[]="N'ayant pas de voiture"; }
172   if ($nh) {    $where.=" AND u.sexe='$nh' ";
173 if (!$nh) $txt2[]="Uniquement les filles"; else $txt2[]="Uniquement les garçons";
174 }
175   if ($ni) {    $where.=" AND u.modea='$ni' ";
176     list($ttt)=@mysql_fetch_array(mq("SELECT data FROM mode_arrivee WHERE id='$ni';"));
177     $txt2[]="Dont le mode d'arrivée est : $ttt";
178  }
179   if ($nj) { $nj=$nj-1;   $where.=" AND u.readmail='$nj' ";
180     if ($nj) $txt2[]="Qui lit son mail régulièrement"; else $txt2[]="Qui ne lit pas son mail régulièrement";
181 }
182
183 }
184
185
186 /* ************************************************************************* */
187 /*                                 ENFANTS                                   */
188 /* ************************************************************************* */
189
190 if ($pa=="d") {                            // enfants
191   if ($nc) {
192     $where.=" AND u.nom LIKE '%$nc%' ";
193     $txt2[]="Dont le nom contient '$nc'";
194   }
195
196   if ($o=="b" && is_array($ob)) {          // restriction par projets
197     if (!$inner[interv_enfants]) {
198       $tbl.=" INNER JOIN interv_enfants ie ON ie.enid=u.id ";
199       $inner[interv_enfants]=1;
200     }
201     if (!$inner[interv]) {
202       $tbl.=" INNER JOIN interv ON interv.id=ie.iid ";
203       $inner[interv]=1;
204     }
205      $ttt2="";
206     for($i=0;$i<count($ob);$i++) {
207       if ($i!=0) $ttt2.=", ";
208       $ttt2.=substr($ob[$i],1);
209     }
210     $where.=" AND interv.pid IN ($ttt2) ";
211         $ttt="";
212         $tt=mq("SELECT concat(nom,' (',ville,')') FROM projets WHERE id IN ($ttt2);");
213         while ($tt2=mysql_fetch_array($tt)) {
214                 $ttt.=$tt2[0].", ";
215         }
216         $txt2[]="Lié à l'un des projets suivants : ".$ttt;
217
218   }
219
220   if ($o=="c" && $oc) {          // restriction par type de projets
221     if (!$inner[interv_enfants]) {
222       $tbl.=" INNER JOIN interv_enfants ie ON ie.enid=u.id ";
223       $inner[interv_enfants]=1;
224     }
225     if (!$inner[interv]) {
226       $tbl.=" INNER JOIN interv ON interv.id=ie.iid ";
227       $inner[interv]=1;
228     }
229     if (!$inner[projets]) {
230       $tbl.=" INNER JOIN projets prj ON prj.id=interv.pid ";
231       $inner[projets]=1;
232     }
233     $where.=" AND prj.type = '".substr($oc,1)."' ";
234     list($ttt)=@mysql_fetch_array(mq("SELECT data FROM type_actions WHERE id='".substr($oc,1)."';"));
235     $txt2[]="Lié à un projet du type : $ttt";
236   }
237
238
239
240   // sexe :
241   if ($tb) {    $where.=" AND u.sexe='$tb' ";
242 if (!$tb) $txt2[]="Uniquement les filles"; else $txt2[]="Uniquement les garçons";
243
244 }
245   // classe :
246   if ($ta) {    $where.=" AND u.classe='$ta' ";
247        list($ttt)=@mysql_fetch_array(mq("SELECT data FROM type_classe WHERE id='$ta';"));
248         $txt2[]="Enfants de la classe de : $ttt";
249 }
250   // etablissement
251   if ($tc=='b') { $where.=" AND u.eid='".substr($tcb,1)."' ";
252         list($ttt)=@mysql_fetch_array(mq("SELECT concat(nom,' (',ville,')') FROM ets WHERE id='".substr($tcb,1)."';"));
253         $txt2[]="Enfants de l'établissement : $ttt";
254 }
255   // type d'établissement
256   if ($tc=='c') {
257     $where.=" AND un.etype='$tcc' ";
258     if (!$inner[ets]) {
259       $tbl.=" LEFT JOIN ets un ON un.id=u.eid ";
260       $inner[ets]=1;
261     }
262     list($ttt)=@mysql_fetch_array(mq("SELECT data FROM type_ets WHERE id='$tcc';"));
263         $txt2[]="Enfants dans les établissements du type : $ttt";
264
265   }
266 }
267
268 /* ************************************************************************* */
269 /*                         ETABLISSEMENTS                                    */
270 /* ************************************************************************* */
271 if ($pa=="e") {     
272   if ($te=="a") {    $where.=" AND u.etype='$tea' ";
273         list($ttt)=@mysql_fetch_array(mq("SELECT data FROM type_ets WHERE id='$tea';"));
274         $txt2[]="Etablissements du type : $ttt";
275 }
276 }
277
278 /* ************************************************************************* */
279 /*                         UNIVERSITES                                       */
280 /* ************************************************************************* */
281 if ($pa=="f") {     
282   if ($tf=="a") {    $where.=" AND u.etype='$tfa' "; }
283     list($ttt)=@mysql_fetch_array(mq("SELECT data FROM type_univ WHERE id='$tfa';"));
284         $txt2[]="Universités du type : $ttt";
285 }
286
287
288 /* ************************************************************************* */
289 /* ************************************************************************* */
290 /*                             NOW THE FIELDS                                */
291 /* ************************************************************************* */
292 /* ************************************************************************* */
293
294 /* ************************************************************************* */
295 /*                                 GROUPS                                    */
296 /* ************************************************************************* */
297
298 if ($r=="e") {
299     /* Special case : handle a group by managment. */
300     switch ($rre) {
301     case 'a':    // par territoire
302         $txt3="Calcul regroupé par territoire";
303         // Ajoute la table territoire si elle n'a pas été incluse.
304         if (!$inner[territoires]) {
305           $tbl.=" INNER JOIN territoires t ON t.id=u.tid ";
306           $inner[territoires]=1;
307             }
308
309         $fields=" t.territoire , count(*) AS compteur ";
310         $group=" GROUP BY t.id ";
311     break;
312     case 'b':     // par région
313         $txt3="Calcul regroupé par région";
314         // Ajoute la table territoire si elle n'a pas été incluse.
315         if (!$inner[territoires]) {
316           $tbl.=" INNER JOIN territoires t ON t.id=u.tid ";
317           $inner[territoires]=1;
318             }
319         // Ajoute la table region si elle n'a pas été incluse.
320           if (!$inner[region]) {
321             $tbl.=" INNER JOIN regions r ON r.id=t.region ";
322             $inner[region]=1;
323           }
324         $fields=" r.region, count(*) AS compteur ";
325         $group=" GROUP BY r.id ";
326     break;
327     case 'c':     // par projet (pour les étudiants)
328         $txt3="Calcul regroupé par projet";
329         if (!$inner[proj_users]) {
330           $tbl.=" INNER JOIN proj_users p ON p.eid=u.login ";
331           $inner[proj_users]=1;
332         }
333           if (!$inner[projets]) {
334             $tbl.=" LEFT JOIN projets prj ON prj.id=p.pid ";
335             $inner[projets]=1;
336           }
337         $fields=" CONCAT(prj.nom,' (',prj.id,')') AS projet, count(*) AS compteur ";
338         $group=" GROUP BY prj.id ";
339     break;
340     case 'd':     // par type de projet (pour les étudiants)
341             $txt3="Calcul regroupé par type de projet";
342         if (!$inner[proj_users]) {
343           $tbl.=" INNER JOIN proj_users p ON p.eid=u.login ";
344           $inner[proj_users]=1;
345         }
346           if (!$inner[projets]) {
347             $tbl.=" LEFT JOIN projets prj ON prj.id=p.pid ";
348             $inner[projets]=1;
349           }
350         if (!$inner[type_actions]) {
351           $tbl.=" INNER JOIN type_actions ta ON ta.id=prj.type ";
352           $inner[type_actions]=1;
353         }
354         $fields=" ta.data AS TypeDeProjet, count(*) AS compteur ";
355         $group=" GROUP BY ta.id ";
356     break;
357     case 'e':     // par université
358         $txt3="Calcul regroupé par université";
359           if (!$inner[univ]) {
360             $tbl.=" LEFT JOIN univ un ON un.id=u.univ ";
361             $inner[univ]=1;
362           }
363         $fields=" concat(un.nom,' (',un.ville,')') AS universite, count(*) as compteur ";
364         $group=" GROUP BY un.id ";
365     break;
366     case 'f':    // par type d'université   
367         $txt3="Calcul regroupé par type d'université";
368           if (!$inner[univ]) {
369             $tbl.=" LEFT JOIN univ un ON un.id=u.univ ";
370             $inner[univ]=1;
371           }
372           if (!$inner[type_univ]) {
373         $tbl.=" LEFT JOIN type_univ tu ON un.etype=tu.id ";
374         $inner[type_univ]=1;
375           }
376         $fields=" tu.data AS TypeUniversite, count(*) as compteur ";
377         $group=" GROUP BY tu.id ";
378     break;
379     case 'g':     // par filiere de l'étudiant
380         $txt3="Calcul regroupé par filière d'étude";
381           if (!$inner[type_filiere]) {
382         $tbl.=" LEFT JOIN type_filiere tf ON u.filiere=tf.id ";
383         $inner[type_filiere]=1;
384           }
385         $fields=" tf.data as Filiere, count(*) as compteur ";
386         $group=" GROUP BY tf.id ";
387     break;
388     case 'h':     // par adhérent
389         $txt3="Calcul regroupé par statut adhérent";
390         $fields=" CASE u.adherent  WHEN 1 THEN 'Adhérent' ELSE 'Non Adhérent' END AS Adherent, count(*) AS compteur ";
391         $group=" GROUP BY u.adherent ";
392     break;
393     case 'i':     // par référent
394         $txt3="Calcul regroupé par statut référent";
395         $fields=" CASE u.referent  WHEN 1 THEN 'Référent' ELSE 'Non Référent' END AS Referent, count(*) AS compteur ";
396         $group=" GROUP BY u.referent ";
397     break;
398     case 'j':    // par niveau d'étude
399         $txt3="Calcul regroupé par niveau d'étude";
400         $fields=" CONCAT('Bac +',niveau) AS Niveau, count(*) AS compteur ";
401         $group=" GROUP BY u.niveau ";
402     break;
403     case 'k':    // par statut
404         $txt3="Calcul regroupé par statut étudiant";
405               $fields=" CASE u.etusta WHEN 1 THEN 'Demandeur' WHEN 2 THEN 'Contacté'
406            WHEN 3 THEN 'Volontaire' WHEN 4 THEN 'Volontaire Actif' WHEN 5 THEN 'Ancien'
407            ELSE 'autre !' END AS statut, count(*) as compteur ";
408               $group=" GROUP BY u.etusta ";
409     break;
410     case 'o':    // par sexe de l'enfant
411     case 'l':     // par sexe
412         $txt3="Calcul regroupé par sexe";
413               $fields=" CASE u.sexe WHEN 1 THEN 'Garçon' ELSE 'Fille' END AS sexe , count(*) as compteur ";
414               $group=" GROUP BY u.sexe ";
415     break;
416     case 'm':    // par mode d'arrivée
417         $txt3="Calcul regroupé par mode d'arrivée à l'AFEV";
418           if (!$inner[mode_arrivee]) {
419             $tbl.=" LEFT JOIN mode_arrivee ma ON ma.id=u.modea ";
420             $inner[mode_arrivee]=1;
421           }
422         $fields=" ma.data AS ModeArrivee, count(*) as compteur ";
423         $group=" GROUP BY ma.id ";
424     break;
425     case 'n':     // par classe de l'enfant
426         $txt3="Calcul regroupé par classe";
427           if (!$inner[type_classe]) {
428             $tbl.=" LEFT JOIN type_classe cl ON cl.id=u.classe ";
429             $inner[type_classe]=1;
430           }
431         $fields=" cl.data AS Classe, count(*) as compteur ";
432         $group=" GROUP BY cl.id ";       
433     break;
434     case 'p':    // par etablissement de l'enfant
435         $txt3="Calcul regroupé par établissement de provenance";
436           if (!$inner[ets]) {
437             $tbl.=" LEFT JOIN ets ON ets.id=u.eid ";
438             $inner[ets]=1;
439           }
440         $fields=" concat(ets.nom,' (',ets.ville,')') AS Etablissement, count(*) as compteur ";
441         $group=" GROUP BY ets.id ";
442     break;
443     case 'q':    // par type d'établissement
444         $txt3="Calcul regroupé par type d'établissement de provenance";
445           if (!$inner[ets]) {
446             $tbl.=" LEFT JOIN ets ON ets.id=u.eid ";
447             $inner[ets]=1;
448           }
449           if (!$inner[type_ets]) {
450             $tbl.=" LEFT JOIN type_ets te ON te.id=ets.etype ";
451             $inner[type_ets]=1;
452           }
453         $fields=" te.data AS TypeEtablissement, count(*) as compteur ";
454         $group=" GROUP BY te.id ";
455     break;
456     case 'r':    // par type d'établissement (pour les ets eux-même)
457         $txt3="Calcul regroupé par type d'établissement";
458           if (!$inner[type_ets]) {
459             $tbl.=" LEFT JOIN type_ets te ON te.id=u.etype ";
460             $inner[type_ets]=1;
461           }
462         $fields=" te.data AS TypeEtablissement, count(*) as compteur ";
463         $group=" GROUP BY te.id ";
464     break;
465     case 's':    // par type d'université (pour les universités elles-memes)
466         $txt3="Calcul regroupé par type d'université";
467           if (!$inner[type_univ]) {
468             $tbl.=" LEFT JOIN type_univ tu ON tu.id=u.etype ";
469             $inner[type_univ]=1;
470           }
471         $fields=" tu.data AS TypeUniversite, count(*) as compteur ";
472         $group=" GROUP BY tu.id ";
473     break;
474     case 't':    // enfants par projet
475         $txt3="Calcul regroupé par projet de rattachement";
476           if (!$inner[interv_enfants]) {
477             $tbl.=" LEFT JOIN interv_enfants ie ON ie.enid=u.id ";
478             $inner[interv_enfants]=1;
479           }
480           if (!$inner[interv]) {
481             $tbl.=" LEFT JOIN interv ON interv.id=ie.iid ";
482             $inner[interv]=1;
483           }
484           if (!$inner[projets]) {
485             $tbl.=" LEFT JOIN projets prj ON prj.id=interv.pid ";
486             $inner[projets]=1;
487           }
488         $fields=" CONCAT(prj.nom,' (',prj.ville,')') AS Projet, count(*) as compteur ";
489         $group=" GROUP BY prj.id ";