<?
require_once('include/global.php');
require_once('include/diary_lib.php');
require_once('include/pager.php');
require_once('conf.inc.php');


// set
	$CFG['TITLE'] = '<b>일정관리</b> >> <b>전체목록</b>';

	// [2006-07-19] 공용일정 구분
	set_diary_no_isshare('', $_GET['share']);

// data

	// search
		$q_where = '';
		if ($_GET['s_word'])
		{
			set_q_search($_GET['s_word']);
			$q_where = " AND ( di_subject LIKE '%" . $_GET['s_word'] . "%' OR di_content LIKE '%" . $_GET['s_word'] . "%' ) ";
			$v_s_word = htmlspecialchars_fix(stripslashes($_GET['s_word']));
		}	// if()

		if ($_GET['s_di_kind'])
		{
			$q_where .= " AND di.di_kind = '" . $_GET['s_di_kind'] . "' ";			
		}	// if()

	// sort
		$CFG['DIARY_LIST_FIELD'] = array(
				'di.di_kind' => '분류',
				'di.di_subject' => '이름',
				'di.di_content' => '내용',
				'di.di_startdate' => '시작시간',
				'di.di_enddate' => '종료시간',
				'di.di_repeat' => '되풀이'
				);
		$order_set = get_order(array_keys($CFG['DIARY_LIST_FIELD']), 'di.di_startdate DESC, di.di_starttime DESC, di.di_enddate', $_GET['s_key'], $_GET['s_key2']);
		$order_img = get_order_img(array_keys($CFG['DIARY_LIST_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(di.di_no) 
			FROM 
				" . $TB['DIARY'] . " di 
			WHERE 
				di.".get_diary_group_where()."
				" . $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
				*
			FROM
				" . $TB['DIARY'] . " di 
			WHERE
				di.".get_diary_group_where()."
				" . $q_where . "
			ORDER BY
				" . $order_set['query'] . "
			";
		$rows = db_get_rows($sql, $pager_limit['from'], $pager_limit['count'], true);
		$rows_cnt = getarraycount($rows['di_subject']);
		$DEBUG['db_select']['exec'] += getmicrotime() - $DEBUG['db_select']['start'];

	// data
		for ($i=0; $i<$rows_cnt; $i++)
		{
			$rows['di_subject'][$i] = e($rows['di_subject'][$i]);
			$rows['di_content'][$i] = e(han_substr($rows['di_content'][$i], 60));
			$rows['di_starttime'][$i] = ' '.substr($rows['di_starttime'][$i], 0, 5);
			$rows['di_endtime'][$i] = ' '.substr($rows['di_endtime'][$i], 0, 5);
		}	// for()

	// 일정수
		$diary_all_cnt = number_format($pager_params['totalItems']);

	// 일정 분류
		$select_diary_group = select_list_value($_GET['s_di_kind'], $G_SYS['DI_KIND_VAL'], $G_SYS['DI_KIND_KEY'], NULL, 0, 1);

		$back_url = urlencode($_SERVER[REQUEST_URI]);


// skin view
	nskinset('webmail', 'diary_list.html');
	define('NMAIL_SKIN_MAIN_TOP_FILE', nskindir('webmail').'/diary_top.inc.html');		// 상단메뉴
	include($NSKIN['view_layout']);


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