From f93fb300b28961f8a7dd0b6403a85eed3d1c0c6e Mon Sep 17 00:00:00 2001 From: Florent Bruneau Date: Sun, 9 Sep 2007 10:54:23 +0200 Subject: [PATCH] Geoloc no remember that the user forced his address, and send a mail when it failed Signed-off-by: Florent Bruneau --- configs/mails.conf | 4 ++++ modules/profile/addresses.inc.php | 5 +++++ modules/profile/jobs.inc.php | 17 +++++++++++----- modules/profile/page.inc.php | 12 ++++++++++- templates/geoloc/form.address.tpl | 1 + templates/geoloc/mail_geoloc.tpl | 42 +++++++++++++++++++++++++++++++++++++++ upgrade/0.9.15/02_entreprises.sql | 1 + 7 files changed, 76 insertions(+), 6 deletions(-) create mode 100644 templates/geoloc/mail_geoloc.tpl diff --git a/configs/mails.conf b/configs/mails.conf index fb63f39..a88d8dd 100644 --- a/configs/mails.conf +++ b/configs/mails.conf @@ -31,6 +31,10 @@ replyto=info+nlp@polytechnique.org from=webmaster@polytechnique.org to=web@polytechnique.org +[geoloc_error] +from=webmaster@polytechnique.org +to=florent.bruneau@polytechnique.org + [mails_ax] from="Association des Anciens élèves de l'X" replyto=info@amicale.polytechnique.org diff --git a/modules/profile/addresses.inc.php b/modules/profile/addresses.inc.php index 1edfbc1..89a3de1 100644 --- a/modules/profile/addresses.inc.php +++ b/modules/profile/addresses.inc.php @@ -51,6 +51,7 @@ class ProfileAddress extends ProfileGeoloc } unset($tel['removed']); } + $address['checked'] = $this->bool->value($page, 'checked', $address['checked'], $s); $address['secondaire'] = $this->bool->value($page, 'secondaire', $address['secondaire'], $s); $address['mail'] = $this->bool->value($page, 'mail', $address['mail'], $s); $address['temporary'] = $this->bool->value($page, 'temporary', $address['temporary'], $s); @@ -125,6 +126,9 @@ class ProfileAddress extends ProfileGeoloc if ($address['current']) { $flags[] = 'active'; } + if ($address['checked']) { + $flags[] = 'coord-checked'; + } $flags = implode(',', $flags); XDB::execute("INSERT INTO adresses (adr1, adr2, adr3, postcode, city, cityid, @@ -181,6 +185,7 @@ class ProfileAddresses extends ProfilePage UNIX_TIMESTAMP(a.datemaj) AS datemaj, a.postcode, a.city, a.cityid, a.region, a.regiontxt, a.pub, a.country, gp.pays AS countrytxt, gp.display, + FIND_IN_SET('coord-checked', a.statut) AS checked, FIND_IN_SET('res-secondaire', a.statut) AS secondaire, FIND_IN_SET('courrier', a.statut) AS mail, FIND_IN_SET('temporaire', a.statut) AS temporary, diff --git a/modules/profile/jobs.inc.php b/modules/profile/jobs.inc.php index c544ef9..5b497c9 100644 --- a/modules/profile/jobs.inc.php +++ b/modules/profile/jobs.inc.php @@ -25,6 +25,7 @@ class ProfileJob extends ProfileGeoloc private $mail; private $web; private $tel; + private $bool; private $checks; public function __construct() @@ -33,6 +34,7 @@ class ProfileJob extends ProfileGeoloc $this->mail = new ProfileEmail(); $this->web = new ProfileWeb(); $this->tel = new ProfileTel(); + $this->bool = new ProfileBool(); $this->checks = array('web' => array('web'), 'mail' => array('email'), 'tel' => array('tel', 'fax', 'mobile'), @@ -52,6 +54,8 @@ class ProfileJob extends ProfileGeoloc } } } + $job['adr']['pub'] = $this->pub->value($page, 'adr_pub', @$job['adr']['pub'], $s); + $job['adr']['checked'] = $this->bool->value($page, 'adr_checked', @$job['adr']['checked'], $s); unset($job['removed']); unset($job['new']); unset($job['adr']['changed']); @@ -96,19 +100,20 @@ class ProfileJob extends ProfileGeoloc fonction, poste, adr1, adr2, adr3, postcode, city, cityid, country, region, regiontxt, tel, fax, mobile, email, web, - pub, adr_pub, tel_pub, email_pub) + pub, adr_pub, tel_pub, email_pub, flags) VALUES ({?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, - {?}, {?}, {?}, {?})", + {?}, {?}, {?}, {?}, {?})", S::i('uid'), $i++, $job['name'], $job['secteur'], $job['ss_secteur'], $job['fonction'], $job['poste'], $job['adr']['adr1'], $job['adr']['adr2'], $job['adr']['adr3'], $job['adr']['postcode'], $job['adr']['city'], $job['adr']['cityid'], $job['adr']['country'], $job['adr']['region'], $job['adr']['regiontxt'], $job['tel'], $job['fax'], $job['mobile'], $job['email'], $job['web'], - $job['pub'], $job['adr']['pub'], $job['tel_pub'], $job['email_pub']); + $job['pub'], $job['adr']['pub'], $job['tel_pub'], $job['email_pub'], + $job['adr']['checked'] ? 'geoloc' : ''); } } } @@ -142,6 +147,7 @@ class ProfileJobs extends ProfilePage e.fonction, e.poste, e.adr1, e.adr2, e.adr3, e.postcode, e.city, e.cityid, e.region, e.regiontxt, e.country, gp.pays, gp.display, + FIND_IN_SET('geoloc', flags), e.tel, e.fax, e.mobile, e.email, e.web, e.pub, e.adr_pub, e.tel_pub, e.email_pub FROM entreprises AS e @@ -152,7 +158,7 @@ class ProfileJobs extends ProfilePage while (list($name, $secteur, $ss_secteur, $fonction, $poste, $adr1, $adr2, $adr3, $postcode, $city, $cityid, $region, $regiontxt, $country, $countrytxt, $display, - $tel, $fax, $mobile, $email, $web, + $checked, $tel, $fax, $mobile, $email, $web, $pub, $adr_pub, $tel_pub, $email_pub) = $res->next()) { $this->values['jobs'][] = array('name' => $name, 'secteur' => $secteur, @@ -170,7 +176,8 @@ class ProfileJobs extends ProfilePage 'country' => $country, 'countrytxt' => $countrytxt, 'display' => $display, - 'pub' => $adr_pub), + 'pub' => $adr_pub, + 'checked' => $checked), 'tel' => $tel, 'fax' => $fax, 'mobile' => $mobile, diff --git a/modules/profile/page.inc.php b/modules/profile/page.inc.php index 1afcd9f..143dd9d 100644 --- a/modules/profile/page.inc.php +++ b/modules/profile/page.inc.php @@ -141,13 +141,23 @@ abstract class ProfileGeoloc implements ProfileSetting if (compare_addresses_text(@$address['text'], $geotxt = get_address_text($new)) || (@$address['parsevalid'] && @$address['cityid'])) { $address = array_merge($address, $new); + $address['checked'] = true; } else if (@$address['parsevalid']) { $address = array_merge($address, cut_address(@$address['text'])); - } else { + $address['checked'] = true; + $mailer = new PlMailer('geoloc/mail_geoloc.tpl'); + $mailer->assign('text', get_address_text($address)); + $mailer->assign('geoloc', $geotxt); + $mailer->send(); + } else if (@$address['changed'] || !@$address['checked']) { $success = false; $address = array_merge($address, cut_address(@$address['text'])); + $address['checked'] = false; $address['geoloc'] = $geotxt; $address['geoloc_cityid'] = $new['cityid']; + } else { + $address = array_merge($address, cut_address(@$address['text'])); + $address['checked'] = true; } } $address['text'] = get_address_text($address); diff --git a/templates/geoloc/form.address.tpl b/templates/geoloc/form.address.tpl index 428cc6e..8ad46c7 100644 --- a/templates/geoloc/form.address.tpl +++ b/templates/geoloc/form.address.tpl @@ -60,4 +60,5 @@ + {* vim:set et sw=2 sts=2 sws=2 enc=utf-8: *} diff --git a/templates/geoloc/mail_geoloc.tpl b/templates/geoloc/mail_geoloc.tpl new file mode 100644 index 0000000..4b74f32 --- /dev/null +++ b/templates/geoloc/mail_geoloc.tpl @@ -0,0 +1,42 @@ +{**************************************************************************} +{* *} +{* Copyright (C) 2003-2007 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 *} +{* *} +{**************************************************************************} + +{config_load file="mails.conf" section="geoloc_error"} +{if $mail_part eq 'head'} +{from full=#from#} +{to addr=#to#} +{subject text="Adresse impossible à geolocaliser"} +{elseif $mail_part eq 'wiki'} +Un camarade {$smarty.session.forlife} a forcé l'utilisation de l'adresse entrée +à la main et a refusé la version geolocalisée : + +'''Version utilisateur (validée) :'''\\ +{$text|replace:"\n":"\\\\\n"} + +'''Version geoloc (refusée) :'''\\ +{$geoloc|replace:"\n":"\\\\\n"} + +-- \\ +Webmaster de Polytechnique.org +{/if} + +{* vim:set et sw=2 sts=2 sws=2: *} diff --git a/upgrade/0.9.15/02_entreprises.sql b/upgrade/0.9.15/02_entreprises.sql index 859e9ae..79cd796 100644 --- a/upgrade/0.9.15/02_entreprises.sql +++ b/upgrade/0.9.15/02_entreprises.sql @@ -1,5 +1,6 @@ alter table entreprises add column cityid int(11) default null after city; alter table entreprises add column regiontxt varchar(80) not null after region; +alter table entreprises add column flags set('geoloc') not null; alter table entreprises add key cityid (cityid); alter table entreprises add key country (country); alter table entreprises add key region (region); -- 2.1.4