term.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  1. <?php
  2. //查询term字典
  3. require_once "../path.php";
  4. require_once "../public/_pdo.php";
  5. require_once '../public/load_lang.php';
  6. require_once '../public/function.php';
  7. //is login
  8. if (isset($_COOKIE["username"])) {
  9. $username = $_COOKIE["username"];
  10. } else {
  11. $username = "";
  12. }
  13. if (isset($_GET["language"])) {
  14. $currLanguage = $_GET["language"];
  15. } else {
  16. if (isset($_COOKIE["language"])) {
  17. $currLanguage = $_COOKIE["language"];
  18. } else {
  19. $currLanguage = "en";
  20. }
  21. }
  22. if (isset($_GET["op"])) {
  23. $op = $_GET["op"];
  24. } else if (isset($_POST["op"])) {
  25. $op = $_POST["op"];
  26. }
  27. if (isset($_GET["word"])) {
  28. $word = mb_strtolower($_GET["word"], 'UTF-8');
  29. $org_word = $word;
  30. }
  31. if (isset($_GET["guid"])) {
  32. $_guid = $_GET["guid"];
  33. }
  34. if (isset($_GET["username"])) {
  35. $username = $_GET["username"];
  36. }
  37. global $PDO;
  38. PDO_Connect("" . _FILE_DB_TERM_);
  39. switch ($op) {
  40. case "pre": //预查询
  41. {
  42. $query = "select word,meaning from term where \"eword\" like " . $PDO->quote($word . '%') . " OR \"word\" like " . $PDO->quote($word . '%') . " group by word limit 0,10";
  43. $Fetch = PDO_FetchAll($query);
  44. if (count($Fetch) < 5) {
  45. $query = "select word,meaning from term where \"eword\" like " . $PDO->quote('%' . $word . '%') . " OR \"word\" like " . $PDO->quote('%' . $word . '%') . " group by word limit 0,10";
  46. $Fetch2 = PDO_FetchAll($query);
  47. //去掉重复的
  48. foreach ($Fetch2 as $onerow) {
  49. $found = false;
  50. foreach ($Fetch as $oldArray) {
  51. if ($onerow["word"] == $oldArray["word"]) {
  52. $found = true;
  53. break;
  54. }
  55. }
  56. if ($found == false) {
  57. array_push($Fetch, $onerow);
  58. }
  59. }
  60. if (count($Fetch) < 8) {
  61. $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";
  62. $Fetch3 = PDO_FetchAll($query);
  63. $Fetch = array_merge($Fetch, $Fetch3);
  64. if (count($Fetch) < 8) {
  65. $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";
  66. $Fetch4 = PDO_FetchAll($query);
  67. //去掉重复的
  68. foreach ($Fetch4 as $onerow) {
  69. $found = false;
  70. foreach ($Fetch as $oldArray) {
  71. if ($onerow["word"] == $oldArray["word"]) {
  72. $found = true;
  73. break;
  74. }
  75. }
  76. if ($found == false) {
  77. array_push($Fetch, $onerow);
  78. }
  79. }
  80. }
  81. }
  82. }
  83. echo json_encode($Fetch, JSON_UNESCAPED_UNICODE);
  84. break;
  85. }
  86. case "my":
  87. {
  88. $query = "select guid,word,meaning,other_meaning,language from term where owner= ? ";
  89. $Fetch = PDO_FetchAll($query, array($_COOKIE["userid"]));
  90. $iFetch = count($Fetch);
  91. if ($iFetch > 0) {
  92. echo json_encode($Fetch, JSON_UNESCAPED_UNICODE);
  93. } else {
  94. echo json_encode(array(), JSON_UNESCAPED_UNICODE);
  95. }
  96. break;
  97. }
  98. case "allpali":
  99. {
  100. $query = "select word from term where 1 group by word";
  101. $Fetch = PDO_FetchAll($query);
  102. $iFetch = count($Fetch);
  103. if ($iFetch > 0) {
  104. echo json_encode($Fetch, JSON_UNESCAPED_UNICODE);
  105. }
  106. break;
  107. }
  108. case "allmean":
  109. {
  110. $query = "select meaning from term where \"word\" = " . $PDO->quote($word) . " group by meaning";
  111. $Fetch = PDO_FetchAll($query);
  112. foreach ($Fetch as $one) {
  113. echo "<a>" . $one["meaning"] . "</a> ";
  114. }
  115. //echo json_encode($Fetch, JSON_UNESCAPED_UNICODE);
  116. break;
  117. }
  118. case "load_id":
  119. {
  120. if (isset($_GET["id"])) {
  121. $id = $_GET["id"];
  122. $query = "select * from term where \"guid\" = " . $PDO->quote($id);
  123. $Fetch = PDO_FetchAll($query);
  124. echo json_encode($Fetch, JSON_UNESCAPED_UNICODE);
  125. } else {
  126. echo json_encode(array(), JSON_UNESCAPED_UNICODE);
  127. }
  128. break;
  129. }
  130. case "search":
  131. {
  132. if (!isset($word)) {
  133. return;
  134. }
  135. if (trim($word) == "") {
  136. return;
  137. }
  138. echo "<div class='pali'>{$word}</div>";
  139. //查本人数据
  140. echo "<div></div>"; //My Term
  141. $query = "select * from term where word = ? AND owner = ? limit 0,30";
  142. $Fetch = PDO_FetchAll($query, array($word, $_COOKIE["userid"]));
  143. $iFetch = count($Fetch);
  144. if ($iFetch > 0) {
  145. for ($i = 0; $i < $iFetch; $i++) {
  146. $mean = $Fetch[$i]["meaning"];
  147. $guid = $Fetch[$i]["guid"];
  148. $dict_list[$guid] = $Fetch[$i]["owner"];
  149. echo "<div class='dict_word'>";
  150. echo "<a name='ref_dict_$guid'></a>";
  151. echo "<div id='term_dict_my_$guid'>";
  152. echo "<div class='dict'>{$_local->gui->my_term}</div>";
  153. echo "<div class='mean'><span>" . $mean . "</span>";
  154. echo "<span class='other_mean' style='margin-right: auto;'>(" . $Fetch[$i]["other_meaning"] . ")</span></div>";
  155. echo "<div class='tag'>{$Fetch[$i]["tag"]}</div>";
  156. echo "<div class='mean'>{$Fetch[$i]["channal"]}</div>";
  157. echo "<div class='mean'>{$Fetch[$i]["language"]}</div>";
  158. echo "<div class='term_note' status=0>" . $Fetch[$i]["note"] . "</div>";
  159. echo "</div>";
  160. //编辑词条表单
  161. echo "<div id='term_dict_my_edit_$guid' style='display:none'>";
  162. echo "<input type='hidden' id='term_edit_word_$guid' value='$word' />";
  163. echo "<div class='mean' style='display:flex;'><span style='flex:1;'>{$_local->gui->first_choice_word}:</span>";
  164. echo "<input type='input' style='flex:3;' placeholder='{$_local->gui->required}' id='term_edit_mean_{$guid}' value='$mean' /></div>"; //'意思'
  165. echo "<div class='mean' style='display:flex;'><span style='flex:1;'>{$_local->gui->other_meaning}:</span>";
  166. echo "<input type='input' style='flex:3;' placeholder='{$_local->gui->optional}' id='term_edit_mean2_{$guid}' value='" . $Fetch[$i]["other_meaning"] . "'/></div>"; //'备选意思(可选项)'
  167. echo "<div class='mean' style='display:flex;'><span style='flex:1;'>{$_local->gui->tag}:</span>";
  168. echo "<input type='input' style='flex:3;' placeholder='{$_local->gui->optional}' id='term_edit_tag_{$guid}' value='" . $Fetch[$i]["tag"] . "'/></div>"; //'标签'
  169. echo "<div class='mean' style='display:flex;'><span style='flex:1;'>{$_local->gui->channel}:</span>";
  170. echo "<input type='input' style='flex:3;' placeholder='{$_local->gui->optional}' id='term_edit_channal_{$guid}' value='" . $Fetch[$i]["channal"] . "'/></div>"; //'版风'
  171. echo "<div class='mean' style='display:flex;'><span style='flex:1;'>{$_local->gui->language}:</span>";
  172. echo "<input type='input' style='flex:3;' placeholder='{$_local->gui->optional}' id='term_edit_language_{$guid}' value='" . $Fetch[$i]["language"] . "'/></div>"; //'语言'
  173. echo "<div class='note'><span style='display:flex;'><span>{$_local->gui->encyclopedia} & {$_local->gui->note}:</span>";
  174. echo "<guide gid='term_pedia_sys' style='margin-left: auto;'></guide></span>";
  175. echo "<textarea width='100%' height='3em' placeholder='{$_local->gui->optional}' id='term_edit_note_$guid'>" . $Fetch[$i]["note"] . "</textarea></div>"; //'注解'
  176. echo "</div>";
  177. echo "<div id='term_edit_btn1_$guid'>";
  178. //echo "<button onclick=\"term_apply('$guid')\">{$_local->gui->apply}</button>";//Apply
  179. echo "<button onclick=\"term_edit('$guid')\">{$_local->gui->edit}</button>"; //Edit
  180. echo "</div>";
  181. echo "<div id='term_edit_btn2_{$guid}' style='display:none'>";
  182. echo "<button onclick=\"term_data_esc_edit('$guid')\">{$_local->gui->cancel}</button>"; //Cancel
  183. echo "<button onclick=\"term_data_save('$guid')\">{$_local->gui->save}</button>"; //保存
  184. echo "</div>";
  185. echo "</div>";
  186. }
  187. }
  188. //新建词条
  189. echo "<div class='dict_word'>";
  190. echo "<button id='new_term_button' onclick=\"term_show_new()\">{$_local->gui->new}</button>";
  191. echo "<div id='term_new_recorder' style='display:none;'>";
  192. echo "<div class='dict'>" . $_local->gui->new_technic_term . "</div>"; //New Techinc Term
  193. echo "<div class='mean' style='display:flex;'><span style='flex:1;'>{$_local->gui->pali_word}:</span>";
  194. echo "<input type='input' style='flex:3;' placeholder='{$_local->gui->required}' id='term_new_word' value='{$word}' /></div>"; //'拼写'
  195. echo "<div class='mean' style='display:flex;'><span style='flex:1;'>{$_local->gui->first_choice_word}:</span>";
  196. echo "<input type='input' style='flex:3;' placeholder='{$_local->gui->required}' id='term_new_mean'/></div>"; //'意思'
  197. echo "<div class='mean' style='display:flex;'><span style='flex:1;'>{$_local->gui->other_meaning}:</span>";
  198. echo "<input type='input' style='flex:3;' placeholder='{$_local->gui->optional}' id='term_new_mean2'/></div>"; //'备选意思(可选项)'
  199. echo "<div class='mean' style='display:flex;'><span style='flex:1;'>{$_local->gui->tag}:</span>";
  200. echo "<input type='input' style='flex:3;' placeholder='{$_local->gui->optional}' id='term_new_tag'/></div>"; //'标签'
  201. echo "<div class='mean' style='display:flex;'><span style='flex:1;'>{$_local->gui->channel}:</span>";
  202. echo "<input type='input' style='flex:3;' placeholder='{$_local->gui->optional}' id='term_new_channal'/></div>"; //'标签'
  203. echo "<div class='mean' style='display:flex;'><span style='flex:1;'>{$_local->gui->language}:</span>";
  204. echo "<input type='input' style='flex:3;' placeholder='{$_local->gui->optional}' id='term_new_language'/></div>"; //'标签'
  205. echo "<div class='note'><span style='display:flex;'><span>{$_local->gui->encyclopedia} & {$_local->gui->note}:</span>";
  206. echo "<guide gid='term_pedia_sys' style='margin-left: auto;'></guide></span>";
  207. echo "<textarea width='100%' height='3em' placeholder='{$_local->gui->optional}' id='term_new_note'></textarea></div>"; //'注解'
  208. echo "<button onclick=\"term_data_save('')\">{$_local->gui->save}</button>"; //保存
  209. echo "</div>";
  210. echo "</div>";
  211. //查他人数据
  212. $query = "SELECT * FROM term WHERE word = ? AND owner <> ? LIMIT 0,30";
  213. $Fetch = PDO_FetchAll($query, array($word, $_COOKIE["userid"]));
  214. $iFetch = count($Fetch);
  215. if ($iFetch > 0) {
  216. for ($i = 0; $i < $iFetch; $i++) {
  217. $mean = $Fetch[$i]["meaning"];
  218. $guid = $Fetch[$i]["guid"];
  219. $dict_list[$guid] = $Fetch[$i]["owner"];
  220. echo "<div class='dict_word'>";
  221. echo "<a name='ref_dict_$guid'></a>";
  222. echo "<div class='dict'>" . $Fetch[$i]["owner"] . "</div>";
  223. echo "<div class='mean'>" . $mean . "</div>";
  224. echo "<div class='other_mean'>" . $Fetch[$i]["other_meaning"] . "</div>";
  225. echo "<div class='term_note'>" . $Fetch[$i]["note"] . "</div>";
  226. echo "<button onclick=\"term_data_copy_to_me($guid)\">{$_local->gui->copy}</button>"; //复制
  227. echo "</div>";
  228. }
  229. }
  230. echo "<div id='dictlist'>";
  231. echo "</div>";
  232. break;
  233. }
  234. case "copy": //拷贝到我的字典
  235. {
  236. $query = "select * from term where \"guid\" = " . $PDO->quote($_GET["wordid"]);
  237. $Fetch = PDO_FetchAll($query);
  238. $iFetch = count($Fetch);
  239. if ($iFetch > 0) {
  240. /* 开始一个事务,关闭自动提交 */
  241. $PDO->beginTransaction();
  242. $query = "INSERT INTO term ('id','guid','word','word_en','meaning','other_meaning','note','tag','create_time','owner','hit') VALUES (null,?,?,?,?,?,?,?," . time() . ",'$username',1)";
  243. $stmt = $PDO->prepare($query);
  244. {
  245. $stmt->execute(array(UUID::v4,
  246. $Fetch[0]["word"],
  247. $Fetch[0]["word_en"],
  248. $Fetch[0]["meaning"],
  249. $Fetch[0]["other_meaning"],
  250. $Fetch[0]["note"],
  251. $Fetch[0]["tag"],
  252. ));
  253. }
  254. /* 提交更改 */
  255. $PDO->commit();
  256. if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
  257. $error = PDO_ErrorInfo();
  258. echo "error - $error[2] <br>";
  259. } else {
  260. echo "updata ok.";
  261. }
  262. }
  263. break;
  264. }
  265. case "extract":
  266. {
  267. if (isset($_POST["words"])) {
  268. $words = $_POST["words"];
  269. }
  270. if (isset($_POST["authors"])) {
  271. $authors = str_getcsv($_POST["authors"]);
  272. }
  273. $queryLang = $currLanguage . "%";
  274. $query = "SELECT * from term where \"word\" in {$words} AND language like ? limit 0,1000";
  275. $Fetch = PDO_FetchAll($query, array($queryLang));
  276. $iFetch = count($Fetch);
  277. echo json_encode($Fetch, JSON_UNESCAPED_UNICODE);
  278. break;
  279. }
  280. case "sync":
  281. {
  282. $time = $_GET["time"];
  283. $query = "SELECT guid,modify_time from term where receive_time>'{$time}' limit 0,1000";
  284. $Fetch = PDO_FetchAll($query);
  285. $iFetch = count($Fetch);
  286. echo json_encode($Fetch, JSON_UNESCAPED_UNICODE);
  287. break;
  288. }
  289. case "get":
  290. {
  291. $Fetch = array();
  292. if (isset($guid)) {
  293. $query = "select * from term where \"guid\" = '{$guid}'";
  294. } else if (isset($word)) {
  295. $query = "select * from term where \"word\" = '{$word}'";
  296. } else {
  297. echo "[]";
  298. return;
  299. }
  300. $Fetch = PDO_FetchAll($query);
  301. $iFetch = count($Fetch);
  302. echo json_encode($Fetch, JSON_UNESCAPED_UNICODE);
  303. break;
  304. }
  305. }