Пример #1
0
 /**
  * 针对指定配置执行sql
  * @param unknown_type $module
  * @param unknown_type $sql
  */
 protected function sql_clean($module, $sql)
 {
     $conf = get_conf($module);
     $ipaddr = $conf["mysql"]["ipaddr"];
     $db = $conf["mysql"]["db"];
     $user = $conf["mysql"]["user"];
     $pwd = $conf["mysql"]["pwd"];
     sql_execute($ipaddr, $db, $user, $pwd, $sql);
 }
Пример #2
0
 public function get_user_options($user_id)
 {
     if (!$user_id) {
         throw new UnexpectedValueException();
     }
     $out = array();
     $res = sql_query("SELECT option_id id, option_value value FROM user_options_values WHERE user_id={$user_id}");
     while ($r = sql_fetch_array($res)) {
         $out[$r['id']] = $r['value'];
     }
     //autovivify absent options
     sql_begin();
     $ins = sql_prepare("INSERT INTO user_options_values VALUES(?, ?, ?)");
     foreach ($this->options as $opt) {
         if (!in_array($opt->id, array_keys($out))) {
             $out[$opt->id] = $opt->default_value;
             sql_execute($ins, array($user_id, $opt->id, $opt->default_value));
         }
     }
     sql_commit();
     return $out;
 }
Пример #3
0
function merge_sentences($id1, $id2)
{
    check_permission(PERM_ADDER);
    if ($id1 < 1 || $id2 < 1) {
        throw new UnexpectedValueException();
    }
    // check same paragraph and adjacency
    $res = sql_pe("SELECT pos, par_id FROM sentences WHERE sent_id IN (?, ?) ORDER BY pos LIMIT 2", array($id1, $id2));
    $r1 = $res[0];
    $r2 = $res[1];
    $res = sql_query("SELECT pos FROM sentences WHERE par_id = " . $r1['par_id'] . " AND pos > " . $r1['pos'] . " AND pos < " . $r2['pos'] . " LIMIT 1");
    if ($r1['par_id'] != $r2['par_id'] || sql_num_rows($res) > 0) {
        throw new Exception();
    }
    //moving tokens
    sql_begin();
    $res = sql_pe("SELECT MAX(pos) AS maxpos FROM tokens WHERE sent_id=?", array($id1));
    sql_pe("UPDATE tokens SET sent_id=?, pos=pos+? WHERE sent_id=?", array($id1, $res[0]['maxpos'], $id2));
    //merging source text
    $res_src = sql_prepare("SELECT `source` FROM sentences WHERE sent_id=? LIMIT 1");
    sql_execute($res_src, array($id1));
    $r1 = sql_fetchall($res_src);
    sql_execute($res_src, array($id2));
    $r2 = sql_fetchall($res_src);
    sql_pe("UPDATE sentences SET source=? WHERE sent_id=? LIMIT 1", array($r1[0]['source'] . ' ' . $r2[0]['source'], $id1));
    //dropping status, moving comments
    sql_pe("UPDATE sentences SET check_status=0 WHERE sent_id=? LIMIT 1", array($id1));
    sql_pe("UPDATE sentence_comments SET sent_id=? WHERE sent_id=?", array($id1, $id2));
    sql_pe("DELETE FROM sentence_check WHERE sent_id=? OR sent_id=?", array($id1, $id2));
    // change syntax markup accordingly
    sql_pe("UPDATE syntax_parses SET sent_id = ? WHERE sent_id = ?", array($id1, $id2));
    //deleting sentence
    sql_pe("DELETE FROM sentence_authors WHERE sent_id=? LIMIT 1", array($id2));
    sql_pe("DELETE FROM sentences WHERE sent_id=? LIMIT 1", array($id2));
    sql_commit();
}
Пример #4
0
function get_context_for_word($tf_id, $delta, $dir = 0, $include_self = 1)
{
    // dir stands for direction (-1 => left, 1 => right, 0 => both)
    // delta <= 0 stands for infinity
    $t = array();
    $tw = 0;
    $left_c = -1;
    //if there is left context to be added
    $right_c = 0;
    //same for right context
    $mw_pos = 0;
    static $query1 = NULL;
    // prepare the 1st query
    if ($query1 == NULL) {
        $query1 = sql_prepare("\n            SELECT MAX(tokens.pos) AS maxpos, MIN(tokens.pos) AS minpos, sent_id, source, book_id\n            FROM tokens\n                JOIN sentences USING (sent_id)\n                JOIN paragraphs USING (par_id)\n            WHERE sent_id = (\n                SELECT sent_id\n                FROM tokens\n                WHERE tf_id=? LIMIT 1\n            )\n        ");
    }
    sql_execute($query1, array($tf_id));
    $res = sql_fetchall($query1);
    $r = $res[0];
    $sent_id = $r['sent_id'];
    $sentence_text = $r['source'];
    $book_id = $r['book_id'];
    $maxpos = $r['maxpos'];
    $minpos = $r['minpos'];
    // prepare the 2nd query
    // this is really bad unreadable code, sorry
    static $query2 = NULL;
    if ($query2 == NULL) {
        $q = "SELECT tf_id, tf_text, pos FROM tokens WHERE sent_id = ?";
        if ($dir != 0 || $delta > 0) {
            $q_left = $dir <= 0 ? $delta > 0 ? "(SELECT IF(pos > {$delta}, pos - {$delta}, 0) FROM tokens WHERE tf_id=? LIMIT 1)" : "0" : "(SELECT pos FROM tokens WHERE tf_id=? LIMIT 1)";
            $q_right = $dir >= 0 ? $delta > 0 ? "(SELECT pos+{$delta} FROM tokens WHERE tf_id=? LIMIT 1)" : "1000" : "(SELECT pos FROM tokens WHERE tf_id=? LIMIT 1)";
            $q .= " AND pos BETWEEN {$q_left} AND {$q_right}";
        }
        $q .= " ORDER BY pos";
        $query2 = sql_prepare($q);
    }
    // how many values should we provide?
    $bound = array($tf_id, $tf_id);
    if ($delta <= 0) {
        if ($dir == 0) {
            $bound = array();
        } else {
            $bound = array($tf_id);
        }
    }
    sql_execute($query2, array_merge(array($sent_id), $bound));
    foreach (sql_fetchall($query2) as $r) {
        if ($delta > 0) {
            if ($left_c == -1) {
                $left_c = $r['pos'] == $minpos ? 0 : $r['tf_id'];
            }
            if ($mw_pos) {
                if ($r['pos'] > $mw_pos) {
                    $right_c = $r['tf_id'];
                }
                if ($right_c && $r['pos'] == $maxpos) {
                    $right_c = 0;
                }
            }
        }
        if ($include_self || $r['tf_id'] != $tf_id) {
            $t[$r['tf_id']] = $r['tf_text'];
        }
        if ($include_self && $r['tf_id'] == $tf_id) {
            $mw_pos = $r['pos'];
        }
    }
    return array('context' => $t, 'mainword' => $tf_id, 'has_left_context' => $left_c, 'has_right_context' => $right_c, 'sentence_id' => $sent_id, 'sentence_text' => $sentence_text, 'book_id' => $book_id);
}
Пример #5
0
        foreach ($changes as $source => $dest) {
            // Voir si la colonne contient la chaine recherch�e
            if (sql_first("SELECT * FROM `" . $table . "` WHERE `" . $column . "` LIKE '%" . $source . "%'")) {
                // Faire la modification complexe pour les lignes JSON
                $json = sql_all("SELECT * FROM `" . $table . "` WHERE `" . $column . "` LIKE 'a:%'");
                foreach ($json as $line) {
                    $source_j = $line->{$column};
                    $j = unserialize($line->{$column});
                    if ($j) {
                        $j = recursive_array_replace($source, $dest, $j);
                        $j = serialize($j);
                        sql_pexecute("UPDATE `" . $table . "` SET `" . $column . "`=? WHERE `" . $column . "`=?", array($j, $source_j));
                    }
                }
                // Faire ensuite la modification pour les autres lignes.
                sql_execute("UPDATE `" . $table . "` SET `" . $column . "` = replace(`" . $column . "`, '" . $source . "', '" . $dest . "') WHERE `" . $column . "` NOT LIKE 'a:%' AND `" . $column . "` LIKE '%" . $source . "%'");
            }
        }
    }
}
function recursive_array_replace($find, $replace, $data)
{
    if (is_array($data)) {
        foreach ($data as $key => $value) {
            if (is_array($value) || is_object($value)) {
                $data[$key] = recursive_array_replace($find, $replace, $value);
            } else {
                $data[$key] = str_replace($find, $replace, $value);
            }
        }
    } else {
Пример #6
0
                 }
                 $area['areaname'] = $areaname;
                 $do->add($area);
             }
         }
         $do->repair();
         dmsg('添加成功', $this_forward);
     } else {
         include tpl('area_add');
     }
     break;
 case 'import':
     $file = DT_ROOT . '/file/setting/area.sql';
     is_file($file) or msg('数据文件不存在,请上传程序包内 file/setting/area.sql 文件至 file/setting 目录');
     require DT_ROOT . '/include/sql.func.php';
     sql_execute(file_get($file));
     cache_area();
     dmsg('导入成功', $this_forward);
     break;
 case 'cache':
     $do->repair();
     dmsg('更新成功', $this_forward);
     break;
 case 'delete':
     if ($areaid) {
         $areaids = $areaid;
     }
     $areaids or msg();
     $do->delete($areaids);
     dmsg('删除成功', $this_forward);
     break;
Пример #7
0
function save_user_options($post)
{
    if (!isset($post['options'])) {
        throw new UnexpectedValueException();
    }
    check_logged();
    sql_begin();
    $upd = sql_prepare("UPDATE user_options_values SET option_value=? WHERE option_id=? AND user_id=? LIMIT 1");
    foreach ($post['options'] as $id => $value) {
        if ($_SESSION['options'][$id]['value'] != $value) {
            sql_execute($upd, array($value, $id, $_SESSION['user_id']));
            $_SESSION['options'][$id] = $value;
        }
    }
    sql_commit();
}
Пример #8
0
         echo json_encode($arr);
         exit;
     }
 }
 if ($i == 999999) {
     exit;
 }
 $sqldata = file_get_contents(SITEDIR . 'Install/yourphp_data.sql');
 sql_execute($sqldata, $dbPrefix);
 $sqldata = file_get_contents(SITEDIR . 'Install/yourphp_area.sql');
 sql_execute($sqldata, $dbPrefix);
 $indexcode = file_get_contents(SITEDIR . 'index.php');
 $indexcode = str_replace('if(!is_file(\'./config.php\'))header("location: ./Install");', '', $indexcode);
 if ($_POST['lang']) {
     $langsql = file_get_contents(SITEDIR . 'Install/yourphp_lang.sql');
     sql_execute($langsql, $dbPrefix);
     $indexcode = str_replace('define(\'APP_LANG\',false);', 'define(\'APP_LANG\',true);', $indexcode);
     $indexcode = @file_put_contents(SITEDIR . 'index.php', $indexcode);
 } else {
     $indexcode = str_replace('define(\'APP_LANG\',true);', 'define(\'APP_LANG\',false);', $indexcode);
     $indexcode = @file_put_contents(SITEDIR . 'index.php', $indexcode);
     mysql_query("UPDATE `{$dbPrefix}menu` SET  `status` ='0'   WHERE model='Lang' ");
 }
 mysql_query("UPDATE `{$dbPrefix}config` SET  `value` = '{$site_name}' WHERE varname='site_name' and lang=1");
 mysql_query("UPDATE `{$dbPrefix}config` SET  `value` = '{$site_url}' WHERE varname='site_url' ");
 mysql_query("UPDATE `{$dbPrefix}config` SET  `value` = '{$site_email}' WHERE varname='site_email'");
 mysql_query("UPDATE `{$dbPrefix}config` SET  `value` = '{$seo_description}' WHERE varname='seo_description'  and lang=1");
 mysql_query("UPDATE `{$dbPrefix}config` SET  `value` = '{$seo_keywords}' WHERE varname='seo_keywords'  and lang=1");
 //读取配置文件,并替换真实配置数据
 $strConfig = file_get_contents(SITEDIR . 'Install/' . $configFile);
 $strConfig = str_replace('#DB_HOST#', $dbHost, $strConfig);
Пример #9
0
             } else {
                 header("location:./recovery.php?anyid={$anyid}&pre={$pre}&dosubmit=1&lang={$lang}");
             }
         }
     }
 } else {
     if ($dosubmit) {
         $fileid = $fileid ? $fileid : 1;
         $filename = $pre . $fileid . '.sql';
         $filepath = '../../databack/' . $filename;
         if (file_exists($filepath)) {
             $sql = file_get_contents($filepath);
             if (substr($sql, 28, 5) != $metcms_v && substr($sql, 28, 6) != $metcms_v) {
                 metsave($rurls, $lang_dataerr1, $depth);
             }
             sql_execute($sql, 0, $dosubmit1);
             $fileid++;
             save_met_cookie();
             metsave($rurls . "&pre=" . $pre . "&fileid=" . $fileid . "&dosubmit=1&adminmodify=1&database_met=1", "{$lang_setdbDBFile} {$filename} {$lang_setdbImportOK}{$lang_setdbImportcen}", $depth, '', '', 1);
         } else {
             require_once '../../column/global.func.php';
             $query = "select * from {$met_column} where ((module<=5 and module>0) or (module=8)) and (classtype=1 or releclass!=0)";
             $result = $db->get_all($query);
             sitemap_robots();
             $sysflie = array(1 => 'about', 2 => 'news', 3 => 'product', 4 => 'download', 5 => 'img', 6 => 'job', 7 => 'message', 8 => 'feedback');
             foreach ($result as $key => $val) {
                 if (array_search($val[foldername], $sysflie) === false) {
                     if (!file_exists(ROOTPATH . $val['foldername'])) {
                         @mkdir(ROOTPATH . $val['foldername'], 0777);
                     }
                     column_copyconfig($val['foldername'], $val['module'], $val['id']);
Пример #10
0
 define('DT_KEY', $CFG['authkey']);
 define('DT_CHARSET', $CFG['charset']);
 define('DT_SKIN', DT_PATH . 'skin/' . $CFG['skin'] . '/');
 define('SKIN_PATH', DT_PATH . 'skin/' . $CFG['skin'] . '/');
 define('VIP', $CFG['com_vip']);
 define('DT_DOMAIN', $CFG['cookie_domain'] ? substr($CFG['cookie_domain'], 1) : '');
 define('errmsg', 'Invalid Request');
 //创建数据
 require DT_ROOT . '/include/db_mysql.class.php';
 require DT_ROOT . '/include/sql.func.php';
 require DT_ROOT . '/admin/global.func.php';
 $db = new db_mysql();
 $db->connect($db_host, $db_user, $db_pass, $db_name, $CFG['db_expires'], $CFG['db_charset'], $CFG['pconnect']);
 $db->pre = $DT_PRE;
 sql_execute(file_get_contents(IN_ROOT . '/table.sql'));
 sql_execute(file_get_contents(IN_ROOT . '/data.sql'));
 //Setting
 $DT = array();
 for ($i = 1; $i <= 22; $i++) {
     $setting = (include DT_ROOT . '/file/setting/module-' . $i . '.php');
     if ($setting) {
         if ($i == 1) {
             $DT = $setting;
         }
         unset($setting['moduleid'], $setting['name'], $setting['moduledir'], $setting['ismenu'], $setting['domain'], $setting['linkurl']);
         if ($i == 3) {
             foreach ($setting as $k => $v) {
                 $setting[$k] = str_replace('http://demo.destoon.com/v' . DT_VERSION . '/', $CFG['url'], $v);
             }
         }
         update_setting($i, $setting);
Пример #11
0
function find_ne_entity($annot_id, $e_id, $e_start_token, $e_length)
{
    static $res = NULL;
    if ($res == NULL) {
        $res = sql_prepare("\n            SELECT entity_id\n            FROM ne_entities\n            WHERE annot_id = ?\n            AND start_token = ?\n            AND length = ?\n        ");
    }
    sql_execute($res, array($annot_id, $e_start_token, $e_length));
    $rows = sql_fetchall($res);
    if (sizeof($rows) == 0) {
        return false;
    }
    // check tags
    $found_id = $rows[0]['entity_id'];
    $tags1 = get_ne_entity_tags($e_id, true);
    $tags2 = get_ne_entity_tags($found_id, true);
    if ($tags1 == $tags2) {
        return $found_id;
    }
    return false;
}
Пример #12
0
function enqueue_updated_forms($forms, $revision_id)
{
    $ins = sql_prepare("INSERT INTO `updated_forms` VALUES (?, ?)");
    foreach (array_unique($forms) as $upd_form) {
        sql_execute($ins, array($upd_form, $revision_id));
    }
}
Пример #13
0
function addtext_add($text, $sentences, $book_id, $par_num)
{
    check_permission(PERM_ADDER);
    if (!$text || !$book_id || !$par_num) {
        throw new UnexpectedValueException();
    }
    if (sizeof(sql_pe("SELECT book_id FROM books WHERE parent_id=?", array($book_id))) > 0) {
        throw new UnexpectedValueException("Can't add paragraphs to a text having subtexts");
    }
    sql_begin();
    $revset_id = create_revset();
    $sent_count = 0;
    $pars = split2paragraphs($text);
    // move the following paragraphs
    sql_query("UPDATE paragraphs SET pos=pos+" . sizeof($pars) . " WHERE book_id = {$book_id} AND pos >= {$par_num}");
    $par_ins = sql_prepare("INSERT INTO `paragraphs` VALUES(NULL, ?, ?)");
    $sent_ins = sql_prepare("INSERT INTO `sentences` VALUES(NULL, ?, ?, ?, 0)");
    $token_ins = sql_prepare("INSERT INTO `tokens` VALUES(NULL, ?, ?, ?)");
    foreach ($pars as $par) {
        //adding a paragraph
        sql_execute($par_ins, array($book_id, $par_num++));
        $par_id = sql_insert_id();
        $sent_num = 1;
        $sents = split2sentences($par);
        foreach ($sents as $sent) {
            if (!preg_match('/\\S/', $sent)) {
                continue;
            }
            //adding a sentence
            sql_execute($sent_ins, array($par_id, $sent_num++, trim($sent)));
            $sent_id = sql_insert_id();
            sql_query("INSERT INTO sentence_authors VALUES({$sent_id}, " . $_SESSION['user_id'] . ", " . time() . ")");
            $token_num = 1;
            $tokens = explode('^^', $sentences[$sent_count++]);
            foreach ($tokens as $token) {
                if (trim($token) === '') {
                    continue;
                }
                //adding a textform
                sql_execute($token_ins, array($sent_id, $token_num++, trim($token)));
                $tf_id = sql_insert_id();
                //adding a revision
                $parse = new MorphParseSet(false, trim($token));
                create_tf_revision($revset_id, $tf_id, $parse->to_xml());
            }
        }
    }
    sql_commit();
}
Пример #14
0
function get_ambiguity_stats_for_chart()
{
    $chart = array();
    $t = array();
    $tchart = array();
    $time = time();
    $param_set = array(5, 35, 36, 37, 41, 45, 62, 64);
    $res = sql_prepare("SELECT timestamp, param_value FROM stats_values WHERE timestamp > ? AND param_id = ? ORDER BY timestamp");
    foreach ($param_set as $param_id) {
        sql_execute($res, array($time - 90 * SEC_PER_DAY, $param_id));
        while ($r = sql_fetch_array($res)) {
            $day = intval($r['timestamp'] / SEC_PER_DAY);
            $t[$day][$param_id] = $r['param_value'];
        }
    }
    ksort($t);
    foreach ($t as $day => $ar) {
        $tchart['disamb_sentences'][] = '[' . $day * MSEC_PER_DAY . ',' . $ar[41] . ']';
        $tchart['disamb_sentences_strict'][] = '[' . $day * MSEC_PER_DAY . ',' . $ar[62] . ']';
        if ($ar[45]) {
            $tchart['disamb_sent_length'][] = '[' . $day * MSEC_PER_DAY . ',' . sprintf("%.3f", $ar[45] / $ar[41]) . ']';
        }
        if ($ar[64]) {
            $tchart['disamb_sent_strict_length'][] = '[' . $day * MSEC_PER_DAY . ',' . sprintf("%.3f", $ar[64] / $ar[62]) . ']';
        }
        if ($ar[35] == 0) {
            continue;
        }
        $tchart['avg_parses'][] = '[' . $day * MSEC_PER_DAY . ',' . sprintf("%.3f", $ar[35] / $ar[5]) . ']';
        $tchart['non_ambig'][] = '[' . $day * MSEC_PER_DAY . ',' . sprintf("%.3f", $ar[37] / $ar[5] * 100) . ']';
        $tchart['unknown'][] = '[' . $day * MSEC_PER_DAY . ',' . sprintf("%.3f", $ar[36] / $ar[5] * 100) . ']';
        $tchart['total_words'][] = '[' . $day * MSEC_PER_DAY . ',' . $ar[5] . ']';
    }
    foreach ($tchart as $name => $ar) {
        $chart[$name] = join(',', $ar);
    }
    return $chart;
}
Пример #15
0
function sql_pe($query, $params)
{
    // prepares and executes query, closes cursor
    // returns all the rows
    $res = sql_prepare($query);
    sql_execute($res, $params);
    try {
        return sql_fetchall($res);
    } catch (PDOException $e) {
        return array();
    }
}
Пример #16
0
 /**
  * 数据库恢复
  * @param unknown_type $filename
  */
 private function import_database($filename)
 {
     $cache_path = FCPATH . 'caches' . DIRECTORY_SEPARATOR;
     $pdo_name = $this->db->database;
     $this->load->library('ifile_lib');
     if ($filename && $this->ifile_lib->get_file_ext($filename) == 'sql') {
         $filepath = $cache_path . 'bakup' . DIRECTORY_SEPARATOR . $pdo_name . DIRECTORY_SEPARATOR . $filename;
         if (!file_exists($filepath)) {
             $this->showmessage('error', '对不起' . " {$filepath} " . '数据库文件不存在', HTTP_REFERER);
         }
         $sql = file_get_contents($filepath);
         sql_execute($sql);
         $this->showmessage('success', "{$filename} " . '中的数据已经成功导入到数据库', HTTP_REFERER);
     } else {
         $fileid = $this->input->get('fileid');
         $fileid = intval($fileid) ? intval($fileid) : 1;
         $pre = $filename;
         $filename = $filename . $fileid . '.sql';
         $filepath = $cache_path . 'bakup' . DIRECTORY_SEPARATOR . $pdo_name . DIRECTORY_SEPARATOR . $filename;
         if (file_exists($filepath)) {
             $sql = file_get_contents($filepath);
             $this->sql_execute($sql);
             $fileid++;
             $this->showmessage('success', '数据文件' . $filename . '上传成功', $this->admin_url . 'maintenance/dbsave/import?pre=' . $pre . '&fileid=' . $fileid . '&loghash=' . $this->session->userdata('loghash') . '&dosubmit=1');
         } else {
             $this->showmessage('success', '数据库恢复成功!', $this->admin_url . 'maintenance/dbsave/import?loghash=' . $this->session->userdata('loghash'));
         }
     }
 }
Пример #17
0
function revert_changeset($set_id, $comment)
{
    if (!$set_id) {
        throw new UnexpectedValueException();
    }
    check_permission(PERM_DICT);
    sql_begin();
    $new_set_id = create_revset($comment);
    $dict_flag = 0;
    $res = sql_pe("SELECT tf_id FROM tf_revisions WHERE set_id=?", array($set_id));
    $res_revtext = sql_prepare("SELECT rev_text FROM tf_revisions WHERE tf_id=? AND set_id<? ORDER BY rev_id DESC LIMIT 1");
    foreach ($res as $r) {
        sql_execute($res_revtext, array($r[0], $set_id));
        $arr = sql_fetch_array($res_revtext);
        create_tf_revision($new_set_id, $r[0], $arr[0]);
    }
    $res_revtext->closeCursor();
    $res = sql_pe("SELECT lemma_id FROM dict_revisions WHERE set_id=?", array($set_id));
    $res_revtext = sql_prepare("SELECT rev_text FROM dict_revisions WHERE lemma_id=? AND set_id<? ORDER BY rev_id DESC LIMIT 1");
    foreach ($res as $r) {
        sql_execute($res_revtext, array($r[0], $set_id));
        $arr = sql_fetch_array($res_revtext);
        new_dict_rev($r[0], $arr[0], $new_set_id);
        $dict_flag = 1;
    }
    $res_revtext->closeCursor();
    sql_commit();
    if ($dict_flag) {
        return 'dict_history.php';
    }
    return 'history.php';
}
Пример #18
0
function update_annot_instance($id, $answer, $user_id = 0)
{
    if (!$user_id) {
        $user_id = $_SESSION['user_id'];
    }
    if (!$id || !$answer || !$user_id) {
        throw new UnexpectedValueException();
    }
    global $config;
    static $res = NULL;
    if ($res == NULL) {
        $res = sql_prepare("\n            SELECT pool_id, p.status, i.user_id, answer\n            FROM morph_annot_instances i\n            LEFT JOIN morph_annot_samples\n                USING (sample_id)\n            LEFT JOIN morph_annot_pools p\n                USING (pool_id)\n            WHERE instance_id = ?\n            LIMIT 1\n        ");
    }
    sql_execute($res, array($id));
    $inst = sql_fetchall($res);
    if (!sizeof($inst)) {
        throw new Exception("Instance not found");
    }
    $r = $inst[0];
    // the pool should be editable
    if ($r['status'] != MA_POOLS_STATUS_IN_PROGRESS) {
        throw new Exception("Пул недоступен для разметки");
    }
    $pool_id = $r['pool_id'];
    sql_begin();
    static $res_rejected = NULL;
    // does the instance really belong to this user?
    $previous_answer = $r['answer'] > 0;
    if ($r['user_id'] != $user_id) {
        // if another user has taken it, no chance
        if ($r['user_id'] > 0) {
            throw new Exception();
        }
        // or, perhaps, this user has rejected it before but has changed his mind
        if ($res_rejected == NULL) {
            $res_rejected = sql_prepare("SELECT sample_id FROM morph_annot_rejected_samples WHERE user_id=? AND sample_id = (SELECT sample_id FROM morph_annot_instances WHERE instance_id=? LIMIT 1) LIMIT 1");
        }
        sql_execute($res_rejected, array($user_id, $id));
        if (sql_num_rows($res_rejected) > 0) {
            $r = sql_fetch_array($res_rejected);
            sql_pe("DELETE FROM morph_annot_rejected_samples WHERE user_id=? AND sample_id=? LIMIT 1", array($user_id, $r['sample_id']));
            sql_pe("UPDATE morph_annot_instances SET user_id=?, ts_finish=? WHERE instance_id=? LIMIT 1", array($user_id, time() + $config['misc']['morph_annot_timeout'], $id));
        }
    }
    // a valid answer
    static $update = NULL;
    if ($update == NULL) {
        $update = sql_prepare("UPDATE morph_annot_instances SET user_id=?, answer=? WHERE instance_id=? LIMIT 1");
    }
    if ($answer > 0) {
        sql_execute($update, array($user_id, $answer, $id));
    } elseif ($answer == -1) {
        reject_annot_instance($id, $user_id);
    }
    sql_commit();
}
Пример #19
0
 public function model_add()
 {
     $module_config = '';
     if (file_exists(COREFRAME_ROOT . 'app/' . $this->m . '/fields/config.php')) {
         $module_config = (include COREFRAME_ROOT . 'app/' . $this->m . '/fields/config.php');
     }
     $master_table = isset($module_config['master_table']) ? $module_config['master_table'] : $this->m . '_share';
     $share_model = isset($GLOBALS['share_model']) && $GLOBALS['share_model'] ? intval($GLOBALS['share_model']) : 0;
     if (isset($GLOBALS['submit'])) {
         if (empty($GLOBALS['tablename'])) {
             MSG(L('database table name is empty'));
         }
         if ($share_model) {
             $GLOBALS['att'] = 2;
         }
         $formdata = '';
         $formdata['master_table'] = $share_model ? $master_table : $GLOBALS['tablename'];
         $formdata['m'] = $this->m;
         $formdata['name'] = $GLOBALS['name'];
         $formdata['css'] = input('css');
         $formdata['attr_table'] = intval($GLOBALS['att']) === 2 ? $GLOBALS['tablename'] . '_data' : '';
         $formdata['share_model'] = isset($GLOBALS['share_model']) ? intval($GLOBALS['share_model']) : 0;
         $formdata['template'] = $GLOBALS['template'];
         $formdata['remark'] = $GLOBALS['remark'];
         //检查表是否存在,若存在则不允许创建
         $tables = array();
         $query = $this->db->query("SHOW TABLES");
         while ($r = $this->db->fetch_array($query)) {
             $tables[] = $r['Tables_in_' . $this->db->dbname];
         }
         //先创建表,然后执行下面的操作
         $basic_tablename = $this->db->tablepre . $GLOBALS['tablename'];
         $att_tablename = $this->db->tablepre . $formdata['attr_table'];
         $table_model_field = $this->db->tablepre . 'model_field';
         if ($share_model) {
             //获取共享表结构
             if (in_array($att_tablename, $tables)) {
                 MSG(L('database table exists'));
             }
             $sqldata = file_get_contents($this->m_path . 'db_share.sql');
         } elseif ($formdata['attr_table']) {
             //选择了创建2个表
             if (in_array($basic_tablename, $tables) || in_array($att_tablename, $tables)) {
                 MSG(L('database table exists'));
             }
             $sqldata = file_get_contents($this->m_path . 'db2.sql');
         } else {
             //创建独立单表
             if (in_array($basic_tablename, $tables)) {
                 MSG(L('database table exists'));
             }
             $sqldata = file_get_contents($this->m_path . 'db1.sql');
         }
         $sqldata = str_replace('$basic_tablename', $basic_tablename, $sqldata);
         $sqldata = str_replace('$att_tablename', $att_tablename, $sqldata);
         $sqldata = str_replace('$table_model_field', $table_model_field, $sqldata);
         load_function('sql');
         if (sql_execute($this->db, $sqldata)) {
             $modelid = $this->db->insert('model', $formdata);
             $this->db->update('model_field', array('modelid' => $modelid), array('modelid' => 0));
             $forward = isset($GLOBALS['forward']) ? $GLOBALS['forward'] : HTTP_REFERER;
             MSG(L('add success'), $forward);
         } else {
             MSG(L('add table faild'));
         }
     } else {
         load_class('form');
         load_function('template');
         include $this->template('model_add');
     }
 }
Пример #20
0
            if ($str1 != '#' && $str1 != '-') {
                $ret[$num] .= $query;
            }
        }
        $num++;
    }
    if (is_array($ret)) {
        foreach ($ret as $sql) {
            if (trim($sql) != '') {
                $db->query($sql);
            }
        }
    } else {
        $db->query($ret);
    }
    return true;
}
$vers = explode('.', VERSION);
$packdir = WWW_ROOT . 'upgrade/' . $vers[0] . '.' . $vers[1] . '/' . $vers[2];
$sqlfile = $packdir . '/sql.sql';
$upgradefile = $packdir . '/upgrade.php';
if (file_exists($sqlfile)) {
    $sql = file_get_contents($sqlfile);
    sql_execute($sql);
    unlink($sqlfile);
}
if (file_exists($upgradefile)) {
    include $upgradefile;
    unlink($upgradefile);
}
echo '升级成功';
Пример #21
0
function import_sql($id)
{
    global $dbcharset;
    $db = (include WWW_ROOT . 'configs/mysql_config.php');
    $db = $db['default'];
    $link = mysql_connect($db['dbhost'], $db['username'], $db['password']) or die('Not connected : ' . mysql_error());
    $version = mysql_get_server_info();
    mysql_query("SET NAMES '{$dbcharset}'", $link);
    if ($version > '5.0') {
        mysql_query("SET sql_mode=''");
    }
    mysql_select_db($db['dbname']);
    if (file_exists(WWW_ROOT . "install/sql/install-{$id}.sql")) {
        $sql = file_get_contents(WWW_ROOT . "install/sql/install-{$id}.sql");
        sql_execute($link, $sql, $db['tablepre']);
    }
}
Пример #22
0
$lastName = @clean_data_field($_POST["lastname"]);
$organizationName = @clean_data_field($_POST["organization"]);
$organizationType = @clean_data_field($_POST["orgtype"]);
$other = @clean_data_field($_POST["other"]);
$sec = strtolower(to_str($_POST["security_code"]));
$check = strtolower(to_str($_SESSION['security_code']));
if ($check != $sec) {
    unset($_SESSION['security_code']);
    header("Location: connect.html?captcha=false&email=" . urlencode($email) . "&firstname=" . urlencode($firstName) . "&lastname=" . urlencode($lastName) . "&organization=" . urlencode($organizationName) . "&orgtype=" . urlencode($organizationType) . "&other=" . $other);
    exit;
}
unset($_SESSION['security_code']);
$stmt = "insert into healthivibe.mailinglist ( email, firstName, lastName, organizationName, organizationType ) ";
$stmt = $stmt . "values ( " . get_sql_string($email) . ", " . get_sql_string($firstName) . ", " . get_sql_string($lastName) . ", ";
$stmt = $stmt . get_sql_string($organizationName) . ", " . get_sql_string($organizationType) . " )";
echo $stmt;
@sql_execute($stmt);
$host = "localhost";
$port = 25;
$from = "*****@*****.**";
$fromName = "HealthiVibe";
$to = "*****@*****.**";
$subject = "New account creation for user " . $email;
$message = "A new account has been created for " . $email . ", details: <br/><br/>";
$message = $message . "First name: " . $firstName . "<br/>";
$message = $message . "Last name: " . $lastName . "<br/>";
$message = $message . "Email: " . $email . "<br/>";
$message = $message . "Organization: " . $organizationName . "<br/>";
$message = $message . "Type: " . $organizationType . "<br/><br/>";
@send_mail($from, $fromName, $to, $subject, $message);
header("Location: connect-complete.html");
Пример #23
0
function get_unknowns()
{
    $res = sql_query("\n        SELECT tf_id, tf_text, sent_id, ut.dict_revision\n        FROM tokens t\n        LEFT JOIN form2lemma f\n            ON (t.tf_text = f.form_text)\n        LEFT JOIN tf_revisions\n            USING (tf_id)\n        LEFT JOIN updated_tokens ut\n            ON (t.tf_id = ut.token_id)\n        WHERE is_last = 1\n        AND rev_text LIKE '%UNKN%'\n        AND f.lemma_id IS NOT NULL\n        GROUP BY tf_id\n        ORDER BY tf_id\n    ");
    $res1 = sql_prepare("\n        SELECT text, user_shown_name\n        FROM morph_annot_comments\n        LEFT JOIN morph_annot_samples\n            USING (sample_id)\n        LEFT JOIN users\n            USING (user_id)\n        WHERE tf_id = ?\n    ");
    $out = array();
    while ($r = sql_fetch_array($res)) {
        sql_execute($res1, array($r['tf_id']));
        $comments = array();
        while ($r1 = sql_fetch_array($res1)) {
            $comments[] = array('text' => $r1['text'], 'author' => $r1['user_shown_name']);
        }
        $out[] = array('sent_id' => $r['sent_id'], 'text' => $r['tf_text'], 'is_pending' => (bool) $r['dict_revision'], 'comments' => $comments);
    }
    return $out;
}
Пример #24
0
 /**
  * 数据库恢复
  * @param unknown_type $filename
  */
 private function import_database($filename)
 {
     if ($filename && fileext($filename) == 'sql') {
         $filepath = CACHE_PATH . 'bakup' . DIRECTORY_SEPARATOR . $this->pdo_name . DIRECTORY_SEPARATOR . $filename;
         if (!file_exists($filepath)) {
             showmessage(L('database_sorry') . " {$filepath} " . L('database_not_exist'));
         }
         $sql = file_get_contents($filepath);
         sql_execute($sql);
         showmessage("{$filename} " . L('data_have_load_to_database'));
     } else {
         $fileid = $this->fileid ? $this->fileid : 1;
         $pre = $filename;
         $filename = $filename . $fileid . '.sql';
         $filepath = CACHE_PATH . 'bakup' . DIRECTORY_SEPARATOR . $this->pdo_name . DIRECTORY_SEPARATOR . $filename;
         if (file_exists($filepath)) {
             $sql = file_get_contents($filepath);
             $this->sql_execute($sql);
             $fileid++;
             showmessage(L('bakup_data_file') . " {$filename} " . L('load_success'), "?m=admin&c=database&a=import&pdoname=" . $this->pdo_name . "&pre=" . $pre . "&fileid=" . $fileid . "&dosubmit=1");
         } else {
             showmessage(L('data_recover_succ'), '?m=admin&c=database&a=import');
         }
     }
 }
Пример #25
0
function set_ne_tags($entity_id, $tags, $annot_id = 0)
{
    // overwrites old set of tags
    // TODO check that tags and annotation belong to the same tagset
    if (!$annot_id) {
        $res = sql_pe("SELECT annot_id FROM ne_entities WHERE entity_id = ?", array($entity_id));
        $annot_id = $res[0]['annot_id'];
    }
    if (!check_ne_paragraph_status($annot_id, $_SESSION['user_id'])) {
        throw new Exception();
    }
    sql_begin();
    sql_pe("DELETE FROM ne_entity_tags WHERE entity_id = ?", array($entity_id));
    $res = sql_prepare("INSERT INTO ne_entity_tags VALUES(?, ?)");
    foreach ($tags as $tag) {
        sql_execute($res, array($entity_id, $tag));
    }
    sql_commit();
}