X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=modules%2Fxnetgrp.php;h=938a6a69f03f525887fc9d0bcd5cdc0bed71dfe8;hb=0001ba7a34dc3b535407cb1b961781c3c69c0ccd;hp=e72013c259940ade3f85a5083f63545f9e51a667;hpb=f6d7a2df40acc6892fa79bbf35939276b8810728;p=platal.git diff --git a/modules/xnetgrp.php b/modules/xnetgrp.php index e72013c..938a6a6 100644 --- a/modules/xnetgrp.php +++ b/modules/xnetgrp.php @@ -66,7 +66,6 @@ class XnetGrpModule extends PLModule function handler_index(&$page, $arg = null) { global $globals, $platal; - if (!is_null($arg)) { return PL_NOT_FOUND; } @@ -138,13 +137,9 @@ class XnetGrpModule extends PLModule { global $globals; - $res = XDB::query("SELECT logo, logo_mime - FROM groupex.asso WHERE id = {?}", - $globals->asso('id')); - list($logo, $logo_mime) = $res->fetchOneRow(); - + $logo = $globals->asso('logo'); if (!empty($logo)) { - header("Content-type: $mime"); + header('Content-type: ' . $globals->asso('logo_mime')); header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); header('Last-Modified:' . gmdate('D, d M Y H:i:s') . ' GMT'); header('Cache-Control: no-cache, must-revalidate'); @@ -327,20 +322,29 @@ class XnetGrpModule extends PLModule $page->changeTpl('xnetgrp/annuaire.tpl'); $sort = Env::s('order', 'directory_name'); + $ofs = Env::i('offset'); + if ($ofs < 0) { + $ofs = 0; + } + + $sdesc = $sort{0} == '-'; + $sf = $sdesc ? substr($sort, 1) : $sort; + if ($sf == 'promo') { + $se = new UFO_Promo(null, $sdesc); + } else { + $se = new UFO_Name($sf, null, null, $sdesc); + } if (Env::b('admin')) { - $uids = XDB::fetchColumn('SELECT uid - FROM groupex.membres - WHERE asso_id = {?} AND perms = \'admin\'', - $globals->asso('id')); + $uf = $globals->asso()->getAdmins(null, $se); } else { - $uids = XDB::fetchColumn('SELECT uid - FROM groupex.membres - WHERE asso_id = {?}', $globals->asso('id')); + $uf = $globals->asso()->getMembers(null, $se); } - $users = User::getBuildUsersWithUIDs($uids, $sort, - NB_PER_PAGE, $ofs * NB_PER_PAGE); - $page->assign('pages', (count($uids) + NB_PER_PAGE - 1) / NB_PER_PAGE); + $users = $uf->getUsers(NB_PER_PAGE, $ofs * NB_PER_PAGE); + $count = $uf->getTotalCount(); + + $page->assign('pages', floor(($count + NB_PER_PAGE - 1) / NB_PER_PAGE)); + $page->assign('current', $ofs); $page->assign('order', $sort); $page->assign('users', $users); $page->assign('only_admin', Env::b('admin')); @@ -359,11 +363,8 @@ class XnetGrpModule extends PLModule function handler_vcard(&$page, $photos = null) { global $globals; - $res = XDB::query('SELECT uid - FROM groupex.membres - WHERE asso_id = {?}', $globals->asso('id')); $vcard = new VCard($photos == 'photos', 'Membre du groupe ' . $globals->asso('nom')); - $vcard->addUsers($res->fetchColumn()); + $vcard->addUsers($globals->asso()->getMembers()->getUIDs()); $vcard->show(); } @@ -373,11 +374,7 @@ class XnetGrpModule extends PLModule if (is_null($filename)) { $filename = $globals->asso('diminutif') . '.csv'; } - $id = XDB::fetchColumn("SELECT uid - FROM groupex.membres - WHERE asso_id = {?}", - $globals->asso('id')); - $users = User::getBuildUsersWithUIDs($id, 'full_name'); + $users = $globals->asso()->getMembers(null, new UFO_Name('directory_name'))->getUsers(); header('Content-Type: text/x-csv; charset=utf-8;'); header('Pragma: '); header('Cache-Control: '); @@ -555,14 +552,11 @@ class XnetGrpModule extends PLModule } } - $it = XDB::iterator("SELECT IF(u.nom_usage != '', u.nom_usage, u.nom) AS nom, - u.prenom, u.promo, u.hruid, s.ts AS date + $it = XDB::iterator('SELECT s.uid, a.hruid, s.ts AS date FROM groupex.membres_sub_requests AS s - INNER JOIN auth_user_md5 AS u ON (s.uid = u.user_id) - WHERE asso_id = {?} - ORDER BY nom, prenom", - $globals->asso('id')); - + INNER JOIN accounts AS a ON(s.uid = a.uid) + WHERE s.asso_id = {?} + ORDER BY s.ts', $globals->asso('id')); $page->changeTpl('xnetgrp/subscribe-valid.tpl'); $page->assign('valid', $it); } @@ -591,7 +585,6 @@ class XnetGrpModule extends PLModule break; } } -// var_dump($_SESSION); http_redirect($_SERVER['HTTP_REFERER']); } @@ -601,8 +594,8 @@ class XnetGrpModule extends PLModule $this->load('mail.inc.php'); $page->changeTpl('xnetgrp/annuaire-admin.tpl'); - $mmlist = new MMList(S::v('uid'), S::v('password'), - $globals->asso('mail_domain')); + $user = S::user(); + $mmlist = new MMList($user, $globals->asso('mail_domain')); $lists = $mmlist->get_lists(); if (!$lists) $lists = array(); $listes = array_map(create_function('$arr', 'return $arr["list"];'), $lists); @@ -619,16 +612,10 @@ class XnetGrpModule extends PLModule $not_in_group_ext = array(); foreach ($subscribers as $mail) { - $res = XDB::query( - 'SELECT COUNT(*) - FROM groupex.membres AS m - LEFT JOIN auth_user_md5 AS u ON (m.uid=u.user_id AND m.uid<50000) - LEFT JOIN aliases AS a ON (a.id=u.user_id and a.type="a_vie") - WHERE asso_id = {?} AND - (m.email = {?} OR CONCAT(a.alias, "@polytechnique.org") = {?})', - $globals->asso('id'), $mail, $mail); - if ($res->fetchOneCell() == 0) { - if (strstr($mail, '@polytechnique.org') === false) { + $uf = new UserFilter(new UFC_And(new UFC_Group($globals->asso('id')), + new UFC_Email($mail))); + if ($uf->getTotalCount() == 0) { + if (User::isForeignEmailAddress($mail)) { $not_in_group_ext[] = $mail; } else { $not_in_group_x[] = $mail; @@ -664,12 +651,10 @@ class XnetGrpModule extends PLModule } } else { if (isvalid_email($email)) { - if (Env::v('x') && Env::has('userid') && Env::i('userid')) { + if (Env::v('x') && Env::i('userid')) { $uid = Env::i('userid'); - $res = XDB::query("SELECT * - FROM auth_user_md5 - WHERE user_id = {?} AND perms = 'pending'", $uid); - if ($res->numRows() == 1) { + $user = User::getWithUID($uid); + if ($user && $user->state == 'pending') { if (Env::v('market')) { $market = Marketing::get($uid, $email); if (!$market) { @@ -702,35 +687,34 @@ class XnetGrpModule extends PLModule function handler_admin_member_new_ajax(&$page) { header('Content-Type: text/html; charset="UTF-8"'); - $page->changeTpl('xnetgrp/membres-new-search.tpl', NO_SKIN); - $res = null; + $page->changeTpl('xnetgrp/membres-new-search.tpl', NO_SKIN); + $users = array(); if (Env::has('login')) { - require_once 'user.func.inc.php'; - $res = get_not_registered_user(Env::v('login'), true); + $user = User::getSilent(Env::t('login')); + if ($user && $user->state != 'pending') { + $users = array($user); + } } - if (is_null($res)) { - list($nom, $prenom) = str_replace(array('-', ' ', "'"), '%', array(Env::v('nom'), Env::v('prenom'))); - $where = "perms = 'pending'"; + if (empty($users)) { + list($nom, $prenom) = str_replace(array('-', ' ', "'"), '%', array(Env::t('nom'), Env::t('prenom'))); + $cond = new UFC_And(new UFC_Not(new UFC_Registered())); if (!empty($nom)) { - $where .= " AND nom LIKE '%$nom%'"; + $cond->addChild(new UFC_Name(UserFilter::LASTNAME, $nom, UFC_Name::CONTAINS)); } if (!empty($prenom)) { - $where .= " AND prenom LIKE '%$prenom%'"; + $cond->addChild(new UFC_Name(UserFilter::FIRSTNAME, $prenom, UFC_Name::CONTAINS)); } - if (preg_match('/^[0-9]{4}$/', Env::v('promo'))) { - $where .= " AND promo = " . Env::i('promo'); - } elseif (preg_match('/^[0-9]{2}$/', Env::v('promo'))) { - $where .= " AND MOD(promo, 100) = " . Env::i('promo'); - } elseif (Env::has('promo')) { - return; + if (Env::i('promo')) { + $cond->addChild(new UFC_Promo('=', UserFilter::GRADE_ING, Env::i('promo'))); + } + $uf = new UserFilter($cond); + $users = $uf->getUsers(30); + if ($uf->getTotalCount() > 30) { + $page->assign('too_many', true); + $users = array(); } - $res = XDB::iterator("SELECT user_id, nom, prenom, promo - FROM auth_user_md5 - WHERE $where"); - } - if ($res && $res->total() < 30) { - $page->assign("choix", $res); } + $page->assign('users', $users); } function unsubscribe(PlUser &$user) @@ -742,12 +726,7 @@ class XnetGrpModule extends PLModule if ($globals->asso('notif_unsub')) { $mailer = new PlMailer('xnetgrp/unsubscription-notif.mail.tpl'); - $uids = XDB::fetchColumn('SELECT uid - FROM groupex.membres - WHERE perms = \'admin\' AND asso_id = {?}', - $globals->asso('id')); - $users = User::getBuildUsersWithUIDs($uids); - foreach ($users as $user) { + foreach ($globals->asso()->getMembers()->getUsers() as $user) { $mailer->addTo($user); } $mailer->assign('group', $globals->asso('nom')); @@ -1207,11 +1186,9 @@ class XnetGrpModule extends PLModule } if (empty($art) && !is_null($aid)) { - $res = XDB::query("SELECT a.*, u.nom, u.prenom, u.promo, u.hruid, - FIND_IN_SET('public', a.flags) AS public, + $res = XDB::query("SELECT a.*, FIND_IN_SET('public', a.flags) AS public, FIND_IN_SET('photo', a.flags) AS photo FROM groupex.announces AS a - INNER JOIN auth_user_md5 AS u USING(user_id) WHERE asso_id = {?} AND a.id = {?}", $globals->asso('id'), $aid); if ($res->numRows()) {