<?php
/**
 * 活动列表-数据详情
 * $Id: event_detail_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("14")) {
	// エラー表示
	$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;
}

$id = ParamUtil::getRequestString("id");

$name = ParamUtil::getRequestString("name");
$mobile = ParamUtil::getRequestString("mobile");
$is_circle = ParamUtil::getRequestString("is_circle");
$is_finish = ParamUtil::getRequestString("is_finish");
$circle_id = ParamUtil::getRequestString("circle_id");

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

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

$event_dat = VolunteerEventDat::getById($id);
if ($event_dat == null) {
  // エラー表示
  $message = "对象不存在.";
  $layout_pages = array();
  $layout_pages["left"] = "menu.inc";
  $layout_pages["right"] = "error.inc";
  require_once(MANAGER_TEMPLATE_DIR_PATH . "/layout/leftmenu_layout.inc");
  exit;
}

$event_member_list = [];
$total_count = 0;
$finish_count = 0;
$circle_list = [];
array_push($circle_list, ["title"=>"请选择","id"=>""]);
//总件数
$event_member_count = CompassHandler::getEventMemberListCount($param);
// // 一览取得
if ($event_member_count > 0) {
  $offset = ($page_num - 1) * $page_row;
  $event_member_list = CompassHandler::getEventMemberList($param, $order_key, $sort, $offset, $page_row);
  $page_count = ceil($event_member_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];
  
  $total_count = count($event_member_list);
  foreach ($event_member_list as $tmp){
    if(!empty($tmp["finish_time"])){
      $finish_count += 1;
    }
    if($tmp["circle_id"] != 0){
      array_push($circle_list, ["title"=>$tmp["circle_title"],"id"=>$tmp["circle_id"]]);
      $circle_list = array_unique($circle_list,SORT_REGULAR);
    }
  }
}


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