<?php
/**
 * 合集视频编辑
 * $Id: collection_media_edit_input.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("11")) {
	// エラー表示
	$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");
$action_type = ParamUtil::getRequestString("action_type");

$course_mst = new CourseMst();
if($action_type =="edit"){
  $course_mst = CourseMst::getById($id);
  if ($course_mst == 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;
  }
}
$parent_category_list = CourseParentCategory::getList();
$param = array();
$param["delete_flg"] = false;
$sub_category_list = CourseCategoryDat::getList($param,"id");

$parent_category_id = $course_mst->parent_category_id??$parent_category_list[0]->id;
$sub_category_id = $course_mst->sub_category_id??getFirstSubCategoryId($sub_category_list,$parent_category_list);
$front_image = $course_mst->front_image;
$title = $course_mst->title;
$teacher_name = $course_mst->teacher_name;
$teacher_profile = $course_mst->teacher_profile;
$new_sub_category_list = [];
foreach ($sub_category_list as $tmp){
  if($tmp->parent_id == $sub_category_id){
    array_push($new_sub_category_list, $tmp);
  }
}

function getFirstSubCategoryId($sub_category_list,$parent_category_list){
  foreach ($sub_category_list as $tmp){
    if($tmp->parent_id == $parent_category_list[0]->id){
      return $tmp->id;
    }
  }
  return "";
}

// 页面表示
$layout_pages = array();
$layout_pages["left"] = "menu.inc";
$layout_pages["right"] = "collection_media_edit_input.inc";
$layout_pages["menu_clicked"] = "4-1";
require_once(MANAGER_TEMPLATE_DIR_PATH . "/layout/leftmenu_layout.inc");
exit;