<?php
/**
 * This file is to upload the videos
 *
 * This file is having VideoUpload class to upload the videos
 *
 * PHP version 5.0
 *
 * @category	rayzz
 * @package		Members
 * @author 		selvaraj_35ag05
 * @copyright 	Copyright (c) 2008 {@link http://www.agriya.com Agriya Infoway}
 * @license		http://www.agriya.com Agriya Infoway Licence
 * @version		SVN: $Id: videoUploadPopUp.php 6360 2007-04-24 11:44:28Z vidhya_29ag04 $
 * @since 		2007-05-02
 *
 **/

require_once('../common/configs/config.inc.php');
$CFG['feature']['auto_hide_success_block'] = false;
$CFG['lang']['include_files'][] = 'languages/%s/common/email_notify.inc.php';
$CFG['lang']['include_files'][] = 'languages/%s/'.$CFG['admin']['index']['anova_module'].'/videoUpload.php';
$CFG['mods']['include_files'][] = 'common/classes/class_FormHandler.lib.php';
$CFG['mods']['include_files'][] = 'common/classes/class_AnovaHandler.lib.php';
$CFG['site']['is_module_page'] = $CFG['admin']['index']['anova_module'];
$CFG['mods']['is_include_only']['non_html_header_files'] = true;
$CFG['html']['is_use_header'] = false;
$CFG['html']['is_use_footer'] = false;
$CFG['is']['ajax_page'] = true;
require_once($CFG['site']['project_path'].'common/application_top.inc.php');

set_time_limit(0);
/**
 * VideoUpload
 *
 * @package
 * @author selvaraj_35ag05
 * @copyright Copyright (c) 2008
 * @version $Id: videoUpload.php 892 2007-05-26 13:23:06Z selvaraj_35ag05 $
 * @access public
 **/
class VideoUpload extends AnovaHandler
	{
		public function resetFieldsArray()
			{
				$this->setFormField('rid', '');
				$this->setFormField('flv_upload_type', 'video_file');
				$this->setFormField('video_flv_url', '');
				$this->setFormField('external_upload_type', '');
			}
	}
//<<<<<-------------- Class VideoUpload begins ---------------//
//-------------------- Code begins -------------->>>>>//
$VideoUpload = new VideoUpload();
if(!isAjax())
	Redirect2URL($CFG['site']['url']);
$VideoUpload->includeHeader();
$VideoUpload->setPageBlockNames(array('block_msg_form_error', 'block_msg_form_success', 'external_video_option', 'upload_video_file_form', 'upload_external_url_form'));
//default form fields and values...
$VideoUpload->resetFieldsArray();
$VideoUpload->setAllPageBlocksHide();
$VideoUpload->setPageBlockShow('external_video_option');
$VideoUpload->sanitizeFormInputs($_REQUEST);
$ask_question_url = getAnovaUrl('questions','','','members');
$smartyObj->assign('ask_question_url', $ask_question_url);
$upload_external_video_url = getAnovaUrl('externalvideoupload', '', '', 'members');

$upload_file = getAnovaUrl('externalvideoupload', '?flv_upload_type=video_file&rid='.$VideoUpload->getFormField('rid'), '/?flv_upload_type=video_file&rid='.$VideoUpload->getFormField('rid'), 'members');
$upload_external_url = getAnovaUrl('externalvideoupload', '?flv_upload_type=external_url&rid='.$VideoUpload->getFormField('rid'), '/?flv_upload_type=external_url&rid='.$VideoUpload->getFormField('rid'), 'members');

$smartyObj->assign('upload_external_video_url', $upload_external_video_url);
$smartyObj->assign('upload_file', $upload_file);
$smartyObj->assign('upload_external_url', $upload_external_url);
if ($VideoUpload->isFormPOSTed($_POST, 'validate_external_url'))
	{
		$VideoUpload->setAllPageBlocksHide();
		$VideoUpload->chkIsNotEmpty('video_flv_url',$LANG['external_url_err_tip_compulsory']) AND
			$VideoUpload->chkIsValidUrl('video_flv_url',$LANG['err_tip_invalid_external_url']);

		if( $VideoUpload->isValidFormInputs() && $VideoUpload->chkIsValidExternalUrl($VideoUpload->getFormField('video_flv_url')) )
			{
				$VideoUpload->chkIsURLAlreadyAdded('video_flv_url', $LANG['url_already_added'], $CFG['db']['tbl']['ans_video'], $CFG['user']['user_id']);
			}
		else
			{
				$VideoUpload->setFormFieldErrorTip('video_flv_url',$LANG['err_tip_invalid_external_url']);
			}
		if($VideoUpload->isValidFormInputs())
			{
				$external_upload_type = $VideoUpload->chkIsValidExternalUrl($VideoUpload->getFormField('video_flv_url'));
				$VideoUpload->setFormField('external_upload_type', $external_upload_type);
				$VideoUpload->setCommonSuccessMsg($LANG['external_url_verified_successfully']);
				$VideoUpload->setPageBlockShow('block_msg_form_success');
			}
		else
			{
				$VideoUpload->setCommonErrorMsg($LANG['msg_error_sorry']);
				$VideoUpload->setPageBlockShow('block_msg_form_error');
				$VideoUpload->setPageBlockShow('upload_external_url_form');
			}
	}
else if ($VideoUpload->isFormGETed($_REQUEST, 'flv_upload_type'))
	{
		$VideoUpload->setAllPageBlocksHide();
		if ($VideoUpload->getFormField('flv_upload_type') == 'external_url')
			$VideoUpload->setPageBlockShow('upload_external_url_form');
		else
			$VideoUpload->setPageBlockShow('upload_video_file_form');
	}
$submitForm = 'frmAjaxLightWindow';
$smartyObj->assign('submitForm', $submitForm);

if ($VideoUpload->isShowPageBlock('block_msg_form_success'))
    {
		$VideoUpload->block_msg_form_success['populateHidden']= array('video_flv_url', 'external_upload_type');
	}
if ($VideoUpload->isShowPageBlock('external_video_option'))
	{
		$VideoUpload->external_video_option['populateHidden']= array('rid');
	}
if ($VideoUpload->isShowPageBlock('upload_video_file_form'))
	{
		$file_name = $VideoUpload->getFormField('rid');
		$smartyObj->assign('file_name', $file_name);
		$config_path = $CFG['site']['url'].$CFG['admin']['index']['anova_module'].'/fileUploadConfigXmlCode.php?querystring='.$file_name.'_Video';
		$smartyObj->assign('config_path', $config_path);
		$swf_path = $CFG['site']['url'].$CFG['admin']['index']['anova_module'].'/files/flash/uploader/fileuploader.swf';
		$smartyObj->assign('swf_path', $swf_path);

		$selUploadFlash_display = 'block';
		$selUploadNormal_display = 'none';
		$smartyObj->assign('selUploadFlash_display', 'block');
		$smartyObj->assign('selUploadNormal_display', 'none');
		if($VideoUpload->isFormPOSTed($_POST, 'upload_audio_normal'))
			{
				$selUploadFlash_display = 'none';
				$selUploadNormal_display = 'block';
				$smartyObj->assign('selUploadNormal_display', 'block');
				$smartyObj->assign('selUploadFlash_display', 'none');
			}
		$VideoUpload->upload_video_file_form['populateHidden']= array('rid', 'flv_upload_type', 'external_upload_type');
	}
if ($VideoUpload->isShowPageBlock('upload_external_url_form'))
	{
		$VideoUpload->upload_external_url_form['populateHidden']= array('rid', 'flv_upload_type', 'external_upload_type');
	}
//include the content of the page
setTemplateFolder('members/', $CFG['admin']['index']['anova_module']);
$smartyObj->display('externalVideoUpload.tpl');
//include the footer of the page
$VideoUpload->includeFooter();
?>

