term-.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  1. <?php
  2. //查询term字典
  3. require_once "../path.php";
  4. require_once "../public/_pdo.php";
  5. require_once "./public.inc";
  6. require_once "../public/load_lang.php";
  7. $username = "";
  8. if (isset($_COOKIE["username"]) && !empty($_COOKIE["username"])) {
  9. $username = $_COOKIE["username"];
  10. }
  11. $op = $_GET["op"];
  12. if (isset($_GET["word"])) {
  13. if (empty($_GET["word"])) {
  14. return;
  15. }
  16. $word = mb_strtolower($_GET["word"], 'UTF-8');
  17. $org_word = $word;
  18. }
  19. if (isset($_GET["list"])) {
  20. $list = $_GET["list"];
  21. }
  22. $count_return = 0;
  23. $dict_list = array();
  24. global $PDO;
  25. PDO_Connect("" . _FILE_DB_TERM_);
  26. switch ($op) {
  27. case "pre": //预查询
  28. echo "<wordlist>";
  29. $query = "select word,count from dict where \"eword\" like " . $PDO->quote($word . '%') . " OR \"word\" like " . $PDO->quote($word . '%') . " limit 0,100";
  30. $Fetch = PDO_FetchAll($query);
  31. $iFetch = count($Fetch);
  32. if ($iFetch > 0) {
  33. for ($i = 0; $i < $iFetch; $i++) {
  34. $outXml = "<word>";
  35. $word = $Fetch[$i]["word"];
  36. $outXml = $outXml . "<pali>$word</pali>";
  37. $outXml = $outXml . "<count>" . $Fetch[$i]["count"] . "</count>";
  38. $outXml = $outXml . "</word>";
  39. echo $outXml;
  40. }
  41. }
  42. echo "</wordlist>";
  43. break;
  44. case "my":
  45. $query = "select guid,word,meaning,other_meaning from term where owner= " . $PDO->quote($username);
  46. $Fetch = PDO_FetchAll($query);
  47. $iFetch = count($Fetch);
  48. if ($iFetch > 0) {
  49. echo json_encode($Fetch, JSON_UNESCAPED_UNICODE);
  50. }
  51. break;
  52. case "allpali":
  53. $query = "select word from term where 1 group by word";
  54. $Fetch = PDO_FetchAll($query);
  55. $iFetch = count($Fetch);
  56. if ($iFetch > 0) {
  57. echo json_encode($Fetch, JSON_UNESCAPED_UNICODE);
  58. }
  59. break;
  60. case "allmean":
  61. $query = "select meaning from term where \"word\" = " . $PDO->quote($word) . " group by meaning";
  62. $Fetch = PDO_FetchAll($query);
  63. foreach ($Fetch as $one) {
  64. echo "<a>" . $one["meaning"] . "</a> ";
  65. }
  66. //echo json_encode($Fetch, JSON_UNESCAPED_UNICODE);
  67. break;
  68. case "load_id":
  69. if (isset($_GET["id"])) {
  70. $id = $_GET["id"];
  71. $query = "select * from term where \"guid\" = " . $PDO->quote($id);
  72. $Fetch = PDO_FetchAll($query);
  73. echo json_encode($Fetch, JSON_UNESCAPED_UNICODE);
  74. } else {
  75. echo "{}";
  76. }
  77. break;
  78. case "search":
  79. //查本人数据
  80. echo "<div>" . $module_gui_str['editor']['1122'] . "</div>"; //My Term
  81. $query = "select * from term where \"word\" = " . $PDO->quote($word) . " AND \"owner\"= " . $PDO->quote($username) . " limit 0,30";
  82. $Fetch = PDO_FetchAll($query);
  83. $iFetch = count($Fetch);
  84. $count_return += $iFetch;
  85. if ($iFetch > 0) {
  86. for ($i = 0; $i < $iFetch; $i++) {
  87. $mean = $Fetch[$i]["meaning"];
  88. $guid = $Fetch[$i]["guid"];
  89. $dict_list[$guid] = $Fetch[$i]["owner"];
  90. echo "<div class='dict_word'>";
  91. echo "<a name='ref_dict_$guid'></a>";
  92. echo "<div class='dict'>$word</div>";
  93. echo "<div id='term_dict_my_$guid'>";
  94. echo "<div class='mean'>" . $mean . "</div>";
  95. echo "<div class='other_mean'>" . $Fetch[$i]["other_meaning"] . "</div>";
  96. echo "<div class='term_note' status=0>" . $Fetch[$i]["note"] . "</div>";
  97. echo "</div>";
  98. //编辑词条表单
  99. echo "<div id='term_dict_my_edit_$guid' style='display:none'>";
  100. echo "<input type='hidden' id='term_edit_word_$guid' value='$word' />";
  101. echo "<div class='mean'><input type='input' id='term_edit_mean_$guid' placeholder='" . $_local->gui->g_mean . "'value='$mean' /></div>"; //'意思'
  102. echo "<div class='other_mean'><input type='input' id='term_edit_mean2_$guid' placeholder=" . $_local->gui->other_meaning . " value='" . $Fetch[$i]["other_meaning"] . "' /></div>"; //'备选意思(可选项)'
  103. echo "<div class='note'><textarea id='term_edit_note_$guid' placeholder='" . $_local->gui->note . "'>" . $Fetch[$i]["note"] . "</textarea></div>"; //'注解'
  104. echo "</div>";
  105. echo "<div id='term_edit_btn1_$guid'>";
  106. echo "<button onclick=\"term_apply('$guid')\">" . $_local->gui->apply . "</button>"; //Apply
  107. echo "<button onclick=\"term_edit('$guid')\">" . $_local->gui->edit . "</button>"; //Edit
  108. echo "</div>";
  109. echo "<div id='term_edit_btn2_$guid' style='display:none'>";
  110. echo "<button onclick=\"term_data_esc_edit('$guid')\">" . $_local->gui->cancel . "</button>"; //Cancel
  111. echo "<button onclick=\"term_data_save('$guid')\">" . $_local->gui->cancel . "</button>"; //保存
  112. echo "</div>";
  113. echo "</div>";
  114. }
  115. }
  116. //新建词条
  117. echo "<div class='dict_word'>";
  118. echo "<div class='dict'>" . $_local->gui->new_technic_term . "</div>"; //New Techinc Term
  119. echo "<div class='mean'>";
  120. echo "<span>" . $_local->gui->spell . ":</span>";
  121. echo "<input type='input' placeholder=" . $_local->gui->spell . " id='term_new_word' value='{$word}' />";
  122. echo "</div>"; //'拼写'
  123. echo "<div class='mean'>";
  124. echo "<span>" . $_local->gui->g_mean . ":</span>";
  125. echo "<input type='input' placeholder='" . $_local->gui->g_mean . "' id='term_new_mean'/>";
  126. echo "</div>"; //'意思'
  127. echo "<div class='other_mean'>";
  128. echo "<span>" . $_local->gui->other_meaning . ":</span>";
  129. echo "<input type='input' placeholder='" . $_local->gui->other_meaning . "' id='term_new_mean2'/>";
  130. echo "</div>"; //'备选意思(可选项)'
  131. echo "<div class='tag'>";
  132. echo "<span>" . $_local->gui->tag . ":</span>";
  133. echo "<input type='input' placeholder='" . $_local->gui->tag . "' id='term_new_tag'/>";
  134. echo "</div>"; //'标签'
  135. echo "<div class='note'>";
  136. echo "<span>" . $_local->gui->note . ":</span>";
  137. echo "<textarea width='100%' height='3em' placeholder='" . $_local->gui->note . "' id='term_new_note'></textarea>";
  138. echo "</div>"; //'注解'
  139. echo "<button onclick=\"term_data_save('')\">" . $_local->gui->save . "</button>"; //保存
  140. echo "</div>";
  141. //查他人数据
  142. $query = "select * from term where \"word\" = " . $PDO->quote($word) . "AND \"owner\" <> " . $PDO->quote($username) . " limit 0,30";
  143. $Fetch = PDO_FetchAll($query);
  144. $iFetch = count($Fetch);
  145. $count_return += $iFetch;
  146. if ($iFetch > 0) {
  147. for ($i = 0; $i < $iFetch; $i++) {
  148. $mean = $Fetch[$i]["meaning"];
  149. $guid = $Fetch[$i]["guid"];
  150. $dict_list[$guid] = $Fetch[$i]["owner"];
  151. echo "<div class='dict_word'>";
  152. echo "<a name='ref_dict_$guid'></a>";
  153. echo "<div class='dict'>" . $Fetch[$i]["owner"] . "</div>";
  154. echo "<div class='mean'>" . $mean . "</div>";
  155. echo "<div class='other_mean'>" . $Fetch[$i]["other_meaning"] . "</div>";
  156. echo "<div class='note'>" . $Fetch[$i]["note"] . "</div>";
  157. echo "<button onclick=\"term_data_copy_to_me($guid)\">" . $module_gui_str['editor']['1123'] . "</button>"; //复制
  158. echo "</div>";
  159. }
  160. }
  161. //查内容
  162. if ($count_return < 2) {
  163. $word1 = $org_word;
  164. $wordInMean = "%$org_word%";
  165. echo $module_gui_str['editor']['1124'] . ":$org_word<br />";
  166. $query = "select * from term where \"meaning\" like " . $PDO->quote($word) . " limit 0,30";
  167. $Fetch = PDO_FetchAll($query);
  168. $iFetch = count($Fetch);
  169. $count_return += $iFetch;
  170. if ($iFetch > 0) {
  171. for ($i = 0; $i < $iFetch; $i++) {
  172. $mean = $Fetch[$i]["meaning"];
  173. $pos = mb_stripos($mean, $word, 0, "UTF-8");
  174. if ($pos) {
  175. if ($pos > 20) {
  176. $start = $pos - 20;
  177. } else {
  178. $start = 0;
  179. }
  180. $newmean = mb_substr($mean, $start, 100, "UTF-8");
  181. } else {
  182. $newmean = $mean;
  183. }
  184. $pos = mb_stripos($newmean, $word1, 0, "UTF-8");
  185. $head = mb_substr($newmean, 0, $pos, "UTF-8");
  186. $mid = mb_substr($newmean, $pos, mb_strlen($word1, "UTF-8"), "UTF-8");
  187. $end = mb_substr($newmean, $pos + mb_strlen($word1, "UTF-8"), null, "UTF-8");
  188. $heigh_light_mean = "$head<hl>$mid</hl>$end";
  189. $outXml = "<div class='dict_word'>";
  190. $outXml = $outXml . "<div class='dict'>" . $Fetch[$i]["owner"] . "</div>";
  191. $outXml = $outXml . "<div class='pali'>" . $Fetch[$i]["word"] . "</div>";
  192. $outXml = $outXml . "<div class='mean'>" . $heigh_light_mean . "</div>";
  193. $outXml = $outXml . "<div class='note'>{$Fetch[$i]["note"]}</div>";
  194. $outXml = $outXml . "</div>";
  195. echo $outXml;
  196. }
  197. }
  198. }
  199. //查内容结束
  200. echo "<div id='dictlist'>";
  201. foreach ($dict_list as $x => $x_value) {
  202. echo "<a href='#ref_dict_$x'>$x_value</a><br/>";
  203. }
  204. echo "</div>";
  205. break;
  206. case "save":
  207. if ($_GET["guid"] != "") {
  208. $mean = $_GET["mean"];
  209. $query = "UPDATE term SET meaning='$mean' ,
  210. other_meaning='" . $_GET["mean2"] . "' ,
  211. note='" . $_GET["note"] . "'
  212. where guid='" . $_GET["guid"] . "'";
  213. } else {
  214. $newGuid = GUIDv4();
  215. $newGuid = str_replace("-", "", $newGuid);
  216. $word = $_GET["word"];
  217. $worden = pali2english($word);
  218. $mean = $_GET["mean"];
  219. $mean2 = $_GET["mean2"];
  220. $note = $_GET["note"];
  221. $tag = $_GET["tag"];
  222. $time = time();
  223. $query = "INSERT INTO term VALUES (NULL,
  224. '$newGuid',
  225. '$word',
  226. '$worden',
  227. '$mean',
  228. '$mean2',
  229. '$note',
  230. '$tag',
  231. '$time',
  232. '$username',
  233. '1',
  234. 'zh',
  235. '0',
  236. '0',
  237. '0')";
  238. }
  239. $stmt = @PDO_Execute($query);
  240. $respond = array("status" => 0, "message" => "");
  241. if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
  242. $error = PDO_ErrorInfo();
  243. $respond['status'] = 1;
  244. $respond['message'] = $error[2];
  245. } else {
  246. $respond['status'] = 0;
  247. $respond['message'] = $word;
  248. }
  249. echo json_encode($respond, JSON_UNESCAPED_UNICODE);
  250. break;
  251. case "copy": //拷贝到我的字典
  252. $query = "select * from term where \"guid\" = " . $PDO->quote($_GET["wordid"]);
  253. $Fetch = PDO_FetchAll($query);
  254. $iFetch = count($Fetch);
  255. if ($iFetch > 0) {
  256. /* 开始一个事务,关闭自动提交 */
  257. $PDO->beginTransaction();
  258. $query = "INSERT INTO term ('id','guid','word','word_en','meaning','other_meaning','note','tag','create_time','owner','hit') VALUES (null,?,?,?,?,?,?,?," . time() . ",'$username',1)";
  259. $stmt = $PDO->prepare($query);
  260. {
  261. $stmt->execute(array(GUIDv4(false),
  262. $Fetch[0]["word"],
  263. $Fetch[0]["word_en"],
  264. $Fetch[0]["meaning"],
  265. $Fetch[0]["other_meaning"],
  266. $Fetch[0]["note"],
  267. $Fetch[0]["tag"],
  268. ));
  269. }
  270. /* 提交更改 */
  271. $PDO->commit();
  272. if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
  273. $error = PDO_ErrorInfo();
  274. echo "error - $error[2] <br>";
  275. } else {
  276. echo "updata ok.";
  277. }
  278. }
  279. break;
  280. case "extract":
  281. $query = "select * from term where \"guid\" in ($list) limit 0,1000";
  282. $Fetch = PDO_FetchAll($query);
  283. $iFetch = count($Fetch);
  284. if ($iFetch > 0) {
  285. echo json_encode($Fetch, JSON_UNESCAPED_UNICODE);
  286. }
  287. break;
  288. }