* Foundation, Inc., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
***************************************************************************
- $Id: notifs.php,v 1.4 2004-11-05 14:34:04 x2000habouzit Exp $
+ $Id: notifs.php,v 1.5 2004-11-06 16:08:27 x2000habouzit Exp $
***************************************************************************/
require("auto.prepend.inc.php");
new_skinned_page('carnet/notifs.tpl', AUTH_COOKIE);
require('notifs.inc.php');
-$notifs = new Notifs($_SESSION['uid']);
+$watch = new Watch($_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 'add_nonins':
- $notifs->add_nonins($val);
- break;
-
- case 'del_nonins':
- $notifs->del_nonins($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;
+if(isset($_REQUEST['promo'])) {
+ if(preg_match('!^ *(\d{4}) *$!', $_REQUEST['promo'], $matches)) {
+ $p = intval($matches[1]);
+ if($p<1900 || $p>2100) {
+ $err[] = 'la promo entrée est invalide';
+ } else {
+ if(isset($_REQUEST['add_promo'])) $watch->_promos->add($p);
+ if(isset($_REQUEST['del_promo'])) $watch->_promos->del($p);
+ }
+ } elseif (preg_match('!^ *(\d{4}) *- *(\d{4}) *$!', $_REQUEST['promo'], $matches)) {
+ $p1 = intval($matches[1]);
+ $p2 = intval($matches[2]);
+ if($p1<1900 || $p1>2100) {
+ $err[] = 'la première promo de la plage entrée est invalide';
+ } elseif($p2<1900 || $p2>2100) {
+ $err[] = 'la seconde promo de la plage entrée est invalide';
+ } else {
+ if(isset($_REQUEST['add_promo'])) $watch->_promos->addRange($p1,$p2);
+ if(isset($_REQUEST['del_promo'])) $watch->_promos->delRange($p1,$p2);
+ }
+ } else {
+ $err[] = "La promo (ou la plage de promo) entrée est dans un format incorrect.";
}
}
-$page->assign_by_ref('notifs', $notifs);
+
+$page->assign_by_ref('watch', $watch);
+$page->assign_by_ref('err', $err);
$page->run();
* Foundation, Inc., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
***************************************************************************
- $Id: notifs.inc.php,v 1.5 2004-11-05 14:34:04 x2000habouzit Exp $
+ $Id: notifs.inc.php,v 1.6 2004-11-06 16:08:27 x2000habouzit Exp $
***************************************************************************/
require_once('diogenes.flagset.inc.php');
-function register_watch_op($uid, $type) {
- global $globals;
- if(in_array($type, Array('fiche','death','photo','ins'))) {
- $globals->db->query("REPLACE INTO watch_ops (user_id,op) VALUES('$uid','$type')");
+class Watch {
+ var $_uid;
+ var $_promos;
+ var $_nonins;
+ var $_cats;
+ var $_subs;
+ var $watch_contacts;
+ var $watch_last;
+
+ function Watch($uid) {
+ global $globals;
+ $this->_uid = $uid;
+ $this->_promos = new PromoNotifs($uid);
+ $this->_nonins = new NoninsNotifs($uid);
+ $this->_cats = new WatchCat();
+ $this->_subs = new WatchSub($uid);
+ $res = $globals->db->query("SELECT watch_contacts,watch_last FROM auth_user_quick WHERE user_id='$uid'");
+ list($this->watch_contacts, $this->watch_last) = mysql_fetch_row($res);
+ mysql_free_result($res);
}
- if($type == 'fiche') {
- $globals->db->query("UPDATE auth_user_md5 SET DATE=NOW() WHERE user_id='$uid'");
+
+ function promos() {
+ return $this->_promos->toRanges();
}
}
-class Notifs {
- var $uid;
- var $flags;
- var $promos = Array();
- var $nonins = Array();
+class WatchCat {
+ var $_data = Array();
+
+ function WatchCat() {
+ global $globals;
+ $res = $globals->db->query("SELECT * FROM watch_cat");
+ while($tmp = mysql_fetch_assoc($res)) $this->_data[$tmp['id']] = $tmp;
+ mysql_free_result($res);
+ }
+}
- function Notifs($uid) {
+class WatchSub {
+ var $_uid;
+ var $_data;
+
+ function WatchSub($uid) {
+ $this->_uid = $uid;
global $globals;
- $this->uid = $uid;
+ $res = $globals->db->query("SELECT cid FROM watch_sub WHERE uid='$uid'");
+ while(list($c) = mysql_fetch_row($res)) $this->_data[$c] = $c;
+ mysql_free_result($res);
+ }
+}
- $res = $globals->db->query("SELECT watch FROM auth_user_md5 WHERE user_id = '$uid'");
- list($flags) = mysql_fetch_row($res);
+class PromoNotifs {
+ var $_uid;
+ var $_data = Array();
+
+ function PromoNotifs($uid) {
+ $this->_uid = $uid;
+ global $globals;
+ $res = $globals->db->query("SELECT promo FROM watch_promo WHERE uid='$uid' ORDER BY promo");
+ while(list($p) = mysql_fetch_row($res)) $this->_data[intval($p)] = intval($p);
mysql_free_result($res);
- $this->flags = new FlagSet($flags);
-
- $res = $globals->db->query("SELECT type,arg,prenom,nom,promo,u.user_id
- FROM watch AS w
- LEFT JOIN auth_user_md5 AS u ON(u.user_id = w.arg)
- WHERE w.user_id = '$uid'
- ORDER BY promo,nom,arg");
- while(list($type, $arg, $prenom, $nom, $promo, $uid) = 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, 'uid'=>$uid);
- }
- }
}
- function del_nonins($p) {
+ function add($p) {
+ global $globals;
+ $promo = intval($p);
+ $globals->db->query("REPLACE INTO watch_promo (uid,promo) VALUES('{$this->_uid}',$promo)");
+ $this->_data[$promo] = $promo;
+ asort($this->_data);
+ }
+
+ function del($p) {
global $globals;
- unset($this->nonins[$p]);
- $globals->db->query("DELETE FROM watch WHERE user_id='{$this->uid}' AND type='non-inscrit' AND arg='$p'");
+ $promo = intval($p);
+ $globals->db->query("DELETE FROM watch_promo WHERE uid='{$this->_uid}' AND promo=$promo");
+ unset($this->_data[$promo]);
+ }
+
+ function addRange($_p1,$_p2) {
+ global $globals;
+ $p1 = intval($_p1);
+ $p2 = intval($_p2);
+ $values = Array();
+ for($i = min($p1,$p2); $i<=max($p1,$p2); $i++) {
+ $values[] = "('{$this->_uid}',$i)";
+ $this->_data[$i] = $i;
+ }
+ $globals->db->query("REPLACE INTO watch_promo (uid,promo) VALUES ".join(',',$values));
+ asort($this->_data);
}
- function add_nonins($p) {
+ function delRange($_p1,$_p2) {
global $globals;
- $globals->db->query("INSERT INTO watch (user_id,type,arg) VALUES('{$this->uid}','non-inscrit','$p')");
- $res = $globals->db->query(" SELECT prenom,nom,promo,user_id FROM auth_user_md5 WHERE user_id='$p'");
- $this->nonins[$p] = mysql_fetch_assoc($res);
- mysql_free_result($res);
+ $p1 = intval($_p1);
+ $p2 = intval($_p2);
+ $where = Array();
+ for($i = min($p1,$p2); $i<=max($p1,$p2); $i++) {
+ $where[] = "promo=$i";
+ unset($this->_data[$i]);
+ }
+ $globals->db->query("DELETE FROM watch_promo WHERE uid='{$this->_uid}' AND (".join(' OR ',$where).')');
+ }
+
+ function toRanges() {
+ $ranges = Array();
+ $I = Array();
+ foreach($this->_data as $promo) {
+ if(!isset($I[0])) {
+ $I = Array($promo,$promo);
+ }
+ elseif($I[1]+1 == $promo) {
+ $I[1] ++;
+ }
+ else {
+ $ranges[] = $I;
+ $I = Array($promo,$promo);
+ }
+ }
+ if(isset($I[0])) $ranges[] = $I;
+ return $ranges;
}
+}
- function del_promo($p) {
+
+class NoninsNotifs {
+ var $_uid;
+ var $_data = Array();
+
+ function NoninsNotifs($uid) {
global $globals;
- unset($this->promos[$p]);
- $globals->db->query("DELETE FROM watch WHERE user_id='{$this->uid}' AND type='promo' AND arg='$p'");
+ $this->_uid = $uid;
+ $res = $globals->db->query("SELECT u.prenom,IF(u.epouse='',u.nom,u.epouse) AS nom, u.promo, u.user_id
+ FROM watch_nonins AS w
+ INNER JOIN auth_user_md5 AS u ON (u.user_id = w.ni_id)
+ WHERE w.uid = '$uid'
+ ORDER BY promo,nom");
+ while($tmp = mysql_fetch_assoc($res)) $this->_data[$tmp['user_id']] = $tmp;
+ mysql_free_result($res);
}
- function add_promo($p) {
+ function del($p) {
global $globals;
- $this->promos[$p] = $p;
- $globals->db->query("REPLACE INTO watch (user_id,type,arg) VALUES ('{$this->uid}','promo','$p')");
+ unset($this->_data["$p"]);
+ $globals->db->query("DELETE FROM watch_nonins WHERE uid='{$this->_uid}' AND ni_id='$p'");
}
- function saveFlags() {
+ function add($p) {
global $globals;
- $globals->db->query("UPDATE auth_user_md5 SET watch='{$this->flags->value}' WHERE user_id='{$this->uid}'");
+ $globals->db->query("INSERT INTO watch_nonins (uid,ni_id) VALUES('{$this->_uid}','$p')");
+ $res = $globals->db->query("SELECT prenom,IF(u.epouse='',u.nom,u.epouse),promo,user_id
+ FROM auth_user_md5
+ WHERE user_id='$p'");
+ $this->_data["$p"] = mysql_fetch_assoc($res);
+ mysql_free_result($res);
}
}
* Foundation, Inc., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
***************************************************************************
- $Id: notifs.tpl,v 1.9 2004-11-05 15:23:41 x2000habouzit Exp $
+ $Id: notifs.tpl,v 1.10 2004-11-06 16:08:28 x2000habouzit Exp $
***************************************************************************}
{dynamic}
+{foreach from=$err item=e}
+<p class='erreur'>{$e}</p>
+{/foreach}
+
<h1>Notifications automatiques</h1>
<p>Les mails sont hebdomadaires (pour éviter une trop grosse charge du serveur de mails et de ta boite mail).
<form action="{$smarty.server.PHP_SELF}" method="post">
<fieldset>
<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}/> Retirer les camarades décédés de mes contacts
+ <input type='checkbox' name='contacts' {if $watch->watch_contacts}checked="checked"{/if} /> Surveiller mes contacts<br />
</fieldset>
<div class='center'>
<input type='submit' name='flags' value='valider' />
<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>
+ Tu peux surveiller des promos (mettre la promo sur 4 chiffres),
+ ou des plages de promos (par ex. 1990-1992) : <br />
+ <input type='text' name='promo' />
+ <input type='submit' name='add_promo' value='ajouter' />
+ <input type='submit' name='del_promo' value='retirer' />
<br />
- {if $notifs->promos|@count eq 0}
+ {if $watch->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>
+ <p>Tu surveilles les les promos suivantes :</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 from=$watch->promos() item=p}
+ <li>{if $p.0 eq $p.1}{$p.0}{else}{$p.0} à {$p.1}{/if}</li>
{/foreach}
</ul>
{/if}