validations for homonyms : closes 291
authorPascal Corpet <pascal.corpet@m4x.org>
Wed, 23 Feb 2005 12:53:13 +0000 (12:53 +0000)
committerFlorent Bruneau <florent.bruneau@polytechnique.org>
Thu, 26 Jun 2008 21:28:14 +0000 (23:28 +0200)
git-archimport-id: opensource@polytechnique.org--2005/platal--mainline--0.9--patch-491

bin/cron/homonymes.php [new file with mode: 0755]
include/validations.inc.php
include/validations/homonymes.inc.php [new file with mode: 0644]
templates/admin/valider.tpl
templates/include/form.valid.homonymes.tpl [new file with mode: 0644]

diff --git a/bin/cron/homonymes.php b/bin/cron/homonymes.php
new file mode 100755 (executable)
index 0000000..feb1451
--- /dev/null
@@ -0,0 +1,43 @@
+#!/usr/bin/php4 -q
+<?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                *
+ ***************************************************************************/
+/* vim: set sw=4 ts=4 sts=4 tw=100:
+ * crée des demandes de validation pour les kill d'alias
+ * une demande 10 jours avant pour un warning, puis une autre pour le robot
+*/ 
+
+$W_PERIOD = "INTERVAL 7 DAY"; // temps d'envoi du warning avant la deadline
+
+require('./connect.db.inc.php');
+
+$resRobot = $globals->xdb->iterator("SELECT id, alias, expire FROM aliases WHERE expire < NOW() + $W_PERIOD AND type = 'alias'");
+
+if ($resRobot->total()) {
+    require_once('validations/homonymes.inc.php');
+    while ($old = $resRobot->next()) {
+       $res = $globals->xdb->query("SELECT alias AS forlife FROM homonymes INNER JOIN aliases ON(user_id = id) WHERE homonyme_id = {?} AND type='a_vie'", $old['id']);
+       $forlifes = $res->fetchColumn();
+       $req = new HomonymeReq($old['id'], $old['alias'], $forlifes, $old['expire'] > date("Y-m-d"));
+       $req->submit();
+    }
+}
+
+?>
index 8e03296..c64e720 100644 (file)
@@ -73,6 +73,8 @@ class Validate
 
     var $stamp;
     var $unique;
+    // enable the refuse button
+    var $refuse = true;
     var $type;
     var $comments = Array();
 
diff --git a/include/validations/homonymes.inc.php b/include/validations/homonymes.inc.php
new file mode 100644 (file)
index 0000000..1b4e979
--- /dev/null
@@ -0,0 +1,148 @@
+<?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('validations.inc.php');
+// {{{ class HomonymeReq
+
+class HomonymeReq extends Validate
+{
+    // {{{ properties
+    
+    var $loginbis;
+
+    var $warning = true;
+
+    var $homonymes_forlife;
+
+    // }}}
+    // {{{ constructor
+   
+    function HomonymeReq($_uid, $_loginbis, $_homonymes_forlife, $warning=true)
+    {
+        global $global;
+
+        $this->warning = $warning;
+
+        $this->Validate($_uid, true, $this->title());
+
+        $this->refuse = false;
+
+        $this->loginbis = $_loginbis;
+
+        $this->homonymes_forlife = $_homonymes_forlife;
+
+    }
+    
+    // }}}
+    // {{{ title()
+    
+    function title() {
+        return $this->warning?'alerte alias':'robot répondeur';
+    }
+
+    // }}}
+    // {{{ function get_request()
+
+    function get_request($uid)
+    {
+        return parent::get_request($uid,$this->title);
+    }
+
+    // }}}
+    // {{{ function formu()
+
+    function formu()
+    { return 'include/form.valid.homonymes.tpl'; }
+
+    // }}}
+    // {{{ function _mail_subj
+
+    function _mail_subj()
+    {
+        return "[Polytechnique.org/Support] ".($this->warning?"Dans une semaine : suppression de l'alias":"Mise en place du robot")." $loginbis@polytechnique.org";
+    }
+
+    // }}}
+    // {{{ function _mail_body
+    
+    function _mail_body($isok)
+    {
+        global $globals;
+        return
+"
+Comme nous t'en avons informé par mail il y a quelques temps,
+pour respecter nos engagements en terme d'adresses e-mail devinables,
+tu te verras bientôt retirer l'alias ".$this->loginbis."@".$globals->mail->domain." pour
+ne garder que ".$this->forlife."@".$globals->mail->domain.".
+
+Toute personne qui écrira à ".$this->loginbis."@".$globals->mail->domain." recevra la
+réponse d'un robot qui l'informera que ".$this->loginbis."@".$globals->mail->domain."
+est ambigu pour des raisons d'homonymie et signalera ton email exact.";
+    }
+
+    // }}}
+    // {{{ function sendmail()
+
+    function sendmail($isok)
+    {
+        if (!$isok) return false;
+        global $globals;
+        require_once('diogenes/diogenes.hermes.inc.php');
+        $mailer = new HermesMailer;
+        $cc = "support+homonyme@".$globals->mail->domain;
+        $FROM = "\"Support Polytechnique.org\" <$cc>";
+        $mailer->setSubject($this->_mail_subj());
+        $mailer->setFrom($FROM);
+        $mailer->addTo("\"{$this->prenom} {$this->nom}\" <{$this->bestalias}@{$globals->mail->domain}>");
+        $mailer->addCc($cc);
+
+        $body = $this->prenom.",\n\n"
+              . $this->_mail_body($isok)
+              . (Env::has('comm') ? "\n\n".Env::get('comm') : '')
+              . "\n\nCordialement,\nL'équipe Polytechnique.org\n";
+
+        $mailer->setTxtBody(wordwrap($body));
+        $mailer->send();
+    }
+    // }}}
+    // {{{ function commit()
+    
+    function commit()
+    {
+        global $globals;
+        require_once('homonymes.inc.php');
+
+        switch_bestalias($this->uid, $this->loginbis);
+        if (!$this->warning) {
+            $globals->xdb->execute("UPDATE aliases SET type='homonyme',expire=NOW() WHERE alias={?}", $this->loginbis);
+            $globals->xdb->execute("REPLACE INTO homonymes (homonyme_id,user_id) VALUES({?},{?})", $this->uid, $this->uid);
+        }
+        
+        return true;
+    }
+
+    // }}}
+}
+
+// }}}
+
+// vim:set et sw=4 sts=4 sws=4 foldmethod=marker:
+?>
index 834a5bd..45a18ee 100644 (file)
@@ -60,7 +60,7 @@
         <input type="hidden" name="stamp"  value="{$valid->stamp}" />
         <input type="submit" name="accept" value="Accepter" />
         <input type="submit" name="hold"   value="Commenter" />
-        <input type="submit" name="refuse" value="Refuser" />
+        {if $valid->refuse}<input type="submit" name="refuse" value="Refuser" />{/if}
         <input type="submit" name="delete" value="Supprimer" />
       </td>
     </tr>
diff --git a/templates/include/form.valid.homonymes.tpl b/templates/include/form.valid.homonymes.tpl
new file mode 100644 (file)
index 0000000..118a628
--- /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                *
+ ***************************************************************************}
+
+<tr class="pair">
+  <td class="titre">Adresse litigieuse :</td>
+  <td>
+    {$valid->loginbis}@polytechnique.org
+  </td>
+</tr>
+<tr class="pair">
+  <td class="titre">Homonymes :</td>
+  <td>
+    {foreach from=$valid->homonymes_forlife item=o}
+    <a href='{rel}/fiche.php?user={$o}' class='popup2'>{$o}</a>
+    {/foreach}
+  </td>
+</tr>
+
+{* vim:set et sw=2 sts=2 sws=2: *}