From 56670b6ac6b3337d615679ec756446a05e18f113 Mon Sep 17 00:00:00 2001 From: x2001corpet Date: Sat, 3 Jun 2006 09:37:56 +0000 Subject: [PATCH] la carte geoloc git-svn-id: svn+ssh://murphy/home/svn/platal/trunk@283 839d8a87-29fc-0310-9880-83ba4fa771e5 --- hooks/geoloc.inc.php | 42 ++++++++ htdocs/admin/geoloc_dynamap.php | 46 +++++++++ htdocs/advanced_search.php | 61 +++--------- htdocs/geoloc/{globe.php => dynamap.php} | 28 +++--- htdocs/geoloc/geolocInit.php | 13 +++ htdocs/geoloc/getCityInfos.php | 53 ++++++++++ htdocs/geoloc/getData.php | 163 +++++++++++++++++++++++++++++++ htdocs/geoloc/icon.php | 31 ++++++ htdocs/geoloc/index.php | 8 ++ include/geoloc.inc.php | 94 +++++++++++++++++- include/search.inc.php | 54 ++++++++++ include/search/classes.inc.php | 31 ++++++ templates/admin/geoloc_dynamap.tpl | 49 ++++++++++ templates/geoloc/geolocInit.tpl | 43 ++++++++ templates/geoloc/getCityInfos.tpl | 27 +++++ templates/geoloc/getData.tpl | 47 +++++++++ templates/geoloc/index.tpl | 60 +++++++++--- templates/search.adv.form.tpl | 31 ++++-- templates/search.tpl | 16 ++- upgrade/0.9.10/00_geoloc.sql | 24 +++++ upgrade/0.9.10/update.sh | 32 ++++++ 21 files changed, 861 insertions(+), 92 deletions(-) create mode 100644 hooks/geoloc.inc.php create mode 100644 htdocs/admin/geoloc_dynamap.php rename htdocs/geoloc/{globe.php => dynamap.php} (71%) create mode 100644 htdocs/geoloc/geolocInit.php create mode 100644 htdocs/geoloc/getCityInfos.php create mode 100644 htdocs/geoloc/getData.php create mode 100644 htdocs/geoloc/icon.php create mode 100644 templates/admin/geoloc_dynamap.tpl create mode 100644 templates/geoloc/geolocInit.tpl create mode 100644 templates/geoloc/getCityInfos.tpl create mode 100644 templates/geoloc/getData.tpl create mode 100644 upgrade/0.9.10/00_geoloc.sql create mode 100755 upgrade/0.9.10/update.sh diff --git a/hooks/geoloc.inc.php b/hooks/geoloc.inc.php new file mode 100644 index 0000000..0165c29 --- /dev/null +++ b/hooks/geoloc.inc.php @@ -0,0 +1,42 @@ +geoloc = new GeolocConfig; +} + +// }}} + +// vim:set et sw=4 sts=4 sws=4 foldmethod=marker: +?> diff --git a/htdocs/admin/geoloc_dynamap.php b/htdocs/admin/geoloc_dynamap.php new file mode 100644 index 0000000..53dd692 --- /dev/null +++ b/htdocs/admin/geoloc_dynamap.php @@ -0,0 +1,46 @@ +trig("Impossible d'accéder au webservice"); +} + +if (Env::has('new_maps')) +{ + require_once('geoloc.inc.php'); + if (!get_new_maps(Env::get('url'))) + $page->trig("Impossible d'accéder aux nouvelles cartes"); +} + +$countMissing = $globals->xdb->query("SELECT COUNT(*) FROM geoloc_city AS c LEFT JOIN geoloc_city_in_maps AS m ON(c.id = m.city_id) WHERE m.city_id IS NULL"); +$page->assign("nb_cities_not_on_map", $countMissing->fetchOneCell()); + +$page->run(); + +// vim:set et sws=4 sts=4 sw=4: +?> + diff --git a/htdocs/advanced_search.php b/htdocs/advanced_search.php index 9832e54..a935b64 100644 --- a/htdocs/advanced_search.php +++ b/htdocs/advanced_search.php @@ -21,8 +21,10 @@ require_once("xorg.inc.php"); require_once('search.inc.php'); -new_skinned_page('search.tpl', AUTH_COOKIE); - +if (Env::get('display')!='mini') + new_skinned_page('search.tpl', AUTH_COOKIE); +else + new_simple_page('search.tpl', AUTH_COOKIE); $page->assign('advanced',1); $page->assign('public_directory',0); require_once("applis.func.inc.php"); @@ -64,59 +66,18 @@ if (!Env::has('rechercher')) { form_prepare(); } else { - // {{{ function get_list() +// {{{ function get_list() function get_list($offset, $limit, $order) { - if ($with_soundex = Env::has('with_soundex')) { - $nameField = new RefWithSoundexSField('name',array('rn.nom1_soundex','rn.nom2_soundex','rn.nom3_soundex'),'recherche_soundex','rn','u.matricule = rn.matricule'); - $firstnameField = new RefWithSoundexSField('firstname',array('rp.prenom1_soundex','rp.prenom2_soundex'),'recherche_soundex','rp','u.matricule = rp.matricule'); - } else { - $nameField = new NameSField('name',array('u.nom','u.nom_usage'),''); - $firstnameField = new StringSField('firstname',array('u.prenom'),''); - } - $nicknameField = new StringSField('nickname',array('q.profile_nick'),''); - - $promo1Field = new PromoSField('promo1','egal1',array('u.promo'),''); - $promo2Field = new PromoSField('promo2','egal2',array('u.promo'),''); - $womanField = new RefSField('woman',array('FIND_IN_SET(u.flags,\'femme\')+1'),'','',''); - $subscriberField = new RefSField('subscriber',array('!(u.perms IN (\'admin\',\'user\'))+1'),'','',''); - $aliveField = new RefSField('alive',array('(u.deces!=0)+1'),'','',''); - - $townField = new RefSField('city',array('av.city'),'adresses','av','u.user_id=av.uid',false); - $countryField = new RefSField('country',array('ap.country'),'adresses','ap','u.user_id=ap.uid'); - $regionField = new RefSField('region',array('ar.region'),'adresses','ar','u.user_id=ar.uid'); - - $entrepriseField = new RefSField('entreprise',array('ee.entreprise'),'entreprises','ee','u.user_id=ee.uid',false); - $posteField = new RefSField('poste',array('ep.poste'),'entreprises','ep','u.user_id=ep.uid', false); - $fonctionField = new RefSField('fonction',array('en.fonction'),'entreprises','en','u.user_id=en.uid'); - $secteurField = new RefSField('secteur',array('fm.secteur'),'entreprises','fm','u.user_id=fm.uid'); - $cvField = new RefSField('cv',array('u.cv'),'','','',false); - - $natField = new RefSField('nationalite',array('u.nationalite'),'','',''); - $binetField = new RefSField('binet',array('b.binet_id'),'binets_ins','b','u.user_id=b.user_id'); - $groupexField = new RefSField('groupex',array('g.gid'),'groupesx_ins','g','u.user_id=g.guid'); - $sectionField = new RefSField('section',array('u.section'),'','',''); - $schoolField = new RefSField('school',array('as.aid'),'applis_ins','`as`','u.user_id=as.uid'); - $diplomaField = new RefSField('diploma',array('ad.type'),'applis_ins','ad','u.user_id=ad.uid'); - - $freeField = new RefSField('free',array('q.profile_freetext'),'','','',false); - - $fields = new SFieldGroup(true, array( - $nameField, $firstnameField, $nicknameField, $promo1Field, - $promo2Field, $womanField, $subscriberField, $aliveField, - $townField, $countryField, $regionField, $entrepriseField, - $posteField, $secteurField, $cvField, $natField, $binetField, - $groupexField, $sectionField, $schoolField, $diplomaField, - $freeField, $fonctionField) - ); - - + $fields = new SFieldGroup(true, advancedSearchFromInput()); if ($fields->too_large()) { form_prepare(); new ThrowError('Recherche trop générale.'); } - global $globals; - + global $globals, $page; + + $page->assign('search_vars', $fields->get_url()); + $where = $fields->get_where_statement(); if ($where) { $where = "WHERE $where"; @@ -144,7 +105,7 @@ if (!Env::has('rechercher')) { return Array($liste, $nb_tot); } - // }}} +// }}} $search = new XOrgSearch('get_list'); $search->setNbLines($globals->search->per_page); diff --git a/htdocs/geoloc/globe.php b/htdocs/geoloc/dynamap.php similarity index 71% rename from htdocs/geoloc/globe.php rename to htdocs/geoloc/dynamap.php index a8b32d0..1d3ecc5 100644 --- a/htdocs/geoloc/globe.php +++ b/htdocs/geoloc/dynamap.php @@ -1,6 +1,6 @@ xdb->iterRow('SELECT lat, lon FROM geoloc_city AS gc LEFT JOIN adresses AS a ON(gc.id = a.cityid) WHERE a.cityid IS NOT NULL GROUP BY gc.id'); +$querystring = ""; +foreach ($_GET as $v => $a) + if ($v != 'initfile') + $querystring .= '&'.urlencode($v).'='.urlencode($a); +$initfile = urlencode('geolocInit.php?'.$querystring); -$img = imageCreateFromPng("../images/globe.png"); +if (urlencode(Env::get('initfile')) != $initfile) +{ + header("Location: dynamap.php?initfile=$initfile{$querystring}"); + die(); +} -$coul = imagecolorallocate($img, 0, 0, 0); +header("Content-type: application/x-shockwave-flash"); -while ($a = $res->next()) { - $x = floor(($a[1]/100000 + 180 )/360*600); - $y = floor((90 - $a[0]/100000)/180*300); - imagefilledrectangle($img, $x, $y, $x+1, $y+1, $coul); -} +readfile("../../plugins/geoloc/dynamap.swf"); -imagePng($img); -imagedestroy($img); -// vim:set et sws=4 sw=4 sts=4: ?> diff --git a/htdocs/geoloc/geolocInit.php b/htdocs/geoloc/geolocInit.php new file mode 100644 index 0000000..6ecc2ca --- /dev/null +++ b/htdocs/geoloc/geolocInit.php @@ -0,0 +1,13 @@ + $a) + if ($v != 'initfile') + $querystring .= '&'.urlencode($v).'='.urlencode($a); +$page->assign('querystring',$querystring); +$page->run(); +?> diff --git a/htdocs/geoloc/getCityInfos.php b/htdocs/geoloc/getCityInfos.php new file mode 100644 index 0000000..45fbf0b --- /dev/null +++ b/htdocs/geoloc/getCityInfos.php @@ -0,0 +1,53 @@ +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); + +$page->assign('users', $users); + +$page->run(); +// vim:set et sw=4 sts=4 sws=4 foldmethod=marker: +?> diff --git a/htdocs/geoloc/getData.php b/htdocs/geoloc/getData.php new file mode 100644 index 0000000..61b6f9c --- /dev/null +++ b/htdocs/geoloc/getData.php @@ -0,0 +1,163 @@ + $field) if ($field->fieldFormName == 'mapid') break; + +$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 = {?}"; +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; + } +} + +$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/geoloc/icon.php b/htdocs/geoloc/icon.php new file mode 100644 index 0000000..7482ffc --- /dev/null +++ b/htdocs/geoloc/icon.php @@ -0,0 +1,31 @@ + diff --git a/htdocs/geoloc/index.php b/htdocs/geoloc/index.php index ad1da96..5b3d7b5 100644 --- a/htdocs/geoloc/index.php +++ b/htdocs/geoloc/index.php @@ -25,6 +25,14 @@ new_skinned_page('geoloc/index.tpl', AUTH_COOKIE); $res = $globals->xdb->query('SELECT COUNT(DISTINCT uid) FROM adresses WHERE cityid IS NOT NULL'); $page->assign('localises', $res->fetchOneCell()); + require_once('search.inc.php'); +$fields = new SFieldGroup(true, advancedSearchFromInput()); +$search = $fields->get_url().'&'; +if (Env::has('only_current') && Env::get('only_current') != 'on') $search .= '&only_current='; +$search = preg_replace('/(^|&)mapid=([0-9]+)(&|$)/','\1\3', $search); +if ($search) + $page->assign('dynamap_vars', $search); + $page->run(); // vim:set et sws=4 sw=4 sts=4: diff --git a/include/geoloc.inc.php b/include/geoloc.inc.php index d77668a..3ef6611 100644 --- a/include/geoloc.inc.php +++ b/include/geoloc.inc.php @@ -73,13 +73,13 @@ $GLOBALS['page']->register_function('geoloc_region', '_geoloc_region_smarty'); * @param $txt the raw text of an address */ function get_address_infos($txt) { - $url ="http://www.geoloc.org/adressparser/address.php?txt=".urlencode(utf8_encode($txt)); + global $globals; + $url = $globals->geoloc->webservice_url."address.php?txt=".urlencode(utf8_encode($txt)."&precise=1"); if (!($f = @fopen($url, 'r'))) return false; $keys = explode('|',fgets($f)); $vals = explode('|',fgets($f)); $infos = array(); foreach ($keys as $i=>$key) if($vals[$i]) $infos[$key] = ($key == 'sql')?$vals[$i]:utf8_decode(strtr($vals[$i], array(chr(197).chr(147) => "œ"))); - global $globals; if ($infos['sql']) $globals->xdb->execute("REPLACE INTO geoloc_city VALUES ".$infos['sql']); if ($infos['display']) @@ -88,6 +88,44 @@ function get_address_infos($txt) { } // }}} +// {{{ get_cities_maps($array) +/* get all the maps id of the cities contained in an array */ +function get_cities_maps($array) +{ + global $globals; + implode("\n",$array); + $url = $globals->geoloc->webservice_url."findMaps.php?datatext=".urlencode(utf8_encode(implode("\n", $array))); + if (!($f = @fopen($url, 'r'))) return false; + $maps = array(); + while (!feof($f)) + { + $l = trim(fgets($f)); + $tab = explode(';', $l); + $i = $tab[0]; + unset($tab[0]); + $maps[$i] = $tab; + } + return $maps; +} +// }}} + +// {{{ get_new_maps($url) +/** set new maps from url **/ +function get_new_maps($url) +{ + if (!($f = @fopen($url, 'r'))) return false; + global $globals; + $globals->xdb->query('TRUNCATE TABLE geoloc_maps'); + $s = ''; + while (!feof($f)) { + $l = fgetcsv($f, 1024, ';', '"'); + foreach ($l as $i => $val) if ($val != 'NULL') $l[$i] = '\''.addslashes($val).'\''; + $s .= ',('.implode(',',$l).')'; + } + $globals->xdb->execute('INSERT INTO geoloc_maps VALUES '.substr($s, 1)); + return true; +} + // {{{ get_address_text($adr) /** make the text of an address that can be read by a mailman * @param $adr an array with all the usual fields @@ -186,11 +224,13 @@ function localize_addresses($uid) { $globals->xdb->execute("UPDATE adresses SET adr1 = {?}, adr2 = {?}, adr3 = {?}, cityid = {?}, city = {?}, postcode = {?}, - region = {?}, regiontxt = {?}, country = {?} + region = {?}, regiontxt = {?}, country = {?}, + glat = {?}, glng = {?} WHERE uid = {?} AND adrid = {?}", $new['adr1'], $new['adr2'], $new['adr3'], $new['cityid'], $new['city'], $new['postcode'], $new['region'], $new['regiontxt'], $new['country'], + $new['precise_lat'], $new['precise_lon'], $uid, $a['adrid']); $new['store'] = true; if (!$new['cityid']) $erreur[$a['adrid']] = $new; @@ -208,14 +248,58 @@ function localize_addresses($uid) { * @param $id the id of the city to synchronize */ function synchro_city($id) { - $url ="http://www.geoloc.org/adressparser/cityFinder.php?method=id&id=".$id."&out=sql"; + global $globals; + $url = $globals->geoloc->webservice_url."cityFinder.php?method=id&id=".$id."&out=sql"; if (!($f = @fopen($url, 'r'))) return false; $s = fgets($f); - global $globals; if ($s) return $globals->xdb->execute("REPLACE INTO geoloc_city VALUES ".$s) > 0; } // }}} +// {{{ function fix_cities_not_on_map($limit) +function fix_cities_not_on_map($limit=false) +{ + global $globals; + $missing = $globals->xdb->query("SELECT c.id FROM geoloc_city AS c LEFT JOIN geoloc_city_in_maps AS m ON(c.id = m.city_id) WHERE m.city_id IS NULL".($limit?" LIMIT $limit":"")); + $maps = get_cities_maps($missing->fetchColumn()); + if ($maps) + { + $values = ""; + foreach ($maps as $cityid => $maps_c) + foreach ($maps_c as $map_id) + $values .= ",($cityid, $map_id, '')"; + $globals->xdb->execute("REPLACE INTO geoloc_city_in_maps VALUES ".substr($values, 1)); + } + else + return false; + + $maxlevelquery = $globals->xdb->query("SELECT MAX(level) FROM geoloc_maps"); + $maxlevel = $maxlevelquery->fetchOneCell(); + for ($level = $maxlevel; $level >= 0; $level--) + $globals->xdb->query(" + UPDATE geoloc_city AS gc + INNER JOIN geoloc_city_in_maps AS gcim ON(gc.id = gcim.city_id) + INNER JOIN geoloc_maps AS gm ON(gm.id = gcim.map_id AND gm.level = {?}) + LEFT JOIN geoloc_city_in_maps AS gcim2 ON(gc.id = gcim2.city_id AND gcim2.infos = 'smallest') + SET gcim.infos = 'smallest' + WHERE gcim2.city_id IS NULL", $level); + + return true; +} +// }}} + + +function geoloc_to_x($lon, $lat) { return deg2rad(1) * $lon *100; } + +function geoloc_to_y($lon, $lat) { + if ($lat < -75) return latToY(-75); + if ($lat > 75) return latToY(75); + return -100 * log(tan(pi()/4 + deg2rad(1)/2*$lat)); +} + +function size_of_city($nb) { $s = round(log($nb + 1)*2,2); if ($s < 1) return 1; return $s; } +function size_of_territory($nb) { return size_of_city($nb); } + // vim:set et sw=4 sts=4 sws=4 foldmethod=marker: ?> diff --git a/include/search.inc.php b/include/search.inc.php index d40856b..a337031 100644 --- a/include/search.inc.php +++ b/include/search.inc.php @@ -22,6 +22,60 @@ require_once('xorg.plugin.inc.php'); require_once("search/classes.inc.php"); +// {{{ function advancedSearchFromInput +function advancedSearchFromInput() +{ + if ($with_soundex = Env::has('with_soundex')) { + $nameField = new RefWithSoundexSField('name',array('rn.nom1_soundex','rn.nom2_soundex','rn.nom3_soundex'),'recherche_soundex','rn','u.matricule = rn.matricule'); + $firstnameField = new RefWithSoundexSField('firstname',array('rp.prenom1_soundex','rp.prenom2_soundex'),'recherche_soundex','rp','u.matricule = rp.matricule'); + } else { + $nameField = new NameSField('name',array('u.nom','u.nom_usage'),''); + $firstnameField = new StringSField('firstname',array('u.prenom'),''); + } + $nicknameField = new StringSField('nickname',array('q.profile_nick'),''); + + $promo1Field = new PromoSField('promo1','egal1',array('u.promo'),''); + $promo2Field = new PromoSField('promo2','egal2',array('u.promo'),''); + $womanField = new RefSField('woman',array('FIND_IN_SET(u.flags,\'femme\')+1'),'','',''); + $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')); + $regionField = new RefSField('region',array('ar.region'),'adresses','ar',getadr_join('ar')); + $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')); + + $entrepriseField = new RefSField('entreprise',array('ee.entreprise'),'entreprises','ee','u.user_id=ee.uid',false); + $posteField = new RefSField('poste',array('ep.poste'),'entreprises','ep','u.user_id=ep.uid', false); + $fonctionField = new RefSField('fonction',array('en.fonction'),'entreprises','en','u.user_id=en.uid'); + $secteurField = new RefSField('secteur',array('fm.secteur'),'entreprises','fm','u.user_id=fm.uid'); + $cvField = new RefSField('cv',array('u.cv'),'','','',false); + + $natField = new RefSField('nationalite',array('u.nationalite'),'','',''); + $binetField = new RefSField('binet',array('b.binet_id'),'binets_ins','b','u.user_id=b.user_id'); + $groupexField = new RefSField('groupex',array('g.gid'),'groupesx_ins','g','u.user_id=g.guid'); + $sectionField = new RefSField('section',array('u.section'),'','',''); + $schoolField = new RefSField('school',array('as.aid'),'applis_ins','`as`','u.user_id=as.uid'); + $diplomaField = new RefSField('diploma',array('ad.type'),'applis_ins','ad','u.user_id=ad.uid'); + + $freeField = new RefSField('free',array('q.profile_freetext'),'','','',false); + + return array( + $nameField, $firstnameField, $nicknameField, $promo1Field, + $promo2Field, $womanField, $subscriberField, $aliveField, + $townField, $countryField, $regionField, $entrepriseField, + $posteField, $secteurField, $cvField, $natField, $binetField, + $groupexField, $sectionField, $schoolField, $diplomaField, + $freeField, $fonctionField, $cityIdField, $mapField); +} + +// }}} + // {{{ class XOrgSearch class XOrgSearch extends XOrgPlugin diff --git a/include/search/classes.inc.php b/include/search/classes.inc.php index 4b5718a..ce6fad3 100644 --- a/include/search/classes.inc.php +++ b/include/search/classes.inc.php @@ -439,6 +439,36 @@ class RefSField extends SField } // }}} + +// {{{ class RefSFieldMultipleTable +class MapSField extends RefSField +{ + var $mapId; + + function MapSField($_fieldFormName, $_fieldDbName='', $_refTable, $_refAlias, $_refCondition, $_mapId=false) + { + if ($_mapId === false) + $this->mapId = Env::get($_fieldFormName); + else + $this->mapId = $_mapId; + $this->RefSField($_fieldFormName, $_fieldDbName, $_refTable, $_refAlias, $_refCondition, true, false); + } + function get_select_statement() + { + $res = implode(' OR ', array_filter(array_map(array($this, 'get_single_match_statement'), $this->fieldDbName))); + foreach ($this->refTable as $i => $refT) + $last = $i; + $inner = ""; + foreach ($this->refTable as $i => $refT) + $inner .= " INNER JOIN {$refT} AS {$this->refAlias[$i]} ON ({$this->refCondition[$i]} ".(($i == $last)?"AND ($res) ":"").")"; + return $inner; + } + function get_request() + { + $this->value = $this->mapId; + } +} + // {{{ class RefWithSoundexSField [ ??? ] class RefWithSoundexSField extends RefSField @@ -777,4 +807,5 @@ class SFieldGroup // }}} +// vim:set et sw=4 sts=4 sws=4 foldmethod=marker: ?> diff --git a/templates/admin/geoloc_dynamap.tpl b/templates/admin/geoloc_dynamap.tpl new file mode 100644 index 0000000..0d37d23 --- /dev/null +++ b/templates/admin/geoloc_dynamap.tpl @@ -0,0 +1,49 @@ +{**************************************************************************} +{* *} +{* Copyright (C) 2003-2006 Polytechnique.org *} +{* http://opensource.polytechnique.org/ *} +{* *} +{* 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 *} +{* *} +{**************************************************************************} + +

+ Administration de la dynamap +

+ +

+ Utiliser de nouvelles cartes +

+
+

+ +
+ +

+
+ +

+ Placement des villes sur les cartes +

+{if $nb_cities_not_on_map} +

+ Il y a {$nb_cities_not_on_map} villes qui ne sont pas placées dans les cartes. [Réparer] +

+{else} +

Toutes les villes de la base sont placées dans des cartes.

+{/if} + +{* vim:set et sw=2 sts=2 sws=2: *} diff --git a/templates/geoloc/geolocInit.tpl b/templates/geoloc/geolocInit.tpl new file mode 100644 index 0000000..5f30813 --- /dev/null +++ b/templates/geoloc/geolocInit.tpl @@ -0,0 +1,43 @@ +{**************************************************************************} +{* *} +{* Copyright (C) 2003-2006 Polytechnique.org *} +{* http://opensource.polytechnique.org/ *} +{* *} +{* 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 *} +{* *} +{**************************************************************************} + diff --git a/templates/geoloc/getCityInfos.tpl b/templates/geoloc/getCityInfos.tpl new file mode 100644 index 0000000..e2488c7 --- /dev/null +++ b/templates/geoloc/getCityInfos.tpl @@ -0,0 +1,27 @@ +{**************************************************************************} +{* *} +{* Copyright (C) 2003-2004 Polytechnique.org *} +{* http://opensource.polytechnique.org/ *} +{* *} +{* 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 *} +{* *} + + + {assign var="beginning" value=true} + {assign var="nb_displayed" value=0} + {iterate from=$users item="user"}{if !$beginning}
{/if}{if $nb_displayed < 10}{$user.prenom|utf8_encode} {$user.nom|strtolower|ucwords|utf8_encode} - {$user.promo}{else}...{/if}{assign var="nb_displayed" value=$nb_displayed+1}{assign var="beginning" value=false}{/iterate} +
+{* vim:set et sw=2 sts=2 sws=2: *} diff --git a/templates/geoloc/getData.tpl b/templates/geoloc/getData.tpl new file mode 100644 index 0000000..81a1918 --- /dev/null +++ b/templates/geoloc/getData.tpl @@ -0,0 +1,47 @@ +{**************************************************************************} +{* *} +{* Copyright (C) 2003-2006 Polytechnique.org *} +{* http://opensource.polytechnique.org/ *} +{* *} +{* 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 *} +{* *} +{**************************************************************************} + + + + {foreach from=$countries item="country"} + + + + + {if $country.nbPop > 0 or $country.id eq 0} + + + + {/if} + + {/foreach} + + + {foreach from=$cities item="city"} + + + + + {/foreach} + + +{* vim:set et sw=2 sts=2 sws=2: *} diff --git a/templates/geoloc/index.tpl b/templates/geoloc/index.tpl index 9bd44ee..0bc0b80 100644 --- a/templates/geoloc/index.tpl +++ b/templates/geoloc/index.tpl @@ -1,6 +1,6 @@ {**************************************************************************} {* *} -{* Copyright (C) 2003-2004 Polytechnique.org *} +{* Copyright (C) 2003-2006 Polytechnique.org *} {* http://opensource.polytechnique.org/ *} {* *} {* This program is free software; you can redistribute it and/or modify *} @@ -22,20 +22,56 @@

Géolocalisation

-

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

- + +{if !$dynamap_vars} +

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

+{/if}

-Carte du monde des X + + + + + + +

- -

Pour savoir comment ça marche tu peux aller faire un tour sur le site de développement du projet.

- +
+

+ +

+

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

{* vim:set et sw=2 sts=2 sws=2: *} diff --git a/templates/search.adv.form.tpl b/templates/search.adv.form.tpl index 4f9562e..2bfff6d 100644 --- a/templates/search.adv.form.tpl +++ b/templates/search.adv.form.tpl @@ -130,6 +130,10 @@ Géographie + + + + Ville @@ -295,15 +299,26 @@ -
-
- {min_auth level='cookie'} - - mettre les fiches modifiées récemment en premier

- {/min_auth} - -
+ {min_auth level='cookie'} +

+ + mettre les fiches modifiées récemment en premier +

+ {/min_auth} + + +

+ + + +

N.B. Le caractère joker * peut remplacer une ou plusieurs lettres dans les recherches.

diff --git a/templates/search.tpl b/templates/search.tpl index 57cc99f..3df8b19 100644 --- a/templates/search.tpl +++ b/templates/search.tpl @@ -22,16 +22,24 @@ {if $formulaire==0 and !$xorg_errors|count} - {if !$advanced} - {include file='search.quick.form.tpl' show_js=1} - {else} - {include file=search.adv.links.tpl do_title=1 with_soundex=$with_soundex} + {if !$simple} + {if !$advanced} + {include file='search.quick.form.tpl' show_js=1} + {else} + {include file=search.adv.links.tpl do_title=1 with_soundex=$with_soundex} + {/if} {/if}

{if $search_results_nb==0}Aucune{else}{$search_results_nb}{/if} réponse{if $search_results_nb>1}s{/if}.

+ {if $search_results_nb and $advanced and !$simple} +

+ [Voir la recherche sur une carte]. +

+ {/if} + {if $search_results_nb > 1}
Trier par : diff --git a/upgrade/0.9.10/00_geoloc.sql b/upgrade/0.9.10/00_geoloc.sql new file mode 100644 index 0000000..4db8efb --- /dev/null +++ b/upgrade/0.9.10/00_geoloc.sql @@ -0,0 +1,24 @@ +CREATE TABLE `geoloc_city_in_maps` ( + `city_id` int(11) NOT NULL default '0', + `map_id` int(11) NOT NULL default '0', + `infos` set('smallest') NOT NULL default '', + PRIMARY KEY (`map_id`,`infos`,`city_id`) +); +insert into admin_a VALUES (11, "Dynamap", "admin/geoloc_dynamap.php", 10); +UPDATE `adresses` AS a, `geoloc_city` AS c SET a.glng = c.lon /100000, a.glat = c.lat /100000 WHERE a.cityid = c.id; +CREATE TABLE `geoloc_maps` ( + `map_id` int(11) NOT NULL default '0', + `name` varchar(50) NOT NULL default '', + `x` double NOT NULL default '0', + `y` double NOT NULL default '0', + `width` double NOT NULL default '0', + `height` double NOT NULL default '0', + `xclip` float NOT NULL default '0', + `yclip` float NOT NULL default '0', + `scale` int(11) NOT NULL default '1', + `parent` int(11) default NULL, + `path` varchar(65) NOT NULL default '', + PRIMARY KEY (`map_id`), + KEY `parent` (`parent`), + KEY `path` (`path`) + ); diff --git a/upgrade/0.9.10/update.sh b/upgrade/0.9.10/update.sh new file mode 100755 index 0000000..de82fc0 --- /dev/null +++ b/upgrade/0.9.10/update.sh @@ -0,0 +1,32 @@ +#!/bin/bash + +. ../inc/pervasive.sh + +mailman_stop +mailman_templates +mailman_start + + +########################################################### +for sql in *.sql +do + echo -n $sql + $MYSQL x4dat < $sql &>/dev/null || echo -n " ERROR" + echo . +done + +########################################################### + +echo "we will now upgrade the search table (this may be a long operation) + +please hit ^D to continue +" + +cat + +pushd ../../bin +./search.rebuild_db.php +popd + +########################################################### + -- 2.1.4