<?php
define('THIS_SCRIPT', 'fileshow');
require_once 'global.php';
include_once CACHE_PATH.'board/board_all.php';
$lang = load_lang($lang, 'fileshow' );
global $title_num,$action,$reaction;
$stats = $lang['tmp.info1'];
$bbs_stat=$fsetting['forumname'];
$title_num = array(
	0=>array('linktitle'=>$_DCACHE['all_forums'][$boardid]['boardtype'])
	);
if($title_num[0]['linktitle']=="" and $action=='' or empty($title_num[0]['linktitle']) and $action==''){
	$title_num = array(
	0=>array('linktitle'=>$lang['forumshow'].$lang['template.str2'])
	);
}
elseif($action=='send'){
	$title_num = array(
	0=>array('linktitle'=>$lang['template.str2'],'linkurl'=>'show.php')
	,1=>array('linktitle'=>$lang['template.str1'].$lang['template.str2'])
	);
}
else {
	$title_num = array(
	0=>array('linktitle'=>$_DCACHE['all_forums'][$boardid]['boardtype'])
	,1=>array('linktitle'=>$lang['forumshow'].$lang['template.str2'])
	);
}
LoadStyleJs();
PageLoad();
LoadFooter();
function PageLoad(){
	global $dv,$db,$lang,$id,$info_list,$send,$msg_num,$action,$userid,$id,$friend_list,$vipuser,$boardmaster,$superboardmaster,$master,$membername,$sendok,$title,$subject,$sname,$sender,$body,$showfile,$fsetting,$upload_url;
	$upload_url=$fsetting['forumuploadname']."/";
	$sendok=false;
	if( $userid <= 0 ){
		//head();
		LoadStyleJs();
		showmsg($lang['Error.strings1']);
		exit;
	}
	if($action=="save"){
		save_card();
		my_friend();
	}
	else{ 
		main_sub();
		click_num();
	}
	//read_msg();¶Á¶ÌÐÅÏ¢;
include_once printout('fileshow');//print fileshow.htm;
}
function main_sub(){
	global $info_list,$dv,$db,$lang,$id;
	$info_list=array();
	if(!is_numeric($id)){
		showmsg($lang['tpl.htm.str22']);
		exit;
	}
	else{
		$sql="select f_id,f_announceid,f_boardid,f_userid,f_username,f_filename,f_filetype,f_type,f_filesize,f_readme,f_downnum,f_viewnum,f_downuser,f_flag,f_addtime,f_viewname from {$dv}upfile where f_id=".intval($id)." order by f_id desc";
	}
	$result=$db->query($sql);
	while ($arr=$db->fetch_array($result)){
		$info_list[]=$arr;
	}
	$db->free_result($result);
}
function save_card(){
	global $dv,$db,$lang,$userid,$title,$subject,$sname,$sender,$body;
		$sname=htmlspecialchars($sname);
		$sender=htmlspecialchars($sender);
		$title=htmlspecialchars($title);
		$body=htmlspecialchars($body);
		if(str_replace(" ","",$title)==""){
			showmsg($lang['error.info2']);
		exit;
		}
		elseif(str_replace(" ","",$subject)==""){
			showmsg($lang['error.info1']);
		exit;
		}
		else{
			$title=trim($title);
			$sname=trim($subject);
			$sender=trim($userid);
			$body=trim($body);
			$now=TIME_NOW;
			$sql="insert into {$dv}message set incept='$sname',sender='$sender',title='$title',content='$body',sendtime='$now',flag='0',issend='1'";
			$result=$db->query($sql);
			if($result){
				showmsg($lang['succse.str1']);
			exit;
			}
			else{
				showmsg($lang['lost.str1']);
			exit;
			}
		}
}
function click_num(){
	global $dv,$db,$lang,$id;
	$sql="update {$dv}upfile set f_viewnum=(f_viewnum+1) where f_id=".intval($_GET['id'])."";
	$result=$db->query($sql);
}
function my_friend(){
	global $dv,$db,$lang,$friend,$friend_list,$userinfo;
	$friend_list=array();
	 $sql="select f_id,f_userid,f_mod,f_friend,f_username from {$dv}friend where f_username='".trim($userid)."'";
	 $result=$db->query($sql);
	 while($arr=$db->fetch_array($result)){
		$friend_list[]=$arr;
	 }
	 $db->free_result($result);
}
function read_msg(){
		global $dv,$db,$lang,$msg_num;
		$sql="select count(id) as col from {$dv}message where incept='$userid' and flag=0";
		$result=$db->query($sql);
		$arr=$db->fetch_array($result);
		$msg_num=$arr['col'];
	return($msg_num);
$db->free_result($result);
}
?>