Defaultly uses the address given by the user; allows bigger differences between the...
[platal.git] / modules / lists.php
index 3313bea..1ebf75f 100644 (file)
@@ -64,7 +64,7 @@ class ListsModule extends PLModule
     {
         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();
@@ -112,24 +112,25 @@ class ListsModule extends PLModule
             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)
@@ -168,14 +169,20 @@ class ListsModule extends PLModule
 
         $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);
@@ -472,7 +479,7 @@ class ListsModule extends PLModule
             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'));
     }
@@ -579,10 +586,9 @@ class ListsModule extends PLModule
 
     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();