quote($word . '%') . " OR \"word\" like " . $PDO->quote($word . '%') . " group by word limit 0,10";
$Fetch = PDO_FetchAll($query);
if (count($Fetch) < 3) {
$query = "SELECT word,meaning from "._TABLE_TERM_." where \"word_en\" like " . $PDO->quote('%' . $word . '%') . " OR \"word\" like " . $PDO->quote('%' . $word . '%') . " group by word limit 0,10";
$Fetch2 = PDO_FetchAll($query);
//去掉重复的
foreach ($Fetch2 as $onerow) {
$found = false;
foreach ($Fetch as $oldArray) {
if ($onerow["word"] == $oldArray["word"]) {
$found = true;
break;
}
}
if ($found == false) {
array_push($Fetch, $onerow);
}
}
if (count($Fetch) < 8) {
$query = "SELECT word,meaning from "._TABLE_TERM_." where \"meaning\" like " . $PDO->quote($word . '%') . " OR \"other_meaning\" like " . $PDO->quote($word . '%') . " group by word limit 0,10";
$Fetch3 = PDO_FetchAll($query);
$Fetch = array_merge($Fetch, $Fetch3);
if (count($Fetch) < 8) {
$query = "SELECT word,meaning from "._TABLE_TERM_." where \"meaning\" like " . $PDO->quote('%' . $word . '%') . " OR \"other_meaning\" like " . $PDO->quote('%' . $word . '%') . " group by word limit 0,10";
$Fetch4 = PDO_FetchAll($query);
//去掉重复的
foreach ($Fetch4 as $onerow) {
$found = false;
foreach ($Fetch as $oldArray) {
if ($onerow["word"] == $oldArray["word"]) {
$found = true;
break;
}
}
if ($found == false) {
array_push($Fetch, $onerow);
}
}
}
}
}
echo json_encode($Fetch, JSON_UNESCAPED_UNICODE);
break;
}
case "my":
{
$query = "select guid,word,meaning,other_meaning,language from "._TABLE_TERM_." where owner= ? ";
$Fetch = PDO_FetchAll($query, array($_COOKIE["userid"]));
$iFetch = count($Fetch);
if ($iFetch > 0) {
echo json_encode($Fetch, JSON_UNESCAPED_UNICODE);
} else {
echo json_encode(array(), JSON_UNESCAPED_UNICODE);
}
break;
}
case "allpali":
{
$query = "select word from "._TABLE_TERM_." group by word";
$Fetch = PDO_FetchAll($query);
$iFetch = count($Fetch);
if ($iFetch > 0) {
echo json_encode($Fetch, JSON_UNESCAPED_UNICODE);
}
break;
}
case "allmean":
{
$query = "select meaning from "._TABLE_TERM_." where \"word\" = " . $PDO->quote($word) . " group by meaning";
$Fetch = PDO_FetchAll($query);
foreach ($Fetch as $one) {
echo "" . $one["meaning"] . " ";
}
//echo json_encode($Fetch, JSON_UNESCAPED_UNICODE);
break;
}
case "load_id":
{
if (isset($_GET["id"])) {
$id = $_GET["id"];
$query = "select * from "._TABLE_TERM_." where \"guid\" = " . $PDO->quote($id);
$Fetch = PDO_FetchAll($query);
echo json_encode($Fetch, JSON_UNESCAPED_UNICODE);
} else {
echo json_encode(array(), JSON_UNESCAPED_UNICODE);
}
break;
}
case "search":
{
if (!isset($word)) {
return;
}
if (trim($word) == "") {
return;
}
echo "
{$word}
";
//查本人数据
echo ""; //My Term
$query = "select * from "._TABLE_TERM_." where word = ? AND owner = ? limit 30";
$Fetch = PDO_FetchAll($query, array($word, $_COOKIE["userid"]));
$iFetch = count($Fetch);
if ($iFetch > 0) {
for ($i = 0; $i < $iFetch; $i++) {
$mean = $Fetch[$i]["meaning"];
$guid = $Fetch[$i]["guid"];
$dict_list[$guid] = $Fetch[$i]["owner"];
echo "";
echo "
";
echo "
";
echo "
{$_local->gui->my_term}
";
echo "
" . $mean . "";
echo "(" . $Fetch[$i]["other_meaning"] . ")
";
echo "
{$Fetch[$i]["tag"]}
";
echo "
{$Fetch[$i]["channal"]}
";
echo "
{$Fetch[$i]["language"]}
";
echo "
" . $Fetch[$i]["note"] . "
";
echo "
";
//编辑词条表单
echo "
";
echo "
";
//echo "";//Apply
echo ""; //Edit
echo "
";
echo "
";
echo ""; //Cancel
echo ""; //保存
echo "
";
echo "
";
}
}
//新建词条
echo "";
echo "
";
echo "
";
echo "
" . $_local->gui->new_technic_term . "
"; //New Techinc Term
echo "
{$_local->gui->pali_word}:";
echo "
"; //'拼写'
echo "
{$_local->gui->first_choice_word}:";
echo "
"; //'意思'
echo "
{$_local->gui->other_meaning}:";
echo "
"; //'备选意思(可选项)'
echo "
{$_local->gui->tag}:";
echo "
"; //'标签'
echo "
{$_local->gui->channel}:";
echo "
"; //'标签'
echo "
{$_local->gui->language}:";
echo "
"; //'标签'
echo "
{$_local->gui->encyclopedia} & {$_local->gui->note}:";
echo "";
echo "
"; //'注解'
echo "
"; //保存
echo "
";
echo "
";
//查他人数据
$query = "SELECT * FROM "._TABLE_TERM_." WHERE word = ? AND owner <> ? LIMIT 30";
$Fetch = PDO_FetchAll($query, array($word, $_COOKIE["userid"]));
$iFetch = count($Fetch);
if ($iFetch > 0) {
for ($i = 0; $i < $iFetch; $i++) {
$mean = $Fetch[$i]["meaning"];
$guid = $Fetch[$i]["guid"];
$dict_list[$guid] = $Fetch[$i]["owner"];
echo "";
echo "
";
echo "
" . $Fetch[$i]["owner"] . "
";
echo "
" . $mean . "
";
echo "
" . $Fetch[$i]["other_meaning"] . "
";
echo "
" . $Fetch[$i]["note"] . "
";
echo "
"; //复制
echo "
";
}
}
echo "";
echo "
";
break;
}
case "copy": //拷贝到我的字典
{
$query = "select * from "._TABLE_TERM_." where \"guid\" = " . $PDO->quote($_GET["wordid"]);
$Fetch = PDO_FetchAll($query);
$iFetch = count($Fetch);
if ($iFetch > 0) {
/* 开始一个事务,关闭自动提交 */
$PDO->beginTransaction();
$query = "INSERT INTO "._TABLE_TERM_."
(
'id',
'guid',
'word',
'word_en',
'meaning',
'other_meaning',
'note',
'tag',
'owner',
'editor_id',
'create_time',
'update_time',
) VALUES (?,?,?,?,?,?,?,?,?,?,?,?)";
$stmt = $PDO->prepare($query);
{
$stmt->execute(array(
$snowflake->id(),
UUID::v4,
$Fetch[0]["word"],
$Fetch[0]["word_en"],
$Fetch[0]["meaning"],
$Fetch[0]["other_meaning"],
$Fetch[0]["note"],
$Fetch[0]["tag"],
$_COOKIE['user_uid'],
$_COOKIE['user_id'],
mTime(),
mTime()
));
}
/* 提交更改 */
$PDO->commit();
if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
$error = PDO_ErrorInfo();
echo "error - $error[2]
";
} else {
echo "updata ok.";
}
}
break;
}
case "extract":
{
if (isset($_POST["words"])) {
$words = $_POST["words"];
}
if (isset($_POST["authors"])) {
$authors = str_getcsv($_POST["authors"]);
}
$queryLang = $currLanguage . "%";
$query = "SELECT * from "._TABLE_TERM_." where \"word\" in {$words} AND language like ? limit 1000";
$Fetch = PDO_FetchAll($query, array($queryLang));
$iFetch = count($Fetch);
echo json_encode($Fetch, JSON_UNESCAPED_UNICODE);
break;
}
case "sync":
{
$time = $_GET["time"];
$query = "SELECT guid,modify_time from "._TABLE_TERM_." where receive_time>'{$time}' limit 1000";
$Fetch = PDO_FetchAll($query);
$iFetch = count($Fetch);
echo json_encode($Fetch, JSON_UNESCAPED_UNICODE);
break;
}
case "get":
{
$Fetch = array();
if (isset($guid)) {
$query = "select * from "._TABLE_TERM_." where \"guid\" = '{$guid}'";
} else if (isset($word)) {
$query = "select * from "._TABLE_TERM_." where \"word\" = '{$word}'";
} else {
echo "[]";
return;
}
$Fetch = PDO_FetchAll($query);
$iFetch = count($Fetch);
echo json_encode($Fetch, JSON_UNESCAPED_UNICODE);
break;
}
}