<?php
/**
 * 商品分类管理
 * $Id: product_category_edit_input.php,v 1.1 2015/10/08 11:18:46 wanggb Exp $
 * @author wanggb
 * @package manager.public_html
 */

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

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

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

// 参数取得
$action_type = ParamUtil::getRequestString("action_type");
$id = ParamUtil::getRequestString("id");
$category_id = ParamUtil::getRequestString("category_id");
$title = ParamUtil::getRequestString("title");
$front_image = ParamUtil::getRequestString("front_image");
$content = ParamUtil::getRequestString("content");
$is_valid = ParamUtil::getRequestBoolean("is_valid");
$is_free = ParamUtil::getRequestBoolean("is_free");
$is_top = ParamUtil::getRequestBoolean("is_top");

//获取上传的媒体文件
$upload_video_file = FileUploadUtil::getScalarFile($_FILES["upload_video_file"]);
$upload_front_file = FileUploadUtil::getScalarFile($_FILES["upload_front_file"]);

$error_flg = false;

//编辑
$video_path = VIDEO_PATH;
if(!is_dir($video_path)){
	mkdir($video_path, 0777, false);
}

$article_dat = null;
//编辑
if($action_type == "edit") {
	$article_dat = ArticleDat::getById($id);
	$article_dat->category_id = $category_id;
	$article_dat->title = $title;
	$article_dat->content = $content;
	$article_dat->is_valid = $is_valid;
	$article_dat->is_top = $is_top;
	$article_dat->is_free = $is_free;	
	$article_dat->save();
}

//添加
if($action_type == "new") {
	$article_dat = new ArticleDat();
	$article_dat->category_id = $category_id;
	$article_dat->title = $title;
	$article_dat->content = $content;
	$article_dat->is_valid = $is_valid;
	$article_dat->is_top = $is_top;	
	$article_dat->is_free = $is_free;	
	$article_dat->save();
	$article_dat->update_date = $article_dat->registration_date;
	$article_dat->save();

	//提交给百度
	
}

// 循环处理上传图片
if(!empty($upload_video_file) && !empty($upload_video_file->name)) {
	//删除目录下所有文件
	if ($upload_video_file->size > 0) {		
		$file_name = "video-" . $article_dat->id . "-" . $upload_video_file->name;
		$dest_file =  $video_path . "/" . $file_name;
		move_uploaded_file($upload_video_file->tmp_name, $dest_file);
		chmod($dest_file, 0777);
		
		//更新文件
		$article_dat->video_file = $file_name;
		$article_dat->front_image = null;
		$article_dat->save();
		
	}
}

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