mapfrance.php 6.6 KB
Newer Older
Ayolo's avatar
Ayolo committed
1
2
3
<?php
/* Copyright 2007
 * - Simon Lopez < simon dot lopez at ayolo dot org >
pedrov's avatar
map    
pedrov committed
4
 * - Pierre Mauduit <pierre POINT mauduit CHEZ utbm POINT fr>
Ayolo's avatar
Ayolo committed
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
 *
 * Ce fichier fait partie du site de l'Association des Étudiants de
 * l'UTBM, http://ae.utbm.fr.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 * 02111-1307, USA.
 */

pedrov's avatar
debug    
pedrov committed
25
define("WATERMARK", FALSE); // watermark TRUE ou FALSE
Ayolo's avatar
Ayolo committed
26
27
28

$topdir = "../";

pedrov's avatar
pedrov committed
29
require_once($topdir. "include/site.inc.php");
Ayolo's avatar
Ayolo committed
30
31
32
33
require_once($topdir. "include/pgsqlae.inc.php");
require_once($topdir. "include/cts/imgcarto.inc.php");
require_once ($topdir . "include/watermark.inc.php");

pedrov's avatar
pedrov committed
34
35
$site = new site ();

pedrov's avatar
pedrov committed
36
$img = new imgcarto(800, 10);
Ayolo's avatar
Ayolo committed
37
38
39
$img->addcolor('pblue_dark', 51, 102, 153);
$img->addcolor('pblue', 222, 235, 245);

pedrov's avatar
pedrov committed
40
41
$nbpaliers = 5;

pedrov's avatar
pedrov committed
42
43
44
45
46
47
48
49
50
51
52
53
54
$img->addcolor('l0', 255, 255, 255);
$img->addcolor('l1', 255, 220, 0);
$img->addcolor('l2', 255, 198, 0);
$img->addcolor('l3', 255, 176, 0);
$img->addcolor('l4', 255, 154, 0);
$img->addcolor('l5', 255, 143, 0);
$img->addcolor('l6', 255, 121, 0);
$img->addcolor('l7', 255, 114, 0);
$img->addcolor('l8', 255, 101, 0);
$img->addcolor('l9', 255, 68, 0);
$img->addcolor('l10', 255, 0, 0);


55
56


Ayolo's avatar
Ayolo committed
57
$pgconn = new pgsqlae();
pedrov's avatar
pedrov committed
58

pedrov's avatar
pedrov committed
59

60
61
62
$statscotis = new requete($site->db, "SELECT
                                      COUNT(`id_utilisateur`) AS num
                                      , substring(cpostal_ville,1,2) AS cpostal
Ayolo's avatar
fix 1    
Ayolo committed
63
                                      FROM `utl_etu`
64
                                      INNER JOIN `loc_ville` ON `loc_ville`.`id_ville` = `utl_etu`.`id_ville`
Ayolo's avatar
bleh    
Ayolo committed
65
                                      WHERE `utl_etu`.`id_ville` IS NOT NULL
Ayolo's avatar
fix 1    
Ayolo committed
66
                                      GROUP BY substring(cpostal_ville,1,2)");
67

pedrov's avatar
pedrov committed
68
while ($rs = $statscotis->get_row())
69
{
70
  $statsdep[$rs['cpostal']] = $rs['num'];
71
72
}

pedrov's avatar
pedrov committed
73
$pgreq = new pgrequete($pgconn, "SELECT code_dept, nom_dept, asText(simplify(the_geom, 2000)) AS points FROM deptfr");
74

Ayolo's avatar
Ayolo committed
75
$rs = $pgreq->get_all_rows();
Ayolo's avatar
bleh    
Ayolo committed
76

Ayolo's avatar
Ayolo committed
77
$numdept = 0;
Ayolo's avatar
bleh    
Ayolo committed
78
$dept=array();
79

Ayolo's avatar
Ayolo committed
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
foreach($rs as $result)
{
  $astext = $result['points'];
  $matched = array();
  preg_match_all("/\(([^)]*)\)/", $astext, $matched);
  $i = 0;
  foreach ($matched[1] as $polygon)
  {
    $polygon = str_replace("(", "", $polygon);
    $points = explode(",", $polygon);
    foreach ($points as $point)
    {
      $coord = explode(" ", $point);
      $dept[$numdept]['plgs'][$i][] = $coord[0];
      $dept[$numdept]['plgs'][$i][] = $coord[1];
    }
    $i++;
  }
pedrov's avatar
map    
pedrov committed
98
  $dept[$numdept]['name'] = $result['nom_dept'];
pedrov's avatar
pedrov committed
99
  $dept[$numdept]['iddept'] = $result['code_dept'];
pedrov's avatar
map    
pedrov committed
100

Ayolo's avatar
Ayolo committed
101
102
103
104
105
106
107
  $numdept++;
}

foreach($dept as $departement)
{
  foreach($departement['plgs'] as $plg)
  {
pedrov's avatar
pedrov committed
108
    if ($statsdep[$departement['iddept']] == 0)
109
      $img->addpolygon($plg, 'l0', true,
Ayolo's avatar
fix 1    
Ayolo committed
110
111
112
           array('id' =>$departement['gid'],
           'url' => "javascript:ploufdept(this, ".
           $departement['iddept']. ")"));
Ayolo's avatar
Ayolo committed
113
    else
114
      $img->addpolygon($plg, 'l' . (int) (1 + $statsdep[$departement['iddept']] / 20), true,
Ayolo's avatar
Ayolo committed
115
116
117
                       array('id' =>$departement['gid'],
                             'url' => "javascript:ploufdept(this, ".
                             $departement['iddept']. ")"));
pedrov's avatar
debug    
pedrov committed
118
    $img->addpolygon($plg, 'black', false);
Ayolo's avatar
Ayolo committed
119
120
121
  }
}

pedrov's avatar
pedrov committed
122
123
$img->draw();

pedrov's avatar
pedrov committed
124
125
if ($_REQUEST['generate'] == 1)
{
pedrov's avatar
debug    
pedrov committed
126
127
128
129
130
131
132
133
  if (WATERMARK == TRUE)
    {
      require_once($topdir . 'include/watermark.inc.php');
      $wm_img = new img_watermark ($img->imgres);
      $wm_img->output();
    }
  else
    $img->output();
pedrov's avatar
pedrov committed
134

pedrov's avatar
pedrov committed
135
136
  exit();
}
pedrov's avatar
pedrov committed
137

pedrov's avatar
pedrov committed
138
139
140
141
if (isset($_REQUEST['getinfodepts']))
{
  $cp = mysql_real_escape_string($_REQUEST['getinfodepts']);

Ayolo's avatar
fix    
Ayolo committed
142
  echo "<h1>Ils viennent de ce département (".sprintf("%02d",$cp).") :</h1>";
pedrov's avatar
pedrov committed
143

pedrov's avatar
et hop    
pedrov committed
144
  echo "<center>\n";
Ayolo's avatar
fix    
Ayolo committed
145
  $cp = sprintf('%02d',$cp).'___';
pedrov's avatar
pedrov committed
146

Ayolo's avatar
fix 1    
Ayolo committed
147
  $req = new requete($site->db, "SELECT `utilisateurs`.`id_utilisateur`
pedrov's avatar
pedrov committed
148
                                        , `utilisateurs`.`prenom_utl`
pedrov's avatar
pedrov committed
149
                                        , `utilisateurs`.`nom_utl`
pedrov's avatar
pedrov committed
150
                                        , `utl_etu_utbm`.`surnom_utbm`
Ayolo's avatar
fix 1    
Ayolo committed
151
152
153
154
155
                                 FROM `utilisateurs`
                                 INNER JOIN `utl_etu` ON `utl_etu`.`id_utilisateur` = `utilisateurs`.`id_utilisateur`
                                 INNER JOIN `utl_etu_utbm` ON `utl_etu_utbm`.`id_utilisateur` = `utilisateurs`.`id_utilisateur`
                                 INNER JOIN `loc_ville` ON `loc_ville`.`id_ville` = `utl_etu`.`id_ville`
                                 WHERE `loc_ville`.`cpostal_ville` LIKE '".$cp."'
156
                                 AND   `publique_utl` = '2'
157
                                 ORDER BY RAND()
pedrov's avatar
et hop    
pedrov committed
158
                                 LIMIT 10");
pedrov's avatar
pedrov committed
159
160
161
162


  if ($req->lines <= 0)
    {
pedrov's avatar
pedrov committed
163
164
      echo "<p><b>Apparemment, personne ;-(</b></p>";
      exit();
pedrov's avatar
pedrov committed
165
    }
pedrov's avatar
pedrov committed
166
  require_once($topdir . "include/cts/sqltable.inc.php");
167
168

  $sqlt = new sqltable('userslst',
Ayolo's avatar
fix 1    
Ayolo committed
169
170
171
                       'Liste des utilisateurs',
                       $req,
                       '../user.php',
172
                       'id_utilisateur',
Ayolo's avatar
fix 1    
Ayolo committed
173
                       array('prenom_utl' => 'prenom', 'nom_utl' => 'nom', 'surnom_utbm' => 'surnom'),
174
175
                       array('view' => 'Voir la fiche'),
                       array(),
Ayolo's avatar
fix 1    
Ayolo committed
176
                       array());
pedrov's avatar
pedrov committed
177
178

  echo $sqlt->html_render();
pedrov's avatar
et hop    
pedrov committed
179
  echo "</center>";
pedrov's avatar
pedrov committed
180
181
182

  exit();
}
pedrov's avatar
pedrov committed
183
184
185
186

$site = new site ();
$site->start_page("services","Carte de France de l'AE");

pedrov's avatar
et hop    
pedrov committed
187
188
189
190
191
192
193
194
195
/*cts 1 : liste des gens */
$cts = new contents("", "");

$cts->add_paragraph("<script language=\"javascript\">
document.getElementById('cts1').style.display = 'none';
</script>\n");

$site->add_contents($cts);

196
/* cts 2 : la carte de France */
pedrov's avatar
pedrov committed
197
198
$cts = new contents("La carte de France de l'AE", "");

pedrov's avatar
pedrov committed
199
$cts->add_paragraph("<script language=\"javascript\">
pedrov's avatar
pedrov committed
200
function ploufdept(obj, id)
pedrov's avatar
map    
pedrov committed
201
  {
pedrov's avatar
et hop    
pedrov committed
202
203
    openInContents('cts1', './mapfrance.php', 'getinfodepts='+id);
    document.getElementById('cts1').style.display = 'block';
pedrov's avatar
map    
pedrov committed
204
  }
pedrov's avatar
et hop    
pedrov committed
205
</script>\n");
pedrov's avatar
pedrov committed
206
207
208
209


$cts->add_paragraph($img->map_area("carte_de_france"));

pedrov's avatar
pedrov committed
210
$cts->add_paragraph("<center><img class=\"cartefr\" src=\"mapfrance.php?generate=1\" alt=\"plouf\" usemap=\"#carte_de_france\" /></center>\n");
pedrov's avatar
pedrov committed
211
212

$site->add_contents($cts);
pedrov's avatar
map    
pedrov committed
213

pedrov's avatar
pedrov committed
214
$site->end_page();
Ayolo's avatar
fix    
Ayolo committed
215

Ayolo's avatar
Ayolo committed
216
?>