db_update_toc.php 4.7 KB

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