Example #1
0
/** Subscribes user to various event related mailing lists.
 *
 * @param $uid: user's id.
 * @param short_name: event's short_name, which corresponds to the beginning of the emails.
 * @param participate: indicates if the user takes part at the event or not;
 *      -1 means he did not answer, 0 means no, and 1 means yes.
 * @param paid: has the user already payed anything?
 *      0 means no, a positive amount means yes.
 * @param payment: is this function called from a payment page?
 *      If true, only payment related lists should be updated.
 */
function subscribe_lists_event($uid, $short_name, $participate, $paid, $payment = false)
{
    global $globals;
    require_once 'emails.inc.php';
    if (is_null($short_name)) {
        return;
    }
    /** If $payment is not null, we do not retrieve the value of $participate,
     * thus we do not alter participant and absent lists.
     */
    if ($payment === true) {
        if ($paid > 0) {
            delete_from_list_alias($uid, $short_name . $globals->xnet->unpayed_list, $globals->xnet->evts_domain, 'event');
            add_to_list_alias($uid, $short_name . $globals->xnet->payed_list, $globals->xnet->evts_domain, 'event');
        }
    } else {
        switch ($participate) {
            case -1:
                delete_from_list_alias($uid, $short_name . $globals->xnet->participant_list, $globals->xnet->evts_domain, 'event');
                delete_from_list_alias($uid, $short_name . $globals->xnet->unpayed_list, $globals->xnet->evts_domain, 'event');
                delete_from_list_alias($uid, $short_name . $globals->xnet->payed_list, $globals->xnet->evts_domain, 'event');
                add_to_list_alias($uid, $short_name . $globals->xnet->absent_list, $globals->xnet->evts_domain, 'event');
                break;
            case 0:
                delete_from_list_alias($uid, $short_name . $globals->xnet->participant_list, $globals->xnet->evts_domain, 'event');
                delete_from_list_alias($uid, $short_name . $globals->xnet->absent_list, $globals->xnet->evts_domain, 'event');
                delete_from_list_alias($uid, $short_name . $globals->xnet->unpayed_list, $globals->xnet->evts_domain, 'event');
                delete_from_list_alias($uid, $short_name . $globals->xnet->payed_list, $globals->xnet->evts_domain, 'event');
                break;
            case 1:
                add_to_list_alias($uid, $short_name . $globals->xnet->participant_list, $globals->xnet->evts_domain, 'event');
                delete_from_list_alias($uid, $short_name . $globals->xnet->absent_list, $globals->xnet->evts_domain, 'event');
                if ($paid > 0) {
                    delete_from_list_alias($uid, $short_name . $globals->xnet->unpayed_list, $globals->xnet->evts_domain, 'event');
                    add_to_list_alias($uid, $short_name . $globals->xnet->payed_list, $globals->xnet->evts_domain, 'event');
                } else {
                    add_to_list_alias($uid, $short_name . $globals->xnet->unpayed_list, $globals->xnet->evts_domain, 'event');
                    delete_from_list_alias($uid, $short_name . $globals->xnet->payed_list, $globals->xnet->evts_domain, 'event');
                }
                break;
        }
    }
}
Example #2
0
 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()));
 }
Example #3
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);
 }
Example #4
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));
 }