step3.php 5.6 KB

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