<?
/*
	---------------------------------------------------------------
	点歌台 V1.0.0 for discuz!5.0.0 RC1 
	---------------------------------------------------------------
	演示网站: http://piaoyun.miyahost.com/bbs/
	原版作者: 雪狼 (伊乐园中文论坛)
	最终修改: 飘云[PYG]
	官方论坛: WwW.ChiNaPYG.CoM
        修改日期: 2006.8.1
*/
require "./include/common.inc.php";
require "./songconfig.php";
$discuz_action = 242;
if(!$discuz_user) { showmessage('not_loggedin'); }
if($action=='addsong') {
	if(!$discuz_user){showmessage('not_loggedin');}
	
	if ($trans_unit=='money') {
		$query=$db->query("select money from {$tablepre}members where username='$discuz_user'");
		$money=@$db->fetch_array($query);
		$nowmoney=$money[money];
		if($nowmoney<$fee) {
			showmessage("对不起，您的现金不足！","song.php");
		}
	} elseif ($trans_unit=='credits') {
		$query=$db->query("select extcredits2 from {$tablepre}members where username='$discuz_user'");
		$money=@$db->fetch_array($query);
		$nowcredits=$money[extcredits2];
		if($nowcredits<$usecredits) {
			showmessage("对不起，你的积分不够！","song.php");
		}
	}

	if(!$touser)showmessage("用户名不能为空","addsong.php");
	$query=$db->query("select count(*) as rnct from {$tablepre}members where username='$touser'");
	$data=@$db->fetch_array($query);

	if ($touser != '所有的人' && $touser != '┬Τ参'){
	if(!$data[rnct])showmessage("指定用户不是社区用户","addsong.php");} else {$toall=1;
             }
	if($advshow){
		$songname=$songxid;
		$songurl=$songxpath;
	}else{
		$f=file("song/song.dat");
		list($songname,$songurl)=explode("||",$f[$songid]);
	}
		$url=explode(".",$songurl);
		$mcount=count($url);
		$mcount--;
		switch ($url[$mcount]) {
			case mp3:
			case rm:
			case ra:
			case rpm:
	   		$songurl=$songurl;
			$songtype=real;
			break;
	   		case swf:
   			$songurl=$songurl;
			$songtype=flash;
	   		break;
   			case asf:
			case wma:
			case wmv:
			case mid:
	   		$songurl=$songurl;
			$songtype=wmp;
	   		break;
	   		default:
	   		$songurl='';
	   		break;	
		}
	if(!$songurl) {showmessage("不支持该格式的歌曲","addsong.php");}

	if ($trans_unit=='money') {
		$newmoney=$nowmoney-$fee;
		$sql_query="SET money='$newmoney'";
		
	} elseif ($trans_unit=='credits') {
		$newcredits=$nowcredits-$usecredits;
		$sql_query="SET extcredits2='$newcredits'";
		
	} else {

		$fee_is_none='free';
	}

	if (empty($fee_is_none)) {
		$query=$db->query("UPDATE {$tablepre}members $sql_query WHERE username='$discuz_user'");
		unset($query);
	}

	$stime=time();
	if ($teding && $toall != 1){$particular=1;}
	else{$particular=0;}

	$songname =  dhtmlspecialchars($songname);
	$content=dhtmlspecialchars($content);

	$query=$db->query("insert into cdb_xn_song (sgid,username,touser,songname,songurl,songtype,content,stime,particular) values ('','$discuz_user','$touser','$songname','$songurl','$songtype','$content','$stime','$particular')");	
             unset($query);	

	if($topm && $toall != 1){
		
		$subject = "点歌台通知";
		$timestamp = time();				
					
                           $tempquery = $db->query("SELECT uid FROM {$tablepre}members WHERE username='$touser'");
                           $tempfetch = $db->fetch_array($tempquery);
                           $changetoid = $tempfetch[uid];
                           $songmessage = $touser." 您好，\n\n您的朋友".$discuz_user."给你送上一首【".$songname."】\n请到论坛点歌台查收\n\n祝您收听愉快！";
                           unset($tempfetch,$tempquery);
                           $db->query("INSERT INTO {$tablepre}pms (msgfrom, msgfromid, msgtoid, folder, new, subject, dateline, message)
                                VALUES('$discuz_user', '$discuz_uid', '$changetoid', 'inbox', '1', '$subject', '$timestamp', '$songmessage')");
                           $db->query("UPDATE {$tablepre}members SET newpm='1' WHERE uid='$changetoid'", 'UNBUFFERED');
		
		}
	{showmessage("谢谢！您已经成功完成点歌程序了。","song.php");}
}else{

	$navigation="<a href=\"song.php\">论坛点歌台</a> &raquo; 点歌";

	if ($trans_unit=='money') {
		$query=$db->query("SELECT money FROM {$tablepre}members where username='$discuz_user'");
		$money=@$db->fetch_array($query);
		$nowmoney=$money[money];
		unset($query);
		unset($money);
		$msg='需付 <b><font color="#FF0000">'.$fee.'</font></b> '.$unit_name.'，点播歌曲在 
		<b><font color="#FF0000">'.$day.'</font></b> 天后将自动失效。您现在有 
		<b><font color="#FF0000">'.$nowmoney.'</font></b> '.$unit_name.'，如果现金不足请到<a href="bank.php"><b>银行</b></a>提款。';
	} elseif ($trans_unit=='credits') {
		$query=$db->query("SELECT extcredits2 FROM {$tablepre}members where username='$discuz_user'");
		$money=@$db->fetch_array($query);
		$nowcredits=$money[extcredits2];
		unset($query);
		unset($money);
		$msg='需扣 <b><font color="#FF0000">'.$usecredits.'</font></b> '.$unit_name.'，点播歌曲在 
		<b><font color="#FF0000">'.$day.'</font></b> 天后将自动失效。您现在有 
		<b><font color="#FF0000">'.$nowcredits.'</font></b> '.$unit_name.'。';
	} else {
		
		$msg='是免费的，点播歌曲在 
		<b><font color="#FF0000">'.$day.'</font></b> 天后将自动失效。';
	}
	
	$f=file("song/song.dat");
    	$mcount=count($f);
    	$i=0;
    	$songlist='';
		while($i<$mcount)	{
			list($songname,$songurl)=explode("||",$f[$i]);
			$songlist.="<option value=\"$i\">$songname</option>";	
			$i++;
		}
	}

include template('club_addsong');
?>