term.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400
  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 = ? AND owner = ? limit 0,30";
  145. $Fetch = PDO_FetchAll($query,array($word,$_COOKIE["userid"]));
  146. $iFetch=count($Fetch);
  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 id='term_dict_my_$guid'>";
  155. echo "<div class='dict'>{$_local->gui->my_term}</div>";
  156. echo "<div class='mean'><span>".$mean."</span>";
  157. echo "<span class='other_mean' style='margin-right: auto;'>(".$Fetch[$i]["other_meaning"].")</span></div>";
  158. echo "<div class='tag'>{$Fetch[$i]["tag"]}</div>";
  159. echo "<div class='mean'>{$Fetch[$i]["channal"]}</div>";
  160. echo "<div class='mean'>{$Fetch[$i]["language"]}</div>";
  161. echo "<div class='term_note' status=0>".$Fetch[$i]["note"]."</div>";
  162. echo "</div>";
  163. //编辑词条表单
  164. echo "<div id='term_dict_my_edit_$guid' style='display:none'>";
  165. echo "<input type='hidden' id='term_edit_word_$guid' value='$word' />";
  166. echo "<div class='mean' style='display:flex;'><span style='flex:1;'>{$_local->gui->first_choice_word}:</span>";
  167. echo "<input type='input' style='flex:3;' placeholder='{$_local->gui->required}' id='term_edit_mean_{$guid}' 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='mean' style='display:flex;'><span style='flex:1;'>{$_local->gui->tag}:</span>";
  171. echo "<input type='input' style='flex:3;' placeholder='{$_local->gui->optional}' id='term_edit_tag_{$guid}' value='".$Fetch[$i]["tag"]."'/></div>";//'标签'
  172. echo "<div class='mean' style='display:flex;'><span style='flex:1;'>{$_local->gui->channel}:</span>";
  173. echo "<input type='input' style='flex:3;' placeholder='{$_local->gui->optional}' id='term_edit_channal_{$guid}' value='".$Fetch[$i]["channal"]."'/></div>";//'版风'
  174. echo "<div class='mean' style='display:flex;'><span style='flex:1;'>{$_local->gui->language}:</span>";
  175. echo "<input type='input' style='flex:3;' placeholder='{$_local->gui->optional}' id='term_edit_language_{$guid}' value='".$Fetch[$i]["language"]."'/></div>";//'语言'
  176. echo "<div class='note'><span style='display:flex;'><span>{$_local->gui->encyclopedia} & {$_local->gui->note}:</span>";
  177. echo "<guide gid='term_pedia_sys' style='margin-left: auto;'></guide></span>";
  178. echo "<textarea width='100%' height='3em' placeholder='{$_local->gui->optional}' id='term_edit_note_$guid'>".$Fetch[$i]["note"]."</textarea></div>";//'注解'
  179. echo "</div>";
  180. echo "<div id='term_edit_btn1_$guid'>";
  181. //echo "<button onclick=\"term_apply('$guid')\">{$_local->gui->apply}</button>";//Apply
  182. echo "<button onclick=\"term_edit('$guid')\">{$_local->gui->edit}</button>";//Edit
  183. echo "</div>";
  184. echo "<div id='term_edit_btn2_{$guid}' style='display:none'>";
  185. echo "<button onclick=\"term_data_esc_edit('$guid')\">{$_local->gui->cancel}</button>";//Cancel
  186. echo "<button onclick=\"term_data_save('$guid')\">{$_local->gui->save}</button>";//保存
  187. echo "</div>";
  188. echo "</div>";
  189. }
  190. }
  191. //新建词条
  192. echo "<div class='dict_word'>";
  193. echo "<button id='new_term_button' onclick=\"term_show_new()\">{$_local->gui->new}</button>";
  194. echo "<div id='term_new_recorder' style='display:none;'>";
  195. echo "<div class='dict'>".$_local->gui->new_technic_term."</div>";//New Techinc Term
  196. echo "<div class='mean' style='display:flex;'><span style='flex:1;'>{$_local->gui->pali_word}:</span>";
  197. echo "<input type='input' style='flex:3;' placeholder='{$_local->gui->required}' id='term_new_word' value='{$word}' /></div>";//'拼写'
  198. echo "<div class='mean' style='display:flex;'><span style='flex:1;'>{$_local->gui->first_choice_word}:</span>";
  199. echo "<input type='input' style='flex:3;' placeholder='{$_local->gui->required}' id='term_new_mean'/></div>";//'意思'
  200. echo "<div class='mean' style='display:flex;'><span style='flex:1;'>{$_local->gui->other_meaning}:</span>";
  201. echo "<input type='input' style='flex:3;' placeholder='{$_local->gui->optional}' id='term_new_mean2'/></div>";//'备选意思(可选项)'
  202. echo "<div class='mean' style='display:flex;'><span style='flex:1;'>{$_local->gui->tag}:</span>";
  203. echo "<input type='input' style='flex:3;' placeholder='{$_local->gui->optional}' id='term_new_tag'/></div>";//'标签'
  204. echo "<div class='mean' style='display:flex;'><span style='flex:1;'>{$_local->gui->channel}:</span>";
  205. echo "<input type='input' style='flex:3;' placeholder='{$_local->gui->optional}' id='term_new_channal'/></div>";//'标签'
  206. echo "<div class='mean' style='display:flex;'><span style='flex:1;'>{$_local->gui->language}:</span>";
  207. echo "<input type='input' style='flex:3;' placeholder='{$_local->gui->optional}' id='term_new_language'/></div>";//'标签'
  208. echo "<div class='note'><span style='display:flex;'><span>{$_local->gui->encyclopedia} & {$_local->gui->note}:</span>";
  209. echo "<guide gid='term_pedia_sys' style='margin-left: auto;'></guide></span>";
  210. echo "<textarea width='100%' height='3em' placeholder='{$_local->gui->optional}' id='term_new_note'></textarea></div>";//'注解'
  211. echo "<button onclick=\"term_data_save('')\">{$_local->gui->save}</button>";//保存
  212. echo "</div>";
  213. echo "</div>";
  214. //查他人数据
  215. $query = "SELECT * FROM term WHERE word = ? AND owner <> ? LIMIT 0,30";
  216. $Fetch = PDO_FetchAll($query,array($word,$_COOKIE["userid"]));
  217. $iFetch=count($Fetch);
  218. if($iFetch>0){
  219. for($i=0;$i<$iFetch;$i++){
  220. $mean=$Fetch[$i]["meaning"];
  221. $guid=$Fetch[$i]["guid"];
  222. $dict_list[$guid]=$Fetch[$i]["owner"];
  223. echo "<div class='dict_word'>";
  224. echo "<a name='ref_dict_$guid'></a>";
  225. echo"<div class='dict'>".$Fetch[$i]["owner"]."</div>";
  226. echo "<div class='mean'>".$mean."</div>";
  227. echo "<div class='other_mean'>".$Fetch[$i]["other_meaning"]."</div>";
  228. echo "<div class='term_note'>".$Fetch[$i]["note"]."</div>";
  229. echo "<button onclick=\"term_data_copy_to_me($guid)\">{$_local->gui->copy}</button>";//复制
  230. echo "</div>";
  231. }
  232. }
  233. echo "<div id='dictlist'>";
  234. echo "</div>";
  235. break;
  236. }
  237. case "save":
  238. {
  239. $currTime=sprintf("%d",microtime(true)*1000);
  240. if(isset($_GET["modify_time"])){
  241. $mTime=$_GET["modify_time"];
  242. }
  243. else{
  244. $mTime=mTime();
  245. }
  246. if($_GET["guid"]!=""){
  247. $query="UPDATE term SET meaning= ? ,other_meaning = ? , tag= ? ,channal = ? , language = ? , note = ? , receive_time= ?, modify_time= ? where guid= ? ";
  248. $stmt = @PDO_Execute($query,array($_GET["mean"],
  249. $_GET["mean2"],
  250. $_GET["tag"],
  251. $_GET["channal"],
  252. $_GET["language"],
  253. $_GET["note"],
  254. mTime(),
  255. $mTime,
  256. $_GET["guid"]
  257. ));
  258. }
  259. else{
  260. $parm = array();
  261. $parm[]=UUID::v4();
  262. $parm[]=$_GET["word"];
  263. $parm[]=pali2english($word);
  264. $parm[]=$_GET["mean"];
  265. $parm[]=$_GET["mean2"];
  266. $parm[]=$_GET["tag"];
  267. $parm[]=$_GET["channal"];
  268. $parm[]=$_GET["language"];
  269. $parm[]=$_GET["note"];
  270. $parm[]=$_COOKIE["userid"];
  271. $parm[]=0;
  272. $parm[]=mTime();
  273. $parm[]=mTime();
  274. $parm[]=mTime();
  275. $query="INSERT INTO term (id, guid, word, worden, meaning, other_meaning, tag, channal, language,note,owner,hit,create_time,modify_time,receive_time )
  276. VALUES (NULL, ? , ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) ";
  277. $stmt = @PDO_Execute($query,$parm);
  278. }
  279. $respond=array("status"=>0,"message"=>"");
  280. if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
  281. $error = PDO_ErrorInfo();
  282. $respond['status']=1;
  283. $respond['message']=$error[2].$query;
  284. }
  285. else{
  286. $respond['status']=0;
  287. $respond['message']=$word;
  288. }
  289. echo json_encode($respond, JSON_UNESCAPED_UNICODE);
  290. break;
  291. }
  292. case "copy"://拷贝到我的字典
  293. {
  294. $query = "select * from term where \"guid\" = ".$PDO->quote($_GET["wordid"]);
  295. $Fetch = PDO_FetchAll($query);
  296. $iFetch=count($Fetch);
  297. if($iFetch>0){
  298. /* 开始一个事务,关闭自动提交 */
  299. $PDO->beginTransaction();
  300. $query="INSERT INTO term ('id','guid','word','word_en','meaning','other_meaning','note','tag','create_time','owner','hit') VALUES (null,?,?,?,?,?,?,?,".time().",'$username',1)";
  301. $stmt = $PDO->prepare($query);
  302. {
  303. $stmt->execute(array(UUID::v4,
  304. $Fetch[0]["word"],
  305. $Fetch[0]["word_en"],
  306. $Fetch[0]["meaning"],
  307. $Fetch[0]["other_meaning"],
  308. $Fetch[0]["note"],
  309. $Fetch[0]["tag"],
  310. ));
  311. }
  312. /* 提交更改 */
  313. $PDO->commit();
  314. if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
  315. $error = PDO_ErrorInfo();
  316. echo "error - $error[2] <br>";
  317. }
  318. else{
  319. echo "updata ok.";
  320. }
  321. }
  322. break;
  323. }
  324. case "extract":
  325. {
  326. if(isset($_POST["words"])){
  327. $words=$_POST["words"];
  328. }
  329. if(isset($_POST["authors"])){
  330. $authors=str_getcsv($_POST["authors"]);
  331. }
  332. $queryLang = $currLanguage."%";
  333. $query = "SELECT * from term where \"word\" in {$words} AND language like ? limit 0,1000";
  334. $Fetch = PDO_FetchAll($query,array($queryLang));
  335. $iFetch=count($Fetch);
  336. echo json_encode($Fetch, JSON_UNESCAPED_UNICODE);
  337. break;
  338. }
  339. case "sync":
  340. {
  341. $time=$_GET["time"];
  342. $query = "SELECT guid,modify_time from term where receive_time>'{$time}' limit 0,1000";
  343. $Fetch = PDO_FetchAll($query);
  344. $iFetch=count($Fetch);
  345. echo json_encode($Fetch, JSON_UNESCAPED_UNICODE);
  346. break;
  347. }
  348. case "get":
  349. {
  350. $Fetch = array();
  351. if(isset($guid)){
  352. $query = "select * from term where \"guid\" = '{$guid}'";
  353. }
  354. else if(isset($word)){
  355. $query = "select * from term where \"word\" = '{$word}'";
  356. }
  357. else{
  358. echo "[]";
  359. return;
  360. }
  361. $Fetch = PDO_FetchAll($query);
  362. $iFetch=count($Fetch);
  363. echo json_encode($Fetch, JSON_UNESCAPED_UNICODE);
  364. break;
  365. }
  366. }
  367. ?>