<?php
/**
 * This file is to upload the audios
 *
 * This file is having AudioUpload class to upload the audios
 *
 * PHP version 5.0
 *
 * @category	###Anova###
 * @package		AnsPreviewAudio
 * @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'].'/ansViewAudio.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');

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

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

				$this->fields_arr['audio_for'] = $param_arr[0];
				$this->fields_arr['aid'] = $param_arr[1];

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

				if(is_file($file_name))
					{
						$temp_dir = $this->CFG['admin']['ans_audios']['temp_folder'];
						$this->chkAndCreateFolder($temp_dir);
						$temp_file = $temp_dir.$this->fields_arr['aid'].'AUD.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 AudioPreview begins ---------------//
//-------------------- Code begins -------------->>>>>//
$AudioPreview = new AudioPreview();

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

$AudioPreview->setPageBlockNames(array('audio_display'));

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

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

if($AudioPreview->isFormGETed($_REQUEST, 'pg'))
	{
		if(!$AudioPreview->populateAudioDetails())
			{
				$AudioPreview->setAllPageBlocksHide();
				$AudioPreview->setCommonErrorMsg($LANG['error_audio']);
				$AudioPreview->setPageBlockShow('block_msg_form_error');
			}
		else
			{
				$AudioPreview->setPageBlockShow('audio_display');
			}
	}
//<<<<<-------------------- Code ends----------------------//

if ($AudioPreview->isShowPageBlock('audio_display'))
	{
		$AudioPreview->player_url = $CFG['site']['url'].'files/flash/mp3_player/player.swf';
		$AudioPreview->audios_folder = $CFG['admin']['ans_audios']['audio_folder'];
		$AudioPreview->config_url = $CFG['site']['url'].'ansAudioConfigXmlCode.php?pg=previewmusic_'.$AudioPreview->getFormField('aid');
		$AudioPreview->playlist_url = $CFG['site']['url'].'ansAudioPlaylistXmlCode.php?pg=previewmusic_'.$AudioPreview->getFormField('aid');
	}
//-------------------- Page block templates begins -------------------->>>>>//
//include the header file
$AudioPreview->includeAjaxHeader();
//include the content of the page
setTemplateFolder('members/', $CFG['admin']['index']['anova_module']);
$smartyObj->display('ansPreviewAudio.tpl');
//<<<<<-------------------- Page block templates ends -------------------//
$AudioPreview->includeAjaxFooter();
?>