Tweaks to login page template (Closes FS#771) [alk]
[platal.git] / include / notifs.inc.php
index 4295b16..4daeaf6 100644 (file)
@@ -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)
@@ -64,11 +68,11 @@ function _select_notifs_base($table, $mail, $where)
         ),
         'watch_promo'  => Array('wfield' => 'promo',   'ufield' => 'promo',   'need_contact' => true,
             'freq_sql' => ' AND ( wc.type = "basic" OR wc.type="near" AND (u.promo <= v.promo_sortie-2 AND u.promo_sortie >= v.promo+2) )',
-            'contact_sql' => 'NOT (c.contact IS NULL)'
+            'contact_sql' => 'IF(c.contact IS NULL, 0, 1)'
         ),
-        'watch_nonins' => Array('wfield' => 'ni_id',   'ufield' => 'user_id', 'need_contact' => false,
+        'watch_nonins' => Array('wfield' => 'ni_id',   'ufield' => 'user_id', 'need_contact' => true,
             'freq_sql' => '',
-            'contact_sql' => '0'
+            'contact_sql' => 'IF(c.contact IS NULL, 0, 1)'
         )
     );
 
@@ -153,6 +157,51 @@ function getNbNotifs()
 }
 
 // }}}
+// {{{
+
+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 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
@@ -208,6 +257,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;
         }
 
@@ -237,8 +289,8 @@ class Watch
         $this->_nonins = new NoninsNotifs($uid);
         $this->_subs = new WatchSub($uid);
         $res = XDB::query("SELECT  FIND_IN_SET('contacts',watch_flags),FIND_IN_SET('mail',watch_flags)
-            FROM  auth_user_quick
-            WHERE  user_id={?}", $uid);
+                             FROM  auth_user_quick
+                            WHERE  user_id={?}", $uid);
         list($this->watch_contacts,$this->watch_mail) = $res->fetchOneRow();
 
         $res = XDB::iterator("SELECT * FROM watch_cat");
@@ -411,12 +463,12 @@ class NoninsNotifs
     public function del($p)
     {
         unset($this->_data["$p"]);
-        XDB::execute('DELETE FROM watch_nonins WHERE uid={?} AND ni_id={?}', $this->_uid, $p);
+        XDB::execute('DELETE FROM  watch_nonins WHERE uid={?} AND ni_id={?}', $this->_uid, $p);
     }
 
     public function add($p)
     {
-        XDB::execute('INSERT INTO watch_nonins (uid,ni_id) VALUES({?},{?})', $this->_uid, $p);
+        XDB::execute('INSERT INTO  watch_nonins (uid,ni_id) VALUES({?},{?})', $this->_uid, $p);
         $res = XDB::query('SELECT  prenom,IF(nom_usage="",nom,nom_usage) AS nom,promo,user_id
                              FROM  auth_user_md5
                             WHERE  user_id={?}', $p);