added user search

This commit is contained in:
printempw 2016-03-27 10:55:16 +08:00
parent 8383e076e3
commit 8921fe38c8
3 changed files with 28 additions and 8 deletions

View File

@ -3,7 +3,7 @@
* @Author: printempw
* @Date: 2016-03-06 14:19:20
* @Last Modified by: printempw
* @Last Modified time: 2016-03-27 09:45:54
* @Last Modified time: 2016-03-27 10:53:06
*/
require "../libraries/session.inc.php";
if (!$user->is_admin) header('Location: ../index.php?msg=看起来你并不是管理员');
@ -17,7 +17,6 @@ if (isset($_GET['show'])) {
}
$data['script'] = <<< 'EOT'
<script type="text/javascript" src="../assets/js/preview.utils.js"></script>
<script type="text/javascript" src="../assets/js/admin.utils.js"></script>
<script>
$('#page-select').on('change', function() {
@ -25,4 +24,6 @@ $('#page-select').on('change', function() {
});
</script>
EOT;
if (isset($_GET['show']))
$data['script'] .= '<script type="text/javascript" src="../assets/js/preview.utils.js"></script>';
View::show('footer', $data); ?>

View File

@ -2,7 +2,7 @@
* @Author: printempw
* @Date: 2016-02-04 16:47:54
* @Last Modified by: printempw
* @Last Modified time: 2016-03-27 09:40:35
* @Last Modified time: 2016-03-27 10:38:36
*/
@import url(https://fonts.googleapis.com/css?family=Ubuntu);
@ -56,3 +56,12 @@ td[class='key'], td[class='value'] {
border-radius: 15px;
outline: none;
}
.user-search-form {
display: inline;
}
.user-search-input {
display: inline;
width: 30%;
float: right;
margin: 0;
}

View File

@ -5,6 +5,9 @@
<h1>
用户管理
<small>User Manage</small>
<form method="post" action="manage.php" class="user-search-form">
<input type="text" name="search-username" class="form-control user-search-input" placeholder="输入用户名,回车搜索。" value="<?php echo Utils::getValue('search-username', $_POST); ?>">
</form>
</h1>
</section>
@ -27,8 +30,14 @@
<?php
$page_now = isset($_GET['page']) ? $_GET['page'] : 1;
$db = new Database\Database();
$result = $db->query("SELECT * FROM users ORDER BY `uid` LIMIT ".(string)(($page_now-1)*30).", 30");
$page_total = round($db->getRecordNum()/30);
if (isset($_POST['search-username'])) {
$result = $db->query("SELECT * FROM users WHERE `username` LIKE '%".$_POST['search-username']."%' ORDER BY `uid` LIMIT ".(string)(($page_now-1)*30).", 30");
} else {
$result = $db->query("SELECT * FROM users ORDER BY `uid` LIMIT ".(string)(($page_now-1)*30).", 30");
}
$page_total = round($result->num_rows/30);
while ($row = $result->fetch_array()) { ?>
<tr>
<td><?php echo $row['uid']; ?></td>
@ -62,13 +71,13 @@
</div>
</div>
<?php if ($page_total != 0): ?>
<ul class="pager">
<?php if ($page_now != 1 && $page_now >= 5): ?>
<li>
<a href="manage.php?page=1">1...</a>
</li>
<li><a href="manage.php?page=1">1...</a></li>
<?php endif;
// calculate page numbers to show
if ($page_now > $page_total - 2) {
$from = $page_total - 4;
$to = $page_total;
@ -94,6 +103,7 @@
} ?>
</select>
</ul>
<?php endif; ?>
</section><!-- /.content -->
</div><!-- /.content-wrapper -->