 <?
/**
 * 用户管理
 * $Id: user_list.php
 * @author taocy
 * @package manager.public_html
 */

// 底层包含
require_once("manager_include.inc");

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

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

//取得参数
$search_flg = ParamUtil::getRequestBoolean("search_flg",false);
$page_num = ParamUtil::getRequestNumber("page_num", 1);
$channel_no = ParamUtil::getRequestString("channel_no", "0");//my、ocean

$status = ParamUtil::getRequestString("status", "ALL");
$mobile = ParamUtil::getRequestNumber("mobile");
$nickname = ParamUtil::getRequestString("nickname");

$order_key = ParamUtil::getRequestString("order_key","id");
$direction = ParamUtil::getRequestString("direction","desc");

$session_name = "user_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;
		$channel_no = $_SESSION[$session_name]["channel_no"];
		$status = $_SESSION[$session_name]["status"];
		$mobile = $_SESSION[$session_name]["mobile"];
		$nickname = $_SESSION[$session_name]["nickname"];
		$order_key = $_SESSION[$session_name]["order_key"];
		$direction = $_SESSION[$session_name]["direction"];
	}
} else {
	if (isset($_SESSION[$session_name])){
		unset($_SESSION[$session_name]);
	}
	// 再設定
	$_SESSION[$session_name]["channel_no"] = $channel_no;
	$_SESSION[$session_name]["status"] = $status;
	$_SESSION[$session_name]["mobile"] = $mobile;
	$_SESSION[$session_name]["nickname"] = $nickname;
	$_SESSION[$session_name]["order_key"] = $order_key;
	$_SESSION[$session_name]["direction"] = $direction;
}

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

$param = array();
$param["delete_flg"] = false;
$param["account_id"] = $_account->id;
$arrow_url = "my_user_list.php";
if (!empty($channel_no)) {
	$param["channel_no"] = $channel_no;
}
$arrow_url += "&channel_no=".$channel_no;

if ($status != "ALL") {
	$param["status"] = $status;
}
$arrow_url += "&status=".$status;

if (!empty($mobile)) {
	$param["mobile"] = $mobile;
}
$arrow_url += "&mobile=".$mobile;

if (!empty($nickname)) {
	$param["nickname"] = $nickname;
}
$arrow_url += "&nickname=".$nickname;

$total_count = 0;
//总页数取得
$total_count = UserHandler::getUserCount($param);

if ($total_count > 0) {
	$page_row = MANAGER_DEFAULT_ROW_COUNT;
	$offset = ($page_num - 1) * $page_row;
	//一览取得
	$user_mst_list = UserHandler::getUserList($param, $order_key, $direction, $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];
}

//渠道列表
$channel_list = ChannelMst::getList(null, "id", "desc");

$channel_map = array();
$channel_map["1000"] = "系统用户";
foreach($channel_list as $channel) {
	$channel_map[$channel->channel_no] = $channel->title;
}

//学员状态
$user_status_list = UserStatus::getList(null, "id", "desc");

// 页面
$_SCRIPT_FILE = array("scripts/validators.js", "scripts/user_list.js");
$layout_pages = array();
$layout_pages["top"] = "menu.inc";
$layout_pages["menu_clicked"] = "li_user";
$layout_pages["middle"] = "my_user_list.inc";
require_once(MANAGER_TEMPLATE_DIR_PATH . "/layout/topmenutopsub_layout.inc");
exit;
?>