Ejemplo n.º 1
0
 function handler_directory_sync($page)
 {
     global $globals;
     require_once 'emails.inc.php';
     $page->changeTpl('xnetgrp/sync.tpl');
     Platal::load('lists', 'lists.inc.php');
     if (Env::has('add_users')) {
         S::assert_xsrf_token();
         $users = array_keys(Env::v('add_users'));
         $former_users = XDB::fetchColumn('SELECT  uid
                                             FROM  group_former_members
                                            WHERE  remember = TRUE AND asso_id = {?} AND uid IN {?}', $globals->asso('id'), $users);
         $new_users = array_diff($users, $former_users);
         foreach ($former_users as $uid) {
             $user = User::getSilentWithUID($uid);
             $page->trigWarning($user->fullName() . ' est un ancien membre du groupe qui ne souhaite pas y revenir.');
         }
         if (count($former_users) > 1) {
             $page->trigWarning('S\'ils souhaitent revenir dans le groupe, il faut qu\'ils en fassent la demande sur la page d\'accueil du groupe.');
         } elseif (count($former_users)) {
             $page->trigWarning('S\'il souhaite revenir dans le groupe, il faut qu\'il en fasse la demande sur la page d\'accueil du groupe.');
         }
         $data = array();
         foreach ($new_users as $uid) {
             Group::subscribe($globals->asso('id'), $uid);
         }
     }
     if (Env::has('add_nonusers')) {
         S::assert_xsrf_token();
         $nonusers = array_keys(Env::v('add_nonusers'));
         foreach ($nonusers as $email) {
             if ($user = User::getSilent($email) || !isvalid_email($email)) {
                 continue;
             }
             list($local_part, $domain) = explode('@', strtolower($email));
             $hruid = User::makeHrid($local_part, $domain, 'ext');
             if ($user = User::getSilent($hruid)) {
                 continue;
             }
             require_once 'name.func.inc.php';
             $parts = explode('.', $local_part);
             if (count($parts) == 1) {
                 $lastname = $display_name = capitalize_name($mbox);
                 $firstname = '';
             } else {
                 $display_name = $firstname = capitalize_name($parts[0]);
                 $lastname = capitalize_name(implode(' ', array_slice($parts, 1)));
             }
             $full_name = build_full_name($firstname, $lastname);
             $directory_name = build_directory_name($firstname, $lastname);
             $sort_name = build_sort_name($firstname, $lastname);
             XDB::execute('INSERT INTO  accounts (hruid, display_name, full_name, directory_name, sort_name,
                                                  firstname, lastname, email, type, state)
                                VALUES  ({?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, \'xnet\', \'disabled\')', $hruid, $display_name, $full_name, $directory_name, $sort_name, $firstname, $lastname, $email);
             $uid = XDB::insertId();
             Group::subscribe($globals->asso('id'), $uid);
         }
     }
     if (Env::has('add_users') || Env::has('add_nonusers')) {
         $page->trigSuccess('Ajouts réalisés avec succès.');
     }
     $user = S::user();
     $client = new MMList($user, $globals->asso('mail_domain'));
     $lists = $client->get_lists();
     $members = array();
     foreach ($lists as $list) {
         $details = $client->get_members($list['list']);
         $members = array_merge($members, list_extract_members($details[1]));
     }
     $members = array_unique($members);
     $uids = array();
     $users = array();
     $nonusers = array();
     foreach ($members as $email) {
         if ($user = User::getSilent($email)) {
             $uids[] = $user->id();
         } else {
             $nonusers[] = $email;
         }
     }
     $aliases = iterate_list_alias($globals->asso('mail_domain'));
     foreach ($aliases as $alias) {
         list($local_part, $domain) = explode('@', $alias);
         $aliases_members = list_alias_members($local_part, $domain);
         $users = array_merge($users, $aliases_members['users']);
         $nonusers = array_merge($nonusers, $aliases_members['nonusers']);
     }
     foreach ($users as $user) {
         $uids[] = $user->id();
     }
     $nonusers = array_unique($nonusers);
     $uids = array_unique($uids);
     if (count($uids)) {
         $uids = XDB::fetchColumn('SELECT  a.uid
                                     FROM  accounts AS a
                                    WHERE  a.uid IN {?} AND NOT EXISTS (SELECT  *
                                                                          FROM  group_members AS g
                                                                         WHERE  a.uid = g.uid AND g.asso_id = {?})', $uids, $globals->asso('id'));
         $users = User::getBulkUsersWithUIDs($uids);
         usort($users, 'User::compareDirectoryName');
     } else {
         $users = array();
     }
     sort($nonusers);
     $page->assign('users', $users);
     $page->assign('nonusers', $nonusers);
 }
Ejemplo n.º 2
0
 function handler_aaliases($page, $alias = null)
 {
     global $globals;
     require_once 'emails.inc.php';
     $page->setTitle('Administration - Aliases');
     if (Post::has('new_alias')) {
         pl_redirect('admin/aliases/' . Post::t('new_alias') . '@' . $globals->mail->domain);
     }
     // If no alias, list them all.
     if (is_null($alias)) {
         $page->changeTpl('lists/admin_aliases.tpl');
         $page->assign('aliases', array_merge(iterate_list_alias($globals->mail->domain), iterate_list_alias($globals->mail->domain2)));
         return;
     }
     list($local_part, $domain) = explode('@', $alias);
     if (!($globals->mail->domain == $domain || $globals->mail->domain2 == $domain) || !preg_match("/^[a-zA-Z0-9\\-\\.]*\$/", $local_part)) {
         $page->trigErrorRedirect('Le nom de l\'alias est erroné.', $globals->asso('diminutif') . 'admin/aliases');
     }
     // Now we can perform the action.
     if (Post::has('del_alias')) {
         S::assert_xsrf_token();
         delete_list_alias($local_part, $domain);
         $page->trigSuccessRedirect($alias . ' supprimé.', 'admin/aliases');
     }
     if (Post::has('add_member')) {
         S::assert_xsrf_token();
         if (add_to_list_alias(Post::t('add_member'), $local_part, $domain)) {
             $page->trigSuccess('Ajout réussit.');
         } else {
             $page->trigError('Ajout infructueux.');
         }
     }
     if (Get::has('del_member')) {
         S::assert_xsrf_token();
         if (delete_from_list_alias(Get::t('del_member'), $local_part, $domain)) {
             $page->trigSuccess('Suppression réussie.');
         } else {
             $page->trigError('Suppression infructueuse.');
         }
     }
     $page->changeTpl('lists/admin_edit_alias.tpl');
     $page->assign('members', list_alias_members($local_part, $domain));
     $page->assign('alias', $alias);
 }
Ejemplo n.º 3
0
 function handler_aadmin($page, $lfull = null)
 {
     if (!$this->get_lists_domain() || is_null($lfull)) {
         return PL_NOT_FOUND;
     }
     $page->changeTpl('xnetlists/alias-admin.tpl');
     require_once 'emails.inc.php';
     list($local_part, $domain) = explode('@', $lfull);
     if ($this->get_lists_domain() != $domain || !preg_match("/^[a-zA-Z0-9\\-\\.]*\$/", $local_part)) {
         global $globals;
         $page->trigErrorRedirect('Le nom de l\'alias est erroné.', $globals->asso('diminutif') . '/lists');
     }
     if (Env::has('add_member')) {
         S::assert_xsrf_token();
         if (add_to_list_alias(Env::t('add_member'), $local_part, $domain)) {
             $page->trigSuccess('Ajout réussi.');
         } else {
             $page->trigError('Ajout infructueux.');
         }
     }
     if (Env::has('del_member')) {
         S::assert_xsrf_token();
         if (delete_from_list_alias(Env::t('del_member'), $local_part, $domain)) {
             $page->trigSuccess('Suppression réussie.');
         } else {
             $page->trigError('Suppression infructueuse.');
         }
     }
     $page->assign('members', list_alias_members($local_part, $domain));
 }