diff options
author | chai <chaifix@163.com> | 2022-03-19 12:26:19 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2022-03-19 12:26:19 +0800 |
commit | 627b8e416d138112ad20b1299aca21dccebcd11c (patch) | |
tree | e522a5e7204e81649a36451e31c2c91b1a8342e3 | |
parent | a90ed9f20c76fbb4b340e51e6ba05500540feba5 (diff) |
*admin music page
-rw-r--r-- | admin.php | 8 | ||||
-rw-r--r-- | admin_add_music.php | 4 | ||||
-rw-r--r-- | admin_config.php | 9 | ||||
-rw-r--r-- | admin_header.php | 2 | ||||
-rw-r--r-- | admin_music.php | 73 | ||||
-rw-r--r-- | admin_new_music.php (renamed from new.php) | 3 | ||||
-rw-r--r-- | admin_paginate.php | 25 | ||||
-rw-r--r-- | admin_template.php | 25 | ||||
-rw-r--r-- | functions.php | 31 | ||||
-rw-r--r-- | header.php | 12 | ||||
-rw-r--r-- | login.php | 14 | ||||
-rw-r--r-- | res/admin.css | 128 | ||||
-rw-r--r-- | res/styles.css | 15 | ||||
-rw-r--r-- | search.php | 2 | ||||
-rw-r--r-- | template.php | 2 | ||||
-rw-r--r-- | uber.php | 37 | ||||
-rw-r--r-- | utils.php | 29 |
17 files changed, 384 insertions, 35 deletions
@@ -41,16 +41,16 @@ form .text { <body> <div id="container"> -<?php require_once 'functions.php';?> +<?php require_once 'utils.php';?> <?php require_once 'config.php';?> <?php require_once 'music.php';?> <?php require_once('checkadmin.php'); ?> - <a href="admin_add_music.php">Add Music</a> + <a href="admin_music.php">Music</a> - <a href="admin_add_music.php">Add Album</a> + <a href="admin_add_music.php">Albums</a> - <a href="admin_add_music.php">Delete Tag</a> + <a href="admin_add_music.php">Tags</a> <div> diff --git a/admin_add_music.php b/admin_add_music.php index 9599a8c..6480318 100644 --- a/admin_add_music.php +++ b/admin_add_music.php @@ -27,7 +27,7 @@ form .text { <body> <div id="container"> -<?php require_once 'functions.php';?> +<?php require_once 'utils.php';?> <?php require_once 'config.php';?> <?php require_once 'music.php';?> @@ -37,7 +37,7 @@ form .text { <h1 style="font-size:1.2em;display:block;color:#c5c5c5;" >Add Music</h1> -<form action="new.php" method="post" enctype="multipart/form-data"> +<form action="admin_new_music.php" method="post" enctype="multipart/form-data"> <div class="section"> <label class="title" for="musicFile" >file:</label> <input type="file" name="musicFile"/> diff --git a/admin_config.php b/admin_config.php new file mode 100644 index 0000000..60a97cd --- /dev/null +++ b/admin_config.php @@ -0,0 +1,9 @@ +<?php + +class AdminConfig +{ + public static $music_per_page = 20; + +} + +?>
\ No newline at end of file diff --git a/admin_header.php b/admin_header.php index 30e4383..d877ef3 100644 --- a/admin_header.php +++ b/admin_header.php @@ -25,7 +25,7 @@ <a href="logout.php">Logout</a> <a href="index.php">Site</a> <a href="admin.php" style="float:left;">Main</a> - <a href="admin.php" style="float:left;">Music</a> + <a href="admin_music.php" style="float:left;">Music</a> <a href="admin.php" style="float:left;">Albums</a> <a href="admin.php" style="float:left;">Tags</a> <div style="clear:both"></div> diff --git a/admin_music.php b/admin_music.php new file mode 100644 index 0000000..c378adb --- /dev/null +++ b/admin_music.php @@ -0,0 +1,73 @@ +<html> + +<head> +<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no, target-densityDpi=device-dpi"> +<style type="text/css"> +#container { + margin:0 auto; + max-width: 500px; +} +form .title { + display:block; + font-size:0.8em; + margin-bottom: 3px; +} +form .section{ + margin-bottom: 10px; + padding: 5px; + background: #efefef; +} +form .text { + width: 100%; +} +</style> + +</head> + +<body> + <div id="container"> + + <?php require_once 'utils.php';?> + <?php require_once 'config.php';?> + <?php require_once 'music.php';?> + <?php require_once 'admin_config.php';?> + <?php require_once 'admin_template.php';?> + + <?php + require_once('checkadmin.php'); + ?> + + <div style="height:auto;"> + <label class="admin-h1">Music</label> + <a id="add-music-link" href="admin_add_music.php">+ new music</a> + <div style="clear:both;"></div> + </div> + + <div id="admin-music-list"> + <?php + $page = $_GET['p']; + if($page == null){ + $page = 0; + } + + $arr = fetch_range_music($page*AdminConfig::$music_per_page, AdminConfig::$music_per_page); + $total_page = ceil(get_all_music_count() / AdminConfig::$music_per_page ); + + if($arr != null && count($arr) > 0){ + foreach($arr as $music){ + html_admin_music($music); + } + } + + $url = "./admin_music.php?"; + $current_page_index = $page; + ?> + + </div> + + <?php require_once 'admin_paginate.php';?> + + <div> + +</body> +</html>
\ No newline at end of file diff --git a/new.php b/admin_new_music.php index d6ccac3..ceb761e 100644 --- a/new.php +++ b/admin_new_music.php @@ -1,5 +1,5 @@ <?php require_once 'upload.php'; ?> -<?php require_once 'functions.php';?> +<?php require_once 'utils.php';?> <?php require_once 'config.php';?> <?php require_once 'music.php';?> @@ -13,5 +13,4 @@ if($music != null) { // 跳转 header('Location: '.'index.php'); - ?>
\ No newline at end of file diff --git a/admin_paginate.php b/admin_paginate.php new file mode 100644 index 0000000..9d4f74c --- /dev/null +++ b/admin_paginate.php @@ -0,0 +1,25 @@ + +<div id="admin-paginate"> + +<?php + // external variables: + // echo $current_page_index ; + // echo $total_page ; + // echo $url; + + if($total_page > 1){ + for ($p=0; $p<$total_page; $p++) { + if($p == $current_page_index){ + html_admin_paginate_link_current($url, $p); + } + else { + html_admin_paginate_link($url, $p); + } + } + } +?> + + +<div style="clear:both;"></div> + +</div>
\ No newline at end of file diff --git a/admin_template.php b/admin_template.php new file mode 100644 index 0000000..b745e44 --- /dev/null +++ b/admin_template.php @@ -0,0 +1,25 @@ +<?php require_once 'music.php'?> +<?php require_once 'utils.php'?> + +<?php + +function html_admin_music($music) { + echo '<div class="admin-music">'; + echo '<img class="admin-music-cover" src="' . $music->cover . '"/>'; + echo '<label class="admin-music-name">' . $music->title .'</label>'; + echo '<label class="admin-music-id">' . $music->uid . '</label>'; + echo '<a class="admin-music-delete" href="./uber.php?op=DEL_MUSIC$mid='. $music->uid .'">Delete</a>'; + echo '<a class="admin-music-modify" href="./uber.php?op=MOD_MUSIC$mid=' . $music->uid . '">Modify</a>'; + echo '<div style="clear:both"></div>'; + echo '</div>'; +} + +function html_admin_paginate_link($url, $pagei) { + echo '<a href="' . $url . '&p=' . $pagei . '">' . ($pagei + 1) . '</a>'; +} + +function html_admin_paginate_link_current($url, $pagei) { + echo '<a class="current" href="' . $url . '&p=' . $pagei . '">' . ($pagei + 1) . '</a>'; +} + +?>
\ No newline at end of file diff --git a/functions.php b/functions.php index 8a7824b..6d3d3cc 100644 --- a/functions.php +++ b/functions.php @@ -1,29 +1,14 @@ <?php - -function echoln($content){ - if($content === true){ - $content = "true"; - } - if($content === false){ - $content = "false"; +// 是否已经登录 +function isLogin() { + session_start(); + if (isset($_SESSION["admin"]) && $_SESSION["admin"] === true) { + return true; + } else { + return false; } - echo $content; - echo "<br/>"; -} -function println($content) -{ - print_r($content); - echo "<br/>"; } -// 替换为html转义字符,否则插入sql会有问题 -function html_escape_string($str) { - $str = str_replace("'", "'", $str); // ' - $str = str_replace('"', """, $str); // " - return $str; -} - -?> - +?>
\ No newline at end of file @@ -1,5 +1,17 @@ <div id="header"> <a href="./index.php"><img id="dachai_logo" src="./res/dachai.png"/></a> + <?php + require_once 'functions.php' ; + + if(!isLogin()){ + echo '<a id="login-link" href="./login.php">Login</a>'; + } else { + echo '<a id="login-link" href="./logout.php">Logout</a>'; + echo '<a id="login-link" href="./admin.php">Admin</a>'; + } + + ?> <label id="site_title">Dachai & Music<br/>Sound, BGM, Vocal, etc.</label> + </div> <div style="clear:both;"></div>
\ No newline at end of file @@ -21,13 +21,25 @@ form .section{ form .text { width: 100%; } +#login_site_link { + text-decoration:none; + color:black; + padding:0 5px; + font-size: 12px; +} +#login_site_link:hover { + color:white; + background:black; +} </style> </head> <body> <div id="container"> - <label style="display:block; margin-bottom:10px;">Login</label> + <label style="float:left;display:block; margin-bottom:10px;">Login</label> + <a id="login_site_link" href="index.php" style="float:right;display:block; margin-bottom:10px;">Site</a> + <div style="clear:both"></div> <form action="authentication.php" method="post" enctype="multipart/form-data"> <div class="section"> <label class="title" for="token" >token:</label> diff --git a/res/admin.css b/res/admin.css index 64b6fc8..beca966 100644 --- a/res/admin.css +++ b/res/admin.css @@ -9,5 +9,133 @@ body{ min-height:100%; padding:10px; box-sizing: border-box; + position:relative; +} + +#add-music-link { + text-decoration: none; + color:black; + float:right; + font-size:12px; + padding: 5px; +} + +#add-music-link:hover { + color:white; + background-color: black; +} + +.admin-h1{ + float:left; + font-size:20px; + display:block; + color:#c5c5c5; + height: 25px; + font-weight: bold; +} + +.admin-music { + background-color: #fafafa; + box-sizing: border-box; + padding: 5px; + margin-bottom: 10px; +} + +.admin-music .admin-music-cover { + width:30px; + height:30px; + float: left; +} + +#admin-music-list{ + margin: 10px 0; +} + +.admin-music a{ + display: block; + float:right; + height:30px; + line-height: 30px; + text-decoration: none; + padding: 0 10px; + font-size:12px; + font-weight: bold; +} + +.admin-music a:hover{ + color: white; +} + +.admin-music .admin-music-modify { + color:black; + margin-right: 10px; +} + +.admin-music .admin-music-modify:hover { + background-color: black; +} + +.admin-music .admin-music-delete { + color:red; +} + +.admin-music .admin-music-delete:hover { + background-color: red; + color:white; +} + +.admin-music-name { + display: block; + float: left; + height: 30px; + line-height: 30px; + font-size: 15px; + margin-left: 30px; + width: 150px; + overflow:hidden; +} + +.admin-music-id { + display: block; + float: left; + height: 30px; + line-height: 30px; + font-size: 15px; + margin-left: 10px; + width: 30px; +} + +/* paginate */ + +#admin-paginate { + width: 100%; + position: absolute; + bottom: 0; +} + +#admin-paginate a { + color:rgb(0, 0, 0); + text-decoration-line: none; + display: block; + width: 30px; + height: 30px; + text-align: center; + line-height: 30px; + float:left; + margin-right: 5px; +} + +#admin-paginate a:hover{ + color:#fff; + background-color: #000; + text-decoration-line: none; + display: block; +} + +#admin-paginate .current{ + color:#fff; + background-color: #000; + text-decoration-line: none; + display: block; } diff --git a/res/styles.css b/res/styles.css index cb0e0a3..6ddcc6e 100644 --- a/res/styles.css +++ b/res/styles.css @@ -16,6 +16,21 @@ body{ float: left; } +#header #login-link{ + float:right; + font-size:12px; + text-decoration: none; + color:black; + display: block; + padding:5px; + margin-left: 5px; +} + +#header #login-link:hover{ + color:white; + background: black; +} + #site_title{ font-size:12px; } @@ -13,7 +13,7 @@ <?php include_once('header.php');?> <?php include_once('titlebar.php');?> <?php include_once 'config.php'?> - <?php include_once 'functions.php'?> + <?php include_once 'utils.php'?> <?php $type = $_GET['type']; // 'tag', 'name' $value = $_GET['value']; // tag id, name diff --git a/template.php b/template.php index 49d96ee..726bdfe 100644 --- a/template.php +++ b/template.php @@ -1,5 +1,5 @@ <?php require_once 'music.php'?> -<?php require_once 'functions.php'?> +<?php require_once 'utils.php'?> <?php diff --git a/uber.php b/uber.php new file mode 100644 index 0000000..fee329d --- /dev/null +++ b/uber.php @@ -0,0 +1,37 @@ +<?php // 处理所有操作请求 + +require_once 'checkadmin.php' ; +require_once 'music.php'; + +$op = $_GET['op']; + +switch($op) { + case "DEL_TAG": + $tag_id = $_GET['tid']; + handle_delete_tag($tag_id); + break; + case "DEL_MUSIC": + $music_id = $_GET['mid']; + handle_delete_music($music_id); + break; + case 'DEL_ALBUM' : + $album_id = $_GET['aid']; + handle_delete_album($album_id); + break; + default: + echo 'Unkown op ' . $op; +} + +function handle_delete_music($music_id){ + +} + +function handle_delete_tag($tag_id) { + +} + +function handle_delete_album($album_id) { + +} + +?>
\ No newline at end of file diff --git a/utils.php b/utils.php new file mode 100644 index 0000000..8a7824b --- /dev/null +++ b/utils.php @@ -0,0 +1,29 @@ +<?php + + +function echoln($content){ + if($content === true){ + $content = "true"; + } + if($content === false){ + $content = "false"; + } + echo $content; + echo "<br/>"; +} + +function println($content) +{ + print_r($content); + echo "<br/>"; +} + +// 替换为html转义字符,否则插入sql会有问题 +function html_escape_string($str) { + $str = str_replace("'", "'", $str); // ' + $str = str_replace('"', """, $str); // " + return $str; +} + +?> + |