<?php
// +----------------------------------------------------------------------
// | 天方夜谭 [ 世界上最好用的QQ秒赞系统 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2014~2019 http://www.eirds.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 天方夜谭 <17404785@qq.com>
// +----------------------------------------------------------------------

//页面标题
define('Title', '音乐大厅');

//获取歌单
if (POST('action')=='toplist'){
    $toplist = json_encode(object_array($TFYT_DB->get_results("select music_id from ".PREFIX."website_toplist order by id asc")));
    exit($toplist);
}elseif (POST('action')=='add'){
    header('Content-Type:application/json; charset=utf-8');
    $name = POST('name');
    $artist = POST('artist');
    $album = POST('album');
    $url_id = POST('url_id');
    $pic_id = POST('pic_id');
    $lyric_id = POST('lyric_id');
    $source = POST('source');
    if (empty($name) || empty($artist) || empty($album) || empty($url_id) || empty($pic_id) || empty($pic_id) || empty($lyric_id) || empty($source)){
        $arr = array('state'=>'no','msg'=>'缺少参数！','id'=>$url_id);
    }else if ($TFYT_DB->get_row("select music_id from ".PREFIX."player_music where music_url_id='{$url_id}' and music_source='{$source}' and only='{$GLOBALS['users']['only']}'")){
        $arr = array('state'=>'no','msg'=>'该歌曲已存在列表！','id'=>$url_id);
    }else{
        if ($TFYT_DB->query("insert into ".PREFIX."player_music (`music_name`,`music_artist`,`music_album`,`music_url_id`,`music_pic_id`,`music_lyric_id`,`music_source`,`only`)values('{$name}','{$artist}','{$album}','{$url_id}','{$pic_id}','{$lyric_id}','{$source}','{$GLOBALS['users']['only']}')")){
            $arr = array('state'=>'ok','msg'=>'添加成功！','id'=>$url_id);
        }else{
            $arr = array('state'=>'no','msg'=>'添加歌曲失败，系统错误，请联系管理员修复！','id'=>$url_id);
        }
    }
    exit(json_encode($arr));
}

//加载头部
Load_Template(Mains.'head.php');

//加载视图
Load_Template(Mains.'music.php');

//加载底部
Load_Template(Mains.'foot.php');