2
0

step3.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  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 = "sqlite:".$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. }
  51. else{
  52. echo "<span style='color:green;'>已存在</span>";
  53. echo "</div>";
  54. echo '<div style="flex:2;"><a href="step3.php?index='.$i.'">重建</a><span style="color:red;">注意!此操作将删除原数据库中所有数据!</span></div>';
  55. }
  56. echo "</div>";
  57. }
  58. ?>
  59. </div>
  60. <div id="response"></div>
  61. <script>
  62. <?php
  63. echo "var rich_file_list = new Array();\n";
  64. $filelist = array();
  65. if(($handle=fopen(_DIR_DICT_TEXT_.'/rich/list.txt','r'))!==FALSE){
  66. while(($data=fgetcsv($handle,0,','))!==FALSE){
  67. $filelist[] = $data;
  68. }
  69. foreach($filelist as $value){
  70. echo "rich_file_list.push(['{$value[0]}','{$value[1]}']);\n";
  71. }
  72. }
  73. else{
  74. // exit("无法打开rich文件列表");
  75. }
  76. echo "var sys_file_list = new Array();\n";
  77. $filelist = array();
  78. if(($handle=fopen(_DIR_DICT_TEXT_.'/system/list.txt','r'))!==FALSE){
  79. while(($data=fgetcsv($handle,0,','))!==FALSE){
  80. $filelist[] = $data;
  81. }
  82. foreach($filelist as $value){
  83. echo "sys_file_list.push(['{$value[0]}','{$value[1]}']);\n";
  84. }
  85. }
  86. else{
  87. // exit("无法打开system文件列表");
  88. }
  89. echo "var thin_file_list = new Array();\n";
  90. $filelist = array();
  91. if(($handle=fopen(_DIR_DICT_TEXT_.'/thin/list.csv','r'))!==FALSE){
  92. while( ($data=fgetcsv($handle,0 , ',' ) )!==FALSE){
  93. $filelist[] = $data;
  94. }
  95. foreach($filelist as $value){
  96. echo "thin_file_list.push(['{$value[0]}','{$value[1]}','{$value[2]}']);\n";
  97. }
  98. }
  99. else{
  100. //exit("无法打开thin文件列表");
  101. }
  102. ?>
  103. var iCurrRichDictIndex = 0;
  104. var iCurrSysDictIndex = 0;
  105. function run_rich_dict(index){
  106. if(index >= rich_file_list.length){
  107. $("#response").html($("#response").html()+"rich dict Down");
  108. run_sys_dict(0);
  109. }
  110. else{
  111. $.get("step3_run.php",
  112. {
  113. dbtype:"rich",
  114. filename:rich_file_list[index][0],
  115. dbname:rich_file_list[index][1]
  116. },
  117. function(data,status){
  118. $("#response").html($("#response").html()+data+"<br>");
  119. iCurrRichDictIndex++;
  120. run_rich_dict(iCurrRichDictIndex);
  121. });
  122. }
  123. }
  124. function run_sys_dict(index){
  125. if(index >= sys_file_list.length){
  126. $("#response").html($("#response").html()+"All Down");
  127. }
  128. else{
  129. iCurrSysDictIndex = index;
  130. $.get("step3_run.php",
  131. {
  132. dbtype:"system",
  133. filename:sys_file_list[index][0],
  134. dbname:sys_file_list[index][1]
  135. },
  136. function(data,status){
  137. $("#response").html($("#response").html()+data+"<br>");
  138. iCurrSysDictIndex++;
  139. run_sys_dict(iCurrSysDictIndex);
  140. });
  141. }
  142. }
  143. var iCurrThinDictIndex=0;
  144. function run_ref_dict(index){
  145. if(index >= thin_file_list.length){
  146. $("#response").html($("#response").html()+"All Down");
  147. }
  148. else{
  149. iCurrThinDictIndex = index;
  150. $.get("step3_run.php",
  151. {
  152. dbtype:"thin",
  153. filename:thin_file_list[index][0],
  154. dbname:thin_file_list[index][1],
  155. table:thin_file_list[index][2]
  156. },
  157. function(data,status){
  158. $("#response").html($("#response").html()+data+"<br>");
  159. iCurrThinDictIndex++;
  160. run_ref_dict(iCurrThinDictIndex);
  161. });
  162. }
  163. }
  164. function run_part_dict(){
  165. $.get("step3_run.php",
  166. {
  167. dbtype:"part",
  168. filename:"",
  169. dbname:""
  170. },
  171. function(data,status){
  172. $("#response").html($("#response").html()+data+" done<br>");
  173. });
  174. }
  175. </script>
  176. <h2>
  177. </h2>
  178. <div class="card">
  179. <h4>第三方参考字典</h4>
  180. <div class="contence">
  181. <button onclick="run_ref_dict(0)">Build rich dictionary </button><span style="请注意!此操作将会覆盖原有数据库。"><br>
  182. </div>
  183. </div>
  184. <div class="card">
  185. <h4>标准格式字典</h4>
  186. <div class="contence">
  187. <button onclick="run_rich_dict(0)">Build rich dictionary </button><span style="请注意!此操作将会覆盖原有数据库。"><br>
  188. </div>
  189. </div>
  190. <div class="card">
  191. <h4>组分字典</h4>
  192. <div class="contence">
  193. <button onclick="run_part_dict()">Build part dictionary</button><span style="请注意!此操作将会覆盖原有数据库。">
  194. </div>
  195. </div>
  196. <hr>
  197. <h2 style="text-align:center;"><a href="step5.php">[Next]</a></h2>
  198. </body>
  199. </html>