Adds ml reminder.
authorStéphane Jacob <jacou@melix.net>
Sun, 10 May 2009 21:40:45 +0000 (23:40 +0200)
committerStéphane Jacob <jacou@melix.net>
Sun, 31 May 2009 12:35:27 +0000 (14:35 +0200)
include/reminder/ml.inc.php [new file with mode: 0644]
templates/reminder/ml.tpl [new file with mode: 0644]

diff --git a/include/reminder/ml.inc.php b/include/reminder/ml.inc.php
new file mode 100644 (file)
index 0000000..2e8deec
--- /dev/null
@@ -0,0 +1,100 @@
+<?php
+/***************************************************************************
+ *  Copyright (C) 2003-2009 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                *
+ ***************************************************************************/
+
+class ReminderMl extends Reminder
+{
+    public function HandleAction($action)
+    {
+        switch ($action) {
+          case 'suscribe':
+            S::assert_xsrf_token();
+            $subs = array_keys(Post::v('sub_ml'));
+            $current_domain = null;
+
+            $res = XDB::iterRow("SELECT  sub, domain
+                                   FROM  register_subs
+                                  WHERE  uid = {?} AND type = 'list'
+                               ORDER BY  domain",
+                                S::i('uid'));
+            while (list($sub, $domain) = $res->next()) {
+                if (array_shift($subs) == "$sub@$domain") {
+                    list($sub, $domain) = explode('@', $list);
+                    if ($domain != $current_domain) {
+                        $current_domain = $domain;
+                        $client = new MMList(S::v('uid'), S::v('password'), $domain);
+                    }
+                    $client->subscribe($sub);
+                }
+            }
+
+            $this->UpdateOnYes();
+            pl_redirect('lists');
+            break;
+
+          case 'dismiss':
+            $this->UpdateOnDismiss();
+            break;
+
+          case 'no':
+            $this->UpdateOnNo();
+            break;
+        }
+    }
+
+    protected function GetDisplayText() {}
+
+    public function Display(&$page)
+    {
+        header('Content-Type: text/html; charset=utf-8');
+        $page->changeTpl('reminder/ml.tpl', NO_SKIN);
+        $page->assign('baseurl', $this->GetBaseUrl());
+
+        $res = XDB::iterRow("SELECT  sub, domain
+                               FROM  register_subs
+                              WHERE  uid = {?} AND type = 'list'
+                           ORDER BY  domain",
+                            S::i('uid'));
+        $current_domain = null;
+        $lists = array();
+        while (list($sub, $domain) = $res->next()) {
+            if ($current_domain != $domain) {
+                $current_domain = $domain;
+                $client = new MMList(S::v('uid'), S::v('password'), $domain);
+            }
+            list($details, ) = $client->get_members($sub);
+            $lists["$sub@$domain"] = $details;
+        }
+        $page->assign_by_ref('lists', $lists);
+    }
+
+    public static function IsCandidate(User &$user)
+    {
+        $res = XDB::execute("SELECT  COUNT(*) AS lists
+                               FROM  register_subs
+                              WHERE  uid = {?} AND type = 'list'",
+                            $user->id());
+
+        return $res->fetchOneCell();
+    }
+}
+
+// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
+?>
diff --git a/templates/reminder/ml.tpl b/templates/reminder/ml.tpl
new file mode 100644 (file)
index 0000000..a431fe7
--- /dev/null
@@ -0,0 +1,54 @@
+{**************************************************************************}
+{*                                                                        *}
+{*  Copyright (C) 2003-2009 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               *}
+{*                                                                        *}
+{**************************************************************************}
+
+<div class="warnings reminder">
+  <span style="float: right">
+    <a href="" onclick="Ajax.update_html('reminder', '{$baseurl}/dismiss')">
+      {icon name=cross title="Cacher cet avertissement."}
+    </a>
+  </span>
+  <form action="{$baseurl}/suscribe" method="post">
+    {xsrf_token_field}
+    Des camarades souhaitent que tu t'inscrives aux listes suivantes&nbsp;:
+    <dl>
+      {foreach from=$lists key=list item=details}
+      <dt>
+        <label>
+          <input type='checkbox' value='1' checked="checked" name="sub_ml[{$list}]" />
+          {$list}*&nbsp;: {$details.desc}
+        </label>
+      </dt>
+      {if $details.info}
+      <dd>
+        {$details.info|nl2br}
+      </dd>
+      {/if}
+      {/foreach}
+    </dl>
+    <input type="submit" value="M'inscrire aux listes choisies." />
+  </form>
+  [<a href="" onclick="Ajax.update_html('reminder', '{$baseurl}/no')">
+    {icon name=delete} Ne pas m'inscrire à ces listes de diffusion.
+  </a>]
+</div>
+
+{* vim:set et sw=2 sts=2 sws=2 enc=utf-8: *}