/**
 * Finds column entries specific to a given $postNumber (e.g., Post 1, Post 2)
 * @param array $procedureRow
 * @param type $postNumber
 * @return array
 */
function ExtractTrial(array $procedureRow, $postNumber)
{
    $output = array();
    if ($postNumber < 1) {
        foreach ($procedureRow as $column => $value) {
            if (substr($column, 0, 5) === 'Post ' && is_numeric($column[5])) {
                continue;
            }
            $output[$column] = $value;
        }
    } else {
        $prefix = 'Post ' . $postNumber;
        $prefixLength = strlen($prefix);
        foreach ($procedureRow as $column => $value) {
            if (substr($column, 0, $prefixLength) !== $prefix) {
                continue;
            }
            $output[substr($column, $prefixLength)] = $value;
        }
    }
    createAliases($output);
    return $output;
}
示例#2
0
 }
 function recordTrial($extraData = array(), $exitIfDone = true, $advancePosition = true)
 {
     return null;
 }
 #### Copied from experiment.php, update as needed ####
 if (!isset($_SESSION['Timestamp'])) {
     $_SESSION['Timestamp'] = microtime(true);
 }
 // setting up easier to use and read aliases(shortcuts) of $_SESSION data
 $condition =& $_SESSION['Condition'];
 $currentPos =& $_SESSION['Position'];
 $currentPost =& $_SESSION['PostNumber'];
 $currentTrial =& $_SESSION['Trials'][$currentPos];
 $currentStimuli = $currentTrial['Stimuli'];
 createAliases($currentStimuli);
 // this will also create aliases of any columns that apply to the current trial (filtering out "post X" prefixes when necessary)
 // currentProcedure becomes an array of all columns matched for this trial, using their original column names
 $currentProcedure = ExtractTrial($currentTrial['Procedure'], $currentPost);
 if (!isset($trialType)) {
     $error = array('Error*Missing_Trial_Type' => 'Post ' . $_SESSION['PostNumber']);
     recordTrial();
     header('Location: experiment.php');
     exit;
 }
 $trialType = strtolower($trialType);
 $trialFiles = getTrialTypeFiles($trialType);
 if (isset($trialFiles['script'])) {
     $addedScripts = array($trialFiles['script']);
 }
 if (isset($trialFiles['style'])) {
示例#3
0
 function handler_register($page, $hash = null)
 {
     $page->forceSkin('register');
     $alert = array();
     $alert_details = '';
     $subState = new PlDict(S::v('subState', array()));
     if (!$subState->has('step')) {
         $subState->set('step', 0);
     }
     if (!$subState->has('backs')) {
         $subState->set('backs', new PlDict());
     }
     if (Get::has('back') && Get::i('back') < $subState->i('step')) {
         $subState->set('step', max(0, Get::i('back')));
         $subState->v('backs')->set($subState->v('backs')->count() + 1, $subState->dict());
         $subState->v('backs')->kill('backs');
         if ($subState->v('backs')->count() == 3) {
             $alert[] = "Tentative d'inscription très hésitante";
             $alert_details .= "\n   * Retours en arrières : 3.";
         }
     }
     if ($hash) {
         $res = XDB::query("SELECT  a.uid, a.hruid, ppn.lastname_initial AS lastname, ppn.firstname_initial AS firstname, p.xorg_id AS xorgid,\n                                       pd.promo, pe.promo_year AS yearpromo, pde.degree AS edu_type,\n                                       p.birthdate_ref AS birthdateRef, FIND_IN_SET('watch', a.flags) AS watch, m.hash, a.type, a.comment\n                                 FROM  register_marketing AS m\n                           INNER JOIN  accounts           AS a   ON (m.uid = a.uid)\n                           INNER JOIN  account_profiles   AS ap  ON (a.uid = ap.uid AND FIND_IN_SET('owner', ap.perms))\n                           INNER JOIN  profiles           AS p   ON (p.pid = ap.pid)\n                           INNER JOIN  profile_display    AS pd  ON (p.pid = pd.pid)\n                           INNER JOIN  profile_education  AS pe  ON (pe.pid = p.pid AND FIND_IN_SET('primary', pe.flags))\n                           INNER JOIN  profile_education_degree_enum AS pde ON (pde.id = pe.degreeid)\n                           INNER JOIN  profile_public_names AS ppn ON (ppn.pid = p.pid)\n                                WHERE  m.hash = {?} AND a.state = 'pending'", $hash);
         if ($res->numRows() == 1) {
             $subState->merge($res->fetchOneRow());
             $subState->set('main_mail_domain', User::$sub_mail_domains[$subState->v('type')]);
             XDB::execute('INSERT INTO  register_mstats (uid, sender, success)
                                SELECT  m.uid, m.sender, 0
                                  FROM  register_marketing AS m
                                 WHERE  m.hash
               ON DUPLICATE KEY UPDATE  sender = VALUES(sender), success = VALUES(success)', $subState->s('hash'));
         }
     }
     switch ($subState->i('step')) {
         case 0:
             $wp = new PlWikiPage('Reference.Charte');
             $wp->buildCache();
             if (Post::has('step1')) {
                 $subState->set('step', 1);
                 if ($subState->has('hash')) {
                     $subState->set('step', 3);
                     $this->load('register.inc.php');
                     createAliases($subState);
                 }
             }
             break;
         case 1:
             if (Post::has('yearpromo')) {
                 $edu_type = Post::t('edu_type');
                 $yearpromo = Post::i('yearpromo');
                 $promo = Profile::$cycle_prefixes[$edu_type] . $yearpromo;
                 $res = XDB::query("SELECT  COUNT(*)\n                                         FROM  accounts         AS a\n                                   INNER JOIN  account_profiles AS ap ON (a.uid = ap.uid AND FIND_IN_SET('owner', ap.perms))\n                                   INNER JOIN  profiles         AS p  ON (p.pid = ap.pid)\n                                   INNER JOIN  profile_education AS pe ON (pe.pid = p.pid AND FIND_IN_SET('primary', pe.flags))\n                                        WHERE  a.state = 'pending' AND p.deathdate IS NULL AND pe.promo_year = {?}", $yearpromo);
                 if (!$res->fetchOneCell()) {
                     $error = 'La promotion saisie est incorrecte ou tous les camarades de cette promotion sont inscrits !';
                 } else {
                     $subState->set('step', 2);
                     $subState->set('promo', $promo);
                     $subState->set('yearpromo', $yearpromo);
                     $subState->set('edu_type', $edu_type);
                     if ($edu_type == Profile::DEGREE_X) {
                         if ($yearpromo >= 1996 && $yearpromo < 2000) {
                             $subState->set('schoolid', $yearpromo % 100 * 10 . '???');
                             $subState->set('schoolid_exemple', $yearpromo % 100 * 10000 + 532);
                             $subState->set('schoolid_exemple_ev2', ($yearpromo + 1) % 100 * 10000 + 532);
                         } elseif ($yearpromo >= 2000) {
                             $subState->set('schoolid', 100 + $yearpromo % 100 . '???');
                             $subState->set('schoolid_exemple', (100 + $yearpromo % 100) * 1000 + 532);
                             $subState->set('schoolid_exemple_ev2', (100 + ($yearpromo + 1) % 100) * 1000 + 532);
                         }
                     }
                 }
             }
             break;
         case 2:
             if (count($_POST)) {
                 $this->load('register.inc.php');
                 $subState->set('firstname', Post::t('firstname'));
                 $subState->set('lastname', Post::t('lastname'));
                 if (Post::has('schoolid')) {
                     $subState->set('schoolid', Post::i('schoolid'));
                 }
                 $error = checkNewUser($subState);
                 if ($error !== true) {
                     break;
                 }
                 $error = createAliases($subState);
                 if ($error === true) {
                     unset($error);
                     $subState->set('step', 3);
                 }
             }
             break;
         case 3:
             if (count($_POST)) {
                 $this->load('register.inc.php');
                 // Validate the email address format and domain.
                 require_once 'emails.inc.php';
                 $user = User::get($subState->s('uid'));
                 if (!isvalid_email(Post::v('email'))) {
                     $error[] = "Le champ 'Email' n'est pas valide.";
                 } elseif (!isvalid_email_redirection(Post::v('email'), $user)) {
                     $error[] = $subState->s('forlife') . ' doit renvoyer vers un email existant ' . 'valide, en particulier, il ne peut pas être renvoyé vers lui-même.';
                 }
                 // Validate the birthday format and range.
                 $birth = Post::t('birthdate');
                 if (!preg_match('@^[0-3]?\\d/[01]?\\d/(19|20)?\\d{2}$@', $birth)) {
                     $error[] = "La 'Date de naissance' n'est pas correcte.";
                 } else {
                     $birth = explode('/', $birth, 3);
                     for ($i = 0; $i < 3; ++$i) {
                         $birth[$i] = intval($birth[$i]);
                     }
                     if ($birth[2] < 100) {
                         $birth[2] += 1900;
                     }
                     $year = $birth[2];
                     $ref_year = substr($subState->v('birthdateRef'), 0, 4);
                     if (abs($ref_year - $year) > 2) {
                         $error[] = "La 'Date de naissance' n'est pas correcte.";
                         $alert[] = "Date de naissance incorrecte à l'inscription";
                         $alert_details .= "\n   * Date de naissance renseignée : " . Post::t('birthdate');
                         if ($subState->v('birthdateRef') == '0000-00-00') {
                             $alert_details .= ' (date inconnue)';
                         } else {
                             $alert_details .= ' (date connue : ' . $subState->v('birthdateRef') . ')';
                         }
                         $subState->set('wrong_birthdate', $birth);
                     }
                 }
                 // Register the optional services requested by the user.
                 $services = array();
                 foreach (array('com_letters', 'imap', 'ml_promo', 'nl') as $service) {
                     if (Post::b($service)) {
                         $services[] = $service;
                     }
                 }
                 $subState->set('services', $services);
                 // Validate the password.
                 if (!Post::v('pwhash', false)) {
                     $error[] = "Le mot de passe n'est pas valide.";
                 }
                 // Check if the given email is known as dangerous.
                 $res = XDB::query("SELECT  state, description\n                                         FROM  email_watch\n                                        WHERE  email = {?} AND state != 'safe'", Post::v('email'));
                 $bannedEmail = false;
                 if ($res->numRows()) {
                     list($state, $description) = $res->fetchOneRow();
                     $alert[] = "Email surveillé proposé à l'inscription";
                     $alert_details .= "\n   * Email surveillé : " . Post::v('email');
                     $subState->set('email_desc', $description);
                     if ($state == 'dangerous') {
                         $bannedEmail = true;
                     }
                 }
                 if ($subState->i('watch') != 0) {
                     $alert[] = "Inscription d'un utilisateur surveillé";
                     $alert_details .= "\n   * Commentaire pour la surveillance : " . $subState->v('comment');
                 }
                 if ($bannedIp = check_ip('unsafe')) {
                     unset($error);
                 }
                 if (isset($error)) {
                     $error = join('<br />', $error);
                 } else {
                     $subState->set('birthdate', sprintf("%04d-%02d-%02d", intval($birth[2]), intval($birth[1]), intval($birth[0])));
                     $subState->set('email', Post::t('email'));
                     $subState->set('password', Post::t('pwhash'));
                     // Update the current alert if the birthdate is incorrect,
                     // or if the IP address of the user has been banned.
                     if ($subState->s('birthdateRef') != '0000-00-00' && $subState->s('birthdateRef') != $subState->s('birthdate')) {
                         $alert[] = "Date de naissance incorrecte à l'inscription";
                         $alert_details .= "\n   * Date de naissance renseignée : " . Post::t('birthdate');
                         if ($subState->v('birthdateRef') == '0000-00-00') {
                             $alert_details .= ' (date inconnue)';
                         } else {
                             $alert_details .= ' (date connue : ' . $subState->v('birthdateRef') . ')';
                         }
                     }
                     if ($bannedIp) {
                         $alert[] = "Tentative d'inscription depuis une IP surveillée";
                         $alert_details .= "\n   * IP surveillée : " . $_SESSION['check_ip'];
                     }
                     // Prevent banned user from actually registering; save the current state for others.
                     if ($bannedEmail || $bannedIp) {
                         global $globals;
                         $error = "Une erreur s'est produite lors de l'inscription." . " Merci de contacter <a href='mailto:register@{$globals->mail->domain}>" . " register@{$globals->mail->domain}</a>" . " pour nous faire part de cette erreur.";
                     } else {
                         $subState->set('step', 4);
                         if ($subState->v('backs')->count() >= 3) {
                             $alert[] = "Fin d'une inscription hésitante";
                             $alert_details .= "\n   * Nombre de retours en arrière : " . $subState->v('backs')->count();
                         }
                         finishRegistration($subState);
                     }
                 }
             }
             break;
     }
     $_SESSION['subState'] = $subState->dict();
     if (count($alert)) {
         $alert_details = "Détails des alertes :" . $alert_details . "\n\n";
         $alert_details .= 'Compte concerné : ' . $subState->s('forlife') . ' (redirection vers : ' . ($subState->s('email') == '' ? Post::t('email') : $subState->s('email')) . ")\n\n\n";
         send_warning_mail(implode(' - ', $alert), $alert_details);
     }
     $page->changeTpl('register/step' . $subState->i('step') . '.tpl');
     if (isset($error)) {
         $page->trigError($error);
     }
 }