12c049706f1257d3ec58538d5d2080625a376f0d
3 require_once 'connect.db.inc.php';
4 require_once 'geocoding.inc.php';
6 $globals->debug
= 0; // Do not store backtraces.
8 $res = XDB
::query('SELECT MIN(pid), MAX(pid)
11 $pids = $res->fetchOneRow();
16 echo "This will take a few minutes.\n";
18 // Fills the 'text' field in profile_addresses.
19 for ($pid = $minPid; $pid < $maxPid +
1; ++
$pid) {
20 $res = XDB
::iterator("SELECT a.adrid AS id, a.adr1, a.adr2, a.adr3,
21 UNIX_TIMESTAMP(a.datemaj) AS datemaj,
22 a.postcode, a.city, a.cityid, a.region, a.regiontxt,
23 a.pub, a.country, gp.pays AS countrytxt, gp.display,
24 FIND_IN_SET('coord-checked', a.statut) AS checked,
25 FIND_IN_SET('res-secondaire', a.statut) AS secondaire,
26 FIND_IN_SET('courrier', a.statut) AS mail,
27 FIND_IN_SET('temporaire', a.statut) AS temporary,
28 FIND_IN_SET('active', a.statut) AS current,
29 FIND_IN_SET('pro', a.statut) AS pro,
30 a.glat AS precise_lat, a.glng AS precise_lon
31 FROM #x4dat#.adresses AS a
32 INNER JOIN #x4dat#.geoloc_pays AS gp ON (gp.a2 = a.country)
33 INNER JOIN account_profiles AS ap ON (a.uid = ap.uid AND FIND_IN_SET('owner', ap.perms))
38 while ($address = $res->next()) {
39 $text = get_address_text($address);
40 XDB
::iterator('UPDATE profile_addresses
42 WHERE pid = {?} AND type = {?} AND id = {?}',
43 $text, $pid, $address['pro'] ?
'job' : 'home', $address['id']);
47 function get_address_text($adr)
50 if (isset($adr['adr1']) && $adr['adr1']) $t .= $adr['adr1'];
51 if (isset($adr['adr2']) && $adr['adr2']) $t .= "\n".$adr['adr2'];
52 if (isset($adr['adr3']) && $adr['adr3']) $t .= "\n".$adr['adr3'];
54 if (isset($adr['display']) && $adr['display']) {
55 $keys = explode(' ', $adr['display']);
56 foreach ($keys as $key) {
57 if (isset($adr[$key])) {
58 $l .= ' ' . $adr[$key];
63 if ($l) substr($l, 1);
64 } elseif ($adr['country'] == 'US' ||
$adr['country'] == 'CA' ||
$adr['country'] == 'GB') {
65 if ($adr['city']) $l .= $adr['city'] . ",\n";
66 if ($adr['region']) $l .= $adr['region'] . ' ';
67 if ($adr['postcode']) $l .= $adr['postcode'];
69 if (isset($adr['postcode']) && $adr['postcode']) $l .= $adr['postcode'] . ' ';
70 if (isset($adr['city']) && $adr['city']) $l .= $adr['city'];
72 if ($l) $t .= "\n" . trim($l);
73 if ($adr['country'] != '00' && (!$adr['countrytxt'] ||
$adr['countrytxt'] == strtoupper($adr['countrytxt']))) {
74 $res = XDB
::query('SELECT countryFR
76 WHERE iso_3166_1_a2 = {?}',
78 $adr['countrytxt'] = $res->fetchOneCell();
80 if (isset($adr['countrytxt']) && $adr['countrytxt']) {
81 $t .= "\n" . $adr['countrytxt'];
86 /* vim:set et sw=4 sts=4 ts=4: */