<?php
/**
 * 用户管理
 * $Id: user_edit_result.php,v 1.1 2016-9-22 09:58:31 cuixl Exp $
 * @author cuixl
 * @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;
}

// 参数取得
$title = ParamUtil::getRequestString("title");
$live_url = ParamUtil::getRequestString("live_url");
$user_ids = ParamUtil::getRequestString("user_ids");

$user_id_array = explode("_", $user_ids);

foreach($user_id_array as $user_id) {
	if(empty($user_id)) continue;
	//echo $user_id . ".<br/>";
	//该用户是否有记录
	$param = array();
	$param["delete_flg"] = false;
	$param["user_id"] = $user_id;
	$tmp_list = UserClassDat::getList($param, "update_date", "desc", 0, 1);
	if(empty($tmp_list)) {
		$user_class_dat = new UserClassDat();
		$user_class_dat->update_date = date("Y-m-d H:i:s");
		$user_class_dat->title = $title;
		$user_class_dat->user_id = $user_id;
		$user_class_dat->live_url = $live_url;
		$user_class_dat->is_valid = true;
		$user_class_dat->save();
	} else {
		$user_class_dat = $tmp_list[0];
		$user_class_dat->update_date = date("Y-m-d H:i:s");
		$user_class_dat->title = $title;
		$user_class_dat->user_id = $user_id;
		$user_class_dat->live_url = $live_url;
		$user_class_dat->save();
	}
}

header("Location:user_class_list.php");
exit;