<?
require_once('include/global.php');
require_once("include/admin_mailing_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'];

		if ($G['DINFO']['d_svc_mailing_list'] === 'N') {
			msg("메일링 리스트를 사용할 수 없습니다.\\n\\n서버관리자에게 문의하여 주십시오.");
		}
	} 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='M' ";
		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']."' ";

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

	// sort
		$CFG['ADMIN_MEMBER_FIELD'] = array(
				'd.d_name' => '도메인',
				'm.m_name' => '메일링 이름',
				'm.m_id' => '메일링 주소',
				'm.m_email' => '메일링 관리주소',
				'm.m_etc1' => '메일링 공개여부',
				'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'];

		// [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['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_id_view'] = get_mailto_url($rows[$i]['m_id'].'@'.$rows[$i]['d_name'], $rows[$i]['m_id'], false, $rows[$i]['m_name']);
			$rows[$i]['m_email'] = get_mailto_url($rows[$i]['m_email']);
			$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_mailing_all_cnt = number_format($pager_params['totalItems']);

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

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


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