further work on notifs
authorx2000habouzit <x2000habouzit>
Thu, 4 Nov 2004 19:57:42 +0000 (19:57 +0000)
committerx2000habouzit <x2000habouzit>
Thu, 4 Nov 2004 19:57:42 +0000 (19:57 +0000)
htdocs/carnet/notifs.php
include/notifs.inc.php [new file with mode: 0644]
scripts/migration/0.9.2/notifs.sql [new file with mode: 0644]
templates/carnet/notifs.tpl

index b4c38fb..af782bb 100644 (file)
  *  Foundation, Inc.,                                                      *
  *  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA                *
  ***************************************************************************
-        $Id: notifs.php,v 1.1 2004-11-04 16:59:29 x2000habouzit Exp $
+        $Id: notifs.php,v 1.2 2004-11-04 19:57:42 x2000habouzit Exp $
  ***************************************************************************/
 
 require("auto.prepend.inc.php");
 new_skinned_page('carnet/notifs.tpl', AUTH_COOKIE);
+require('notifs.inc.php');
+
+$notifs = new Notifs($_SESSION['uid']);
+
+$err = Array();
+
+foreach($_REQUEST as $key=>$val) {
+    switch($key) {
+       case 'add_promo':
+           $p = intval($val);
+           if(($p<1900) || ($p>2100)) {
+               $err[] = "il faut entrer une promo sur 4 chiffres";
+           } else {
+               $notifs->add_promo($val);
+           };
+           break;
+       case 'del_promo':
+           $notifs->del_promo($val);
+           break;
+
+       case 'flags':
+           $flags = new FlagSet();
+           if(isset($_REQUEST['contacts'])) $flags->addflag('contacts');
+           if(isset($_REQUEST['deaths'])) $flags->addflag('deaths');
+           $notifs->flags = $flags;
+           $notifs->saveFlags();
+           break;
+    }
+}
+$page->assign_by_ref('notifs', $notifs);
+
 $page->run();
 
 ?>
diff --git a/include/notifs.inc.php b/include/notifs.inc.php
new file mode 100644 (file)
index 0000000..8cd93b8
--- /dev/null
@@ -0,0 +1,73 @@
+<?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                *
+ ***************************************************************************
+        $Id: notifs.inc.php,v 1.1 2004-11-04 19:57:43 x2000habouzit Exp $
+ ***************************************************************************/
+
+require_once('diogenes.flagset.inc.php');
+class Notifs {
+    var $uid;
+    var $flags;
+    var $promos = Array();
+    var $nonins = Array();
+
+    function Notifs($uid) {
+       global $globals;
+       $this->uid = $uid;
+
+       $res = $globals->db->query("SELECT watch FROM auth_user_md5 WHERE user_id = '$uid'");
+       list($flags) = mysql_fetch_row($res);
+       mysql_free_result($res);
+       $this->flags = new FlagSet($flags);
+       
+       $res = $globals->db->query("SELECT  type,arg,prenom,nom,promo
+                                     FROM  watch
+                               INNER JOIN  auth_user_md5 USING(user_id)
+                                    WHERE  watch.user_id = '$uid'
+                                 ORDER BY  arg");
+       while(list($type, $arg, $prenom, $nom, $promo) = mysql_fetch_row($res)) {
+           if($type=='promo') {
+               $this->promos[$arg] = $arg;
+           } elseif($type =='non-inscrit') {
+               $this->nonins[$arg] = Array('prenom'=>$prenom, 'nom'=>$nom, 'promo'=>$promo);
+           }
+       }
+    }
+
+    function del_promo($p) {
+       global $globals;
+       unset($this->promos[$p]);
+       $globals->db->query("DELETE FROM watch WHERE user_id='{$this->uid}' AND type='promo' AND arg='$p'");
+    }
+
+    function add_promo($p) {
+       global $globals;
+       $this->promos[$p] = $p;
+       $globals->db->query("REPLACE INTO watch (user_id,type,arg) VALUES ('{$this->uid}','promo','$p')");
+    }
+
+    function saveFlags() {
+       global $globals;
+       $globals->db->query("UPDATE auth_user_md5 SET watch='{$this->flags->value}' WHERE user_id='{$this->uid}'");
+    }
+}
+?>
diff --git a/scripts/migration/0.9.2/notifs.sql b/scripts/migration/0.9.2/notifs.sql
new file mode 100644 (file)
index 0000000..6f3e5d8
--- /dev/null
@@ -0,0 +1,14 @@
+alter table auth_user_md5 add column watch set('contacts', 'deaths') default 'contacts' not null;
+
+create table watch (
+    user_id smallint not null,
+    `type` enum('promo','non-inscrit') not null,
+    arg smallint not null,
+    primary key (user_id,type,arg)
+);
+
+create table watch_ops (
+    user_id smallint not null,
+    op enum('fiche','death','photo','ins') not null,
+    primary key (user_id,op)
+);
index 0bfe6d2..e26acd6 100644 (file)
  *  Foundation, Inc.,                                                      *
  *  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA                *
  ***************************************************************************
-        $Id: notifs.tpl,v 1.3 2004-11-04 18:24:01 x2000habouzit Exp $
+        $Id: notifs.tpl,v 1.4 2004-11-04 19:57:46 x2000habouzit Exp $
  ***************************************************************************}
 
+{dynamic}
+
 <h1>Notifications automatiques</h1>
 
 <p>Les mails sont hebdomadaires (pour éviter une trop grosse charge du serveur de mails et de ta boite mail).
@@ -36,16 +38,42 @@ S'il n'y a rien 
 
 <form action="{$smarty.server.PHP_SELF}" method="post">
   <fieldset>
-    <legend>Options</legend>
-    <input type='checkbox' name='' /> Surveiller mes contacts<br />
-    <input type='checkbox' name='/> Supprimer les camarades décédés de mes contacts
+    <legend>Contacts</legend>
+    <input type='checkbox' name='contacts' {if $notifs->flags->hasflag('contacts')}checked="checked"{/if} /> Surveiller mes contacts<br />
+    <input type='checkbox' name='deaths' {if $notifs->flags->hasflag('deaths')}checked="checked"{/if}/> Supprimer les camarades décédés de mes contacts
   </fieldset>
   <div class='center'>
-    <input type='submit' value='valider' />
+    <input type='submit' name='flags' value='valider' />
   </div>
 </form>
 
 <br />
+<h1>Surveiller des promos</h1>
+
+<p>
+Pour les promos, tu es notifié lorsque un camarade de cette promo s'inscrit, et lorsque un camarade de cette promo décède.
+</p>
+
+<form action="{$smarty.server.PHP_SELF}" method="post">
+  <fieldset>
+    <legend>Ajouter une promo</legend>
+    <input type='text' name='add_promo' maxlength='4' size='4' />
+    <input type='submit' value='ajouter' />
+    <span class='smaller'>mettre la promo sur quatre chiffres </span>
+    <br />
+    {if $notifs->promos|@count eq 0}
+    <p>Tu ne surveilles actuellement aucune promo.</p>
+    {else}
+    <p>Tu surveilles {if $notifs->promos|@count eq 1}la promo{else}les promos{/if} :</p>
+    <ul>
+      {foreach from=$notifs->promos item=p}
+      <li>{$p} <a href="?del_promo={$p}"><img src="{"images/retirer.gif"|url}" alt="retirer cette promo" /></a></li>
+      {/foreach}
+    </ul>
+    {/if}
+  </fieldset>
+</form>
+
 <h1>Surveiller des non inscrits</h1>
 
 <p>
@@ -69,16 +97,19 @@ Si un non-inscrit que tu surveille s'inscrit, il sera automatiquement ajout
   <tr>
     <td>
       {if !$nonins|@count}
-      Tu ne surveilles actuellement aucun non-inscrit.<br />
+      <p>Tu ne surveilles actuellement aucun non-inscrit.</p>
       {elseif $promos|@count}
-      Tu surveilles {if $promos|@count eq 1}le non-inscrit{else}les non-inscrits{/if} :
-      {foreach from=$nonins item=p}
-      {$p}<br />
-      {/foreach}
+      <p>Tu surveilles {if $promos|@count eq 1}le non-inscrit{else}les non-inscrits{/if} :</p>
+      <ul>
+        {foreach from=$nonins item=p}
+        <li>{$p}</li>
+        {/foreach}
+      </ul>
       {/if}
     </td>
   </tr>
 </table>
 
+{/dynamic}
 
 {* vim:set et sw=2 sts=2 sws=2: *}