Example #1
0
 for ($i = 1; $i < count($percent_sessions); $i++) {
     $percent_sessions[$i] += $percent_sessions[$i - 1];
 }
 for ($i = 0; $i < $session_count; $i++) {
     $test = $all_tests[rand(0, count($all_tests) - 1)];
     if (rand(0, 100) < $percent_partner_sessions) {
         $partner = $all_partners[rand(0, count($all_partners) - 1)];
     } else {
         $partner = null;
     }
     $partner_id = is_null($partner) ? 0 : $partner->id;
     $day_ordinal = rand(0, $time_range);
     $timeofday = rand(0, 60 * 60 * 24 - 1);
     $start_time = time() - $day_ordinal * 60 * 60 * 24 + $timeofday;
     $day = strftime('%Y-%m-%d', $start_time);
     $session_id = stat_test_started($test->id, $partner_id, $day, $test->all_questions[0]->id, $test->sms_enabled);
     $r = rand(0, 100);
     $count_questions = $r <= $percent_sessions[0] ? rand(0, count($test->all_questions) - 1) : count($test->all_questions) - 1;
     for ($q = 0; $q < $count_questions; $q++) {
         $question = $test->all_questions[$i];
         $answer = $question->all_answers[rand(0, count($question->all_answers) - 1)];
         stat_question_answered($session_id, $test->id, $partner_id, $day, $question->id, $answer->id, $test->all_questions[$i + 1]->id, $test->sms_enabled);
     }
     if ($r > $percent_sessions[0]) {
         $question = $test->all_questions[count($test->all_questions) - 1];
         $answer = $question->all_answers[rand(0, count($question->all_answers) - 1)];
         stat_test_finished($session_id, $test->id, $partner_id, $day, $question->id, $answer->id, $test->sms_enabled, random_string(REATESTER_SMS_CHAL_LENGTH), random_string(REATESTER_SMS_RESP_LENGTH));
         if ($r > $percent_sessions[1]) {
             stat_sms_received($session_id, $test->id, $partner_id, $day, $test->sms_enabled, 300, 200);
         }
     }
Example #2
0
$submit_url = "/tests/{$test->id}/";
if (!isset($RES->question_no)) {
    // start of test
    $RES->question_no = 0;
    $RES->partner_id = isset($_SESSION['partner_id']) ? $_SESSION['partner_id'] : 0;
    $RES->day = strftime("%Y-%m-%d");
    // be nice to the user (and to the statistics), save sms_enabled at the start of test in case it is changed later
    $RES->paid = $test->sms_enabled;
    $RES->sms_password_entered = false;
    include $test->handler_file();
    if (!function_exists('next_action')) {
        die("Invalid handler {$handler_file}: a handler must define function next_action(\$RES, \$question_count)");
    }
    // if the handler finishes the test right away, the statistics will end up incorrect
    $question = run_handler($RES, $test, null, null);
    $RES->session_id = stat_test_started($test->id, $RES->partner_id, $RES->day, $question->id, $RES->paid);
} else {
    if ($RES->finished) {
        if ($RES->paid) {
            if ($RES->sms_password_entered) {
                $full = true;
            } else {
                $full = false;
                ob_start();
                include 'templates/sms-info.inc.php';
                $sms_info = ob_get_clean();
            }
        } else {
            $full = true;
        }
        include $test->finisher_file();