X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=modules%2Fxnetgrp.php;h=a558cbf7d4b9621950dfa2f508e90725eb6126b6;hb=cafb410fea6f257f45da08631c6cdb5c35f86b17;hp=e4449a0f461be3a2d5cc53933ac27d511d5d324b;hpb=7c4ae1c3d38d458ac3b6dea25ca76ebdd2c0ecd8;p=platal.git diff --git a/modules/xnetgrp.php b/modules/xnetgrp.php index e4449a0..a558cbf 100644 --- a/modules/xnetgrp.php +++ b/modules/xnetgrp.php @@ -130,7 +130,7 @@ class XnetGrpModule extends PLModule $platal->ns . "rss/rss.xml"); } else { $page->setRssLink("Polytechnique.net :: {$globals->asso("nom")} :: News", - $platal->ns . 'rss/'.S::v('hruid') .'/'.S::v('token').'/rss.xml'); + $platal->ns . 'rss/' . S::v('hruid') . '/' . S::user()->token . '/rss.xml'); } $page->assign('articles', $arts); @@ -193,7 +193,7 @@ class XnetGrpModule extends PLModule flags={?} WHERE id={?}", Post::v('nom'), Post::v('diminutif'), - Post::v('cat'), Post::i('dom'), + Post::v('cat'), (Post::i('dom') == 0) ? null : Post::i('dom'), Post::v('descr'), $site, Post::v('mail'), Post::v('resp'), Post::v('forum'), Post::v('mail_domain'), @@ -249,8 +249,7 @@ class XnetGrpModule extends PLModule global $globals; $page->changeTpl('xnetgrp/mail.tpl'); - $mmlist = new MMList(S::v('uid'), S::v('password'), - $globals->asso('mail_domain')); + $mmlist = new MMList(S::user(), $globals->asso('mail_domain')); $page->assign('listes', $mmlist->get_lists()); $page->assign('user', S::user()); $page->addJsLink('ajax.js'); @@ -401,13 +400,13 @@ class XnetGrpModule extends PLModule $mailer->setSubject('[' . $globals->asso('nom') . '] Demande d\'inscription'); $message = ($user->isFemale() ? '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" + . " Suite à ta demande d'adhésion à " . $globals->asso('nom') + . ", j'ai le plaisir de t'annoncer que ton inscription a été validée !\n" . "\n" . "Bien cordialement,\n" . "-- \n" . S::user()->fullName() . '.'; - $mailer->setTxtBody($message); + $mailer->setTxtBody(wordwrap($message, 72)); $mailer->send(); } } @@ -636,55 +635,75 @@ class XnetGrpModule extends PLModule S::assert_xsrf_token(); - // Finds or creates account + // Finds or creates account: first cases are for users with an account. if (!User::isForeignEmailAddress($email)) { - // standard x account + // Standard account $user = User::get($email); } else if (!isvalid_email($email)) { // email might not be a regular email but an alias or a hruid $user = User::get($email); if (!$user) { // need a valid email address - $page->trigError("« $email Â» n'est pas une adresse email valide."); + $page->trigError('« ' . $email . ' Â» n\'est pas une adresse email valide.'); return; } } else if (Env::v('x') && Env::i('userid')) { - // user is an x but might not yet be registered $user = User::getWithUID(Env::i('userid')); if (!$user) { - $page->trigError("Utilisateur invalide"); + $page->trigError('Utilisateur invalide.'); return; } - // add email for marketing if unknown - if ($user->state == 'pending' && Env::v('market')) { - $market = Marketing::get($user->uid, $email); - if (!$market) { - $market = new Marketing($user->uid, $email, 'group', $globals->asso('nom'), - Env::v('market_from'), S::v('uid')); - $market->add(); + + // User has an account but is not yet registered. + if ($user->state == 'pending') { + // Add email in account table. + XDB::query('UPDATE accounts + SET email = {?} + WHERE uid = {?} AND email IS NULL', + Post::t('email'), $user->id()); + // Add email for marketing if required. + if (Env::v('market')) { + $market = Marketing::get($user->uid, $email); + if (!$market) { + $market = new Marketing($user->uid, $email, 'group', $globals->asso('nom'), + Env::v('market_from'), S::v('uid')); + $market->add(); + } } } } else { - // user is not an x - $hruid = strtolower(str_replace('@','.',$email).'.ext'); - // might already exists (in another group for example) + // User is of type xnet. + list($mbox, $domain) = explode('@', strtolower($email)); + $hruid = User::makeHrid($mbox, $domain, 'ext'); + // User might already have an account (in another group for example). $user = User::get($hruid); + + // If the user has no account yet, creates new account: build names from email address. if (empty($user)) { - // creates new account: build names from email address - $display_name = ucwords(strtolower(substr($hruid, strpos('.', $hruid)))); - $full_name = ucwords(strtolower(str_replace('.', ' ',substr($email, strpos('@', $email))))); - XDB::execute("INSERT INTO accounts (hruid, display_name, full_name, email, type) - VALUES({?}, {?}, {?}, {?}, 'xnet')", - $hruid, $display_name, $full_name, $email); + $parts = explode('.', $mbox); + if (count($parts) == 1) { + $display_name = $full_name = $directory_name = ucfirst($mbox); + } else { + $firstname = ucfirst($parts[0]); + $lastname = ucwords(implode(' ', array_slice($parts, 1))); + $display_name = $firstname; + $full_name = "$firstname $lastname"; + $directory_name = strtoupper($lastname) . " " . $firstname; + } + XDB::execute('INSERT INTO accounts (hruid, display_name, full_name, directory_name, + email, type) + VALUES ({?}, {?}, {?}, {?}, {?}, \'xnet\')', + $hruid, $display_name, $full_name, $directory_name, $email); $user = User::get($hruid); } } + if ($user) { - XDB::execute("REPLACE INTO group_members (uid, asso_id) - VALUES ({?}, {?})", + XDB::execute('INSERT IGNORE INTO group_members (uid, asso_id) + VALUES ({?}, {?})', $user->id(), $globals->asso('id')); $this->removeSubscriptionRequest($user->id()); - pl_redirect("member/" . $user->login()); + pl_redirect('member/' . $user->login()); } } @@ -700,16 +719,16 @@ class XnetGrpModule extends PLModule } } if (empty($users)) { - list($nom, $prenom) = str_replace(array('-', ' ', "'"), '%', array(Env::t('nom'), Env::t('prenom'))); + list($lastname, $firstname) = str_replace(array('-', ' ', "'"), '%', array(Env::t('nom'), Env::t('prenom'))); $cond = new PFC_And(new PFC_Not(new UFC_Registered())); - if (!empty($nom)) { - $cond->addChild(new UFC_Name(Profile::LASTNAME, $nom, UFC_Name::CONTAINS)); + if (!empty($lastname)) { + $cond->addChild(new UFC_Name(Profile::LASTNAME, $lastname, UFC_Name::CONTAINS)); } - if (!empty($prenom)) { - $cond->addChild(new UFC_Name(Profile::FIRSTNAME, $prenom, UFC_Name::CONTAINS)); + if (!empty($firstname)) { + $cond->addChild(new UFC_Name(Profile::FIRSTNAME, $firstname, UFC_Name::CONTAINS)); } - if (Env::i('promo')) { - $cond->addChild(new UFC_Promo('=', UserFilter::GRADE_ING, Env::i('promo'))); + if (Env::t('promo')) { + $cond->addChild(new UFC_Promo('=', UserFilter::DISPLAY, Env::t('promo'))); } $uf = new UserFilter($cond); $users = $uf->getUsers(new PlLimit(30)); @@ -745,7 +764,7 @@ class XnetGrpModule extends PLModule return true; } - $mmlist = new MMList($user, $domain); + $mmlist = new MMList(S::user(), $domain); $listes = $mmlist->get_lists($user->forlifeEmail()); $may_update = may_update(); @@ -824,7 +843,7 @@ class XnetGrpModule extends PLModule private function changeLogin(PlPage &$page, PlUser &$user, MMList &$mmlist, $login) { - // Search the uid of the user... + // Search the user's uid. $xuser = User::getSilent($login); if (!$xuser) { $accounts = User::getPendingAccounts($login); @@ -836,16 +855,16 @@ class XnetGrpModule extends PLModule return false; } $xuser = User::getSilent($accounts[0]['uid']); - $sub = false; } if (!$xuser) { return false; } - $user->mergeIn($xuser); - - return $xuser->login(); + if ($user->mergeIn($xuser)) { + return $xuser->login(); + } + return $user->login(); } function handler_admin_member(&$page, $user) @@ -859,7 +878,7 @@ class XnetGrpModule extends PLModule return PL_NOT_FOUND; } - $mmlist = new MMList($user, $globals->asso('mail_domain')); + $mmlist = new MMList(S::user(), $globals->asso('mail_domain')); if (Post::has('change')) { S::assert_xsrf_token(); @@ -877,13 +896,20 @@ class XnetGrpModule extends PLModule $from_email = $user->forlifeEmail(); if (!$user->profile()) { XDB::query('UPDATE accounts - SET full_name = {?}, directory_name = {?}, display_name = {?}, sex = {?}, email = {?}, type = {?} + SET full_name = {?}, directory_name = {?}, display_name = {?}, + sex = {?}, email = {?}, type = {?} WHERE uid = {?}', - Post::t('full_name'), Post::t('directory_name'), Post::t('display_name'), (Post::v('sex') == 'male')?'male':'female', Post::v('email'), (Post::v('type') == 'xnet')?'xnet':'virtual', - $user->id()); - if (XDB::affectedRows()) { - $page->trigSuccess('Données de l\'utilisateur mise à jour.'); - } + Post::t('full_name'), Post::t('directory_name'), Post::t('display_name'), + (Post::t('sex') == 'male') ? 'male' : 'female', Post::t('email'), + (Post::t('type') == 'xnet') ? 'xnet' : 'virtual', $user->id()); + } else if (!$user->perms) { + XDB::query('UPDATE accounts + SET email = {?} + WHERE uid = {?}', + Post::t('email'), $user->id()); + } + if (XDB::affectedRows()) { + $page->trigSuccess('Données de l\'utilisateur mise à jour.'); } // Update group params for user @@ -895,11 +921,13 @@ class XnetGrpModule extends PLModule WHERE uid = {?} AND asso_id = {?}', ($perms == 'admin') ? 'admin' : 'membre', $comm, $user->id(), $globals->asso('id')); - if ($perms != $user->group_perms) { - $page->trigSuccess('Permissions modifiées !'); - } - if ($comm != $user->group_comm) { - $page->trigSuccess('Commentaire mis à jour.'); + if (XDB::affectedRows()) { + if ($perms != $user->group_perms) { + $page->trigSuccess('Permissions modifiées !'); + } + if ($comm != $user->group_comm) { + $page->trigSuccess('Commentaire mis à jour.'); + } } } @@ -1119,7 +1147,6 @@ class XnetGrpModule extends PLModule $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['expiration'], "", S::user(), $upload); @@ -1129,7 +1156,6 @@ class XnetGrpModule extends PLModule $upload->rm(); } if ($art['nl']) { - require_once('validations.inc.php'); $article = new NLReq(S::user(), $globals->asso('nom') . " : " .$art['titre'], $art['texte'], $art['contact_html']); $article->submit(); @@ -1145,9 +1171,10 @@ class XnetGrpModule extends PLModule $art['id'], $globals->asso('id')); if ($art['photo'] && $upload->exists()) { list($imgx, $imgy, $imgtype) = $upload->imageInfo(); - XDB::execute("REPLACE INTO group_announces_photo - SET eid = {?}, attachmime = {?}, x = {?}, y = {?}, attach = {?}", - $aid, $imgtype, $imgx, $imgy, $upload->getContents()); + XDB::execute('INSERT INTO group_announces_photo (eid, attachmime, attach, x, y) + VALUES ({?}, {?}, {?}, {?}, {?}) + ON DUPLICATE KEY UPDATE attachmime = VALUES(attachmime), attach = VALUES(attach), x = VALUES(x), y = VALUES(y)', + $aid, $imgtype, $upload->getContents(), $imgx, $imgy); $upload->rm(); } }