<?
require_once('include/global.php');
require_once('include/pager.php');
require_once("include/bigfile_lib.php");
require_once('include/member_size_lib.php');
require_once('conf.inc.php');


// set
	$CFG['TITLE'] = '<b>대용량 첨부내역</b>';


// 계정 사용용량 재갱신	- 첫 페이지에서만, 검색이 아닐때만 재갱신함.
	if ($_GET['pageID'] <= 1 && $_GET['s_word'] == '')
		member_size_update_check($AUTH['auth_m_no']);


// data

	// search
		$q_where = '';
		if ($_GET['s_word'])
		{
			set_q_search($_GET['s_word']);
			$q_where = " AND ( bf_to LIKE '%" . $_GET['s_word'] . "%' OR bf_subject LIKE '%" . $_GET['s_word'] . "%' OR bf_name LIKE '%" . $_GET['s_word'] . "%' ) ";
			$v_s_word = htmlspecialchars_fix(stripslashes($_GET['s_word']));
		}	// if()

	// sort
		$CFG['BIGFILE_FIELD'] = array(
				'bf_to' => '받는이',
				'bf_subject' => '제 목',
				'bf_type' => '첨부방식',
				'bf_name' => '파일',
				'bf_size' => '크기',
				'bf_down' => '다운',
				'bf_regdate' => '보낸날짜',
				);
		$order_set = get_order(array_keys($CFG['BIGFILE_FIELD']), 'bf_key', $_GET['s_key'], $_GET['s_key2']);
		$order_img = get_order_img(array_keys($CFG['BIGFILE_FIELD']), $_GET['s_key'], $_GET['s_key2'], false, 'common_skin');		// array

	// db - pager
		$DEBUG['db_cnt']['start'] = getmicrotime();
		$pager_params['totalItems'] = db_get_one("SELECT COUNT(*) FROM " . $TB['BIGFILE'] . " WHERE m_no='" . $AUTH['auth_m_no'] . "'" . $q_where);
		// [2007-05-29]
		//$pager_params['perPage'] = 20;
		if (!is_numeric($_GET['page_size']) || $_GET['page_size'] > $G_SYS['MAIL_LIST_COUNT'])
		{
			$dfcon = get_default_config($AUTH['auth_m_no']);
			$_GET['page_size'] = $dfcon['m_cfg_mail_list_cnt'];
		}	// if()
		$pager_params['perPage'] = $_GET['page_size'];

		$DEBUG['db_cnt']['exec'] += getmicrotime() - $DEBUG['db_cnt']['start'];

		// [2016-01-11] PHP 5버전대에서 Ampersand가 DEPRECATED처리되어 &삭제
		#$pager = &new Pager_Sliding($pager_params);
		// [2016-01-11] Ampersand가 DEPRECATED관련하여 PEAR Pager라이브러리 업그레이드 소스적용  
		#$pager = new Pager_Sliding($pager_params);
		$pager = Pager::factory($pager_params);
		$pager_links = $pager->getLinks();
		$pager_limit = get_pager_limit($pager->getCurrentPageID(), $pager_params['perPage']);

	// db - select
		$DEBUG['db_select']['start'] = getmicrotime();
		$sql = "
			SELECT
				*
			FROM
				" . $TB['BIGFILE'] . "
			WHERE
				m_no='". $AUTH['auth_m_no'] . "'
				" . $q_where . "
			ORDER BY
				" . $order_set['query'] . "
			";
		$rows = db_get_rows($sql, $pager_limit['from'], $pager_limit['count']);
		$DEBUG['db_select']['exec'] += getmicrotime() - $DEBUG['db_select']['start'];

	// process data
		$DEBUG['db_fetch_all']['start'] = getmicrotime();

		$view = array();
		for ($i=0; $i<sizeof($rows); $i++)
		{
			$view['bf_key'][$i] = $rows[$i]['bf_key'];
			$view['bf_to'][$i] = address_view($rows[$i]['bf_to']);
			$_ap = mime_address_parse($rows[$i]['bf_to']);
			$view['bf_to_view'][$i] = $_ap['display'];
			$view['bf_subject'][$i] = (trim($rows[$i]['bf_subject']) == NULL) ? '__제목없음__' : htmlspecialchars_fix(han_substr($rows[$i]['bf_subject'], 90));
			if ($rows[$i]['mf_no'])
			{
				$view['bf_subject'][$i] = '<a href="'.$nmpath.'/mail_read.php?mb_id=sent&mf_no='.$rows[$i]['mf_no'].'&back_url='.urlencode($_SERVER['REQUEST_URI']).'">'.$view['bf_subject'][$i].'</a>';
			} else 
			{
				$view['bf_subject'][$i] = '<a href="JavaScript:alert(\'보낸편지함에 저장하지 않은 메일입니다.\');">'.$view['bf_subject'][$i].'</a>';
			}	// if()

			if ($rows[$i]['bf_type'] == 'W')
			{
				$view['bf_type'][$i] = '웹하드';
			} else
			{
				$view['bf_type'][$i] = '대용량첨부';
			}	// if()

			$view['bf_size'][$i] = filesize_human($rows[$i]['bf_size']);

			// 만료여부 검사
			$is_expire = bigfile_expire($rows[$i], false);
			$view['bf_regdate'][$i] = substr($rows[$i]['bf_regdate'],2, 14);
			if ($is_expire)
			{
				$view['bf_down'][$i] = '<font color=red><strike>'.$rows[$i]['bf_down'].'</strike></font>';
				$view['bf_regdate'][$i] = '<font color=red><strike>'.$view['bf_regdate'][$i].'</strike></font>';
				$view['bf_name'][$i] = '<strike>'.$rows[$i]['bf_name'].'</strike>';
				$view['bf_size'][$i] = '<strike>'.$view['bf_size'][$i].'</strike>';
			} else 
			{
				$view['bf_down'][$i] = '<font color=blue>'.$rows[$i]['bf_down'].'</font>';
				$view['bf_regdate'][$i] = '<font color=blue>'.$view['bf_regdate'][$i].'</font>';
				$view['bf_name'][$i] = '<a href="'.$nmpath.'/bigfile_down.php?id='.bigfile_id_encode2($rows[$i]).'">'.$rows[$i]['bf_name'].'</a>';
			}	// if()
		}	// for()
		$view_cnt = sizeof($rows);

		$DEBUG['db_fetch_all']['exec'] += getmicrotime() - $DEBUG['db_fetch_all']['start'];

	// 메일수
		$mail_all_cnt = number_format($pager_params['totalItems']);


	// 사용량
		$q = "SELECT m_bigfile_quota FROM ".$TB['MEMBER']." WHERE m_no='".$AUTH['auth_m_no']."'";
		$m_bigfile_quota = db_get_one($q);
		$m_bigfile_quota = $m_bigfile_quota*1024;
		$m_bigfile_quota_view = filesize_human($m_bigfile_quota);

		$q = "SELECT ms_bigfile FROM ".$TB['MEMBER_SIZE']." WHERE m_no='".$AUTH['auth_m_no']."'";
		$ms_bigfile = db_get_one($q);
		$ms_bigfile_view = filesize_human($ms_bigfile);

		$bigfile_free_size = $m_bigfile_quota - $ms_bigfile;
		if ($bigfile_free_size < 0)
			$bigfile_free_size = 0;

		$m_bigfile_quota_rate = @ceil($ms_bigfile / $m_bigfile_quota * 100);


// skin view
	nskinset('webmail', 'bigfile_list.html');
	include($NSKIN['view_layout']);


require_once('include/global_end.php');
?>