autocomplete improvements: can find pierre-yves when looking for yves
[platal.git] / modules / lists.php
index 009950b..7111516 100644 (file)
@@ -21,7 +21,7 @@
 
 class ListsModule extends PLModule
 {
-    var $client;
+    protected $client;
 
     function handlers()
     {
@@ -31,7 +31,7 @@ class ListsModule extends PLModule
             'lists/create'    => $this->make_hook('create',    AUTH_MDP),
 
             'lists/members'   => $this->make_hook('members',   AUTH_COOKIE),
-            'lists/trombi'    => $this->make_hook('trombi',    AUTH_COOKIE),
+            'lists/annu'      => $this->make_hook('annu',      AUTH_COOKIE),
             'lists/archives'  => $this->make_hook('archives',  AUTH_COOKIE),
             'lists/archives/rss' => $this->make_hook('rss',    AUTH_PUBLIC),
 
@@ -225,16 +225,6 @@ class ListsModule extends PLModule
         }
     }
 
-    function changeTpl($tpl)
-    {
-        if (!empty($GLOBALS['IS_XNET_SITE'])) {
-            new_group_open_page($tpl);
-        } else {
-            global $page;
-            $page->changeTpl($tpl);
-        }
-    }
-
     function handler_members(&$page, $liste = null)
     {
         if (is_null($liste)) {
@@ -243,7 +233,7 @@ class ListsModule extends PLModule
 
         $this->prepare_client($page);
 
-        $this->changeTpl('lists/members.tpl');
+        $page->changeTpl('lists/members.tpl');
 
         if (Get::has('del')) {
             $this->client->unsubscribe($liste);
@@ -272,42 +262,7 @@ class ListsModule extends PLModule
         }
     }
 
-    function compare($a, $b)
-    {
-        if ($a['promo'] == $b['promo']) {
-            if ($a['nom'] == $b['nom']) {
-                return strcmp($a['prenom'], $b['prenom']);
-            }
-            return strcmp($a['nom'], $b['nom']);
-        }
-        return $a['promo'] - $b['promo'];
-    }
-
-    function _get_list($offset, $limit)
-    {
-        global $platal;
-        list($total, $members) = $this->client->get_members_limit($platal->argv[1], $offset, $limit);
-
-        $membres = Array();
-        foreach ($members as $member) {
-            list($m) = explode('@',$member[1]);
-            $res = XDB::query("SELECT  prenom,if (nom_usage='', nom, nom_usage) AS nom,
-                                                 promo, a.alias AS forlife
-                                           FROM  auth_user_md5 AS u
-                                     INNER JOIN  aliases AS a ON u.user_id = a.id
-                                     INNER JOIN  photo AS p ON p.uid = u.user_id
-                                          WHERE  a.alias = {?}", $m);
-            if ($tmp = $res->fetchOneAssoc()) {
-                $membres[$tmp['nom']] = $tmp;
-            } else {
-                $total--;
-            }
-        }
-        uasort($membres, array($this, 'compare'));
-        return array($total, $membres);
-    }
-
-    function handler_trombi(&$page, $liste = null)
+    function handler_annu(&$page, $liste = null, $action = null, $subaction = null)
     {
         if (is_null($liste)) {
             return PL_NOT_FOUND;
@@ -315,30 +270,42 @@ class ListsModule extends PLModule
 
         $this->prepare_client($page);
 
-        $this->changeTpl('lists/trombi.tpl');
-
         if (Get::has('del')) {
             $this->client->unsubscribe($liste);
-            pl_redirect('lists/trombi/'.$liste);
+            pl_redirect('lists/annu/'.$liste);
         }
         if (Get::has('add')) {
             $this->client->subscribe($liste);
-            pl_redirect('lists/trombi/'.$liste);
+            pl_redirect('lists/annu/'.$liste);
         }
 
         $owners = $this->client->get_owners($liste);
-
-        if (is_array($owners)) {
-            $moderos = list_sort_owners($owners[1]);
-
-            $page->assign_by_ref('details', $owners[0]);
-            $page->assign_by_ref('owners',  $moderos);
-
-            $trombi = new Trombi(array(&$this, '_get_list'));
-            $page->assign('trombi', $trombi);
-        } else {
+        if (!is_array($owners)) {
             $page->kill("La liste n'existe pas ou tu n'as pas le droit d'en voir les détails");
         }
+
+        global $platal;
+        list(,$members) = $this->client->get_members($liste);
+        $users = array();
+        foreach ($members as $m) {
+            $users[] = $m[1];
+        }
+        require_once 'userset.inc.php';
+        $view = new ArraySet($users);
+        $view->addMod('trombi', 'Trombinoscope', true, array('with_promo' => true));
+        if (empty($GLOBALS['IS_XNET_SITE'])) {
+            $view->addMod('minifiche', 'Minifiches', false);
+        }
+        $view->addMod('geoloc', 'Planisphère');
+        $view->apply("lists/annu/$liste", $page, $action, $subaction);
+        if ($action == 'geoloc' && $subaction) {
+            return;
+        }
+
+        $page->changeTpl('lists/annu.tpl');
+        $moderos = list_sort_owners($owners[1]);
+        $page->assign_by_ref('details', $owners[0]);
+        $page->assign_by_ref('owners',  $moderos);
     }
 
     function handler_archives(&$page, $liste = null, $action = null, $artid = null)
@@ -351,7 +318,7 @@ class ListsModule extends PLModule
 
         $domain = $this->prepare_client($page);
 
-        $this->changeTpl('lists/archives.tpl');
+        $page->changeTpl('lists/archives.tpl');
 
         if (list($det) = $this->client->get_members($liste)) {
             if (substr($liste,0,5) != 'promo' && ($det['ins'] || $det['priv'])
@@ -451,7 +418,7 @@ class ListsModule extends PLModule
 
         $domain = $this->prepare_client($page);
 
-        $this->changeTpl('lists/moderate.tpl');
+        $page->changeTpl('lists/moderate.tpl');
 
         $page->register_modifier('hdc', 'list_header_decode');
 
@@ -513,7 +480,7 @@ class ListsModule extends PLModule
             if (list($subs,$mails) = $this->client->get_pending_ops($liste)) {
                 foreach($subs as $user) {
                     if ($user['id'] == Env::v('sid')) {
-                        $this->changeTpl('lists/moderate_sub.tpl');
+                        $page->changeTpl('lists/moderate_sub.tpl');
                         $page->assign('del_user', $user);
                         return;
                     }
@@ -533,6 +500,22 @@ class ListsModule extends PLModule
         }
     }
 
+    static public function no_login_callback($login)
+    {
+        require_once 'user.func.inc.php';
+        global $list_unregistered;
+
+        $users = get_not_registered_user($login, true);
+        if ($users->total()) {
+            if (!isset($list_unregistered)) {
+                $list_unregistered = array();
+            }
+            $list_unregistered[$login] = $users;
+        } else {
+            _default_user_callback($login);
+        }
+    }
+
     function handler_admin(&$page, $liste = null)
     {
         global $globals;
@@ -541,13 +524,43 @@ class ListsModule extends PLModule
             return PL_NOT_FOUND;
         }
 
-        $this->prepare_client($page);
+        $domain = $this->prepare_client($page);
+
+        $page->changeTpl('lists/admin.tpl');
 
-        $this->changeTpl('lists/admin.tpl');
+        if (Env::has('send_mark')) {
+            $actions = Env::v('mk_action');
+            $uids    = Env::v('mk_uid');
+            $mails   = Env::v('mk_email');
+            foreach ($actions as $key=>$action) {
+                switch ($action) {
+                  case 'none':
+                    break;
+
+                  case 'marketu': case 'markets':
+                    require_once 'emails.inc.php';
+                    $mail = valide_email($mails[$key]);
+                    if (isvalid_email_redirection($mail)) {
+                        $from = ($action == 'marketu') ? 'user' : 'staff';
+                        $market = Marketing::get($uids[$key], $mail);
+                        if (!$market) {
+                            $market = new Marketing($uids[$key], $mail, 'list', "$liste@$domain", $from, S::v('uid'));
+                            $market->add();
+                            break;
+                        }
+                    }
+
+                  default:
+                    XDB::execute('INSERT IGNORE INTO  register_subs (uid, type, sub, domain)
+                                              VALUES  ({?}, \'list\', {?}, {?})',
+                                  $uids[$key], $liste, $domain);
+                }
+            }
+        }
 
         if (Env::has('add_member')) {
             require_once('user.func.inc.php');
-            $members = get_users_forlife_list(Env::v('add_member'));
+            $members = get_users_forlife_list(Env::v('add_member'), false, array('ListsModule', 'no_login_callback'));
             $arr = $this->client->mass_subscribe($liste, $members);
             if (is_array($arr)) {
                 foreach($arr as $addr) {
@@ -568,7 +581,7 @@ class ListsModule extends PLModule
 
         if (Env::has('add_owner')) {
             require_once('user.func.inc.php');
-            $owners = get_users_forlife_list(Env::v('add_owner'));
+            $owners = get_users_forlife_list(Env::v('add_owner'), false, array('ListsModule', 'no_login_callback'));
             if ($owners) {
                 foreach ($owners as $login) {
                     if ($this->client->add_owner($liste, $login)) {
@@ -588,6 +601,10 @@ class ListsModule extends PLModule
         }
 
         if (list($det,$mem,$own) = $this->client->get_members($liste)) {
+            global $list_unregistered;
+            if ($list_unregistered) {
+                $page->assign_by_ref('unregistered', $list_unregistered);
+            }
             $membres = list_sort_members($mem, @$tri_promo);
             $moderos = list_sort_owners($own, @$tri_promo);
 
@@ -611,7 +628,7 @@ class ListsModule extends PLModule
 
         $this->prepare_client($page);
 
-        $this->changeTpl('lists/options.tpl');
+        $page->changeTpl('lists/options.tpl');
 
         if (Post::has('submit')) {
             $values = $_POST;
@@ -673,7 +690,7 @@ class ListsModule extends PLModule
             $type   = 'list';
         }
 
-        $this->changeTpl('lists/delete.tpl');
+        $page->changeTpl('lists/delete.tpl');
         if (Post::v('valid') == 'OUI') {
             if ($this->client->delete_list($liste, Post::b('del_archive'))) {
                 foreach (array('', '-owner', '-admin', '-bounces') as $app) {
@@ -704,7 +721,7 @@ class ListsModule extends PLModule
 
         $this->prepare_client($page);
 
-        $this->changeTpl('lists/soptions.tpl');
+        $page->changeTpl('lists/soptions.tpl');
 
         if (Post::has('submit')) {
             $values = $_POST;
@@ -731,7 +748,7 @@ class ListsModule extends PLModule
 
         $this->prepare_client($page);
 
-        $this->changeTpl('lists/check.tpl');
+        $page->changeTpl('lists/check.tpl');
 
         if (Post::has('correct')) {
             $this->client->check_options($liste, true);
@@ -746,7 +763,7 @@ class ListsModule extends PLModule
     }
 
     function handler_admin_all(&$page) {
-        $this->changeTpl('lists/admin_all.tpl');
+        $page->changeTpl('lists/admin_all.tpl');
         $page->assign('xorg_title','Polytechnique.org - Administration - Mailing lists');
 
         $client = new MMList(S::v('uid'), S::v('password'));