<?php

/*
'**************************************************************************************************
' 程序名称: CCTVAI开源音乐管理系统
' 官方网站: http://www.cctvai.com
' 联系 Q Q: 1542367792
' QQ交流群：136687984
' 版本：(终结版)
' 备注：未经书面授权，不得向任何第三方提供本软件系统！
' 功能，模板，插件，扩展，定制请联系QQ：1542367792
'**************************************************************************************************
*/
error_reporting(0);
include "../include/cctvai.conn.php";
include "../include/cctvai.inc.php";
ob_start();
//允许动作
$dos=array(
    'friend',
    'home',
    'upmusic',
    'upvideo',
    'malbum',
    'valbum',
    'miniblog',
    'music',
    'video',
    'pic',
    'wall',
    'message',
    'pm',
    'assets',
    'error',
    'profile'
);
//获取变量
$id=SafeRequest("id", "get");
$key=SafeRequest("key", "get");
$view=SafeRequest("view", "get");
$orderby=SafeRequest("orderby", "get");
$day=SafeRequest("day", "get");
$fgid=SafeRequest("fgid", "get");
$cid=SafeRequest("cid", "get");
$error="您访问的Url页面不存在，请检查Url是否正确或包含非法字符！";
if(!IsNumID($day | $id | $fgid | $cid)) {
    exit(include _cctvai_root_ . "/include/error/content_error.php");
}
$ac=(!empty($_GET['do']) && in_array($_GET['do'], $dos)) ? $_GET['do'] : exit(include _cctvai_root_ . "/include/error/content_error.php");
include "source/function_common.php";
global $userlogined;
if($userlogined) {
    if($CcTvAi_com_grade == 1) {
	$vipenddate = strtotime($CcTvAi_com_vipenddate)-time();
	if($vipenddate<=0){
		$db->query("update ".tname('user')." set cd_grade=0,cd_vipindate='0000-00-00 00:00:00',cd_vipenddate='0000-00-00 00:00:00' where cd_id='$CcTvAi_com_userid'");
		//发消息通知
		$rowlast=$db->getrow("select cd_id from ".tname('user')." where cd_name='$cctvai_username' order by cd_id desc");
		$cd_lastid=$rowlast['cd_id'];
					$setarr=array(
						'cd_uid' => 0,
						'cd_uname' => '系统提示',
						'cd_uids' => $CcTvAi_com_userid,
						'cd_unames' => $CcTvAi_com_username,
						'cd_icon' => 'account',
						'cd_data' => cd_viptxt,
						'cd_dataid' => 0,
						'cd_state' => 1,
						'cd_addtime' => date('Y-m-d H:i:s')
					);
					inserttable('notice', $setarr, 1);
    }
	}

    if($CcTvAi_com_viprank >= 1) {
        if($CcTvAi_com_grade == 0) {
            $startdate=strtotime($CcTvAi_com_logintime);
            $enddate=strtotime(date('Y-m-d H:i:s'));
            $days=round(($enddate-$startdate)/3600/24);
            if($days >= 1) {
                $db->query("update " . tname('user') . " set cd_viprank=cd_viprank-" . ($days*5) . " where cd_viprank>=1 and cd_id=" . $CcTvAi_com_userid);
            }
        }
    }

    if($CcTvAi_com_djmub >= cd_userupmusicmub && cd_userupmusicmub >= 1 && $CcTvAi_com_checkmusic == 0) {
        $setarr=array(
            'cd_uid'=>0,
            'cd_uname'=>'系统提示',
            'cd_uids'=>$CcTvAi_com_userid,
            'cd_unames'=>$CcTvAi_com_username,
            'cd_icon'=>'account',
            'cd_data'=>'恭喜，系统已经将您自动授予音乐认证！',
            'cd_dataid'=>0,
            'cd_state'=>1,
            'cd_addtime'=>date('Y-m-d H:i:s')
        );
        inserttable('notice', $setarr, 1);
        $db->query("update " . tname('user') . " set cd_checkmusic=1 where cd_id=" . $CcTvAi_com_userid);
    }
    if(getrankname($CcTvAi_com_rank, 1) > $CcTvAi_com_level) {
        $db->query("update " . tname('user') . " set cd_level='" . getrankname($CcTvAi_com_rank, 1) . "' where cd_id=" . $CcTvAi_com_userid);
        $setarr=array(
            'cd_uid'=>0,
            'cd_uname'=>'系统提示',
            'cd_uids'=>$CcTvAi_com_userid,
            'cd_unames'=>$CcTvAi_com_username,
            'cd_icon'=>'account',
            'cd_data'=>'恭喜，您的用户等级升级到Lv' . getrankname($CcTvAi_com_rank, 1) . '/' . getrankname($CcTvAi_com_rank, 2) . '',
            'cd_dataid'=>0,
            'cd_state'=>1,
            'cd_addtime'=>date('Y-m-d H:i:s')
        );
        inserttable('notice', $setarr, 1);
        $setarr=array(
            'cd_type'=>1,
            'cd_uid'=>$CcTvAi_com_userid,
            'cd_uname'=>$CcTvAi_com_username,
            'cd_icon'=>'update',
            'cd_title'=>'用户等级提升至Lv' . getrankname($CcTvAi_com_rank, 1) . '/' . getrankname($CcTvAi_com_rank, 2) . '',
            'cd_points'=>cd_upgradepoints,
            'cd_state'=>0,
            'cd_addtime'=>date('Y-m-d H:i:s'),
            'cd_endtime'=>date('Y-m-d H:i:s')
        );
        inserttable('bill', $setarr, 1);
        $db->query("update " . tname('user') . " set cd_points=cd_points+'" . cd_upgradepoints . "' where cd_id=" . $CcTvAi_com_userid);
    }
    if(cd_djdayhitstime == "yes") {
        $daytime=date('Ymd');
        $newtime=$db->getrow('select * from ' . tname('system') . '');
        if($newtime['cd_daynewtime'] != $daytime) {
            $db->query('update ' . tname('dj') . " set CD_DayHits=0");
            $db->query('update ' . tname('video') . " set CD_DayHits=0");
            $db->query('update ' . tname('system') . " set cd_daynewtime=" . $daytime . "");
        }
    }
    if(cd_djweekhitstime == "yes") {
        $daytime=date('w');
        $daytimes=date('Ymdw');
        if($daytime == 1) {
            $newtime=$db->getrow('select * from ' . tname('system') . '');
            if($newtime['cd_weeknewtime'] !== $daytimes) {
                $db->query('update ' . tname('dj') . " set CD_WeekHits=0");
                $db->query('update ' . tname('video') . " set CD_WeekHits=0");
                $db->query('update ' . tname('system') . " set cd_weeknewtime=" . $daytimes . "");
            }
        }
    }
    if(cd_djmonthhitstime == "yes") {
        $daytime=date('d');
        $daytimes=date('Ymd');
        if($daytime == '01') {
            $newtime=$db->getrow('select * from ' . tname('system') . '');
            if($newtime['cd_monthnewtime'] !== $daytimes) {
                $db->query('update ' . tname('dj') . " set CD_MonthHits=0");
                $db->query('update ' . tname('video') . " set CD_MonthHits=0");
                $db->query('update ' . tname('system') . " set cd_monthnewtime=" . $daytimes . "");
            }
        }
    }

}
?>
<?php include_once('source/space_header.php');?>
<?php include_once('source/space_' . $ac . '.php');?>
