note.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. <?php
  2. require_once "../public/_pdo.php";
  3. require_once "../public/function.php";
  4. require_once "../path.php";
  5. $_data = array();
  6. if(isset($_POST["data"])){
  7. $_data = json_decode($_POST["data"],true);
  8. }
  9. else{
  10. if(isset($_GET["id"])){
  11. $id=$_GET["id"];
  12. }
  13. else{
  14. echo "error: no id";
  15. return;
  16. }
  17. if(isset($_GET["info"])){
  18. $info=$_GET["info"];
  19. }
  20. else{
  21. echo "error: no info";
  22. return;
  23. }
  24. $_data[] = array("id"=>$id,"data"=>$info);
  25. }
  26. if(isset($_POST["setting"])){
  27. $_setting = json_decode($_POST["setting"],true);
  28. }
  29. else{
  30. $_setting["lang"] = "";
  31. $_setting["channal"] = "";
  32. }
  33. $dns = "sqlite:"._FILE_DB_PALI_SENTENCE_;
  34. $db_pali_sent = new PDO($dns, "", "",array(PDO::ATTR_PERSISTENT=>true));
  35. $db_pali_sent->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
  36. $dns = "sqlite:"._FILE_DB_SENTENCE_;
  37. $db_trans_sent = new PDO($dns, "", "",array(PDO::ATTR_PERSISTENT=>true));
  38. $db_trans_sent->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
  39. $output = array();
  40. foreach ($_data as $key => $value) {
  41. # code...
  42. $id = $value["id"];
  43. $arrInfo = explode("@",$value["data"]);
  44. if(isset($arrInfo[1])){
  45. $sentChannal = $arrInfo[1];
  46. }
  47. else{
  48. $sentChannal = "";
  49. }
  50. if(isset($arrInfo[0])){
  51. $arrSent = str_getcsv($arrInfo[0],"-");
  52. $bookId=$arrSent[0];
  53. $para=$arrSent[1];
  54. $begin=$arrSent[2];
  55. $end=$arrSent[3];
  56. }
  57. else{
  58. $bookId=0;
  59. $para=0;
  60. $begin=0;
  61. $end=0;
  62. }
  63. $query="SELECT html FROM 'pali_sent' WHERE book = ? AND paragraph = ? AND begin = ? AND end = ? ";
  64. $sth = $db_pali_sent->prepare($query);
  65. $sth->execute(array($bookId,$para,$begin,$end));
  66. $row = $sth->fetch(PDO::FETCH_NUM);
  67. if ($row) {
  68. $palitext= $row[0];
  69. } else {
  70. $palitext="";
  71. }
  72. //find out translation
  73. $tran="";
  74. $translation = array();
  75. try{
  76. if(!empty($_setting["channal"])){
  77. $queryChannal = " AND channal = ? ";
  78. $query="SELECT * FROM sentence WHERE book= ? AND paragraph= ? AND begin= ? AND end= ? AND strlen >0 AND channal = ? limit 0 ,1 ";
  79. $channal = $_setting["channal"];
  80. }
  81. else{
  82. $query="SELECT * FROM sentence WHERE book= ? AND paragraph= ? AND begin= ? AND end= ? AND strlen >0 order by modify_time DESC limit 0 ,1 ";
  83. $channal = "";
  84. }
  85. $stmt = $db_trans_sent->prepare($query);
  86. if(empty($_setting["channal"])){
  87. $stmt->execute(array($bookId,$para,$begin,$end));
  88. $Fetch = $stmt->fetch(PDO::FETCH_ASSOC);
  89. if($Fetch){
  90. $tran = $Fetch["text"];
  91. $translation[]=array("id"=>$Fetch["id"],"text"=>$Fetch["text"],"channal"=>$Fetch["channal"]);
  92. }
  93. }
  94. else{
  95. $arrChannal = explode(",",$_setting["channal"]);
  96. foreach ($arrChannal as $key => $value) {
  97. # code...
  98. $stmt->execute(array($bookId,$para,$begin,$end,$value));
  99. $Fetch = $stmt->fetch(PDO::FETCH_ASSOC);
  100. if($Fetch){
  101. $translation[]=array("id"=>$Fetch["id"],"text"=>$Fetch["text"],"channal"=>$value);
  102. }
  103. else{
  104. $translation[]=array("id"=>"","text"=>"","channal"=>$value);
  105. }
  106. }
  107. }
  108. $tran_count = 1;
  109. }
  110. catch (Exception $e) {
  111. $tran = $e->getMessage();
  112. //echo 'Caught exception: ', $e->getMessage(), "\n";
  113. }
  114. $para_path=_get_para_path($bookId,$para);
  115. $output[]=array("id"=>$id,
  116. "palitext"=>$palitext,
  117. "tran"=>$tran,
  118. "translation"=>$translation,
  119. "ref"=>$para_path,
  120. "tran_count"=>$tran_count,
  121. "book"=>$bookId,
  122. "para"=>$para,
  123. "begin"=>$begin,
  124. "end"=>$end
  125. );
  126. }
  127. echo json_encode($output, JSON_UNESCAPED_UNICODE);
  128. ?>