X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=modules%2Fnewsletter.php;h=9ce53c397eef7f60ad1f68682bfcc579931c70dc;hb=f7a93ff33f4c2f41702950e9258faa09894afcd1;hp=ff3f749dbaa63f5c7a0617442d0fdb387c8df8e7;hpb=673e56aa757fce4ea57c27ab2c0d5ce87d713e51;p=platal.git diff --git a/modules/newsletter.php b/modules/newsletter.php index ff3f749..9ce53c3 100644 --- a/modules/newsletter.php +++ b/modules/newsletter.php @@ -34,6 +34,7 @@ class NewsletterModule extends PLModule 'admin/newsletter/categories' => $this->make_hook('admin_nl_cat', AUTH_PASSWD, 'admin'), 'admin/newsletter/edit' => $this->make_hook('admin_nl_edit', AUTH_PASSWD, 'admin'), 'admin/newsletter/edit/delete' => $this->make_hook('admin_nl_delete', AUTH_PASSWD, 'admin'), + 'stat/newsletter' => $this->make_hook('stat_nl', AUTH_PASSWD, 'admin') // Automatic mailing is disabled for X.org NL // 'admin/newsletter/edit/cancel' => $this->make_hook('cancel', AUTH_PASSWD, 'admin'), // 'admin/newsletter/edit/valid' => $this->make_hook('valid', AUTH_PASSWD, 'admin'), @@ -216,14 +217,36 @@ class NewsletterModule extends PLModule $page->assign('nl_list', $nl->listAllIssues()); } - function handler_admin_nl_groups($page) + function handler_admin_nl_groups($page, $sort = 'id', $order = 'ASC') { require_once 'newsletter.inc.php'; + static $titles = array( + 'id' => 'Id', + 'group_name' => 'Groupe', + 'name' => 'Titre', + 'custom_css' => 'CSS spécifique', + 'criteria' => 'Critères actifs' + ); + static $next_orders = array( + 'ASC' => 'DESC', + 'DESC' => 'ASC' + ); + + if (!array_key_exists($sort, $titles)) { + $sort = 'id'; + } + if (!in_array($order, array('ASC', 'DESC'))) { + $order = 'ASC'; + } + $page->changeTpl('newsletter/admin_all.tpl'); $page->setTitle('Administration - Newsletters : Liste des Newsletters'); - - $page->assign('nls', Newsletter::getAll()); + $page->assign('nls', Newsletter::getAll($sort, $order)); + $page->assign('sort', $sort); + $page->assign('order', $order); + $page->assign('next_order', $next_orders[$order]); + $page->assign('titles', $titles); } function handler_admin_nl_edit($page, $nid = 'last', $aid = null, $action = 'edit') { @@ -398,6 +421,11 @@ class NewsletterModule extends PLModule if (!$issue) { $page->kill("La lettre {$nid} n'existe pas."); } + + if ($issue->isEmpty()) { + $page->trigErrorRedirect("La lettre étant vide, il n'est pas possible de l'envoyer.", $nl->adminPrefix()); + } + if (!$issue->scheduleMailing()) { $page->trigErrorRedirect("Une erreur est survenue lors de la validation de l'envoi.", $nl->adminPrefix()); } @@ -469,6 +497,52 @@ class NewsletterModule extends PLModule $table_editor->on_delete(null, null); $table_editor->apply($page, $action, $id); } + + function handler_stat_nl($page) + { + $nl = $this->getNl(); + if (!$nl) { + return PL_NOT_FOUND; + } + if (!$nl->mayEdit()) { + return PL_FORBIDDEN; + } + + $page->setTitle('Statistiques - Newsletter'); + $page->changeTpl('newsletter/statistics.tpl'); + + $data = array(); + foreach (Profile::$cycles as $grade => $name) { + $data[$name] = array(); + list($min, $max) = Profile::extremePromotions($grade); + $bound = (((int)($min / 10)) + 1) * 10; + while ($bound <= $max) { + $data[$name][$min . ' - ' . $bound] = array( + 'count' => $nl->subscriberCount(null, null, $grade, $min, $bound), + 'lost' => $nl->subscriberCount(true, null, $grade, $min, $bound), + 'count_female' => $nl->subscriberCount(null, User::GENDER_FEMALE, $grade, $min, $bound), + 'lost_female' => $nl->subscriberCount(true, User::GENDER_FEMALE, $grade, $min, $bound) + ); + $min = $bound + 1; + $bound += 10; + } + $bound -= 9; + if ($bound <= $max) { + $data[$name][$bound . ' - ' . $max] = array( + 'count' => $nl->subscriberCount(null, null, $grade, $bound, $max), + 'lost' => $nl->subscriberCount(true, null, $grade, $bound, $max), + 'count_female' => $nl->subscriberCount(null, User::GENDER_FEMALE, $grade, $bound, $max), + 'lost_female' => $nl->subscriberCount(true, User::GENDER_FEMALE, $grade, $bound, $max) + ); + } + } + $page->assign_by_ref('nl', $nl); + $page->assign('count', $nl->subscriberCount()); + $page->assign('lost', $nl->lostSubscriberCount()); + $page->assign('count_female', $nl->subscriberCount(null, User::GENDER_FEMALE)); + $page->assign('lost_female', $nl->lostSubscriberCount(User::GENDER_FEMALE)); + $page->assign('data', $data); + } } // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: