Exemple #1
0
$app->get('/level/:level/:lesson/exam', function ($level, $lesson) use($app, $user) {
    if (!$user->isLessonAvailable($level, $lesson)) {
        $app->redirect('/level/' . $user->getLevel());
    }
    $lessonData = \PTA\App::getLesson($level, $lesson);
    $bgImage = $user->getBackgroundImage();
    # Get the preceding and following lessons for back/next style buttons
    $prev_lesson = $user->getPreviousLesson($level, $lesson);
    $next_lesson = $user->getNextLesson($level, $lesson);
    if ($prev_lesson !== null) {
        $prev_lesson = '/level/' . $prev_lesson[0] . '/' . $prev_lesson[1] . '/exam';
    }
    if ($next_lesson !== null) {
        $next_lesson = '/level/' . $next_lesson[0] . '/' . $next_lesson[1] . '/exam';
    }
    $app->render('lesson-exam.twig', ['pjax' => array_key_exists('X-PJAX', getallheaders()), 'bgImage' => $bgImage, 'lesson' => $lesson, 'level' => $level, 'neturl' => \PTA\App::getNetConnectionUrl(), 'next_lesson' => $next_lesson, 'prev_lesson' => $prev_lesson, 'title_ar' => $lessonData['title_ar'], 'title_en' => $lessonData['title_en'], 'url' => \PTA\App::getExamURL($level, $lesson, $user->getUserId(), $user->createNonce($_SERVER['REMOTE_ADDR'], 'exam')), 'user_id' => $user->getUserId()]);
});
$app->get('/level/:level/congratulations', function ($level) use($app, $user) {
    # If the request is for a higher level than is available then redirect to the home screen
    if ($level < 2 || !$user->isLevelAvailable($level)) {
        $app->redirect('/home');
    }
    $names = preg_split('/\\s/', $user->getName());
    $app->render('congratulations.twig', ['pjax' => array_key_exists('X-PJAX', getallheaders()), 'level' => $level, 'firstname' => $names[0]]);
});
$app->get('/apihelp/', function () use($app, $user) {
    $app->contentType('text/plain');
    print_r(\AM_Lite::getInstance()->getAccess());
    print_r(\AM_Lite::getInstance()->getProducts());
    echo "\n\n# AM_Lite User Array\n\n";
    print_r(\AM_Lite::getInstance()->getUser());
Exemple #2
0
 public function getVideoPlaylist($level, $lesson, $gender)
 {
     if (!\PTA\Validate::gender($gender)) {
         $gender = $this->getPreferredGender();
     }
     //		return \PTA\App::getVideoPlayList($level, $lesson, $gender, $this->getPref('video:pseudoStreaming'));
     return \PTA\App::getVideoPlayList($level, $lesson, $gender, true);
 }
Exemple #3
0
    public function createNonce($ip, $class = 'undefined', $user_id = null)
    {
        $uuid = App::createUUID();
        if (!$uuid) {
            $uuid = md5(uniqid(mt_rand(), true));
        }
        if ($user_id === null) {
            $user_id = $this->getUserId();
        }
        $sql = <<<SQL
\t\t\tINSERT INTO nonce (user_id, ip, class, value, created_on)
\t\t\tVALUES (:user_id, :ip, :class, :value, NOW())
\t\t\tON DUPLICATE KEY UPDATE value = :value, created_on = NOW()
SQL;
        $stmt = PdoFactory::getInstance()->prepare($sql);
        $rc = $stmt->execute([':user_id' => $user_id, ':ip' => $ip, ':class' => $class, ':value' => $uuid]);
        return $rc === true ? $uuid : null;
    }
    $logged = true;
    #if ($user->isLoggedIn() && $user->verifyNonce($request->post('nonce'), $ip, 'login-' . $user->getUsername(), 0)) {
    $user->logLogin($ip);
    #}
    $app->contentType('application/json');
    echo json_encode(['status' => $logged ? '0' : '1']);
});
$app->post('/api/affiliate/search', function () use($app, $user) {
    $app->contentType('application/json');
    $searchterm = $app->request()->post('searchterm');
    $affiliates = \PTA\App::findAffiliate($searchterm);
    echo json_encode($affiliates);
});
$app->get('/api/teachers', function () use($app, $user) {
    $app->contentType('application/json');
    echo json_encode(\PTA\App::getTeachers());
});
$app->post('/api/survey', function () use($app, $user) {
    $app->contentType('application/json');
    $data = json_decode($app->request()->getBody());
    $rc = 0;
    $rc |= $user->setPreferredGender($data->gender);
    $position = ['level' => 1, 'lesson' => 1];
    switch ($data->rating) {
        case 2:
            $position = ['level' => 1, 'lesson' => 5];
            break;
        case 3:
            $position = ['level' => 2, 'lesson' => 1];
            break;
        case 4: