Bye xorg.misc.inc.php
[platal.git] / include / notifs.inc.php
index b77bd34..33ae8eb 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /***************************************************************************
- *  Copyright (C) 2003-2007 Polytechnique.org                              *
+ *  Copyright (C) 2003-2008 Polytechnique.org                              *
  *  http://opensource.polytechnique.org/                                   *
  *                                                                         *
  *  This program is free software; you can redistribute it and/or modify   *
@@ -39,9 +39,13 @@ function register_watch_op($uid, $cid, $date='', $info='')
     if (empty($date)) {
         $date = date('Y-m-d');
     };
-    XDB::execute('REPLACE INTO watch_ops (uid,cid,known,date,info) VALUES({?},{?},NOW(),{?},{?})',
-        $uid, $cid, $date, $info);
+    XDB::execute('REPLACE INTO  watch_ops (uid,cid,known,date,info)
+                        VALUES  ({?}, {?}, NOW(), {?}, {?})',
+                 $uid, $cid, $date, $info);
     if($cid == WATCH_FICHE) {
+        if ($info) {
+            register_profile_update($uid, $info);
+        }
         XDB::execute('UPDATE auth_user_md5 SET DATE=NOW() WHERE user_id={?}', $uid);
     } elseif($cid == WATCH_INSCR) {
         XDB::execute('REPLACE INTO  contacts (uid,contact)
@@ -50,6 +54,7 @@ function register_watch_op($uid, $cid, $date='', $info='')
                              WHERE  ni_id={?}', $uid);
         XDB::execute('DELETE FROM watch_nonins WHERE ni_id={?}', $uid);
     }
+    update_NbNotifs();
 }
 
 // }}}
@@ -76,7 +81,7 @@ function _select_notifs_base($table, $mail, $where)
     $sql = "
         (
             SELECT  u.promo, u.prenom, IF(u.nom_usage='',u.nom,u.nom_usage) AS nom,
-                    u.deces != 0 AS dcd,
+                    u.deces != 0 AS dcd, (u.flags = 'femme') AS sexe,
                     a.alias AS bestalias,
                     wo.*,
                     {$our['contact_sql']} AS contact,
@@ -84,7 +89,7 @@ function _select_notifs_base($table, $mail, $where)
     if ($mail) {
         $sql.=",
             w.uid AS aid, v.prenom AS aprenom, IF(v.nom_usage='',v.nom,v.nom_usage) AS anom,
-            b.alias AS abestalias, (v.flags='femme') AS sexe, q.core_mail_fmt AS mail_fmt";
+            b.alias AS abestalias, (v.flags='femme') AS asexe, q.core_mail_fmt AS mail_fmt";
     }
 
     $sql .= "
@@ -130,29 +135,51 @@ function select_notifs($mail, $uid=null, $last=null, $iterator=true)
 }
 
 // }}}
-// {{{ function getNbNotifs
-
-function getNbNotifs()
-{
-    if (!S::has('uid')) {
-        return 0;
-    }
-    $uid       = S::v('uid', -1);
-    $watchlast = S::v('watch_last');
-
-    // selectionne les notifs de uid, sans detail sur le watcher, depuis
-    // $watchlast, meme ceux sans surveillance, non ordonnés
-    $res = select_notifs(false, $uid, $watchlast, false);
-    $n   = $res->numRows();
-    $res->free();
-    if ($n == 0) {
-        return;
+// {{{
+
+global $prf_desc;
+$prf_desc = array('nom' => 'Son patronyme',
+                  'freetext' => 'Le texte libre',
+                  'mobile' => 'Son numéro de téléphone portable',
+                  'nationalite' => 'Sa nationalité',
+                  'nick' => 'Son surnom',
+                  'web' => 'L\'adresse de son site web',
+                  'appli1' => 'Son école d\'application',
+                  'appli2' => 'Son école de post-application',
+                  'addresses' => 'Ses adresses',
+                  'section' => 'Sa section sportive',
+                  'binets' => 'La liste de ses binets',
+                  'medals' => 'Ses décorations',
+                  'cv' => 'Son Curriculum Vitae',
+                  'jobs' => 'Ses informations professionnelles',
+                  'photo' => 'Sa photographie');
+
+function get_profile_change_details($event, $limit) {
+    global $prf_desc;
+    $res = XDB::iterRow("SELECT  field
+                           FROM  watch_profile
+                          WHERE  uid = {?} AND ts > {?}
+                       ORDER BY  ts DESC",
+                         $event['uid'], $limit);
+    if ($res->total() > 0) {
+        $data = array();
+        while (list($field) = $res->next()) {
+            $data[] .= $prf_desc[$field];
+        }
+        return '<ul><li>' . implode('</li><li>', $data) . '</li></ul>';
     }
-
-    return "<a href='carnet/panel'>$n événement".($n > 1 ? 's' : '')." !</a>";
+    return null;
 }
 
 // }}}
+// {{{ function register_profile_update
+
+function register_profile_update($uid, $field) {
+    XDB::execute("REPLACE INTO  watch_profile (uid, ts, field)
+                        VALUES  ({?}, NOW(), {?})",
+                 $uid, $field);
+}
+
 // {{{ class AllNotifs
 
 class AllNotifs
@@ -175,10 +202,10 @@ class AllNotifs
             $aid = $tmp['aid'];
             if (empty($this->_data[$aid])) {
                 $this->_data[$aid] = Array("prenom" => $tmp['aprenom'], 'nom' => $tmp['anom'],
-                    'bestalias'=>$tmp['abestalias'], 'sexe' => $tmp['sexe'], 'mail_fmt' => $tmp['mail_fmt'],
+                    'bestalias'=>$tmp['abestalias'], 'sexe' => $tmp['asexe'], 'mail_fmt' => $tmp['mail_fmt'],
                     'dcd'=>$tmp['dcd']);
             }
-            unset($tmp['aprenom'], $tmp['anom'], $tmp['abestalias'], $tmp['aid'], $tmp['sexe'], $tmp['mail_fmt'], $tmp['dcd']);
+            unset($tmp['aprenom'], $tmp['anom'], $tmp['abestalias'], $tmp['aid'], $tmp['asexe'], $tmp['mail_fmt'], $tmp['dcd']);
             $this->_data[$aid]['data'][$tmp['cid']][] = $tmp;
         }
     }
@@ -208,6 +235,9 @@ class Notifs
         // depuis la semaine dernière, meme ceux sans surveillance, ordonnés
         $res = select_notifs(false, $uid, $lastweek);
         while($tmp = $res->next()) {
+            if ($tmp['cid'] == WATCH_FICHE) {
+                $tmp['data'] = get_profile_change_details($tmp, $lastweek);
+            }
             $this->_data[$tmp['cid']][$tmp['promo']][] = $tmp;
         }