function handler_admin($page) { $page->changeTpl('xnet/admin.tpl'); if (Get::has('del')) { $res = XDB::query('SELECT id, nom, mail_domain FROM groups WHERE diminutif={?}', Get::v('del')); list($id, $nom, $domain) = $res->fetchOneRow(); $page->assign('nom', $nom); if ($id && Post::has('del')) { S::assert_xsrf_token(); XDB::query('DELETE FROM group_members WHERE asso_id={?}', $id); $page->trigSuccess('membres supprimés'); if ($domain) { XDB::execute('DELETE v FROM email_virtual AS v INNER JOIN email_virtual_domains AS d ON (v.domain = d.id) WHERE d.name = {?}', $domain); XDB::execute('DELETE FROM email_virtual_domains WHERE name = {?}', $domain); $page->trigSuccess('suppression des alias mails'); $mmlist = new MMList(S::v('uid'), S::v('password'), $domain); if ($listes = $mmlist->get_lists()) { foreach ($listes as $l) { $mmlist->delete_list($l['list'], true); } $page->trigSuccess('mail lists surpprimées'); } } XDB::query('DELETE FROM groups WHERE id={?}', $id); $page->trigSuccess("Groupe {$nom} supprimé"); Get::kill('del'); } if (!$id) { Get::kill('del'); } } if (Post::has('diminutif') && Post::v('diminutif') != "") { S::assert_xsrf_token(); $res = XDB::query('SELECT COUNT(*) FROM groups WHERE diminutif = {?}', Post::v('diminutif')); if ($res->fetchOneCell() == 0) { XDB::execute('INSERT INTO groups (id, diminutif) VALUES (NULL, {?})', Post::v('diminutif')); pl_redirect(Post::v('diminutif') . '/edit'); } else { $page->trigError('Le diminutif demandé est déjà pris.'); } } $res = XDB::query('SELECT nom, diminutif FROM groups ORDER BY nom'); $page->assign('assos', $res->fetchAllAssoc()); }
function handler_admin_member($page, $user) { global $globals; $user = User::getSilent($user); if (empty($user)) { return PL_NOT_FOUND; } if (!$user->inGroup($globals->asso('id'))) { pl_redirect('annuaire'); } $page->changeTpl('xnetgrp/membres-edit.tpl'); $page->addJsLink('xnet_members.js'); $mmlist = new MMList(S::user(), $globals->asso('mail_domain')); if (Post::has('change')) { S::assert_xsrf_token(); require_once 'emails.inc.php'; require_once 'name.func.inc.php'; // Convert user status to X if (!Post::blank('x')) { $forlife = $this->changeLogin($page, $user, Post::i('userid'), Post::b('broken'), Post::b('marketing'), Post::v('marketing_from')); if ($forlife) { pl_redirect('member/' . $forlife); } } // Update user info if ($user->type == 'virtual' || $user->type == 'xnet' && !$user->perms) { $lastname = capitalize_name(Post::t('lastname')); if (Post::s('type') != 'virtual') { $firstname = capitalize_name(Post::t('firstname')); } else { $firstname = ''; } $full_name = build_full_name($firstname, $lastname); $directory_name = build_directory_name($firstname, $lastname); $sort_name = build_sort_name($firstname, $lastname); XDB::query('UPDATE accounts SET full_name = {?}, directory_name = {?}, sort_name = {?}, display_name = {?}, firstname = {?}, lastname = {?}, sex = {?}, type = {?} WHERE uid = {?}', $full_name, $directory_name, $sort_name, Post::t('display_name'), $firstname, $lastname, Post::t('sex') == 'male' ? 'male' : 'female', Post::t('type') == 'xnet' ? 'xnet' : 'virtual', $user->id()); } // Updates email. $new_email = strtolower(Post::t('email')); if (($user->type == 'virtual' || $user->type == 'xnet' && !$user->perms) && require_email_update($user, $new_email)) { XDB::query('UPDATE accounts SET email = {?} WHERE uid = {?}', $new_email, $user->id()); if ($user->forlifeEmail()) { $listClient = new MMList(S::user()); $listClient->change_user_email($user->forlifeEmail(), $new_email); update_alias_user($user->forlifeEmail(), $new_email); } $user = User::getWithUID($user->id()); } if (XDB::affectedRows()) { $page->trigSuccess('Données de l\'utilisateur mises à jour.'); } if ($user->type == 'xnet' && !$user->perms) { if (Post::b('suggest')) { $request = new AccountReq(S::user(), $user->hruid, Post::t('email'), $globals->asso('nom'), $globals->asso('diminutif')); $request->submit(); $page->trigSuccess('Le compte va bientôt être activé.'); } if (Post::b('again')) { $this->again($user->id()); $page->trigSuccess('Relance effectuée avec succès.'); } } // Update group params for user $perms = Post::v('group_perms'); $comm = Post::t('comm'); $position = Post::t('group_position') == '' ? null : Post::v('group_position'); if ($user->group_perms != $perms || $user->group_comm != $comm || $user->group_position != $position) { XDB::query('UPDATE group_members SET perms = {?}, comm = {?}, position = {?} WHERE uid = {?} AND asso_id = {?}', $perms == 'admin' ? 'admin' : 'membre', $comm, $position, $user->id(), $globals->asso('id')); if (XDB::affectedRows()) { if ($perms != $user->group_perms) { $page->trigSuccess('Permissions modifiées !'); } if ($comm != $user->group_comm) { $page->trigSuccess('Commentaire mis à jour.'); } if ($position != $user->group_position) { $page->trigSuccess('Poste mis à jour.'); } } } // Gets user info again as they might have change $user = User::getSilent($user->id()); // Update ML subscriptions foreach (Env::v('ml1', array()) as $ml => $state) { $ask = empty($_REQUEST['ml2'][$ml]) ? 0 : 2; if ($ask == $state) { continue; } if ($state == '1') { $page->trigWarning("{$user->fullName()} a " . "actuellement une demande d'inscription en " . "cours sur <strong>{$ml}@</strong> !!!"); } elseif ($ask) { $mmlist->mass_subscribe($ml, array($user->forlifeEmail())); $page->trigSuccess("{$user->fullName()} a été abonné à {$ml}@."); } else { $mmlist->mass_unsubscribe($ml, array($user->forlifeEmail())); $page->trigSuccess("{$user->fullName()} a été désabonné de {$ml}@."); } } // Change subscriptioin to aliases foreach (Env::v('ml3', array()) as $ml => $state) { require_once 'emails.inc.php'; $ask = !empty($_REQUEST['ml4'][$ml]); list($local_part, ) = explode('@', $ml); if ($ask == $state) { continue; } if ($ask) { add_to_list_alias($user->id(), $local_part, $globals->asso('mail_domain')); $page->trigSuccess("{$user->fullName()} a été abonné à {$ml}."); } else { delete_from_list_alias($user->id(), $local_part, $globals->asso('mail_domain')); $page->trigSuccess("{$user->fullName()} a été désabonné de {$ml}."); } } if ($globals->asso('has_nl')) { $nl = NewsLetter::forGroup($globals->asso('shortname')); // Updates group's newsletter subscription. if (Post::i('newsletter') == 1) { $nl->subscribe($user); } else { $nl->unsubscribe(null, $user->id()); } } } $res = XDB::rawFetchAllAssoc('SHOW COLUMNS FROM group_members LIKE \'position\''); $positions = str_replace(array('enum(', ')', '\''), '', $res[0]['Type']); if ($globals->asso('has_nl')) { $nl = NewsLetter::forGroup($globals->asso('shortname')); $nl_registered = $nl->subscriptionState($user); } else { $nl_registered = false; } $page->assign('user', $user); $page->assign('suggest', $this->suggest($user)); $page->assign('listes', $mmlist->get_lists($user->forlifeEmail())); $page->assign('alias', $user->emailGroupAliases($globals->asso('mail_domain'))); $page->assign('positions', explode(',', $positions)); $page->assign('nl_registered', $nl_registered); $page->assign('pending_xnet_account', XDB::fetchOneCell('SELECT 1 FROM register_pending_xnet WHERE uid = {?}', $user->id())); }