2
0

term.php 10 KB

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