示例#1
0
 public function __construct()
 {
     global $globals;
     parent::__construct();
     $this->register_function('list_all_my_groups', 'list_all_my_groups');
     $this->register_modifier('cat_pp', 'cat_pp');
     $this->assign('it_is_xnet', true);
     global $globals;
     $this->assign('is_logged', S::logged());
     if ($globals->asso('id')) {
         $this->assign('asso', $globals->asso());
         $this->setType($globals->asso('cat'));
         $this->assign('is_admin', may_update());
         $this->assign('is_member', is_member());
     }
     if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false) {
         $this->addJsLink('json2.js');
     }
     $this->addJsLink('jquery.xorg.js');
     $this->addJsLink('overlib.js');
     $this->addJsLink('core.js');
     $this->addJsLink('xorg.js');
     if ($globals->core->sentry_js_dsn) {
         $this->addJsLink('raven.min.js');
     }
     $this->setTitle('Les associations polytechniciennes');
 }
示例#2
0
 public function startAvailableAuth()
 {
     if (!S::logged() && Get::has('auth')) {
         if (!$this->start(AUTH_PASSWD)) {
             return false;
         }
     }
     global $globals;
     if (!S::logged() && $globals->xnet->auth_baseurl) {
         // prevent connection to be linked to disconnection
         if (($i = strpos($_SERVER['REQUEST_URI'], 'exit')) !== false) {
             $returl = "http://{$_SERVER['SERVER_NAME']}" . substr($_SERVER['REQUEST_URI'], 0, $i);
         } else {
             $returl = "http://{$_SERVER['SERVER_NAME']}{$_SERVER['REQUEST_URI']}";
         }
         $url = $globals->xnet->auth_baseurl;
         $url .= "?session=" . session_id();
         $url .= "&challenge=" . S::v('challenge');
         $url .= "&pass="******"&url=" . urlencode($returl);
         S::set('loginX', $url);
     }
     if (S::logged() && $globals->asso()) {
         $perms = S::v('perms');
         $perms->rmFlag('groupadmin');
         $perms->rmFlag('groupmember');
         $perms->rmFlag('groupannu');
         if (may_update()) {
             $perms->addFlag('groupadmin');
             $perms->addFlag('groupmember');
             $perms->addFlag('groupannu');
         }
         if (is_member()) {
             $perms->addFlag('groupmember');
             if ($globals->asso('pub') != 'private') {
                 $perms->addFlag('groupannu');
             }
         } else {
             if ($globals->asso('pub') == 'public') {
                 $perms->addFlag('groupannu');
             }
         }
         if ($globals->asso('cat') == 'Promotions') {
             $perms->addFlag('groupannu');
         }
         S::set('perms', $perms);
     }
     return true;
 }
示例#3
0
function get_event_participants(&$evt, $item_id, array $tri = array(), $limit = null, $offset = 0)
{
    global $globals;
    $eid = $evt['eid'];
    $money = $evt['money'] && function_exists('may_update') && may_update();
    $pay_id = $evt['paiement_id'];
    $append = $item_id ? XDB::format(' AND ep.item_id = {?}', $item_id) : '';
    $query = XDB::fetchAllAssoc('uid', 'SELECT  ep.uid, SUM(ep.paid) AS paid, SUM(ep.nb) AS nb,
                                                FIND_IN_SET(\'notify_payment\', ep.flags) AS notify_payment
                                          FROM  group_event_participants AS ep
                                         WHERE  ep.eid = {?} AND nb > 0 ' . $append . '
                                      GROUP BY  ep.uid', $eid);
    $uf = new UserFilter(new PFC_True(), $tri);
    $users = User::getBulkUsersWithUIDs($uf->filter(array_keys($query), new PlLimit($limit, $offset)));
    $tab = array();
    foreach ($users as $user) {
        $uid = $user->id();
        $tab[$uid] = $query[$uid];
        $tab[$uid]['user'] = $user;
    }
    if ($item_id) {
        return $tab;
    }
    $evt['adminpaid'] = 0;
    $evt['telepaid'] = 0;
    $evt['topay'] = 0;
    $evt['paid'] = 0;
    foreach ($tab as $uid => &$u) {
        $u['adminpaid'] = (double) $u['paid'];
        $u['montant'] = 0;
        if ($money && $pay_id) {
            $montant = XDB::fetchOneCell('SELECT  SUM(amount)
                                            FROM  payment_transactions AS t
                                           WHERE  status = "confirmed" AND ref = {?} AND uid = {?}', $pay_id, $uid);
            $u['paid'] += $montant;
        }
        $u['telepayment'] = $u['paid'] - $u['adminpaid'];
        $res_ = XDB::iterator('SELECT  ep.nb, ep.item_id, ei.montant
                                 FROM  group_event_participants AS ep
                           INNER JOIN  group_event_items AS ei ON (ei.eid = ep.eid AND ei.item_id = ep.item_id)
                                WHERE  ep.eid = {?} AND ep.uid = {?}', $eid, $uid);
        while ($i = $res_->next()) {
            $u[$i['item_id']] = $i['nb'];
            $u['montant'] += $i['montant'] * $i['nb'];
        }
        $evt['telepaid'] += $u['telepayment'];
        $evt['adminpaid'] += $u['adminpaid'];
        $evt['paid'] += $u['paid'];
        $evt['topay'] += $u['montant'];
    }
    return $tab;
}
示例#4
0
文件: xnetgrp.php 项目: Ekleog/platal
 function unsubscribe(PlUser $user, $remember = false)
 {
     global $globals;
     Group::unsubscribe($globals->asso('id'), $user->id(), $remember);
     if ($globals->asso('notif_unsub')) {
         $mailer = new PlMailer('xnetgrp/unsubscription-notif.mail.tpl');
         $admins = $globals->asso()->iterToNotify();
         while ($admin = $admins->next()) {
             $mailer->addTo($admin);
         }
         $mailer->assign('group', $globals->asso('nom'));
         $mailer->assign('user', $user);
         $mailer->assign('selfdone', $user->id() == S::i('uid'));
         $mailer->send();
     }
     $nl = Newsletter::forGroup($globals->asso('shortname'));
     if (!is_null($nl)) {
         $nl->unsubscribe(null, S::i('uid'));
     }
     $domain = $globals->asso('mail_domain');
     if (!$domain) {
         return true;
     }
     $mmlist = new MMList(S::user(), $domain);
     $listes = $mmlist->get_lists($user->forlifeEmail());
     $may_update = may_update();
     $warning = false;
     if (is_array($listes)) {
         foreach ($listes as $liste) {
             if ($liste['sub'] == 2) {
                 if ($may_update) {
                     $mmlist->mass_unsubscribe($liste['list'], array($user->forlifeEmail()));
                 } else {
                     $mmlist->unsubscribe($liste['list']);
                 }
             } elseif ($liste['sub']) {
                 Platal::page()->trigWarning($user->fullName() . " a une" . " demande d'inscription en cours sur la" . " liste {$liste['list']}@ !");
                 $warning = true;
             }
         }
     }
     XDB::execute('DELETE  v
                     FROM  email_virtual         AS v
               INNER JOIN  email_virtual_domains AS d ON (v.domain = d.id)
                    WHERE  v.redirect = {?} AND d.name = {?}', $user->forlifeEmail(), $domain);
     return !$warning;
 }
示例#5
0
文件: payment.php 项目: Ekleog/platal
 function handler_xnet_payment($page, $pid = null)
 {
     global $globals;
     $perms = S::v('perms');
     if (is_null($pid)) {
         if (!(S::identified() && $perms->hasFlag('groupadmin'))) {
             return PL_FORBIDDEN;
         }
     } else {
         if (!(S::identified() && $perms->hasFlag('groupmember'))) {
             $res = XDB::query("SELECT  1\n                                     FROM  group_events AS e\n                               INNER JOIN  group_event_participants AS ep ON (ep.eid = e.eid AND ep.uid = {?})\n                                    WHERE  e.paiement_id = {?} AND e.asso_id = {?}", S::i('uid'), $pid, $globals->asso('id'));
             $public = XDB::query("SELECT  1\n                                        FROM  payments     AS p\n                                  INNER JOIN  group_events AS g ON (g.paiement_id = p.id)\n                                       WHERE  g.asso_id = {?} AND p.id = {?} AND FIND_IN_SET('public', p.flags)", $globals->asso('id'), $pid);
             if ($res->numRows() == 0 && $public->numRows() == 0) {
                 return PL_FORBIDDEN;
             }
         }
     }
     if (!is_null($pid)) {
         return $this->handler_payment($page, $pid);
     }
     $page->changeTpl('payment/xnet.tpl');
     $res = XDB::query("SELECT  id, text, url\n                   FROM  payments\n                  WHERE  asso_id = {?} AND NOT FIND_IN_SET('old', flags)\n               ORDER BY  id DESC", $globals->asso('id'));
     $tit = $res->fetchAllAssoc();
     $page->assign('titles', $tit);
     $trans = array();
     $event = array();
     if (may_update()) {
         static $orders = array('ts_confirmed' => 'p', 'directory_name' => 'a', 'promo' => 'pd', 'comment' => 'p', 'amount' => 'p');
         if (Get::has('order_id') && Get::has('order') && array_key_exists(Get::v('order'), $orders)) {
             $order_id = Get::i('order_id');
             $order = Get::v('order');
             $ordering = ' ORDER BY ' . $orders[$order] . '.' . $order;
             if (Get::has('order_inv') && Get::i('order_inv') == 1) {
                 $ordering .= ' DESC';
                 $page->assign('order_inv', 0);
             } else {
                 $page->assign('order_inv', 1);
             }
             $page->assign('order_id', $order_id);
             $page->assign('order', $order);
             $page->assign('anchor', 'legend_' . $order_id);
         } else {
             $order_id = false;
             $ordering = '';
             $page->assign('order', false);
         }
     } else {
         $ordering = '';
         $page->assign('order', false);
     }
     foreach ($tit as $foo) {
         $pid = $foo['id'];
         if (may_update()) {
             $res = XDB::query('SELECT  p.uid, IF(p.ts_confirmed = \'0000-00-00\', 0, p.ts_confirmed) AS date, p.comment, p.amount
                                  FROM  payment_transactions AS p
                            INNER JOIN  accounts             AS a  ON (a.uid = p.uid)
                             LEFT JOIN  account_profiles     AS ap ON (ap.uid = p.uid AND FIND_IN_SET(\'owner\', ap.perms))
                             LEFT JOIN  profile_display      AS pd ON (ap.pid = pd.pid)
                                 WHERE  p.ref = {?}' . ($order_id == $pid ? $ordering : ''), $pid);
             $trans[$pid] = User::getBulkUsersWithUIDs($res->fetchAllAssoc(), 'uid', 'user');
             $sum = 0;
             foreach ($trans[$pid] as $i => $t) {
                 $sum += $t['amount'];
                 $trans[$pid][$i]['amount'] = $t['amount'];
             }
             $trans[$pid][] = array('limit' => true, 'amount' => $sum);
         }
         $res = XDB::iterRow("SELECT  e.eid, e.short_name, e.intitule, ep.nb, ei.montant, ep.paid\n                                   FROM  group_events             AS e\n                              LEFT JOIN  group_event_participants AS ep ON (ep.eid = e.eid AND ep.uid = {?})\n                             INNER JOIN  group_event_items        AS ei ON (ep.eid = ei.eid AND ep.item_id = ei.item_id)\n                                  WHERE  e.paiement_id = {?}", S::v('uid'), $pid);
         $event[$pid] = array();
         $event[$pid]['paid'] = 0;
         if ($res->total()) {
             $event[$pid]['topay'] = 0;
             while (list($eid, $shortname, $title, $nb, $montant, $paid) = $res->next()) {
                 $event[$pid]['topay'] += $nb * $montant;
                 $event[$pid]['eid'] = $eid;
                 $event[$pid]['shortname'] = $shortname;
                 $event[$pid]['title'] = $title;
                 $event[$pid]['ins'] = !is_null($nb);
                 $event[$pid]['paid'] = $paid;
             }
         }
         $res = XDB::query('SELECT  SUM(amount) AS sum_amount
                              FROM  payment_transactions
                             WHERE  ref = {?} AND uid = {?}', $pid, S::v('uid'));
         $event[$pid]['paid'] = $res->fetchOneCell();
     }
     $page->register_modifier('decode_comment', 'decode_comment');
     $page->assign('trans', $trans);
     $page->assign('event', $event);
 }
示例#6
0
 function handler_admin($page, $eid = null, $item_id = null)
 {
     global $globals;
     $this->load('xnetevents.inc.php');
     $evt = get_event_detail($eid, $item_id);
     if (!$evt) {
         return PL_NOT_FOUND;
     }
     $page->changeTpl('xnetevents/admin.tpl');
     if (!$evt['show_participants'] && !may_update()) {
         return PL_FORBIDDEN;
     }
     if (may_update() && Post::v('adm')) {
         S::assert_xsrf_token();
         $member = User::getSilent(Post::v('mail'));
         if (!$member) {
             $page->trigError("Membre introuvable");
         }
         // change the price paid by a participant
         if (Env::v('adm') == 'prix' && $member) {
             $amount = strtr(Env::v('montant'), ',', '.');
             XDB::execute("UPDATE group_event_participants\n                                 SET paid = paid + {?}\n                               WHERE uid = {?} AND eid = {?} AND nb > 0\n                            ORDER BY item_id ASC\n                               LIMIT 1", $amount, $member->uid, $evt['eid']);
             subscribe_lists_event($member->uid, $evt['short_name'], 1, $amount);
         }
         // change the number of personns coming with a participant
         if (Env::v('adm') == 'nbs' && $member) {
             $res = XDB::query("SELECT SUM(paid)\n                                     FROM group_event_participants\n                                    WHERE uid = {?} AND eid = {?}", $member->uid, $evt['eid']);
             $paid = $res->fetchOneCell();
             // Ensure we have an integer
             if ($paid == null) {
                 $paid = 0;
             }
             $nbs = Post::v('nb', array());
             $paid_inserted = false;
             foreach ($nbs as $id => $nb) {
                 $nb = max(intval($nb), 0);
                 if (!$paid_inserted && $nb > 0) {
                     $item_paid = $paid;
                     $paid_inserted = true;
                 } else {
                     $item_paid = 0;
                 }
                 XDB::execute('INSERT INTO  group_event_participants (eid, uid, item_id, nb, flags, paid)
                                    VALUES  ({?}, {?}, {?}, {?}, {?}, {?})
                   ON DUPLICATE KEY UPDATE  nb = VALUES(nb), flags = VALUES(flags), paid = VALUES(paid)', $evt['eid'], $member->uid, $id, $nb, '', $item_paid);
             }
             $res = XDB::query('SELECT  COUNT(uid) AS cnt, SUM(nb) AS nb
                                  FROM  group_event_participants
                                 WHERE  uid = {?} AND eid = {?}
                              GROUP BY  uid', $member->uid, $evt['eid']);
             $u = $res->fetchOneAssoc();
             if ($paid == 0 && Post::v('cancel')) {
                 XDB::execute("DELETE FROM group_event_participants\n                                        WHERE uid = {?} AND eid = {?}", $member->uid, $evt['eid']);
                 $u = 0;
                 subscribe_lists_event($member->uid, $evt['short_name'], -1, $paid);
             } else {
                 $u = $u['cnt'] ? $u['nb'] : null;
                 subscribe_lists_event($member->uid, $evt['short_name'], $u > 0 ? 1 : 0, $paid);
             }
         }
         $evt = get_event_detail($eid, $item_id);
     }
     $page->assign_by_ref('evt', $evt);
     $page->assign('tout', is_null($item_id));
     if (count($evt['moments'])) {
         $page->assign('moments', $evt['moments']);
     }
     if ($evt['paiement_id']) {
         $infos = User::getBulkUsersWithUIDs(XDB::fetchAllAssoc('SELECT  t.uid, t.amount
                                               FROM  payment_transactions AS t
                                          LEFT JOIN  group_event_participants AS ep ON(ep.uid = t.uid AND ep.eid = {?})
                                              WHERE  t.status = "confirmed" AND t.ref = {?} AND ep.uid IS NULL', $evt['eid'], $evt['paiement_id']), 'uid', 'user');
         $page->assign('oublis', count($infos));
         $page->assign('oubliinscription', $infos);
     }
     $absents = User::getBulkUsersFromDB('SELECT  p.uid
                                            FROM  group_event_participants AS p
                                       LEFT JOIN  group_event_participants AS p2 ON (p2.uid = p.uid
                                                                                            AND p2.eid = p.eid
                                                                                            AND p2.nb != 0)
                                           WHERE  p.eid = {?} AND p2.eid IS NULL
                                        GROUP BY  p.uid', $evt['eid']);
     $ofs = Env::i('offset');
     $part = get_event_participants($evt, $item_id, UserFilter::sortByName(), NB_PER_PAGE, $ofs * NB_PER_PAGE);
     $nbp = ceil($evt['user_count'] / NB_PER_PAGE);
     if ($nbp > 1) {
         $links = array();
         if ($ofs) {
             $links['précédent'] = $ofs - 1;
         }
         for ($i = 1; $i <= $nbp; $i++) {
             $links[(string) $i] = $i - 1;
         }
         if ($ofs < $nbp - 1) {
             $links['suivant'] = $ofs + 1;
         }
         $page->assign('links', $links);
     }
     $page->assign('absents', $absents);
     $page->assign('participants', $part);
 }
示例#7
0
 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é&nbsp;!');
     }
     $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&nbsp;: l'affichage des listes de diffusion ne tient pas compte de l'option « Voir le site comme&hellip; ».");
     }
     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'));
     }
 }