From 2b784c4c144e50109c3c32a8b0b7bd931a1a4427 Mon Sep 17 00:00:00 2001 From: x2000habouzit Date: Thu, 4 Nov 2004 19:57:42 +0000 Subject: [PATCH] further work on notifs --- htdocs/carnet/notifs.php | 33 ++++++++++++++++- include/notifs.inc.php | 73 ++++++++++++++++++++++++++++++++++++++ scripts/migration/0.9.2/notifs.sql | 14 ++++++++ templates/carnet/notifs.tpl | 51 ++++++++++++++++++++------ 4 files changed, 160 insertions(+), 11 deletions(-) create mode 100644 include/notifs.inc.php create mode 100644 scripts/migration/0.9.2/notifs.sql diff --git a/htdocs/carnet/notifs.php b/htdocs/carnet/notifs.php index b4c38fb..af782bb 100644 --- a/htdocs/carnet/notifs.php +++ b/htdocs/carnet/notifs.php @@ -18,11 +18,42 @@ * 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 index 0000000..8cd93b8 --- /dev/null +++ b/include/notifs.inc.php @@ -0,0 +1,73 @@ +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 index 0000000..6f3e5d8 --- /dev/null +++ b/scripts/migration/0.9.2/notifs.sql @@ -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) +); diff --git a/templates/carnet/notifs.tpl b/templates/carnet/notifs.tpl index 0bfe6d2..e26acd6 100644 --- a/templates/carnet/notifs.tpl +++ b/templates/carnet/notifs.tpl @@ -17,9 +17,11 @@ * 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} +

Notifications automatiques

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

- Options - Surveiller mes contacts
- Supprimer les camarades décédés de mes contacts + Contacts + flags->hasflag('contacts')}checked="checked"{/if} /> Surveiller mes contacts
+ flags->hasflag('deaths')}checked="checked"{/if}/> Supprimer les camarades décédés de mes contacts
- +

+

Surveiller des promos

+ +

+Pour les promos, tu es notifié lorsque un camarade de cette promo s'inscrit, et lorsque un camarade de cette promo décède. +

+ +
+
+ Ajouter une promo + + + mettre la promo sur quatre chiffres +
+ {if $notifs->promos|@count eq 0} +

Tu ne surveilles actuellement aucune promo.

+ {else} +

Tu surveilles {if $notifs->promos|@count eq 1}la promo{else}les promos{/if} :

+
    + {foreach from=$notifs->promos item=p} +
  • {$p} retirer cette promo
  • + {/foreach} +
+ {/if} +
+
+

Surveiller des non inscrits

@@ -69,16 +97,19 @@ Si un non-inscrit que tu surveille s'inscrit, il sera automatiquement ajout {if !$nonins|@count} - Tu ne surveilles actuellement aucun non-inscrit.
+

Tu ne surveilles actuellement aucun non-inscrit.

{elseif $promos|@count} - Tu surveilles {if $promos|@count eq 1}le non-inscrit{else}les non-inscrits{/if} : - {foreach from=$nonins item=p} - {$p}
- {/foreach} +

Tu surveilles {if $promos|@count eq 1}le non-inscrit{else}les non-inscrits{/if} :

+ {/if} +{/dynamic} {* vim:set et sw=2 sts=2 sws=2: *} -- 2.1.4