<?php
/**
 * This file is to upload the audios
 *
 * This file is having AudioUpload class to upload the audios
 *
 * PHP version 5.0
 *
 * @category	rayzz
 * @package		Members
 * @author 		senthil_52ag05
 * @copyright 	Copyright (c) 2008 {@link http://www.agriya.com Agriya Infoway}
 * @license		http://www.agriya.com Agriya Infoway Licence
 * @version		SVN: $Id: $
 * @since 		2008-03-14
 *
 **/
require_once('../common/configs/config.inc.php');
$CFG['feature']['auto_hide_success_block'] = false;
$CFG['lang']['include_files'][] = 'languages/%s/'.$CFG['admin']['index']['anova_module'].'/videoUpload.php';
$CFG['mods']['include_files'][] = 'common/classes/class_AnsVideoUpload.lib.php';
$CFG['mods']['include_files'][] = 'common/classes/class_FormHandler.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($CFG['site']['project_path'].'common/application_top.inc.php');
require_once($CFG['site']['project_path'].'common/application_top.inc.php');
set_time_limit(0);
/**
 * AudioUpload
 *
 * @package
 * @author senthil_52ag05
 * @copyright Copyright (c) 2008
 * @version $Id: $
 * @access public
 **/
class AudioUpload extends FormHandler
	{
		public function resetFieldsArray()
			{
				$this->setFormField('rid', '');
				$this->setFormField('audio_upload_type', 'audio_file');
				$this->setFormField('audio_url', '');
			}
	}
//<<<<<-------------- Class AudioUpload begins ---------------//
//-------------------- Code begins -------------->>>>>//
$AudioUpload = new AudioUpload();
if(!isAjax())
	Redirect2URL($CFG['site']['url']);
$AudioUpload->includeHeader();
$AudioUpload->setPageBlockNames(array('block_msg_form_error', 'block_msg_form_success', 'external_audio_option', 'upload_audio_file_form', 'upload_external_url_form'));
//default form fields and values...
$AudioUpload->resetFieldsArray();

$AudioUpload->setAllPageBlocksHide();
$AudioUpload->setPageBlockShow('external_audio_option');
$AudioUpload->sanitizeFormInputs($_REQUEST);

$ask_question_url = getAnovaUrl('questions');
$smartyObj->assign('ask_question_url', $ask_question_url);
$upload_external_audio_url = getAnovaUrl('externalaudioupload', '', '','members');
$upload_file = getAnovaUrl('externalaudioupload', '?audio_upload_type=audio_file&rid='.$AudioUpload->getFormField('rid'), '/?audio_upload_type=audio_file&rid='.$AudioUpload->getFormField('rid'), 'members');
$upload_external_url = getAnovaUrl('externalaudioupload', '?audio_upload_type=external_url&rid='.$AudioUpload->getFormField('rid'), '/?audio_upload_type=external_url&rid='.$AudioUpload->getFormField('rid'), 'members');

$smartyObj->assign('upload_external_audio_url', $upload_external_audio_url);
$smartyObj->assign('upload_file', $upload_file);
$smartyObj->assign('upload_external_url', $upload_external_url);
if ($AudioUpload->isFormPOSTed($_POST, 'validate_external_url'))
	{
		$AudioUpload->setAllPageBlocksHide();
		$AudioUpload->chkIsNotEmpty('audio_url', $LANG['external_url_err_tip_compulsory']) and
			$AudioUpload->chkIsValidUrl('audio_url', $LANG['err_tip_invalid_external_url']);
		$AudioUpload->chkIsURLAlreadyAdded('audio_url', $LANG['url_already_added'], $CFG['db']['tbl']['ans_audio'], $CFG['user']['user_id']);
		if($AudioUpload->isValidFormInputs())
			{
				$AudioUpload->setCommonSuccessMsg($LANG['external_url_verified_successfully']);
				$AudioUpload->setPageBlockShow('block_msg_form_success');
			}
		else
			{
				$AudioUpload->setCommonErrorMsg($LANG['msg_error_sorry']);
				$AudioUpload->setPageBlockShow('block_msg_form_error');
				$AudioUpload->setPageBlockShow('upload_external_url_form');
			}
	}
else if ($AudioUpload->isFormGETed($_REQUEST, 'audio_upload_type'))
	{
		$AudioUpload->setAllPageBlocksHide();
		if ($AudioUpload->getFormField('audio_upload_type') == 'external_url')
			$AudioUpload->setPageBlockShow('upload_external_url_form');
		else
			$AudioUpload->setPageBlockShow('upload_audio_file_form');
	}
$submitForm = 'frmAjaxLightWindow';
$smartyObj->assign('submitForm',$submitForm);
if ($AudioUpload->isShowPageBlock('block_msg_form_success'))
    {
		$AudioUpload->block_msg_form_success['populateHidden']= array('audio_url');
	}
if ($AudioUpload->isShowPageBlock('external_audio_option'))
	{
		$AudioUpload->external_audio_option['populateHidden']= array('rid');
	}
if ($AudioUpload->isShowPageBlock('upload_audio_file_form'))
	{
		$file_name = $AudioUpload->getFormField('rid');
		$smartyObj->assign('file_name', $file_name);
		$config_path = $CFG['site']['url'].$CFG['admin']['index']['anova_module'].'/fileUploadConfigXmlCode.php?querystring='.$file_name.'_Audio';
		$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 = '';
		$selUploadNormal_display = 'none';
		$smartyObj->assign('selUploadFlash_display', '');
		$smartyObj->assign('selUploadNormal_display', 'none');
		if($AudioUpload->isFormPOSTed($_POST, 'upload_audio_normal'))
			{
				$selUploadFlash_display = 'none';
				$selUploadNormal_display = '';
				$smartyObj->assign('selUploadNormal_display', '');
				$smartyObj->assign('selUploadFlash_display', 'none');
			}
		$AudioUpload->upload_audio_file_form['populateHidden']= array('rid', 'audio_upload_type');
	}
if ($AudioUpload->isShowPageBlock('upload_external_url_form'))
	{
		$AudioUpload->upload_external_url_form['populateHidden']= array('rid', 'audio_upload_type');
	}
//include the content of the page
setTemplateFolder('members/', $CFG['admin']['index']['anova_module']);
$smartyObj->display('externalAudioUpload.tpl');
//include the footer of the page
$AudioUpload->includeFooter();
?>