<?php
/**
 * 消息管理
 * $Id: message_list.php,v 1.1 2016-9-22 09:58:31 cuixl Exp $
 * @author cuixl
 * @package manager.public_html
 */
// 底层包含
require_once("manager_include.inc");

// 登录检查
require_once("check_login.inc");

// 权限检查
if (!checkAuthority("ADMIN,MANAGER,STAFF")) {
	// エラー表示
	$layout_pages = array();
	$layout_pages["footer"] = "footer.inc";
	$layout_pages["top"] = "menu.inc";
	$layout_pages["middle"] = "error.inc";
	$message = "权限不足，请联系系统管理员。";
	require_once(MANAGER_TEMPLATE_DIR_PATH . "/layout/topmenutopsub_layout.inc");
	exit;
}

// 一览取得
$page_num = ParamUtil::getRequestNumber("page_num", 1);
$category_id = ParamUtil::getRequestNumber("category_id", 0);
$search_flg = ParamUtil::getRequestBoolean("search_flg",false);

//系列列表
$param = array();
$param["delete_flg"] = false;
$category_list = ArticleCategoryMst::getList($param, "display_order", "desc");
if($category_id == 0 && !empty($category_list)) {
	$category_id = $category_list[0]->id;
}

$session_name = "article_dat_list";
if (!$search_flg) {
	if (isset($_SESSION[$session_name])){
		// ページ番、ソート順など保存
		if (isset($_SESSION[$session_name]["page_num"]) && !isset($_REQUEST["page_num"])) {
			$page_num = $_SESSION[$session_name]["page_num"];
		}
		$_SESSION[$session_name]["page_num"] = $page_num;
		$_SESSION[$session_name]["category_id"] = $category_id;
	}
} else {
	if (isset($_SESSION[$session_name])){
		unset($_SESSION[$session_name]);
	}
	// 再設定
	$page_num = $_SESSION[$session_name]["page_num"];
	$category_id = $_SESSION[$session_name]["category_id"];
}

//当前页取得
$paging_url_link = "article_dat_list.php";

$param = array();
$param["delete_flg"] = false;
if($category_id != 0) {
	$param["category_id"] = $category_id;
}
$total_count = ArticleDat::getListCount($param);

$dream_dat_list = array();
if ($total_count > 0) {
	$page_row = 50;
	$offset = ($page_num - 1) * $page_row;
	
	$article_dat_list = ArticleDat::getList($param, "display_order", "asc", $offset, $page_row);
	
	$page_count = ceil($total_count / $page_row);
	$show_page_num = 5;
	$page_range = PagingHandler::getPageRange($page_num, $page_count, $show_page_num);
	$page_first = $page_range[0];
	$page_end = $page_range[1];	
}

// ページ
$_SCRIPT_FILE = array("scripts/validators.js", "scripts/article_dat.js");
$layout_pages = array();
$layout_pages["top"] = "menu.inc";
$layout_pages["menu_clicked"] = "li_data";
$layout_pages["middle"] = "article_dat_list.inc";
require_once(MANAGER_TEMPLATE_DIR_PATH . "/layout/topmenutopsub_layout.inc");
exit;