<?php
/***************************************************************************
- * Copyright (C) 2003-2009 Polytechnique.org *
+ * Copyright (C) 2003-2010 Polytechnique.org *
* http://opensource.polytechnique.org/ *
* *
* This program is free software; you can redistribute it and/or modify *
);
}
- function prepare_client(&$page)
+ function prepare_client(&$page, $user = null)
{
global $globals;
$this->load('lists.inc.php');
+ if (is_null($user)) {
+ $user = S::user();
+ }
- $this->client = new MMList(S::v('uid'), S::v('password'));
+ $this->client = new MMList($user);
return $globals->mail->domain;
}
{
list($subs,$mails) = $this->client->get_pending_ops($list);
$res = XDB::query("SELECT mid
- FROM ml_moderate
+ FROM email_list_moderate
WHERE ml = {?} AND domain = {?}",
$list, $domain);
$mids = $res->fetchColumn();
if ($promo >= 1900 and $promo < 2100) {
$this->client->subscribe("promo$promo");
} else {
- $page->trigSuccess("promo incorrecte, il faut une promo sur 4 chiffres.");
+ $page->trigError("promo incorrecte, il faut une promo sur 4 chiffres.");
}
}
- $listes = $this->client->get_lists();
- $owner = array_filter($listes, 'filter_owner');
- $listes = array_diff_key($listes, $owner);
- $member = array_filter($listes, 'filter_member');
- $listes = array_diff_key($listes, $member);
- foreach ($owner as $key=>$liste) {
- list($subs,$mails) = $this->get_pending_ops($domain, $liste['list']);
- $owner[$key]['subscriptions'] = $subs;
- $owner[$key]['mails'] = $mails;
+ if (!is_null($listes = $this->client->get_lists())) {
+ $owner = array_filter($listes, 'filter_owner');
+ $listes = array_diff_key($listes, $owner);
+ $member = array_filter($listes, 'filter_member');
+ $listes = array_diff_key($listes, $member);
+ foreach ($owner as $key => $liste) {
+ list($subs, $mails) = $this->get_pending_ops($domain, $liste['list']);
+ $owner[$key]['subscriptions'] = $subs;
+ $owner[$key]['mails'] = $mails;
+ }
+ $page->register_modifier('hdc', 'list_header_decode');
+ $page->assign_by_ref('owner', $owner);
+ $page->assign_by_ref('member', $member);
+ $page->assign_by_ref('public', $listes);
}
- $page->register_modifier('hdc', 'list_header_decode');
- $page->assign_by_ref('owner', $owner);
- $page->assign_by_ref('member', $member);
- $page->assign_by_ref('public', $listes);
}
function handler_ajax(&$page, $list = null)
{
- header('Content-Type: text/html; charset="UTF-8"');
+ pl_content_headers("text/html");
$domain = $this->prepare_client($page);
$page->changeTpl('lists/liste.inc.tpl', NO_SKIN);
S::assert_xsrf_token();
$page->changeTpl('lists/create.tpl');
- $user_promo = S::i('promo');
+ $user_promo = S::user()->profile()->yearPromo();
$year = date('Y');
$month = date('m');
+ // scolar year starts in september
+ $scolarmonth = ($year - $user_promo) * 12 + ($month - 8);
$young_promo = $very_young_promo = 0;
- if ((($year > $user_promo) && ($month > 3)) && ($year < $user_promo + 5)) {
+ // binet are accessible only in april in the first year and until
+ // march of the 5th year
+ if ($scolarmonth >= 8 && $scolarmonth < 56) {
$young_promo = 1;
}
- if ((($year > $user_promo) && ($month > 7)) && (($year < $user_promo + 1) && ($month < 8))) {
+ // PSC aliases are accesible only between september and june of the second
+ // year of scolarity
+ if ($scolarmonth >= 12 && $scolarmonth < 22) {
$very_young_promo = 1;
}
$page->assign('young_promo', $young_promo);
$liste = Post::v('liste');
if (empty($liste)) {
- $page->trigError('Le champ «adresse souhaitée» est vide.');
+ $page->trigError('Le champ « adresse souhaitée » est vide.');
}
if (!preg_match("/^[a-zA-Z0-9\-]*$/", $liste)) {
$page->trigError('Le nom de la liste ne doit contenir que des lettres non accentuées, chiffres et tirets.');
$domain = $promo . '.' . $globals->mail->domain;
if (($promo < 1921) || ($promo > date('Y'))) {
- $page->trigError('La promotion est mal renseignée, elle doit être du type : 2004.');
+ $page->trigError('La promotion est mal renseignée, elle doit être du type : 2004.');
}
$new = $liste . '@' . $domain;
- $res = XDB::query('SELECT COUNT(*) FROM x4dat.virtual WHERE alias={?}', $new);
+ $res = XDB::query('SELECT COUNT(*) FROM virtual WHERE alias={?}', $new);
} else {
if ($asso == "groupex") {
$groupex_name = Post::v('groupex_name');
- $res_groupe = XDB::query('SELECT mail_domain FROM groupex.asso WHERE nom={?}', $groupex_name);
+ $res_groupe = XDB::query('SELECT mail_domain FROM groups WHERE nom={?}', $groupex_name);
$domain = $res_groupe->fetchOneCell();
if (!$domain) {
}
$new = $liste . '@' . $domain;
- $res = XDB::query('SELECT COUNT(*) FROM x4dat.virtual WHERE alias={?}', $new);
+ $res = XDB::query('SELECT COUNT(*) FROM virtual WHERE alias={?}', $new);
} else {
$res = XDB::query("SELECT COUNT(*) FROM aliases WHERE alias={?}", $liste);
$domain = $globals->mail->domain;
$n = $res->fetchOneCell();
if ($n) {
- $page->trigError('L\'«adresse souhaitée» est déjà prise.');
+ $page->trigError("L'« adresse souhaitée » est déjà prise.");
}
if (!Post::v('desc')) {
}
if (!$page->nb_errs()) {
+ $page->trigSuccess('Demande de création envoyée !');
$page->assign('created', true);
require_once 'validations.inc.php';
$req = new ListeReq(S::user(), $asso, $liste, $domain,
$page->assign_by_ref('owners', $moderos);
$page->assign('nb_m', count($mem));
} else {
- $page->kill("La liste n'existe pas ou tu n'as pas le droit d'en voir les détails");
+ $page->kill("La liste n'existe pas ou tu n'as pas le droit d'en voir les détails.");
}
}
}
$this->prepare_client($page);
$members = $this->client->get_members($liste);
- $list = list_fetch_names(list_extract_members($members[1]));
- header('Content-Type: text/x-csv; charset=utf-8;');
- header('Pragma: ');
- header('Cache-Control: ');
+ $list = list_fetch_basic_info(list_extract_members($members[1]));
+ pl_content_headers("text/x-csv");
- echo "email,nom,prenom,promo\n";
- foreach ($list as $member) {
- echo @$member['email'] . ',' . @$member['nom'] . ',' . @$member['prenom'] . ',' . @$member['promo'] . "\n";
- }
+ echo "email,nom,promo\n";
+ echo implode("\n", $list);
exit;
}
$owners = $this->client->get_owners($liste);
if (!is_array($owners)) {
- $page->kill("La liste n'existe pas ou tu n'as pas le droit d'en voir les détails");
+ $page->kill("La liste n'existe pas ou tu n'as pas le droit d'en voir les détails.");
}
global $platal;
if (empty($GLOBALS['IS_XNET_SITE'])) {
$view->addMod('minifiche', 'Mini-fiches', false);
}
- $view->addMod('geoloc', 'Planisphère');
+ // TODO: Reactivate when the new map is completed.
+ // $view->addMod('geoloc', 'Planisphère');
$view->apply("lists/annu/$liste", $page, $action, $subaction);
if ($action == 'geoloc' && $subaction) {
return;
function handler_rss(&$page, $liste = null, $alias = null, $hash = null)
{
- require_once('rss.inc.php');
- $uid = init_rss(null, $alias, $hash);
- if (!$uid || !$liste) {
- exit;
+ if (!$liste) {
+ return PL_NOT_FOUND;
+ }
+ $user = Platal::session()->tokenAuth($alias, $hash);
+ if (is_null($user)) {
+ return PL_FORBIDDEN;
}
- $res = XDB::query("SELECT user_id AS uid, password, alias AS forlife
- FROM auth_user_md5 AS u
- INNER JOIN aliases AS a ON (a.id = u.user_id AND a.type = 'a_vie')
- WHERE u.user_id = {?}", $uid);
- $row = $res->fetchOneAssoc();
- $_SESSION = array_merge($row, $_SESSION);
-
- $domain = $this->prepare_client($page);
+ $domain = $this->prepare_client($page, $user);
if (list($det) = $this->client->get_members($liste)) {
if (substr($liste,0,5) != 'promo' && ($det['ins'] || $det['priv'])
&& !$det['own'] && ($det['sub'] < 2)) {
exit;
}
require_once('banana/ml.inc.php');
- $banana = new MLBanana(S::user(), Array('listname' => $liste, 'domain' => $domain, 'action' => 'rss2'));
+ $banana = new MLBanana($user, Array('listname' => $liste, 'domain' => $domain, 'action' => 'rss2'));
$banana->run();
}
exit;
return false;
}
Get::kill('mid');
- return XDB::execute("INSERT IGNORE INTO ml_moderate
+ return XDB::execute("INSERT IGNORE INTO email_list_moderate
VALUES ({?}, {?}, {?}, {?}, {?}, NOW(), {?}, NULL)",
$liste, $domain, $mid, S::i('uid'), $action, Post::v('reason'));
}
}
} elseif (Env::has('mid')) {
if (Get::has('mid') && !Env::has('mok') && !Env::has('mdel')) {
- $page->changeTpl('lists/moderate_mail.tpl');
- require_once('banana/moderate.inc.php');
- $params = array('listname' => $liste, 'domain' => $domain,
- 'artid' => Get::i('mid'), 'part' => Get::v('part'), 'action' => Get::v('action'));
- $params['client'] = $this->client;
- run_banana($page, 'ModerationBanana', $params);
+ require_once 'banana/moderate.inc.php';
- $msg = file_get_contents('/etc/mailman/fr/refuse.txt');
- $msg = str_replace("%(adminaddr)s", "$liste-owner@{$domain}", $msg);
- $msg = str_replace("%(request)s", "<< SUJET DU MAIL >>", $msg);
- $msg = str_replace("%(reason)s", "<< TON EXPLICATION >>", $msg);
- $msg = str_replace("%(listname)s", $liste, $msg);
- $page->assign('msg', $msg);
- return;
- } elseif (Get::has('mid') && Env::has('mok')) {
$page->changeTpl('lists/moderate_mail.tpl');
- require_once('banana/moderate.inc.php');
$params = array('listname' => $liste, 'domain' => $domain,
'artid' => Get::i('mid'), 'part' => Get::v('part'), 'action' => Get::v('action'));
$params['client'] = $this->client;
run_banana($page, 'ModerationBanana', $params);
- $msg = file_get_contents('/etc/mailman/fr/accept.txt');
+ $msg = file_get_contents('/etc/mailman/fr/refuse.txt');
$msg = str_replace("%(adminaddr)s", "$liste-owner@{$domain}", $msg);
$msg = str_replace("%(request)s", "<< SUJET DU MAIL >>", $msg);
$msg = str_replace("%(reason)s", "<< TON EXPLICATION >>", $msg);
return;
}
- $mail = $this->moderate_mail($domain, $liste, Env::i('mid'));
+ $this->moderate_mail($domain, $liste, Env::i('mid'));
} elseif (Env::has('sid')) {
if (list($subs,$mails) = $this->get_pending_ops($domain, $liste)) {
foreach($subs as $user) {
$page->assign_by_ref('subs', $subs);
$page->assign_by_ref('mails', $mails);
} else {
- $page->kill("La liste n'existe pas ou tu n'as pas le droit de la modérer");
+ $page->kill("La liste n'existe pas ou tu n'as pas le droit de la modérer.");
}
}
static public function no_login_callback($login)
{
- require_once 'user.func.inc.php';
global $list_unregistered, $globals;
- $users = get_not_registered_user($login, true);
+ $users = User::getPendingAccounts($login, true);
if ($users && $users->total()) {
if (!isset($list_unregistered)) {
$list_unregistered = array();
S::assert_xsrf_token();
$members = User::getBulkForlifeEmails(Env::v('add_member'),
- false,
+ true,
array('ListsModule', 'no_login_callback'));
$arr = $this->client->mass_subscribe($liste, $members);
if (is_array($arr)) {
$page->trigError('Une erreur s\'est produite lors du téléchargement du fichier');
} else {
$members = User::getBulkForlifeEmails($upload->getContents(),
- false,
+ true,
array('ListsModule', 'no_login_callback'));
$arr = $this->client->mass_subscribe($liste, $members);
if (is_array($arr)) {
} else {
$page->kill("La liste n'existe pas ou tu n'as pas le droit de l'administrer.<br />"
- ." Si tu penses qu'il s'agit d'une erreur, "
- ."<a href='mailto:support@polytechnique.org'>contact le support</a>");
+ . " Si tu penses qu'il s'agit d'une erreur, "
+ . "<a href='mailto:support@polytechnique.org'>contact le support</a>.");
}
}
$type, $liste.$app.$domain);
}
$page->assign('deleted', true);
- $page->trigSuccess('La liste a été détruite !');
+ $page->trigSuccess('La liste a été détruite !');
} else {
$page->kill('Une erreur est survenue lors de la suppression de la liste.<br />'
. 'Contact les administrateurs du site pour régler le problème : '
- . '<a href="mailto:support@polytechnique.org">support@polytechnique.org</a>');
+ . '<a href="mailto:support@polytechnique.org">support@polytechnique.org</a>.');
}
} elseif (list($details,$options) = $this->client->get_owner_options($liste)) {
if (!$details['own']) {
$page->assign_by_ref('options', $options);
$page->assign('bogo_level', $this->client->get_bogo_level($liste));
} else {
- $page->kill("La liste n'existe pas ou tu n'as pas le droit de l'administrer");
+ $page->kill("La liste n'existe pas ou tu n'as pas le droit de l'administrer.");
}
}
$page->assign_by_ref('details', $details);
$page->assign_by_ref('options', $options);
} else {
- $page->kill("La liste n'existe pas");
+ $page->kill("La liste n'existe pas.");
}
}
$page->assign_by_ref('details', $details);
$page->assign_by_ref('options', $options);
} else {
- $page->kill("La liste n'existe pas");
+ $page->kill("La liste n'existe pas.");
}
}
- function handler_admin_all(&$page) {
+ function handler_admin_all(&$page)
+ {
$page->changeTpl('lists/admin_all.tpl');
$page->setTitle('Administration - Mailing lists');
- $client = new MMList(S::v('uid'), S::v('password'));
- $listes = $client->get_all_lists();
+ $this->prepare_client($page);
+ $listes = $this->client->get_all_lists();
$page->assign_by_ref('listes', $listes);
}
}