<?
require_once('include/global.php');
require_once('include/admin_lib.php');
require_once('include/pager.php');
require_once('include/file.php');


// set
	if ($_GET['isadmin'])
	{
		// [2013-07-05] 관리자메뉴에서는 비허용
		//auth_limit('admin');
		auth_limit('serveradmin');
		$CFG[TITLE] = '<b>관리자메뉴</b> >> <b>회원관리</b> >> <b>메일계정 관리 로그</b>';
		$_GET['d_no'] = $G['DINFO']['d_no'];
	} else
	{
		auth_limit('serveradmin');
		$CFG[TITLE] = '<b>메일서버관리</b> >> <b>전체회원관리</b> >> <b>메일계정 관리 로그</b>';
	}	// if()




// set
$CFG['l_status'] = array(
					'ADD' => '추가',
					'MODP' => '비밀번호 변경',
					'DEL' => '삭제',
					);

// data

	// search
		$q_where = "";

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

		if ($_GET['s_word'])
		{
			set_q_search($_GET['s_word']);
			$q_where .= " AND (
							l_time LIKE '%" . $_GET['s_word'] . "%'
							OR l_ip LIKE '%" . $_GET['s_word'] . "%'
							OR m_id LIKE '%" . $_GET['s_word'] . "%' ";
			$q_where .= " ) ";

			$v_s_word = htmlspecialchars_fix(stripslashes($_GET['s_word']));
		}	// if()

		// 검색조건이 없을 때 기본적으로 오늘 로그만 보여주도록 함.
		if ($_GET['sdp'] != 'A' && !$_GET['sd1'] && !$_GET['sd2'])
		{
			$_GET['sdp'] = '0';
			$_GET['sd1'] = date('Y-m-d');
			$_GET['sd2'] = $_GET['sd1'];
		}	// if()

		if ($_GET['sd1'] && strtotime($_GET['sd1']))
		{
			$_ex = explode('-', $_GET['sd1']);
			$_GET['sd1'] = sprintf('%04d', $_ex[0]).'-'.sprintf('%02d', $_ex[1]).'-'.sprintf('%02d', $_ex[2]);
			if ($_GET['sd2'] && strtotime($_GET['sd2']))
			{
				$_ex = explode('-', $_GET['sd2']);
				$_GET['sd2'] = sprintf('%04d', $_ex[0]).'-'.sprintf('%02d', $_ex[1]).'-'.sprintf('%02d', $_ex[2]);
				$q_where .= " AND l_date >= '".$_GET['sd1']."' AND l_date <= '".$_GET['sd2']."' ";
			}	// if()
		}	// if()

		if ($_GET['l_status'] != '')
			$q_where .= " AND l_status='".$_GET['l_status']."' ";

	// sort
		$CFG['ADMIN_MEMBER_FIELD'] = array(
				'l_date' => '날짜',
				'd_no' => '도메인',
				'm_id' => '아이디',
				'l_admin_id' => '관리자',
				'l_ip' => '관리 IP',
				'l_status' => '결과',
				);
		if ($_GET['isadmin'])
		{
			unset($CFG['ADMIN_MEMBER_FIELD']['d_no']);
		}	// if()


		$order_set = get_order(array_keys($CFG['ADMIN_MEMBER_FIELD']), 'l_date DESC, l_time ', $_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['LOG_MEMBER'] . "
			WHERE
				1=1
				" . $q_where
			);
		$pager_params['perPage'] = 100;

		$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

		// l_date 로 정렬시 날짜,시간 필드를 동시에 정렬하도록 함.
		if ($order_set['query'] == 'l_date ASC')
		{
			$order_set['query'] = 'l_date ASC, l_time ASC';
		} else if ($order_set['query'] == 'l_date DESC')
		{
			$order_set['query'] = 'l_date DESC, l_time DESC';
		}	// if()

		$DEBUG['db_select']['start'] = getmicrotime();
		$sql = "
			SELECT
				*
			FROM
				" . $TB['LOG_MEMBER'] . "
			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'];


	// 도메인
		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['d_no'], $mbr_domain['d_name'], $mbr_domain['d_no'], '전체 도메인', 0, 1);
		}	// if()


	// process data
		$DEBUG['db_fetch_all']['start'] = getmicrotime();
		for ($i=0; $i<sizeof($rows); $i++)
		{
			$rows[$i]['l_date'] = $rows[$i]['l_date'].' '.$rows[$i]['l_time'];

			$q = "SELECT d_name FROM ".$TB['DOMAIN']." WHERE d_no='".$rows[$i]['d_no']."'";
			$rows[$i]['d_name'] = db_get_one($q);
			$rows[$i]['l_status_view'] = $CFG['l_status'][$rows[$i]['l_status']];
		}	// for()
		$rows = db_rows_fieldtokey($rows);
		$rows_cnt = getarraycount($rows['l_date']);

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

	// 메일 로그 뷰어수
		$admin_mailing_all_cnt = number_format($pager_params['totalItems']);

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


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