<?php
require("../sub_inc/commfunc.php");

$listPageUrl = "CNFconf.php?linkset=$linkset&trunkgp=$trunkgp&infoNo=$infoNo&sysNo=$sysNo&subSysNo=$subSysNo"; 

$objDB = 'OBJ_160';
$paramTab = 'param_'.$sysNo;
?>

<body topmargin="0" leftmargin="12">
	
<?php

$confParaArr = array(
array('name' => 'Conference ID',		'bit' => '00.0-00.7', 	'inputName' => 'conf1',		'value' => ''),
array('name' => 'Conference number',	'bit' => '01.0-08.7', 	'inputName' => 'conf2',		'value' => ''),
array('name' => 'Password',				'bit' => '09.0-10.7', 	'inputName' => 'conf3',		'value' => ''),
array('name' => 'Applicant',			'bit' => '11.0-18.7', 	'inputName' => 'conf4',		'value' => ''),
array('name' => 'Start time',			'bit' => '19.0-22.7', 	'inputName' => 'conf5',		'value' => ''),
array('name' => 'Duration',				'bit' => '23.0-24.7', 	'inputName' => 'conf6',		'value' => ''),
array('name' => 'Maximum party',		'bit' => '25.0-25.7', 	'inputName' => 'conf7',		'value' => ''),
array('name' => 'Status',				'bit' => '26.0-26.7', 	'inputName' => 'conf8',		'value' => '')
);

$startTimeArr=array(
	array('name' => 'month', 	'value' => ''),
	array('name' => 'day', 		'value' => ''),
	array('name' => 'House',	'value' => ''),
	array('name' => 'Minute', 	'value' => '')
);

if($_SERVER['REQUEST_METHOD'] == "POST")
{
	$oidstr = "2.1.8";
	$objWhereStr = getLevelWhere($oidstr);	
	$setValue = omc_keep_length($prefix,'E',4,0);
	$setValue = strtoupper($setValue);
	$updSql = "update $paramTab set initValue='$setValue' where $objWhereStr and subSysNo='99' and instanceNo='$instanceNo'";
	mysqli_query($pubConn,$updSql);
	
	$oidstr = "2.1.9";
	$objWhereStr = getLevelWhere($oidstr);	
	$tmp1 = omc_keep_length(decbin($dialLen),'0',6);
	$tmp2 = omc_keep_length(decbin($leadDig),'0',2);
	$tmpbin = $tmp2.$tmp1;
	$setValue = bindec($tmpbin);
	$setValue = omc_keep_length(dechex($setValue),'0',2);
	$setValue = strtoupper($setValue);
	$updSql = "update $paramTab set initValue='$setValue' where $objWhereStr and subSysNo='99' and instanceNo='$instanceNo'";
	mysqli_query($pubConn,$updSql);
	
	echo "<script LANGUAGE=\"JavaScript\">";
	if(!$DEBUG)
	{
		echo "\n window.location.href=\"$listPageUrl\";";
	} 	
	echo "\n </script>";
}

if($instanceNo=='new')
{
	$oidstr = "2.1.8";
	$objWhereStr = getLevelWhere($oidstr);	

	$selSql = "select initValue,instanceNo from $paramTab where $objWhereStr  and subSysNo='99' and initValue='0000'";
	$result = @mysqli_query($pubConn,$selSql);
	if($row = @mysqli_fetch_array($result))
	{
		$instanceNo = $row[instanceNo];
		$prefix = str_replace('E','',$row[initValue]);
		
		$oidstr = "2.1.9";
		$objWhereStr = getLevelWhere($oidstr);	
		$selSql = "select initValue,instanceNo from $paramTab where $objWhereStr and subSysNo='99' and instanceNo='{$inst}'";
		$result = @mysqli_query($pubConn,$selSql);
		$row = mysqli_fetch_array($result);
		$dialLen = bindec(getBitValue($row[initValue],'00.0-00.5'));
		$leadDig = bindec(getBitValue($row[initValue],'00.6-00.7'));
	}
	else
	{
		echo "<script language='javascript'>";  
		echo "window.alert(\"Have no more prefix to be added!\");";	
		echo "history.go(-1)";
		echo "</script>";	
	}
}
else
{
	$oidstr = "2.1.8";
	$objWhereStr = getLevelWhere($oidstr);	
	$selSql = "select initValue,instanceNo from $paramTab where $objWhereStr and subSysNo='99' and instanceNo='$instanceNo'";
	$result = @mysqli_query($pubConn,$selSql);
	$row = mysqli_fetch_array($result);
	$prefix = str_replace('E','',$row[initValue]);
	
	$oidstr = "2.1.9";
	$objWhereStr = getLevelWhere($oidstr);	
	$selSql = "select initValue,instanceNo from $paramTab where $objWhereStr and subSysNo='99' and instanceNo='$instanceNo'";
	$result = @mysqli_query($pubConn,$selSql);
	$row = mysqli_fetch_array($result);
	$dialLen = bindec(getBitValue($row[initValue],'00.0-00.5'));
	$leadDig = bindec(getBitValue($row[initValue],'00.6-00.7'));
}
$selfPage = "$PHP_SELF?linkset=$linkset&trunkgp=$trunkgp&infoNo=$infoNo&instanceNo=$instanceNo&sysNo=$sysNo&subSysNo=$subSysNo";

echo "<form method=\"POST\" name=\"Set\" action=\"$selfPage\">";
{
	echo "<table border=\"0\" width=\"100%\">";
	echo "<tr>";
	echo "<td width=\"50%\">";
	echo "Configuration > <a href=\"../overview/overview.php\">Network</a> > <a href=\"$listPageUrl\">CNF</a> > <a href=\"#\">Prefix</a>";
	echo "<td width=\"50%\" align=\"right\" title=\"Help\">";
	showHelp($helpId);
	echo "</td>";
	echo "</tr>";
	echo "</table>";
	echo "<br>";
	
	echo "<table width=\"100%\">";
	echo "<tr><td width=\"70%\">";
	echo "<b>CNF Prefix:&nbsp;&nbsp;</b>";
	echo "$instanceNo";
	echo "</td>";
	echo "<td width=\"20%\">";
	echo "<input type=\"submit\" value=$strSave class=\"button\" name=\"setSys\" style=\"left: 1; top: 2; width: 60; height: 25; position: relative\">";	
	echo "&nbsp;&nbsp;&nbsp;&nbsp;";
	echo "<input type=\"reset\" value=$strReset  class=\"button\" name=\"Reset\" style=\"left: 1; top: 2; width: 60; height: 25; position: relative\">";
	echo "</td>";
	echo "<td width=\"10%\">";
	echo "<p align=\"right\"><a href=\"$listPageUrl\"><img align=absBottom border=0 src=\"../../images/left.gif\" width=\"14\" height=\"14\">$strBack</a>";
	echo "</td></tr>";
	echo "</table>";
}

$leadDigArr = array(
		'Internal',
		'Conference',
		'PPS'
	);
echo "<table border=\"1\" width=\"100%\" cellpadding=\"1\" cellspacing=\"0\" bordercolor=\"#666666\" bordercolordark=\"#FFFFFF\">";
	echo "<tr>";
	echo "<th colspan=\"2\">Conference parameter</th>";
	echo "</tr>";
		echo "<td width=\"40%\">Prefix</td>";
		echo "<td><input type=\"text\" name=\"prefix\" value=\"$prefix\" size=\"4\" maxlength=\"4\"  onchange=checkInput(this,16,0)></td>";
	echo "</tr>";
	
	echo "</tr>";
		echo "<td>Length of dialed number</td>";
		echo "<td><input type=\"text\" name=\"dialLen\" value=\"$dialLen\" size=\"4\" maxlength=\"2\"  onchange=checkInput(this,10,0)></td>";
	echo "</tr>";
		echo "<td>Lead digit</td>";
		echo "<td>";
		echo "<select name=\"leadDig\" >";
		while (list ($key, $val) = each ($leadDigArr)) 
		{
			echo "<option value=\"$key\" ";
			if($key == $leadDig)
				echo "selected";
			echo ">$val</option>";
		}
		echo "</select>";
		echo "</td>";
	echo "<tr>";
	echo "</tr>";
echo "</talble>";
?>

