<?php
session_start();

include('includes/ajax_check_login.php');

require_once('includes/common.php');

if( !isset($_POST['video_id']) 
|| !isset($_POST['video_no']) 
|| !isset($_POST['subject']) 
|| !isset($_POST['order']) 
|| ( $static_uint_video_id = (int)$_REQUEST['video_id'] ) <= 0 
|| ( $static_str_video_no = process_quotes(strip_tags($_POST['video_no'])) ) == '' 
|| ( $static_uint_order = (int)$_POST['order'] ) < 0 
|| $static_uint_order > 255 )
	exit(json_encode(array('ErrCode'=>-1, 'ErrMessage'=>'輸入資料不足', 'RedirectURL'=>'')));
else
	$static_str_subject = trim(strip_tags($_POST['subject']));

require_once('includes/author.php');
$obj_class_author = new class_author();

if( !( $arr_news_video = $obj_class_author->get_news_video_by_video_id($static_uint_video_id) ) )
{
	$_SESSION['init_info'] = '指定的影片不存在！';
	
	exit(json_encode(array('ErrCode'=>-1, 'ErrMessage'=>'', 'RedirectURL'=>'manage_news.php')));
}
else if( !$obj_class_author->get_news_by_news_id($arr_news_video[0]['NewsId']) )
	exit(json_encode(array('ErrCode'=>0, 'ErrMessage'=>'所選擇的新聞不存在！', 'RedirectURL'=>'')));
else if( ( $arr_news_video = $obj_class_author->get_news_video_by_news_id_n_video_no($arr_news_video[0]['NewsId'], $static_str_video_no) ) && $arr_news_video[0]['VideoId'] != $static_uint_video_id )
	exit(json_encode(array('ErrCode'=>0, 'ErrMessage'=>'指定的影片已存在！', 'RedirectURL'=>'')));
else if( !$obj_class_author->update_news_video($static_uint_video_id, $static_str_subject, $static_str_video_no, $static_uint_order) )
	exit(json_encode(array('ErrCode'=>0, 'ErrMessage'=>'新聞影片編輯失敗！', 'RedirectURL'=>'')));
else
	exit(json_encode(array('ErrCode'=>1, 'ErrMessage'=>'新聞影片編輯成功', 'RedirectURL'=>'')));
?>