X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=modules%2Fxnetgrp.php;h=c5e2dc1a7efaad6393fc2e85b52346c797feb0d7;hb=2a557a092265981fcb53edfd38ed0dde353d9c24;hp=a45d3705640254371ec1d64cf7f42a38b9dd8e0a;hpb=0cc4c07df8bc6a10c893d0f91aae02e4856f3123;p=platal.git
diff --git a/modules/xnetgrp.php b/modules/xnetgrp.php
index a45d370..c5e2dc1 100644
--- a/modules/xnetgrp.php
+++ b/modules/xnetgrp.php
@@ -65,14 +65,15 @@ class XnetGrpModule extends PLModule
function handlers()
{
return array(
- '%grp' => $this->make_hook('index', AUTH_PUBLIC),
- '%grp/asso.php' => $this->make_hook('index', AUTH_PUBLIC),
- '%grp/logo' => $this->make_hook('logo', AUTH_PUBLIC),
- '%grp/edit' => $this->make_hook('edit', AUTH_MDP),
- '%grp/mail' => $this->make_hook('mail', AUTH_MDP),
- '%grp/annuaire' => $this->make_hook('annuaire', AUTH_MDP),
- '%grp/subscribe' => $this->make_hook('subscribe', AUTH_MDP),
- '%grp/paiement' => $this->make_hook('paiement', AUTH_MDP),
+ '%grp' => $this->make_hook('index', AUTH_PUBLIC),
+ '%grp/asso.php' => $this->make_hook('index', AUTH_PUBLIC),
+ '%grp/logo' => $this->make_hook('logo', AUTH_PUBLIC),
+ '%grp/edit' => $this->make_hook('edit', AUTH_MDP),
+ '%grp/mail' => $this->make_hook('mail', AUTH_MDP),
+ '%grp/annuaire' => $this->make_hook('annuaire', AUTH_MDP),
+ '%grp/annuaire/vcard' => $this->make_hook('vcard', AUTH_MDP),
+ '%grp/subscribe' => $this->make_hook('subscribe', AUTH_MDP),
+ '%grp/paiement' => $this->make_hook('paiement', AUTH_MDP),
'%grp/admin/annuaire'
=> $this->make_hook('admin_annuaire', AUTH_MDP),
@@ -83,23 +84,86 @@ class XnetGrpModule extends PLModule
=> $this->make_hook('admin_member_new', AUTH_MDP),
'%grp/member/del'
=> $this->make_hook('admin_member_del', AUTH_MDP),
+
+ '%grp/rss' => $this->make_hook('rss', AUTH_PUBLIC),
+ '%grp/announce/new' => $this->make_hook('edit_announce', AUTH_MDP),
+ '%grp/announce/edit' => $this->make_hook('edit_announce', AUTH_MDP),
+ '%grp/admin/announces' => $this->make_hook('admin_announce', AUTH_MDP),
);
}
function handler_index(&$page, $arg = null)
{
- global $globals;
+ global $globals, $platal;
if (!is_null($arg)) {
return PL_NOT_FOUND;
}
$page->changeTpl('xnet/groupe/asso.tpl');
- $page->useMenu();
$page->setType($globals->asso('cat'));
+ $page->assign('is_admin', may_update());
$page->assign('is_member', is_member());
$page->assign('logged', S::logged());
+ if (S::logged()) {
+ if (Env::has('read')) {
+ XDB::query('DELETE r.*
+ FROM groupex.announces_read AS r
+ INNER JOIN groupex.announces AS a ON a.id = r.announce_id
+ WHERE peremption < CURRENT_DATE()');
+ XDB::query('INSERT INTO groupex.announces_read
+ VALUES ({?}, {?})',
+ Env::i('read'), S::i('uid'));
+ pl_redirect("");
+ }
+ if (Env::has('unread')) {
+ XDB::query('DELETE FROM groupex.announces_read
+ WHERE announce_id={?} AND user_id={?}',
+ Env::i('unread'), S::i('uid'));
+ pl_redirect("#art" . Env::i('unread'));
+ }
+ $arts = XDB::iterator("SELECT a.*, u.nom, u.prenom, u.promo, l.alias AS forlife
+ FROM groupex.announces AS a
+ INNER JOIN auth_user_md5 AS u USING(user_id)
+ INNER JOIN aliases AS l ON (u.user_id = l.id AND l.type = 'a_vie')
+ LEFT JOIN groupex.announces_read AS r ON (r.user_id = {?} AND r.announce_id = a.id)
+ WHERE asso_id = {?} AND peremption >= CURRENT_DATE()
+ AND (promo_min = 0 OR promo_min <= {?})
+ AND (promo_max = 0 OR promo_max >= {?})
+ AND r.announce_id IS NULL
+ ORDER BY a.peremption",
+ S::i('uid'), $globals->asso('id'), S::i('promo'), S::i('promo'));
+ $index = XDB::iterator("SELECT a.id, a.titre, r.user_id IS NULL AS nonlu
+ FROM groupex.announces AS a
+ LEFT JOIN groupex.announces_read AS r ON (a.id = r.announce_id AND r.user_id = {?})
+ WHERE asso_id = {?} AND peremption >= CURRENT_DATE()
+ AND (promo_min = 0 OR promo_min <= {?})
+ AND (promo_max = 0 OR promo_max >= {?})
+ ORDER BY a.peremption",
+ S::i('uid'), $globals->asso('id'), S::i('promo'), S::i('promo'));
+ $page->assign('article_index', $index);
+ } else {
+ $arts = XDB::iterator("SELECT a.*, u.nom, u.prenom, u.promo
+ FROM groupex.announces AS a
+ INNER JOIN auth_user_md5 AS u USING(user_id)
+ WHERE asso_id = {?} AND peremption >= CURRENT_DATE()
+ AND FIND_IN_SET(a.flags, 'public')",
+ $globals->asso('id'));
+ }
+
+ if (!S::has('core_rss_hash')) {
+ $page->setRssLink("Polytechnique.net :: {$globals->asso("nom")} :: News publiques",
+ "rss/rss.xml");
+ } else {
+ $page->setRssLink("Polytechnique.net :: {$globals->asso("nom")} :: News",
+ 'rss/'.S::v('forlife') .'/'.S::v('core_rss_hash').'/rss.xml');
+ }
+
+ require_once('url_catcher.inc.php');
+ $page->register_modifier('url_catcher', 'url_catcher');
+ $page->assign('articles', $arts);
+
$page->assign('asso', $globals->asso());
}
@@ -108,8 +172,8 @@ class XnetGrpModule extends PLModule
global $globals;
$res = XDB::query("SELECT logo, logo_mime
- FROM groupex.asso WHERE id = {?}",
- $globals->asso('id'));
+ FROM groupex.asso WHERE id = {?}",
+ $globals->asso('id'));
list($logo, $logo_mime) = $res->fetchOneRow();
if (!empty($logo)) {
@@ -125,7 +189,7 @@ class XnetGrpModule extends PLModule
header('Last-Modified:' . gmdate('D, d M Y H:i:s') . ' GMT');
header('Cache-Control: no-cache, must-revalidate');
header('Pragma: no-cache');
- readfile(dirname(__FILE__).'/../htdocs.net/images/dflt_carre.jpg');
+ readfile(dirname(__FILE__).'/../htdocs/images/dflt_carre.jpg');
}
exit;
@@ -198,13 +262,10 @@ class XnetGrpModule extends PLModule
{
global $globals;
- require_once 'lists.inc.php';
-
new_groupadmin_page('xnet/groupe/mail.tpl');
- $client =& lists_xmlrpc(S::v('uid'),
- S::v('password'),
- $globals->asso('mail_domain'));
- $page->assign('listes', $client->get_lists());
+ $mmlist = new MMList(S::v('uid'), S::v('password'),
+ $globals->asso('mail_domain'));
+ $page->assign('listes', $mmlist->get_lists());
if (Post::has('send')) {
$from = Post::v('from');
@@ -214,7 +275,7 @@ class XnetGrpModule extends PLModule
$mls = array_keys(Env::v('ml', array()));
require_once 'xnet/mail.inc.php';
- $tos = get_all_redirects(Post::has('membres'), $mls, $client);
+ $tos = get_all_redirects(Post::has('membres'), $mls, $mmlist);
send_xnet_mails($from, $sujet, $body, $tos, Post::v('replyto'));
$page->kill("Mail envoyé !");
$page->assign('sent', true);
@@ -235,12 +296,14 @@ class XnetGrpModule extends PLModule
$page->assign('admin', may_update());
+ $sort = Env::v('order');
switch (Env::v('order')) {
case 'promo' : $group = 'promo'; $tri = 'promo_o DESC, nom, prenom'; break;
case 'promo_inv': $group = 'promo'; $tri = 'promo_o, nom, prenom'; break;
case 'alpha_inv': $group = 'initiale'; $tri = 'nom DESC, prenom DESC, promo'; break;
- default : $group = 'initiale'; $tri = 'nom, prenom, promo';
+ default : $group = 'initiale'; $tri = 'nom, prenom, promo'; $sort = 'alpha';
}
+ $page->assign('sort', $sort);
if ($group == 'initiale')
$res = XDB::iterRow(
@@ -317,19 +380,35 @@ class XnetGrpModule extends PLModule
LEFT JOIN auth_user_md5 AS u ON ( u.user_id = m.uid )
LEFT JOIN aliases AS a ON ( a.id = m.uid AND a.type='a_vie' )
WHERE m.asso_id = {?} $ini
+ AND (m.origine = 'ext' OR u.perms != 'pending')
ORDER BY $tri
LIMIT {?},{?}", $globals->asso('id'), $ofs*NB_PER_PAGE, NB_PER_PAGE);
$page->assign('ann', $ann);
}
+ function handler_vcard(&$page, $photos = null)
+ {
+ global $globals;
+
+ if (($globals->asso('pub') == 'public' && is_member()) || may_update()) {
+ $res = XDB::query('SELECT uid
+ FROM groupex.membres
+ WHERE asso_id = {?}', $globals->asso('id'));
+ require_once('vcard.inc.php');
+ $vcard = new VCard($res->fetchColumn(), $photos == 'photos', 'Membre du groupe ' . $globals->asso('nom'));
+ $vcard->do_page($page);
+ } else {
+ return PL_NOTALLOWED;
+ }
+ }
+
function handler_subscribe(&$page, $u = null)
{
global $globals;
$page->changeTpl('xnet/groupe/inscrire.tpl');
- $page->useMenu();
$page->setType($globals->asso('cat'));
$page->assign('asso', $globals->asso());
$page->assign('admin', may_update());
@@ -356,13 +435,13 @@ class XnetGrpModule extends PLModule
$u, $globals->asso('id'));
$n = $res->fetchOneCell();
if ($n) {
- $page->trig("$prenom $nom est déjà membre du groupe !");
+ $page->kill("$prenom $nom est déjà membre du groupe !");
return;
}
elseif (Env::has('accept'))
{
XDB::execute("INSERT INTO groupex.membres
- VALUES ({?}, {?}, 'membre', 'X', NULL, NULL, NULL, NULL)",
+ VALUES ({?}, {?}, 'membre', 'X', NULL, NULL, NULL, NULL, NULL)",
$globals->asso('id'), $uid);
require_once 'diogenes/diogenes.hermes.inc.php';
$mailer = new HermesMailer();
@@ -525,20 +604,19 @@ class XnetGrpModule extends PLModule
{
global $globals;
- require_once 'lists.inc.php';
require_once 'xnet/mail.inc.php';
new_groupadmin_page('xnet/groupe/annuaire-admin.tpl');
- $client =& lists_xmlrpc(S::v('uid'), S::v('password'),
- $globals->asso('mail_domain'));
- $lists = $client->get_lists();
+ $mmlist = new MMList(S::v('uid'), S::v('password'),
+ $globals->asso('mail_domain'));
+ $lists = $mmlist->get_lists();
if (!$lists) $lists = array();
$listes = array_map(create_function('$arr', 'return $arr["list"];'), $lists);
$subscribers = array();
foreach ($listes as $list) {
- list(,$members) = $client->get_members($list);
+ list(,$members) = $mmlist->get_members($list);
$mails = array_map(create_function('$arr', 'return $arr[1];'), $members);
$subscribers = array_unique(array_merge($subscribers, $mails));
}
@@ -635,13 +713,12 @@ class XnetGrpModule extends PLModule
if (($domain = $globals->asso('mail_domain')) && empty($user_same_email)) {
- require 'lists.inc.php';
- $client =& lists_xmlrpc(S::v('uid'), S::v('password'), $domain);
- $listes = $client->get_lists($user['email2']);
+ $mmlist = new MMList(S::v('uid'), S::v('password'), $domain);
+ $listes = $mmlist->get_lists($user['email2']);
foreach ($listes as $liste) {
if ($liste['sub'] == 2) {
- $client->mass_unsubscribe($liste['list'], Array($user['email2']));
+ $mmlist->mass_unsubscribe($liste['list'], Array($user['email2']));
$page->trig("{$user['prenom']} {$user['nom']} a été"
." désinscrit de {$liste['list']}");
} elseif ($liste['sub']) {
@@ -675,11 +752,12 @@ class XnetGrpModule extends PLModule
return PL_NOT_FOUND;
}
- require 'lists.inc.php';
- $client =& lists_xmlrpc(S::v('uid'), S::v('password'),
- $globals->asso('mail_domain'));
+ $mmlist = new MMList(S::v('uid'), S::v('password'),
+ $globals->asso('mail_domain'));
if (Post::has('change')) {
+ $email_changed = ($user['origine'] != 'X' && $user['email'] != Post::v('email'));
+ $from_email = $user['email'];
if ($user['origine'] != 'X') {
XDB::query('UPDATE groupex.membres
SET prenom={?}, nom={?}, email={?}, sexe={?}
@@ -706,16 +784,26 @@ class XnetGrpModule extends PLModule
foreach (Env::v('ml1', array()) as $ml => $state) {
$ask = empty($_REQUEST['ml2'][$ml]) ? 0 : 2;
- if ($ask == $state) continue;
+ if ($ask == $state) {
+ if ($state) {
+ $mmlist->replace_email($ml, $from_email, $user['email2']);
+ $page->trig("L'abonnement de {$user['prenom']} {$user['nom']} à $ml@ a été mis à jour");
+ }
+ continue;
+ }
if ($state == '1') {
$page->trig("{$user['prenom']} {$user['nom']} a "
."actuellement une demande d'inscription en "
."cours sur $ml@ !!!");
} elseif ($ask) {
- $client->mass_subscribe($ml, Array($user['email2']));
+ $mmlist->mass_subscribe($ml, Array($user['email2']));
$page->trig("{$user['prenom']} {$user['nom']} a été abonné à $ml@");
} else {
- $client->mass_unsubscribe($ml, Array($user['email2']));
+ if ($email_changed) {
+ $mmlist->mass_unsubscribe($ml, Array($from_email));
+ } else {
+ $mmlist->mass_unsubscribe($ml, Array($user['email2']));
+ }
$page->trig("{$user['prenom']} {$user['nom']} a été désabonné de $ml@");
}
}
@@ -740,7 +828,7 @@ class XnetGrpModule extends PLModule
}
$page->assign('user', $user);
- $listes = $client->get_lists($user['email2']);
+ $listes = $mmlist->get_lists($user['email2']);
$page->assign('listes', $listes);
$res = XDB::query(
@@ -751,6 +839,180 @@ class XnetGrpModule extends PLModule
$user['email'], '%@'.$globals->asso('mail_domain'));
$page->assign('alias', $res->fetchAllAssoc());
}
+
+ function handler_rss(&$page, $user = null, $hash = null)
+ {
+ global $globals;
+ require_once('rss.inc.php');
+ require_once('url_catcher.inc.php');
+ $uid = init_rss('xnet/groupe/announce-rss.tpl', $user, $hash, false);
+ $page->register_modifier('url_catcher', 'url_catcher');
+
+ if ($uid) {
+ $rss = XDB::iterator("SELECT a.id, a.titre, a.texte, a.contacts, a.create_date,
+ IF(u2.nom_usage != '', u2.nom_usage, u2.nom) AS nom, u2.prenom, u2.promo
+ FROM auth_user_md5 AS u
+ INNER JOIN groupex.announces AS a ON ( (a.promo_min = 0 OR a.promo_min <= u.promo)
+ AND (a.promo_max = 0 OR a.promo_max <= u.promo))
+ INNER JOIN auth_user_md5 AS u2 ON (u2.user_id = a.user_id)
+ WHERE u.user_id = {?} AND peremption >= NOW()", $uid);
+ } else {
+ $rss = XDB::iterator("SELECT a.id, a.titre, a.texte, a.create_date,
+ IF(u.nom_usage != '', u.nom_usage, u.nom) AS nom, u.prenom, u.promo
+ FROM groupex.announces AS a
+ INNER JOIN auth_user_md5 AS u USING(user_id)
+ WHERE FIND_IN_SET(a.flags, 'public') AND peremption >= NOW()");
+ }
+ $page->assign('asso', $globals->asso());
+ $page->assign('rss', $rss);
+ }
+
+ function handler_edit_announce(&$page, $aid = null)
+ {
+ global $globals, $platal;
+ new_groupadmin_page('xnet/groupe/announce-edit.tpl');
+ $page->assign('new', is_null($aid));
+ $art = array();
+
+ if (Post::v('valid') == 'Visualiser' || Post::v('valid') == 'Enregistrer') {
+ if (!is_null($aid)) {
+ $art['id'] = $aid;
+ }
+ $art['titre'] = Post::v('titre');
+ $art['texte'] = Post::v('texte');
+ $art['contacts'] = Post::v('contacts');
+ $art['promo_min'] = Post::i('promo_min');
+ $art['promo_max'] = Post::i('promo_max');
+ $art['nom'] = S::v('nom');
+ $art['prenom'] = S::v('prenom');
+ $art['promo'] = S::v('promo');
+ $art['forlife'] = S::v('forlife');
+ $art['peremption'] = Post::v('peremption');
+ $art['public'] = Post::has('public');
+ $art['xorg'] = Post::has('xorg');
+ $art['nl'] = Post::has('nl');
+ $art['event'] = Post::v('event');
+
+ $art['contact_html'] = $art['contacts'];
+ if (@$art['event']) {
+ $art['contact_html'] .= "\n{$globals->baseurl}/{$platal->ns}events/sub/{$art['event']}";
+ }
+
+ if (!$art['public'] &&
+ ($art['promo_min'] > $art['promo_max'] ||
+ ($art['promo_min'] != 0 && ($art['promo_min'] <= 1900 || $art['promo_min'] >= 2020)) ||
+ ($art['promo_max'] != 0 && ($art['promo_max'] <= 1900 || $art['promo_max'] >= 2020))))
+ {
+ $page->trig("L'intervalle de promotions est invalide");
+ Post::kill('valid');
+ }
+ }
+
+ if (Post::v('valid') == 'Enregistrer') {
+ $promo_min = ($art['public'] ? 0 : $art['promo_min']);
+ $promo_max = ($art['public'] ? 0 : $art['promo_max']);
+ if (is_null($aid)) {
+ XDB::query("INSERT INTO groupex.announces
+ (user_id, asso_id, create_date, titre, texte, contacts,
+ peremption, promo_min, promo_max, flags)
+ VALUES ({?}, {?}, NOW(), {?}, {?}, {?}, {?}, {?}, {?}, {?})",
+ S::i('uid'), $globals->asso('id'), $art['titre'], $art['texte'], $art['contact_html'],
+ $art['peremption'], $promo_min, $promo_max, $art['public'] ? 'public' : '');
+ $aid = mysql_insert_id();
+ if ($art['xorg']) {
+ require_once('validations.inc.php');
+ require_once('url_catcher.inc.php');
+ $article = new EvtReq("[{$globals->asso('nom')}] " . $art['titre'],
+ url_catcher($art['texte'] . (!empty($art['contacts']) ? "\n\nContacts :\n" . $art['contacts'] : "")),
+ $art['promo_min'], $art['promo_max'], $art['peremption'], "", S::v('uid'));
+ $article->submit();
+ $page->trig("L'affichage sur la page d'accueil de Polytechnique.org est en attente de validation");
+ }
+ if ($art['nl']) {
+ require_once('validations.inc.php');
+ $article = new NLReq(S::v('uid'), $globals->asso('nom') . " : " .$art['titre'],
+ $art['texte'], $art['contact_html']);
+ $article->submit();
+ $page->trig("La parution dans la Lettre Mensuelle est en attente de validation");
+ }
+ } else {
+ XDB::query("UPDATE groupex.announces
+ SET titre={?}, texte={?}, contacts={?}, peremption={?},
+ promo_min={?}, promo_max={?}, flags={?}
+ WHERE id={?} AND asso_id={?}",
+ $art['titre'], $art['texte'], $art['contacts'], $art['peremption'],
+ $promo_min, $promo_max, $art['public'] ? 'public' : '',
+ $art['id'], $globals->asso('id'));
+ }
+ }
+ if (Post::v('valid') == 'Enregistrer' || Post::v('valid') == 'Annuler') {
+ pl_redirect("");
+ }
+
+ if (empty($art) && !is_null($aid)) {
+ $res = XDB::query("SELECT a.*, u.nom, u.prenom, u.promo, l.alias AS forlife,
+ FIND_IN_SET(a.flags, 'public') AS public
+ FROM groupex.announces AS a
+ INNER JOIN auth_user_md5 AS u USING(user_id)
+ INNER JOIN aliases AS l ON (l.id = u.user_id AND l.type = 'a_vie')
+ WHERE asso_id = {?} AND a.id = {?}",
+ $globals->asso('id'), $aid);
+ if ($res->numRows()) {
+ $art = $res->fetchOneAssoc();
+ $art['contact_html'] = $art['contacts'];
+ } else {
+ $page->kill("Aucun article correspond à l'identifiant indiqué");
+ }
+ }
+
+ $select = '';
+ for ($i = 1 ; $i < 30 ; $i++) {
+ $time = time() + 3600 * 24 * $i;
+ $p_stamp = date('Ymd', $time);
+ $year = date('Y', $time);
+ $month = date('m', $time);
+ $day = date('d', $time);
+
+ $select .= "\n";
+ }
+ $page->assign('select', $select);
+
+ if (is_null($aid)) {
+ $events = XDB::iterator("SELECT *
+ FROM groupex.evenements
+ WHERE asso_id = {?} AND archive = 0",
+ $globals->asso('id'));
+ if ($events->total()) {
+ $page->assign('events', $events);
+ }
+ }
+
+ require_once('url_catcher.inc.php');
+ $art['contact_html'] = url_catcher($art['contact_html']);
+ $page->assign('art', $art);
+ }
+
+ function handler_admin_announce(&$page)
+ {
+ global $globals;
+ new_groupadmin_page('xnet/groupe/announce-admin.tpl');
+
+ if (Env::has('del')) {
+ XDB::execute("DELETE FROM groupex.announces
+ WHERE id = {?} AND asso_id = {?}",
+ Env::i('del'), $globals->asso('id'));
+ }
+ $res = XDB::iterator("SELECT a.id, a.titre, a.peremption, a.peremption < CURRENT_DATE() AS perime
+ FROM groupex.announces AS a
+ WHERE a.asso_id = {?}
+ ORDER BY a.peremption DESC",
+ $globals->asso('id'));
+ $page->assign('articles', $res);
+ }
}
?>