Esempio n. 1
0
function mark_shown_user_level($user_id, $level)
{
    if (!$user_id || $level < 0) {
        throw new UnexpectedValueException();
    }
    $res = sql_pe("SELECT user_level, user_shown_level FROM users WHERE user_id=? LIMIT 1", array($user_id));
    $r = $res[0];
    if ($r['user_level'] == $r['user_shown_level'] || $level <= $r['user_shown_level'] || $level > $r['user_level']) {
        throw new Exception();
    }
    sql_pe("UPDATE users SET user_shown_level = ? WHERE user_id = ? LIMIT 1", array($level, $user_id));
}
Esempio n. 2
0
function log_timing($is_ajax = false)
{
    global $config;
    global $total_time;
    if ($total_time < $config['misc']['timing_log_threshold']) {
        return;
    }
    $user_id = 0;
    // todo use is_logged() when it doesn't depend on pending license
    if (isset($_SESSION['user_id']) && $_SESSION['user_id'] > 0) {
        $user_id = $_SESSION['user_id'];
    }
    $page = $_SERVER['REQUEST_URI'];
    sql_pe("INSERT INTO timing (user_id, page, total_time, is_ajax) VALUES (?, ?, ?, ?)", array($user_id, $page, $total_time, $is_ajax ? 1 : 0));
}
Esempio n. 3
0
function get_anaphora_by_book($book_id)
{
    $res = sql_pe("\n        SELECT token_id, group_id, ref_id, tf.tf_text as token\n        FROM anaphora a\n            JOIN tokens tf ON (a.token_id = tf.tf_id)\n            JOIN sentences USING (sent_id)\n            JOIN paragraphs USING (par_id)\n        WHERE book_id = ?\n    ", array($book_id));
    $out = array();
    foreach ($res as $r) {
        $out[$r['ref_id']] = $r;
        $out[$r['ref_id']]['group_text'] = get_group_text($r['group_id']);
        $out[$r['ref_id']]['group_tokens'] = get_group_tokens($r['group_id']);
    }
    return $out;
}
Esempio n. 4
0
 private function _get_divergence_info()
 {
     // returns array(number_of_checked_samples, divergence_rate)
     $res = sql_pe("\n            SELECT param_value FROM user_stats\n            WHERE param_id = " . STATS_ANNOTATOR_DIVERGENCE_TOTAL . "\n            AND user_id = ?\n        ", array($this->user_id));
     if (!sizeof($res)) {
         return array(0, 1);
     }
     $divergent_count = $res[0]['param_value'];
     $info = get_user_info($this->user_id);
     $diverg_rate = $info['answers_in_ready_pools'] ? $divergent_count / $info['answers_in_ready_pools'] : 1;
     return array($info['answers_in_ready_pools'], $diverg_rate);
 }
Esempio n. 5
0
function save_user_team($team_id, $new_team_name = false)
{
    check_logged();
    sql_begin();
    // create new team if necessary
    if ($new_team_name) {
        sql_pe("INSERT INTO user_teams VALUES(NULL, ?, ?)", array(trim($new_team_name), $_SESSION['user_id']));
        $team_id = sql_insert_id();
    }
    sql_pe("UPDATE users SET user_team=? WHERE user_id=? LIMIT 1", array($team_id, $_SESSION['user_id']));
    sql_commit();
    return $team_id;
}
Esempio n. 6
0
function delete_fact($fact_id)
{
    sql_begin();
    sql_pe("DELETE FROM fact_field_values WHERE fact_id = ?", array($fact_id));
    sql_pe("DELETE FROM facts WHERE fact_id = ?", array($fact_id));
    sql_commit();
}
Esempio n. 7
0
function source_add($url, $title, $parent_id)
{
    check_permission(PERM_ADDER);
    if (!$url) {
        throw new UnexpectedValueException();
    }
    sql_pe("INSERT INTO sources VALUES(NULL, ?, ?, ?, 0, 0)", array($parent_id, $url, $title));
}
Esempio n. 8
0
function get_most_useful_pools($type = 0)
{
    $res = sql_pe("\n        SELECT pool_id, pool_name, p.status, user_name,\n            COUNT(sent_id) cnt\n        FROM morph_annot_samples\n            LEFT JOIN morph_annot_pools p\n                USING (pool_id)\n            LEFT JOIN users\n                ON (p.moderator_id = users.user_id)\n            LEFT JOIN tokens tf\n                USING (tf_id)\n            RIGHT JOIN good_sentences\n                USING (sent_id)\n            LEFT JOIN tokens tf2\n                USING (sent_id)\n        WHERE p.status >= " . MA_POOLS_STATUS_ANSWERED . "\n            AND p.status <= " . MA_POOLS_STATUS_MODERATED . "\n            AND num_homonymous = 1\n            AND (p.pool_type = ?\n            " . ($type == 0 ? "OR TRUE)" : ")") . "\n        GROUP BY pool_id\n        ORDER BY COUNT(sent_id) DESC\n        LIMIT 50\n    ", array($type));
    $out = array();
    foreach ($res as $r) {
        $out[] = array('id' => $r['pool_id'], 'name' => $r['pool_name'], 'status' => $r['status'], 'moderator' => $r['user_name'], 'count' => $r['cnt']);
    }
    return $out;
}
Esempio n. 9
0
function del_dict_restriction($id)
{
    check_permission(PERM_DICT);
    sql_begin();
    sql_pe("DELETE FROM gram_restrictions WHERE restr_id=? LIMIT 1", array($id));
    calculate_gram_restrictions();
    sql_commit();
}
Esempio n. 10
0
function get_monitor_data($from, $until)
{
    $query = "\n        SELECT\n            run,\n            threshold,\n            `precision`,\n            recall,\n            F1\n        FROM\n            tokenizer_qa\n        WHERE\n            run >= ?\n            AND run <= ?\n    ";
    $qa_data = array('precision' => array(), 'recall' => array(), 'F1' => array());
    $q = sql_pe($query, array($from, $until));
    foreach ($q as $res) {
        $run_date = strtotime($res['run']) * 1000;
        $thrshld = $res['threshold'];
        $qa_data['precision'][$thrshld][] = array($run_date, (double) $res['precision']);
        $qa_data['recall'][$thrshld][] = array($run_date, (double) $res['recall']);
        $qa_data['F1'][$thrshld][] = array($run_date, (double) $res['F1']);
    }
    return $qa_data;
}
Esempio n. 11
0
function get_user_stats($weekly = false, $team = 0)
{
    if ($weekly) {
        $start_time = time() - 7 * SEC_PER_DAY;
        $counter_param = 58;
        $params = array(59, 60, 61);
    } else {
        $start_time = 0;
        $counter_param = 33;
        $params = array(STATS_ANNOTATOR_DIVERGENCE_TOTAL, 38, 39);
    }
    $annotators = array();
    // team info
    $uid2team = array();
    $res = sql_query("SELECT user_id, user_team FROM users WHERE user_team > 0");
    while ($r = sql_fetch_array($res)) {
        $uid2team[$r['user_id']] = $r['user_team'];
    }
    $teams = get_team_list();
    foreach ($teams as $i => $v) {
        if ($v['num_users'] == 0) {
            unset($teams[$i]);
            continue;
        }
        $teams[$i]['total'] = $teams[$i]['moderated'] = $teams[$i]['correct'] = $teams[$i]['active_users'] = 0;
    }
    $uid2sid = array();
    $res = sql_pe("\n        SELECT user_id, COUNT(*) AS cnt, user_rating10 AS rating\n        FROM morph_annot_instances\n        LEFT JOIN users USING(user_id)\n        WHERE answer > 0\n            AND ts_finish > ?\n            " . ($team ? "AND user_team = ?" : "") . "\n        GROUP BY user_id\n        ORDER BY " . ($weekly ? 'cnt' : 'rating') . " DESC\n    ", $team ? array($start_time, $team) : array($start_time));
    foreach ($res as $r) {
        $annotators[] = array('total' => number_format($r['cnt'], 0, '', ' '), 'user_id' => $r['user_id'], 'rating' => number_format($r['rating'], 0, '', ' '));
        $uid2sid[$r['user_id']] = sizeof($annotators) - 1;
        if (isset($uid2team[$r['user_id']])) {
            $teams[$uid2team[$r['user_id']]]['total'] += $r['cnt'];
            $teams[$uid2team[$r['user_id']]]['active_users'] += 1;
        }
    }
    uasort($teams, function ($a, $b) {
        if ($a['total'] > $b['total']) {
            return -1;
        }
        if ($a['total'] < $b['total']) {
            return 1;
        }
        return 0;
    });
    // last activity info
    $last_click = array();
    $res = sql_query("\n        SELECT user_id, MAX(timestamp) AS last_time\n        FROM morph_annot_click_log\n        WHERE timestamp > UNIX_TIMESTAMP(NOW()) - " . SEC_PER_DAY . " * " . ($weekly ? "7" : "60") . "\n        GROUP BY user_id\n    ");
    while ($r = sql_fetch_array($res)) {
        $last_click[$r['user_id']] = $r['last_time'];
    }
    // divergence and moderation info
    $divergence = array();
    $moderated = array();
    $correct = array();
    $res = sql_query("SELECT user_id, param_id, param_value FROM user_stats WHERE param_id IN (" . join(', ', $params) . ")");
    while ($r = sql_fetch_array($res)) {
        switch ($r['param_id']) {
            case STATS_ANNOTATOR_DIVERGENCE_TOTAL:
            case 59:
                $divergence[$r['user_id']] = $r['param_value'];
                break;
            case 38:
            case 60:
                $moderated[$r['user_id']] = $r['param_value'];
                if (isset($uid2team[$r['user_id']])) {
                    $teams[$uid2team[$r['user_id']]]['moderated'] += $r['param_value'];
                }
                break;
            case 39:
            case 61:
                $correct[$r['user_id']] = $r['param_value'];
                if (isset($uid2team[$r['user_id']])) {
                    $teams[$uid2team[$r['user_id']]]['correct'] += $r['param_value'];
                }
        }
    }
    foreach ($teams as $i => $v) {
        if ($v['total'] == 0) {
            unset($teams[$i]);
            continue;
        }
        if ($v['moderated']) {
            $teams[$i]['error_rate'] = get_error_rate($v['moderated'], $v['correct']);
        } else {
            $teams[$i]['error_rate'] = 0;
        }
    }
    $res = sql_query("SELECT u.user_id, u.user_shown_name AS user_name, param_value FROM user_stats s LEFT JOIN users u ON (s.user_id=u.user_id) WHERE param_id={$counter_param} ORDER BY param_value DESC");
    while ($r = sql_fetch_array($res)) {
        $t = array('user_id' => $r['user_id'], 'user_name' => $r['user_name'], 'value' => number_format($r['param_value'], 0, '', ' '), 'divergence' => $divergence[$r['user_id']] / $r['param_value'] * 100, 'last_active' => isset($last_click[$r['user_id']]) ? $last_click[$r['user_id']] : 0, 'moderated' => isset($moderated[$r['user_id']]) ? $moderated[$r['user_id']] : 0, 'error_rate' => isset($correct[$r['user_id']]) ? get_error_rate($moderated[$r['user_id']], $correct[$r['user_id']]) : 0);
        if (isset($uid2team[$r['user_id']])) {
            $t['team_id'] = $uid2team[$r['user_id']];
            $t['team_name'] = $teams[$t['team_id']]['name'];
        }
        if (isset($uid2sid[$r['user_id']])) {
            $annotators[$uid2sid[$r['user_id']]]['fin'] = $t;
        }
    }
    foreach ($annotators as $k => $v) {
        if (!isset($v['fin']['user_name'])) {
            $annotators[$k]['fin']['user_id'] = $v['user_id'];
            $annotators[$k]['fin']['user_name'] = get_user_shown_name($v['user_id']);
            $annotators[$k]['fin']['last_active'] = isset($last_click[$v['user_id']]) ? $last_click[$v['user_id']] : 0;
            $annotators[$k]['fin']['moderated'] = isset($moderated[$v['user_id']]) ? $moderated[$v['user_id']] : 0;
            $annotators[$k]['fin']['error_rate'] = isset($moderated[$v['user_id']]) ? get_error_rate($moderated[$v['user_id']], $correct[$v['user_id']]) : 0;
        }
    }
    $timestamp_yesterday = ($timestamp_today = mktime(0, 0, 0)) - SEC_PER_DAY;
    return array('annotators' => $annotators, 'teams' => $teams, 'timestamp_today' => $timestamp_today, 'timestamp_yesterday' => $timestamp_yesterday, 'added_sentences' => get_sentence_adders_stats($weekly, $team));
}
Esempio n. 12
0
<?php

require_once '../lib/header_ajax.php';
require_once '../lib/lib_dict.php';
$result['ids'] = array();
$res = sql_pe("SELECT lemma_id FROM dict_lemmata WHERE lemma_text=? AND deleted=0", array($_POST['q']));
foreach ($res as $r) {
    $result['ids'][] = $r['lemma_id'];
}
log_timing(true);
die(json_encode($result));
<?php

if (php_sapi_name() == 'cli') {
    set_include_path(get_include_path() . PATH_SEPARATOR . __DIR__ . PATH_SEPARATOR . __DIR__ . '/..');
    require_once "lib/header.php";
    require_once "lib/lib_achievements.php";
    if (date("j") != 1) {
        die("Today is not the first day of the month, finishing.\n");
    }
    print "Pinging dog achievement recalculation.. \n";
    // get all users which registered the same day as today
    $users = sql_pe("SELECT user_id FROM users\n    \tWHERE DATE(FROM_UNIXTIME(user_reg)) < DATE_SUB(DATE(NOW()), INTERVAL 15 DAY)\n    \t   ", array());
    print "Month(s) (or at least 15 days) since registration passed for " . count($users) . " user(s)\n";
    foreach ($users as $u) {
        $am = new AchievementsManager((int) $u['user_id']);
        $am->emit(EventTypes::MONTH_PASSED);
    }
    print "Achievements pinged, finishing\n";
}
Esempio n. 14
0
function delete_entity_mention_link($entity_id, $mention_id)
{
    $entity = sql_pe("SELECT * FROM ne_entities WHERE entity_id = ? LIMIT 1", array($entity_id));
    if (sizeof($entity) != 1) {
        throw new Exception("Entity not found");
    }
    $mention = sql_pe("SELECT * FROM ne_mentions WHERE mention_id = ? LIMIT 1", array($mention_id));
    if (sizeof($mention) != 1) {
        throw new Exception("Mention not found");
    }
    sql_pe("DELETE FROM ne_entities_mentions WHERE entity_id = ? AND mention_id = ?", array($entity_id, $mention_id));
}
Esempio n. 15
0
<?php

require_once '../lib/header_ajax.php';
require_once '../lib/lib_dict.php';
require_once '../lib/lib_annot.php';
require_once '../lib/lib_users.php';
if (isset($_POST['tf_id'])) {
    $res = sql_pe("SELECT tf_text FROM tokens WHERE tf_id=? LIMIT 1", array($_POST['tf_id']));
    $r = $res[0];
    $pset = new MorphParseSet(false, $r['tf_text'], false, true);
    $result['xml'] = "<tfr>";
    foreach ($pset->parses as $parse) {
        $result['xml'] .= '<v><l id="' . $parse->lemma_id . '" t="' . htmlspecialchars($parse->lemma_text) . '">';
        foreach ($parse->gramlist as $gram) {
            if (OPTION(OPT_GRAMNAMES) == 1) {
                $result['xml'] .= '<g v="' . $gram['outer'] . '" d="' . $gram['descr'] . '"/>';
            } else {
                $result['xml'] .= '<g v="' . $gram['inner'] . '" d="' . $gram['descr'] . '"/>';
            }
        }
        $result['xml'] .= '</l></v>';
    }
    $result['xml'] .= '</tfr>';
}
log_timing(true);
die(json_encode($result));
Esempio n. 16
0
function finish_book_moderation($book_id, $tagset_id)
{
    check_permission(PERM_NE_MODER);
    // create absent annotations
    $res = sql_pe("\n        SELECT par_id FROM paragraphs\n        LEFT JOIN ne_paragraphs USING (par_id)\n        WHERE book_id = ?\n        AND tagset_id = ?\n        GROUP BY par_id\n        HAVING COUNT(annot_id) = 0\n    ", array($book_id, $tagset_id));
    sql_begin();
    foreach ($res as $r) {
        start_ne_annotation($r['par_id'], $tagset_id, true);
    }
    set_ne_book_status($book_id, $tagset_id, NE_STATUS_FINISHED);
    sql_commit();
}
Esempio n. 17
0
 private function _save_found_tokens($token_sets)
 {
     sql_begin();
     foreach ($token_sets as $tset) {
         if (!$tset instanceof FoundTokens) {
             throw new Exception();
         }
         sql_pe("INSERT INTO mw_main (status, applied, mw_type) VALUES (?, ?, ?)", array(MultiWordTask::NOT_READY, MultiWordTask::NOT_APPLIED, $tset->type));
         $mw_id = sql_insert_id();
         foreach ($tset as $tf_id) {
             sql_pe("INSERT INTO mw_tokens (mw_id, tf_id) VALUES (?, ?)", array($mw_id, $tf_id));
         }
     }
     sql_commit();
 }
Esempio n. 18
0
 private function _from_token($token, $force_unknown, $force_include_init)
 {
     $this->token_text = $token;
     $cyrillic = false;
     if ($force_unknown) {
         $this->parses[] = new MorphParseUnknown($token);
     } elseif (preg_match(self::$RE_CYR_TOKEN, $token) || preg_match(self::$RE_MIXED_TOKEN, $token)) {
         $cyrillic = true;
         $res = sql_pe("\n                SELECT lemma_id, lemma_text, grammems\n                FROM form2lemma\n                WHERE form_text=?\n                ORDER BY lemma_id, grammems\n            ", array($token));
         if (sizeof($res) > 0) {
             $var = array();
             foreach ($res as $r) {
                 $var[] = $r;
             }
             if (sizeof($var) > 1) {
                 $var = self::_yo_filter($token, $var);
             }
             foreach ($var as $r) {
                 $gramlist = array();
                 if (preg_match_all('/g v="([^"]+)"/', $r['grammems'], $matches) > 0) {
                     $require_uc = false;
                     foreach ($matches[1] as $gr) {
                         $gramlist[] = array('inner' => $gr);
                         if ($gr == 'Init') {
                             $require_uc = true;
                             break;
                         }
                     }
                 }
                 if (!$require_uc || $force_include_init || preg_match('/^[А-ЯЁ]+$/u', $token)) {
                     $this->parses[] = new MorphParse($r['lemma_text'], $gramlist, $r['lemma_id']);
                 }
             }
         }
     } elseif (preg_match('/^\\p{P}+$/u', $token)) {
         $this->parses[] = new MorphParse($token, array(array('inner' => 'PNCT')));
     } elseif (preg_match('/^\\p{Nd}+[\\.,]?\\p{Nd}*$/u', $token)) {
         $this->parses[] = new MorphParse($token, array(array('inner' => 'NUMB')));
     } elseif (preg_match('/^[\\p{Latin}\\.-]+$/u', $token)) {
         $this->parses[] = new MorphParse($token, array(array('inner' => 'LATN')));
     }
     if (preg_match('/^[IVXLCMDivxlcmdХх]+$/u', $token)) {
         $this->parses[] = new MorphParse($token, array(array('inner' => 'ROMN')));
     }
     if (sizeof($this->parses) == 0) {
         if ($cyrillic) {
             $token = mb_strtolower($token, 'UTF-8');
         }
         $this->parses[] = new MorphParseUnknown($token);
     }
     foreach ($this->parses as $parse) {
         $parse->gramlist = self::_fill_gram_info($parse->gramlist);
     }
 }
Esempio n. 19
0
function create_revset($comment = '')
{
    if (!isset($_SESSION['user_id']) || !$_SESSION['user_id']) {
        throw new Exception();
    }
    $now = time();
    global $config;
    // check if there is a recent set by the same user with the same comment
    $timeout = $now - $config['misc']['changeset_timeout'];
    $res = sql_pe("\n        SELECT set_id\n        FROM rev_sets\n        WHERE user_id = ?\n        AND timestamp > ?\n        AND comment = ?\n        ORDER BY set_id DESC\n        LIMIT 1\n    ", array($_SESSION['user_id'], $timeout, $comment));
    if (sizeof($res) > 0) {
        sql_query("UPDATE rev_sets SET timestamp={$now} WHERE set_id=" . $res[0]['set_id'] . " LIMIT 1");
        return $res[0]['set_id'];
    }
    $q = "INSERT INTO `rev_sets` VALUES(NULL, ?, ?, ?)";
    sql_pe($q, array($now, $_SESSION['user_id'], $comment));
    return sql_insert_id();
}
 private function _get_count_for_last_month()
 {
     $res = sql_pe("SELECT MONTH(FROM_UNIXTIME(ts_finish)) AS month,\n                   YEAR(FROM_UNIXTIME(ts_finish)) AS year, COUNT(*) as cnt\n                FROM morph_annot_instances\n                WHERE user_id=? AND answer > 0\n                GROUP BY year, month\n                HAVING month = MONTH(NOW()) AND year = YEAR(NOW())\n                ORDER BY year, month", array($this->user_id));
     if (!empty($res)) {
         return $res[0]['cnt'];
     } else {
         return 0;
     }
 }
Esempio n. 21
0
<?php

require_once '../lib/header_ajax.php';
$res = sql_pe("SELECT DISTINCT tag_name FROM book_tags WHERE tag_name LIKE ? ORDER BY tag_name LIMIT 10", array($_GET['query'] . '%'));
$result['suggestions'] = array();
foreach ($res as $line) {
    $result['suggestions'][] = $line['tag_name'];
}
log_timing(true);
die(json_encode($result));
Esempio n. 22
0
function get_pool_manual_page($type_id)
{
    $res = sql_pe("SELECT doc_link FROM morph_annot_pool_types WHERE type_id=? LIMIT 1", array($type_id));
    return $res[0]['doc_link'];
}
        if ($regdaysago < 16) {
            continue;
        }
        $res = sql_query("\n\t        SELECT MONTH(FROM_UNIXTIME(ts_finish)) AS month,\n                   YEAR(FROM_UNIXTIME(ts_finish)) AS year\n            FROM morph_annot_instances\n            WHERE user_id={$user_id} AND answer > 0\n            GROUP BY year, month\n\t        HAVING COUNT(*) >= 50\n            AND NOT (month = MONTH(NOW()) AND year = YEAR(NOW()))\n\t        ORDER BY year, month\n\t    ");
        $level = 0;
        $progress = 0;
        while ($r = sql_fetch_array($res)) {
            $level++;
        }
        $res = sql_pe("\n                SELECT MONTH(FROM_UNIXTIME(ts_finish)) AS month,\n                   YEAR(FROM_UNIXTIME(ts_finish)) AS year, COUNT(*) as count\n                FROM morph_annot_instances\n                WHERE user_id=? AND answer > 0\n                GROUP BY year, month\n                HAVING month = MONTH(NOW()) AND year = YEAR(NOW())\n                ORDER BY year, month", array($user_id));
        $res = $res[0];
        $progress = ceil($res['count'] * 100 / 50);
        if ($progress > 100) {
            $progress = 100;
        }
        if (isset($dog_levels[$level])) {
            $dog_levels[$level]++;
        } else {
            $dog_levels[$level] = 1;
        }
        $level > 20 && ($level = 20);
        if ($level > 0) {
            $r = sql_pe("INSERT INTO user_achievements\n        \t\t(user_id, achievement_type, level, progress, seen)\n        \t\tVALUES(:user, :type, :level, :progress, 0)\n        \t\tON DUPLICATE KEY UPDATE level=VALUES(level), seen=0", array('user' => $user_id, 'type' => 'dog', 'level' => $level, 'progress' => $progress));
        }
        print "dog: {$level} month(s), level {$level}, progress {$progress}\n";
    }
    // aist
    sql_pe("insert ignore into user_achievements\n        (user_id, achievement_type, level, progress, seen)\nselect user_id, 'aist', 0, 0, 0 from users;", array());
    // fish
    sql_pe("insert ignore into user_achievements (user_id, achievement_type, level, progress, seen)\nselect user_id, 'fish', 0, 0, 0 from users where user_team > 0;", array());
}
Esempio n. 24
0
<?php

require_once '../lib/header_ajax.php';
try {
    if (!isset($_POST['sid']) || !isset($_POST['status'])) {
        throw new UnexpectedValueException();
    }
    check_permission(PERM_ADDER);
    $sid = $_POST['sid'];
    $status = $_POST['status'];
    if ($status == 0) {
        $res = sql_pe("SELECT user_id FROM sources WHERE source_id=? LIMIT 1", array($sid));
        if ($res[0]['user_id'] != $_SESSION['user_id']) {
            throw new Exception("Book is already owned");
        }
    }
    $user_id = $status > 0 ? $_SESSION['user_id'] : 0;
    sql_pe("UPDATE sources SET user_id=? WHERE source_id=? LIMIT 1", array($user_id, $sid));
} catch (Exception $e) {
    $result['error'] = 1;
}
log_timing(true);
die(json_encode($result));
Esempio n. 25
0
function revert_dict($rev_id)
{
    if (!$rev_id) {
        throw new UnexpectedValueException();
    }
    check_permission(PERM_DICT);
    $res = sql_pe("SELECT lemma_id, rev_text FROM dict_revisions WHERE rev_id=? LIMIT 1", array($rev_id));
    $lemma_id = $res[0]['lemma_id'];
    $old_rev = sql_pe("SELECT rev_text FROM dict_revisions WHERE lemma_id=? and is_last=1 LIMIT 1", array($lemma_id));
    sql_begin();
    $new_set_id = create_revset("Отмена правки, возврат к версии d{$rev_id}");
    $new_rev_id = new_dict_rev($lemma_id, $res[0]['rev_text'], $new_set_id);
    // updated forms
    $pdr = parse_dict_rev($old_rev[0]['rev_text']);
    enqueue_updated_forms(calculate_updated_forms($pdr, parse_dict_rev($res[0]['rev_text'])), $new_rev_id);
    sql_commit();
}
Esempio n. 26
0
try {
    check_permission(PERM_ADDER);
    if (!isset($_POST['sid']) || !isset($_POST['book_id'])) {
        throw new UnexpectedValueException();
    }
    $sid = $_POST['sid'];
    $book_id = $_POST['book_id'];
    sql_begin();
    //creating book if necessary
    if ($book_id == -1) {
        //find the parent id
        $res = sql_pe("SELECT book_id, url FROM sources WHERE source_id = (SELECT parent_id FROM sources WHERE source_id=? LIMIT 1) LIMIT 1", array($sid));
        if (!isset($_POST['book_name']) || !$res[0]['book_id']) {
            throw new UnexpectedValueException();
        }
        $book_id = books_add($_POST['book_name'], $res[0]['book_id']);
        $res = sql_pe("SELECT url FROM sources WHERE source_id=? LIMIT 1", array($sid));
        books_add_tag($book_id, 'url:' . $res[0]['url']);
        download_url($res[0]['url']);
    }
    //bind
    sql_pe("UPDATE sources SET book_id=? WHERE source_id=? LIMIT 1", array($book_id, $sid));
    sql_commit();
    $res = sql_pe("SELECT book_name FROM books WHERE book_id=? LIMIT 1", array($book_id));
    $result['title'] = htmlspecialchars($res[0]['book_name']);
    $result['book_id'] = $book_id;
} catch (Exception $e) {
    $result['error'] = 1;
}
log_timing(true);
die(json_encode($result));
Esempio n. 27
0
require_once '../lib/header_ajax.php';
try {
    if (!isset($_POST['type']) || !isset($_POST['id']) || !$_POST['id'] || !isset($_POST['text']) || !trim($_POST['text']) || !isset($_SESSION['user_id'])) {
        throw new UnexpectedValueException();
    }
    $id = $_POST['id'];
    $text = trim($_POST['text']);
    $reply_to = isset($_POST['reply_to']) ? $_POST['reply_to'] : 0;
    $user_id = $_SESSION['user_id'];
    $time = time();
    switch ($_POST['type']) {
        case 'sentence':
            sql_pe("INSERT INTO sentence_comments VALUES(NULL, ?, ?, ?, ?, ?)", array($reply_to, $id, $user_id, $text, $time));
            break;
        case 'source':
            sql_pe("INSERT INTO sources_comments VALUES(NULL, ?, ?, ?, ?)", array($id, $user_id, $text, $time));
            break;
        case 'morph_annot':
            sql_pe("INSERT INTO morph_annot_comments VALUES(NULL, ?, ?, ?, ?)", array($id, $user_id, $text, $time));
            break;
        default:
            throw new UnexpectedValueException();
    }
    sql_query($q);
    $result['timestamp'] = date("d.m.y, H:i", $time);
    $result['id'] = sql_insert_id();
} catch (Exception $e) {
    $result['error'] = 1;
}
log_timing(true);
die(json_encode($result));