<?
require_once('include/global.php');
require_once("include/admin_web_allow_ip_lib.php");
require_once("include/board_lib.php");
require_once('include/pager.php');
require_once('include/member_lib.php');
#require_once('sadmin_conf.inc.php');

// get
	$mf = get_member_field();

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


// data

	// search
		$q_where = " AND m.d_no=d.d_no ";
		if ($_GET['s_word'])
		{
			set_q_search($_GET['s_word']);
			if (strpos($_GET['s_word'], 'm_id=') !== false)
			{
				$_tmp = str_replace('m_id=', '', $_GET['s_word']);
				$q_where .= " AND (m.m_id='" . $_tmp . "') ";
			} else {
				$q_where .= " AND ( d.d_name LIKE '%" . $_GET['s_word'] . "%' OR m.m_id LIKE '%" . $_GET['s_word']
					. "%' OR m.ip_netmask LIKE '%" . $_GET['s_word'] . "%' OR m.ip_ipaddr LIKE '%" . $_GET['s_word']
					. "%' OR m.ip_memo LIKE '%" . $_GET['s_word'] . "%' ) ";
			}
			$v_s_word = htmlspecialchars_fix(stripslashes($_GET['s_word']));
		}	// if()

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

	// sort
		$CFG['ADMIN_WEB_ALLOW_IP_FIELD'] = array(
				'd.d_name' => '도메인',
				'm.m_id' => '아이디',
				'm.ip_ipaddr' => 'IP',
				'm.ip_netmask' => 'NETMASK',
				'm.ip_memo' => '메모',
				'm.ip_regdate' => '등록일자'
				);
		$order_set = get_order(array_keys($CFG['ADMIN_WEB_ALLOW_IP_FIELD']), 'm.ip_regdate', $_GET['s_key'], $_GET['s_key2']);
		$order_img = get_order_img(array_keys($CFG['ADMIN_WEB_ALLOW_IP_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['WEB_ALLOW_IP'] . " m,
				" . $TB['DOMAIN'] . " d
			WHERE 
				1=1
				" . $q_where
			);

		if ($_GET['excel_down'])
		{
			set_time_limit(3600);
			ini_set('memory_limit', '2047M');
			$pager_params['perPage'] = 999999;
		} else {
			$pager_params['perPage'] = 20;
		}

		$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
				m.*, d.d_name
			FROM
				" . $TB['WEB_ALLOW_IP'] . " m,
				" . $TB['DOMAIN'] . " d
			WHERE
				1=1
				" . $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();
		for ($i=0; $i<sizeof($rows); $i++)
		{
			//
		}	// for()
		$rows = db_rows_fieldtokey($rows);
		$rows_cnt = getarraycount($rows['ip_netmask']);

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

	// 웹메일 접근 IP 관리수
		$admin_web_allow_ip_all_cnt = number_format($pager_params['totalItems']);

	// view
		$row = array();
		$view = array();
		$view = setform_admin_web_allow_ip($row);


	// 도메인
		if ($_GET['isadmin'])
		{
			$mbr_domain_select = NULL;
		} else
		{
			$q = "SELECT * FROM ".$TB['DOMAIN']." WHERE d_is_use='Y' ORDER BY d_name";
			$mbr_domain = db_get_rows($q, true);
			$mbr_domain_select = select_list_value($_GET['sa_d_no'], $mbr_domain['d_name'], $mbr_domain['d_no'], '전체 도메인', 0, 1);
		}	// if()

		if ($_GET['excel_down'])
		{
			$excel_down_name = 'NmailWebAllowIpList.xls';
			header("Content-type: application/vnd.ms-excel; charset=utf-8");
			header("Content-Disposition: attachment; filename=$excel_down_name");
			header("Expires: 0");
			header("Cache-Control: must-revalidate, post-check=0,pre-check=0");
			header("Pragma: public");

			include('sadmin/admin_web_allow_ip_excel.html');
			exit;
		}


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


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