db_update_toc.php 4.3 KB

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