<?php require 'lib/header.php'; require_once 'lib/constants.php'; require_once 'lib/lib_xml.php'; require_once 'lib/lib_morph_pools.php'; $smarty->assign('active_page', 'tasks'); if (!is_logged()) { $smarty->assign('content', get_wiki_page("Инструкция по интерфейсу для снятия омонимии")); $smarty->display('qa/tasks_guest.tpl'); return; } $action = isset($_GET['act']) ? $_GET['act'] : ''; $smarty->assign('user_rating', get_user_rating($_SESSION['user_id'])); switch ($action) { case 'annot': 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; }
function get_stars($fid = -1, $href = '#', $enabled = true) { $ret_val = 'Rate:' . ($enabled ? '' : ' '); $urating = SESSION_EMPTY() ? -1 : get_user_rating($fid, SESSION()); $class = 'fa lsp-star'; $title = $enabled ? '' : 'Login to rate'; $href = $enabled ? htmlentities($href) : '#'; $ret_val .= '<div class="lsp-starrating clearfix pull-left">'; for ($i = 5; $i > 0; --$i) { if ($enabled) { $ret_val .= '<a href="' . ($href == '#' ? '#' : $href . $i) . '" class="' . ($urating == $i ? "fa lsp-star active" : $class) . '" title="' . $title . '"></a>'; } else { $ret_val .= '<a href="" class="' . $class . ' disabled"></a>'; } } $ret_val .= '</div>'; return $ret_val; }
function update_rating($file_id, $stars, $user) { // Incorrect $stars value supplied if (!isset($stars) || trim($stars) == '' || $stars < 1 || $stars > 5) { echo '<h3 class="text-danger">Invalid rating: ' . (isset($stars) ? sanitize($stars) : '(empty)') . '</h3>'; return; } // Incorrect $file_id supplied if (!is_numeric($file_id) || !isset($file_id) || $file_id < 0) { echo '<h3 class="text-danger">Invalid file_id: ' . (is_int($file_id) ? '"' . intval($file_id) . '"' : (isset($file_id) ? '"' . sanitize($file_id) . '"' : '(empty)')) . '</h3>'; return; } // Incorrect user name supplied $user_id = get_user_id($user); if ($user_id < 0) { echo '<h3 class="text-danger">Invalid user: '******'"' . sanitize($user) . '"' : '(empty)') . '</h3>'; return; } $dbh =& get_db(); if ($user_id >= 0) { $stmt = null; if (get_user_rating($file_id, $user) > 0) { $stmt = $dbh->prepare('UPDATE ratings SET stars=:stars WHERE file_id=:file_id AND user_id=:user_id'); } else { $stmt = $dbh->prepare('INSERT INTO ratings(file_id, user_id, stars) VALUES(:file_id, :user_id, :stars)'); } $stmt->bindParam(':file_id', $file_id); $stmt->bindParam(':stars', $stars); $stmt->bindParam(':user_id', $user_id); $stmt->execute(); $stmt = null; } $dbh = null; return get_user_rating($file_id, $user); }