term.php 16 KB

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