<?php
/**
 * 活动审核
 * $Id: event_examine.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("15")) {
	// エラー表示
	$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;
}

$finish_time = ParamUtil::getRequestString("finish_time");
$author = ParamUtil::getRequestString("author");
$start_time = ParamUtil::getRequestString("start_time");

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

// trueの場合、Sessionを再設定
$search_flg = ParamUtil::getRequestBoolean("search_flg", false);
$session_name = "event_examine_criteria";

if ($search_flg) {
  if (isset($_SESSION[$session_name])){
    $param = $_SESSION[$session_name];
  } else {
    $param = array();
  }
  
  if (isset($param["registration_date_MAX"])) {
    $finish_time = $param["registration_date_MAX"];
  }
  if (isset($param["registration_date_MIN"])) {
    $start_time = $param["registration_date_MIN"];
  }
  if (isset($param["author"])) {
    $author = $param["author"];
  }
} else {
  // 検索条件を作成してsessionに設定
  $param = array();
  if (!empty($finish_time)) {
    $param["registration_date_MAX"] = $finish_time;
  }
  if (!empty($start_time)) {
    $param["registration_date_MIN"] = $start_time;
  }
  if (!empty($author)) {
    $param["author"] = $author;
  }
  $_SESSION[$session_name] = $param;
}

// 一览取得
$param["delete_flg"] = false;
$param["status"] = "NEW";
if($_account->user_id != 0){
  //TODO
}
$volunteer_event_list = [];
$volunteer_event_count = VolunteerEventDat::getListCount($param);
// 一览取得
if ($volunteer_event_count > 0) {
  $offset = ($page_num - 1) * $page_row;
  $volunteer_event_list = VolunteerEventDat::getList($param, $order_key, $sort, $offset, $page_row);
  $page_count = ceil($volunteer_event_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];
}
foreach ($volunteer_event_list as $tmp){
  if(!empty($tmp->circle_id)){
    $tmp->author = CircleDat::getById($tmp->circle_id)->title;
  }
}


// JavaScriptページ
$_SCRIPT_FILE = array("scripts/validators.js");
// ページ
$layout_pages = array();
$layout_pages["left"] = "menu.inc";
$layout_pages["right"] = "event_examine.inc";
$layout_pages["menu_clicked"] = "3-3";
require_once(MANAGER_TEMPLATE_DIR_PATH . "/layout/leftmenu_layout.inc");
exit;