<?php
/**
 * This file is to upload the videos
 *
 * This file is having VideoPreview class to upload the videos
 *
 * PHP version 5.0
 *
 * @category	###Anova###
 * @package		AnsPreviewVideo
 * @author 		shankar_76ag08
 * @copyright 	Copyright (c) 2009 {@link http://www.agriya.com Agriya Infoway}
 * @license		http://www.agriya.com Agriya Infoway Licence
 * @since 		2008-11-13
 **/
require_once('../common/configs/config.inc.php');

$CFG['lang']['include_files'][] = 'languages/%s/'.$CFG['admin']['index']['anova_module'].'/ansViewVideo.php';
$CFG['site']['is_module_page'] = $CFG['admin']['index']['anova_module'];
//compulsory
$CFG['mods']['is_include_only']['non_html_header_files'] = true;
$CFG['is']['ajax_page'] = true;
$CFG['auth']['is_authenticate'] = 'members';
/**
 * To include application top file
*/
require_once($CFG['site']['project_path'].'common/application_top.inc.php');

/**
 * VideoPreview
 *
 * @package
 * @author selvaraj_35ag05
 * @copyright Copyright (c) 2009
 * @version $Id: VideoPreview.php 892 2007-05-26 13:23:06Z selvaraj_35ag05 $
 * @access public
 **/
class VideoPreview extends FormHandler
	{
		public $video_details;

		public function chkIsValidPreviewVideo()
			{
				$param_arr = explode('_', $this->fields_arr['pg']);

				$this->fields_arr['video_for'] = $param_arr[0];
				$this->fields_arr['vid'] = $param_arr[1];

				$file_name = $this->CFG['admin']['video']['red5_flv_path'].$this->fields_arr['vid'].'.flv';

				if(is_file($file_name))
					{
						$temp_dir = $this->CFG['admin']['ans_videos']['temp_folder'];
						$this->chkAndCreateFolder($temp_dir);
						$temp_file = $temp_dir.$this->fields_arr['vid'].'.flv';
						if(file_exists($temp_file))
							@unlink($temp_file);
						copy($file_name, $temp_file);

						$result = exec("\"".$this->CFG['admin']['video']['flvtool2_path']."\" -UP ". $temp_file);

						return true;
					}
				return false;
			}

		public function resetFieldsArray()
			{
				$this->setFormField('pg', '');
			}
	}
//<<<<<-------------- Class VideoPreview begins ---------------//
//-------------------- Code begins -------------->>>>>//
$VideoPreview = new VideoPreview();

if(!isAjax())
	Redirect2URL($CFG['site']['url']);

$VideoPreview->setPageBlockNames(array('video_display'));

//default form fields and values...
$VideoPreview->resetFieldsArray();

$VideoPreview->setAllPageBlocksHide();
$VideoPreview->sanitizeFormInputs($_REQUEST);

if($VideoPreview->isFormGETed($_REQUEST, 'pg'))
	{
		if(!$VideoPreview->chkIsValidPreviewVideo())
			{
				$VideoPreview->setAllPageBlocksHide();
				$VideoPreview->setCommonErrorMsg($LANG['error_video']);
				$VideoPreview->setPageBlockShow('block_msg_form_error');
			}
		else
			{
				$VideoPreview->setPageBlockShow('video_display');
			}
	}
//<<<<<-------------------- Code ends----------------------//
if ($VideoPreview->isShowPageBlock('video_display'))
	{
		$VideoPreview->videos_folder = $CFG['admin']['ans_videos']['folder'];
		$VideoPreview->flv_player_url = $CFG['site']['url'].'files/flash/flv_player/flvplayer_elite.swf';
		$VideoPreview->arguments_play = 'pg=previewvideo_'.$VideoPreview->getFormField('vid');
		$VideoPreview->configXmlcode_url = $CFG['site']['url'].'elite_videoConfigXmlCode.php?';
	}
//-------------------- Page block templates begins -------------------->>>>>//
//include the header file
$VideoPreview->includeAjaxHeader();
//include the content of the page
setTemplateFolder('members/', $CFG['admin']['index']['anova_module']);
$smartyObj->display('ansPreviewVideo.tpl');
//<<<<<-------------------- Page block templates ends -------------------//
$VideoPreview->includeAjaxFooter();
?>