note.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. $query="SELECT html FROM 'pali_sent' WHERE book = ? AND paragraph = ? AND begin = ? AND end = ? ";
  58. $sth = $db_pali_sent->prepare($query);
  59. $sth->execute(array($bookId,$para,$begin,$end));
  60. $row = $sth->fetch(PDO::FETCH_NUM);
  61. if ($row) {
  62. $palitext= $row[0];
  63. } else {
  64. $palitext="";
  65. }
  66. //find out translation
  67. $tran="";
  68. try{
  69. if(!empty($_setting["channal"])){
  70. $queryChannal = " AND channal = ? ";
  71. }
  72. else{
  73. $queryChannal ="";
  74. }
  75. $query="SELECT * FROM sentence WHERE book= ? AND paragraph= ? AND begin= ? AND end= ? AND strlen >0 $queryChannal order by modify_time DESC limit 0 ,1 ";
  76. $stmt = $db_trans_sent->prepare($query);
  77. if(empty($_setting["channal"])){
  78. $stmt->execute(array($bookId,$para,$begin,$end));
  79. }
  80. else{
  81. $stmt->execute(array($bookId,$para,$begin,$end,$_setting["channal"]));
  82. }
  83. $Fetch = $stmt->fetch(PDO::FETCH_ASSOC);
  84. if($Fetch){
  85. $tran = $Fetch["text"];
  86. }
  87. $tran_count = 1;
  88. }
  89. catch (Exception $e) {
  90. $tran = $e->getMessage();
  91. //echo 'Caught exception: ', $e->getMessage(), "\n";
  92. }
  93. $para_path=_get_para_path($bookId,$para);
  94. $output[]=array("id"=>$id,"palitext"=>$palitext,"tran"=>$tran,"ref"=>$para_path,"tran_count"=>$tran_count);
  95. }
  96. echo json_encode($output, JSON_UNESCAPED_UNICODE);
  97. ?>