X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=modules%2Femail.php;h=8b4bcf35f6f114eb6060c6b397ef72b6e58b6729;hb=ed06daba6f36cdc16110292ad939ee1813049b18;hp=197ae8ec42f94701de1cb3ddc910b61747feddf1;hpb=1285cf5413df654ccac839b9d9a32c4df2cee95a;p=platal.git diff --git a/modules/email.php b/modules/email.php index 197ae8e..8b4bcf3 100644 --- a/modules/email.php +++ b/modules/email.php @@ -1,6 +1,6 @@ $this->make_hook('emails', AUTH_COOKIE), - 'emails/alias' => $this->make_hook('alias', AUTH_MDP), - 'emails/antispam' => $this->make_hook('antispam', AUTH_MDP), + 'emails' => $this->make_hook('emails', AUTH_COOKIE, 'mail'), + 'emails/alias' => $this->make_hook('alias', AUTH_MDP, 'mail'), + 'emails/antispam' => $this->make_hook('antispam', AUTH_MDP, 'mail'), 'emails/broken' => $this->make_hook('broken', AUTH_COOKIE), - 'emails/redirect' => $this->make_hook('redirect', AUTH_MDP), - 'emails/send' => $this->make_hook('send', AUTH_MDP), + 'emails/redirect' => $this->make_hook('redirect', AUTH_MDP, 'mail'), + 'emails/send' => $this->make_hook('send', AUTH_MDP, 'mail'), 'emails/antispam/submit' => $this->make_hook('submit', AUTH_COOKIE), - 'emails/test' => $this->make_hook('test', AUTH_COOKIE, 'user', NO_AUTH), + 'emails/test' => $this->make_hook('test', AUTH_COOKIE, 'mail', NO_AUTH), 'emails/rewrite/in' => $this->make_hook('rewrite_in', AUTH_PUBLIC), 'emails/rewrite/out' => $this->make_hook('rewrite_out', AUTH_PUBLIC), @@ -45,7 +45,7 @@ class EmailModule extends PLModule ); } - function handler_emails(&$page, $action = null, $email = null) + function handler_emails($page, $action = null, $email = null) { global $globals; require_once 'emails.inc.php'; @@ -104,10 +104,8 @@ class EmailModule extends PLModule $page->assign('melix', $res->fetchOneCell()); } - function handler_alias(&$page, $action = null, $value = null) + function handler_alias($page, $action = null, $value = null) { - require_once 'validations.inc.php'; - global $globals; $page->changeTpl('emails/alias.tpl'); @@ -171,9 +169,9 @@ class EmailModule extends PLModule } //vérifier que l'alias n'est pas déja en demande - $it = new ValidateIterator(); + $it = Validate::iterate('alias'); while($req = $it->next()) { - if ($req->type == 'alias' and $req->alias == $alias_mail) { + if ($req->alias == $alias_mail) { $page->trigError("L'alias $alias_mail a déja été demandé. Tu ne peux donc pas l'obtenir pour l'instant."); return ; @@ -194,7 +192,7 @@ class EmailModule extends PLModule if ($user->hasProfile()) { XDB::execute("UPDATE profiles SET alias_pub = {?} - WHERE pid = {?}", + WHERE pid = {?}", $value, $user->profile()->id()); } $visibility = ($value == 'public'); @@ -206,7 +204,7 @@ class EmailModule extends PLModule $page->assign('mail_public', $visibility); } - function handler_redirect(&$page, $action = null, $email = null) + function handler_redirect($page, $action = null, $email = null) { global $globals; @@ -318,7 +316,7 @@ class EmailModule extends PLModule fill_email_combobox($page); } - function handler_antispam(&$page, $statut_filtre = null) + function handler_antispam($page, $statut_filtre = null) { require_once 'emails.inc.php'; $wp = new PlWikiPage('Xorg.Antispam'); @@ -334,7 +332,7 @@ class EmailModule extends PLModule $page->assign('filtre', $bogo->level()); } - function handler_submit(&$page) + function handler_submit($page) { $wp = new PlWikiPage('Xorg.Mails'); $wp->buildCache(); @@ -369,10 +367,9 @@ class EmailModule extends PLModule } } - function handler_send(&$page) + function handler_send($page) { $page->changeTpl('emails/send.tpl'); - $page->addJsLink('ajax.js'); $page->setTitle('Envoyer un email'); @@ -384,11 +381,12 @@ class EmailModule extends PLModule unset($_POST['save']); if (trim(preg_replace('/-- .*/', '', Post::v('contenu'))) != "") { - $_POST['to_contacts'] = explode(';', @$_POST['to_contacts']); - $_POST['cc_contacts'] = explode(';', @$_POST['cc_contacts']); + Post::set('to_contacts', explode(';', Post::s('to_contacts'))); + Post::set('cc_contacts', explode(';', Post::s('cc_contacts'))); $data = serialize($_POST); - XDB::execute("REPLACE INTO email_send_save - VALUES ({?}, {?})", + XDB::execute('INSERT INTO email_send_save (uid, data) + VALUES ({?}, {?}) + ON DUPLICATE KEY UPDATE data = VALUES(data)', S::user()->id('uid'), $data); } exit; @@ -497,7 +495,7 @@ class EmailModule extends PLModule $page->assign('user', S::user()); } - function handler_test(&$page, $hruid = null) + function handler_test($page, $hruid = null) { require_once 'emails.inc.php'; @@ -527,7 +525,7 @@ class EmailModule extends PLModule exit; } - function handler_rewrite_in(&$page, $mail, $hash) + function handler_rewrite_in($page, $mail, $hash) { $page->changeTpl('emails/rewrite.tpl'); $page->assign('option', 'in'); @@ -555,7 +553,7 @@ class EmailModule extends PLModule return PL_NOT_FOUND; } - function handler_rewrite_out(&$page, $mail, $hash) + function handler_rewrite_out($page, $mail, $hash) { $page->changeTpl('emails/rewrite.tpl'); $page->assign('option', 'out'); @@ -596,7 +594,7 @@ class EmailModule extends PLModule return PL_NOT_FOUND; } - function handler_imap_in(&$page, $hash = null, $login = null) + function handler_imap_in($page, $hash = null, $login = null) { $page->changeTpl('emails/imap_register.tpl'); $user = null; @@ -619,18 +617,18 @@ class EmailModule extends PLModule $storage = new EmailStorage(S::user(), 'imap'); $storage->activate(); $page->assign('ok', true); - $page->assign('prenom', S::v('prenom')); - $page->assign('sexe', S::v('femme')); + $page->assign('yourself', S::user()->displayName()); + $page->assign('sexe', S::user()->isFemale()); } else if (!S::logged() && $user) { $storage = new EmailStorage($user, 'imap'); $storage->activate(); $page->assign('ok', true); - $page->assign('prenom', $user->displayName()); + $page->assign('yourself', $user->displayName()); $page->assign('sexe', $user->isFemale()); } } - function handler_broken(&$page, $warn = null, $email = null) + function handler_broken($page, $warn = null, $email = null) { require_once 'emails.inc.php'; $wp = new PlWikiPage('Xorg.PatteCassée'); @@ -696,7 +694,7 @@ class EmailModule extends PLModule } } - function handler_duplicated(&$page, $action = 'list', $email = null) + function handler_duplicated($page, $action = 'list', $email = null) { $page->changeTpl('emails/duplicated.tpl'); @@ -790,22 +788,23 @@ class EmailModule extends PLModule } } - function handler_lost(&$page, $action = 'list', $email = null) + function handler_lost($page, $action = 'list', $email = null) { $page->changeTpl('emails/lost.tpl'); - // TODO: Order by promo. $page->assign('lost_emails', - XDB::iterator("SELECT a.uid, a.hruid - FROM accounts AS a - INNER JOIN email_options AS eo ON (eo.uid = a.uid) - LEFT JOIN emails AS e ON (a.uid = e.uid AND FIND_IN_SET('active', e.flags)) - WHERE e.uid IS NULL AND FIND_IN_SET('googleapps', eo.storage) = 0 AND - a.state = 'active' - ORDER BY a.hruid")); + XDB::iterator('SELECT a.uid, a.hruid, pd.promo + FROM accounts AS a + INNER JOIN email_options AS eo ON (eo.uid = a.uid) + LEFT JOIN emails AS e ON (a.uid = e.uid AND FIND_IN_SET(\'active\', e.flags)) + LEFT JOIN account_profiles AS ap ON (ap.uid = a.uid AND FIND_IN_SET(\'owner\', perms)) + LEFT JOIN profile_display AS pd ON (ap.pid = pd.pid) + WHERE e.uid IS NULL AND FIND_IN_SET(\'googleapps\', eo.storage) = 0 + AND a.state = \'active\' + ORDER BY pd.promo, a.hruid')); } - function handler_broken_addr(&$page) + function handler_broken_addr($page) { require_once 'emails.inc.php'; $page->changeTpl('emails/broken_addr.tpl'); @@ -852,8 +851,6 @@ class EmailModule extends PLModule if ($list == '') { $page->trigError('La liste est vide.'); } else { - global $platal; - $broken_user_list = array(); $broken_list = explode("\n", $list); sort($broken_list); @@ -891,7 +888,7 @@ class EmailModule extends PLModule if (!empty($x['nb_mails'])) { $mail = new PlMailer('emails/broken.mail.tpl'); $mail->addTo("\"{$x['full_name']}\" <{$x['alias']}@" - . $globals->mail->domain . '>'); + . Platal::globals()->mail->domain . '>'); $mail->assign('x', $x); $mail->assign('email', $email); $mail->send(); @@ -917,21 +914,27 @@ class EmailModule extends PLModule // Output the list of users with recently broken addresses, // along with the count of valid redirections. require_once 'notifs.inc.php'; - pl_content_headers("text/x-csv"); + pl_cached_content_headers('text/x-csv', 1); $csv = fopen('php://output', 'w'); - fputcsv($csv, array('nom', 'promo', 'alias', 'bounce', 'nbmails', 'url'), ';'); + fputcsv($csv, array('nom', 'promo', 'alias', 'bounce', 'nbmails', 'url', 'corps', 'job', 'networking'), ';'); foreach ($broken_user_list as $alias => $mails) { $sel = Xdb::query( - "SELECT acc.uid, count(e.email) AS nb_mails, + "SELECT acc.uid, count(DISTINCT(e.email)) AS nb_mails, IFNULL(pd.public_name, acc.full_name) AS fullname, - IFNULL(pd.promo, 0) AS promo - FROM aliases AS a - INNER JOIN accounts AS acc ON (a.uid = acc.uid) - LEFT JOIN emails AS e ON (e.uid = acc.uid - AND FIND_IN_SET('active', e.flags) AND e.panne = 0) - LEFT JOIN account_profiles AS ap ON (acc.uid = ap.uid AND FIND_IN_SET('owner', ap.perms)) - LEFT JOIN profile_display AS pd ON (pd.pid = ap.pid) + IFNULL(pd.promo, 0) AS promo, IFNULL(pce.name, 'Aucun') AS corps, + IFNULL(pje.name, 'Aucun') AS job, GROUP_CONCAT(pn.address SEPARATOR ', ') AS networking + FROM aliases AS a + INNER JOIN accounts AS acc ON (a.uid = acc.uid) + LEFT JOIN emails AS e ON (e.uid = acc.uid + AND FIND_IN_SET('active', e.flags) AND e.panne = 0) + LEFT JOIN account_profiles AS ap ON (acc.uid = ap.uid AND FIND_IN_SET('owner', ap.perms)) + LEFT JOIN profile_display AS pd ON (pd.pid = ap.pid) + LEFT JOIN profile_corps AS pc ON (pc.pid = ap.pid) + LEFT JOIN profile_corps_enum AS pce ON (pc.current_corpsid = pce.id) + LEFT JOIN profile_job AS pj ON (pj.pid = ap.pid) + LEFT JOIN profile_job_enum AS pje ON (pj.jobid = pje.id) + LEFT JOIN profile_networking AS pn ON (pn.pid = ap.pid) WHERE a.alias = {?} GROUP BY acc.uid", $alias); @@ -943,7 +946,8 @@ class EmailModule extends PLModule } fputcsv($csv, array($x['fullname'], $x['promo'], $alias, join(',', $mails), $x['nb_mails'], - 'https://www.polytechnique.org/marketing/broken/' . $alias), ';'); + 'https://www.polytechnique.org/marketing/broken/' . $alias, + $x['corps'], $x['job'], $x['networking']), ';'); } } fclose($csv);