X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=modules%2Fxnetgrp.php;h=2d6d56d9720a9ea7e4b30141864c7e08641ffc6c;hb=b71f7275d0abe31614da74e05524ac08033bbe18;hp=918101ef77289087e9a56b6865cd9dadcdedd95c;hpb=8fc4efa394721853bca6ee0e4f2028f33ed0867d;p=platal.git diff --git a/modules/xnetgrp.php b/modules/xnetgrp.php index 918101e..2d6d56d 100644 --- a/modules/xnetgrp.php +++ b/modules/xnetgrp.php @@ -46,7 +46,7 @@ function get_infos($email) WHERE user_id = {?}", $user['uid']); $user = array_merge($user, $res->fetchOneAssoc()); } - return $user; + return $user; } elseif ($dom == 'polytechnique.org' || $dom == 'm4x.org') { $res = XDB::query( "SELECT user_id AS uid, u.promo, @@ -54,12 +54,12 @@ function get_infos($email) u.prenom, b.alias, CONCAT(b.alias, '@m4x.org') AS email, CONCAT(b.alias, '@polytechnique.org') AS email2, - m.perms='admin' AS perms, m.origine, + m.perms = 'admin' AS perms, m.origine, FIND_IN_SET('femme', u.flags) AS sexe FROM auth_user_md5 AS u INNER JOIN aliases AS a ON ( u.user_id = a.id AND a.type != 'homonyme' ) INNER JOIN aliases AS b ON ( u.user_id = b.id AND b.type = 'a_vie' ) - INNER JOIN groupex.membres AS m ON ( m.uid = u.user_id AND asso_id={?}) + LEFT JOIN groupex.membres AS m ON ( m.uid = u.user_id AND asso_id={?}) WHERE a.alias = {?} AND u.user_id < 50000", $globals->asso('id'), $mbox); return $res->fetchOneAssoc(); } @@ -122,7 +122,7 @@ class XnetGrpModule extends PLModule XDB::query('DELETE r.* FROM groupex.announces_read AS r INNER JOIN groupex.announces AS a ON a.id = r.announce_id - WHERE peremption < CURRENT_DATE()'); + WHERE peremption < CURRENT_DATE()'); XDB::query('INSERT INTO groupex.announces_read VALUES ({?}, {?})', Env::i('read'), S::i('uid')); @@ -170,11 +170,8 @@ class XnetGrpModule extends PLModule $page->setRssLink("Polytechnique.net :: {$globals->asso("nom")} :: News", 'rss/'.S::v('forlife') .'/'.S::v('core_rss_hash').'/rss.xml'); } - - $page->register_modifier('wiki_to_html', array('MiniWiki','WikiToHTML')); - $page->assign('articles', $arts); - $page->assign('asso', $globals->asso()); + $page->assign('articles', $arts); } function handler_logo(&$page) @@ -233,14 +230,15 @@ class XnetGrpModule extends PLModule SET nom={?}, diminutif={?}, cat={?}, dom={?}, descr={?}, site={?}, mail={?}, resp={?}, forum={?}, mail_domain={?}, ax={?}, pub={?}, - sub_url={?}, inscriptible={?}, unsub_url={?} + sub_url={?}, inscriptible={?}, unsub_url={?}, + flags='wiki_desc' WHERE id={?}", Post::v('nom'), Post::v('diminutif'), Post::v('cat'), Post::i('dom'), Post::v('descr'), Post::v('site'), Post::v('mail'), Post::v('resp'), Post::v('forum'), Post::v('mail_domain'), - Post::has('ax'), Post::has('pub')?'private':'public', + Post::has('ax'), Post::v('pub'), Post::v('sub_url'), Post::v('inscriptible'), Post::v('unsub_url'),$globals->asso('id')); if (Post::v('mail_domain')) { @@ -252,12 +250,12 @@ class XnetGrpModule extends PLModule "UPDATE groupex.asso SET descr={?}, site={?}, mail={?}, resp={?}, forum={?}, ax={?}, pub= {?}, sub_url={?}, - unsub_url={?} + unsub_url={?},flags='wiki_desc' WHERE id={?}", Post::v('descr'), Post::v('site'), Post::v('mail'), Post::v('resp'), Post::v('forum'), Post::has('ax'), - Post::has('pub')?'private':'public', + Post::has('pub'), Post::v('sub_url'), Post::v('unsub_url'), $globals->asso('id')); } @@ -266,9 +264,9 @@ class XnetGrpModule extends PLModule $logo = file_get_contents($_FILES['logo']['tmp_name']); $mime = $_FILES['logo']['type']; XDB::execute('UPDATE groupex.asso - SET logo={?}, logo_mime={?} - WHERE id={?}', $logo, $mime, - $globals->asso('id')); + SET logo={?}, logo_mime={?} + WHERE id={?}', $logo, $mime, + $globals->asso('id')); } pl_redirect('../'.Post::v('diminutif', $globals->asso('diminutif')).'/edit'); @@ -279,6 +277,11 @@ class XnetGrpModule extends PLModule $page->assign('dom', $dom); $page->assign('super', true); } + if (!$globals->asso('wiki_desc') && $globals->asso('descr')) { + $page->trig("Attention, le format de la description a changé et utilise désormais la syntaxe wiki " + . "intégrée au site. Il te faudra probablement adapter le formatage du texte actuel pour " + . "qu'il s'affiche correctement avec cette nouvelle syntaxe."); + } } function handler_mail(&$page) @@ -328,10 +331,13 @@ class XnetGrpModule extends PLModule { global $globals; - if ($action == 'geoloc' || $action == 'trombi') { + 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(); $view->addMod('trombi', 'Trombinoscope'); - $view->addMod('geoloc', 'Planisphère'); + $view->addMod('geoloc', 'Planisphère', false, array('with_annu' => 'annuaire/search')); $view->apply('annuaire', $page, $action, $subaction); if ($action == 'geoloc' && $subaction) { return; @@ -355,7 +361,7 @@ class XnetGrpModule extends PLModule 1, 1)) as letter, COUNT(*) FROM groupex.membres AS m LEFT JOIN auth_user_md5 AS u ON ( u.user_id = m.uid) - WHERE asso_id = {?} and (u.perms != \'pending\' OR u.perms IS NULL) + WHERE asso_id = {?} and (u.perms != \'pending\' OR m.email IS NOT NULL) GROUP BY letter ORDER BY letter', $globals->asso('id')); } else { @@ -430,7 +436,7 @@ class XnetGrpModule extends PLModule LEFT JOIN emails AS e ON ( e.flags = 'active' AND e.uid = m.uid) WHERE m.asso_id = {?} $ini AND (m.origine != 'X' OR u.perms != 'pending' OR m.email IS NOT NULL) - GROUP BY m.uid + GROUP BY m.uid ORDER BY $tri LIMIT {?},{?}", $globals->asso('id'), $ofs*NB_PER_PAGE, NB_PER_PAGE); $page->assign('ann', $ann); @@ -446,7 +452,7 @@ class XnetGrpModule extends PLModule { pl_redirect('annuaire/geoloc'); } - + function handler_vcard(&$page, $photos = null) { global $globals; @@ -469,19 +475,17 @@ class XnetGrpModule extends PLModule if (!is_null($u) && may_update()) { $page->assign('u', $u); - $res = XDB::query("SELECT nom, prenom, promo, user_id - FROM auth_user_md5 AS u - INNER JOIN aliases AS al ON (al.id = u.user_id - AND al.type != 'liste') - WHERE al.alias = {?}", $u); + $res = XDB::query("SELECT u.nom, u.prenom, u.promo, u.user_id, FIND_IN_SET('femme', u.flags) + FROM auth_user_md5 AS u + INNER JOIN aliases AS al ON (al.id = u.user_id AND al.type != 'liste') + WHERE al.alias = {?}", $u); - if (list($nom, $prenom, $promo, $uid) = $res->fetchOneRow()) { + if (list($nom, $prenom, $promo, $uid, $sexe) = $res->fetchOneRow()) { $res = XDB::query("SELECT COUNT(*) - FROM groupex.membres AS m - INNER JOIN aliases AS a ON (m.uid = a.id - AND a.type != 'homonyme') - WHERE a.alias = {?} AND m.asso_id = {?}", - $u, $globals->asso('id')); + FROM groupex.membres AS m + INNER JOIN aliases AS a ON (m.uid = a.id AND a.type != 'homonyme') + WHERE a.alias = {?} AND m.asso_id = {?}", + $u, $globals->asso('id')); $n = $res->fetchOneCell(); if ($n) { $page->kill("$prenom $nom est déjà membre du groupe !"); @@ -489,15 +493,15 @@ class XnetGrpModule extends PLModule } elseif (Env::has('accept')) { - XDB::execute("INSERT INTO groupex.membres - VALUES ({?}, {?}, 'membre', 'X', NULL, NULL, NULL, NULL, NULL)", + XDB::execute("INSERT INTO groupex.membres (asso_id, uid) + VALUES ({?}, {?})", $globals->asso('id'), $uid); $mailer = new PlMailer(); $mailer->addTo("$u@polytechnique.org"); $mailer->setFrom('"'.S::v('prenom').' '.S::v('nom') .'" <'.S::v('forlife').'@polytechnique.org>'); $mailer->setSubject('['.$globals->asso('nom').'] Demande d\'inscription'); - $message = "Cher Camarade,\n" + $message = ($sexe ? 'Chère' : 'Cher') . " Camarade,\n" . "\n" . " Suite à ta demande d'adhésion à ".$globals->asso('nom').",\n" . "j'ai le plaisir de t'annoncer que ton inscription a été validée !\n" @@ -506,7 +510,7 @@ class XnetGrpModule extends PLModule . "{$_SESSION["prenom"]} {$_SESSION["nom"]}."; $mailer->setTxtBody($message); $mailer->send(); - $page->kill("$prenom $nom a bien été inscrit"); + $page->kill("$prenom $nom a bien été inscrit" . ($sexe ? 'e' : '')); } elseif (Env::has('refuse')) { @@ -582,7 +586,7 @@ class XnetGrpModule extends PLModule { if (Env::has('right') && (may_update() || S::has('suid'))) { switch (Env::v('right')) { - case 'admin': + case 'admin': XnetSession::killSuid(); break; case 'anim': @@ -591,7 +595,7 @@ class XnetGrpModule extends PLModule is_member(true); break; case 'member': - XnetSession::doSelfSuid(); + XnetSession::doSelfSuid(); may_update(false, true); is_member(true); break; @@ -602,7 +606,7 @@ class XnetGrpModule extends PLModule break; } } - pl_redirect(""); + http_redirect($_SERVER['HTTP_REFERER']); } function handler_admin_annuaire(&$page) @@ -681,7 +685,7 @@ class XnetGrpModule extends PLModule WHERE a.alias={?}', $globals->asso('id'), $forlife); pl_redirect("member/$forlife"); } else { - $page->trig($email." n'est pas un alias polytechnique.org valide"); + $page->trig($email." n'est pas un alias polytechnique.org valide."); } } else { require_once 'xorg.misc.inc.php'; @@ -698,7 +702,7 @@ class XnetGrpModule extends PLModule $market = new Marketing($uid, $email, 'group', $globals->asso('nom'), Env::v('market_from'), S::v('uid')); $market->add(); - } + } } XDB::execute('INSERT INTO groupex.membres (uid, asso_id, origine, email) VALUES ({?}, {?}, "X", {?})', @@ -749,7 +753,7 @@ class XnetGrpModule extends PLModule FROM auth_user_md5 WHERE $where"); } - if ($res->total() < 30) { + if ($res && $res->total() < 30) { $page->assign("choix", $res); } } @@ -811,7 +815,7 @@ class XnetGrpModule extends PLModule } if ($this->unsubscribe($user)) { - $page->trig('Vous avez été désinscrit du groupe avec succès'); + $page->trig('Vous avez été désinscrit du groupe avec succès.'); } else { $page->trig('Vous avez été désinscrit du groupe, mais des erreurs se sont produites lors des désinscriptions des alias et des mailing-lists.'); } @@ -838,6 +842,72 @@ class XnetGrpModule extends PLModule } } + private function changeLogin(PlatalPage &$page, array &$user, MMList &$mmlist, $login) + { + require_once 'user.func.inc.php'; + // Search the uid of the user... + $res = XDB::query("SELECT f.id, f.alias + FROM aliases AS a + INNER JOIN aliases AS f ON (f.id = a.id AND f.type = 'a_vie') + WHERE a.alias = {?}", + $login); + if ($res->numRows() == 0) { + $x = get_not_registered_user($login); + if (!$x) { + $page->trig("Le login $login ne correspond à aucun X"); + return false; + } else if (count($x) > 1) { + $page->trig("Le login $login correspond a plusieurs camarades"); + return false; + } + $uid = $x[0]['user_id']; + $sub = false; + } else { + list($uid, $login) = $res->fetchOneRow(); + $sub = true; + } + + // Check if the user is already in the group + global $globals; + $res = XDB::query("SELECT uid, email + FROM groupex.membres + WHERE uid = {?} AND asso_id = {?}", + $uid, $globals->asso('id')); + if ($res->numRows()) { + list($uid, $email) = $res->fetchOneRow(); + XDB::execute("DELETE FROM groupex.membres + WHERE uid = {?}", + $user['uid']); + } else { + $email = $user['email']; + XDB::execute("UPDATE groupex.membres + SET uid = {?}, origine = 'X' + WHERE uid = {?} AND asso_id = {?}", + $uid, $user['uid'], $globals->asso('id')); + } + if ($sub) { + $email = $login . '@' . $globals->mail->domain; + } + + // Update subscription to aliases + if ($email != $user['email']) { + XDB::execute("UPDATE IGNORE virtual_redirect AS vr + INNER JOIN virtual AS v ON(vr.vid = v.vid AND SUBSTRING_INDEX(alias, '@', 2) = {?}) + SET vr.redirect = {?} + WHERE vr.redirect = {?}", + $globals->asso('mail_domain'), $email, $user['email']); + XDB::execute("DELETE vr.* + FROM virtual_redirect AS vr + INNER JOIN virtual AS v ON(vr.vid = v.vid AND SUBSTRING_INDEX(alias, '@', 2) = {?}) + WHERE vr.redirect = {?}", + $globals->asso('mail_domain'), $user['email']); + foreach (Env::v('ml1', array()) as $ml => $state) { + $mmlist->replace_email($ml, $user['email'], $email); + } + } + return $login; + } + function handler_admin_member(&$page, $user) { global $globals; @@ -853,6 +923,15 @@ class XnetGrpModule extends PLModule $globals->asso('mail_domain')); if (Post::has('change')) { + // Convert user status to X + if ($user['origine'] == 'ext' && trim(Post::v('login_X'))) { + $forlife = $this->changeLogin($page, $user, $mmlist, trim(Post::v('login_X'))); + if ($forlife) { + pl_redirect('member/' . $forlife); + } + } + + // Update user info $email_changed = ($user['origine'] != 'X' && strtolower($user['email']) != strtolower(Post::v('email'))); $from_email = $user['email']; if ($user['origine'] != 'X') { @@ -880,6 +959,7 @@ class XnetGrpModule extends PLModule $page->trig('permissions modifiées'); } + // Update ML subscriptions foreach (Env::v('ml1', array()) as $ml => $state) { $ask = empty($_REQUEST['ml2'][$ml]) ? 0 : 2; if ($ask == $state) { @@ -906,6 +986,7 @@ class XnetGrpModule extends PLModule } } + // Change subscriptioin to aliases foreach (Env::v('ml3', array()) as $ml => $state) { $ask = !empty($_REQUEST['ml4'][$ml]); if($state == $ask) continue; @@ -943,7 +1024,6 @@ class XnetGrpModule extends PLModule global $globals; require_once('rss.inc.php'); $uid = init_rss('xnetgrp/announce-rss.tpl', $user, $hash, false); - $page->register_modifier('wiki_to_html', array('MiniWiki', 'WikiToHTML')); if ($uid) { $rss = XDB::iterator("SELECT a.id, a.titre, a.texte, a.contacts, a.create_date, @@ -970,7 +1050,6 @@ class XnetGrpModule extends PLModule { global $globals, $platal; $page->changeTpl('xnetgrp/announce-edit.tpl'); - $page->register_modifier('wiki_to_html', array('MiniWiki','WikiToHTML')); $page->assign('new', is_null($aid)); $art = array(); @@ -1017,9 +1096,9 @@ class XnetGrpModule extends PLModule $promo_min = ($art['public'] ? 0 : $art['promo_min']); $promo_max = ($art['public'] ? 0 : $art['promo_max']); if (is_null($aid)) { - $fulltext = $art['texte']; - if (!empty($art['contact_html'])) { - $fulltext .= "\n\n'''Contacts :'''\\\\\n" . $art['contact_html']; + $fulltext = $art['texte']; + if (!empty($art['contact_html'])) { + $fulltext .= "\n\n'''Contacts :'''\\\\\n" . $art['contact_html']; } $post = null; if ($globals->asso('forum')) { @@ -1037,8 +1116,7 @@ class XnetGrpModule extends PLModule $aid = XDB::insertId(); if ($art['xorg']) { require_once('validations.inc.php'); - $article = new EvtReq("[{$globals->asso('nom')}] " . $art['titre'], - MiniWiki::WikiToHTML($fulltext), + $article = new EvtReq("[{$globals->asso('nom')}] " . $art['titre'], $fulltext, $art['promo_min'], $art['promo_max'], $art['peremption'], "", S::v('uid')); $article->submit(); $page->trig("L'affichage sur la page d'accueil de Polytechnique.org est en attente de validation"); @@ -1062,7 +1140,7 @@ class XnetGrpModule extends PLModule } if (Post::v('valid') == 'Enregistrer' || Post::v('valid') == 'Annuler') { pl_redirect(""); - } + } if (empty($art) && !is_null($aid)) { $res = XDB::query("SELECT a.*, u.nom, u.prenom, u.promo, l.alias AS forlife, @@ -1088,7 +1166,7 @@ class XnetGrpModule extends PLModule if ($events->total()) { $page->assign('events', $events); } - } + } $art['contact_html'] = @MiniWiki::WikiToHTML($art['contact_html']); $page->assign('art', $art);