create_wbw.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  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. /* 创建一个填充了和 _para 相同数量占位符的字符串 */
  49. $place_holders = implode(',', array_fill(0, count($_para), '?'));
  50. $query = "SELECT sum(lenght) FROM _TABLE_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. PDO_Connect(_FILE_DB_PALICANON_TEMPLET_);
  65. $dbh_tpl = $PDO;
  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, _DB_USERNAME_, _DB_PASSWORD_);
  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. $stmt = $dbh_wbw->prepare($query);
  78. $stmt->execute(array($_channel,$_book,$para));
  79. $row = $stmt->fetch(PDO::FETCH_NUM);
  80. if ($row) {
  81. $FetchWBW = $row[0];
  82. } else {
  83. $FetchWBW = 0;
  84. }
  85. if($FetchWBW == 0){
  86. #建立
  87. //写入数据库
  88. // 开始一个事务,关闭自动提交
  89. #更新block库
  90. $block_id=UUID::v4();
  91. $trans_block_id = UUID::v4();
  92. $block_data = array($block_id,
  93. "",
  94. $_channel,
  95. $_COOKIE["userid"],
  96. $_book,
  97. $para,
  98. "",
  99. $channelInfo["lang"],
  100. $channelInfo["status"],
  101. mTime(),
  102. mTime()
  103. );
  104. $block_list[] = array("channal"=>$_channel,
  105. "type"=>6,//word by word
  106. "book"=>$_book,
  107. "paragraph"=>$para,
  108. "block_id"=>$block_id,
  109. "readonly"=>false
  110. );
  111. $dbh_wbw->beginTransaction();
  112. $query="INSERT INTO "._TABLE_USER_WBW_BLOCK_." ('id',
  113. 'parent_id',
  114. 'channal',
  115. 'owner',
  116. 'book',
  117. 'paragraph',
  118. 'style',
  119. 'lang',
  120. 'status',
  121. 'modify_time',
  122. 'receive_time')
  123. VALUES (? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? )";
  124. $stmt_wbw = $dbh_wbw->prepare($query);
  125. $stmt_wbw->execute($block_data);
  126. // 提交更改
  127. $dbh_wbw->commit();
  128. if (!$stmt_wbw || ($stmt_wbw && $stmt_wbw->errorCode() != 0)) {
  129. $error = $dbh_wbw->errorInfo();
  130. $output["status"]=1;
  131. $output["error"]=$error[2];
  132. echo json_encode($output, JSON_UNESCAPED_UNICODE);
  133. eixt;
  134. }
  135. #逐词解析库
  136. $query="SELECT * FROM "._TABLE_PALICANON_TEMPLET_." WHERE book = ? AND paragraph = ? ";
  137. $sth = $dbh_tpl->prepare($query);
  138. $sth->execute(array($_book,$para));
  139. $level=100;
  140. $title="";
  141. while($result = $sth->fetch(PDO::FETCH_ASSOC))
  142. {
  143. if($result["gramma"]=="?"){
  144. $wGrammar="";
  145. }
  146. else{
  147. $wGrammar=$result["gramma"];
  148. }
  149. $strXml="<word>";
  150. $strXml.="<pali>{$result["word"]}</pali>";
  151. $strXml.="<real>{$result["real"]}</real>";
  152. $wordid = "p{$result["book"]}-{$result["paragraph"]}-{$result["wid"]}";
  153. $strXml.="<id>{$wordid}</id>";
  154. $strXml.="<type s=\"0\">{$result["type"]}</type>";
  155. $strXml.="<gramma s=\"0\">{$wGrammar}</gramma>";
  156. $strXml.="<mean s=\"0\"></mean>";
  157. $strXml.="<org s=\"0\">".mb_strtolower($result["part"], 'UTF-8')."</org>";
  158. $strXml.="<om s=\"0\"></om>";
  159. $strXml.="<case s=\"0\">{$result["type"]}#{$wGrammar}</case>";
  160. $strXml.="<style>{$result["style"]}</style>";
  161. $strXml.="<status>0</status>";
  162. $strXml.="</word>";
  163. $wbw_data[] = array(UUID::v4(),
  164. $block_id,
  165. $_book,
  166. $para,
  167. $result["wid"],
  168. $result["real"],
  169. $strXml,
  170. mTime(),
  171. mTime(),
  172. 1,
  173. $_COOKIE["userid"]
  174. );
  175. }
  176. // 开始一个事务,关闭自动提交
  177. $dbh_wbw->beginTransaction();
  178. $query="INSERT INTO "._TABLE_USER_WBW_." ('id',
  179. 'block_id',
  180. 'book',
  181. 'paragraph',
  182. 'wid',
  183. 'word',
  184. 'data',
  185. 'modify_time',
  186. 'receive_time',
  187. 'status',
  188. 'owner'
  189. )
  190. VALUES (? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? )";
  191. $stmt_wbw = $dbh_wbw->prepare($query);
  192. foreach($wbw_data as $oneParam){
  193. $stmt_wbw->execute($oneParam);
  194. }
  195. // 提交更改
  196. $dbh_wbw->commit();
  197. if (!$stmt_wbw || ($stmt_wbw && $stmt_wbw->errorCode() != 0)) {
  198. $error = $dbh_wbw->errorInfo();
  199. $output["status"]=1;
  200. $output["error"]=$error[2];
  201. echo json_encode($output, JSON_UNESCAPED_UNICODE);
  202. eixt;
  203. }
  204. }
  205. }
  206. /*TO DO
  207. //更新服务器端文件列表
  208. $db_file = _FILE_DB_FILEINDEX_;
  209. PDO_Connect("$db_file");
  210. $query="INSERT INTO fileindex ('id',
  211. 'parent_id',
  212. 'channal',
  213. 'user_id',
  214. 'book',
  215. 'paragraph',
  216. 'file_name',
  217. 'title',
  218. 'tag',
  219. 'status',
  220. 'create_time',
  221. 'modify_time',
  222. 'accese_time',
  223. 'file_size',
  224. 'share',
  225. 'doc_info',
  226. 'doc_block',
  227. 'receive_time'
  228. )
  229. VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
  230. $stmt = $PDO->prepare($query);
  231. $doc_id=UUID::v4();
  232. $file_name = $book . '_' . $create_para . '_' . time();
  233. $newData=array(
  234. $doc_id,
  235. "",
  236. $_POST["channal"],
  237. $uid,
  238. $book,
  239. $create_para,
  240. $file_name,
  241. $user_title,
  242. $tag,
  243. 1,
  244. mTime(),
  245. mTime(),
  246. mTime(),
  247. $filesize,
  248. 0,
  249. $doc_head,
  250. json_encode($block_list, JSON_UNESCAPED_UNICODE),
  251. mTime()
  252. );
  253. $stmt->execute($newData);
  254. if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
  255. $error = PDO_ErrorInfo();
  256. echo "error - $error[2] <br>";
  257. }
  258. else{
  259. echo "成功新建一个文件.";
  260. }
  261. */
  262. echo json_encode($output, JSON_UNESCAPED_UNICODE);
  263. PrefLog();
  264. ?>