step3.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  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){
  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. iCurrSysDictIndex++;
  135. run_sys_dict(iCurrSysDictIndex);
  136. });
  137. }
  138. }
  139. var iCurrThinDictIndex=0;
  140. function run_ref_dict(index){
  141. if(index >= thin_file_list.length){
  142. $("#response").html($("#response").html()+"All Down");
  143. }
  144. else{
  145. iCurrThinDictIndex = index;
  146. $.get("step3_run.php",
  147. {
  148. dbtype:"thin",
  149. filename:thin_file_list[index][0],
  150. dbname:thin_file_list[index][1],
  151. table:thin_file_list[index][2]
  152. },
  153. function(data,status){
  154. $("#response").html($("#response").html()+data+"<br>");
  155. iCurrThinDictIndex++;
  156. run_ref_dict(iCurrThinDictIndex);
  157. });
  158. }
  159. }
  160. function run_part_dict(){
  161. $.get("step3_run.php",
  162. {
  163. dbtype:"part",
  164. filename:"",
  165. dbname:""
  166. },
  167. function(data,status){
  168. $("#response").html($("#response").html()+data+" done<br>");
  169. });
  170. }
  171. </script>
  172. <h2>
  173. </h2>
  174. <div class="card">
  175. <h4>第三方参考字典</h4>
  176. <div class="contence">
  177. <button onclick="run_ref_dict(0)">Build rich dictionary </button><span style="请注意!此操作将会覆盖原有数据库。"><br>
  178. </div>
  179. </div>
  180. <div class="card">
  181. <h4>标准格式字典</h4>
  182. <div class="contence">
  183. <button onclick="run_rich_dict(0)">Build rich dictionary </button><span style="请注意!此操作将会覆盖原有数据库。"><br>
  184. </div>
  185. </div>
  186. <div class="card">
  187. <h4>组分字典</h4>
  188. <div class="contence">
  189. <button onclick="run_part_dict()">Build part dictionary</button><span style="请注意!此操作将会覆盖原有数据库。">
  190. </div>
  191. </div>
  192. <hr>
  193. <h2 style="text-align:center;"><a href="step5.php">[Next]</a></h2>
  194. </body>
  195. </html>