function.php 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. <?php
  2. function update_historay($sent_id, $user_id, $text, $landmark)
  3. {
  4. # 更新historay
  5. PDO_Connect("" . _FILE_DB_USER_SENTENCE_HISTORAY_);
  6. $query = "INSERT INTO sent_historay (sent_id, user_id, text, date, landmark) VALUES (? , ? , ? , ? , ? )";
  7. $stmt = PDO_Execute($query,
  8. array($sent_id,
  9. $user_id,
  10. $text,
  11. mTime(),
  12. $landmark,
  13. ));
  14. if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
  15. /* 识别错误 */
  16. $error = PDO_ErrorInfo();
  17. return $error[2];
  18. } else {
  19. #没错误
  20. return "";
  21. }
  22. }
  23. class Sent_DB
  24. {
  25. public $dbh_sent;
  26. public $dbh_his;
  27. private $errorMsg="";
  28. public function __construct() {
  29. $this->dbh_sent = new PDO(_FILE_DB_SENTENCE_, "", "",array(PDO::ATTR_PERSISTENT=>true));
  30. $this->dbh_sent->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
  31. $this->dbh_his = new PDO(_FILE_DB_USER_SENTENCE_HISTORAY_, "", "",array(PDO::ATTR_PERSISTENT=>true));
  32. $this->dbh_his->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
  33. }
  34. public function getError(){
  35. return $errorMsg;
  36. }
  37. public function update($arrData){
  38. /* 修改现有数据 */
  39. if (count($arrData) > 0) {
  40. //add_edit_event(_SENT_EDIT_, "{$oldList[0]["book"]}-{$oldList[0]["paragraph"]}-{$oldList[0]["begin"]}-{$oldList[0]["end"]}@{$oldList[0]["channal"]}");
  41. $this->dbh_sent->beginTransaction();
  42. $query = "UPDATE sentence SET text = ? , strlen = ? , editor=?, modify_time= ? where id= ? ";
  43. $sth = $this->dbh_sent->prepare($query);
  44. foreach ($arrData as $data) {
  45. $sth->execute(array($data["text"],mb_strlen($data["text"],"UTF-8"),$data["editor"],mTime(),$data["id"]));
  46. }
  47. $this->dbh_sent->commit();
  48. if (!$sth || ($sth && $sth->errorCode() != 0)) {
  49. /* 识别错误且回滚更改 */
  50. $this->dbh_sent->rollBack();
  51. $error = $this->dbh_sent->errorInfo();
  52. $this->errorMsg = $error[2];
  53. return false;
  54. } else {
  55. #没错误 添加log
  56. $this->errorMsg = "";
  57. return true;
  58. }
  59. }
  60. else{
  61. $this->errorMsg = "";
  62. return true;
  63. }
  64. }
  65. public function insert($arrData){
  66. /* 插入新数据 */
  67. //查询channel语言
  68. if (count($arrData) > 0) {
  69. //add_edit_event(_SENT_NEW_, "{$newList[0]["book"]}-{$newList[0]["paragraph"]}-{$newList[0]["begin"]}-{$newList[0]["end"]}@{$newList[0]["channal"]}");
  70. $this->dbh_sent->beginTransaction();
  71. $query = "INSERT INTO sentence (id,
  72. parent,
  73. book,
  74. paragraph,
  75. begin,
  76. end,
  77. channal,
  78. tag,
  79. author,
  80. editor,
  81. text,
  82. language,
  83. ver,
  84. status,
  85. strlen,
  86. modify_time,
  87. receive_time,
  88. create_time
  89. )
  90. VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? )";
  91. $sth = $this->dbh_sent->prepare($query);
  92. $channel_info = new Channal();
  93. foreach ($arrData as $data) {
  94. if($data["id"]==""){
  95. $data["id"] = UUID::v4();
  96. }
  97. $queryChannel = $channel_info->getChannal($data["channal"]);
  98. if ($queryChannel == false) {
  99. $lang = $data["language"];
  100. $status = 10;
  101. } else {
  102. $lang = $queryChannel["lang"];
  103. $status = $queryChannel["status"];
  104. }
  105. $sth->execute(array($data["id"],
  106. isset($data["parent"]) ? $data["parent"] : "",
  107. $data["book"],
  108. $data["paragraph"],
  109. $data["begin"],
  110. $data["end"],
  111. $data["channal"],
  112. isset($data["tag"]) ? $data["tag"] : "",
  113. $data["author"],
  114. $data["editor"],
  115. $data["text"],
  116. $lang,
  117. 1,
  118. $status,
  119. mb_strlen($data["text"], "UTF-8"),
  120. mTime(),
  121. mTime(),
  122. mTime(),
  123. ));
  124. }
  125. $this->dbh_sent->commit();
  126. if (!$sth || ($sth && $sth->errorCode() != 0)) {
  127. /* 识别错误且回滚更改 */
  128. $this->dbh_sent->rollBack();
  129. $error = $this->dbh_sent->errorInfo();
  130. $this->errorMsg = $error[2];
  131. return false;
  132. } else {
  133. $this->errorMsg = "";
  134. return true;
  135. }
  136. }
  137. else{
  138. $this->errorMsg = "";
  139. return true;
  140. }
  141. }
  142. public function send_pr($arrData){
  143. if (count($arrData) ==0) {
  144. $this->errorMsg = "";
  145. return true;
  146. }
  147. $this->dbh_sent->beginTransaction();
  148. $query = "INSERT INTO sent_pr (id,
  149. book,
  150. paragraph,
  151. begin,
  152. end,
  153. channel,
  154. tag,
  155. author,
  156. editor,
  157. text,
  158. language,
  159. status,
  160. strlen,
  161. modify_time,
  162. receive_time,
  163. create_time
  164. )
  165. VALUES (NULL, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? )";
  166. $stmt = $this->dbh_sent->prepare($query);
  167. foreach ($arrData as $data) {
  168. # 初始状态 1 未处理
  169. $stmt->execute(array(
  170. $data["book"],
  171. $data["para"],
  172. $data["begin"],
  173. $data["end"],
  174. $data["channal"],
  175. "",
  176. "[]",
  177. $data["editor"],
  178. $data["text"],
  179. $data["language"],
  180. 1,
  181. mb_strlen($data["text"], "UTF-8"),
  182. mTime(),
  183. mTime(),
  184. mTime(),
  185. ));
  186. }
  187. $this->dbh_sent->commit();
  188. if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
  189. # 识别错误
  190. $this->dbh_sent->rollBack();
  191. $error = $this->dbh_sent->errorInfo();
  192. $this->errorMsg = $error[2];
  193. return false;
  194. } else {
  195. # 没错误
  196. $this->errorMsg = "";
  197. return true;
  198. }
  199. }
  200. public function historay($arrData)
  201. {
  202. if (count($arrData) ==0) {
  203. $this->errorMsg = "";
  204. return true;
  205. }
  206. $this->dbh_his->beginTransaction();
  207. # 更新historay
  208. $query = "INSERT INTO sent_historay (sent_id, user_id, text, date, landmark) VALUES (? , ? , ? , ? , ? )";
  209. $stmt = $this->dbh_his->prepare($query);
  210. foreach ($arrData as $data) {
  211. $stmt->execute(array($data["id"],
  212. $data["editor"],
  213. $data["text"],
  214. mTime(),
  215. $data["landmark"]));
  216. }
  217. if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
  218. /* 识别错误 */
  219. $this->dbh_sent->rollBack();
  220. $error = $this->dbh_sent->errorInfo();
  221. $this->errorMsg = $error[2];
  222. return false;
  223. } else {
  224. #没错误
  225. $this->errorMsg = "";
  226. return true;
  227. }
  228. }
  229. }