示例#1
0
文件: carnet.php 项目: Ekleog/platal
 function handler_batch($page)
 {
     $page->changeTpl('carnet/batch.tpl');
     $errors = false;
     $incomplete = array();
     if (Post::has('add')) {
         S::assert_xsrf_token();
         require_once 'userset.inc.php';
         require_once 'emails.inc.php';
         require_once 'marketing.inc.php';
         $list = explode("\n", Post::v('list'));
         $origin = Post::v('origin');
         foreach ($list as $item) {
             if ($item = trim($item)) {
                 $elements = preg_split("/\\s/", $item);
                 $email = array_pop($elements);
                 if (!isvalid_email($email)) {
                     $page->trigError('Email invalide : ' . $email);
                     $incomplete[] = $item;
                     $errors = true;
                     continue;
                 }
                 $user = User::getSilent($email);
                 if (is_null($user)) {
                     $details = implode(' ', $elements);
                     $promo = trim(array_pop($elements));
                     $cond = new PFC_And();
                     if (preg_match('/^[MDX]\\d{4}$/', $promo)) {
                         $cond->addChild(new UFC_Promo('=', UserFilter::DISPLAY, $promo));
                     } else {
                         $cond->addChild(new UFC_NameTokens($promo));
                     }
                     foreach ($elements as $element) {
                         $cond->addChild(new UFC_NameTokens($element));
                     }
                     $uf = new UserFilter($cond);
                     $count = $uf->getTotalCount();
                     if ($count == 0) {
                         $page->trigError('Les informations : « ' . $item . ' » ne correspondent à aucun camarade.');
                         $incomplete[] = $item;
                         $errors = true;
                         continue;
                     } elseif ($count > 1) {
                         $page->trigError('Les informations : « ' . $item . ' » sont ambigues et correspondent à plusieurs camarades.');
                         $incomplete[] = $item;
                         $errors = true;
                         continue;
                     } else {
                         $user = $uf->getUser();
                     }
                 }
                 if ($user->state == 'active') {
                     $this->addRegistered($page, $user->profile());
                 } else {
                     if (!User::isForeignEmailAddress($email)) {
                         $page->trigError('Email pas encore attribué : ' . $email);
                         $incomplete[] = $item;
                         $errors = true;
                     } else {
                         $this->addNonRegistered($page, $user);
                         if (!Marketing::get($user->id(), $email, true)) {
                             check_email($email, "Une adresse surveillée est proposée au marketing par " . S::user()->login());
                             $market = new Marketing($user->id(), $email, 'default', null, $origin, S::v('uid'), null);
                             $market->add();
                         }
                     }
                 }
             }
         }
     }
     $page->assign('errors', $errors);
     $page->assign('incomplete', $incomplete);
 }
示例#2
0
文件: lists.php 项目: Ekleog/platal
 function handler_admin($page, $liste = null)
 {
     global $globals;
     if (is_null($liste)) {
         return PL_NOT_FOUND;
     }
     $mlist = $this->prepare_list($liste);
     $this->is_group_admin($page);
     if (!$this->is_group_admin($page)) {
         $this->verify_list_owner($page, $mlist);
     }
     $page->changeTpl('lists/admin.tpl');
     if (Env::has('send_mark')) {
         S::assert_xsrf_token();
         $actions = Env::v('mk_action');
         $uids = Env::v('mk_uid');
         $mails = Env::v('mk_email');
         foreach ($actions as $key => $action) {
             switch ($action) {
                 case 'none':
                     break;
                 case 'marketu':
                 case 'markets':
                     require_once 'emails.inc.php';
                     $user = User::get($uids[$key]);
                     $mail = valide_email($mails[$key]);
                     if (isvalid_email_redirection($mail, $user)) {
                         $from = $action == 'marketu' ? 'user' : 'staff';
                         $market = Marketing::get($uids[$key], $mail);
                         if (!$market) {
                             $market = new Marketing($uids[$key], $mail, 'list', $mlist->address, $from, S::v('uid'));
                             $market->add();
                             break;
                         }
                     }
                 default:
                     XDB::execute('INSERT IGNORE INTO  register_subs (uid, type, sub, domain)
                                           VALUES  ({?}, \'list\', {?}, {?})', $uids[$key], $mlist->mbox, $mlist->domain);
             }
         }
     }
     if (Env::has('add_member') || isset($_FILES['add_member_file']) && $_FILES['add_member_file']['tmp_name']) {
         S::assert_xsrf_token();
         if (isset($_FILES['add_member_file']) && $_FILES['add_member_file']['tmp_name']) {
             $upload =& PlUpload::get($_FILES['add_member_file'], S::user()->login(), 'list.addmember', true);
             if (!$upload) {
                 $page->trigError("Une erreur s'est produite lors du téléchargement du fichier.");
             } else {
                 $logins = $upload->getContents();
             }
         } else {
             $logins = Env::v('add_member');
         }
         $logins = preg_split("/[; ,\r\n\\|]+/", $logins);
         $members = User::getBulkForlifeEmailsFromEmail($logins);
         $unfound = array_diff_key($logins, $members);
         // Make sure we send a list (array_values) of unique (array_unique)
         // emails.
         $members = array_values(array_unique($members));
         $arr = $mlist->subscribeBulk($members);
         $successes = array();
         if (is_array($arr)) {
             foreach ($arr as $addr) {
                 $successes[] = $addr[1];
                 $page->trigSuccess("{$addr[0]} inscrit.");
             }
         }
         $already = array_diff($members, $successes);
         if (is_array($already)) {
             foreach ($already as $item) {
                 $page->trigWarning($item . ' est déjà inscrit.');
             }
         }
         if (is_array($unfound)) {
             foreach ($unfound as $item) {
                 if (trim($item) != '') {
                     $page->trigError($item . " ne correspond pas à un compte existant et n'est pas une adresse email.");
                 }
             }
         }
     }
     if (Env::has('del_member')) {
         S::assert_xsrf_token();
         if (strpos(Env::v('del_member'), '@') === false) {
             if ($del_member = User::getSilent(Env::t('del_member'))) {
                 $mlist->unsubscribeBulk(array($del_member->forlifeEmail()));
             }
         } else {
             $mlist->unsubscribeBulk(array(Env::v('del_member')));
         }
         pl_redirect('lists/admin/' . $liste);
     }
     if (Env::has('add_owner')) {
         S::assert_xsrf_token();
         $owners = User::getBulkForlifeEmailsFromEmail(Env::v('add_owner'));
         if ($owners) {
             foreach ($owners as $forlife_email) {
                 if ($mlist->addOwner($forlife_email)) {
                     $page->trigSuccess($login . " ajouté aux modérateurs.");
                 }
             }
         }
     }
     if (Env::has('del_owner')) {
         S::assert_xsrf_token();
         if (strpos(Env::v('del_owner'), '@') === false) {
             if ($del_owner = User::getSilent(Env::t('del_owner'))) {
                 $mlist->removeOwner($del_owner->forlifeEmail());
             } else {
                 // Shit happens, and a non-email could be set as the owner
                 $mlist->removeOwner(Env::v('del_owner'));
             }
         } else {
             $mlist->removeOwner(Env::v('del_owner'));
         }
         pl_redirect('lists/admin/' . $liste);
     }
     if (list($det, $mem, $own) = $mlist->getMembers()) {
         global $list_unregistered;
         if ($list_unregistered) {
             $page->assign_by_ref('unregistered', $list_unregistered);
         }
         $membres = list_sort_members($mem, @$tri_promo);
         $moderos = list_sort_owners($own, @$tri_promo);
         $page->assign_by_ref('details', $det);
         $page->assign_by_ref('members', $membres);
         $page->assign_by_ref('owners', $moderos);
         $page->assign('np_m', count($mem));
     } else {
         $page->kill("La liste n'existe pas ou tu n'as pas le droit de l'administrer.<br />" . " Si tu penses qu'il s'agit d'une erreur, " . "<a href='mailto:support@polytechnique.org'>contact le support</a>.");
     }
 }
示例#3
0
    exit;
}
$matcol = intval($opts['m']);
$logcol = intval($opts['l']);
$handle = fopen($file, 'r');
while ($data = fgetcsv($handle)) {
    $login = $data[$logcol];
    $xorgid = preg_replace('/1(\\d{2})(\\d{3})/', '20${1}0\\2', $data[$matcol]);
    if (!is_numeric($xorgid)) {
        echo "ERROR The matricule ({$xorgid}) is not a numerical value.\n";
        break;
    }
    $query = XDB::query("SELECT  a.uid\n                           FROM  profiles         AS p\n                     INNER JOIN  account_profiles AS ap ON (p.pid = ap.pid AND FIND_IN_SET('owner', perms)\n                     INNER JOIN  accounts         AS a  ON (a.uid = ap.uid)\n                          WHERE  p.xorg_id = {?}", $xorgid);
    $uid = $query->fetchOneCell();
    if (!$uid) {
        echo "WARNING Can't find uid for matricule {$xorgid} (login {$login})\n";
        continue;
    }
    $market = Marketing::get($uid, "{$login}@poly.polytechnique.fr");
    if (!is_null($market)) {
        echo "WARNING A marketing has already been to {$xorgid} on {$login}\n";
        continue;
    }
    $market = new Marketing($uid, "{$login}@poly.polytechnique.fr", 'default', null, 'staff');
    $market->add(false);
    $market->send();
}
// vim:set et sw=4 sts=4 sws=4 foldmethod=marker fenc=utf-8:
?>

示例#4
0
 function handler_public($page, $hruid = null)
 {
     $page->changeTpl('marketing/public.tpl');
     // Retrieves the user info, and checks the user is not yet registered.
     $user = User::getSilent($hruid);
     if (!$user || !$user->hasProfile()) {
         return PL_NOT_FOUND;
     }
     if ($user->state != 'pending') {
         $page->kill('Cet utilisateur est déjà inscrit');
     }
     // Displays the page, and handles the eventual user actions.
     $page->assign('full_name', $user->fullName());
     $page->assign('promo', $user->promo());
     if (Post::has('valide')) {
         S::assert_xsrf_token();
         $email = trim(Post::v('mail'));
         require_once 'emails.inc.php';
         if (!isvalid_email_redirection($email, $user)) {
             $page->trigError('Email invalide&nbsp;!');
         } else {
             // On cherche les marketings précédents sur cette adresse
             // email, en se restreignant au dernier mois
             if (Marketing::get($user->id(), $email, true)) {
                 $page->assign('already', true);
             } else {
                 $page->assign('ok', true);
                 check_email($email, "Une adresse surveillée est proposée au marketing par " . S::user()->login());
                 $market = new Marketing($user->id(), $email, 'default', null, Post::v('origine'), S::v('uid'), Post::v('origine') == 'user' ? Post::v('personal_notes') : null);
                 $market->add();
             }
         }
     } else {
         global $globals;
         require_once 'marketing.inc.php';
         $sender = User::getSilent(S::v('uid'));
         $perso_signature = 'Cordialement,<br />-- <br />' . $sender->fullName();
         $market = new AnnuaireMarketing(null, true);
         $text = $market->getText(array('sexe' => $user->isFemale(), 'forlife_email' => $user->hruid . "@" . $user->mainEmailDomain(), 'forlife_email2' => $user->hruid . "@" . $user->alternateEmailDomain()));
         $text = str_replace('%%hash%%', '', $text);
         $text = str_replace('%%personal_notes%%', '<em id="personal_notes_display"></em>', $text);
         $text = str_replace('%%sender%%', '<span id="sender">' . $perso_signature . '</span>', $text);
         $page->assign('text', nl2br($text));
         $page->assign('perso_signature', $perso_signature);
         $page->assign('mail_part', 'escaped_html');
     }
 }
示例#5
0
文件: xnetgrp.php 项目: Ekleog/platal
 private function changeLogin(PlPage $page, PlUser $user, $login, $req_broken = false, $req_marketing = false, $marketing_from = 'user')
 {
     // Search the user's uid.
     $xuser = User::getSilent($login);
     if (!$xuser) {
         $accounts = User::getPendingAccounts($login);
         if (!$accounts) {
             $page->trigError("L'identifiant {$login} ne correspond à aucun X.");
             return false;
         } else {
             if (count($accounts) > 1) {
                 $page->trigError("L'identifiant {$login} correspond à plusieurs camarades.");
                 return false;
             }
         }
         $xuser = User::getSilent($accounts[0]['uid']);
     }
     if (!$xuser) {
         return false;
     }
     // Market or suggest new redirection if required.
     $email = $user->bestEmail();
     if ($req_broken) {
         $valid = new BrokenReq(S::user(), $xuser, $email, 'Groupe : ' . Platal::globals()->asso('nom'));
         $valid->submit();
     } elseif ($req_marketing) {
         $market = Marketing::get($xuser->uid, $email);
         if (!$market) {
             $market = new Marketing($xuser->uid, $email, 'group', Platal::globals()->asso('nom'), $marketing_from, S::i('uid'));
             $market->add();
         }
     }
     if ($user->mergeIn($xuser)) {
         return $xuser->login();
     }
     return $user->login();
 }