<?
require_once('include/global.php');
require_once("include/admin_alias_lib.php");
require_once("include/board_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 m.d_no=d.d_no AND m.m_usertype='A' ";
		if ($_GET['s_word'])
		{
			set_q_search($_GET['s_word']);
			$q_where .= " AND ( d.d_name LIKE '%" . $_GET['s_word'] . "%' OR m.m_name LIKE '%" . $_GET['s_word'] . "%' OR m.m_id LIKE '%" . $_GET['s_word'] . "%' OR m.m_email LIKE '%" . $_GET['s_word'] . "%' OR m.m_memo LIKE '%" . $_GET['s_word'] . "%' ) ";
			$v_s_word = htmlspecialchars_fix(stripslashes($_GET['s_word']));
		}	// if()

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

	// sort
		$CFG['ADMIN_MEMBER_FIELD'] = array(
				'd.d_name' => '도메인',
				'm.m_id' => '앨리어스 주소',
				'm.m_cfg_from_addr' => '보낸사람 주소로 사용여부',
				'm.m_name' => '메일 수신 계정',
				'm.m_memo' => '메모',
				'm.m_regdate' => '등록일자'
				);
		$order_set = get_order(array_keys($CFG['ADMIN_MEMBER_FIELD']), 'm.m_no', $_GET['s_key'], $_GET['s_key2']);
		$order_img = get_order_img(array_keys($CFG['ADMIN_MEMBER_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['MEMBER'] . " m,
				" . $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
				m.*, d.d_name
			FROM
				" . $TB['MEMBER'] . " 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++)
		{
			$rows[$i]['m_name_view'] = get_mailto_url($rows[$i]['m_name'].'@'.$rows[$i]['d_name'], $rows[$i]['m_name'], false);
			$rows[$i]['m_id_view'] = get_mailto_url($rows[$i]['m_id'].'@'.$rows[$i]['d_name'], $rows[$i]['m_id'], false);
			$rows[$i]['m_email'] = get_mailto_url($rows[$i]['m_email']);
			if ($rows[$i]['m_cfg_from_addr'] == '')
				$rows[$i]['m_cfg_from_addr'] = 'N';
			//$rows[$i]['m_regdate'] = substr($rows[$i]['m_regdate'], 0, 10);
			$rows[$i]['ml_cnt'] = db_get_one("SELECT COUNT(*) FROM ".$TB['MAILING_LIST']." WHERE m_no='". $rows[$i]['m_no'] . "'");
		}	// for()
		$rows = db_rows_fieldtokey($rows);
		$rows_cnt = getarraycount($rows['m_name']);

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

	// 앨리어스 주소 관리수
		$admin_alias_all_cnt = number_format($pager_params['totalItems']);

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

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


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