update_index.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. </head>
  5. <body>
  6. <h2>Update Resouce DataBase</h2>
  7. <?php
  8. include "../public/_pdo.php";
  9. include "../public/config.php";
  10. include "../app/public.inc";
  11. if(isset($_GET["res"])){
  12. $res_type=$_GET["res"];
  13. }
  14. else{
  15. echo "请输入资源类型";
  16. exit;
  17. }
  18. if(isset($_GET["from"])){
  19. $from=$_GET["from"];
  20. }
  21. if(isset($_GET["to"])){
  22. $to=$_GET["to"];
  23. }
  24. switch($res_type){
  25. case "palitext":
  26. echo "<h2>正在处理 - $res_type - $from</h2>";
  27. PDO_Connect("sqlite:"._FILE_DB_PALITEXT_);
  28. $query="select * from pali_text_album where 1";
  29. $Fetch = PDO_FetchAll($query);
  30. $iFetch=count($Fetch);
  31. echo "找到album记录 $iFetch<br/>";
  32. if($iFetch>0 && $from<$iFetch){
  33. $i=$from;
  34. {
  35. $album_id=$Fetch[$i]["id"];
  36. $guid=$Fetch[$i]["guid"];
  37. $title=$Fetch[$i]["title"];
  38. $file=_FILE_DB_PALITEXT_;
  39. $cover=$Fetch[$i]["cover"];
  40. $language=$Fetch[$i]["language"];
  41. $author=$Fetch[$i]["author"];
  42. $target=$Fetch[$i]["target"];
  43. $summary=$Fetch[$i]["summary"];
  44. $publish_time=$Fetch[$i]["publish_time"];
  45. $update_time=$Fetch[$i]["update_time"];
  46. $edition=$Fetch[$i]["edition"];
  47. $edition1=$Fetch[$i]["edition_text"];
  48. $type=$Fetch[$i]["type"];
  49. PDO_Connect("sqlite:"._FILE_DB_PALITEXT_);
  50. $query="select * from pali_text where album_index='$album_id' ";
  51. $title_data = PDO_FetchAll($query);
  52. echo "Paragraph Count:".count($title_data)."<br>";
  53. $query="select count(*) from pali_text where album_index='$album_id'";
  54. $paragraph_count = PDO_FetchOne($query);
  55. // 开始一个事务,关闭自动提交
  56. $PDO->beginTransaction();
  57. $query ="UPDATE pali_text SET chapter_len = ? , next_chapter = ?, prev_chapter=? , parent= ? WHERE book=? and paragraph=?";
  58. $stmt = $PDO->prepare($query);
  59. $paragraph_info = array();
  60. array_push($paragraph_info,array($from,-1,$paragraph_count,-1,-1,-1));
  61. for($iPar=0;$iPar < count($title_data); $iPar++){
  62. $book=$from+1;
  63. $paragraph=$title_data[$iPar]["paragraph"];
  64. if($title_data[$iPar]["level"]==8){
  65. $title_data[$iPar]["level"]=100;
  66. }
  67. $curr_level=$title_data[$iPar]["level"];
  68. $length=-1;
  69. for($iPar1=$iPar+1;$iPar1<count($title_data); $iPar1++){
  70. if($title_data[$iPar1]["level"]<=$curr_level){
  71. $length=$title_data[$iPar1]["paragraph"]-$paragraph;
  72. break;
  73. }
  74. }
  75. if($length==-1){
  76. $length=$paragraph_count-$paragraph+1;
  77. }
  78. $prev=-1;
  79. if($iPar>0){
  80. for($iPar1=$iPar-1;$iPar1>=0; $iPar1--){
  81. if($title_data[$iPar1]["level"]==$curr_level){
  82. $prev=$title_data[$iPar1]["paragraph"];
  83. break;
  84. }
  85. }
  86. }
  87. $next=-1;
  88. if($iPar<count($title_data)-1){
  89. for($iPar1=$iPar+1;$iPar1<count($title_data); $iPar1++){
  90. if($title_data[$iPar1]["level"]==$curr_level){
  91. $next=$title_data[$iPar1]["paragraph"];
  92. break;
  93. }
  94. }
  95. }
  96. $parent=-1;
  97. if($iPar>0){
  98. for($iPar1=$iPar-1;$iPar1>=0; $iPar1--){
  99. if($title_data[$iPar1]["level"]<$curr_level){
  100. $parent=$title_data[$iPar1]["paragraph"];
  101. break;
  102. }
  103. }
  104. }
  105. $newData=array($length,
  106. $next,
  107. $prev,
  108. $parent,
  109. $book,
  110. $paragraph);
  111. $stmt->execute($newData);
  112. if($curr_level>0 && $curr_level<8){
  113. array_push($paragraph_info,array($book,$paragraph,$length,$prev,$next,$parent));
  114. }
  115. //echo "<tr><td>$book</td><td>$paragraph</td><td>$curr_level</td><td>$length</td><td>$prev</td><td>$next</td><td>$parent</td></tr>";
  116. }
  117. // 提交更改
  118. $PDO->commit();
  119. if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
  120. $error = PDO_ErrorInfo();
  121. echo "error - $error[2] <br>";
  122. $log=$log."$from, $FileName, error, $error[2] \r\n";
  123. }
  124. else{
  125. $count=count($title_data);
  126. echo "updata $count paragraph info recorders.<br>";
  127. echo count($paragraph_info)." Heading<br>";
  128. }
  129. /*
  130. */
  131. $db_file = _FILE_DB_RESRES_INDEX_;
  132. PDO_Connect("sqlite:$db_file");
  133. $query="select * from album where guid = '$guid'";
  134. $search_album = PDO_FetchAll($query);
  135. if(count($search_album)==0){
  136. $query="INSERT INTO album (id,
  137. guid,
  138. title,
  139. file,
  140. cover,
  141. language,
  142. author,
  143. target,
  144. summary,
  145. publish_time,
  146. update_time,
  147. edition,
  148. edition1,
  149. type) VALUES (NULL,
  150. '$guid',
  151. '".$title."',
  152. '$file',
  153. '',
  154. '0',
  155. 'VRI',
  156. '',
  157. '',
  158. '1',
  159. '".time()."',
  160. '1',
  161. 'CSCD4',
  162. '1')";
  163. $stmt = @PDO_Execute($query);
  164. if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
  165. $error = PDO_ErrorInfo();
  166. print_r($error[2]);
  167. break;
  168. }
  169. //获取刚刚插入的索引号
  170. $album_index=$PDO->lastInsertId();
  171. }
  172. else{
  173. $album_index=$search_album[0]["id"];
  174. $query="UPDATE album SET title = '$title' ,
  175. file = '$file' ,
  176. cover = '$cover' ,
  177. language = '$language' ,
  178. author = '$author' ,
  179. target = '$target' ,
  180. summary = '$summary' ,
  181. publish_time = '$publish_time' ,
  182. update_time = '$update_time' ,
  183. edition = '$edition' ,
  184. edition1 = '$edition1' ,
  185. type = '$type'
  186. WHERE guid='$guid' ";
  187. $stmt = @PDO_Execute($query);
  188. if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
  189. $error = PDO_ErrorInfo();
  190. print_r($error[2]);
  191. break;
  192. }
  193. }
  194. echo "开始更新索引 ",count($title_data),"<br />";
  195. //开始更新索引
  196. foreach($title_data as $oneTitle){
  197. if($oneTitle["level"]>0 && $oneTitle["level"]<8){
  198. $query="select * from 'index' where album = '$album_index' and book='".$oneTitle["book"]."' and paragraph='".$oneTitle["paragraph"]."'";
  199. $search_title = PDO_FetchAll($query);
  200. $title_en=pali2english($oneTitle["text"]);
  201. //找到已有的记录 更新
  202. if(count($search_title)!=0){
  203. $query="UPDATE 'index' SET title = '".$oneTitle["text"]."' ,
  204. title_en = '".$title_en."' ,
  205. language = '1' ,
  206. type = '$type',
  207. editor = '1' ,
  208. share = '1' ,
  209. update_time = '".time()."'
  210. WHERE id='".$search_title[0]["id"]."' ";
  211. $stmt = @PDO_Execute($query);
  212. if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
  213. $error = PDO_ErrorInfo();
  214. print_r($error[2]);
  215. break;
  216. }
  217. }
  218. else{
  219. /*未找到 插入*/
  220. $book=$oneTitle["book"];
  221. if(substr($book,0,1)=="b"){
  222. $book=substr($book,1);
  223. }
  224. $query="INSERT INTO 'index' (id,
  225. book,
  226. paragraph,
  227. title,
  228. title_en,
  229. level,
  230. type,
  231. language,
  232. author,
  233. editor,
  234. share,
  235. edition,
  236. album,
  237. update_time)
  238. VALUES (NULL,
  239. '".$book."',
  240. '".$oneTitle["paragraph"]."',
  241. '".$oneTitle["text"]."',
  242. '".$title_en."',
  243. '".$oneTitle["level"]."',
  244. '1',
  245. '1',
  246. '5',
  247. '1',
  248. '1',
  249. '1',
  250. '$album_index',
  251. '".time()."')";
  252. $stmt = @PDO_Execute($query);
  253. if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
  254. $error = PDO_ErrorInfo();
  255. print_r($error[2]);
  256. break;
  257. }
  258. }
  259. }
  260. }
  261. foreach($paragraph_info as $onePar){
  262. $query="select * from 'paragraph_info' where book='".$onePar[0]."' and paragraph='".$onePar[1]."'";
  263. $search_par = PDO_FetchAll($query);
  264. //找到已有的记录 更新
  265. if(count($search_par)!=0){
  266. $query="UPDATE 'paragraph_info' SET length = '".$onePar[2]."' ,
  267. prev = '".$onePar[3]."' ,
  268. next = '".$onePar[4]."' ,
  269. parent = '".$onePar[5]."'
  270. WHERE id='".$search_par[0]["id"]."' ";
  271. $stmt = @PDO_Execute($query);
  272. if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
  273. $error = PDO_ErrorInfo();
  274. print_r($error[2]);
  275. break;
  276. }
  277. }
  278. else{
  279. //未找到 插入
  280. $query="INSERT INTO 'paragraph_info' (id,
  281. book,
  282. paragraph,
  283. length,
  284. prev,
  285. next,
  286. parent)
  287. VALUES (NULL,
  288. '".$onePar[0]."',
  289. '".$onePar[1]."',
  290. '".$onePar[2]."',
  291. '".$onePar[3]."',
  292. '".$onePar[4]."',
  293. '".$onePar[5]."')";
  294. $stmt = @PDO_Execute($query);
  295. if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
  296. $error = PDO_ErrorInfo();
  297. print_r($error[2]);
  298. break;
  299. }
  300. }
  301. }
  302. }
  303. }
  304. echo "insert ok<br>";
  305. if($from>=$to){
  306. echo "<h2>齐活!功德无量!all done!</h2>";
  307. }
  308. else{
  309. echo "<script>";
  310. echo "window.location.assign(\"update_index.php?res=palitext&from=".($from+1)."&to=".$to."\")";
  311. echo "</script>";
  312. echo "正在载入:".($from+1);
  313. }
  314. break;
  315. case "heading":
  316. break;
  317. case "album":
  318. $db_file = _FILE_DB_RESRES_INDEX_;
  319. PDO_Connect("sqlite:$db_file");
  320. $query="select * from album where 1";
  321. $search_album = PDO_FetchAll($query);
  322. foreach($search_album as $oneAlbum){
  323. $query="select id from 'index' where album = '{$oneAlbum["id"]}' and
  324. book='{$oneAlbum["book"]}' and
  325. paragraph='-1'";
  326. $id = PDO_FetchAll($query);
  327. //找到已有的记录 更新
  328. $title_en=pali2english($oneAlbum["title"]);
  329. if(count($id)>0){
  330. $query="UPDATE 'index' SET title = '{$oneAlbum["title"]}' ,
  331. title_en = '{$title_en}' ,
  332. language = '{$oneAlbum["language"]}' ,
  333. type = '{$oneAlbum["type"]}',
  334. editor = '1' ,
  335. share = '1' ,
  336. update_time = '".time()."'
  337. WHERE id='{$id[0]["id"]}' ";
  338. $stmt = @PDO_Execute($query);
  339. if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
  340. $error = PDO_ErrorInfo();
  341. print_r($error[2]);
  342. break;
  343. }
  344. else{
  345. echo "Updae记录成功。{$oneAlbum["title"]} <br />";
  346. }
  347. }
  348. else{
  349. /*未找到 插入*/
  350. $book=$oneAlbum["book"];
  351. $query="INSERT INTO 'index' (id,
  352. book,
  353. paragraph,
  354. title,
  355. title_en,
  356. level,
  357. type,
  358. language,
  359. author,
  360. editor,
  361. share,
  362. edition,
  363. album,
  364. update_time)
  365. VALUES (NULL,
  366. '".$book."',
  367. '-1',
  368. '{$oneAlbum["title"]}',
  369. '{$title_en}',
  370. '-1',
  371. '{$oneAlbum["type"]}',
  372. '{$oneAlbum["language"]}',
  373. '{$oneAlbum["author"]}',
  374. '1',
  375. '1',
  376. '{$oneAlbum["edition"]}',
  377. '{$oneAlbum["id"]}',
  378. '".time()."')";
  379. $stmt = @PDO_Execute($query);
  380. if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
  381. $error = PDO_ErrorInfo();
  382. print_r($error[2]);
  383. break;
  384. }
  385. else{
  386. echo "新建记录成功。{$oneAlbum["title"]} <br />";
  387. }
  388. }
  389. }
  390. break;
  391. case "translation":
  392. break;
  393. case "note":
  394. break;
  395. }
  396. ?>