<?php 
/**
#	Project: PHPDISK File Storage Solution
#	This is NOT a freeware, use is subject to license terms.
#
#	Site: http://www.phpdisk.com
#
#	$Id: files.inc.php 64 2016-07-30 14:01:18Z along $
#
#	Copyright (C) 2008-2016 PHPDisk Team. All Rights Reserved.
#
*/

if(!defined('IN_PHPDISK') || !defined('IN_MYDISK')) {
	exit('[PHPDisk] Access Denied');
}

// fix set_extract_code
$a_upload_file = urr("mydisk","item=upload&folder_id=$folder_id&uid=$pd_uid");
$a_folder_create = urr("mydisk","item=folders&action=folder_create");
$a_share_folder = '';
$a_list_detail = urr("mydisk","item=files&action=detail");

$group_set = $group_settings[$pd_gid];
/*if(display_plugin('multi_server','open_multi_server_plugin',$settings['open_multi_server'],0)){
// reload $a_upload_file
$rs = $db->fetch_one_array("select server_host,server_key from {$tpf}servers where is_default=1 limit 1");
if($rs){
$a_upload_file = $rs['server_host'].urr("mydisk","item=upload&folder_id=$folder_id&uid=$pd_uid");
}
unset($rs);
}*/
//echo $a_upload_file;
$tmp_arr = array('a_folder_create'=>$a_folder_create,'a_upload_file' =>$a_upload_file,'a_list_detail'=>$a_list_detail,'a_share_folder'=>$a_share_folder,'title'=>__('extract_file_list'));
$nav_arr = get_my_nav($tmp_arr);

switch($action){
	case 'ftp_upload':
		if(display_plugin('phpdisk_ftp','open_phpdisk_ftp_plugin',1,0)){
			$rs = $db->fetch_one_array("select * from {$tpf}ftp where userid='$pd_uid' limit 1");
			if(!$rs || $rs[ftp_locked]){
				$msg = 'FTP上传服务未配置或被锁定，暂时无法使用';
			}
			$hash = md5(md5($_SERVER['HTTP_USER_AGENT'].'import'.$onlineip.$rs['userid']));
			$a_import = $rs[file_host].'plugins/phpdisk_ftp/import.php?param='.rawurlencode(pd_encode("uid={$rs['userid']}&job=import&username=$rs[username]&hash=$hash"));
		}else{
			$msg = '网盘FTP上传插件未启用';
		}
		require_once template_echo('files',$user_tpl_dir);
		break;
	case 'multi_down':
		$file_ids = gpc('file_ids','GP','');

		$file_str = get_ids($file_ids);

		$q = $db->query("select * from {$tpf}files where file_id in ($file_str)");
		$filearr = array();
		while ($rs = $db->fetch_array($q)) {
			$rs[tmp_ext] = $rs[file_extension] ? '.'.$rs[file_extension] : '';
			$rs[file_name] = $rs[file_name].$rs[tmp_ext];
			$filearr[] = $rs;
		}
		$db->free($q);
		unset($rs);

		if($task=='multi_down' && $auth[pd_3]){
			if(count($filearr)){
				$dir = PHPDISK_ROOT.'system/cache/'.$pd_uid.'/';
				make_dir($dir);
				$pt_str = '';
				foreach($filearr as $v){
					if(@copy(PHPDISK_ROOT.$settings[file_path].'/'.$v[file_store_path].$v[file_real_name].$v[tmp_ext],$dir.convert_str('utf-8','gbk',$v[file_name]))){
						$pt_str .= convert_str('utf-8','gbk',trim($v[file_name])).',';
					}else{
						$pt_str .= convert_str('utf-8','gbk',trim($v[file_name]).'[文件不存在]').',';
					}
				}
				$pt_arr = explode(',',substr($pt_str,0,-1));
				//print_r($pt_arr);exit;
				$zipfile="";
				$zip = new zip;
				$dl = $pt_arr;
				for($k=0;isset($dl[$k]);$k++){
					$zipfile=$dir."/".$dl[$k];
					$filename=$dl[$k];
					$filesize=@filesize($zipfile);
					$fp=@fopen($zipfile,rb);
					$zipfiles[]=Array($filename,@fread($fp,$filesize));
					@fclose($fp);
					@unlink($zipfile);
				}
				@rmdir($dir);
				$zip->Add($zipfiles,1);
				$code = $zip->get_file();
				//print_r($code);exit;
				ob_end_clean();
				$ext_fn = '网盘文件打包下载('.date('Y-m-d').')';
				$ua = $_SERVER["HTTP_USER_AGENT"];
				if(preg_match("/MSIE/i", $ua)){
					header('Content-disposition: attachment;filename="'.convert_str('utf-8','gbk',$ext_fn).'.zip"');
				}else{
					header('Content-disposition: attachment;filename="'.$ext_fn.'.zip"');
				}
				header('Content-Encoding: none');
				header('Content-Transfer-Encoding: binary');
				header("Content-type: application/octet-stream");
				header("Accept-Length: ".strlen($code));
				echo $code;
				exit;
			}else{
				exit('no file');
			}
		}else{

			require_once template_echo('files',$user_tpl_dir);
		}
		break;
	case 'download':
		$file_id = (int)gpc('file_id','GP',0);
		$num = @$db->result_first("select count(*) from {$tpf}shares where is_file=1 and share_fid='$file_id'");
		$num2 = @$db->result_first("select count(*) from {$tpf}files where file_id='$file_id' and userid='$pd_uid'");
		$num3 = @$db->result_first("select count(*) from {$tpf}shares where is_file=0 and share_fid=(select folder_id from {$tpf}files where file_id='$file_id')");
		$num4 = @$db->result_first("select count(*) from {$tpf}msg_file where touserid='$pd_uid' and file_id=$file_id");

		if($num || $num2 ||$num3 || $num4){
			$file = $db->fetch_one_array("select * from {$tpf}files where file_id='$file_id'");
			if($file){
				$file[a_downfile] = create_down_url($file);
				$file[file_time] = $file[file_time] ? date('Y-m-d',$file[file_time]) : '-';
				$file[file_last_view] = $file[file_last_view] ? date('Y-m-d',$file[file_last_view]) : '-';
				$file[file_size] = get_size($file[file_size]);
				$tmp_ext = $file[file_extension] ? '.'.$file[file_extension] : '';
				$file[file_name_all] = $file[file_name].$tmp_ext;
			}
			$db->query_unbuffered("update {$tpf}files set file_last_view='$timestamp',file_views=file_views+1 where file_id='$file_id'");
			$userid = @$db->result_first("select userid from {$tpf}files where file_id='$file_id' and in_recycle=0 and is_del=0");
			add_credit_log($file_id,1,'view',$userid,$pd_uid);
			require_once template_echo('files',$user_tpl_dir);
		}else{
			tb_redirect('','您权限不足，无法访问此文件',0);
			exit;
		}

		break;
	case 'search':
		$nav_arr['title'] = '搜索网盘文件(夹)';
		$srh_type = (int)gpc('srh_type','G',0);
		$word = trim(gpc('word','G',''));
		$word = replace_inject_str($word);

		if($word){
			$perpage = 30;

			if($srh_type==3){
				$tmp_word = (int)$word;
				$sql_do = " {$tpf}folders where folder_id='$tmp_word' and userid='$pd_uid'";

			}elseif($srh_type==2){
				$sql_do = " {$tpf}folders where folder_name like '%$word%' and userid='$pd_uid'";

			}elseif($srh_type==1){
				$tmp_word = (int)$word;
				$sql_do = " {$tpf}files where file_id='$tmp_word' and userid='$pd_uid' and in_recycle=0 and is_del=0";

			}else{
				$sql_do = " {$tpf}files where (file_name like '%$word%' or file_extension like '%$word%') and userid='$pd_uid' and in_recycle=0 and is_del=0";

			}
			if($srh_type==2||$srh_type==3){
				$rs = $db->fetch_one_array("select count(*) as total_num from {$sql_do}");
				$total_num = $rs['total_num'];
				$start_num = ($pg-1) * $perpage;

				$q = $db->query("select * from {$sql_do} order by folder_id asc");
				$sub_folders = array();
				while($rs = $db->fetch_array($q)){
					$rs['folder_name'] = str_ireplace($word,'<span class="txtred">'.$word.'</span>',$rs['folder_name']);
					$rs['folder_icon'] = $rs['in_share'] ? 'share_folder' : 'folder';
					$rs['folder_size'] = get_size($rs['folder_size']);
					$rs['folder_time'] = date("Y-m-d",$rs['in_time']);
					$rs['a_view'] = urr("mydisk","item=files&menu=file&action=index&folder_id={$rs['folder_id']}");
					$rs['a_modify'] = urr("mydisk","item=folders&action=folder_modify&folder_id={$rs['folder_id']}");
					$rs['a_delete'] = urr("mydisk","item=folders&action=folder_delete&folder_id={$rs['folder_id']}");

					$sub_folders[] = $rs;
				}
				$db->free($q);
				unset($rs);
			}else{
				$rs = $db->fetch_one_array("select count(*) as total_num from {$sql_do}");
				$total_num = $rs['total_num'];
				$start_num = ($pg-1) * $perpage;

				$q = $db->query("select * from {$sql_do} order by file_id desc limit $start_num,$perpage");
				$files_array = array();
				while($rs = $db->fetch_array($q)){
					$rs['a_downfile'] = create_down_url($rs);
					$tmp_ext = $rs['file_extension'] ? '.'.$rs['file_extension'] : "";
					$rs['file_thumb'] = get_file_thumb($rs);

					$rs['file_name_all'] = $rs['file_name'].$tmp_ext;
					$rs['file_name_all'] = str_ireplace($word,'<span class="txtred">'.$word.'</span>',$rs['file_name_all']);
					$rs['file_name'] = cutstr($rs['file_name_all'],80);
					$rs['file_size'] = get_size($rs['file_size']);
					$rs['file_description'] = cutstr($rs['file_description'],80);
					$rs['file_time'] = date("Y-m-d",$rs['file_time']);
					$rs['a_viewfile'] = urr("mydisk","item=files&action=download&file_id={$rs['file_id']}");
					$rs['a_out_share'] = urr("mydisk","item=files&action=out_share&file_id={$rs['file_id']}");
					$rs['a_file_modify'] = urr("mydisk","item=files&action=file_modify&file_id={$rs['file_id']}");
					$rs['a_file_delete'] = urr("mydisk","item=files&action=file_delete&file_id={$rs['file_id']}");
					$rs['a_file_unshare'] = urr("mydisk","item=share&action=unshare_file&sel_type=all&file_id={$rs['file_id']}");
					if($rs[share_end_time]<$timestamp){
						$rs[link_ico] = 'ico_link.gif';
						$rs[link_txt] = '设置外部共享';
					}else{
						$rs[link_ico] = 'ico_link_share.gif';
						$rs[link_txt] = '外部共享中';
					}
					$files_array[] = $rs;
				}
				$db->free($q);
				unset($rs);
			}

			$page_nav = multi($total_num, $perpage, $pg, urr("mydisk","item=files&menu=file&action=$action&srh_type=$srh_type&word=".rawurlencode($word)));
		}
		require_once template_echo('files',$user_tpl_dir);
		break;

	case 'index':
	case 'detail':

		$folder_id = (int)gpc('folder_id','G',0);
		$folder_node = (int)gpc('folder_node','G',0);
		$n = trim(gpc('n','G',''));
		$s = trim(gpc('s','G',''));
		$t = trim(gpc('t','G',''));

		$rs = $db->fetch_one_array("select in_recycle,folder_name,folder_node,parent_id,in_share,folder_description,folder_size from {$tpf}folders where folder_id='$folder_id' and userid='$pd_uid' and in_recycle=0");
		if($rs){
			$folder_description = $rs['folder_description'] ? '['.cutstr(str_replace("\r\n",'',preg_replace("/<.+?>/i","",$rs['folder_description'])),50).']' : '';
			$file_count = (int)@$db->result_first("select count(*) from {$tpf}files where folder_id='$folder_id' and userid='$pd_uid' and in_recycle=0 and is_del=0");
			$folder_stat = $file_count ? ' ('.__('all_file').$file_count.' , '.__('folder_size').get_size($rs['folder_size']).')' : '';
		}
		unset($rs);

		$folder_id = $folder_id ? (int)$folder_id : -1;

		$o_arr = array('asc','desc');
		if($n){
			$sql_order = in_array($n,$o_arr) ? " file_name $n" : " file_name asc";
		}elseif($s){
			$sql_order = in_array($s,$o_arr) ? " file_size $s" : " file_size asc";
		}elseif($t){
			$sql_order = in_array($t,$o_arr) ? " file_time $t" : " file_time asc";
		}else{
			$sql_order = " file_id desc";
		}

		$perpage = 30;
		$sql_do = " {$tpf}files where folder_id='$folder_id' and userid='$pd_uid' and in_recycle=0 and is_del=0";
		$rs = $db->fetch_one_array("select count(*) as total_num from {$sql_do}");
		$total_num = $rs['total_num'];
		$start_num = ($pg-1) * $perpage;

		$q = $db->query("select * from {$sql_do} order by {$sql_order} limit $start_num,$perpage");
		$files_array = array();
		while($rs = $db->fetch_array($q)){
			$rs['a_downfile'] = create_down_url($rs);
			$tmp_ext = $rs['file_extension'] ? '.'.$rs['file_extension'] : "";
			$rs['file_thumb'] = get_file_thumb($rs);

			$rs['file_name_all'] = $rs['file_name'].$tmp_ext;
			$rs['file_name'] = ($action =='detail') ? cutstr($rs['file_name'].$tmp_ext,15) : cutstr($rs['file_name'].$tmp_ext,35);
			$rs['folder_icon'] = $rs['in_share'] ? 'share_folder' : 'folder';
			$rs['file_size'] = get_size($rs['file_size']);
			$rs['file_description'] = cutstr($rs['file_description'],80);
			$rs['file_time'] = date("Y-m-d",$rs['file_time']);
			$rs['a_viewfile'] = urr("mydisk","item=files&action=download&file_id={$rs['file_id']}");
			$rs['a_out_share'] = urr("mydisk","item=files&action=out_share&file_id={$rs['file_id']}");
			$rs['a_file_modify'] = urr("mydisk","item=files&action=file_modify&file_id={$rs['file_id']}");
			$rs['a_file_delete'] = urr("mydisk","item=files&action=file_delete&file_id={$rs['file_id']}");
			$rs['a_file_unshare'] = urr("mydisk","item=share&action=unshare_file&sel_type=all&file_id={$rs['file_id']}");
			if($rs[share_end_time]<$timestamp){
				$rs[link_ico] = 'ico_link.gif';
				$rs[link_txt] = '设置外部共享';
			}else{
				$rs[link_ico] = 'ico_link_share.gif';
				$rs[link_txt] = '外部共享中';
			}
			$files_array[] = $rs;
		}
		$db->free($q);
		unset($rs);

		$a_upload_file = urr("mydisk","item=upload&folder_id=$folder_id&uid=$pd_uid");

		$a_share_folder = $folder_id ? urr("mydisk","item=share&action=share_folder&folder_id=$folder_id&in_share=$in_share") : '';
		$chg_action = ($action=='detail') ? 'index' : 'detail';
		$a_list_detail = urr("mydisk","item=files&action=$chg_action&folder_id=$folder_id");

		$group_set = $group_settings[$pd_gid];
		/*if(display_plugin('multi_server','open_multi_server_plugin',$settings['open_multi_server'],0)){
		// reload $a_upload_file
		$rs = $db->fetch_one_array("select server_host,server_key from {$tpf}servers where is_default=1 limit 1");
		if($rs){
		$a_upload_file = $rs['server_host'].urr("mydisk","item=upload&folder_id=$folder_id&uid=$pd_uid");
		}
		unset($rs);
		}*/

		$tmp_arr = array('a_folder_create'=>$a_folder_create,'a_upload_file' =>$a_upload_file,'a_list_detail'=>$a_list_detail,'a_share_folder'=>$a_share_folder,'title'=>__('file_manage'));
		$nav_arr = get_my_nav($tmp_arr);
		$arrow_arr = array('o_asc'=>'↑','o_desc'=>'↓');
		$n_t = ($n=='asc') ? 'desc' : 'asc';
		$s_t = ($s=='asc') ? 'desc' : 'asc';
		$t_t = ($t=='asc') ? 'desc' : 'asc';
		$n_order = $n ? $arrow_arr['o_'.$n_t] : '';
		$s_order = $s ? $arrow_arr['o_'.$s_t] : '';
		$t_order = $t ? $arrow_arr['o_'.$t_t] : '';
		$n_url = urr("mydisk","item=files&menu=file&action=$action&folder_id=$folder_id&n=$n_t");
		$s_url = urr("mydisk","item=files&menu=file&action=$action&folder_id=$folder_id&s=$s_t");
		$t_url = urr("mydisk","item=files&menu=file&action=$action&folder_id=$folder_id&t=$t_t");
		$arr = explode('&',$_SERVER['QUERY_STRING']);

		$page_nav = multi($total_num, $perpage, $pg, urr("mydisk","item=files&menu=file&action=$action&folder_id=$folder_id&{$arr[4]}"));

		require_once template_echo('files',$user_tpl_dir);

		break;

	case 'file_modify':
		if(!get_group_power($pd_gid,'can_edit_myfile',1)){
			tb_redirect('','您的帐号没有编辑文件权限',0);
			exit;
		}		
		$file_id = (int)gpc('file_id','GP',0);

		if($task == 'file_modify'){
			form_auth(gpc('formhash','P',''),formhash());

			$ref = trim(gpc('ref','P',''));
			$file_name = trim(gpc('file_name','P',''));
			$file_description = trim(gpc('file_description','P',''));

			$cate_id=0;
			if(get_group_power($pd_gid,'can_public_file',1) && $settings[open_public_file]){
				$cate_id = (int)gpc('cate_id','P',0);
			}

			if(checklength($file_name,1,100)){
				$error = true;
				$sysmsg[] = __('file_min_max');
			}
			if($file_description && checklength($file_description,1,250)){
				$error = true;
				$sysmsg[] = __('file_description_min_max');
			}
			if(!$error){
				$ins = array(
				'file_name' => $file_name,
				'file_description' => $file_description,
				'cate_id' => $cate_id,
				'ip' => $onlineip,
				);
				$db->query_unbuffered("update {$tpf}files set ".$db->sql_array($ins)." where file_id='$file_id' and userid='$pd_uid';");

				tb_redirect($ref,__('file_modify_success'));

			}else{
				tb_redirect('back',$sysmsg);
			}
		}else{
			$file = $db->fetch_one_array("select file_name,file_description,in_share,cate_id from {$tpf}files where file_id='$file_id' and userid='$pd_uid' and in_recycle=0 and is_del=0");
			$str = '';
			$ref = $_SERVER['HTTP_REFERER'];
			require_once template_echo('files',$user_tpl_dir);
		}
		break;

	case 'file_delete':
		if(!get_group_power($pd_gid,'can_del_myfile',1)){
			tb_redirect('','您的帐号没有删除文件权限',0);
			exit;
		}
		$file_id = (int)gpc('file_id','GP',0);
		if($task =='file_delete'){
			form_auth(gpc('formhash','P',''),formhash());

			$ref = trim(gpc('ref','P',''));

			$sql = "update {$tpf}files set in_recycle=1 where file_id='$file_id' and userid='$pd_uid'";
			$db->query_unbuffered($sql);
			tb_redirect($ref,__('file_delete_success'));
		}else{
			$rs = $db->fetch_one_array("select file_name,file_extension from {$tpf}files where file_id='$file_id' and userid='$pd_uid' and in_recycle=0 and is_del=0");
			$tmp_ext = $rs['file_extension'] ? '.'.$rs['file_extension'] : "";
			$file_name = $rs['file_name'].$tmp_ext;
			$file_extension = $rs['file_extension'];
			$ref = $_SERVER['HTTP_REFERER'];
			require_once template_echo('files',$user_tpl_dir);
		}
		break;

	case 'make_link_code':
		$file_ids = gpc('file_ids','G','');
		$file_str = get_ids($file_ids);
		$order = gpc('order','G','');
		$order_txt = $order=='asc' ? 'desc' : 'asc';
		if($file_str){
			$q = $db->query("select file_id,file_name,file_key,file_extension,is_image,file_store_path,file_real_name,server_oid from {$tpf}files where file_id in ($file_str) order by file_id $order");
			$upl_array = array();
			while($rs = $db->fetch_array($q)){
				$tmp_ext = $rs['file_extension'] ? '.'.$rs['file_extension'] : "";
				$rs['file_name_all'] = $rs['file_name'].$tmp_ext;
				$rs['file_name'] = cutstr($rs['file_name'].$tmp_ext,35);
				$rs['file_link'] = $settings['phpdisk_url'].urr("viewfile","file_id=".$rs['file_id']);
				$rs['file_link_img'] = $settings['phpdisk_url'].urr("downfile","action=view&file_id=".$rs['file_id']."&file_key=".$rs['file_key']);
				$upl_array[] = $rs;
			}
			$db->free($q);
			unset($rs);
			$order_url = $settings['phpdisk_url'].urr("mydisk","item=$item&menu=file&action=$action&file_ids=$file_str&order=$order_txt");

			require_once template_echo('files',$user_tpl_dir);
		}
		break;
	case 'to_folder':
		$folder_id = (int)gpc('folder_id','GP',0);
		$go_folder = (int)gpc('go_folder','GP',0);
		$file_ids = trim(gpc('file_ids','GP',''));
		$file_str = get_ids($file_ids);
		if($task=='to_folder'){
			form_auth(gpc('formhash','P',''),formhash());
			$dest_fid = (int)gpc('dest_fid','P',0);

			if(!$dest_fid){
				$error = true;
				$sysmsg[] = '请选择目标文件夹。';
			}
			if(!$error){
				$db->query_unbuffered("update {$tpf}files set folder_id='$dest_fid' where file_id in ($file_str) and userid='$pd_uid'");
				$sysmsg[] = '文件移动成功';
				if($go_folder){
					tb_redirect(urr("mydisk","item=files&menu=file&action=index&folder_id=$dest_fid"),$sysmsg);
				}else{
					tb_redirect(urr("mydisk","item=files&menu=file&action=index&folder_id=$folder_id"),$sysmsg);
				}
			}else{
				tb_redirect('back',$sysmsg);
			}
		}else{
			$ref = $_SERVER['HTTP_REFERER'];
			require_once template_echo('files',$user_tpl_dir);
		}
		break;
	case 'to_recycle':

		$file_ids = trim(gpc('file_ids','GP',''));
		$file_str = get_ids($file_ids);

		if($task=='to_recycle'){
			form_auth(gpc('formhash','P',''),formhash());
			$ref = gpc('ref','P','');

			if(!$error){
				$db->query_unbuffered("update {$tpf}files set in_recycle='1' where file_id in ($file_str) and userid='$pd_uid'");
				$sysmsg[] = '删除文件到回收站成功';

				tb_redirect($ref,$sysmsg);

			}else{
				tb_redirect('back',$sysmsg);
			}
		}else{
			$ref = $_SERVER['HTTP_REFERER'];
			require_once template_echo('files',$user_tpl_dir);
		}
		break;
	case 'out_share':
		$file_id = (int)gpc('file_id','GP',0);
		if($task=='out_share'){
			form_auth(gpc('formhash','P',''),formhash());
			$ref = gpc('ref','P','');
			$use_code = (int)gpc('use_code','P',0);
			$expire_time = (int)gpc('expire_time','P',0);

			if(!$error){
				$ins = array(
				'use_code'=>$use_code,
				'expire_time'=>$expire_time,
				'share_end_time'=>$timestamp+$expire_time,
				);
				$db->query_unbuffered("update {$tpf}files set ".$db->sql_array($ins)." where file_id='$file_id' and userid='$pd_uid'");
				$sysmsg[] = '外部共享设置成功';
				tb_redirect('reload',$sysmsg);
			}else{
				tb_redirect('back',$sysmsg);
			}

		}else{
			$ref = $_SERVER['HTTP_REFERER'];
			$pa = $db->fetch_one_array("select * from {$tpf}files where file_id='$file_id' and userid='$pd_uid' and in_recycle=0 and is_del=0");
			$pa[expire_time] = $pa[expire_time] ? $pa[expire_time] : '86400';
			$ext_txt = ($pa[share_end_time]<$timestamp) ? '<span class="txtred">(已过期)</span>' : '';
			$pa[share_end_time] = $pa[share_end_time] ? date('Y-m-d H:i:s',$pa[share_end_time]).$ext_txt : '未共享';
			require_once template_echo('files',$user_tpl_dir);
		}
		break;
	default:
		redirect(urr("mydisk","item=files&menu=file&action=index"),'',0);
}
function get_announce_list(){
	global $db,$tpf;
	$q = $db->query("select subject,annid,in_time from {$tpf}announces where is_hidden=0 order by show_order asc,annid desc");
	$anns = array();
	while($rs = $db->fetch_array($q)){
		$rs['subject'] = htmlspecialchars_decode($rs['subject']);
		$rs[href] = urr("announce","aid=".$rs[annid]);
		$rs[in_time] = date("Y-m-d",$rs['in_time']);
		$anns[] = $rs;
	}
	$db->free($q);
	unset($rs);
	return $anns;
}


?>