<?php
/**
 * 视频一览
 * $Id: media_list.php,v 1.1 2020/01/03 11:18:46  Exp $
 * @author lixq
 * @package manager.public_html
 */
// 底层包含
require_once("manager_include.inc");

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

// 权限检查
if (!checkAuthority("11")) {
	// エラー表示
	$layout_pages = array();
	$layout_pages["left"] = "menu.inc";
	$layout_pages["right"] = "error.inc";
	$message = "权限不足，请联系系统管理员。";
	require_once(MANAGER_TEMPLATE_DIR_PATH . "/layout/leftmenu_layout.inc");
	exit;
}

$title = ParamUtil::getRequestString("title");
$media_type = ParamUtil::getRequestString("media_type");//种类 0:所有 1:单个 2:合集
$media_kind = ParamUtil::getRequestString("media_kind");//类型 0:所有 1:志愿免费 2:公益收费

$order_key = ParamUtil::getRequestString("order_key", "id");
$sort = ParamUtil::getRequestString("sort", "DESC");
$page_num = ParamUtil::getRequestNumber("page_num", 1);
$page_row = MANAGER_DEFAULT_ROW_COUNT;
$paging_url_link = "./media_list.php";

// trueの場合、Sessionを再設定
$search_flg = ParamUtil::getRequestBoolean("search_flg", false);
$session_name = "media_criteria";
if ($search_flg) {
  if (isset($_SESSION[$session_name])){
    $param = $_SESSION[$session_name];
  } else {
    $param = array();
  }
  
  if (isset($param["title"])) {
    $title = $param["title"];
  }
  if (isset($param["media_type"])) {
    $media_type = $param["media_type"];
  }
  if (isset($param["media_kind"])) {
    $media_kind = $param["media_kind"];
  }
  
  if (isset($param["page_num"])) {
    $page_num = $param["page_num"];
  }
} else {
  // 検索条件を作成してsessionに設定
  $param = array();
  if (!empty($media_type)) {
    $param["media_type"] = $media_type;
  }
  if (!empty($media_kind)) {
    $param["media_kind"] = $media_kind;
  }
  if (!empty($title)) {
    $param["title"] = $title;
  }
  
  if (!empty($page_num)) {
    $param["page_num"] = $page_num;
  }
  $_SESSION[$session_name] = $param;
}

$course_list = [];

//总件数
$course_count = CompassHandler::getCourseMediaListCount($param);
// // 一览取得
if ($course_count > 0) {
  $offset = ($page_num - 1) * $page_row;
  $course_list = CompassHandler::getCourseMediaList($param, $order_key, $sort, $offset, $page_row);
  $page_count = ceil($course_count / $page_row);
  $show_page_num = MANAGER_PAGING_SHOW_PAGE_COUNT;
  $page_range = PagingHandler::getPageRange($page_num, $page_count, $show_page_num);
  $page_first = $page_range[0];
  $page_end = $page_range[1];
}

// ページ
$layout_pages = array();
$layout_pages["left"] = "menu.inc";
$layout_pages["right"] = "media_list.inc";
$layout_pages["menu_clicked"] = "4-2";
require_once(MANAGER_TEMPLATE_DIR_PATH . "/layout/leftmenu_layout.inc");
exit;