if ($user_id) { $token = remember_user($user_id, false, false); $answer['answer'] = array('user_id' => $user_id, 'token' => $token); } else { $answer['error'] = 'Incorrect login or password'; } break; case 'get_available_morph_tasks': $answer['answer'] = array('tasks' => get_available_tasks($user_id, true)); break; case 'get_morph_task': if (empty($_POST['pool_id']) || empty($_POST['size'])) { throw new UnexpectedValueException("Wrong args"); } // timeout is in seconds $answer['answer'] = get_annotation_packet($_POST['pool_id'], $_POST['size'], $user_id, $_POST['timeout']); break; case 'update_morph_task': throw new Exception("Not implemented"); // currently no backend break; case 'save_morph_task': // answers is expected to be an array(array(id, answer), array(id, answer), ...) update_annot_instances($user_id, $_POST['answers']); break; default: throw new Exception('Unknown action'); } } catch (Exception $e) { $answer['error'] = $e->getMessage(); }
if (!isset($_GET['pool_id']) || !$_GET['pool_id']) { throw new UnexpectedValueException('Wrong pool_id'); } $pool_size = 5; $opt = OPTION(OPT_SAMPLES_PER_PAGE); switch ($opt) { case 2: $pool_size = 10; break; case 3: $pool_size = 20; break; case 4: $pool_size = 50; } if ($t = get_annotation_packet((int) $_GET['pool_id'], $pool_size)) { $smarty->assign('packet', $t); $smarty->display('qa/morph_annot.tpl'); } else { $smarty->assign('next_pool_id', get_next_pool($_SESSION['user_id'], (int) $_GET['pool_id'])); $smarty->assign('final', true); if (game_is_on()) { $am2 = new AchievementsManager($_SESSION['user_id']); $smarty->assign('achievement', $am2->get_closest()); } $smarty->display('qa/morph_annot_thanks.tpl'); } break; case 'my': if (!isset($_GET['pool_id']) || !$_GET['pool_id']) { throw new UnexpectedValueException('Wrong pool_id');