step3.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. <?php
  2. require_once "install_head.php";
  3. require_once '../pcdl/html_head.php';
  4. ?>
  5. <body>
  6. <style>
  7. #step3{
  8. background-color: #f1e7a4;
  9. }
  10. body{
  11. font-size:unset;
  12. }
  13. </style>
  14. <?php
  15. require_once 'nav_bar.php';
  16. ?>
  17. <div style="margin:1em;background-color:#f1e7a4;">
  18. 生成字典数据库。约需要10分钟。
  19. </div>
  20. <div>
  21. <?php
  22. $dbfile[] = array(_FILE_DB_REF_, "ref.sql");
  23. $dbfile[] = array(_FILE_DB_REF_INDEX_, "ref_index.sql");
  24. $dir = "./refdict_db/";
  25. if (isset($_GET["index"])) {
  26. echo '<div style="padding:10px;margin:5px;border-bottom: 1px solid gray;background-color:yellow;">';
  27. $index = $_GET["index"];
  28. $dns = "" . $dbfile[$index][0];
  29. $dbh = new PDO($dns, "", "", array(PDO::ATTR_PERSISTENT => true));
  30. $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
  31. //建立数据库
  32. $_sql = file_get_contents($dir . $dbfile[$index][1]);
  33. $_arr = explode(';', $_sql);
  34. //执行sql语句
  35. foreach ($_arr as $_value) {
  36. $dbh->query($_value . ';');
  37. }
  38. echo $dns . "建立数据库成功";
  39. echo "</div>";
  40. }
  41. for ($i = 0; $i < count($dbfile); $i++) {
  42. $db = $dbfile[$i];
  43. echo '<div style="padding:10px;margin:5px;border-bottom: 1px solid gray;display:flex;">';
  44. echo '<div style="flex:5;">' . $db[0] . '</div>';
  45. echo '<div style="flex:3;">';
  46. if (!file_exists($db[0])) {
  47. echo "<span style='color:red;'>数据库不存在</span>";
  48. echo "</div>";
  49. echo '<div style="flex:2;"><a href="step3.php?index=' . $i . '">建立</a></div>';
  50. } else {
  51. echo "<span style='color:green;'>已存在</span>";
  52. echo "</div>";
  53. echo '<div style="flex:2;"><a href="step3.php?index=' . $i . '">重建</a><span style="color:red;">注意!此操作将删除原数据库中所有数据!</span></div>';
  54. }
  55. echo "</div>";
  56. }
  57. ?>
  58. </div>
  59. <div id="response"></div>
  60. <script>
  61. <?php
  62. echo "var rich_file_list = new Array();\n";
  63. $filelist = array();
  64. if (($handle = fopen(_DIR_DICT_TEXT_ . '/rich/list.txt', 'r')) !== false) {
  65. while (($data = fgetcsv($handle, 0, ',')) !== false) {
  66. $filelist[] = $data;
  67. }
  68. foreach ($filelist as $value) {
  69. echo "rich_file_list.push(['{$value[0]}','{$value[1]}']);\n";
  70. }
  71. } else {
  72. // exit("无法打开rich文件列表");
  73. }
  74. echo "var sys_file_list = new Array();\n";
  75. $filelist = array();
  76. if (($handle = fopen(_DIR_DICT_TEXT_ . '/system/list.txt', 'r')) !== false) {
  77. while (($data = fgetcsv($handle, 0, ',')) !== false) {
  78. $filelist[] = $data;
  79. }
  80. foreach ($filelist as $value) {
  81. echo "sys_file_list.push(['{$value[0]}','{$value[1]}']);\n";
  82. }
  83. } else {
  84. // exit("无法打开system文件列表");
  85. }
  86. echo "var thin_file_list = new Array();\n";
  87. $filelist = array();
  88. if (($handle = fopen(_DIR_DICT_TEXT_ . '/thin/list.csv', 'r')) !== false) {
  89. while (($data = fgetcsv($handle, 0, ',')) !== false) {
  90. $filelist[] = $data;
  91. }
  92. foreach ($filelist as $value) {
  93. echo "thin_file_list.push(['{$value[0]}','{$value[1]}','{$value[2]}']);\n";
  94. }
  95. } else {
  96. //exit("无法打开thin文件列表");
  97. }
  98. ?>
  99. var iCurrRichDictIndex = 0;
  100. var iCurrSysDictIndex = 0;
  101. function run_rich_dict(index){
  102. if(index >= rich_file_list.length){
  103. $("#response").html($("#response").html()+"rich dict Down");
  104. run_sys_dict(0);
  105. }
  106. else{
  107. $.get("step3_run.php",
  108. {
  109. dbtype:"rich",
  110. filename:rich_file_list[index][0],
  111. dbname:rich_file_list[index][1]
  112. },
  113. function(data,status){
  114. $("#response").html($("#response").html()+data+"<br>");
  115. iCurrRichDictIndex++;
  116. run_rich_dict(iCurrRichDictIndex);
  117. });
  118. }
  119. }
  120. function run_sys_dict(index,onlyOne=false){
  121. if(index >= sys_file_list.length){
  122. $("#response").html($("#response").html()+"All Down");
  123. }
  124. else{
  125. iCurrSysDictIndex = index;
  126. $.get("step3_run.php",
  127. {
  128. dbtype:"system",
  129. filename:sys_file_list[index][0],
  130. dbname:sys_file_list[index][1]
  131. },
  132. function(data,status){
  133. $("#response").html($("#response").html()+data+"<br>");
  134. if(onlyOne){
  135. $("#response").html($("#response").html()+"all done<br>");
  136. }
  137. else{
  138. iCurrSysDictIndex++;
  139. run_sys_dict(iCurrSysDictIndex);
  140. }
  141. });
  142. }
  143. }
  144. var iCurrThinDictIndex=0;
  145. function run_ref_dict(index){
  146. if(index >= thin_file_list.length){
  147. $("#response").html($("#response").html()+"All Down");
  148. }
  149. else{
  150. iCurrThinDictIndex = index;
  151. $.get("step3_run.php",
  152. {
  153. dbtype:"thin",
  154. filename:thin_file_list[index][0],
  155. dbname:thin_file_list[index][1],
  156. table:thin_file_list[index][2]
  157. },
  158. function(data,status){
  159. $("#response").html($("#response").html()+data+"<br>");
  160. iCurrThinDictIndex++;
  161. run_ref_dict(iCurrThinDictIndex);
  162. });
  163. }
  164. }
  165. function run_part_dict(){
  166. $.get("step3_run.php",
  167. {
  168. dbtype:"part",
  169. filename:"",
  170. dbname:""
  171. },
  172. function(data,status){
  173. $("#response").html($("#response").html()+data+" done<br>");
  174. });
  175. }
  176. </script>
  177. <h2>
  178. </h2>
  179. <div class="card">
  180. <h4>第三方参考字典</h4>
  181. <div class="contence">
  182. <button onclick="run_ref_dict(0)">Build rich dictionary </button><span style="请注意!此操作将会覆盖原有数据库。"><br>
  183. </div>
  184. </div>
  185. <div class="card">
  186. <h4>标准格式字典</h4>
  187. <div class="contence">
  188. <button onclick="run_rich_dict(0)">Build rich dictionary </button><span style="请注意!此操作将会覆盖原有数据库。"><br>
  189. </div>
  190. </div>
  191. <div class="card">
  192. <h4>组分字典</h4>
  193. <div class="contence">
  194. <button onclick="run_part_dict()">Build part dictionary</button><span style="请注意!此操作将会覆盖原有数据库。">
  195. </div>
  196. </div>
  197. <hr>
  198. <h2 style="text-align:center;"><a href="step5.php">[Next]</a></h2>
  199. </body>
  200. </html>