Пример #1
0
function get_all_redirects($membres, $mls, $client)
{
    global $globals;
    $tos = array();
    // TODO: add more filters to choose users
    if (!empty($membres)) {
        $uf = new UserFilter(new UFC_Group($globals->asso('id')));
        $tos = $uf->getUsers();
    }
    foreach ($mls as $ml) {
        // $list_members is a (list_details, members, list_owners) array, where
        // members is an array of (0 => name, 1 => email) arrays.
        $list_members = $client->get_members($ml);
        if ($list_members) {
            foreach ($list_members[1] as $mem) {
                $uf = new UserFilter(new UFC_Email($mem[1]));
                $user = $uf->getUser();
                if ($user) {
                    $tos[] = $user;
                } else {
                    $tos[] = $mem[1];
                }
            }
        }
    }
    return $tos;
}
Пример #2
0
 public function handler_notifs($page, $action = null, $arg = null)
 {
     $page->changeTpl('carnet/notifs.tpl');
     if ($action) {
         S::assert_xsrf_token();
         switch ($action) {
             case 'add_promo':
                 $this->addPromo($page, $arg);
                 break;
             case 'del_promo':
                 $this->delPromo($page, $arg);
                 break;
             case 'add_group':
                 $this->addGroup($page, $arg);
                 break;
             case 'del_group':
                 $this->delGroup($page, $arg);
                 break;
             case 'del_nonins':
                 $user = User::get($arg);
                 if ($user) {
                     $this->delNonRegistered($page, $user);
                 }
                 break;
             case 'add_nonins':
                 $user = User::get($arg);
                 if ($user) {
                     $this->addNonRegistered($page, $user);
                 }
                 break;
         }
     }
     if (Env::has('subs')) {
         S::assert_xsrf_token();
         $flags = new PlFlagSet();
         foreach (Env::v('sub') as $key => $value) {
             $flags->addFlag($key, $value);
         }
         XDB::execute('UPDATE  watch
                          SET  actions = {?}
                        WHERE  uid = {?}', $flags, S::i('uid'));
         S::user()->invalidWatchCache();
         Platal::session()->updateNbNotifs();
     }
     if (Env::has('flags_contacts')) {
         S::assert_xsrf_token();
         XDB::execute('UPDATE  watch
                          SET  ' . XDB::changeFlag('flags', 'contacts', Env::b('contacts')) . '
                        WHERE  uid = {?}', S::i('uid'));
         S::user()->invalidWatchCache();
         Platal::session()->updateNbNotifs();
     }
     if (Env::has('flags_mail')) {
         S::assert_xsrf_token();
         XDB::execute('UPDATE  watch
                          SET  ' . XDB::changeFlag('flags', 'mail', Env::b('mail')) . '
                        WHERE  uid = {?}', S::i('uid'));
         S::user()->invalidWatchCache();
         Platal::session()->updateNbNotifs();
     }
     $user = S::user();
     $nonins = new UserFilter(new UFC_WatchRegistration($user));
     $promo = XDB::fetchColumn('SELECT  promo
                                  FROM  watch_promo
                                 WHERE  uid = {?}
                              ORDER BY  promo', S::i('uid'));
     $page->assign('promo_count', count($promo));
     $ranges = array();
     $range_start = null;
     $range_end = null;
     foreach ($promo as $p) {
         if (is_null($range_start)) {
             $range_start = $range_end = $p;
         } else {
             if ($p != $range_end + 1) {
                 $ranges[] = array($range_start, $range_end);
                 $range_start = $range_end = $p;
             } else {
                 $range_end = $p;
             }
         }
     }
     $ranges[] = array($range_start, $range_end);
     $page->assign('promo_ranges', $ranges);
     $page->assign('nonins', $nonins->getUsers());
     $groups = XDB::fetchColumn('SELECT  g.nom
                                   FROM  watch_group AS w
                             INNER JOIN  groups      AS g ON (g.id = w.groupid)
                                  WHERE  w.uid = {?}
                               ORDER BY  g.nom', S::i('uid'));
     $page->assign('groups', $groups);
     $page->assign('groups_count', count($groups));
     list($flags, $actions) = XDB::fetchOneRow('SELECT  flags, actions
                                                  FROM  watch
                                                 WHERE  uid = {?}', S::i('uid'));
     $flags = new PlFlagSet($flags);
     $actions = new PlFlagSet($actions);
     $page->assign('flags', $flags);
     $page->assign('actions', $actions);
 }
Пример #3
0
 function handler_week($page, $sorting = 'per_promo')
 {
     $page->changeTpl('marketing/this_week.tpl');
     $sort = $sorting == 'per_promo' ? new UFO_Promo() : new UFO_Registration();
     $uf = new UserFilter(new UFC_Registered(false, '>', strtotime('1 week ago')), $sort);
     $page->assign('users', $uf->getUsers());
 }
Пример #4
0
 /** Sent this issue to all valid recipients
  * @return Number of issues sent
  */
 public function sendToAll()
 {
     $this->fetchArticles();
     XDB::execute('UPDATE  newsletter_issues
                      SET  state = \'sent\', date=CURDATE()
                    WHERE  id = {?}', $this->id);
     // Every minute, select BATCH_SIZE users who:
     // * are subscribed to the newsletter
     // * have not yet been mailed this issue of the newsletter
     // * have a valid email address
     // ... and send them the current issue.
     // Once a mail is sent, newsletter_ins is updated to prevent selecting again the same user a minute later.
     $ufc = new PFC_And($this->getRecipientsUFC(), new UFC_NLSubscribed($this->nl->id, $this->id), new UFC_HasValidEmail());
     $uf = new UserFilter($ufc, array(new UFO_IsAdmin(true), new UFO_Uid()));
     $limit = new PlLimit(self::BATCH_SIZE);
     $global_sent = array();
     while (true) {
         $sent = array();
         $users = $uf->getUsers($limit);
         if (count($users) == 0) {
             break;
         }
         foreach ($users as $user) {
             if (array_key_exists($user->id(), $global_sent)) {
                 // Such a condition may happen if an user:
                 // 1. was mailed the issue,
                 // 2. unsubscribed the newsletter,
                 // 3. subscribed again before the sending was done.
                 // Such a case is reported by mail to people who monitor the website.
                 // If you are reading this comment because of such a mail and the lines above explain what happened,
                 // you only need to reset the state of the issue to "pending".
                 // A cron script will then restart the mailing from where it stopped and only the problematic user will reveive the issue twice.
                 Platal::page()->kill('Sending the same newsletter issue ' . $this->id . ' to user ' . $user->id() . ' twice, something must be wrong.');
             }
             $sent[] = $user->id();
             $global_sent[$user->id()] = true;
             $this->sendTo($user, $hash);
         }
         XDB::execute("UPDATE  newsletter_ins\n                             SET  last = {?}\n                           WHERE  nlid = {?} AND uid IN {?}", $this->id, $this->nl->id, $sent);
         sleep(60);
     }
     return count($global_sent);
 }
Пример #5
0
 function handler_admin_member_new_ajax($page)
 {
     pl_content_headers("text/html");
     $page->changeTpl('xnetgrp/membres-new-search.tpl', NO_SKIN);
     $users = array();
     $same_email = false;
     if (Env::has('login')) {
         $user = User::getSilent(Env::t('login'));
         if ($user && $user->state != 'pending') {
             $users = array($user->id() => $user);
             $same_email = true;
         }
     }
     if (empty($users)) {
         list($lastname, $firstname) = str_replace(array('-', ' ', "'"), '%', array(Env::t('nom'), Env::t('prenom')));
         $cond = new PFC_And();
         if (!empty($lastname)) {
             $cond->addChild(new UFC_NameTokens($lastname, array(), false, false, Profile::LASTNAME));
         }
         if (!empty($firstname)) {
             $cond->addChild(new UFC_NameTokens($firstname, array(), false, false, Profile::FIRSTNAME));
         }
         if (Env::t('promo')) {
             $cond->addChild(new UFC_Promo('=', UserFilter::DISPLAY, Env::t('promo')));
         }
         $uf = new UserFilter($cond);
         $users = $uf->getUsers(new PlLimit(30));
         if ($uf->getTotalCount() > 30) {
             $page->assign('too_many', true);
             $users = array();
         }
     }
     $page->assign('users', $users);
     $page->assign('same_email', $same_email);
 }