From: x2000habouzit Date: Sat, 6 Nov 2004 16:08:27 +0000 (+0000) Subject: well, promos are okay X-Git-Tag: xorg/old~1044 X-Git-Url: http://git.polytechnique.org/?a=commitdiff_plain;h=afd346b44392069e48a56e28f85dfa10b1a8d080;p=platal.git well, promos are okay --- diff --git a/htdocs/carnet/notifs.php b/htdocs/carnet/notifs.php index 81e421c..22f1556 100644 --- a/htdocs/carnet/notifs.php +++ b/htdocs/carnet/notifs.php @@ -18,50 +18,44 @@ * 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(); diff --git a/include/notifs.inc.php b/include/notifs.inc.php index e5725ad..f70188e 100644 --- a/include/notifs.inc.php +++ b/include/notifs.inc.php @@ -18,79 +18,164 @@ * 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); } } diff --git a/templates/carnet/notifs.tpl b/templates/carnet/notifs.tpl index a9fd39c..e043c73 100644 --- a/templates/carnet/notifs.tpl +++ b/templates/carnet/notifs.tpl @@ -17,11 +17,15 @@ * 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} +

{$e}

+{/foreach} +

Notifications automatiques

Les mails sont hebdomadaires (pour éviter une trop grosse charge du serveur de mails et de ta boite mail). @@ -39,8 +43,7 @@ S'il n'y a rien

Contacts - flags->hasflag('contacts')}checked="checked"{/if} /> Surveiller mes contacts
- flags->hasflag('deaths')}checked="checked"{/if}/> Retirer les camarades décédés de mes contacts + watch_contacts}checked="checked"{/if} /> Surveiller mes contacts
@@ -57,17 +60,19 @@ Pour les promos, tu es notifi
Ajouter une promo - - - mettre la promo sur quatre chiffres + Tu peux surveiller des promos (mettre la promo sur 4 chiffres), + ou des plages de promos (par ex. 1990-1992) :
+ + +
- {if $notifs->promos|@count eq 0} + {if $watch->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} :

+

Tu surveilles les les promos suivantes :

    - {foreach from=$notifs->promos item=p} -
  • {$p} retirer cette promo
  • + {foreach from=$watch->promos() item=p} +
  • {if $p.0 eq $p.1}{$p.0}{else}{$p.0} à {$p.1}{/if}
  • {/foreach}
{/if}