synchro geoloc pour les admins
authorPascal Corpet <pascal.corpet@m4x.org>
Sat, 25 Jun 2005 18:16:23 +0000 (18:16 +0000)
committerFlorent Bruneau <florent.bruneau@polytechnique.org>
Thu, 26 Jun 2008 21:29:25 +0000 (23:29 +0200)
git-archimport-id: opensource@polytechnique.org--2005/platal--mainline--0.9--patch-750

htdocs/admin/geoloc.php [new file with mode: 0644]
include/geoloc.inc.php
templates/admin/geoloc.tpl [new file with mode: 0644]
upgrade/0.9.8/00_admin.sql [new file with mode: 0644]
upgrade/0.9.8/update.sh [new file with mode: 0755]

diff --git a/htdocs/admin/geoloc.php b/htdocs/admin/geoloc.php
new file mode 100644 (file)
index 0000000..90148fa
--- /dev/null
@@ -0,0 +1,46 @@
+<?php
+/***************************************************************************
+ *  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                *
+ ***************************************************************************/
+
+require_once("xorg.inc.php");
+new_admin_page('admin/geoloc.tpl');
+require_once("geoloc.inc.php");
+
+$nb_synchro = 0;
+
+if (Env::has('id') && is_numeric(Env::get('id'))) {
+    if (synchro_city(Env::get('id'))) $nb_synchro ++;
+}
+
+if (Env::has('missinglat')) {
+    $res = $globals->xdb->iterRow("SELECT id FROM geoloc_city WHERE lat = 0 AND lon = 0");
+    while ($a = $res->next()) if (synchro_city($a[0])) $nb_synchro++;
+}
+
+if ($nb_synchro) 
+    $page->trig(($nb_synchro > 1)?($nb_synchro." villes ont été synchronisées"):"Une ville a été synchronisée");
+
+$res = $globals->xdb->query("SELECT COUNT(*) FROM geoloc_city WHERE lat = 0 AND lon = 0");
+$page->assign("nb_missinglat", $res->fetchOneCell());
+
+$page->run();
+
+// vim:set et sws=4 sts=4 sw=4:
+?>
index eaabbd0..4a1bf07 100644 (file)
@@ -67,8 +67,11 @@ function _geoloc_region_smarty($params){
 $page->register_function('geoloc_region', '_geoloc_region_smarty');
 // }}}
 
-// retrieve the infos on a text address
-// store on the fly the info of the city concerned
+// {{{ get_address_infos($txt)
+/** retrieve the infos on a text address
+ * store on the fly the info of the city concerned
+ * @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));
     if (!($f = @fopen($url, 'r'))) return false;
@@ -81,8 +84,12 @@ function get_address_infos($txt) {
        $globals->xdb->execute("REPLACE INTO geoloc_city VALUES ".$infos['sql']);
     return $infos;
 }
+// }}}
 
-// make the text of an address that can be read by a mailman
+// {{{ 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
+ */
 function get_address_text($adr) {
     $t = "";
     if ($adr['adr1']) $t.= $adr['adr1'];
@@ -106,9 +113,13 @@ function get_address_text($adr) {
     if ($adr['countrytxt']) $t .= "\n".$adr['countrytxt'];
     return trim($t);
 }
+// }}}
 
-// compares if two address matches
-// $b should be a complete valid address
+// {{{ compare_addresses_text($a, $b)
+/** compares if two address matches
+ * @param $a the raw text of an address
+ * @param $b the raw text of a complete valid address
+ */
 function compare_addresses_text($a, $b) {
     $ta = strtoupper(preg_replace(array("/[0-9,\"'#~:;_\- ]/", "/\r\n/"), array("", "\n"), $a));
     $tb = strtoupper(preg_replace(array("/[0-9,\"'#~:;_\- ]/", "/\r\n/"), array("", "\n"), $b));
@@ -121,6 +132,8 @@ function compare_addresses_text($a, $b) {
     return true;
 }
 
+// }}}
+
 function empty_address() {
     return Array(
         "adr1" => "",
@@ -141,8 +154,11 @@ function cut_address($txt) {
     return array("adr1" => trim($a[1]), "adr2" => trim($a[3]), "adr3" => trim(str_replace("\n", " ", $a[5])));
 }
 
-// localize all the address of a user and modify the database
-// if the new address match with the old one
+// {{{ localize_addresses($uid)
+/* localize all the address of a user and modify the database
+ * if the new address match with the old one
+ * @param $uid the id of the user
+ */
 function localize_addresses($uid) {
     global $globals;
     $res = $globals->xdb->iterator("SELECT * FROM adresses WHERE uid = {?} and (cityid IS NULL OR cityid = 0)", $uid);
@@ -169,6 +185,21 @@ function localize_addresses($uid) {
     }
     return $erreur;
 }
+// }}}
+
+// {{{ synchro_city($id)
+/** synchronise the local geoloc_city base to geoloc.org
+ * @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";
+    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;
+ }
+ // }}}
 
 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker:
 ?>
diff --git a/templates/admin/geoloc.tpl b/templates/admin/geoloc.tpl
new file mode 100644 (file)
index 0000000..5159741
--- /dev/null
@@ -0,0 +1,36 @@
+{**************************************************************************}
+{*                                                                        *}
+{*  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               *}
+{*                                                                        *}
+{**************************************************************************}
+
+<h1>Geoloc</h1>
+<h2>Synchroniser des villes avec geoloc.org</h2>
+
+{if $nb_missinglat}
+<p>[<a href='?missinglat=1'>toutes les villes sans coordonnées ({$nb_missinglat})</a>]</p>
+{/if}
+
+<form action='{$smarty.server.PHP_SELF}' method='get'>
+<p>
+La ville dont l'id est : <input size="6" name="id" />
+</p>
+</form>
+{* vim:set et sw=2 sts=2 sws=2: *}
diff --git a/upgrade/0.9.8/00_admin.sql b/upgrade/0.9.8/00_admin.sql
new file mode 100644 (file)
index 0000000..ae7fd08
--- /dev/null
@@ -0,0 +1,2 @@
+INSERT INTO admin_h2 VALUES(2, 11, 'Géoloc', 70);
+INSERT INTO admin_a VALUES(11, 'Synchro', 'admin/geoloc.php',0); 
diff --git a/upgrade/0.9.8/update.sh b/upgrade/0.9.8/update.sh
new file mode 100755 (executable)
index 0000000..de82fc0
--- /dev/null
@@ -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
+
+###########################################################
+