create_wbw.php 11 KB

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