db_update_toc.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. <?php
  2. require_once "install_head.php";
  3. require_once '../path.php';
  4. require_once "../public/_pdo.php";
  5. require_once "../public/function.php";
  6. function getWordEn($strIn){
  7. $strIn = strtolower($strIn);
  8. $search = array('ā', 'ī', 'ū', 'ṅ', 'ñ' , 'ṭ', 'ḍ', 'ṇ', 'ḷ', 'ṃ');
  9. $replace = array('a', 'i', 'u', 'n', 'n' , 't', 'd', 'n', 'l', 'm');
  10. return(str_replace($search,$replace,$strIn));
  11. }
  12. ?>
  13. <!DOCTYPE html>
  14. <html>
  15. <head>
  16. </head>
  17. <body>
  18. <h2>Update Table of Contence</h2>
  19. <?php
  20. if(isset($_GET["from"])==false){
  21. ?>
  22. <form action="db_update_toc.php" method="get">
  23. From: <input type="text" name="from" value="0"><br>
  24. To: <input type="text" name="to" value="216"><br>
  25. File: <input type="text" name="file" value="title"><br>
  26. Author: <input type="text" name="author" value=""><br>
  27. Language:
  28. <select name="lang">
  29. <option value="1">pali</option>
  30. <option value="2">English</option>
  31. <option value="3">简体中文</option>
  32. <option value="4">繁体中文</option>
  33. </select>
  34. <br>
  35. <input type="submit">
  36. </form>
  37. <?php
  38. return;
  39. }
  40. $from=$_GET["from"];
  41. $to=$_GET["to"];
  42. $_file=$_GET["file"];
  43. $_author=$_GET["author"];
  44. $_lang=$_GET["lang"];
  45. $filelist=array();
  46. $fileNums=0;
  47. $log="";
  48. echo "<h2>$from</h2>";
  49. if(($handle=fopen("filelist.csv",'r'))!==FALSE){
  50. while(($filelist[$fileNums]=fgetcsv($handle,0,','))!==FALSE){
  51. $fileNums++;
  52. }
  53. }
  54. if($to==0 || $to>=$fileNums) $to=$fileNums-1;
  55. $FileName=$filelist[$from][1].".htm";
  56. $fileId=$filelist[$from][0];
  57. $fileId=$filelist[$from][0];
  58. $dirLog=_DIR_LOG_."/";
  59. $dirDb="/";
  60. $inputFileName=$FileName;
  61. $outputFileNameHead=$filelist[$from][1];
  62. $bookId=$filelist[$from][2];
  63. $vriParNum=0;
  64. $wordOrder=1;
  65. $dirXmlBase=_DIR_PALI_CSV_."/";
  66. $dirPaliTextBase=_DIR_PALI_HTML_."/";
  67. $dirXml=$outputFileNameHead."/";
  68. $xmlfile = $inputFileName;
  69. $log=$log.date("Y-m-d h:i:sa").",$from,$FileName,open\r\n";
  70. $arrInserString=array();
  71. // 打开csv文件并读取数据
  72. $inputRow=0;
  73. if(($fp=fopen(_DIR_PALI_TITLE_."/".($from+1)."_{$_file}.csv", "r"))!==FALSE){
  74. while(($data=fgetcsv($fp,0,','))!==FALSE){
  75. if($inputRow>0 && $data[3] != 100 && !empty($data[6])){
  76. array_push($arrInserString,$data);
  77. }
  78. $inputRow++;
  79. }
  80. fclose($fp);
  81. echo "res load:"._DIR_PALI_TITLE_."/".($from+1)."_title.csv<br>";
  82. }
  83. else{
  84. echo "can not open csv ";
  85. if($from==$to){
  86. echo "<h2>齐活!功德无量!all done!</h2>";
  87. }
  88. else{
  89. echo "<script>";
  90. $next = $from+1;
  91. echo "window.location.assign(\"db_update_toc.php?from={$next}&to={$to}&file={$_file}&author={$_author}&lang={$_lang}\")";
  92. echo "</script>";
  93. echo "正在载入:".($from+1);
  94. echo "</body></html>";
  95. exit;
  96. }
  97. }
  98. $book=$from+1;
  99. //删除已有标题
  100. PDO_Connect("sqlite:"._FILE_DB_RESRES_INDEX_);
  101. $query =" DELETE FROM 'index' WHERE book ='{$book}' AND language = '{$_lang}' ";
  102. $PDO->query($query);
  103. // 开始一个事务,关闭自动提交
  104. $PDO->beginTransaction();
  105. $query="INSERT INTO 'index' ('id','book','paragraph','title','title_en' ,'level','type','language','author','share','create_time','update_time' ) VALUES ( NULL , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? )";
  106. $stmt = $PDO->prepare($query);
  107. if($_lang=="1"){
  108. $type=1;
  109. }
  110. else{
  111. $type=2;
  112. }
  113. foreach($arrInserString as $title){
  114. $newData=array(
  115. $book,
  116. $title[2],
  117. $title[6],
  118. getWordEn($title[6]),
  119. $title[3],
  120. $type,
  121. $_lang,
  122. $_author,
  123. 1,
  124. mTime(),
  125. mTime()
  126. );
  127. $stmt->execute($newData);
  128. }
  129. // 提交更改
  130. $PDO->commit();
  131. if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
  132. $error = PDO_ErrorInfo();
  133. echo "error - $error[2] <br>";
  134. $log=$log."$from, error, $error[2] \r\n";
  135. }
  136. else{
  137. $count=count($arrInserString);
  138. echo "updata $count title recorders.<br>";
  139. }
  140. //段落信息结束
  141. $myLogFile = fopen(_DIR_LOG_."/db_update_toc.log", "a");
  142. fwrite($myLogFile, $log);
  143. fclose($myLogFile);
  144. ?>
  145. <?php
  146. if($from==$to){
  147. echo "<h2>齐活!功德无量!all done!</h2>";
  148. }
  149. else{
  150. echo "<script>";
  151. $next = $from+1;
  152. echo "window.location.assign(\"db_update_toc.php?from={$next}&to={$to}&file={$_file}&author={$_author}&lang={$_lang}\")";
  153. echo "</script>";
  154. echo "正在载入:".($from+1)."——".$filelist[$from+1][0];
  155. }
  156. ?>
  157. </body>
  158. </html>