quote($word . '%') . " OR \"word\" like " . $PDO->quote($word . '%') . " group by word limit 0,10";
$Fetch = PDO_FetchAll($query);
if (count($Fetch) < 5) {
$query = "select word,meaning from term where \"eword\" 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 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 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 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 term where 1 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 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 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 term where word = ? AND owner = ? limit 0,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 term WHERE word = ? AND owner <> ? LIMIT 0,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 "save":
{
$currTime = sprintf("%d", microtime(true) * 1000);
if (isset($_POST["modify_time"])) {
$mTime = $_POST["modify_time"];
} else {
$mTime = mTime();
}
if ($_POST["guid"] != "") {
$query = "UPDATE term SET meaning= ? ,other_meaning = ? , tag= ? ,channal = ? , language = ? , note = ? , receive_time= ?, modify_time= ? where guid= ? ";
$stmt = @PDO_Execute($query, array($_POST["mean"],
$_POST["mean2"],
$_POST["tag"],
$_POST["channal"],
$_POST["language"],
$_POST["note"],
mTime(),
$mTime,
$_POST["guid"],
));
} else {
$parm = array();
$parm[] = UUID::v4();
$parm[] = $_POST["word"];
$parm[] = pali2english($_POST["word"]);
$parm[] = $_POST["mean"];
$parm[] = $_POST["mean2"];
$parm[] = $_POST["tag"];
$parm[] = $_POST["channal"];
$parm[] = $_POST["language"];
$parm[] = $_POST["note"];
$parm[] = $_COOKIE["userid"];
$parm[] = 0;
$parm[] = mTime();
$parm[] = mTime();
$parm[] = mTime();
$query = "INSERT INTO term (id, guid, word, word_en, meaning, other_meaning, tag, channal, language,note,owner,hit,create_time,modify_time,receive_time )
VALUES (NULL, ? , ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) ";
$stmt = @PDO_Execute($query, $parm);
}
$respond = array("status" => 0, "message" => "");
if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
$error = PDO_ErrorInfo();
$respond['status'] = 1;
$respond['message'] = $error[2] . $query;
} else {
$respond['status'] = 0;
$respond['message'] = $_POST["word"];
}
echo json_encode($respond, JSON_UNESCAPED_UNICODE);
break;
}
case "copy": //拷贝到我的字典
{
$query = "select * from term where \"guid\" = " . $PDO->quote($_GET["wordid"]);
$Fetch = PDO_FetchAll($query);
$iFetch = count($Fetch);
if ($iFetch > 0) {
/* 开始一个事务,关闭自动提交 */
$PDO->beginTransaction();
$query = "INSERT INTO term ('id','guid','word','word_en','meaning','other_meaning','note','tag','create_time','owner','hit') VALUES (null,?,?,?,?,?,?,?," . time() . ",'$username',1)";
$stmt = $PDO->prepare($query);
{
$stmt->execute(array(UUID::v4,
$Fetch[0]["word"],
$Fetch[0]["word_en"],
$Fetch[0]["meaning"],
$Fetch[0]["other_meaning"],
$Fetch[0]["note"],
$Fetch[0]["tag"],
));
}
/* 提交更改 */
$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 term where \"word\" in {$words} AND language like ? limit 0,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 term where receive_time>'{$time}' limit 0,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 term where \"guid\" = '{$guid}'";
} else if (isset($word)) {
$query = "select * from term where \"word\" = '{$word}'";
} else {
echo "[]";
return;
}
$Fetch = PDO_FetchAll($query);
$iFetch = count($Fetch);
echo json_encode($Fetch, JSON_UNESCAPED_UNICODE);
break;
}
}