term.php 13 KB

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