checktable.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. <?php
  2. error_reporting(0);
  3. date_default_timezone_set('Asia/Shanghai');
  4. $config = new stdclass();
  5. include '../framework/helper.class.php';
  6. include '../config/config.php';
  7. define('DS', DIRECTORY_SEPARATOR);
  8. session_start();
  9. /* Set Client lang. */
  10. if(isset($_SESSION['lang']))
  11. {
  12. $clientLang = $_SESSION['lang'];
  13. }
  14. elseif(isset($_COOKIE['lang']))
  15. {
  16. $clientLang = $_COOKIE['lang'];
  17. }
  18. elseif(isset($_SERVER['HTTP_ACCEPT_LANGUAGE']))
  19. {
  20. if(strpos($_SERVER['HTTP_ACCEPT_LANGUAGE'], ',') === false)
  21. {
  22. $clientLang = $_SERVER['HTTP_ACCEPT_LANGUAGE'];
  23. }
  24. else
  25. {
  26. $clientLang = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, strpos($_SERVER['HTTP_ACCEPT_LANGUAGE'], ','));
  27. }
  28. /* Fix clientLang for ie >= 10. https://www.drupal.org/node/365615. */
  29. if(stripos($clientLang, 'hans')) $clientLang = 'zh-cn';
  30. if(stripos($clientLang, 'hant')) $clientLang = 'zh-tw';
  31. }
  32. if(!empty($clientLang))
  33. {
  34. $clientLang = strtolower($clientLang);
  35. if(!isset($config->langs[$clientLang])) $clientLang = $config->default->lang;
  36. }
  37. else
  38. {
  39. $clientLang = $config->default->lang;
  40. }
  41. ?>
  42. <?php
  43. $webRoot = $config->webRoot;
  44. $themeRoot = $webRoot . "theme/";
  45. $type = !isset($_GET['type']) ? 'check' : $_GET['type'];
  46. if($type != 'check' and $type != 'repair') die();
  47. if(!isset($_SESSION['checkFileName']))
  48. {
  49. $checkFileName = dirname(__FILE__) . DS . uniqid('repair_') . '.txt';
  50. $_SESSION['checkFileName'] = $checkFileName;
  51. }
  52. $checkFileName = $_SESSION['checkFileName'];
  53. $status = '';
  54. if(!file_exists($checkFileName) or (time() - filemtime($checkFileName)) > 60 * 10) $status = 'createFile';
  55. $lang = new stdclass();
  56. $lang->misc = new stdclass();
  57. $lang->storyCommon = '';
  58. $lang->productCommon = '';
  59. $lang->executionCommon = '';
  60. $lang->URCommon = '';
  61. $lang->SRCommon = '';
  62. $lang->productURCommon = '';
  63. $lang->productSRCommon = '';
  64. $lang->projectSRCommon = '';
  65. $lang->projectURCommon = '';
  66. include "../module/common/lang/{$clientLang}.php";
  67. include "../module/misc/lang/{$clientLang}.php";
  68. if($status == 'createFile')
  69. {
  70. $lang->user = new stdclass();
  71. include "../module/user/lang/{$clientLang}.php";
  72. }
  73. else
  74. {
  75. $error = '';
  76. try
  77. {
  78. $dsn = "mysql:host={$config->db->host}; port={$config->db->port}; dbname={$config->db->name}";
  79. $dbh = new PDO($dsn, $config->db->user, $config->db->password, array(PDO::ATTR_PERSISTENT => $config->db->persistent));
  80. $dbh->exec("SET NAMES {$config->db->encoding}");
  81. $dbh->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_OBJ);
  82. $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  83. $tables = array();
  84. $stmt = $dbh->query("select * from information_schema.tables where table_schema = '{$config->db->name}'");
  85. while($table = $stmt->fetch(PDO::FETCH_ASSOC))
  86. {
  87. $tableName = $table["TABLE_NAME"];
  88. $tableType = strtolower($table['TABLE_TYPE']);
  89. if($tableType == 'base table')
  90. {
  91. $tableStatus = $dbh->query("$type table $tableName")->fetch();
  92. $tables[$tableName] = array('status' => strtolower($tableStatus->Msg_text), 'engine' => strtolower($table['ENGINE']));
  93. }
  94. }
  95. $status = 'check';
  96. }
  97. catch(PDOException $exception)
  98. {
  99. $error = sprintf($lang->misc->connectFail, $exception->getMessage());
  100. }
  101. }
  102. ?>
  103. <!DOCTYPE html>
  104. <html>
  105. <head>
  106. <meta charset='utf-8'>
  107. <meta http-equiv='X-UA-Compatible' content='IE=edge'>
  108. <meta name="renderer" content="webkit">
  109. <link rel='stylesheet' href='<?php echo $themeRoot . 'zui/css/min.css'?>' type='text/css' media='screen' />
  110. </head>
  111. <body>
  112. <div class='alert alert-info' style='margin-bottom:0px;'><strong><?php echo $lang->misc->repairTable;?></strong></div>
  113. <div class='container mw-700px'>
  114. <div class='panel'>
  115. <?php if(!empty($error)):?>
  116. <?php echo $error;?>
  117. <?php elseif($status == 'createFile'):?>
  118. <div class='panel-body'>
  119. <?php
  120. $checkFileName = $_SESSION['checkFileName'];
  121. $checkFileName = str_replace(dirname(dirname(__FILE__)) . DS, '', $checkFileName);
  122. printf($lang->misc->noticeRepair, $checkFileName);
  123. ?>
  124. <p><a href='<?php echo $config->webRoot . 'checktable.php';?>' class='btn btn-sm'><i class='icon-refresh'></i> <?php echo $lang->refresh;?></a></p>
  125. </div>
  126. <?php elseif($status == 'check'):?>
  127. <table class='table table-form'>
  128. <thead>
  129. <tr>
  130. <th><?php echo $lang->misc->tableName?></th>
  131. <th><?php echo $lang->misc->tableStatus?></th>
  132. <th></th>
  133. </tr>
  134. </thead>
  135. <tbody>
  136. <?php $needRepair = false;?>
  137. <?php foreach($tables as $tableName => $tableInfo):?>
  138. <?php if($tableInfo['status'] != 'ok') $needRepair = true;?>
  139. <tr>
  140. <td><?php echo $tableName;?></td>
  141. <td><span style='color:<?php echo $tableInfo['status'] == 'ok' ? 'green' : 'red'?>'><?php echo $tableInfo['status'];?></span></td>
  142. <td>
  143. <?php
  144. if($type == 'repair' && $tableInfo['status'] != 'ok')
  145. {
  146. if($tableInfo['engine'] == 'myisam') printf($lang->misc->repairFail, $tableName);
  147. if($tableInfo['engine'] == 'innodb') echo $lang->misc->withoutCmd;
  148. }
  149. ?>
  150. </td>
  151. </tr>
  152. </tbody>
  153. <?php endforeach;?>
  154. <?php if($needRepair):?>
  155. <tfoot>
  156. <tr><td class='text-center' colspan='3'><a href='<?php echo $config->webRoot . 'checktable.php?type=repair'?>' class='btn btn-primary'><?php echo $lang->misc->needRepair?></a></td></tr>
  157. </tfoot>
  158. <?php endif;?>
  159. </table>
  160. <?php endif;?>
  161. </div>
  162. </div>
  163. </body>
  164. </html>