note.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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. try{
  75. if(!empty($_setting["channal"])){
  76. $queryChannal = " AND channal = ? ";
  77. }
  78. else{
  79. $queryChannal ="";
  80. }
  81. $query="SELECT * FROM sentence WHERE book= ? AND paragraph= ? AND begin= ? AND end= ? AND strlen >0 $queryChannal order by modify_time DESC limit 0 ,1 ";
  82. $stmt = $db_trans_sent->prepare($query);
  83. if(empty($_setting["channal"])){
  84. $stmt->execute(array($bookId,$para,$begin,$end));
  85. }
  86. else{
  87. $stmt->execute(array($bookId,$para,$begin,$end,$_setting["channal"]));
  88. }
  89. $Fetch = $stmt->fetch(PDO::FETCH_ASSOC);
  90. if($Fetch){
  91. $tran = $Fetch["text"];
  92. }
  93. $tran_count = 1;
  94. }
  95. catch (Exception $e) {
  96. $tran = $e->getMessage();
  97. //echo 'Caught exception: ', $e->getMessage(), "\n";
  98. }
  99. $para_path=_get_para_path($bookId,$para);
  100. $output[]=array("id"=>$id,
  101. "palitext"=>$palitext,
  102. "tran"=>$tran,
  103. "ref"=>$para_path,
  104. "tran_count"=>$tran_count,
  105. "book"=>$bookId,
  106. "para"=>$para,
  107. "begin"=>$begin,
  108. "end"=>$end
  109. );
  110. }
  111. echo json_encode($output, JSON_UNESCAPED_UNICODE);
  112. ?>