X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=modules%2Fxnetgrp.php;h=aacc262b67d65a3fcfcc580373d3bc1775486c53;hb=c3d959ce95385169d0337c5927513f87d9ced493;hp=254819bb6cc417c16876f29efbcac4e3dcc90d07;hpb=fb813fb52d5ab65ca9a5b92b5cb9089523380d79;p=platal.git diff --git a/modules/xnetgrp.php b/modules/xnetgrp.php index 254819b..aacc262 100644 --- a/modules/xnetgrp.php +++ b/modules/xnetgrp.php @@ -66,45 +66,45 @@ class XnetGrpModule extends PLModule if (S::logged()) { if (Env::has('read')) { - XDB::query('DELETE group_r.* - FROM group_announces_read AS r - INNER JOIN group_announces AS a ON a.id = r.announce_id - WHERE peremption < CURRENT_DATE()'); - XDB::query('INSERT INTO group_announces_read - VALUES ({?}, {?})', + XDB::query('DELETE r.* + FROM group_announces_read AS r + INNER JOIN group_announces AS a ON (a.id = r.announce_id) + WHERE expiration < CURRENT_DATE()'); + XDB::query('INSERT INTO group_announces_read + VALUES ({?}, {?})', Env::i('read'), S::i('uid')); pl_redirect(""); } if (Env::has('unread')) { - XDB::query('DELETE FROM group_announces_read - WHERE announce_id={?} AND user_id={?}', + XDB::query('DELETE FROM group_announces_read + WHERE announce_id = {?} AND uid = {?}', Env::i('unread'), S::i('uid')); pl_redirect("#art" . Env::i('unread')); } // XXX: Fix promo_min; promo_max $arts = XDB::iterator("SELECT a.*, FIND_IN_SET('photo', a.flags) AS photo - FROM group_announces AS a - LEFT JOIN group_announces_read AS r ON (r.user_id = {?} AND r.announce_id = a.id) - WHERE asso_id = {?} AND peremption >= CURRENT_DATE() + FROM group_announces AS a + LEFT JOIN group_announces_read AS r ON (r.uid = {?} AND r.announce_id = a.id) + WHERE asso_id = {?} AND expiration >= CURRENT_DATE() AND (promo_min = 0 OR promo_min <= {?}) AND (promo_max = 0 OR promo_max >= {?}) AND r.announce_id IS NULL - ORDER BY a.peremption", + ORDER BY a.expiration", S::i('uid'), $globals->asso('id'), S::i('promo'), S::i('promo')); - $index = XDB::iterator("SELECT a.id, a.titre, r.user_id IS NULL AS nonlu - FROM group_announces AS a - LEFT JOIN group_announces_read AS r ON (a.id = r.announce_id AND r.user_id = {?}) - WHERE asso_id = {?} AND peremption >= CURRENT_DATE() + $index = XDB::iterator("SELECT a.id, a.titre, r.uid IS NULL AS nonlu + FROM group_announces AS a + LEFT JOIN group_announces_read AS r ON (a.id = r.announce_id AND r.uid = {?}) + WHERE asso_id = {?} AND expiration >= CURRENT_DATE() AND (promo_min = 0 OR promo_min <= {?}) AND (promo_max = 0 OR promo_max >= {?}) - ORDER BY a.peremption", + ORDER BY a.expiration", S::i('uid'), $globals->asso('id'), S::i('promo'), S::i('promo')); $page->assign('article_index', $index); } else { - $arts = XDB::iterator("SELECT a.*, FIND_IN_SET('photo', a.flags) AS photo - FROM group_announces AS a - WHERE asso_id = {?} AND peremption >= CURRENT_DATE() - AND FIND_IN_SET('public', a.flags)", + $arts = XDB::iterator("SELECT *, FIND_IN_SET('photo', flags) AS photo + FROM group_announces + WHERE asso_id = {?} AND expiration >= CURRENT_DATE() + AND FIND_IN_SET('public', flags)", $globals->asso('id')); } if (may_update()) { @@ -164,10 +164,20 @@ class XnetGrpModule extends PLModule $site = ""; } if (S::has_perms()) { + $dom = XDB::iterator('SELECT * + FROM group_dom + ORDER BY nom'); + $page->assign('dom', $dom); + $page->assign('super', true); + if (Post::v('mail_domain') && (strstr(Post::v('mail_domain'), '.') === false)) { $page->trigError('Le domaine doit être un FQDN (aucune modification effectuée) !!!'); return; } + if (Post::t('nom') == '' || Post::t('diminutif') == '') { + $page->trigError('Ni le nom ni le diminutif du groupe ne peuvent être vide.'); + return; + } XDB::execute( "UPDATE groups SET nom={?}, diminutif={?}, cat={?}, dom={?}, @@ -218,12 +228,6 @@ class XnetGrpModule extends PLModule pl_redirect('../'.Post::v('diminutif', $globals->asso('diminutif')).'/edit'); } - - if (S::admin()) { - $dom = XDB::iterator('SELECT * FROM group_dom ORDER BY nom'); - $page->assign('dom', $dom); - $page->assign('super', true); - } } function handler_mail(&$page) @@ -282,21 +286,20 @@ class XnetGrpModule extends PLModule { global $globals; - if ($action == 'search') { - http_redirect("https://www.polytechnique.org/search/adv?rechercher=Chercher&groupex={$globals->asso('id')}" - . "&cityid=" . Env::v('cityid') . "&mapid=" . Env::v('mapid')); - } else if ($action == 'geoloc' || $action == 'trombi') { - $view = new UserSet(); + if ($action == 'trombi') { + __autoload('userset'); + if ($action == 'trombi') { + $view = new ProfileSet(new UFC_Group($globals->asso('id'))); + } else { + $view = new UserSet(new UFC_Group($globals->asso('id'))); + } $view->addMod('trombi', 'Trombinoscope'); - // TODO: Reactivate when the new map is completed. - // $view->addMod('geoloc', 'Planisphère', false, array('with_annu' => 'annuaire/search')); $view->apply('annuaire', $page, $action, $subaction); - if ($action == 'geoloc' && $subaction) { - return; - } + $page->changeTpl('xnetgrp/annuaire.tpl'); + return; } - $page->changeTpl('xnetgrp/annuaire.tpl'); + $page->changeTpl('xnetgrp/annuaire.tpl'); $sort = Env::s('order', 'directory_name'); $ofs = Env::i('offset'); if ($ofs < 0) { @@ -312,9 +315,9 @@ class XnetGrpModule extends PLModule } if (Env::b('admin')) { - $uf = $globals->asso()->getAdmins(null, $se); + $uf = $globals->asso()->getAdminsFilter(null, $se); } else { - $uf = $globals->asso()->getMembers(null, $se); + $uf = $globals->asso()->getMembersFilter(null, $se); } $users = $uf->getUsers(new PlLimit(NB_PER_PAGE, $ofs * NB_PER_PAGE)); $count = $uf->getTotalCount(); @@ -340,7 +343,7 @@ class XnetGrpModule extends PLModule { global $globals; $vcard = new VCard($photos == 'photos', 'Membre du groupe ' . $globals->asso('nom')); - $vcard->addUsers($globals->asso()->getMembers()->getUIDs()); + $vcard->addProfiles($globals->asso()->getMembersFilter()->getProfiles()); $vcard->show(); } @@ -350,7 +353,7 @@ class XnetGrpModule extends PLModule if (is_null($filename)) { $filename = $globals->asso('diminutif') . '.csv'; } - $users = $globals->asso()->getMembers(null, new UFO_Name('directory_name'))->getUsers(); + $users = $globals->asso()->getMembersFilter(null, new UFO_Name('directory_name'))->getUsers(); header('Content-Type: text/x-csv; charset=utf-8;'); header('Pragma: '); header('Cache-Control: '); @@ -474,8 +477,8 @@ class XnetGrpModule extends PLModule CONCAT(al.alias,"@polytechnique.org"), m.email) FROM group_members AS m - INNER JOIN #x4dat#.aliases AS al ON (al.type = "a_vie" - AND al.id = m.uid) + INNER JOIN aliases AS al ON (al.type = "a_vie" + AND al.uid = m.uid) WHERE perms="admin" AND m.asso_id = {?}', $globals->asso('id')); $emails = $res->fetchColumn(); @@ -532,7 +535,7 @@ class XnetGrpModule extends PLModule $it = XDB::iterator('SELECT s.uid, a.hruid, s.ts AS date FROM group_member_sub_requests AS s - INNER JOIN #x4dat#.accounts AS a ON(s.uid = a.uid) + 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'); @@ -590,7 +593,7 @@ class XnetGrpModule extends PLModule $not_in_group_ext = array(); foreach ($subscribers as $mail) { - $uf = new UserFilter(new UFC_And(new UFC_Group($globals->asso('id')), + $uf = new UserFilter(new PFC_And(new UFC_Group($globals->asso('id')), new UFC_Email($mail))); if ($uf->getTotalCount() == 0) { if (User::isForeignEmailAddress($mail)) { @@ -675,12 +678,12 @@ class XnetGrpModule extends PLModule } 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())); + $cond = new PFC_And(new PFC_Not(new UFC_Registered())); if (!empty($nom)) { - $cond->addChild(new UFC_Name(UserFilter::LASTNAME, $nom, UFC_Name::CONTAINS)); + $cond->addChild(new UFC_Name(Profile::LASTNAME, $nom, UFC_Name::CONTAINS)); } if (!empty($prenom)) { - $cond->addChild(new UFC_Name(UserFilter::FIRSTNAME, $prenom, UFC_Name::CONTAINS)); + $cond->addChild(new UFC_Name(Profile::FIRSTNAME, $prenom, UFC_Name::CONTAINS)); } if (Env::i('promo')) { $cond->addChild(new UFC_Promo('=', UserFilter::GRADE_ING, Env::i('promo'))); @@ -704,8 +707,9 @@ class XnetGrpModule extends PLModule if ($globals->asso('notif_unsub')) { $mailer = new PlMailer('xnetgrp/unsubscription-notif.mail.tpl'); - foreach ($globals->asso()->getMembers()->getUsers() as $user) { - $mailer->addTo($user); + $admins = $globals->asso()->iterAdmins(); + while ($admin = $admins->next()) { + $mailer->addTo($admin); } $mailer->assign('group', $globals->asso('nom')); $mailer->assign('user', $user); @@ -794,23 +798,22 @@ class XnetGrpModule extends PLModule private function changeLogin(PlPage &$page, PlUser &$user, MMList &$mmlist, $login) { - require_once 'user.func.inc.php'; // Search the uid of the user... - $res = XDB::query("SELECT f.id, f.alias + $res = XDB::query("SELECT f.uid, f.alias FROM aliases AS a - INNER JOIN aliases AS f ON (f.id = a.id AND f.type = 'a_vie') + INNER JOIN aliases AS f ON (f.uid = a.uid AND f.type = 'a_vie') WHERE a.alias = {?}", $login); if ($res->numRows() == 0) { - $x = get_not_registered_user($login); - if (!$x) { - $page->trigError("Le login $login ne correspond à aucun X."); + $accounts = User::getPendingAccounts($login); + if (!$accounts) { + $page->trigError("L'identifiant $login ne correspond à aucun X."); return false; - } else if (count($x) > 1) { - $page->trigError("Le login $login correspond a plusieurs camarades."); + } else if (count($accounts) > 1) { + $page->trigError("L'identifiant $login correspond à plusieurs camarades."); return false; } - $uid = $x[0]['user_id']; + $uid = $accounts[0]['uid']; $sub = false; } else { list($uid, $login) = $res->fetchOneRow(); @@ -1006,7 +1009,9 @@ class XnetGrpModule extends PLModule function handler_photo_announce(&$page, $eid = null) { if ($eid) { - $res = XDB::query("SELECT * FROM group_announces_photo WHERE eid = {?}", $eid); + $res = XDB::query('SELECT * + FROM group_announces_photo + WHERE eid = {?}', $eid); if ($res->numRows()) { $photo = $res->fetchOneAssoc(); pl_cached_dynamic_content_headers("image/" . $photo['attachmime']); @@ -1050,7 +1055,7 @@ class XnetGrpModule extends PLModule $art['prenom'] = S::v('prenom'); $art['promo'] = S::v('promo'); $art['hruid'] = S::user()->login(); - $art['peremption'] = Post::v('peremption'); + $art['expiration'] = Post::v('expiration'); $art['public'] = Post::has('public'); $art['xorg'] = Post::has('xorg'); $art['nl'] = Post::has('nl'); @@ -1083,7 +1088,8 @@ class XnetGrpModule extends PLModule } $art['photo'] = $upload->exists() || Post::i('photo'); if (Post::v('valid') == 'Pas d\'image' && !is_null($aid)) { - XDB::query("DELETE FROM group_announces_photo WHERE eid = {?}", $aid); + XDB::query('DELETE FROM group_announces_photo + WHERE eid = {?}', $aid); $upload->rm(); Post::kill('valid'); $art['photo'] = false; @@ -1112,23 +1118,22 @@ class XnetGrpModule extends PLModule $post = $banana->post($globals->asso('forum'), null, $art['titre'], MiniWiki::wikiToText($fulltext, false, 0, 80)); }*/ - XDB::query("INSERT INTO group_announces - (user_id, asso_id, create_date, titre, texte, contacts, - peremption, promo_min, promo_max, flags, post_id) - VALUES ({?}, {?}, NOW(), {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?})", + XDB::query('INSERT INTO group_announces (uid, asso_id, create_date, titre, texte, contacts, + expiration, promo_min, promo_max, flags, post_id) + VALUES ({?}, {?}, NOW(), {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?})', S::i('uid'), $globals->asso('id'), $art['titre'], $art['texte'], $art['contact_html'], - $art['peremption'], $promo_min, $promo_max, $flags, $post); + $art['expiration'], $promo_min, $promo_max, $flags, $post); $aid = XDB::insertId(); if ($art['photo']) { list($imgx, $imgy, $imgtype) = $upload->imageInfo(); - XDB::execute("INSERT INTO group_announces_photo - SET eid = {?}, attachmime = {?}, x = {?}, y = {?}, attach = {?}", + XDB::execute('INSERT INTO group_announces_photo + SET eid = {?}, attachmime = {?}, x = {?}, y = {?}, attach = {?}', $aid, $imgtype, $imgx, $imgy, $upload->getContents()); } if ($art['xorg']) { require_once('validations.inc.php'); $article = new EvtReq("[{$globals->asso('nom')}] " . $art['titre'], $fulltext, - $art['promo_min'], $art['promo_max'], $art['peremption'], "", S::user(), + $art['promo_min'], $art['promo_max'], $art['expiration'], "", S::user(), $upload); $article->submit(); $page->trigWarning("L'affichage sur la page d'accueil de Polytechnique.org est en attente de validation."); @@ -1143,11 +1148,11 @@ class XnetGrpModule extends PLModule $page->trigWarning("La parution dans la Lettre Mensuelle est en attente de validation."); } } else { - XDB::query("UPDATE group_announces - SET titre={?}, texte={?}, contacts={?}, peremption={?}, - promo_min={?}, promo_max={?}, flags={?} - WHERE id={?} AND asso_id={?}", - $art['titre'], $art['texte'], $art['contacts'], $art['peremption'], + XDB::query('UPDATE group_announces + SET titre = {?}, texte = {?}, contacts = {?}, expiration = {?}, + promo_min = {?}, promo_max = {?}, flags = {?} + WHERE id = {?} AND asso_id = {?}', + $art['titre'], $art['texte'], $art['contacts'], $art['expiration'], $promo_min, $promo_max, $flags, $art['id'], $globals->asso('id')); if ($art['photo'] && $upload->exists()) { @@ -1164,10 +1169,10 @@ class XnetGrpModule extends PLModule } if (empty($art) && !is_null($aid)) { - $res = XDB::query("SELECT a.*, FIND_IN_SET('public', a.flags) AS public, - FIND_IN_SET('photo', a.flags) AS photo - FROM group_announces AS a - WHERE asso_id = {?} AND a.id = {?}", + $res = XDB::query("SELECT *, FIND_IN_SET('public', flags) AS public, + FIND_IN_SET('photo', flags) AS photo + FROM group_announces + WHERE asso_id = {?} AND id = {?}", $globals->asso('id'), $aid); if ($res->numRows()) { $art = $res->fetchOneAssoc(); @@ -1199,14 +1204,14 @@ class XnetGrpModule extends PLModule if (Env::has('del')) { S::assert_xsrf_token(); - XDB::execute("DELETE FROM group_announces - WHERE id = {?} AND asso_id = {?}", + XDB::execute('DELETE FROM group_announces + WHERE id = {?} AND asso_id = {?}', Env::i('del'), $globals->asso('id')); } - $res = XDB::iterator("SELECT a.id, a.titre, a.peremption, a.peremption < CURRENT_DATE() AS perime - FROM group_announces AS a - WHERE a.asso_id = {?} - ORDER BY a.peremption DESC", + $res = XDB::iterator('SELECT id, titre, expiration, expiration < CURRENT_DATE() AS perime + FROM group_announces + WHERE asso_id = {?} + ORDER BY expiration DESC', $globals->asso('id')); $page->assign('articles', $res); }