Geoloc no remember that the user forced his address, and send a mail when it
authorFlorent Bruneau <florent.bruneau@polytechnique.org>
Sun, 9 Sep 2007 08:54:23 +0000 (10:54 +0200)
committerFlorent Bruneau <florent.bruneau@polytechnique.org>
Sun, 9 Sep 2007 08:54:23 +0000 (10:54 +0200)
failed

Signed-off-by: Florent Bruneau <florent.bruneau@polytechnique.org>
configs/mails.conf
modules/profile/addresses.inc.php
modules/profile/jobs.inc.php
modules/profile/page.inc.php
templates/geoloc/form.address.tpl
templates/geoloc/mail_geoloc.tpl [new file with mode: 0644]
upgrade/0.9.15/02_entreprises.sql

index fb63f39..a88d8dd 100644 (file)
@@ -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" <info@amicale.polytechnique.org>
 replyto=info@amicale.polytechnique.org
index 1edfbc1..89a3de1 100644 (file)
@@ -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,
index c544ef9..5b497c9 100644 (file)
@@ -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,
index 1afcd9f..143dd9d 100644 (file)
@@ -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);
index 428cc6e..8ad46c7 100644 (file)
@@ -60,4 +60,5 @@
 <input type="hidden" name="{$name}[countrytxt]" value="{$adr.countrytxt}" />
 <input type="hidden" name="{$name}[region]" value="{$adr.region}" />
 <input type="hidden" name="{$name}[regiontxt]" value="{$adr.regiontxt}" />
+<input type="hidden" name="{$name}[checked]" value="{$adr.checked}" />
 {* 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 (file)
index 0000000..4b74f32
--- /dev/null
@@ -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: *}
index 859e9ae..79cd796 100644 (file)
@@ -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);