<?php
session_start();

if( isset($_SESSION['init_info']) )
{
	if( ( $str_temp = trim($_SESSION['init_info']) ) != '' )
		$str_init_info = $str_temp;

	unset($_SESSION['init_info']);
}

include('includes/check_login.php');

if( !isset($_REQUEST['video_id']) || ( $static_uint_video_id = (int)$_REQUEST['video_id'] ) < 0 )
{
	$_SESSION['init_info'] = '輸入資料不足！';
	exit('<script language="javascript">history.back();</script>');
}

require_once('includes/common.php');

require_once('includes/admin.php');
$obj_class_admin = new class_admin();

if( !( $arr_news_video = $obj_class_admin->get_news_video_by_video_id($static_uint_video_id) ) )
{
	$_SESSION['init_info'] = '指定的影片不存在！';
	exit('<script language="javascript">history.back();</script>');
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="utf-8" lang="utf-8">
<head>
	<meta http-equiv="content-type" content="text/html; charset=utf-8" />
	<meta http-equiv="content-language" content="zh-tw" />
	<meta name="robots" content="none" />
	<link rel="stylesheet" type="text/css" href="admin.css" />
	<title>編輯新聞影片</title>
	<script type="text/javascript" src="scripts/jquery.js"></script>
	<script type="text/javascript">
<!--
var global_bool_processing = false;

function do_edit_news_video()
{
	if( global_bool_processing )
		return false;

	if( document.edit_news_video.video_no.value == '' )
	{
		alert('請輸入影片youtube編號');
		return false;
	}

	if( document.edit_news_video.order.value == '' )
	{
		alert('請輸入優先順序');
		return false;
	}

	if( document.edit_news_video.order.value < 0 || document.edit_news_video.order.value > 255 )
	{
		alert('優先順序必須在0至255之間');
		return false;
	}

	var obj_form_data = new FormData(document.edit_news_video);

	global_bool_processing = true;

	$.ajax(
	{
		url: 'ajax_do_edit_news_video.php',
		type: 'POST',
		data: obj_form_data,
		cache: false,
		processData: false,
		contentType: false,
		dataType: 'json',
		success: function(jdata)
		{
			if( jdata['ErrMessage'] != '' )
				alert(jdata['ErrMessage']);
			else if( jdata['ErrCode'] != '1' )
				alert('Error:' + jdata['ErrCode']);

			if( jdata['RedirectURL'] )
				location.replace(jdata['RedirectURL']);
			else if( jdata['ErrCode'] == '1' )
				history.back();

			global_bool_processing = false;
		}
	});

	return false;
}
//-->
	</script>
</head>

<body<?=( isset($str_init_info) ? ' onLoad="javascript:alert(\'' . $str_init_info . '\');"' : '' )?>>
<? include('_title.php'); ?>
<? include('_menu.php'); ?>
<div id="content">
<h2>編輯新聞影片?></h2>
<form name="edit_news_video">
<fieldset class="data">
<legend>影片內容</legend>
<input type="hidden" name="video_id" value="<?=$arr_news_video[0]['VideoId']?>" />
<div class="field"><span class="subject">影片網址</span>https://www.youtube.com/watch?v=<input type="text" class="video_no" name="video_no" value="<?=$arr_news_video[0]['VideoNo']?>" maxlength="11" /></div>
<div class="field"><span class="subject">影片標題</span><input class="content" type="text" name="subject" value="<?=$arr_news_video[0]['Subject']?>" maxlength="255" /></div>
<div class="field"><span class="subject">優先順序</span><input class="content" type="text" name="order" value="<?=$arr_news_video[0]['Order']?>" maxlength="3" /></div>
</fieldset>
<div class="buttons"><input class="previous" type="button" value="回上一頁" onclick="history.back();" /><input class="submit" id="button_submit" type="button" value="確定編輯" onclick="do_edit_news_video();" /></div>
</form>
</div>
<? include('_footer.php'); ?>
</body>

</html>