index.php 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <link type="text/css" rel="stylesheet" href="../studio/css/font.css"/>
  7. <link type="text/css" rel="stylesheet" href="../studio/css/style.css"/>
  8. <link type="text/css" rel="stylesheet" href="../studio/css/color_day.css" id="colorchange" />
  9. <style>
  10. .toc_1{
  11. padding-left:0;
  12. }
  13. .toc_2{
  14. padding-left:1em;
  15. }
  16. .toc_3{
  17. padding-left:2em;
  18. }
  19. .toc_4{
  20. padding-left:3em;
  21. }
  22. .nimbus-is-editor{
  23. background-color: var(--tool-bg-color);
  24. color: white;
  25. }
  26. </style>
  27. </head>
  28. <body>
  29. <?php require_once '../lang/lang.php';?>
  30. <?php
  31. require_once "../public/_pdo.php";
  32. require_once "../path.php";
  33. require_once "../public/load_lang.php";
  34. if (isset($_GET["language"])) {
  35. $language = $_GET["language"];
  36. } else {
  37. $language = "en";
  38. }
  39. include "./language/" . $language . ".php";
  40. echo "{$language}<br>";
  41. $toc = array();
  42. if (($handle = fopen("./book_index_" . $language . ".csv", 'r')) !== false) {
  43. while (($data = fgetcsv($handle, 0, ',')) !== false) {
  44. array_push($toc, $data);
  45. if ($data[2] > 0) {
  46. $bookid = $data[2];
  47. $toc_book["$bookid"] = $data[1];
  48. }
  49. }
  50. }
  51. echo "<h2>";
  52. echo $gui['word_analysis'];
  53. echo "</h2>";
  54. if (isset($_GET["spell"])) {
  55. $spell = $_GET["spell"];
  56. } else {
  57. $spell = "";
  58. }
  59. if (isset($_GET["wordop"])) {
  60. $wordop = $_GET["wordop"];
  61. if (isset($_GET["spell"]) && $_GET["spell"] != "" && $wordop = "end") {
  62. $spell = "%" . $_GET["spell"];
  63. $wordop = "like";
  64. } else if (isset($_GET["spell"]) && $_GET["spell"] != "" && $wordop = "begin") {
  65. $spell = $_GET["spell"] . "%";
  66. $wordop = "like";
  67. } else {
  68. $spell = "";
  69. }
  70. } else {
  71. $wordop = "=";
  72. }
  73. if (!isset($_GET["groupby"])) {
  74. ?>
  75. <form action="index.php" method="get">
  76. <input type="hidden" name="language" value="<?php echo $language ?>" />
  77. <?php echo $gui['spell'] ?>:
  78. <select name="wordop">
  79. <option value="like" ><?php echo $gui['like'] ?></option>
  80. <option value="end" ><?php echo $gui['end_with'] ?></option>
  81. <option value="begin" ><?php echo $gui['begin_with'] ?></option>
  82. </select>
  83. <input type="text" name="spell" value="" style="width: auto;" placeholder=<?php echo $gui['empty'] ?> /><br>
  84. <?php echo $gui['group_by'] ?>:
  85. <select name="groupby">
  86. <option value="base" ><?php echo $gui['base'] ?></option>
  87. <option value="word" ><?php echo $gui['spell'] ?></option>
  88. <option value="end1" ><?php echo $gui['ending_1'] ?></option>
  89. <option value="end2" ><?php echo $gui['ending_2'] ?></option>
  90. </select>
  91. <input type="submit" value="<?php echo $gui['submit'] ?>"><br>
  92. <br>
  93. <?php
  94. $arrlength = count($toc);
  95. echo "<ul>";
  96. for ($x = 0; $x < $arrlength; $x++) {
  97. echo "<li class='toc_" . $toc[$x][0] . "'><input type='checkbox' name='" . $toc[$x][2] . "' onchange=\"chk_change(this)\" checked />" . $toc[$x][1] . "</li>";
  98. }
  99. echo "</ul>";
  100. ?>
  101. <input type="submit">
  102. </form>
  103. <?php
  104. return;
  105. }
  106. $groupby = $_GET["groupby"];
  107. echo "<a href='index.php?language=$language'>" . $gui['home'] . "</a><br>";
  108. echo $gui['your_choice'] . ":</br>";
  109. $boolList = array();
  110. for ($i = 1; $i < 218; $i++) {
  111. if (isset($_GET["$i"])) {
  112. if ($_GET["$i"] == "on") {
  113. array_push($boolList, "$i");
  114. echo $toc_book["$i"] . "; ";
  115. }
  116. }
  117. }
  118. echo "</br>";
  119. $countInsert = 0;
  120. $wordlist = array();
  121. $db_file = _FILE_DB_STATISTICS_;
  122. $bookstring = "";
  123. for ($i = 0; $i < count($boolList); $i++) {
  124. $bookstring .= "'" . $boolList[$i] . "'";
  125. if ($i < count($boolList) - 1) {
  126. $bookstring .= ",";
  127. }
  128. }
  129. //open database
  130. PDO_Connect("$db_file");
  131. if ($spell == "") {
  132. echo ("<h3>" . $gui['group_by'] . ":$groupby</h3>");
  133. $query = "SELECT count(*) FROM \"word\" WHERE (bookid in (" . $bookstring . ")) "; /*查總數*/
  134. $count_word = PDO_FetchOne($query);
  135. $query = "SELECT sum(count) FROM \"word\" WHERE (bookid in (" . $bookstring . ")) "; /*查總數,并分類匯總*/
  136. $sum_word = PDO_FetchOne($query);
  137. $query = "select count(*) from (SELECT count() FROM \"word\" WHERE (bookid in (" . $bookstring . ") and $groupby<>'') group by $groupby )"; /*查總數,并分類匯總*/
  138. $count_parent = PDO_FetchOne($query);
  139. $query = "select sum(length) from (SELECT * FROM \"word\" WHERE (bookid in (" . $bookstring . ") and $groupby<>'') group by $groupby )"; /*查總數,并分類匯總*/
  140. $count_parent1 = PDO_FetchOne($query);
  141. $query = "SELECT sum(count) FROM \"word\" WHERE (bookid in (" . $bookstring . ") and $groupby<>'') "; /*查總數,并分類匯總*/
  142. $sum_parent = PDO_FetchOne($query);
  143. $format = number_format($count_word);
  144. echo $gui['vacab'] . ":$format<br>";
  145. echo $gui['word_count'] . ":" . number_format($sum_word) . "<br> ";
  146. echo "<b>$groupby</b>" . $gui['statistics'] . ":" . number_format($count_parent) . "<br> ";
  147. echo "<b>$groupby</b>字母" . $gui['statistics'] . ":" . number_format($count_parent1) . "<br> ";
  148. echo $gui['effective'] . ":" . number_format($sum_parent) . " <br>";
  149. $query = "select * from (SELECT $groupby,sum(count) as wordsum FROM \"word\" WHERE (bookid in (" . $bookstring . ") and $groupby<>'') group by $groupby) order by wordsum DESC limit 0 ,4000"; /*查總數,并分類匯總*/
  150. $Fetch = PDO_FetchAll($query);
  151. $iFetch = count($Fetch);
  152. echo "<table>";
  153. echo "<th>" . $gui['serial_num'] . "</th><th>$groupby</th><th>" . $gui['count'] . "</th><th>" . $gui['percentage'] . "</th><th>" . $gui['accumulative'] . "</th>";
  154. $sum_prsent = 0;
  155. if ($iFetch > 0) {
  156. $sum = $Fetch[0]["wordsum"];
  157. $first = $sum * 100 / $sum_word;
  158. for ($i = 0; $i < $iFetch; $i++) {
  159. $sum = $Fetch[$i]["wordsum"];
  160. $prsent = $sum * 100 / $sum_word;
  161. $prsent1 = $prsent * 100 / $first;
  162. $sum_prsent += $prsent;
  163. echo "<tr>";
  164. echo "<td>" . ($i + 1) . "</td><td>" . $Fetch[$i][$groupby] . "</td><td>" . number_format($sum) . "</td><td><span style='width:" . $prsent1 . "px;background-color:red;'></span><span style:'width:" . (100 - $prsent1) . "px;background-color: var(--tool-link-hover-color);'></span>" . number_format($prsent, 3) . "</td><td>" . number_format($sum_prsent, 1) . "</td>";
  165. echo "</tr>";
  166. }
  167. }
  168. echo "</table>";
  169. } else {
  170. echo ("<h3>Word: <spen style='color: var(--tool-link-hover-color);'>$spell</spen></h3>");
  171. $newSpell = $PDO->quote($spell);
  172. $query = "SELECT count(*) FROM \"word\" WHERE (word $wordop $newSpell) "; /*查總词數*/
  173. $count_word = PDO_FetchOne($query);
  174. $query = "SELECT sum(count) FROM \"word\" WHERE (word $wordop $newSpell) "; /*查總數,并分類匯總*/
  175. $sum_word = PDO_FetchOne($query);
  176. echo "单词总个数:" . number_format($count_word) . "<br>";
  177. echo "单词总数:" . number_format($sum_word) . "<br>";
  178. $query = "select count(*) from (SELECT bookid FROM \"word\" WHERE (word $wordop $newSpell) group by bookid) "; /*查總數,并分類匯總*/
  179. $in_book_count = PDO_FetchOne($query);
  180. echo "<p>In $in_book_count Books</p>";
  181. $query = "select bookid,co,su from (SELECT bookid,sum(count) as su,count(*) co FROM \"word\" WHERE (word $wordop $newSpell) group by bookid) order by co DESC limit 0 ,20"; /*查總數,并分類匯總*/
  182. $Fetch = PDO_FetchAll($query);
  183. $iFetch = count($Fetch);
  184. echo "<table>";
  185. echo "<th>序号</th><th>Book</th><th>单词个数</th><th>单词数量</th>";
  186. if ($iFetch > 0) {
  187. for ($i = 0; $i < $iFetch; $i++) {
  188. echo "<tr>";
  189. echo "<td>" . ($i + 1) . "</td><td>" . $toc_book[$Fetch[$i]["bookid"]] . "</td><td>" . number_format($Fetch[$i]["co"]) . "</td><td>" . number_format($Fetch[$i]["su"]) . "</td>";
  190. echo "</tr>";
  191. }
  192. }
  193. echo "</table>";
  194. $query = "select count(*) from (SELECT bookid FROM \"word\" WHERE (word $wordop $newSpell) group by word) "; /*查總數,并分類匯總*/
  195. $word_count = PDO_FetchOne($query);
  196. echo "<p>$word_count Words</p>";
  197. $query = "select word,co from (SELECT word,sum(count) co FROM \"word\" WHERE (word $wordop $newSpell) group by word) order by co DESC limit 0 ,100"; /*查總數,并分類匯總*/
  198. $Fetch = PDO_FetchAll($query);
  199. $iFetch = count($Fetch);
  200. echo "<table>";
  201. echo "<th>序号</th><th>Word</th><th>数量</th>";
  202. if ($iFetch > 0) {
  203. for ($i = 0; $i < $iFetch; $i++) {
  204. echo "<tr>";
  205. echo "<td>" . ($i + 1) . "</td><td>" . $Fetch[$i]["word"] . "</td><td>" . number_format($Fetch[$i]["co"]) . "</td>";
  206. echo "</tr>";
  207. }
  208. }
  209. echo "</table>";
  210. }
  211. /*查询结束*/
  212. ?>
  213. </body>
  214. </html>