2
0

index.php 9.0 KB

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