create_wbw.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. <?php
  2. //工程文件操作
  3. //建立,
  4. require_once '../path.php';
  5. require_once "../public/_pdo.php";
  6. require_once "../public/function.php";
  7. define("MAX_LETTER" ,20000);
  8. $output["status"]=0;
  9. $output["error"]="";
  10. $output{"book"}="";
  11. $output{"para"}="";
  12. $output{"channel"}="";
  13. if(isset($_POST["book"])){
  14. $_book = $_POST["book"];
  15. }
  16. else{
  17. $output["status"]=1;
  18. $output["error"]="#no_param book";
  19. echo json_encode($output, JSON_UNESCAPED_UNICODE);
  20. exit;
  21. }
  22. if(isset($_POST["para"])){
  23. $_para = json_decode($_POST["para"]);
  24. }
  25. else{
  26. $output["status"]=1;
  27. $output["error"]="#no_param paragraph";
  28. echo json_encode($output, JSON_UNESCAPED_UNICODE);
  29. exit;
  30. }
  31. if(isset($_POST["channel"])){
  32. $_channel = $_POST["channel"];
  33. }
  34. else{
  35. $output["status"]=1;
  36. $output["error"]="#no_param channel";
  37. echo json_encode($output, JSON_UNESCAPED_UNICODE);
  38. exit;
  39. }
  40. $output{"book"}=$_book;
  41. $output{"para"}=$_para;
  42. $output{"channel"}=$_channel;
  43. //判断单词数量 太大的不能加载
  44. PDO_Connect(""._FILE_DB_PALITEXT_);
  45. $params = array(1, 21, 63, 171);
  46. /* 创建一个填充了和params相同数量占位符的字符串 */
  47. $place_holders = implode(',', array_fill(0, count($_para), '?'));
  48. $query = "SELECT sum(lenght) FROM pali_text WHERE paragraph IN ($place_holders) AND book = ?";
  49. $param_letter = $_para;
  50. $param_letter[] = $_book;
  51. $sum_len = PDO_FetchOne($query,$param_letter);
  52. if($sum_len>MAX_LETTER){
  53. $output["status"]=1;
  54. $output["error"]="#oversize_to_load";
  55. echo json_encode($output, JSON_UNESCAPED_UNICODE);
  56. exit;
  57. }
  58. # 查询数据库是否有数据,没有就建立
  59. // 查询逐词解析库
  60. PDO_Connect(""._FILE_DB_USER_WBW_);
  61. //模板库
  62. $db_tpl = "sqlite:"._DIR_PALICANON_TEMPLET_."/p".$_book."_tpl.db3";
  63. $dbh_tpl = new PDO($db_tpl, "", "");
  64. $dbh_tpl->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
  65. #用户逐词译库
  66. $db_wbw = ""._FILE_DB_USER_WBW_;
  67. $dbh_wbw= new PDO($db_wbw, "", "");
  68. $dbh_wbw->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
  69. foreach ($_para as $key => $para) {
  70. # code...
  71. $query = "SELECT count(*) FROM "._TABLE_USER_WBW_BLOCK_." WHERE channal = ? AND book= ? and paragraph = ? ";
  72. $FetchWBW = PDO_FetchOne($query,array($_channel,$_book,$para));
  73. if($FetchWBW==0){
  74. #建立
  75. //写入数据库
  76. // 开始一个事务,关闭自动提交
  77. #更新block库
  78. $block_id=UUID::v4();
  79. $trans_block_id = UUID::v4();
  80. $block_data = array($block_id,
  81. "",
  82. $_channel,
  83. $_COOKIE["userid"],
  84. $_book,
  85. $para,
  86. "",
  87. $_POST["lang"],
  88. 1,
  89. mTime(),
  90. mTime()
  91. );
  92. $block_list[] = array("channal"=>$_channel,
  93. "type"=>6,//word by word
  94. "book"=>$_book,
  95. "paragraph"=>$para,
  96. "block_id"=>$block_id,
  97. "readonly"=>false
  98. );
  99. $dbh_wbw->beginTransaction();
  100. $query="INSERT INTO "._TABLE_USER_WBW_BLOCK_." ('id',
  101. 'parent_id',
  102. 'channal',
  103. 'owner',
  104. 'book',
  105. 'paragraph',
  106. 'style',
  107. 'lang',
  108. 'status',
  109. 'modify_time',
  110. 'receive_time')
  111. VALUES (? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? )";
  112. $stmt_wbw = $dbh_wbw->prepare($query);
  113. $stmt_wbw->execute($block_data);
  114. // 提交更改
  115. $dbh_wbw->commit();
  116. if (!$stmt_wbw || ($stmt_wbw && $stmt_wbw->errorCode() != 0)) {
  117. $error = $dbh_wbw->errorInfo();
  118. $output["status"]=1;
  119. $output["error"]=$error[2];
  120. echo json_encode($output, JSON_UNESCAPED_UNICODE);
  121. eixt;
  122. }
  123. #逐词解析库
  124. $query="SELECT * FROM 'main' WHERE paragraph = ? ";
  125. $sth = $dbh_tpl->prepare($query);
  126. $sth->execute(array($para));
  127. $level=100;
  128. $title="";
  129. while($result = $sth->fetch(PDO::FETCH_ASSOC))
  130. {
  131. if($result["gramma"]=="?"){
  132. $wGrammar="";
  133. }
  134. else{
  135. $wGrammar=$result["gramma"];
  136. }
  137. $strXml="<word>";
  138. $strXml.="<pali>{$result["word"]}</pali>";
  139. $strXml.="<real>{$result["real"]}</real>";
  140. $wordid = "p{$result["book"]}-{$result["paragraph"]}-{$result["wid"]}";
  141. $strXml.="<id>{$wordid}</id>";
  142. $strXml.="<type s=\"0\">{$result["type"]}</type>";
  143. $strXml.="<gramma s=\"0\">{$wGrammar}</gramma>";
  144. $strXml.="<mean s=\"0\"></mean>";
  145. $strXml.="<org s=\"0\">".mb_strtolower($result["part"], 'UTF-8')."</org>";
  146. $strXml.="<om s=\"0\"></om>";
  147. $strXml.="<case s=\"0\">{$result["type"]}#{$wGrammar}</case>";
  148. $strXml.="<style>{$result["style"]}</style>";
  149. $strXml.="<status>0</status>";
  150. $strXml.="</word>";
  151. $wbw_data[] = array(UUID::v4(),
  152. $block_id,
  153. $_book,
  154. $para,
  155. $result["wid"],
  156. $result["real"],
  157. $strXml,
  158. mTime(),
  159. mTime(),
  160. 1,
  161. $_COOKIE["userid"]
  162. );
  163. }
  164. // 开始一个事务,关闭自动提交
  165. $dbh_wbw->beginTransaction();
  166. $query="INSERT INTO wbw ('id',
  167. 'block_id',
  168. 'book',
  169. 'paragraph',
  170. 'wid',
  171. 'word',
  172. 'data',
  173. 'modify_time',
  174. 'receive_time',
  175. 'status',
  176. 'owner'
  177. )
  178. VALUES (? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? )";
  179. $stmt_wbw = $dbh_wbw->prepare($query);
  180. foreach($wbw_data as $oneParam){
  181. $stmt_wbw->execute($oneParam);
  182. }
  183. // 提交更改
  184. $dbh_wbw->commit();
  185. if (!$stmt_wbw || ($stmt_wbw && $stmt_wbw->errorCode() != 0)) {
  186. $error = $dbh_wbw->errorInfo();
  187. $output["status"]=1;
  188. $output["error"]=$error[2];
  189. echo json_encode($output, JSON_UNESCAPED_UNICODE);
  190. eixt;
  191. }
  192. }
  193. }
  194. /*TO DO
  195. //更新服务器端文件列表
  196. $db_file = _FILE_DB_FILEINDEX_;
  197. PDO_Connect("$db_file");
  198. $query="INSERT INTO fileindex ('id',
  199. 'parent_id',
  200. 'channal',
  201. 'user_id',
  202. 'book',
  203. 'paragraph',
  204. 'file_name',
  205. 'title',
  206. 'tag',
  207. 'status',
  208. 'create_time',
  209. 'modify_time',
  210. 'accese_time',
  211. 'file_size',
  212. 'share',
  213. 'doc_info',
  214. 'doc_block',
  215. 'receive_time'
  216. )
  217. VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
  218. $stmt = $PDO->prepare($query);
  219. $doc_id=UUID::v4();
  220. $file_name = $book . '_' . $create_para . '_' . time();
  221. $newData=array(
  222. $doc_id,
  223. "",
  224. $_POST["channal"],
  225. $uid,
  226. $book,
  227. $create_para,
  228. $file_name,
  229. $user_title,
  230. $tag,
  231. 1,
  232. mTime(),
  233. mTime(),
  234. mTime(),
  235. $filesize,
  236. 0,
  237. $doc_head,
  238. json_encode($block_list, JSON_UNESCAPED_UNICODE),
  239. mTime()
  240. );
  241. $stmt->execute($newData);
  242. if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
  243. $error = PDO_ErrorInfo();
  244. echo "error - $error[2] <br>";
  245. }
  246. else{
  247. echo "成功新建一个文件.";
  248. }
  249. */
  250. echo json_encode($output, JSON_UNESCAPED_UNICODE);
  251. ?>