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. $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. PDO_Connect(_FILE_DB_PALICANON_TEMPLET_);
  66. $dbh_tpl = $PDO;
  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. $stmt = $dbh_wbw->prepare($query);
  79. $stmt->execute(array($_channel,$_book,$para));
  80. $row = $stmt->fetch(PDO::FETCH_NUM);
  81. if ($row) {
  82. $FetchWBW = $row[0];
  83. } else {
  84. $FetchWBW = 0;
  85. }
  86. if($FetchWBW == 0){
  87. #建立
  88. //写入数据库
  89. // 开始一个事务,关闭自动提交
  90. #更新block库
  91. $block_id=UUID::v4();
  92. $trans_block_id = UUID::v4();
  93. $block_data = array($block_id,
  94. "",
  95. $_channel,
  96. $_COOKIE["userid"],
  97. $_book,
  98. $para,
  99. "",
  100. $channelInfo["lang"],
  101. $channelInfo["status"],
  102. mTime(),
  103. mTime()
  104. );
  105. $block_list[] = array("channal"=>$_channel,
  106. "type"=>6,//word by word
  107. "book"=>$_book,
  108. "paragraph"=>$para,
  109. "block_id"=>$block_id,
  110. "readonly"=>false
  111. );
  112. $dbh_wbw->beginTransaction();
  113. $query="INSERT INTO "._TABLE_USER_WBW_BLOCK_." ('id',
  114. 'parent_id',
  115. 'channal',
  116. 'owner',
  117. 'book',
  118. 'paragraph',
  119. 'style',
  120. 'lang',
  121. 'status',
  122. 'modify_time',
  123. 'receive_time')
  124. VALUES (? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? )";
  125. $stmt_wbw = $dbh_wbw->prepare($query);
  126. $stmt_wbw->execute($block_data);
  127. // 提交更改
  128. $dbh_wbw->commit();
  129. if (!$stmt_wbw || ($stmt_wbw && $stmt_wbw->errorCode() != 0)) {
  130. $error = $dbh_wbw->errorInfo();
  131. $output["status"]=1;
  132. $output["error"]=$error[2];
  133. echo json_encode($output, JSON_UNESCAPED_UNICODE);
  134. eixt;
  135. }
  136. #逐词解析库
  137. $query="SELECT * FROM "._TABLE_PALICANON_TEMPLET_." WHERE book = ? AND paragraph = ? ";
  138. $sth = $dbh_tpl->prepare($query);
  139. $sth->execute(array($_book,$para));
  140. $level=100;
  141. $title="";
  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. ?>