git-archimport-id: opensource@polytechnique.org--2005/platal--mainline--0.9--patch-750
--- /dev/null
+<?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:
+?>
$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;
$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'];
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));
return true;
}
+// }}}
+
function empty_address() {
return Array(
"adr1" => "",
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);
}
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:
?>
--- /dev/null
+{**************************************************************************}
+{* *}
+{* 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: *}
--- /dev/null
+INSERT INTO admin_h2 VALUES(2, 11, 'Géoloc', 70);
+INSERT INTO admin_a VALUES(11, 'Synchro', 'admin/geoloc.php',0);
--- /dev/null
+#!/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
+
+###########################################################
+