<?
require_once('../include/global.php');
require_once("include/admin_webhard_share_lib.php");
require_once("include/webhard_lib.php");
require_once('include/pager.php');
#require_once('sadmin_conf.inc.php');


// set
	if ($_GET['isadmin'])
	{
		auth_limit('admin');
		$CFG['TITLE'] = '<b>관리자메뉴</b> >> <b>공용웹하드관리</b>';
		$_GET['d_no'] = $G['DINFO']['d_no'];
	} else
	{
		auth_limit('serveradmin');
		$CFG['TITLE'] = '<b>메일서버관리</b> >> <b>전체 공용웹하드관리</b>';
	}	// if()


// data

	// search
		$q_where = " AND ws.d_no=d.d_no ";
		if ($_GET['s_word'])
		{
			set_q_search($_GET['s_word']);
			$q_where .= " AND ( d.d_name LIKE '%" . $_GET['s_word'] . "%' OR ws.ws_name LIKE '%" . $_GET['s_word'] . "%' OR ws.ws_guest_id LIKE '%" . $_GET['s_word'] . "%' OR ws.ws_admin_id LIKE '%" . $_GET['s_word'] . "%' OR ws.ws_memo LIKE '%" . $_GET['s_word'] . "%' ) ";
			$v_s_word = htmlspecialchars_fix(stripslashes($_GET['s_word']));
		}	// if()

		if ($_GET['d_no'])
			$q_where .= " AND ws.d_no='".$_GET['d_no']."' ";

	// sort
		$CFG['ADMIN_WEBHARD_SHARE_FIELD'] = array(
				'd.d_name' => '도메인',
				'ws.ws_name' => '공용웹하드 이름',
				'ws.ws_mg_no' => '회원 조직',
				'ws.ws_guest_id' => 'Guest 계정',
				'ws.ws_perm' => '사용권한',
				'ws.ws_admin_id' => '관리자 ID',
				'ws.ws_isuse' => '사용여부',
				'ws.ws_regdate' => '등록일자',
				'ws.ws_quota' => '용량'
				);
		if ($_GET['isadmin'])
			unset($CFG['ADMIN_WEBHARD_SHARE_FIELD']['d.d_name']);

		$order_set = get_order(array_keys($CFG['ADMIN_WEBHARD_SHARE_FIELD']), 'ws.ws_key', $_GET['s_key'], $_GET['s_key2']);
		$order_img = get_order_img(array_keys($CFG['ADMIN_WEBHARD_SHARE_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['WEBHARD_SHARE'] . " ws,
				" . $TB['DOMAIN'] . " d
			WHERE
				1=1
				" . $q_where
			);
		$pager_params['perPage'] = 20;

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

		$pager = &new Pager_Sliding($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
				ws.*, d.d_name
			FROM
				" . $TB['WEBHARD_SHARE'] . " ws,
				" . $TB['DOMAIN'] . " d
			WHERE
				1=1
				" . $q_where . "
			ORDER BY
				" . $order_set['query'] . "
			";
		$rows = db_get_rows($sql, $pager_limit['from'], $pager_limit['count']);
		$rows_cnt = sizeof($rows);
		$DEBUG['db_select']['exec'] += getmicrotime() - $DEBUG['db_select']['start'];

	// process data
		$DEBUG['db_fetch_all']['start'] = getmicrotime();
		for ($i=0; $i<sizeof($rows); $i++)
		{
			$rows[$i]['ws_regdate'] = substr($rows[$i]['ws_regdate'], 2, 8);

			if ($rows[$i]['ws_mg_no'] != '')
			{
				$q = "SELECT mg_name FROM ".$TB['MEMBER_GROUP']." WHERE d_no='".$rows[$i]['d_no']."' AND mg_no IN (".implode(',', db_str_explode('|', $rows[$i]['ws_mg_no'])).") ORDER BY mg_name";
				$mg = db_get_rows($q, true);
				// [2009-12-09] 회원 조직에 지정된 조직이 삭제되고난 후 에러 메세지 해결
				//$rows[$i]['ws_mg_no'] = implode(',', $mg['mg_name']);
				$rows[$i]['ws_mg_no'] = @implode(',', $mg['mg_name']);
			}	// if()		

			$rows[$i]['ws_guest_id'] = implode(',', db_str_explode('|', $rows[$i]['ws_guest_id']));

			$rows[$i]['ws_perm_view'] = '';
			foreach ($G_SYS['WEBHARD_WS_PERM'] as $key=>$val)
			{
				if (strpos($rows[$i]['ws_perm'], $key) !== false)
				{
					$rows[$i]['ws_perm_view'] .= '<font color=blue>'.$val.'</font>';
				} else
				{
					$rows[$i]['ws_perm_view'] .= '<font color=red><strike>'.$val.'</strike></font>';
				}	// if()
				if ($key != 'D')
					$rows[$i]['ws_perm_view'] .= ',';
			}	// foreach()

			$rows[$i]['ws_admin_id'] = implode(',', db_str_explode('|', $rows[$i]['ws_admin_id']));

			// [2008-02-21] 공용웹하드 용량합계 재계산
			$DEBUG['webhard_share_size_update_check']['start'] = getmicrotime();
			$rows[$i]['ws_quota_use'] = webhard_share_size_update_check($rows[$i]['ws_key']);
			$DEBUG['webhard_share_size_update_check']['exec'] += getmicrotime() - $DEBUG['webhard_share_size_update_check']['start'];

			$rows[$i]['ws_quota'] *= 1024;
			$rows[$i]['ws_quota_use_view'] = filesize_human($rows[$i]['ws_quota_use'], 1);
			$rows[$i]['ws_quota_use_rate'] = @ceil($rows[$i]['ws_quota_use'] / $rows[$i]['ws_quota'] * 100);
			$rows[$i]['ws_quota_view'] = filesize_human($rows[$i]['ws_quota'], 1);
		}	// for()

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

	// 공용웹하드관리수
		$admin_webhard_share_all_cnt = number_format($pager_params['totalItems']);


		// [2008-02-20] 공용웹하드 용량 합산
		require_once('include/webhard_lib.php');
		$m_webhard_quota_sum = get_webhard_quota_sum($_GET['d_no']);

		$d_webhard_quota = db_get_one("SELECT d_webhard_quota FROM ".$TB['DOMAIN']." WHERE d_no='".$_GET['d_no']."'");

		$vd['d_webhard_quota_sum'] = filesize_human($m_webhard_quota_sum*1024, 2);
		$vd['d_webhard_quota_sum_rate'] = @ceil($m_webhard_quota_sum / $d_webhard_quota * 100);
		$vd['d_webhard_quota'] = filesize_human($d_webhard_quota*1024, 2);

	$webhard_demo_limit = webhard_demo_check('S');


// skin view
	nskinset('sadmin', 'admin_webhard_share_list.html');		// 컨텐츠
	include($NSKIN['view_layout']);


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