asso('id'));
if ($res->numRows()) {
$user = $res->fetchOneAssoc();
if ($user['origine'] == 'X') {
$res = XDB::query("SELECT nom, prenom, promo, FIND_IN_SET(flags, 'femme') AS sexe
FROM auth_user_md5
WHERE user_id = {?}", $user['uid']);
$user = array_merge($user, $res->fetchOneAssoc());
}
return $user;
} elseif ($dom == 'polytechnique.org' || $dom == 'm4x.org') {
$res = XDB::query(
"SELECT user_id AS uid, u.promo,
IF(u.nom_usage<>'', u.nom_usage, u.nom) AS nom,
u.prenom, b.alias,
CONCAT(b.alias, '@m4x.org') AS email,
CONCAT(b.alias, '@polytechnique.org') AS email2,
m.perms='admin' AS perms, m.origine,
FIND_IN_SET(u.flags, 'femme') AS sexe
FROM auth_user_md5 AS u
INNER JOIN aliases AS a ON ( u.user_id = a.id AND a.type != 'homonyme' )
INNER JOIN aliases AS b ON ( u.user_id = b.id AND b.type = 'a_vie' )
INNER JOIN groupex.membres AS m ON ( m.uid = u.user_id AND asso_id={?})
WHERE a.alias = {?} AND u.user_id < 50000", $globals->asso('id'), $mbox);
return $res->fetchOneAssoc();
}
return null;
}
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/annuaire/vcard' => $this->make_hook('vcard', AUTH_MDP),
'%grp/trombi' => $this->make_hook('trombi', AUTH_MDP),
'%grp/subscribe' => $this->make_hook('subscribe', AUTH_MDP),
'%grp/admin/annuaire'
=> $this->make_hook('admin_annuaire', AUTH_MDP),
'%grp/member'
=> $this->make_hook('admin_member', AUTH_MDP),
'%grp/member/new'
=> $this->make_hook('admin_member_new', AUTH_MDP),
'%grp/member/new/ajax'
=> $this->make_hook('admin_member_new_ajax', AUTH_MDP, '', NO_AUTH),
'%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, $platal;
if (!is_null($arg)) {
return PL_NOT_FOUND;
}
new_group_open_page('xnet/groupe/asso.tpl');
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());
}
function handler_logo(&$page)
{
global $globals;
$res = XDB::query("SELECT logo, logo_mime
FROM groupex.asso WHERE id = {?}",
$globals->asso('id'));
list($logo, $logo_mime) = $res->fetchOneRow();
if (!empty($logo)) {
header("Content-type: $mime");
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Last-Modified:' . gmdate('D, d M Y H:i:s') . ' GMT');
header('Cache-Control: no-cache, must-revalidate');
header('Pragma: no-cache');
echo $logo;
} else {
header('Content-type: image/jpeg');
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
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/images/dflt_carre.jpg');
}
exit;
}
function handler_edit(&$page)
{
global $globals;
new_groupadmin_page('xnet/groupe/edit.tpl');
if (Post::has('submit')) {
if (S::has_perms()) {
if (Post::v('mail_domain') && (strstr(Post::v('mail_domain'), '.') === false)) {
$page->trig("le domaine doit être un FQDN (aucune modif effectuée) !!!");
return;
}
XDB::execute(
"UPDATE groupex.asso
SET nom={?}, diminutif={?}, cat={?}, dom={?},
descr={?}, site={?}, mail={?}, resp={?},
forum={?}, mail_domain={?}, ax={?}, pub={?},
sub_url={?}, inscriptible={?}
WHERE id={?}",
Post::v('nom'), Post::v('diminutif'),
Post::v('cat'), Post::i('dom'),
Post::v('descr'), Post::v('site'),
Post::v('mail'), Post::v('resp'),
Post::v('forum'), Post::v('mail_domain'),
Post::has('ax'), Post::has('pub')?'private':'public',
Post::v('sub_url'), Post::v('inscriptible'),
$globals->asso('id'));
if (Post::v('mail_domain')) {
XDB::execute('INSERT INTO virtual_domains (domain) VALUES({?})',
Post::v('mail_domain'));
}
} else {
XDB::execute(
"UPDATE groupex.asso
SET descr={?}, site={?}, mail={?}, resp={?},
forum={?}, ax={?}, pub= {?}, sub_url={?}
WHERE id={?}",
Post::v('descr'), Post::v('site'),
Post::v('mail'), Post::v('resp'),
Post::v('forum'), Post::has('ax'),
Post::has('pub')?'private':'public',
Post::v('sub_url'), $globals->asso('id'));
}
if ($_FILES['logo']['name']) {
$logo = file_get_contents($_FILES['logo']['tmp_name']);
$mime = $_FILES['logo']['type'];
XDB::execute('UPDATE groupex.asso
SET logo={?}, logo_mime={?}
WHERE id={?}', $logo, $mime,
$globals->asso('id'));
}
pl_redirect('../'.Post::v('diminutif', $globals->asso('diminutif')).'/edit');
}
if (S::has_perms()) {
$dom = XDB::iterator('SELECT * FROM groupex.dom ORDER BY nom');
$page->assign('dom', $dom);
$page->assign('super', true);
}
}
function handler_mail(&$page)
{
global $globals;
new_groupadmin_page('xnet/groupe/mail.tpl');
$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');
$sujet = Post::v('sujet');
$body = Post::v('body');
$mls = array_keys(Env::v('ml', array()));
require_once 'xnet/mail.inc.php';
$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);
}
}
function handler_annuaire(&$page)
{
global $globals;
new_annu_page('xnet/groupe/annuaire.tpl');
$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'; $sort = 'alpha';
}
$page->assign('sort', $sort);
if ($group == 'initiale')
$res = XDB::iterRow(
'SELECT UPPER(SUBSTRING(
IF(m.origine="X", IF(u.nom_usage<>"", u.nom_usage, u.nom),m.nom),
1, 1)) as letter, COUNT(*)
FROM groupex.membres AS m
LEFT JOIN auth_user_md5 AS u ON ( u.user_id = m.uid )
WHERE asso_id = {?}
GROUP BY letter
ORDER BY letter', $globals->asso('id'));
else
$res = XDB::iterRow(
'SELECT IF(m.origine="X",u.promo,"extérieur") AS promo,
COUNT(*), IF(m.origine="X",u.promo,"") AS promo_o
FROM groupex.membres AS m
LEFT JOIN auth_user_md5 AS u ON ( u.user_id = m.uid )
WHERE asso_id = {?}
GROUP BY promo
ORDER BY promo_o DESC', $globals->asso('id'));
$alphabet = array();
$nb_tot = 0;
while (list($char, $nb) = $res->next()) {
$alphabet[] = $char;
$nb_tot += $nb;
if (Env::has($group) && $char == strtoupper(Env::v($group))) {
$tot = $nb;
}
}
$page->assign('group', $group);
$page->assign('request_group', Env::v($group));
$page->assign('only_admin', Env::has('admin'));
$page->assign('alphabet', $alphabet);
$page->assign('nb_tot', $nb_tot);
$ofs = Env::i('offset');
$tot = Env::v($group) ? $tot : $nb_tot;
$nbp = intval(($tot-1)/NB_PER_PAGE);
$links = array();
if ($ofs) {
$links['précédent'] = $ofs-1;
}
for ($i = 0; $i <= $nbp; $i++) {
$links[(string)($i+1)] = $i;
}
if ($ofs < $nbp) {
$links['suivant'] = $ofs+1;
}
if (count($links)>1) {
$page->assign('links', $links);
}
$ini = '';
if (Env::has('initiale')) {
$ini = 'AND IF(m.origine="X",
IF(u.nom_usage<>"", u.nom_usage, u.nom),
m.nom) LIKE "'.addslashes(Env::v('initiale')).'%"';
} elseif (Env::has('promo')) {
$ini = 'AND IF(m.origine="X", u.promo, "extérieur") = "'
.addslashes(Env::v('promo')).'"';
} elseif (Env::has('admin')) {
$ini = 'AND m.perms = "admin"';
}
$ann = XDB::iterator(
"SELECT IF(m.origine='X',IF(u.nom_usage<>'', u.nom_usage, u.nom) ,m.nom) AS nom,
IF(m.origine='X',u.prenom,m.prenom) AS prenom,
IF(m.origine='X',u.promo,'extérieur') AS promo,
IF(m.origine='X',u.promo,'') AS promo_o,
IF(m.origine='X' AND u.perms != 'pending',a.alias,m.email) AS email,
IF(m.origine='X',FIND_IN_SET('femme', u.flags), m.sexe) AS femme,
m.perms='admin' AS admin,
m.origine='X' AS x,
u.perms!='pending' AS inscrit,
m.uid
FROM groupex.membres AS m
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' OR m.email IS NOT NULL)
ORDER BY $tri
LIMIT {?},{?}", $globals->asso('id'), $ofs*NB_PER_PAGE, NB_PER_PAGE);
$page->assign('ann', $ann);
}
function handler_trombi(&$page, $num = 1)
{
global $globals;
new_annu_page('xnet/groupe/trombi.tpl');
$page->assign('urlmainsite', "https://www.polytechnique.org/");
$trombi = new Trombi(array($this, '_trombi_getlist'));
$trombi->hidePromo();
$trombi->setAdmin();
$page->assign_by_ref('trombi', $trombi);
}
function _trombi_getlist($offset, $limit)
{
global $globals;
$where = "WHERE m.asso_id= '".addslashes($globals->asso('id'))."'";
$res = XDB::query(
"SELECT COUNT(*)
FROM auth_user_md5 AS u
RIGHT JOIN photo AS p ON u.user_id=p.uid
INNER JOIN groupex.membres AS m ON (m.uid = u.user_id)
$where");
$pnb = $res->fetchOneCell();
$res = XDB::query("SELECT promo, user_id, a.alias AS forlife,
IF (nom_usage='', u.nom, nom_usage) AS nom, u.prenom
FROM photo AS p
INNER JOIN auth_user_md5 AS u ON u.user_id=p.uid
INNER JOIN aliases AS a ON ( u.user_id=a.id AND a.type='a_vie' )
INNER JOIN groupex.membres AS m ON (m.uid = u.user_id)
$where
ORDER BY promo, u.nom, u.prenom LIMIT {?}, {?}", $offset*$limit, $limit);
return array($pnb, $res->fetchAllAssoc());
}
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;
new_group_open_page('xnet/groupe/inscrire.tpl');
if (!$globals->asso('inscriptible'))
$page->kill("Il n'est pas possible de s'inscire en ligne à ce "
."groupe. Essaie de joindre le contact indiqué "
."sur la page de présentation.");
if (!is_null($u) && may_update()) {
$page->assign('u', $u);
$res = XDB::query("SELECT nom, prenom, promo, user_id
FROM auth_user_md5 AS u
INNER JOIN aliases AS al ON (al.id = u.user_id
AND al.type != 'liste')
WHERE al.alias = {?}", $u);
if (list($nom, $prenom, $promo, $uid) = $res->fetchOneRow()) {
$res = XDB::query("SELECT COUNT(*)
FROM groupex.membres AS m
INNER JOIN aliases AS a ON (m.uid = a.id
AND a.type != 'homonyme')
WHERE a.alias = {?} AND m.asso_id = {?}",
$u, $globals->asso('id'));
$n = $res->fetchOneCell();
if ($n) {
$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, NULL)",
$globals->asso('id'), $uid);
require_once 'diogenes/diogenes.hermes.inc.php';
$mailer = new HermesMailer();
$mailer->addTo("$u@polytechnique.org");
$mailer->setFrom('"'.S::v('prenom').' '.S::v('nom')
.'" <'.S::v('forlife').'@polytechnique.org>');
$mailer->setSubject('['.$globals->asso('nom').'] Demande d\'inscription');
$message = "Cher Camarade,\n"
. "\n"
. " Suite à ta demande d'adhésion à ".$globals->asso('nom').",\n"
. "j'ai le plaisir de t'annoncer que ton inscription a été validée !\n"
. "\n"
. "Bien cordialement,\n"
. "{$_SESSION["prenom"]} {$_SESSION["nom"]}.";
$mailer->setTxtBody($message);
$mailer->send();
$page->kill("$prenom $nom a bien été inscrit");
}
elseif (Env::has('refuse'))
{
require_once 'diogenes/diogenes.hermes.inc.php';
$mailer = new HermesMailer();
$mailer->addTo("$u@polytechnique.org");
$mailer->setFrom('"'.S::v('prenom').' '.S::v('nom')
.'" <'.S::v('forlife').'@polytechnique.org>');
$mailer->setSubject('['.$globals->asso('nom').'] Demande d\'inscription annulée');
$mailer->setTxtBody(Env::v('motif'));
$mailer->send();
$page->kill("la demande $prenom $nom a bien été refusée");
} else {
$page->assign('show_form', true);
$page->assign('prenom', $prenom);
$page->assign('nom', $nom);
$page->assign('promo', $promo);
$page->assign('uid', $uid);
}
return;
}
return PL_NOT_FOUND;
}
if (is_member()) {
$page->kill("tu es déjà membre !");
return;
}
if (Post::has('inscrire')) {
$res = XDB::query('SELECT IF(m.email IS NULL,
CONCAT(al.alias,"@polytechnique.org"),
m.email)
FROM groupex.membres AS m
INNER JOIN aliases AS al ON (al.type = "a_vie"
AND al.id = m.uid)
WHERE perms="admin" AND m.asso_id = {?}',
$globals->asso('id'));
$emails = $res->fetchColumn();
$to = implode(',', $emails);
$append = "\n"
. "-- \n"
. "Ce message a été envoyé suite à la demande d'inscription de\n"
. S::v('prenom').' '.S::v('nom').' (X'.S::v('promo').")\n"
. "Via le site www.polytechnique.net. Tu peux choisir de valider ou\n"
. "de refuser sa demande d'inscription depuis la page :\n"
.
"http://www.polytechnique.net/".$globals->asso("diminutif")."/subscribe/"
.S::v('forlife')."\n"
. "\n"
. "En cas de problème, contacter l'équipe de Polytechnique.org\n"
. "à l'adresse : support@polytechnique.org\n";
if (!$to) {
$to = $globals->asso("mail").", support@polytechnique.org";
$append = "\n-- \nLe groupe ".$globals->asso("nom")
." n'a pas d'administrateur, l'équipe de"
." Polytechnique.org a été prévenue et va rapidement"
." résoudre ce problème.\n";
}
require_once 'diogenes/diogenes.hermes.inc.php';
$mailer = new HermesMailer();
$mailer->addTo($to);
$mailer->setFrom('"'.S::v('prenom').' '.S::v('nom')
.'" <'.S::v('forlife').'@polytechnique.org>');
$mailer->setSubject('['.$globals->asso('nom').'] Demande d\'inscription');
$mailer->setTxtBody(Post::v('message').$append);
$mailer->send();
}
}
function handler_admin_annuaire(&$page)
{
global $globals;
require_once 'xnet/mail.inc.php';
new_groupadmin_page('xnet/groupe/annuaire-admin.tpl');
$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) = $mmlist->get_members($list);
$mails = array_map(create_function('$arr', 'return $arr[1];'), $members);
$subscribers = array_unique(array_merge($subscribers, $mails));
}
$not_in_group_x = array();
$not_in_group_ext = array();
foreach ($subscribers as $mail) {
$res = XDB::query(
'SELECT COUNT(*)
FROM groupex.membres AS m
LEFT JOIN auth_user_md5 AS u ON (m.uid=u.user_id AND m.uid<50000)
LEFT JOIN aliases AS a ON (a.id=u.user_id and a.type="a_vie")
WHERE asso_id = {?} AND
(m.email = {?} OR CONCAT(a.alias, "@polytechnique.org") = {?})',
$globals->asso('id'), $mail, $mail);
if ($res->fetchOneCell() == 0) {
if (strstr($mail, '@polytechnique.org') === false) {
$not_in_group_ext[] = $mail;
} else {
$not_in_group_x[] = $mail;
}
}
}
$page->assign('not_in_group_ext', $not_in_group_ext);
$page->assign('not_in_group_x', $not_in_group_x);
$page->assign('lists', $lists);
}
function handler_admin_member_new(&$page, $email = null)
{
global $globals;
new_groupadmin_page('xnet/groupe/membres-add.tpl');
$page->addJsLink('ajax.js');
if (is_null($email)) {
return;
}
list(,$fqdn) = explode('@', $email);
$fqdn = strtolower($fqdn);
$x = ($fqdn == 'polytechnique.org' || $fqdn == 'melix.org' ||
$fqdn == 'm4x.org' || $fqdn == 'melix.net');
if ($x) {
require_once 'user.func.inc.php';
if ($forlife = get_user_forlife($email)) {
XDB::execute(
'INSERT INTO groupex.membres (uid,asso_id,origine)
SELECT user_id,{?},"X"
FROM auth_user_md5 AS u
INNER JOIN aliases AS a ON (u.user_id = a.id)
WHERE a.alias={?}', $globals->asso('id'), $forlife);
pl_redirect("member/$email");
} else {
$page->trig($email." n'est pas un alias polytechnique.org valide");
}
} else {
if (isvalid_email($email)) {
if (Env::v('x') && Env::has('userid') && Env::i('userid')) {
$uid = Env::i('userid');
$res = XDB::query("SELECT *
FROM auth_user_md5
WHERE user_id = {?} AND perms = 'pending'", $uid);
if ($res->numRows() == 1) {
XDB::execute('INSERT INTO groupex.membres (uid, asso_id, origine, email)
VALUES ({?}, {?}, "X", {?})',
$uid, $globals->asso('id'), $email);
if (Env::v('market')) {
$res = XDB::query('SELECT COUNT(*)
FROM register_marketing
WHERE uid={?} AND email={?}', $uid, $email);
if (!$res->fetchOneCell()) {
XDB::execute("INSERT INTO register_marketing (uid,sender,email,date,last,nb,type,hash)
VALUES ({?}, {?}, {?}, NOW(), 0, 0, {?}, '')",
$uid, S::v('uid'), $email, Env::v('market_from'));
require_once('validations.inc.php');
$req = new MarkReq(S::v('uid'), $uid, $email, Env::v('market_from') == 'user');
$req->submit();
}
}
pl_redirect("member/$email");
}
$page->trig("Utilisateur invalide");
} else {
$res = XDB::query('SELECT MAX(uid)+1 FROM groupex.membres');
$uid = max(intval($res->fetchOneCell()), 50001);
XDB::execute('INSERT INTO groupex.membres (uid,asso_id,origine,email)
VALUES({?},{?},"ext",{?})', $uid,
$globals->asso('id'), $email);
pl_redirect("member/$email");
}
} else {
$page->trig("« $email » n'est pas une adresse mail valide");
}
}
}
function handler_admin_member_new_ajax(&$page)
{
header('Content-Type: text/html; charset="iso-8859-15"');
$page->changeTpl('xnet/groupe/membres-new-search.tpl', NO_SKIN);
list($nom, $prenom) = str_replace(array('-', ' ', "'"), '%', array(Env::v('nom'), Env::v('prenom')));
$where = "perms = 'pending'";
if (!empty($nom)) {
$where .= " AND nom LIKE '%$nom%'";
}
if (!empty($prenom)) {
$where .= " AND prenom LIKE '%$prenom%'";
}
if (preg_match('/^[0-9]{4}$/', Env::v('promo'))) {
$where .= " AND promo = " . Env::i('promo');
} elseif (Env::has('promo')) {
return;
}
$res = XDB::iterator("SELECT user_id, nom, prenom, promo
FROM auth_user_md5
WHERE $where");
if ($res->total() < 30) {
$page->assign("choix", $res);
}
}
function handler_admin_member_del(&$page, $user = null)
{
global $globals;
new_groupadmin_page('xnet/groupe/membres-del.tpl');
$user = get_infos($user);
if (empty($user)) {
return PL_NOT_FOUND;
}
$page->assign('user', $user);
if (!Post::has('confirm')) {
return;
}
XDB::execute(
"DELETE FROM groupex.membres WHERE uid={?} AND asso_id={?}",
$user['uid'], $globals->asso('id'));
// don't unsubscribe email from list if other user use same email
$user_same_email = get_infos($user['email']);
if (($domain = $globals->asso('mail_domain')) && empty($user_same_email)) {
$mmlist = new MMList(S::v('uid'), S::v('password'), $domain);
$listes = $mmlist->get_lists($user['email2']);
foreach ($listes as $liste) {
if ($liste['sub'] == 2) {
$mmlist->mass_unsubscribe($liste['list'], Array($user['email2']));
$page->trig("{$user['prenom']} {$user['nom']} a été"
." désinscrit de {$liste['list']}");
} elseif ($liste['sub']) {
$page->trig("{$user['prenom']} {$user['nom']} a une"
." demande d'inscription en cours sur la"
." liste {$liste['list']}@ !");
}
}
XDB::execute(
"DELETE FROM virtual_redirect
USING virtual_redirect
INNER JOIN virtual USING(vid)
WHERE redirect={?} AND alias LIKE {?}", $user['email'], '%@'.$domain);
if (mysql_affected_rows()) {
$page->trig("{$user['prenom']} {$user['nom']} a été désabonné des alias du groupe !");
}
}
$page->trig("{$user['prenom']} {$user['nom']} a été retiré du groupe !");
}
function handler_admin_member(&$page, $user)
{
global $globals;
new_groupadmin_page('xnet/groupe/membres-edit.tpl');
$user = get_infos($user);
if (empty($user)) {
return PL_NOT_FOUND;
}
$mmlist = new MMList(S::v('uid'), S::v('password'),
$globals->asso('mail_domain'));
if (Post::has('change')) {
$email_changed = ($user['origine'] != 'X' && strtolower($user['email']) != strtolower(Post::v('email')));
$from_email = $user['email'];
if ($user['origine'] != 'X') {
XDB::query('UPDATE groupex.membres
SET prenom={?}, nom={?}, email={?}, sexe={?}
WHERE uid={?} AND asso_id={?}',
Post::v('prenom'), Post::v('nom'),
Post::v('email'), Post::v('sexe'),
$user['uid'], $globals->asso('id'));
$user['nom'] = Post::v('nom');
$user['prenom'] = Post::v('prenom');
$user['sexe'] = Post::v('sexe');
$user['email'] = Post::v('email');
$user['email2'] = Post::v('email');
}
$perms = Post::i('is_admin');
if ($user['perms'] != $perms) {
XDB::query('UPDATE groupex.membres SET perms={?}
WHERE uid={?} AND asso_id={?}',
$perms ? 'admin' : 'membre',
$user['uid'], $globals->asso('id'));
$user['perms'] = $perms;
$page->trig('permissions modifiées');
}
foreach (Env::v('ml1', array()) as $ml => $state) {
$ask = empty($_REQUEST['ml2'][$ml]) ? 0 : 2;
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) {
$mmlist->mass_subscribe($ml, Array($user['email2']));
$page->trig("{$user['prenom']} {$user['nom']} a été abonné à $ml@");
} else {
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@");
}
}
foreach (Env::v('ml3', array()) as $ml => $state) {
$ask = !empty($_REQUEST['ml4'][$ml]);
if($state == $ask) continue;
if($ask) {
XDB::query("INSERT INTO virtual_redirect (vid,redirect)
SELECT vid,{?} FROM virtual WHERE alias={?}",
$user['email'], $ml);
$page->trig("{$user['prenom']} {$user['nom']} a été abonné à $ml");
} else {
XDB::query("DELETE FROM virtual_redirect
USING virtual_redirect
INNER JOIN virtual USING(vid)
WHERE redirect={?} AND alias={?}",
$user['email'], $ml);
$page->trig("{$user['prenom']} {$user['nom']} a été désabonné de $ml");
}
}
}
$page->assign('user', $user);
$listes = $mmlist->get_lists($user['email2']);
$page->assign('listes', $listes);
$res = XDB::query(
'SELECT alias, redirect IS NOT NULL as sub
FROM virtual AS v
LEFT JOIN virtual_redirect AS vr ON(v.vid=vr.vid AND redirect={?})
WHERE alias LIKE {?} AND type="user"',
$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() AND a.asso_id = {?}",
$uid, $globals->asso('id'));
} 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() AND a.asso_id = {?}",
$globals->asso('id'));
}
$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 = XDB::insertId();
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['contact_html']) ? "\n\nContacts :\n" . $art['contact_html'] : "")),
$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);
}
}
?>