create_wbw.php 11 KB

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