term.php 14 KB

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