<?php
/**
 * 用户申请证书管理
 * $Id: certificate_apply_list.php,v 1.1 2015/10/08 11:18:46 wanggb Exp $
 * @author lixq
 * @package manager.public_html
 */
// 底层包含
require_once("manager_include.inc");

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

// 权限检查
if (!checkAuthority("16")) {
	// エラー表示
	$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;
}

$user_name = ParamUtil::getRequestString("user_name");
$certificate_title = ParamUtil::getRequestString("certificate_title");
$name = ParamUtil::getRequestString("name");
$status = ParamUtil::getRequestString("status");

$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 = "./user_certificate_list.php";

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


$user_certificate_list = [];
$param["delete_flg"] = false;
//总件数
$user_certificate_count = CompassHandler::getUserCertificateListCount($param);
// 获取相应页面的数据
if ($user_certificate_count > 0) {
  // 一览取得
  $offset = ($page_num - 1) * $page_row;
  $user_certificate_list = CompassHandler::getUserCertificateList($param, $order_key, $sort, $offset, $page_row);
  $page_count = ceil($user_certificate_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"] = "certificate_apply_list.inc";
$layout_pages["menu_clicked"] = "5-5";
require_once(MANAGER_TEMPLATE_DIR_PATH . "/layout/leftmenu_layout.inc");
exit;