term.php 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387
  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 "save":
  235. {
  236. $currTime = sprintf("%d", microtime(true) * 1000);
  237. if (isset($_POST["modify_time"])) {
  238. $mTime = $_POST["modify_time"];
  239. } else {
  240. $mTime = mTime();
  241. }
  242. if ($_POST["guid"] != "") {
  243. $query = "UPDATE term SET meaning= ? ,other_meaning = ? , tag= ? ,channal = ? , language = ? , note = ? , receive_time= ?, modify_time= ? where guid= ? ";
  244. $stmt = @PDO_Execute($query, array($_POST["mean"],
  245. $_POST["mean2"],
  246. $_POST["tag"],
  247. $_POST["channal"],
  248. $_POST["language"],
  249. $_POST["note"],
  250. mTime(),
  251. $mTime,
  252. $_POST["guid"],
  253. ));
  254. } else {
  255. $parm = array();
  256. $parm[] = UUID::v4();
  257. $parm[] = $_POST["word"];
  258. $parm[] = pali2english($_POST["word"]);
  259. $parm[] = $_POST["mean"];
  260. $parm[] = $_POST["mean2"];
  261. $parm[] = $_POST["tag"];
  262. $parm[] = $_POST["channal"];
  263. $parm[] = $_POST["language"];
  264. $parm[] = $_POST["note"];
  265. $parm[] = $_COOKIE["userid"];
  266. $parm[] = 0;
  267. $parm[] = mTime();
  268. $parm[] = mTime();
  269. $parm[] = mTime();
  270. $query = "INSERT INTO term (id, guid, word, word_en, meaning, other_meaning, tag, channal, language,note,owner,hit,create_time,modify_time,receive_time )
  271. VALUES (NULL, ? , ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) ";
  272. $stmt = @PDO_Execute($query, $parm);
  273. }
  274. $respond = array("status" => 0, "message" => "");
  275. if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
  276. $error = PDO_ErrorInfo();
  277. $respond['status'] = 1;
  278. $respond['message'] = $error[2] . $query;
  279. } else {
  280. $respond['status'] = 0;
  281. $respond['message'] = $_POST["word"];
  282. }
  283. echo json_encode($respond, JSON_UNESCAPED_UNICODE);
  284. break;
  285. }
  286. case "copy": //拷贝到我的字典
  287. {
  288. $query = "select * from term where \"guid\" = " . $PDO->quote($_GET["wordid"]);
  289. $Fetch = PDO_FetchAll($query);
  290. $iFetch = count($Fetch);
  291. if ($iFetch > 0) {
  292. /* 开始一个事务,关闭自动提交 */
  293. $PDO->beginTransaction();
  294. $query = "INSERT INTO term ('id','guid','word','word_en','meaning','other_meaning','note','tag','create_time','owner','hit') VALUES (null,?,?,?,?,?,?,?," . time() . ",'$username',1)";
  295. $stmt = $PDO->prepare($query);
  296. {
  297. $stmt->execute(array(UUID::v4,
  298. $Fetch[0]["word"],
  299. $Fetch[0]["word_en"],
  300. $Fetch[0]["meaning"],
  301. $Fetch[0]["other_meaning"],
  302. $Fetch[0]["note"],
  303. $Fetch[0]["tag"],
  304. ));
  305. }
  306. /* 提交更改 */
  307. $PDO->commit();
  308. if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
  309. $error = PDO_ErrorInfo();
  310. echo "error - $error[2] <br>";
  311. } else {
  312. echo "updata ok.";
  313. }
  314. }
  315. break;
  316. }
  317. case "extract":
  318. {
  319. if (isset($_POST["words"])) {
  320. $words = $_POST["words"];
  321. }
  322. if (isset($_POST["authors"])) {
  323. $authors = str_getcsv($_POST["authors"]);
  324. }
  325. $queryLang = $currLanguage . "%";
  326. $query = "SELECT * from term where \"word\" in {$words} AND language like ? limit 0,1000";
  327. $Fetch = PDO_FetchAll($query, array($queryLang));
  328. $iFetch = count($Fetch);
  329. echo json_encode($Fetch, JSON_UNESCAPED_UNICODE);
  330. break;
  331. }
  332. case "sync":
  333. {
  334. $time = $_GET["time"];
  335. $query = "SELECT guid,modify_time from term where receive_time>'{$time}' limit 0,1000";
  336. $Fetch = PDO_FetchAll($query);
  337. $iFetch = count($Fetch);
  338. echo json_encode($Fetch, JSON_UNESCAPED_UNICODE);
  339. break;
  340. }
  341. case "get":
  342. {
  343. $Fetch = array();
  344. if (isset($guid)) {
  345. $query = "select * from term where \"guid\" = '{$guid}'";
  346. } else if (isset($word)) {
  347. $query = "select * from term where \"word\" = '{$word}'";
  348. } else {
  349. echo "[]";
  350. return;
  351. }
  352. $Fetch = PDO_FetchAll($query);
  353. $iFetch = count($Fetch);
  354. echo json_encode($Fetch, JSON_UNESCAPED_UNICODE);
  355. break;
  356. }
  357. }