update_translate.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. </head>
  5. <body>
  6. <h2>Change DB</h2>
  7. <?php
  8. include "./_pdo.php";
  9. include "./config.php";
  10. include "../app/public.inc";
  11. $dbfile=$_GET["file"];
  12. $from=$_GET["from"];
  13. $to=$_GET["to"];
  14. echo "<h2>$from</h2>";
  15. {
  16. $db_file = "../appdata/palicanon/translate/$dbfile.db3";
  17. PDO_Connect("sqlite:$db_file");
  18. $query="select * from album where 1";
  19. $Fetch = PDO_FetchAll($query);
  20. $iFetch=count($Fetch);
  21. echo "找到album记录 $iFetch<br/>";
  22. if($iFetch>0){
  23. for($i=0;$i<$iFetch;$i++){
  24. $album_id=$Fetch[$i]["id"];
  25. $book=$Fetch[$i]["book"];
  26. $guid=$Fetch[$i]["guid"];
  27. $title=$Fetch[$i]["title"];
  28. $file=$Fetch[$i]["file"];
  29. $cover=$Fetch[$i]["cover"];
  30. $language=$Fetch[$i]["language"];
  31. $author=$Fetch[$i]["author"];
  32. $target=$Fetch[$i]["target"];
  33. $summary=$Fetch[$i]["summary"];
  34. $publish_time=$Fetch[$i]["publish_time"];
  35. $update_time=$Fetch[$i]["update_time"];
  36. $edition=$Fetch[$i]["edition"];
  37. $edition1=$Fetch[$i]["edition1"];
  38. $type=$Fetch[$i]["type"];
  39. $db_file = _FILE_DB_PALITEXT_;
  40. PDO_Connect("sqlite:$db_file");
  41. $query="select * from pali_text where book = '{$book}' and level > 0 and level < 8";
  42. $title_data = PDO_FetchAll($query);
  43. echo "par count:".count($title_data)."<br>";
  44. $par_list="";
  45. foreach($title_data as $oneTitle){
  46. $par_list .= " , ".$oneTitle["paragraph"]." ";
  47. }
  48. $par_list = substr($par_list,3);
  49. $db_file = "../appdata/palicanon/translate/$dbfile.db3";
  50. PDO_Connect("sqlite:$db_file");
  51. $query="select * from data where album='$album_id' and paragraph in ($par_list)";
  52. echo $query."<br>";
  53. $paragraph_list = PDO_FetchAll($query);
  54. $db_file =_FILE_DB_RESRES_INDEX_;
  55. PDO_Connect("sqlite:$db_file");
  56. $query="select * from album where guid = '$guid'";
  57. $search_album = PDO_FetchAll($query);
  58. if(count($search_album)==0){
  59. $query="INSERT INTO album (id,
  60. guid,
  61. title,
  62. file,
  63. cover,
  64. language,
  65. author,
  66. target,
  67. summary,
  68. publish_time,
  69. update_time,
  70. edition,
  71. edition1,
  72. type) VALUES (NULL,
  73. '$guid',
  74. '".$title."',
  75. '$file',
  76. '',
  77. '0',
  78. '$author',
  79. '',
  80. '',
  81. '1',
  82. '".time()."',
  83. '1',
  84. '$edition1',
  85. '1')";
  86. $stmt = @PDO_Execute($query);
  87. if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
  88. $error = PDO_ErrorInfo();
  89. print_r($error[2]);
  90. break;
  91. }
  92. //获取刚刚插入的索引号
  93. $album_index=$PDO->lastInsertId();
  94. }
  95. else{
  96. $album_index=$search_album[0]["id"];
  97. $query="UPDATE album SET title = '$title' ,
  98. file = '$file' ,
  99. cover = '$cover' ,
  100. language = '$language' ,
  101. author = '$author' ,
  102. target = '$target' ,
  103. summary = '$summary' ,
  104. publish_time = '$publish_time' ,
  105. update_time = '$update_time' ,
  106. edition = '$edition' ,
  107. edition1 = '$edition1' ,
  108. type = '$type'
  109. WHERE guid='$guid' ";
  110. $stmt = @PDO_Execute($query);
  111. if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
  112. $error = PDO_ErrorInfo();
  113. print_r($error[2]);
  114. break;
  115. }
  116. }
  117. echo "开始更新索引 ".count($paragraph_list)."<br />";
  118. //开始更新索引
  119. for($iPar=0;$iPar<count($paragraph_list);$iPar++){
  120. $oneTitle=$paragraph_list[$iPar];
  121. $query="select * from 'index' where album = '$album_index' and book='".$book."' and paragraph='".$paragraph_list[$iPar]["paragraph"]."'";
  122. $search_title = PDO_FetchAll($query);
  123. $title_en=$oneTitle["text"];
  124. //找到已有的记录 更新
  125. if(count($search_title)!=0){
  126. $query="UPDATE 'index' SET title = '".$oneTitle["text"]."' ,
  127. title_en = '".$title_en."' ,
  128. language = '1' ,
  129. type = '$type',
  130. editor = '1' ,
  131. share = '1' ,
  132. update_time = '".time()."'
  133. WHERE id='".$search_title[0]["id"]."' ";
  134. $stmt = @PDO_Execute($query);
  135. if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
  136. $error = PDO_ErrorInfo();
  137. print_r($error[2]);
  138. break;
  139. }
  140. }
  141. else{/*未找到 插入*/
  142. if(substr($book,0,1)=="b"){
  143. $book=substr($book,1);
  144. }
  145. $query="INSERT INTO 'index' (id,
  146. book,
  147. paragraph,
  148. title,
  149. title_en,
  150. level,
  151. type,
  152. language,
  153. author,
  154. editor,
  155. share,
  156. edition,
  157. album,
  158. update_time)
  159. VALUES (NULL,
  160. '".$book."',
  161. '".$oneTitle["paragraph"]."',
  162. '".$oneTitle["text"]."',
  163. '".$title_en."',
  164. '".$title_data[$iPar]["level"]."',
  165. '$type',
  166. '$language',
  167. '1',
  168. '1',
  169. '1',
  170. '1',
  171. '$album_index',
  172. '".time()."')";
  173. $stmt = @PDO_Execute($query);
  174. if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
  175. $error = PDO_ErrorInfo();
  176. print_r($error[2]);
  177. break;
  178. }
  179. }
  180. }
  181. }
  182. }
  183. echo "insert ok<br>";
  184. }
  185. if($from>=$to){
  186. echo "<h2>齐活!功德无量!all done!</h2>";
  187. }
  188. else{
  189. echo "<script>";
  190. echo "window.location.assign(\"update_translate.php?from=".($from+1)."&to=".$to."\")";
  191. echo "</script>";
  192. echo "正在载入:".($from+1);
  193. }
  194. ?>