<?php
/*
	[Office 515158] (C) 2009-2019 天生创想 Inc.
	$Id: sms.class.php 1209087 2018-01-08 08:58:28Z baiwei.jiang $
*/
!defined('IN_TOA') && exit('Access Denied!');
class Annex
{
	//$officetype：模块类型
	//$number：记录ID
	//$filetype：文件类型
	public function Show($officetype,$number,$filetype){
		global $db;
		global $_USER;
		$sqls = "SELECT * FROM ".DB_TABLEPRE.DB_JT."fileoffice WHERE number='".$number."' and officetype='".$officetype."' and filetype='".$filetype."' ORDER BY id desc";
		$result = $db->query($sqls);
		$html='';
		while ($rows = $db->fetch_array($result)) {
			$extention=preg_replace('/.*\.(.*[^\.].*)*/iU','\\1',$rows['filename']);
			if(strtolower($extention)=='doc' || strtolower($extention)=='docx'){
				$html.= $rows['filename'].Annex::Office($rows['number'],$rows['fileaddr'],urlencode($rows['filename']),$rows['date'],'word');
			}elseif(strtolower($extention)=='xls' || strtolower($extention)=='xlsx'){
				$html.= $rows['filename'].Annex::Office($rows['number'],$rows['fileaddr'],urlencode($rows['filename']),$rows['date'],'excel');
			}elseif(strtolower($extention)=='ppt'){
				$html.= $rows['filename'].Annex::Office($rows['number'],$rows['fileaddr'],urlencode($rows['filename']),$rows['date'],'ppt');
			}elseif(strtolower($extention)=='pdf' || strtolower($extention)=='tif'){
				$html.= $rows['filename'].Annex::Office($rows['number'],$rows['fileaddr'],urlencode($rows['filename']),$rows['date'],'pdf');
			}elseif($extention=='jpg' || $extention=='gif' || $extention=='png' || $extention=='bmp'){
				$html.= $rows['filename'].Annex::Pic($rows['fileaddr'],urlencode($rows['filename']),$rows['date']);
			}else{
				$html.= $rows['filename'];
			}
		}
		return  $html;
	}
	public function Pic($fileaddr,$filename,$date){
		return '<a href="ntko/pic.php?fileaddr='.$fileaddr.'&title='.rawurlencode($filename).'&date='.$date.'" target="_blank">查看</a> ';
	}
	
	public function Office($number,$fileaddr,$filename,$date,$type){
		return '<a href="ntko/fileviews.php?fileType='.$type.'&number='.$number.'&fileaddr='.$fileaddr.'&title='.rawurlencode($filename).'&date='.$date.'" target="_blank">打开</a> '.Annex::down($fileaddr,urlencode($filename));
	}
	
	public function down($fileaddr,$filename){
		return '<a href="downurl.php?urls='.$fileaddr.'&filename='.urlencode($filename).'">下载</a> ';
	}
	
	
	

}

?>