term.php 10 KB

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