<?php
/**
 * 志愿者活动编辑
 * $Id: event_edit_input.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::getRequestNumber("id");

$volunteer_event_dat = VolunteerEventDat::getById($id);
if ($volunteer_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;
}

$checkedScope = [];
if(!empty($volunteer_event_dat->province)){
  array_push($checkedScope, "school");
}
if($volunteer_event_dat->include_social_user){
  array_push($checkedScope, "social");
}


$province_list = [["lable"=>"","value"=>""]];
$city_list = [];
$district_list = [];
if($_account->role == 10 || $_account->role == 99){
  $param = array();
  $param["delete_flg"] = false;
  $school_list = SchoolMst::getList($param);
  foreach ($school_list as $tmp){
    if(!empty($tmp->province)){
      array_push($province_list, ["lable"=>$tmp->province,"value"=>$tmp->province]);
    }
    if(!empty($tmp->city)){
      array_push($city_list,["lable"=>$tmp->province,"value"=>$tmp->city]);
    }
    if(!empty($tmp->district)){
      array_push($district_list,["lable"=>$tmp->city,"value"=>$tmp->district]);
    }
  }
  $province_list = array_unique($province_list,SORT_REGULAR);
  $city_list = array_unique($city_list,SORT_REGULAR);
  $district_list = array_unique($district_list,SORT_REGULAR);
}

$new_city_list = [];
$new_district_list = [];
if(!empty($volunteer_event_dat->province)){
  array_push($new_city_list, ["lable"=>"", "value"=>""]);
  foreach ($city_list as $tmp){
    if ($volunteer_event_dat->province == $tmp["lable"]){
      array_push($new_city_list, ["lable"=>$tmp["lable"], "value"=>$tmp["value"]]);
    }
  }
  array_push($new_district_list, ["lable"=>"", "value"=>""]);
  foreach ($district_list as $tmp){
    if ($volunteer_event_dat->city == $tmp["lable"]){
      array_push($new_district_list, ["lable"=>$tmp["lable"], "value"=>$tmp["value"]]);
    }
  }
}



$scope_list = [];
if($_account->user_id != 0){
  array_push($scope_list, ["id"=>"school","title"=>"区域内学校"]);
  array_push($scope_list, ["id"=>"social","title"=>"社会人士"]);
}else if($_account->school_id != 0){
  array_push($scope_list, ["id"=>"school","title"=>"校内"]);
  array_push($scope_list, ["id"=>"social","title"=>"社会人士"]);
}else if($_account->government_id != 0){
  array_push($scope_list, ["id"=>"school","title"=>"辖区区域内学校"]);
  array_push($scope_list, ["id"=>"social","title"=>"社会人士"]);
}else {
  array_push($scope_list, ["id"=>"school","title"=>"指定区域内学校"]);
  array_push($scope_list, ["id"=>"social","title"=>"社会人士"]);
}
// JavaScriptページ
$_SCRIPT_FILE = array("scripts/validators.js");
// ページ
$layout_pages = array();
$layout_pages["left"] = "menu.inc";
$layout_pages["right"] = "event_edit_input.inc";
$layout_pages["menu_clicked"] = "3-1";
require_once(MANAGER_TEMPLATE_DIR_PATH . "/layout/leftmenu_layout.inc");
exit;