From 2b105fb604b57ce6534783c4ad083827230ea93d Mon Sep 17 00:00:00 2001 From: x2001corpet Date: Fri, 16 Jun 2006 06:32:04 +0000 Subject: [PATCH] geoloc sur xnet git-svn-id: svn+ssh://murphy/home/svn/platal/trunk@317 839d8a87-29fc-0310-9880-83ba4fa771e5 --- ChangeLog | 3 +- htdocs.net/groupe/dynamap.php | 42 +++++++++++++ htdocs.net/groupe/geoloc.php | 34 +++++++++++ htdocs.net/groupe/geolocInit.php | 28 +++++++++ htdocs.net/groupe/getCityInfos.php | 56 +++++++++++++++++ htdocs.net/groupe/getData.php | 54 +++++++++++++++++ htdocs.net/groupe/icon.php | 32 ++++++++++ htdocs/geoloc/getData.php | 121 ++----------------------------------- include/geoloc.inc.php | 118 +++++++++++++++++++++++++++++++++++- include/search.inc.php | 7 +-- include/xnet/page.inc.php | 7 ++- templates/geoloc/index.tpl | 46 ++++++++------ 12 files changed, 405 insertions(+), 143 deletions(-) create mode 100644 htdocs.net/groupe/dynamap.php create mode 100644 htdocs.net/groupe/geoloc.php create mode 100644 htdocs.net/groupe/geolocInit.php create mode 100644 htdocs.net/groupe/getCityInfos.php create mode 100644 htdocs.net/groupe/getData.php create mode 100644 htdocs.net/groupe/icon.php diff --git a/ChangeLog b/ChangeLog index 4ec746e..8b41967 100644 --- a/ChangeLog +++ b/ChangeLog @@ -22,8 +22,9 @@ New : - Add a quick search form in this common header. -Car * Xnet : - - Use wiki from Xnet. -Car + - Use wiki from Xorg. -Car - Use wiki for group pages. -Car + - Dynamic maps using geodesix plugin. -Car Bug/Wish : diff --git a/htdocs.net/groupe/dynamap.php b/htdocs.net/groupe/dynamap.php new file mode 100644 index 0000000..ed7b7db --- /dev/null +++ b/htdocs.net/groupe/dynamap.php @@ -0,0 +1,42 @@ + $a) + if ($v != 'initfile') + $querystring .= '&'.urlencode($v).'='.urlencode($a); +$initfile = urlencode('geolocInit.php?'.$querystring); + +if (urlencode(Env::get('initfile')) != $initfile) +{ + header("Location: dynamap.php?initfile=$initfile{$querystring}"); + die(); +} + +header("Content-type: application/x-shockwave-flash"); + +if ($globals->geoloc->use_map()) + readfile($globals->geoloc->dynamap_path); + +?> diff --git a/htdocs.net/groupe/geoloc.php b/htdocs.net/groupe/geoloc.php new file mode 100644 index 0000000..ecbb45e --- /dev/null +++ b/htdocs.net/groupe/geoloc.php @@ -0,0 +1,34 @@ +asso('pub') == 'public') + new_group_page('geoloc/index.tpl'); +else + new_groupadmin_page('geoloc/index.tpl'); + +$page->assign('use_map', $globals->geoloc->use_map()); +$page->assign('no_annu', true); +$page->assign('dynamap_vars', 'none'); +$page->run(); + +?> \ No newline at end of file diff --git a/htdocs.net/groupe/geolocInit.php b/htdocs.net/groupe/geolocInit.php new file mode 100644 index 0000000..e9ce723 --- /dev/null +++ b/htdocs.net/groupe/geolocInit.php @@ -0,0 +1,28 @@ +run(); +?> diff --git a/htdocs.net/groupe/getCityInfos.php b/htdocs.net/groupe/getCityInfos.php new file mode 100644 index 0000000..80d8032 --- /dev/null +++ b/htdocs.net/groupe/getCityInfos.php @@ -0,0 +1,56 @@ +asso('id'); +$_REQUEST['only_current'] = 1; +$assoField = new RefSField('asso_id',array('gxm.asso_id'),'groupex.membres','gxm','u.user_id=gxm.uid'); +$cityIdField = new RefSField('cityid',array('av.cityid'),'adresses','av',getadr_join('av')); + +$fields = new SFieldGroup(true, array($assoField, $cityIdField)); +$where = $fields->get_where_statement(); +if ($where) $where = "WHERE ".$where; + +$users = $globals->xdb->iterator(" + SELECT u.user_id AS id, u.prenom, u.nom, u.promo + FROM adresses AS a +INNER JOIN auth_user_md5 AS u ON(u.user_id = a.uid) +INNER JOIN auth_user_quick AS q ON(q.user_id = a.uid) + ".$fields->get_select_statement()." + ".$where." + GROUP BY u.user_id LIMIT 11", + $id); + +if ($globals->asso('pub') == 'public' || has_perms()) + $page->assign('users', $users); + +$page->run(); +// vim:set et sw=4 sts=4 sws=4 foldmethod=marker: +?> diff --git a/htdocs.net/groupe/getData.php b/htdocs.net/groupe/getData.php new file mode 100644 index 0000000..28701ab --- /dev/null +++ b/htdocs.net/groupe/getData.php @@ -0,0 +1,54 @@ +asso('pub') != 'public') && !has_perms(); + +header("Content-type: text/xml"); + +require_once('geoloc.inc.php'); +require_once('search.inc.php'); + +$querystring = ""; +foreach ($_GET as $v => $a) + if ($v != 'mapid') + $querystring .= urlencode($v).'='.urlencode($a).'&'; +$page->assign('searchvars', $querystring); +if (Env::has('mapid')) + $mapid = Env::getInt('mapid', -2); +else + $mapid = false; + +$_REQUEST['asso_id'] = $globals->asso('id'); +$_REQUEST['only_current'] = 1; +$assoField = new RefSField('asso_id',array('gxm.asso_id'),'groupex.membres','gxm','u.user_id=gxm.uid'); + +if (!$nodata) { + list($countries, $cities) = geoloc_getData_subcountries($mapid, array($assoField), 10); + $page->assign('countries', $countries); + $page->assign('cities', $cities); +} + +$page->run(); +// vim:set et sw=4 sts=4 sws=4 foldmethod=marker: +?> diff --git a/htdocs.net/groupe/icon.php b/htdocs.net/groupe/icon.php new file mode 100644 index 0000000..9fcd601 --- /dev/null +++ b/htdocs.net/groupe/icon.php @@ -0,0 +1,32 @@ +geoloc->use_map()) + readfile($globals->geoloc->icon_path); + +?> diff --git a/htdocs/geoloc/getData.php b/htdocs/geoloc/getData.php index 61b6f9c..d358631 100644 --- a/htdocs/geoloc/getData.php +++ b/htdocs/geoloc/getData.php @@ -1,6 +1,6 @@ $field) if ($field->fieldFormName == 'mapid') break; +require_once('search.inc.php'); $querystring = ""; foreach ($_GET as $v => $a) if ($v != 'mapid') $querystring .= urlencode($v).'='.urlencode($a).'&'; $page->assign('searchvars', $querystring); - -$maxentities = 100; -$minentities = 5; - -function get_cities_in_territory($t, $usual_fields, $direct=true) -{ - global $cities, $globals, $i_mapfield; - $usual_fields[$i_mapfield] = new MapSField('mapid', array('gcim.map_id'), array('adresses','geoloc_city_in_maps'), array('am','gcim'), array(getadr_join('am'), 'am.cityid = gcim.city_id'), $t); - $fields = new SFieldGroup(true, $usual_fields); - $where = $fields->get_where_statement(); - if ($where) $where = " AND ".$where; - $cityres = $globals->xdb->iterator(" - SELECT gc.id, - gc.lon / 100000 AS x, gc.lat/100000 AS y, - gc.name, - COUNT(u.user_id) AS pop, - SUM(u.promo % 2) AS yellow - FROM auth_user_md5 AS u - INNER JOIN auth_user_quick AS q ON(u.user_id = q.user_id) - ".$fields->get_select_statement()." - LEFT JOIN geoloc_city AS gc ON(gcim.city_id = gc.id) - WHERE ".($direct?"gcim.infos = 'smallest'":"1")." - $where - GROUP BY gc.id,gc.alias ORDER BY pop DESC"); - while ($c = $cityres->next()) - if ($c['pop'] > 0) - { - $city = $c; - $city['x'] = geoloc_to_x($c['x'], $c['y']); - $city['y'] = geoloc_to_y($c['x'], $c['y']); - $city['size'] = size_of_city($c['pop']); - $cities[$c['id']] = $city; - } -} - if (Env::has('mapid')) - $wheremapid = "WHERE gm.parent = {?}"; + $mapid = Env::getInt('mapid', -2); else - $wheremapid = "WHERE gm.parent IS NULL"; - -$submapres = $globals->xdb->iterator( - "SELECT gm.map_id AS id, gm.name, gm.x, gm.y, gm.xclip, gm.yclip, - gm.width, gm.height, gm.scale, 1 AS rat - FROM geoloc_maps AS gm - ".$wheremapid, Env::get('mapid','')); - -$countries = array(); -while ($c = $submapres->next()) -{ - $country = $c; - $country['name'] = utf8_decode($country['name']); - $country['color'] = 0xFFFFFF; - $country['swf'] = $globals->geoloc->webservice_url."maps/mercator/map_".$c['id'].".swf"; - $countries[$c['id']] = $country; -} - -$cities = array(); -if (Env::has('mapid')) -{ - get_cities_in_territory(Env::getInt('mapid'), $usual_fields); - $nbcities = count($cities); - $nocity = $nbcities == 0; - - $usual_fields[$i_mapfield] = new MapSField('mapid', array('map.parent'), array('adresses','geoloc_city_in_maps','geoloc_maps'), array('am','gcim','map'), array(getadr_join('am'), 'am.cityid = gcim.city_id', 'map.map_id = gcim.map_id')); - $fields = new SFieldGroup(true, $usual_fields); - $where = $fields->get_where_statement(); - if ($where) $where = " WHERE ".$where; - - $countryres = $globals->xdb->iterator(" - SELECT map.map_id AS id, - COUNT(u.user_id) AS nbPop, - SUM(u.promo % 2) AS yellow, - COUNT(DISTINCT gcim.city_id) AS nbCities, - SUM(IF(u.user_id IS NULL,0,am.glng)) AS lonPop, - SUM(IF(u.user_id IS NULL, 0,am.glat)) AS latPop - FROM auth_user_md5 AS u - INNER JOIN auth_user_quick AS q ON(u.user_id = q.user_id) - ".$fields->get_select_statement()." - $where - GROUP BY map.map_id ORDER BY NULL", $hierarchy); - - $maxpop = 0; - $nbentities = $nbcities + $countryres->total(); - while ($c = $countryres->next()) - { - $c['latPop'] /= $c['nbPop']; - $c['lonPop'] /= $c['nbPop']; - $c['rad'] = size_of_territory($c['nbPop']); - if ($maxpop < $c['nbPop']) $maxpop = $c['nbPop']; - $c['xPop'] = geoloc_to_x($c['lonPop'], $c['latPop']); - $c['yPop'] = geoloc_to_y($c['lonPop'], $c['latPop']); - $countries[$c['id']] = array_merge($countries[$c['id']], $c); - - $nbcities += $c['nbCities']; - } - - if ($nocity && $nbcities < 10) - { - foreach($countries as $i => $c) - { - $countries[$i]['nbPop'] = 0; - if ($c['nbCities'] > 0) - get_cities_in_territory($c['id'], $usual_fields, false); - } - } - - foreach ($countries as $i => $c) if ($c['nbPop'] > 0) - { - $lambda = pow($c['nbPop'] / $maxpop,0.3); - $countries[$i]['color'] = 0x0000FF + round((1-$lambda) * 0xFF)*0x010100; - } -} + $mapid = false; + +list($countries, $cities) = geoloc_getData_subcountries($mapid, advancedSearchFromInput(), 10); $page->assign('countries', $countries); $page->assign('cities', $cities); diff --git a/include/geoloc.inc.php b/include/geoloc.inc.php index 3ef6611..43ed1f1 100644 --- a/include/geoloc.inc.php +++ b/include/geoloc.inc.php @@ -1,6 +1,6 @@ fieldFormName == 'mapid') break; + $SFields[$i_mapfield] = new MapSField('mapid', array('gcim.map_id'), array('adresses','geoloc_city_in_maps'), array('am','gcim'), array(getadr_join('am'), 'am.cityid = gcim.city_id'), $mapid); + + $fields = new SFieldGroup(true, $SFields); + $where = $fields->get_where_statement(); + if ($where) $where = " AND ".$where; + + $cityres = $globals->xdb->iterator(" + SELECT gc.id, + gc.lon / 100000 AS x, gc.lat/100000 AS y, + gc.name, + COUNT(u.user_id) AS pop, + SUM(u.promo % 2) AS yellow + FROM auth_user_md5 AS u + INNER JOIN auth_user_quick AS q ON(u.user_id = q.user_id) + ".$fields->get_select_statement()." + LEFT JOIN geoloc_city AS gc ON(gcim.city_id = gc.id) + WHERE ".($direct?"gcim.infos = 'smallest'":"1")." + $where + GROUP BY gc.id,gc.alias ORDER BY pop DESC"); + while ($c = $cityres->next()) + if ($c['pop'] > 0) + { + $city = $c; + $city['x'] = geoloc_to_x($c['x'], $c['y']); + $city['y'] = geoloc_to_y($c['x'], $c['y']); + $city['size'] = size_of_city($c['pop']); + $cities[$c['id']] = $city; + } +} + +function geoloc_getData_subcountries($mapid, $SFields, $minentities) { + global $globals; + $countries = array(); + $cities = array(); + + if ($mapid === false) + $wheremapid = "WHERE gm.parent IS NULL"; + else + $wheremapid = "WHERE gm.parent = {?}"; + $submapres = $globals->xdb->iterator( + "SELECT gm.map_id AS id, gm.name, gm.x, gm.y, gm.xclip, gm.yclip, + gm.width, gm.height, gm.scale, 1 AS rat + FROM geoloc_maps AS gm + ".$wheremapid, Env::get('mapid','')); + + while ($c = $submapres->next()) + { + $country = $c; + $country['name'] = utf8_decode($country['name']); + $country['color'] = 0xFFFFFF; + $country['swf'] = $globals->geoloc->webservice_url."maps/mercator/map_".$c['id'].".swf"; + $countries[$c['id']] = $country; + } + + if ($mapid === false) return array($countries, $cities); + + geoloc_getData_subcities(Env::getInt('mapid'), $SFields, $cities); + $nbcities = count($cities); + $nocity = $nbcities == 0; + + for ($i_mapfield=0; $i_mapfield < count($SFields) ; $i_mapfield++) if ($SFields[$i_mapfield]->fieldFormName == 'mapid') break; + $SFields[$i_mapfield] = new MapSField('mapid', array('map.parent'), array('adresses','geoloc_city_in_maps','geoloc_maps'), array('am','gcim','map'), array(getadr_join('am'), 'am.cityid = gcim.city_id', 'map.map_id = gcim.map_id')); + + $fields = new SFieldGroup(true, $SFields); + $where = $fields->get_where_statement(); + if ($where) $where = " WHERE ".$where; + + $countryres = $globals->xdb->iterator(" + SELECT map.map_id AS id, + COUNT(u.user_id) AS nbPop, + SUM(u.promo % 2) AS yellow, + COUNT(DISTINCT gcim.city_id) AS nbCities, + SUM(IF(u.user_id IS NULL,0,am.glng)) AS lonPop, + SUM(IF(u.user_id IS NULL, 0,am.glat)) AS latPop + FROM auth_user_md5 AS u + INNER JOIN auth_user_quick AS q ON(u.user_id = q.user_id) + ".$fields->get_select_statement()." + $where + GROUP BY map.map_id ORDER BY NULL", $hierarchy); + + $maxpop = 0; + $nbentities = $nbcities + $countryres->total(); + while ($c = $countryres->next()) + { + $c['latPop'] /= $c['nbPop']; + $c['lonPop'] /= $c['nbPop']; + $c['rad'] = size_of_territory($c['nbPop']); + if ($maxpop < $c['nbPop']) $maxpop = $c['nbPop']; + $c['xPop'] = geoloc_to_x($c['lonPop'], $c['latPop']); + $c['yPop'] = geoloc_to_y($c['lonPop'], $c['latPop']); + $countries[$c['id']] = array_merge($countries[$c['id']], $c); + + $nbcities += $c['nbCities']; + } + + if ($nocity && $nbcities < $minentities) + { + foreach($countries as $i => $c) + { + $countries[$i]['nbPop'] = 0; + if ($c['nbCities'] > 0) + geoloc_getData_subcities($c['id'], $SFields, $cities, false); + } + } + + foreach ($countries as $i => $c) if ($c['nbPop'] > 0) + { + $lambda = pow($c['nbPop'] / $maxpop,0.3); + $countries[$i]['color'] = 0x0000FF + round((1-$lambda) * 0xFF)*0x010100; + } + + return array($countries, $cities); +} // vim:set et sw=4 sts=4 sws=4 foldmethod=marker: ?> diff --git a/include/search.inc.php b/include/search.inc.php index a337031..179e9c1 100644 --- a/include/search.inc.php +++ b/include/search.inc.php @@ -23,6 +23,9 @@ require_once('xorg.plugin.inc.php'); require_once("search/classes.inc.php"); // {{{ function advancedSearchFromInput +function getadr_join($table) { + return 'u.user_id='.$table.'.uid'.(Env::get('only_current',false)?' AND FIND_IN_SET(\'active\','.$table.'.statut)':''); +} function advancedSearchFromInput() { if ($with_soundex = Env::has('with_soundex')) { @@ -40,10 +43,6 @@ function advancedSearchFromInput() $subscriberField = new RefSField('subscriber',array('!(u.perms IN (\'admin\',\'user\'))+1'),'','',''); $aliveField = new RefSField('alive',array('(u.deces!=0)+1'),'','',''); - function getadr_join($table) { - return 'u.user_id='.$table.'.uid'.(Env::get('only_current',false)?' AND FIND_IN_SET(\'active\','.$table.'.statut)':''); - } - $townField = new RefSField('city',array('ac.city'),'adresses','ac',getadr_join('ac'),false); $cityIdField = new RefSField('cityid',array('av.cityid'),'adresses','av',getadr_join('av')); $countryField = new RefSField('country',array('ap.country'),'adresses','ap',getadr_join('ap')); diff --git a/include/xnet/page.inc.php b/include/xnet/page.inc.php index 6fd7c7a..261da94 100644 --- a/include/xnet/page.inc.php +++ b/include/xnet/page.inc.php @@ -1,6 +1,6 @@ asso('diminutif'); $sub['présentation'] = "$dim/asso.php"; - if (may_update() || $globals->asso('pub') == 'public') + if (may_update() || $globals->asso('pub') == 'public') { $sub['annuaire du groupe'] = "$dim/annuaire.php"; + if ($globals->xnet->geoloc) + $sub['carte'] = "$dim/geoloc.php"; + } if ($globals->asso('mail_domain')) { $sub['listes de diffusion'] = "$dim/listes.php"; } diff --git a/templates/geoloc/index.tpl b/templates/geoloc/index.tpl index 524d589..2194487 100644 --- a/templates/geoloc/index.tpl +++ b/templates/geoloc/index.tpl @@ -28,6 +28,9 @@ function ficheXorg(id) { window.open('../fiche.php?user='+id,'_blank','toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width=840,height=600'); } +{/literal} +{if !$no_annu} +{literal} function clickOnCity(id) { var f = document.getElementById('search_form'); @@ -51,31 +54,34 @@ function searchMapId(f) document.getElementById('search_results').style.height = '250px'; } {/literal} +{/if} -{if !$dynamap_vars} -

-Aujourd'hui {$localises} de nos camarades sont localisés grâce à leurs adresses personnelles. -

+{if !$dynamap_vars and $localises} +

+ Aujourd'hui {$localises} de nos camarades sont localisés grâce à leurs adresses personnelles. +

{/if} {if $use_map} -

- - - - - - - -

Carte fournie gracieusement par Geodesix.

-

-
-

- -

-
+

+ + + + + + + +

+

Carte fournie gracieusement par Geodesix.

+ {if !$no_annu} +
+

+ +

+
+ {/if} {else} -

Le moteur de carte n'a pas été installé sur cette version de plat/al. Veuillez contacter Geodesix.

+

Le moteur de carte n'a pas été installé sur cette version de plat/al. Veuillez contacter Geodesix.

{/if}

Pour toute question, problème ou suggestion tu peux envoyer un mail à contact+geoloc@polytechnique.org

-- 2.1.4