<?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")) {
	// エラー表示
	$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);
$search_flg = ParamUtil::getRequestBoolean("search_flg",false);
$category_id = ParamUtil::getRequestString("category_id", 0);
$title = ParamUtil::getRequestString("title", "");

$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;
		$category_id = $_SESSION[$session_name]["category_id"];
		$title = $_SESSION[$session_name]["title"];
	}
} else {
	if (isset($_SESSION[$session_name])){
		unset($_SESSION[$session_name]);
	}
	// 再設定
	$_SESSION[$session_name]["category_id"] = $category_id;
	$_SESSION[$session_name]["title"] = $title;
}

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

$param = array();
$param["delete_flg"] = false;
$param["video_file_NOT"] = NULL;
if(!empty($category_id)){
	$param["category_id"] = $category_id;
}
if(!empty($title)){
	$param["title_ALT"] = "%" . $title . "%";
}
$total_count = ArticleDat::getListCount($param);

$dream_dat_list = array();
if ($total_count > 0) {
	$page_row = 20;
	$offset = ($page_num - 1) * $page_row;
	
	$article_dat_list = ArticleDat::getList($param, "id", "desc", $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];	
}

//分类抽取
$category_array = array();
$param = array();
$param["delete_flg"] = false;
$category_list = ArticleCategoryMst::getList($param, "display_order", "desc");
foreach($category_list as $category_mst) {
	$category_array[$category_mst->category_id] = $category_mst->title;
}

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