<?php 
/*********************************************************/
require("../sub_inc/commfunc.php");
$helpId = "6.13.1"; 
$DEBUG=0;

//==========================================================
//变量定义
//==========================================================
if(isset($backurl)){
	$backurl = rawurldecode($backurl);
}

$pubDb				= 'OMC_PUB';

$ftpLoginName		= 'ems';
$ftpLoginPwd		= 'Ems123!';

$remotepath = '/usr/local/prompt/';
$localpath	='./'.$localpath.'/';
//echo "localpath:$localpath";
//$impFileArr[0][localFile] 	= $localpath.time().".evr";
$impFileArr[0][localFile] 	= $localpath.time().".wav";
$impFileArr[0][remoteFile] 	= $remotepath."$voicefile";
$output 					= $localpath.time().".wav";

function getFile($ftpCon)
{
	global $impFileArr,$language;
	for($j=0;$j<sizeof($impFileArr);$j++)
	{
		$localFile	=$impFileArr[$j][localFile];
		$remoteFile	=$impFileArr[$j][remoteFile];
//echo "<br>ftpCon:$ftpCon";
//echo "<br>localFile:$localFile";
//echo "<br>remoteFile:$remoteFile";
		if(!@ftp_get($ftpCon,$localFile,$remoteFile,FTP_BINARY))
		{
			if($language == 'chn')
			{
				echo "<br><font color=\"#FF0000\">下载失败.<br></font>";
				exit();
			}
			else
			{
				echo "<br><font color=\"#FF0000\">Get File Failed.<br></font>";
				exit();
			}
			return(-1);
		}
		else
		{
			if($language == 'chn')
			{
				//echo "<br><font color=\"#0000FF\">下载成功.<br></font>";
			}
			else
			{
				//echo "<br><font color=\"#0000FF\">Successful.<br></font>";
			}
		}
	}
	return(1);
}

function PCMtoWAV($infile)
{
	$fsize2 = filesize($infile);	
	$fsize1 = $fsize2+36;
	$fsize2 = dechex($fsize2);
	$fsize1 = dechex($fsize1);
	$tmp = "";
	$tmp = omc_keep_length($fsize2,"0","8");
	$unitByte3 = substr($tmp,0,2);
	$unitByte2 = substr($tmp,2,2);
	$unitByte1 = substr($tmp,4,2);
	$unitByte0 = substr($tmp,6,2);
	$setfsize2 = $unitByte0.$unitByte1.$unitByte2.$unitByte3;
	$tmp = "";
	$tmp = omc_keep_length($fsize1,"0","8");
	$unitByte3 = substr($tmp,0,2);
	$unitByte2 = substr($tmp,2,2);
	$unitByte1 = substr($tmp,4,2);
	$unitByte0 = substr($tmp,6,2);
	$setfsize1 = $unitByte0.$unitByte1.$unitByte2.$unitByte3;
	$wavehead = "52494646".$setfsize1."57415645666d74201000000006000100401f0000401f00000200080064617461".$setfsize2;
	$szwavehead = toAscii($wavehead);
	$fp = fopen($infile, 'r+');
	if(!$fp)
	{
		echo "open file fail.";
		exit();
	}
	$contents = fread($fp, filesize($infile));
	if(!$contents)
	{
		echo "read file fail.";
		exit();		
	}
	if(!rewind($fp))
	{
		echo "rewind file fail.";
		exit();				
	}

	if(!fwrite($fp, $szwavehead.$contents))
	{
		echo "write file fail.";
		exit();
	}	
	if(!fclose($fp))
	{
		echo "close file fail.";
		exit();
	}	
}
echo "<table border=\"0\" width=\"100%\">";
echo "<tr>";
echo "<td width=\"50%\">";
echo "<b>Voice Play</b></td><td>";
if(isset($backurl))
{
	echo "<input type=\"hidden\" name=\"backurl\" value=\"$backurl\">";
	echo "<p align=\"right\"><a href=\"$backurl\"><img align=absBottom border=0 src=\"../../images/left.gif\" width=\"14\" height=\"14\">$strBack</a>";
}
else
{
	echo "<p align=\"right\"><a href=\"javascript:history.go(-1)\"><img align=absBottom border=0 src=\"../../images/left.gif\" width=\"14\" height=\"14\">$strBack</a>";
}
echo "</td></tr>";
echo "</table>";
echo "<table><tr><td>";
//==========================================================
//数据处理
//==========================================================
	//delete *.wav *.evr
	$handle=opendir($localpath);
	while($file=readdir($handle))
	{
		$retval="";
		$pt=strrpos($file,".");
		if($pt) $retval=substr($file,$pt+1,strlen($file)-$pt);
		if($retval=='wav') unlink($localpath.$file);
		if($retval=='evr') unlink($localpath.$file);
	}

	$sysIdArr	= explode('_',$sysId);
	$sysTypeNo	= $sysIdArr[0];
	$sysNo		= $sysIdArr[1];
	$subSysNo	= $sysIdArr[2];	

	
	$getSysIdSql = "SELECT sysNo,subSysNo,ip FROM sysInfo
				WHERE sysTypeNo='$sysTypeNo' AND sysNo='$sysNo' AND subSysNo='$subSysNo'
			";
//	echo "<br>getSysIdSql:$getSysIdSql";
	$getSysIdResult= mysqli_query($pubConn,$getSysIdSql);
	$omcNum=mysqli_num_rows($getSysIdResult);
	if($omcNum <= 0)
	{
		if($language == 'chn')
		{
			echo "[错误]：系统列表中没有配置 OMC or VSS 的IP!";
			exit();
		}
		else
		{
			echo "Error:Can not find any OMC's or VSS's IP in system list,Please ADD it!";
			exit();
		}
		if($default !=1)
		{
			delImpFile();
		}
		exit();
	}

	$getSysIdRow=mysqli_fetch_array($getSysIdResult);
	$dstSeverIp = $getSysIdRow[ip];
	flush();
	$ftpCon=@ftp_connect($dstSeverIp);
	if($ftpCon < 1)
	{
		if($language == 'chn')
		{
			echo "<br><font color=\"#FF0000\">连接 $dstSeverIp 失败!</font>";
			exit();
		}
		else
		{
			echo "<br><font color=\"#FF0000\">Connect <u>$dstSeverIp</u> Failed!</font>";
			exit();
		}
		continue;
	}
	else
	{
		flush();
	}
	if(!@ftp_login($ftpCon,$ftpLoginName,$ftpLoginPwd))
	{
		if($language == 'chn')
		{
			echo "<br><font color=\"#FF0000\">登陆 $sysName 失败!</font>";
			exit();
		}
		else
		{
			echo "<br><font color=\"#FF0000\">Login $sysName Failed!</font>";
			exit();
		}
		@ftp_quit($ftpCon);
		continue;
	}
	else
	{
		flush();
	}
	getFile($ftpCon);
	ftp_quit($ftpCon);
	
	flush();
	//$result = exec("mv {$impFileArr[0][localFile]}  $output");
	
	$tmpSql = "SELECT detailStat FROM sysStat
				WHERE sysTypeNo='$sysTypeNo' AND sysNo='$sysNo' AND subSysNo='$subSysNo'
			";
	$tmpResult= mysqli_query($pubConn,$tmpSql);
	$tmpRows=mysqli_num_rows($tmpResult);
	
	$voiceRule=bindec(getBitValue($tmpRows[detailStat],'68.3-68.3'));
	if($voiceRule==1)//MU LAW
		PCMtoWAV($impFileArr[0][localFile]);
?>
</td></tr><tr>
<meta http-equiv="pragma" content="no-cache" />
<meta http-equiv="Cache-Control" content="no-cache, must-revalidate" />
<meta http-equiv="expires" content="Mon, 23 Jan 1978 12:52:30 GMT" />	
<object classid="clsid:22D6F312-B0F6-11D0-94AB-0080C74C7E95" id="MediaPlayer1" width="286" height="225">
    <param name="AudioStream" value="-1">
    <param name="AutoSize" value="-1">
    <!--是否自动调整播放大小-->
    <param name="AutoStart" value="-1">
    <!--是否自动播放-->
    <param name="AnimationAtStart" value="-1">
    <param name="AllowScan" value="-1">
    <param name="AllowChangeDisplaySize" value="-1">
    <param name="AutoRewind" value="0">
    <param name="Balance" value="0">
    <!--左右声道平衡,最左-9640,最右9640-->
    <param name="BaseURL" value>
    <param name="BufferingTime" value="15">
    <!--缓冲时间-->
    <param name="CaptioningID" value>
    <param name="ClickToPlay" value="-1">
    <param name="CursorType" value="0">
    <param name="CurrentPosition" value="0">
    <!--当前播放进度 -1 表示不变,0表示开头 单位是秒,比如10表示从第10秒处开始播放,值必须是-1.0或大于等于0-->
    <param name="CurrentMarker" value="0">
    <param name="DefaultFrame" value>
    <param name="DisplayBackColor" value="0">
    <param name="DisplayForeColor" value="16777215">
    <param name="DisplayMode" value="0">
    <param name="DisplaySize" value="0">
    <!--视频1-50%, 0-100%, 2-200%,3-全屏 其它的值作0处理,小数则采用四舍五入然后按前的处理-->
    <param name="Enabled" value="-1">
    <param name="EnableContextMenu" value="0">
    <!-是否用右键弹出菜单控制-->
    <param name="EnablePositionControls" value="-1">
    <param name="EnableFullScreenControls" value="0">
    <param name="EnableTracker" value="0">
    <!--是否允许拉动播放进度条到任意地方播放-->
    <param name="Filename" value="<?php echo"$output"; ?>" valuetype="ref"> //把地址傳遞到這裡
    <!--播放的文件地址-->
    <param name="InvokeURLs" value="-1">
    <param name="Language" value="-1">
    <param name="Mute" value="0">
    <!--是否静音-->
    <param name="PlayCount" value="1">
    <!--重复播放次数,0为始终重复-->
    <param name="PreviewMode" value="-1">
    <param name="Rate" value="1">
    <!--播放速率控制,1为正常,允许小数-->
    <param name="SAMIStyle" value>
    <!--SAMI样式-->
    <param name="SAMILang" value>
    <!--SAMI语言-->
    <param name="SAMIFilename" value>
    <!--字幕ID-->
    <param name="SelectionStart" value="-1">
    <param name="SelectionEnd" value="-1">
    <param name="SendOpenStateChangeEvents" value="-1">
    <param name="SendWarningEvents" value="-1">
    <param name="SendErrorEvents" value="-1">
    <param name="SendKeyboardEvents" value="0">
    <param name="SendMouseClickEvents" value="0">
    <param name="SendMouseMoveEvents" value="0">
    <param name="SendPlayStateChangeEvents" value="-1">
    <param name="ShowCaptioning" value="0">
    <!--是否显示字幕,为一块黑色,下面会有一大块黑色,一般不显示-->
    <param name="ShowControls" value="-1">
    <!--是否显示控制,比如播放,停止,暂停-->
    <param name="ShowAudioControls" value="-1">
    <!--是否显示音量控制-->
    <param name="ShowDisplay" value="0">
    <!--显示节目信息,比如版权等-->
    <param name="ShowGotoBar" value="0">
    <!--是否启用上下文菜单-->
    <param name="ShowPositionControls" value="-1">
    <!--是否显示往前往后及列表,如果显示一般也都是灰色不可控制-->
    <param name="ShowStatusBar" value="-1">
    <!--当前播放信息,显示是否正在播放,及总播放时间和当前播放到的时间-->
    <param name="ShowTracker" value="-1">
    <!--是否显示当前播放跟踪条,即当前的播放进度条-->
    <param name="TransparentAtStart" value="-1">
    <param name="VideoBorderWidth" value="-1">
    <!--显示部的宽部,如果小于视频宽,则最小为视频宽,或者加大到指定值,并自动加大高度.此改变只改变四周的黑框大小,不改变视频大小-->
    <param name="VideoBorderColor" value="0">
    <!--显示黑色框的颜色, 为RGB值,比如ffff00为黄色-->
    <param name="VideoBorder3D" value="0">
    <param name="Volume" value="0">
    <!--音量大小,负值表示是当前音量的减值,值自动会取绝对值,最大为0,最小为-9640-->
    <param name="WindowlessVideo" value="-1">
    <!--如果是0可以允许全屏,否则只能在窗口中查看-->
</object>
</tr></table>
