term.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419
  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. }
  11. else{
  12. $username = "";
  13. }
  14. if(isset($_GET["op"])){
  15. $op=$_GET["op"];
  16. }
  17. else if(isset($_POST["op"])){
  18. $op=$_POST["op"];
  19. }
  20. if(isset($_GET["word"])){
  21. $word=mb_strtolower($_GET["word"],'UTF-8');
  22. $org_word=$word;
  23. }
  24. if(isset($_GET["guid"])){
  25. $_guid=$_GET["guid"];
  26. }
  27. if(isset($_GET["username"])){
  28. $username=$_GET["username"];
  29. }
  30. global $PDO;
  31. PDO_Connect("sqlite:"._FILE_DB_TERM_);
  32. switch($op){
  33. case "pre"://预查询
  34. {
  35. $query = "select word,meaning from term where \"eword\" like ".$PDO->quote($word.'%')." OR \"word\" like ".$PDO->quote($word.'%')." group by word limit 0,10";
  36. $Fetch = PDO_FetchAll($query);
  37. if(count($Fetch)<5){
  38. $query = "select word,meaning from term where \"eword\" like ".$PDO->quote('%'.$word.'%')." OR \"word\" like ".$PDO->quote('%'.$word.'%')." group by word limit 0,10";
  39. $Fetch2 = PDO_FetchAll($query);
  40. //去掉重复的
  41. foreach($Fetch2 as $onerow){
  42. $found=false;
  43. foreach($Fetch as $oldArray){
  44. if($onerow["word"]==$oldArray["word"]){
  45. $found=true;
  46. break;
  47. }
  48. }
  49. if($found==false){
  50. array_push($Fetch,$onerow);
  51. }
  52. }
  53. if(count($Fetch)<8){
  54. $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";
  55. $Fetch3 = PDO_FetchAll($query);
  56. $Fetch = array_merge($Fetch,$Fetch3);
  57. if(count($Fetch)<8){
  58. $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";
  59. $Fetch4 = PDO_FetchAll($query);
  60. //去掉重复的
  61. foreach($Fetch4 as $onerow){
  62. $found=false;
  63. foreach($Fetch as $oldArray){
  64. if($onerow["word"]==$oldArray["word"]){
  65. $found=true;
  66. break;
  67. }
  68. }
  69. if($found==false){
  70. array_push($Fetch,$onerow);
  71. }
  72. }
  73. }
  74. }
  75. }
  76. echo json_encode($Fetch, JSON_UNESCAPED_UNICODE);
  77. break;
  78. }
  79. case "my":
  80. {
  81. $query = "select guid,word,meaning,other_meaning from term where owner= ".$PDO->quote($username);
  82. $Fetch = PDO_FetchAll($query);
  83. $iFetch=count($Fetch);
  84. if($iFetch>0){
  85. echo json_encode($Fetch, JSON_UNESCAPED_UNICODE);
  86. }
  87. break;
  88. }
  89. case "allpali":
  90. {
  91. $query = "select word from term where 1 group by word";
  92. $Fetch = PDO_FetchAll($query);
  93. $iFetch=count($Fetch);
  94. if($iFetch>0){
  95. echo json_encode($Fetch, JSON_UNESCAPED_UNICODE);
  96. }
  97. break;
  98. }
  99. case "allmean":
  100. {
  101. $query = "select meaning from term where \"word\" = ".$PDO->quote($word)." group by meaning";
  102. $Fetch = PDO_FetchAll($query);
  103. foreach($Fetch as $one){
  104. echo "<a>".$one["meaning"]."</a> ";
  105. }
  106. //echo json_encode($Fetch, JSON_UNESCAPED_UNICODE);
  107. break;
  108. }
  109. case "load_id":
  110. {
  111. if(isset($_GET["id"])){
  112. $id=$_GET["id"];
  113. $query = "select * from term where \"guid\" = ".$PDO->quote($id);
  114. $Fetch = PDO_FetchAll($query);
  115. echo json_encode($Fetch, JSON_UNESCAPED_UNICODE);
  116. }
  117. else{
  118. echo json_encode(array(), JSON_UNESCAPED_UNICODE);
  119. }
  120. break;
  121. }
  122. case "search":
  123. {
  124. if(!isset($word)){
  125. return;
  126. }
  127. if(trim($word)==""){
  128. return;
  129. }
  130. echo"<div class='pali'>{$word}</div>";
  131. //查本人数据
  132. echo "<div></div>";//My Term
  133. $query = "select * from term where \"word\" = ".$PDO->quote($word)." AND \"owner\"= ".$PDO->quote($username)." limit 0,30";
  134. $Fetch = PDO_FetchAll($query);
  135. $iFetch=count($Fetch);
  136. $count_return+=$iFetch;
  137. if($iFetch>0){
  138. for($i=0;$i<$iFetch;$i++){
  139. $mean=$Fetch[$i]["meaning"];
  140. $guid=$Fetch[$i]["guid"];
  141. $dict_list[$guid]=$Fetch[$i]["owner"];
  142. echo "<div class='dict_word'>";
  143. echo "<a name='ref_dict_$guid'></a>";
  144. echo "<div id='term_dict_my_$guid'>";
  145. echo "<div class='dict'>{$_local->gui->my_term}</div>";
  146. echo "<div class='mean'><span>".$mean."</span>";
  147. echo "<span class='other_mean' style='margin-right: auto;'>(".$Fetch[$i]["other_meaning"].")</span></div>";
  148. echo "<div class='tag'>{$Fetch[$i]["tag"]}</div>";
  149. echo "<div class='term_note' status=0>".$Fetch[$i]["note"]."</div>";
  150. echo "</div>";
  151. //编辑词条表单
  152. echo "<div id='term_dict_my_edit_$guid' style='display:none'>";
  153. echo "<input type='hidden' id='term_edit_word_$guid' value='$word' />";
  154. echo "<div class='mean' style='display:flex;'><span style='flex:1;'>{$_local->gui->first_choice_word}:</span>";
  155. echo "<input type='input' style='flex:3;' placeholder='{$_local->gui->required}' id='term_edit_mean_{$guid}' value='$mean' /></div>";//'意思'
  156. //echo "<div class='mean'><input type='input' id='term_edit_mean_{$guid}' placeholder='{$_local->gui->meaning}' value='$mean' /></div>";//'意思'
  157. echo "<div class='mean' style='display:flex;'><span style='flex:1;'>{$_local->gui->other_meaning}:</span>";
  158. echo "<input type='input' style='flex:3;' placeholder='{$_local->gui->optional}' id='term_edit_mean2_{$guid}' value='".$Fetch[$i]["other_meaning"]."'/></div>";//'备选意思(可选项)'
  159. //echo "<div class='other_mean'><input type='input' id='term_edit_mean2_{$guid}' placeholder='{$_local->gui->other_meaning}' value='".$Fetch[$i]["other_meaning"]."' /></div>";//'备选意思(可选项)'
  160. echo "<div class='mean' style='display:flex;'><span style='flex:1;'>{$_local->gui->tag}:</span>";
  161. echo "<input type='input' style='flex:3;' placeholder='{$_local->gui->optional}' id='term_edit_tag_{$guid}' value='".$Fetch[$i]["tag"]."'/></div>";//'标签'
  162. //echo "<div class='tag'><input type='input' id='term_edit_tag_{$guid}' placeholder='{$_local->gui->other_tag}' value='".$Fetch[$i]["tag"]."' /></div>";//'标签'
  163. echo "<div class='note'><span style='display:flex;'><span>{$_local->gui->encyclopedia} & {$_local->gui->note}:</span>";
  164. echo "<guide gid='term_pedia_sys' style='margin-left: auto;'></guide></span>";
  165. echo "<textarea width='100%' height='3em' placeholder='{$_local->gui->optional}' id='term_edit_note_$guid'>".$Fetch[$i]["note"]."</textarea></div>";//'注解'
  166. //echo "<div class='note'><textarea id='term_edit_note_$guid' placeholder='".$module_gui_str['editor']['1043']."'>".$Fetch[$i]["note"]."</textarea></div>";//'注解'
  167. echo "</div>";
  168. echo "<div id='term_edit_btn1_$guid'>";
  169. //echo "<button onclick=\"term_apply('$guid')\">{$_local->gui->apply}</button>";//Apply
  170. echo "<button onclick=\"term_edit('$guid')\">{$_local->gui->edit}</button>";//Edit
  171. echo "</div>";
  172. echo "<div id='term_edit_btn2_{$guid}' style='display:none'>";
  173. echo "<button onclick=\"term_data_esc_edit('$guid')\">{$_local->gui->cancel}</button>";//Cancel
  174. echo "<button onclick=\"term_data_save('$guid')\">{$_local->gui->save}</button>";//保存
  175. echo "</div>";
  176. echo "</div>";
  177. }
  178. }
  179. //新建词条
  180. echo "<div class='dict_word'>";
  181. echo "<button id='new_term_button' onclick=\"term_show_new()\">{$_local->gui->new}</button>";
  182. echo "<div id='term_new_recorder' style='display:none;'>";
  183. echo "<div class='dict'>".$_local->gui->new_technic_term."</div>";//New Techinc Term
  184. echo "<div class='mean' style='display:flex;'><span style='flex:1;'>{$_local->gui->pali_word}:</span>";
  185. echo "<input type='input' style='flex:3;' placeholder='{$_local->gui->required}' id='term_new_word' value='{$word}' /></div>";//'拼写'
  186. echo "<div class='mean' style='display:flex;'><span style='flex:1;'>{$_local->gui->first_choice_word}:</span>";
  187. echo "<input type='input' style='flex:3;' placeholder='{$_local->gui->required}' id='term_new_mean'/></div>";//'意思'
  188. echo "<div class='mean' style='display:flex;'><span style='flex:1;'>{$_local->gui->other_meaning}:</span>";
  189. echo "<input type='input' style='flex:3;' placeholder='{$_local->gui->optional}' id='term_new_mean2'/></div>";//'备选意思(可选项)'
  190. echo "<div class='mean' style='display:flex;'><span style='flex:1;'>{$_local->gui->tag}:</span>";
  191. echo "<input type='input' style='flex:3;' placeholder='{$_local->gui->optional}' id='term_new_tag'/></div>";//'标签'
  192. echo "<div class='note'><span style='display:flex;'><span>{$_local->gui->encyclopedia} & {$_local->gui->note}:</span>";
  193. echo "<guide gid='term_pedia_sys' style='margin-left: auto;'></guide></span>";
  194. echo "<textarea width='100%' height='3em' placeholder='{$_local->gui->optional}' id='term_new_note'></textarea></div>";//'注解'
  195. echo "<button onclick=\"term_data_save('')\">{$_local->gui->save}</button>";//保存
  196. echo "</div>";
  197. echo "</div>";
  198. //查他人数据
  199. $query = "select * from term where \"word\" = ".$PDO->quote($word)."AND \"owner\" <> ".$PDO->quote($username)." limit 0,30";
  200. $Fetch = PDO_FetchAll($query);
  201. $iFetch=count($Fetch);
  202. $count_return+=$iFetch;
  203. if($iFetch>0){
  204. for($i=0;$i<$iFetch;$i++){
  205. $mean=$Fetch[$i]["meaning"];
  206. $guid=$Fetch[$i]["guid"];
  207. $dict_list[$guid]=$Fetch[$i]["owner"];
  208. echo "<div class='dict_word'>";
  209. echo "<a name='ref_dict_$guid'></a>";
  210. echo"<div class='dict'>".$Fetch[$i]["owner"]."</div>";
  211. echo "<div class='mean'>".$mean."</div>";
  212. echo "<div class='other_mean'>".$Fetch[$i]["other_meaning"]."</div>";
  213. echo "<div class='term_note'>".$Fetch[$i]["note"]."</div>";
  214. echo "<button onclick=\"term_data_copy_to_me($guid)\">{$_local->gui->copy}</button>";//复制
  215. echo "</div>";
  216. }
  217. }
  218. //查内容
  219. /*
  220. if($count_return<2){
  221. $word1=$org_word;
  222. $wordInMean="%$org_word%";
  223. echo $module_gui_str['editor']['1124'].":$org_word<br />";
  224. $query = "select * from term where \"meaning\" like ".$PDO->quote($word)." limit 0,30";
  225. $Fetch = PDO_FetchAll($query);
  226. $iFetch=count($Fetch);
  227. $count_return+=$iFetch;
  228. if($iFetch>0){
  229. for($i=0;$i<$iFetch;$i++){
  230. $mean=$Fetch[$i]["meaning"];
  231. $pos=mb_stripos($mean,$word,0,"UTF-8");
  232. if($pos){
  233. if($pos>20){
  234. $start=$pos-20;
  235. }
  236. else{
  237. $start=0;
  238. }
  239. $newmean=mb_substr($mean,$start,100,"UTF-8");
  240. }
  241. else{
  242. $newmean=$mean;
  243. }
  244. $pos=mb_stripos($newmean,$word1,0,"UTF-8");
  245. $head=mb_substr($newmean,0,$pos,"UTF-8");
  246. $mid=mb_substr($newmean,$pos,mb_strlen($word1,"UTF-8"),"UTF-8");
  247. $end=mb_substr($newmean,$pos+mb_strlen($word1,"UTF-8"),NULL,"UTF-8");
  248. $heigh_light_mean="$head<hl>$mid</hl>$end";
  249. $outXml = "<div class='dict_word'>";
  250. $outXml = $outXml."<div class='dict'>".$Fetch[$i]["owner"]."</div>";
  251. $outXml = $outXml."<div class='pali'>".$Fetch[$i]["word"]."</div>";
  252. $outXml = $outXml."<div class='mean'>".$heigh_light_mean."</div>";
  253. $outXml = $outXml."<div class='note'>{$Fetch[$i]["note"]}</div>";
  254. $outXml = $outXml."</div>";
  255. echo $outXml;
  256. }
  257. }
  258. }
  259. */
  260. //查内容结束
  261. echo "<div id='dictlist'>";
  262. echo "</div>";
  263. break;
  264. }
  265. case "save":
  266. {
  267. $currTime=sprintf("%d",microtime(true)*1000);
  268. if(isset($_GET["modify_time"])){
  269. $mTime=$_GET["modify_time"];
  270. }
  271. else{
  272. $mTime=time();
  273. }
  274. if($_GET["guid"]!=""){
  275. $mean=$_GET["mean"];
  276. $query="UPDATE term SET meaning='$mean' ,
  277. other_meaning='".$_GET["mean2"]."' ,
  278. tag='".$_GET["tag"]."' ,
  279. receive_time='".time()."' ,
  280. modify_time='$mTime' ,
  281. note='".$_GET["note"]."'
  282. where guid='".$_GET["guid"]."'";
  283. }
  284. else{
  285. $newGuid=UUID::v4();
  286. $word=$_GET["word"];
  287. $worden=pali2english($word);
  288. $mean=$_GET["mean"];
  289. $mean2=$_GET["mean2"];
  290. $note=$_GET["note"];
  291. $tag=$_GET["tag"];
  292. $time=time();
  293. $query="INSERT INTO term VALUES (NULL,
  294. '$newGuid',
  295. '$word',
  296. '$worden',
  297. '$mean',
  298. '$mean2',
  299. '$note',
  300. '$tag',
  301. '$time',
  302. '$username',
  303. '1',
  304. 'zh',
  305. '$time',
  306. '$time')";
  307. }
  308. $stmt = @PDO_Execute($query);
  309. $respond=array("status"=>0,"message"=>"");
  310. if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
  311. $error = PDO_ErrorInfo();
  312. $respond['status']=1;
  313. $respond['message']=$error[2].$query;
  314. }
  315. else{
  316. $respond['status']=0;
  317. $respond['message']=$word;
  318. }
  319. echo json_encode($respond, JSON_UNESCAPED_UNICODE);
  320. break;
  321. }
  322. case "copy"://拷贝到我的字典
  323. {
  324. $query = "select * from term where \"guid\" = ".$PDO->quote($_GET["wordid"]);
  325. $Fetch = PDO_FetchAll($query);
  326. $iFetch=count($Fetch);
  327. if($iFetch>0){
  328. /* 开始一个事务,关闭自动提交 */
  329. $PDO->beginTransaction();
  330. $query="INSERT INTO term ('id','guid','word','word_en','meaning','other_meaning','note','tag','create_time','owner','hit') VALUES (null,?,?,?,?,?,?,?,".time().",'$username',1)";
  331. $stmt = $PDO->prepare($query);
  332. {
  333. $stmt->execute(array(UUID::v4,
  334. $Fetch[0]["word"],
  335. $Fetch[0]["word_en"],
  336. $Fetch[0]["meaning"],
  337. $Fetch[0]["other_meaning"],
  338. $Fetch[0]["note"],
  339. $Fetch[0]["tag"],
  340. ));
  341. }
  342. /* 提交更改 */
  343. $PDO->commit();
  344. if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
  345. $error = PDO_ErrorInfo();
  346. echo "error - $error[2] <br>";
  347. }
  348. else{
  349. echo "updata ok.";
  350. }
  351. }
  352. break;
  353. }
  354. case "extract":
  355. {
  356. if(isset($_POST["words"])){
  357. $words=$_POST["words"];
  358. }
  359. if(isset($_POST["authors"])){
  360. $authors=str_getcsv($_POST["authors"]);
  361. }
  362. $query = "select * from term where \"word\" in {$words} limit 0,1000";
  363. $Fetch = PDO_FetchAll($query);
  364. $iFetch=count($Fetch);
  365. echo json_encode($Fetch, JSON_UNESCAPED_UNICODE);
  366. break;
  367. }
  368. case "sync":
  369. {
  370. $time=$_GET["time"];
  371. $query = "select guid,modify_time from term where receive_time>'{$time}' limit 0,1000";
  372. $Fetch = PDO_FetchAll($query);
  373. $iFetch=count($Fetch);
  374. echo json_encode($Fetch, JSON_UNESCAPED_UNICODE);
  375. break;
  376. }
  377. case "get":
  378. {
  379. $Fetch = array();
  380. if(isset($guid)){
  381. $query = "select * from term where \"guid\" = '{$guid}'";
  382. }
  383. else if(isset($word)){
  384. $query = "select * from term where \"word\" = '{$word}'";
  385. }
  386. else{
  387. echo "[]";
  388. return;
  389. }
  390. $Fetch = PDO_FetchAll($query);
  391. $iFetch=count($Fetch);
  392. echo json_encode($Fetch, JSON_UNESCAPED_UNICODE);
  393. break;
  394. }
  395. }
  396. ?>