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); }
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); }
function handler_lists($page, $order_by = null, $order = null) { require_once 'emails.inc.php'; if (!$this->get_lists_domain()) { return PL_NOT_FOUND; } $page->changeTpl('xnetlists/index.tpl'); if (Get::has('del')) { S::assert_xsrf_token(); $mlist = $this->prepare_list(Get::v('del')); $mlist->unsubscribe(); pl_redirect('lists'); } if (Get::has('add')) { S::assert_xsrf_token(); $mlist = $this->prepare_list(Get::v('add')); $mlist->subscribe(); pl_redirect('lists'); } if (Post::has('del_alias') && may_update()) { S::assert_xsrf_token(); $alias = Post::t('del_alias'); list($local_part, ) = explode('@', $alias); delete_list_alias($local_part, $this->get_lists_domain()); $page->trigSuccess($alias . ' supprimé !'); } $client = $this->prepare_client(); $listes = $client->get_lists(); // Default ordering is by ascending names. if (is_null($order_by) || is_null($order) || !in_array($order_by, array('list', 'desc', 'nbsub')) || !in_array($order, array('asc', 'desc'))) { $order_by = 'list'; $order = 'asc'; } $compare = function ($a, $b) use($order_by, $order) { switch ($order_by) { case 'desc': $a[$order_by] = replace_accent($a[$order_by]); $b[$order_by] = replace_accent($b[$order_by]); case 'list': $res = strcasecmp($a[$order_by], $b[$order_by]); break; case 'nbsub': $res = $a[$order_by] - $b[$order_by]; break; default: $res = 0; } if ($order == 'asc') { return $res; } return $res * -1; }; usort($listes, $compare); $page->assign('listes', $listes); $page->assign('order_by', $order_by); $page->assign('order', $order); $page->assign('aliases', iterate_list_alias($this->get_lists_domain())); $page->assign('may_update', may_update()); if (S::suid()) { $page->trigWarning("Attention : l'affichage des listes de diffusion ne tient pas compte de l'option « Voir le site comme… »."); } global $globals; if (count($listes) > 0 && !$globals->asso('has_ml')) { XDB::execute("UPDATE groups\n SET flags = CONCAT_WS(',', IF(flags = '', NULL, flags), 'has_ml')\n WHERE id = {?}", $globals->asso('id')); } }