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

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

$center_objDB='OBJ_270';
$center_paramTab='param_0';
?>

<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.2";
	$objWhereStr = getLevelWhere($oidstr);	
	$setValue='EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE000000EE';
	$conf1 = omc_keep_length(dechex($conf1),'0',2);
	$conf2 = omc_keep_length($conf2,'E',16,1);
	$conf3 = omc_keep_length($conf3,'E',4,1);
	$conf4 = omc_keep_length($conf4,'E',16,1);
	$conf5 = '';
	for($i=0;$i< sizeof($startTimeArr); $i++)
	{
		$tmp = ${"{$startTimeArr[$i][name]}"};
//		echo "<br>{$startTimeArr[$i][name]}:$tmp";
		$startTimeArr[$i][value] = omc_keep_length(dechex($tmp),'0',2);
		$conf5 .= $startTimeArr[$i][value];
	}
	$conf6 = omc_keep_length(dechex($conf6),'0',4);
	$conf7 = omc_keep_length(dechex($conf7),'0',2);
	$conf8 = omc_keep_length(dechex($conf8),'0',2);
	for($i=0; $i< sizeof($confParaArr); $i++)
	{
//		echo "<br>{$confParaArr[$i][inputName]}:" . ${"{$confParaArr[$i][inputName]}"};
		$setValue = setBitValue($setValue,$confParaArr[$i][bit],${"{$confParaArr[$i][inputName]}"});		
	}
	$setValue = strtoupper($setValue);
//	echo "<br>setValue: $setValue";
//	exit;	
	$updSql = "update $center_paramTab set initValue='$setValue' where $objWhereStr 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')
{
	
	//===============get the default value======================
	$database="OBJ_270";
	$sql="select initValue from paramConf where level_1=2 and level_2=2 ";
	$result=@mysqli_query($pubConn,$sql);
	$rows=@mysqli_fetch_array($result);
	$conference_parameter_default_value=$rows[initValue];
	//=====================
	$oidstr = "2.2";
	$objWhereStr = getLevelWhere($oidstr);	

	$selSql = "select initValue,instanceNo from $center_paramTab where $objWhereStr ";
	$result = mysqli_query($pubConn,$selSql);
	$n=0;
	while($row = mysqli_fetch_array($result))
	{
		//$confNumber = getBitValue($row[initValue],$confParaArr[1][bit]);
		//$confNumber = str_replace('E','',$confNumber); 
		//if(strlen($confNumber)==0)
		if($conference_parameter_default_value==$row[initValue])
		{
			$instanceNo = $row[instanceNo];
			break;
		}
	}
}
else
{

	$oidstr = "2.2";
	$objWhereStr = getLevelWhere($oidstr);	
	
	$selSql = "select initValue,instanceNo from $center_paramTab where $objWhereStr and instanceNo='$instanceNo' ";
	$result = mysqli_query($pubConn,$selSql);
	$row = mysqli_fetch_array($result);
	
	$confParaArr[0][value] = hexdec(getBitValue($row[initValue],$confParaArr[0][bit]));
	$confParaArr[1][value] = str_replace('E','',getBitValue($row[initValue],$confParaArr[1][bit]));
	$confParaArr[2][value] = str_replace('E','',getBitValue($row[initValue],$confParaArr[2][bit]));
	$confParaArr[3][value] = str_replace('E','',getBitValue($row[initValue],$confParaArr[3][bit]));
	$confParaArr[4][value] = str_replace('E','E',getBitValue($row[initValue],$confParaArr[4][bit]));
	$confParaArr[5][value] = hexdec(getBitValue($row[initValue],$confParaArr[5][bit]));
	$confParaArr[6][value] = hexdec(getBitValue($row[initValue],$confParaArr[6][bit]));
	$confParaArr[7][value] = getBitValue($row[initValue],$confParaArr[7][bit]);
}
$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=\"#\">Conference parameter</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 "&nbsp;&nbsp;";
	//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=$strUndo  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>";
}

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>";
	$status_label=array(0=>"Not Executable",1=>"Booking",2=>"On Going",3=>"Finished",4=>"Draft");
	
	for($i=0; $i< sizeof($confParaArr); $i++)
	{
		echo "<tr>";
			echo "<td>";
				echo $confParaArr[$i][name];
			echo "</td>";
			echo "<td>";
			if($i==4)
			{
				$confParaArr[$i][value] = omc_keep_length($confParaArr[$i][value],'0',8,0);
				for($k=0; $k< sizeof($startTimeArr); $k++)
				{
					$startTimeArr[$k][value] = omc_keep_length(hexdec(substr($confParaArr[$i][value],$k*2,2)),'0',2);
					echo "<input type=\"text\" size=\"2\" maxlength=\"2\" name=\"{$startTimeArr[$k][name]}\" value=\"{$startTimeArr[$k][value]}\">";
					if($k==0)
						echo "&nbsp;-&nbsp;";
					else if($k==1) echo "&nbsp;&nbsp;&nbsp;&nbsp;";
					else if($k==2) echo "&nbsp;:&nbsp;";
				}	
				//echo "&nbsp;Month Day House Minute";			
			}
			else if($i==7)
			{
				$status_tmp=$status_label[$confParaArr[$i][value]+0];
				echo "$status_tmp";
				echo "<input type=\"hidden\" name=\"{$confParaArr[$i][inputName]}\" value=\"{$confParaArr[$i][value]}\" >";
			}
			else if($i==0)
			{
				$tmp=$instanceNo+1;
				echo "$tmp";
				echo "<input type=\"hidden\" name=\"{$confParaArr[$i][inputName]}\" value=\"$tmp\" >";
			}
			else
			{
				echo "<input type=\"text\" name=\"{$confParaArr[$i][inputName]}\" value=\"{$confParaArr[$i][value]}\" >";
			}
			echo "</td>";
		echo "</tr>";
	}
//	echo "<tr>";
//		echo "<td>";
//			echo $confParaArr[$i][name];
//		echo "</td>";
//		echo "<td>";
//			echo $confParaArr[$i][value];
//		echo "</td>";
//		echo "<input type=\"hidden\" name=\"{$confParaArr[7][inputName]}\" value=\"{$confParaArr[7][value]}\">";
//	echo "</tr>";
echo "</talble>";
?>

