some rework, now have to work on the mail
authorx2000habouzit <x2000habouzit>
Sun, 7 Nov 2004 11:54:07 +0000 (11:54 +0000)
committerx2000habouzit <x2000habouzit>
Sun, 7 Nov 2004 11:54:07 +0000 (11:54 +0000)
htdocs/carnet/notifs.php
htdocs/inscription/step4.php
include/notifs.inc.php
scripts/migration/0.9.2/notifs.sql
templates/carnet/notifs.tpl

index 0bb3ca1..d0ca80e 100644 (file)
@@ -18,7 +18,7 @@
  *  Foundation, Inc.,                                                      *
  *  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA                *
  ***************************************************************************
-        $Id: notifs.php,v 1.6 2004-11-06 17:22:12 x2000habouzit Exp $
+        $Id: notifs.php,v 1.7 2004-11-07 11:54:07 x2000habouzit Exp $
  ***************************************************************************/
 
 require("auto.prepend.inc.php");
@@ -57,6 +57,11 @@ if(isset($_REQUEST['promo'])) {
 if(isset($_REQUEST['del_nonins'])) $watch->_nonins->del($_REQUEST['del_nonins']);
 if(isset($_REQUEST['add_nonins'])) $watch->_nonins->add($_REQUEST['add_nonins']);
 if(isset($_REQUEST['subs'])) $watch->_subs->update('sub');
+if(isset($_REQUEST['flags'])) {
+    $watch->watch_contacts = !empty($_REQUEST['contacts']);
+    $watch->watch_mail     = !empty($_REQUEST['mail']);
+    $watch->saveFlags();
+}
 
 $page->assign_by_ref('watch', $watch);
 $page->assign_by_ref('err', $err);
index 3791fd3..7808a3b 100644 (file)
@@ -18,7 +18,7 @@
  *  Foundation, Inc.,                                                      *
  *  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA                *
  ***************************************************************************
-        $Id: step4.php,v 1.9 2004-11-06 17:37:22 x2000habouzit Exp $
+        $Id: step4.php,v 1.10 2004-11-07 11:54:07 x2000habouzit Exp $
  ***************************************************************************/
 
 require("auto.prepend.inc.php");
@@ -123,6 +123,7 @@ if (!empty($_REQUEST['ref'])) {
     $globals->db->query("INSERT INTO ins_confirmees SET id=$uid");
     require_once('notifs.inc.php');
     register_watch_op($uid,WATCH_INSCR);
+    inscription_notifs_base($uid);
 
     // insérer une ligne dans user_changes pour que les coordonnées complè
     // soient envoyées a l'
index e09854d..d65de98 100644 (file)
  *  Foundation, Inc.,                                                      *
  *  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA                *
  ***************************************************************************
-        $Id: notifs.inc.php,v 1.11 2004-11-06 22:34:17 x2000habouzit Exp $
+        $Id: notifs.inc.php,v 1.12 2004-11-07 11:54:08 x2000habouzit Exp $
  ***************************************************************************/
 
 define("WATCH_FICHE", 1);
 define("WATCH_INSCR", 2);
 define("WATCH_DEATH", 3);
 
+function inscription_notifs_base($uid) {
+    global $globals;
+    $globals->db->query("REPLACE INTO  watch_sub (uid,cid)
+                               SELECT  '$uid',id
+                                FROM  watch_cat");
+}
+
 function register_watch_op($uid,$cid,$date='',$info='') {
     global $globals;
     $date = empty($date) ? 'NOW()' : "'$date'";
@@ -49,7 +56,7 @@ function getNbNotifs() {
        INNER JOIN  watch_sub       AS ws ON(wo.cid=ws.cid AND ws.uid=c.uid)
        INNER JOIN  auth_user_md5   AS u  ON(u.user_id = wo.uid)
         LEFT JOIN  aliases         AS a  ON(u.user_id = a.id AND a.type='a_vie')
-            WHERE  q.user_id = '$uid' AND q.watch_contacts=1 AND wo.known > q.watch_last
+            WHERE  q.user_id = '$uid' AND FIND_IN_SET('contacts',q.watch_flags) AND wo.known > q.watch_last
     ) UNION DISTINCT (
            SELECT  u.promo, u.prenom, IF(u.epouse='',u.nom,u.epouse) AS nom, a.alias AS forlife,
                    wo.*, NOT (c.contact IS NULL) AS contact, (u.perms='admin' OR u.perms='user') AS inscrit
@@ -58,7 +65,7 @@ function getNbNotifs() {
        INNER JOIN  auth_user_quick AS q  ON(q.user_id = w.uid)
         LEFT JOIN  contacts        AS c  ON(w.uid = c.uid AND c.contact=u.user_id)
        INNER JOIN  watch_ops       AS wo ON(wo.uid=u.user_id)
-       INNER JOIN  watch_sub       AS ws ON(wo.cid=ws.cid)
+       INNER JOIN  watch_sub       AS ws ON(wo.cid=ws.cid AND ws.uid=w.uid)
        INNER JOIN  watch_cat       AS wc ON(wc.id=wo.cid AND wc.frequent=0)
         LEFT JOIN  aliases         AS a  ON(u.user_id = a.id AND a.type='a_vie')
             WHERE  w.uid = '$uid' AND wo.known > q.watch_last
@@ -69,7 +76,7 @@ function getNbNotifs() {
        INNER JOIN  auth_user_quick AS q  ON(q.user_id = w.uid)
        INNER JOIN  auth_user_md5   AS u  ON(w.ni_id=u.user_id)
        INNER JOIN  watch_ops       AS wo ON(wo.uid=u.user_id)
-       INNER JOIN  watch_sub       AS ws ON(wo.cid=ws.cid)
+       INNER JOIN  watch_sub       AS ws ON(wo.cid=ws.cid AND ws.uid=w.uid)
        INNER JOIN  watch_cat       AS wc ON(wc.id=wo.cid)
         LEFT JOIN  aliases         AS a  ON(u.user_id = a.id AND a.type='a_vie')
             WHERE  w.uid = '$uid' AND wo.known > q.watch_last
@@ -108,10 +115,10 @@ class Notifs {
                  FROM  auth_user_quick AS q
            INNER JOIN  contacts        AS c  ON(q.user_id = c.uid)
            INNER JOIN  watch_ops       AS wo ON(wo.uid=c.contact)
-           INNER JOIN  watch_sub       AS ws ON(wo.cid=ws.cid AND ws.uid=c.uid)
+           INNER JOIN  watch_sub       AS ws ON(wo.cid=ws.cid AND ws.uid=q.user_id)
            INNER JOIN  auth_user_md5   AS u  ON(u.user_id = wo.uid)
             LEFT JOIN  aliases         AS a  ON(u.user_id = a.id AND a.type='a_vie')
-                WHERE  q.user_id = '$uid' AND q.watch_contacts=1 AND wo.known > $lastweek
+                WHERE  q.user_id = '$uid' AND FIND_IN_SET('contacts',q.watch_flags) AND wo.known > $lastweek
        ) UNION DISTINCT (
                SELECT  u.promo, u.prenom, IF(u.epouse='',u.nom,u.epouse) AS nom, a.alias AS forlife,
                        wo.*, NOT (c.contact IS NULL) AS contact, (u.perms='admin' OR u.perms='user') AS inscrit
@@ -119,7 +126,7 @@ class Notifs {
            INNER JOIN  auth_user_md5   AS u  USING(promo)
             LEFT JOIN  contacts        AS c  ON(w.uid = c.uid AND c.contact=u.user_id)
            INNER JOIN  watch_ops       AS wo ON(wo.uid=u.user_id)
-           INNER JOIN  watch_sub       AS ws ON(wo.cid=ws.cid)
+           INNER JOIN  watch_sub       AS ws ON(wo.cid=ws.cid AND ws.uid=w.uid)
            INNER JOIN  watch_cat       AS wc ON(wc.id=wo.cid AND wc.frequent=0)
             LEFT JOIN  aliases         AS a  ON(u.user_id = a.id AND a.type='a_vie')
                 WHERE  w.uid = '$uid' AND wo.known > $lastweek
@@ -129,7 +136,7 @@ class Notifs {
                  FROM  watch_nonins    AS w
            INNER JOIN  auth_user_md5   AS u  ON(w.ni_id=u.user_id)
            INNER JOIN  watch_ops       AS wo ON(wo.uid=u.user_id)
-           INNER JOIN  watch_sub       AS ws ON(wo.cid=ws.cid)
+           INNER JOIN  watch_sub       AS ws ON(wo.cid=ws.cid AND ws.uid=w.uid)
            INNER JOIN  watch_cat       AS wc ON(wc.id=wo.cid)
             LEFT JOIN  aliases         AS a  ON(u.user_id = a.id AND a.type='a_vie')
                 WHERE  w.uid = '$uid' AND wo.known > $lastweek
@@ -152,6 +159,7 @@ class Watch {
     var $_cats = Array();
     var $_subs;
     var $watch_contacts;
+    var $watch_mail;
     
     function Watch($uid) {
        global $globals;
@@ -159,8 +167,10 @@ class Watch {
        $this->_promos = new PromoNotifs($uid);
        $this->_nonins = new NoninsNotifs($uid);
        $this->_subs = new WatchSub($uid);
-       $res = $globals->db->query("SELECT watch_contacts FROM auth_user_quick WHERE user_id='$uid'");
-       list($this->watch_contacts) = mysql_fetch_row($res);
+       $res = $globals->db->query("SELECT  FIND_IN_SET('contacts',watch_flags),FIND_IN_SET('mail',watch_flags)
+                                     FROM  auth_user_quick
+                                    WHERE  user_id='$uid'");
+       list($this->watch_contacts,$this->watch_mail) = mysql_fetch_row($res);
        mysql_free_result($res);
        
        $res = $globals->db->query("SELECT * FROM watch_cat");
@@ -168,6 +178,15 @@ class Watch {
        mysql_free_result($res);
     }
 
+    function saveFlags() {
+       global $globals;
+       $flags = "";
+       if($this->watch_contacts) $flags = "contacts";
+       if($this->watch_mail) $flags .= ($flags ? ',' : '')."mail";
+       $globals->db->query("UPDATE auth_user_quick SET watch_flags='$flags' WHERE user_id='{$this->_uid}'");
+       
+    }
+
     function cats() {
        return $this->_cats;
     }
index 9e36a24..76ef9c0 100644 (file)
@@ -1,5 +1,5 @@
 alter table aliases add index (type);
-alter table auth_user_quick add column watch_contacts tinyint(1) not null default 1;
+alter table auth_user_quick add column watch_flags set('contacts','mail') not null default 'contacts';
 alter table auth_user_quick add column watch_last timestamp not null;
 
 create table watch_cat (
@@ -42,4 +42,10 @@ create table watch_promo (
     primary key (uid,promo)
 );
 
+replace into  watch_sub
+     select  u.user_id,id
+       from  auth_user_md5 AS u
+       join  watch_cat
+      where  u.perms != 'non-inscrit';
+
 
index 4ce5de6..172fe79 100644 (file)
@@ -17,7 +17,7 @@
  *  Foundation, Inc.,                                                      *
  *  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA                *
  ***************************************************************************
-        $Id: notifs.tpl,v 1.12 2004-11-07 09:36:03 x2000habouzit Exp $
+        $Id: notifs.tpl,v 1.13 2004-11-07 11:54:08 x2000habouzit Exp $
  ***************************************************************************}
 
 {dynamic}
@@ -55,6 +55,8 @@ S'il n'y a rien 
   <fieldset>
     <legend>Contacts</legend>
     <input type='checkbox' name='contacts' {if $watch->watch_contacts}checked="checked"{/if} /> Surveiller mes contacts<br />
+    <input type='checkbox' name='mail' {if $watch->watch_mail}checked="checked"{/if} />
+      Recevoir un mail hebdomadaire des évènements que je n'ai pas vus sur le site<br />
   </fieldset>
   <div class='center'>
     <input type='submit' name='flags' value='valider' />