create_wbw.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  1. <?php
  2. //工程文件操作
  3. //建立,
  4. include("../log/pref_log.php");
  5. require_once '../config.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. #TODO 查不到数据报错
  142. while($result = $sth->fetch(PDO::FETCH_ASSOC))
  143. {
  144. if($result["gramma"]=="?"){
  145. $wGrammar="";
  146. }
  147. else{
  148. $wGrammar=$result["gramma"];
  149. }
  150. $strXml="<word>";
  151. $strXml.="<pali>{$result["word"]}</pali>";
  152. $strXml.="<real>{$result["real"]}</real>";
  153. $wordid = "p{$result["book"]}-{$result["paragraph"]}-{$result["wid"]}";
  154. $strXml.="<id>{$wordid}</id>";
  155. $strXml.="<type s=\"0\">{$result["type"]}</type>";
  156. $strXml.="<gramma s=\"0\">{$wGrammar}</gramma>";
  157. $strXml.="<mean s=\"0\"></mean>";
  158. $strXml.="<org s=\"0\">".mb_strtolower($result["part"], 'UTF-8')."</org>";
  159. $strXml.="<om s=\"0\"></om>";
  160. $strXml.="<case s=\"0\">{$result["type"]}#{$wGrammar}</case>";
  161. $strXml.="<style>{$result["style"]}</style>";
  162. $strXml.="<status>0</status>";
  163. $strXml.="</word>";
  164. $wbw_data[] = array(UUID::v4(),
  165. $block_id,
  166. $_book,
  167. $para,
  168. $result["wid"],
  169. $result["real"],
  170. $strXml,
  171. mTime(),
  172. mTime(),
  173. 1,
  174. $_COOKIE["userid"]
  175. );
  176. }
  177. // 开始一个事务,关闭自动提交
  178. $dbh_wbw->beginTransaction();
  179. $query="INSERT INTO "._TABLE_USER_WBW_." ('id',
  180. 'block_id',
  181. 'book',
  182. 'paragraph',
  183. 'wid',
  184. 'word',
  185. 'data',
  186. 'modify_time',
  187. 'receive_time',
  188. 'status',
  189. 'owner'
  190. )
  191. VALUES (? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? )";
  192. $stmt_wbw = $dbh_wbw->prepare($query);
  193. foreach($wbw_data as $oneParam){
  194. $stmt_wbw->execute($oneParam);
  195. }
  196. // 提交更改
  197. $dbh_wbw->commit();
  198. if (!$stmt_wbw || ($stmt_wbw && $stmt_wbw->errorCode() != 0)) {
  199. $error = $dbh_wbw->errorInfo();
  200. $output["status"]=1;
  201. $output["error"]=$error[2];
  202. echo json_encode($output, JSON_UNESCAPED_UNICODE);
  203. eixt;
  204. }
  205. }
  206. }
  207. /*TO DO
  208. //更新服务器端文件列表
  209. $db_file = _FILE_DB_FILEINDEX_;
  210. PDO_Connect("$db_file");
  211. $query="INSERT INTO fileindex ('id',
  212. 'parent_id',
  213. 'channal',
  214. 'user_id',
  215. 'book',
  216. 'paragraph',
  217. 'file_name',
  218. 'title',
  219. 'tag',
  220. 'status',
  221. 'create_time',
  222. 'modify_time',
  223. 'accese_time',
  224. 'file_size',
  225. 'share',
  226. 'doc_info',
  227. 'doc_block',
  228. 'receive_time'
  229. )
  230. VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
  231. $stmt = $PDO->prepare($query);
  232. $doc_id=UUID::v4();
  233. $file_name = $book . '_' . $create_para . '_' . time();
  234. $newData=array(
  235. $doc_id,
  236. "",
  237. $_POST["channal"],
  238. $uid,
  239. $book,
  240. $create_para,
  241. $file_name,
  242. $user_title,
  243. $tag,
  244. 1,
  245. mTime(),
  246. mTime(),
  247. mTime(),
  248. $filesize,
  249. 0,
  250. $doc_head,
  251. json_encode($block_list, JSON_UNESCAPED_UNICODE),
  252. mTime()
  253. );
  254. $stmt->execute($newData);
  255. if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
  256. $error = PDO_ErrorInfo();
  257. echo "error - $error[2] <br>";
  258. }
  259. else{
  260. echo "成功新建一个文件.";
  261. }
  262. */
  263. echo json_encode($output, JSON_UNESCAPED_UNICODE);
  264. PrefLog();
  265. ?>