<?php

/*********************************************************      
 程序说明：         
    功能说明：本程序定义用户需要下载的数据信息

    调用关系：调用:header.inc     
              被调用:      
 
    变量说明：

    返回值：无

 作者：   
      
修改注释：      
NO.1      
姓名：     
时间：    
修改说明：
 *********************************************************/
require("../../inc/header.inc");
?>

<body onload="javascript:adjust();" onresize="javascript:adjust();" leftmargin="15" style="overflow:hidden;overflow-x:hidden;overflow-y:hidden;">

	<?php
	adjust_head();
	adjust_title_head();
	echo "<table id=\"table_up\" border=\"0\" width=\"100%\">";
	echo "<tr>";
	echo "<td width=\"50%\">";
	echo "Template > CSV";
	echo "</td>";
	echo "<td width=\"50%\" align=\"right\" title=\"Help\">";
	//showHelp($helpId);
	echo "</td>";
	echo "</tr>";
	echo "</table>";
	adjust_title_tail();
	adjust_content_head();
	echo "<br>";

	$max_menu = 4;
	$db = $omc_db;
	$db_name = isset($db_name) ? $db_name : $omc_db;
	$elementTable	= 'elementExistConf';

	//----------------------
	//选择语言版本
	if ($language_type == 'eng') {
		$show_menu_name = menu_name_2;	//语种2
	} else {
		$show_menu_name = menu_name;	//语种1
	}
	//-----------------------

	/**************************************删除一个类型说明***********************************************/
	if ($delete) {
		$del_sql = "DELETE FROM $syscsvconf_table WHERE key_menu_id='$key_menu_id'";
		$del_result = mysqli_query($pubConn, $del_sql);
		//----------------
		//插入日志
		//insertLog(0,3,$del_sql,$user_info["account"]);
		insertLog($user_info["account"]);
		//------------
		if ($del_result) {
			echo "<font color=\"#0000ff\">$strDeleteSuccess</font>";
		} else {
			echo "<font color=\"#ff0000\">$strDeleteFailure</font>";
		}
	} //end if($delete) 


	/*****************************添加,保存一个新的参数类型或创建新的参数结构表*****************************/
	if ($save) {
		$key_menu_id = $type_list;
		if ($key_menu_id == 'new') {  //插入一个新类型
			$save_sql = "REPLACE INTO $syscsvconf_table 
			(sys_type, sys_id, obj_id, if_enable, if_subsys, menu_name, menu_name_2, can_download, can_upload, server_name, db_name, table_name, where_find, description, description_2, level_0, level_1, level_2, level_3) 
		     VALUES 
			('$sys_type', '$sys_id', '$obj_id', '$if_enable', '$if_subsys', '$menu_name', '$menu_name_2', '$can_download', '$can_upload', '$server_name', '$db_name', '$table_name', '$where_find', '$description', '$description_2', '$level_0', '$level_1', '$level_2', '$level_3') 
		    ";
		} elseif (isset($key_menu_id)) {  //修改已有类型
			$save_sql = "
			UPDATE $syscsvconf_table 
			SET 
			sys_type  = '$sys_type',
			sys_id	  = '$sys_id',
			obj_id	  = '$obj_id',
			if_enable = '$if_enable',
			if_subsys = '$if_subsys',
			menu_name = '$menu_name',
			menu_name_2 = '$menu_name_2',
			can_download = '$can_download',
			can_upload = '$can_upload',
			server_name = '$server_name',
			db_name = '$db_name',
			table_name = '$table_name',
			where_find = '$where_find',
			description = '$description',
			description_2 = '$description_2',
			level_0 = '$level_0',
			level_1 = '$level_1',
			level_2 = '$level_2',
			level_3 = '$level_3'
			WHERE  key_menu_id='$key_menu_id'
			";
		}
		//echo "<br>$save_sql";
		$save_result = mysqli_query($pubConn, $save_sql);
		echo mysqli_error($pubConn);
		//------------插入日志------------
		//insertLog(0,3,$save_sql,$user_info["account"]);
		insertLog($user_info["account"]);
		//------------
		//echo "$save_sql";
		if ($save_result > 0) {
			echo "<font color=\"#0000ff\" >$strSaveSuccess</font>";
		} else {
			echo mysqli_error($pubConn);
			echo "<font color=\"#ff0000\">$strSaveFailure</font>";
		}
	} //end if($save) 
	?>


	<script LANGUAGE="JavaScript">
		function select_db() {
			var base_url, url_add, url;
			base_url = '<?php echo "$PHP_SELF"; ?>?db_name=';
			url_add = document.dp_define.db_name.options[document.dp_define.db_name.selectedIndex].value;
			url = base_url + url_add;
			window.location = url;
		}

		function goto() {
			var base_url, url_add, url;
			base_url = '<?php echo "$PHP_SELF"; ?>?key_menu_id=';
			url_add = document.dp_define.type_list.options[document.dp_define.type_list.selectedIndex].value;
			url = base_url + url_add;
			window.location = url;
		}
	</script>
	<form method="POST" name=dp_define action="<?php echo "$PHP_SELF"; ?>">
		<table border="1" width="100%" cellpadding="2" cellspacing="0" bordercolor="#666666" bordercolordark="#FFFFFF" bgcolor="#FFFFFF">
			<tr bgcolor="#E6E6E6">
				<td width="100%" colspan="2">
					<p align="center"><b><?php echo "$strCSVDefine"; ?></b></p>
				</td>
			</tr>


			<tr>
				<td width="40%"><?php echo "$strExistedTemplateInquiry"; ?>
				</td>
				<td width="60%">


					<?php

					if (isset($key_menu_id) && $key_menu_id != 'new') {
						$sel_sql	= "SELECT * FROM $syscsvconf_table WHERE key_menu_id = '$key_menu_id'";
						$result		= mysqli_query($pubConn, $sel_sql);
						$sel_rows	= mysqli_fetch_array($result);
						$db_name	= $sel_rows[db_name];
						$table_name	= $sel_rows[table_name];
						$sys_type	= $sel_rows[sys_type];
						$sys_id		= $sel_rows[sys_id];
						$obj_id		= $sel_rows[obj_id];
						$if_enable	= $sel_rows[if_enable];
						$if_subsys	= $sel_rows[if_subsys];
						$can_download	= $sel_rows[can_download];
						$can_upload	= $sel_rows[can_upload];
						$description	= $sel_rows[description];
						$description_2	= $sel_rows[description_2];
						$where_find	= $sel_rows[where_find];
					}
					$type_sql = "SELECT * 
	FROM $syscsvconf_table 
	ORDER BY level_0,level_1,level_2,level_3
	";
					$type_result = @mysqli_query($pubConn, $type_sql);
					$type_rows = @mysqli_fetch_array($type_result);
					//显示选择参数类型下拉菜单
					echo " <select size=\"1\" name=\"type_list\" onChange=\"javascript:goto()\">";
					echo "<option value=\"new\">----------------------NEW--------------------</option>";
					do {
						echo "<option value=\"$type_rows[key_menu_id]\" ";
						if ($type_rows[key_menu_id] == $sel_rows[key_menu_id] && isset($type_rows[key_menu_id])) {
							echo "selected";
						}
						echo ">";
						if ($type_rows[level_3])
							echo "&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp|-- $type_rows[level_0].$type_rows[level_1].$type_rows[level_2].$type_rows[level_3]&nbsp&nbsp $type_rows[$show_menu_name] ";
						elseif ($type_rows[level_2])
							echo "&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp|-- $type_rows[level_0].$type_rows[level_1].$type_rows[level_2]&nbsp&nbsp $type_rows[$show_menu_name] ";
						elseif ($type_rows[level_1])
							echo "&nbsp&nbsp&nbsp&nbsp|-- $type_rows[level_0].$type_rows[level_1]&nbsp&nbsp $type_rows[$show_menu_name] ";
						elseif ($type_rows[level_0])
							echo "$type_rows[level_0].$type_rows[level_1]&nbsp&nbsp $type_rows[$show_menu_name] ";
						echo "</option>";
					} while ($type_rows = @mysqli_fetch_array($type_result));
					?>
					</select>
				</td>
			</tr>
			<tr bgcolor="#E6E6E6">
				<td width="40%"><?php echo "$strDatabase"; ?></td>
				<td width="60%"><input type="hidden" name="server_name" value="omc-0">
					<select size="1" name="db_name" onChange="javascript:select_db()">
						<?php

						$sel_db_list = mysqli_query($pubConn, "SHOW DATABASES");
						$sel_db_num = mysqli_num_rows($sel_db_list);
						$dbRows = mysqli_fetch_array($sel_db_list);
						for ($i = 0; $i < $sel_db_num; $i++) {
							//$sel_db_name = mysql_dbname($sel_db_list, $i);
							$sel_db_name = $dbRows[0];

							if ($sel_db_name == $db_name) {
								echo "<option value=\"$sel_db_name\" selected>$sel_db_name</option>";
							} else {
								echo "<option value=\"$sel_db_name\" >$sel_db_name</option>";
							}
						}

						?>
					</select>
				</td>
			</tr>
			<tr>
				<td width="40%"><?php echo "$strTable"; ?></td>
				<td width="60%"><select size="1" name="table_name">
						<?php
						// $sel_table_list = mysql_list_tables($db_name);
						// $sel_tables_num = @mysql_numrows($sel_table_list);
						if ($db_name) $dbConn = mysqli_connect($OMC_server[0]['host'], $OMC_server[0]['user'], $OMC_server[0]['password'], $db_name);
						$sel_table_list = mysqli_query($dbConn, "SHOW TABLES");
						$sel_tables_num = @mysqli_num_rows($sel_table_list);
						$tableRows = @mysqli_fetch_array($sel_table_list);
						echo "<option value=\"\" >  ------ </option>";
						for ($j = 0; $j < $sel_tables_num; $j++) {
							//	$sel_table_name = mysql_tablename($sel_table_list, $j);
							$sel_table_name = $tableRows[0];

							if ($sel_table_name == $table_name) {
								echo "<option value=\"$sel_table_name\" selected>$sel_table_name</option>";
							} else {
								echo "<option value=\"$sel_table_name\" >$sel_table_name</option>";
							}
						}

						?>
					</select>
				</td>
			</tr>

			<tr bgcolor="#E6E6E6">
				<td width="40%"><?php echo "$strSystemType"; ?></td>
				<td>
					<select name="sys_type">
						<?php
						$tmpSql = "SELECT * FROM $elementTable ORDER BY elementNo";
						//if($DEBUG) 
						//echo "<br>tmpSql = $tmpSql";
						//exit();
						$tmpResult = @mysqli_query($pubConn, $tmpSql);
						echo mysqli_error($pubConn);
						while ($tmpRow = mysqli_fetch_array($tmpResult)) {
							echo "<option value=\"$tmpRow[elementNo]\" ";
							if ($tmpRow[elementNo] == $sys_type && isset($sys_type)) {
								echo "selected";
								$menuTypeName = $tmpRow[elementName];
							}
							echo ">";
							echo "{$tmpRow[elementName]}";
							echo "</option>";
						}
						?>
						<!--
	<?php
	for ($i = 0; $i < sizeof($omcTypeArr); $i++) {
		echo "<option value=\"{$omcTypeArr[$i][typeNo]}\" ";
		if ($omcTypeArr[$i][typeNo] == $sys_type && isset($sys_type)) {
			echo "selected";
			$menuTypeName = $omcTypeArr[$i][name];
		}
		echo ">";
		echo "{$omcTypeArr[$i][name]}";
		echo "</option>";
	}
	?>
	-->
					</select>
				</td>
			</tr>
			<?php
			echo "<tr>";
			echo "<td width=\"20%\">$strEnableDaemon</td>";
			echo "<td width=\"80%\">";
			if ($if_enable == 1) {
				echo "Yes<input type=radio value=\"1\" name=\"if_enable\" checked> ";
				echo "No<input type=radio value=\"0\" name=\"if_enable\">";
			} else {
				echo "Yes<input type=radio value=\"1\" name=\"if_enable\"> ";
				echo "No<input type=radio value=\"0\" name=\"if_enable\" checked>";
			}
			echo "</td>";
			echo "</tr>";


			echo "<tr bgcolor=\"#E6E6E6\">";
			echo "<td width=\"20%\">Subsys parameter</td>";
			echo "<td width=\"80%\">";
			if ($if_subsys == 1) {
				echo "Yes<input type=radio value=\"1\" name=\"if_subsys\" checked> ";
				echo "No<input type=radio value=\"0\" name=\"if_subsys\">";
			} else {
				echo "Yes<input type=radio value=\"1\" name=\"if_subsys\"> ";
				echo "No<input type=radio value=\"0\" name=\"if_subsys\" checked>";
			}
			echo "</td>";
			echo "</tr>";
			?>

			<tr>
				<td width="40%"><?php echo "$strObjectID"; ?></td>
				<td width="60%">
					<input type="input" maxlength="10" name="obj_id" value="<?php echo $obj_id; ?>">(Only input when enable,<?php echo "$strExample"; ?>:0506020102)
				</td>
			</tr>

			<tr bgcolor="#E6E6E6">
				<td width="40%"><?php echo "$strSystemID"; ?></td>
				<td width="60%">
					<input type="input" name="sys_id" value="<?php echo $sys_id; ?>">(<?php echo "$strOnlyInputWhenParameter,$strExample"; ?>:MSC_0_0)
				</td>
			</tr>

			<td width="40%"><?php echo "$strDescription ($strPrimaryLanguage)"; ?>:</td>
			<td width="60%"> <input type="text" name="menu_name" size="20" maxlength="40" value="<?php echo "$sel_rows[menu_name]"; ?>"></td>
			</tr>
			<tr bgcolor="#E6E6E6">
				<td width="40%"><?php echo "$strDescription ($strSecondLanguage)"; ?>:</td>
				<td width="60%"> <input type="text" name="menu_name_2" size="20" maxlength="40" value="<?php echo "$sel_rows[menu_name_2]"; ?>"></td>
			</tr>
			<tr>
				<td width="40%"><?php echo $strTypeCode; ?>:</td>
				<td width="60%">
					<input type="text" name="level_0" maxLength=2 size="2" value="<?php if (isset($sel_rows[level_0])) echo "$sel_rows[level_0]";
																					else echo "0"; ?>">&#8226;
					<input type="text" name="level_1" maxLength=2 size="2" value="<?php if (isset($sel_rows[level_1])) echo "$sel_rows[level_1]";
																					else echo "0"; ?>">&#8226;
					<input type="text" name="level_2" maxLength=2 size="2" value="<?php if (isset($sel_rows[level_2])) echo "$sel_rows[level_2]";
																					else echo "0"; ?>">&#8226;
					<input type="text" name="level_3" maxLength=2 size="2" value="<?php if (isset($sel_rows[level_3])) echo "$sel_rows[level_3]";
																					else echo "0"; ?>">
			</tr>
			<tr bgcolor="#E6E6E6">
				<td width="40%"><?php echo "$strWhereCode"; ?>:</td>
				<td width="60%"><input type="text" name="where_find" size="60" value="<?php echo "$where_find"; ?>"></td>
			</tr>
			<tr>
				<td width="40%"><?php echo "$strLoadOutOrLoadIn"; ?>:</td>
				<td width="60%">
					<input type="checkbox" name="is_need_download" OnClick="if(this.checked) document.dp_define.can_download.value=1; else document.dp_define.can_download.value=0;" <?php if ($can_download > 0 || !isset($can_download)) echo "checked";
																																														echo ">$strLoadOut"; ?> <input type="hidden" name="can_download" value="<?php $can_download = isset($can_download) ? $can_download : 1;
																																																																																	echo "$can_download"; ?>">

					<input type="checkbox" name="is_need_upload" OnClick="if(this.checked) document.dp_define.can_upload.value=1; else document.dp_define.can_upload.value=0;" <?php if ($can_upload > 0 || !isset($can_upload)) echo "checked";
																																												echo ">$strLoadIn"; ?> <input type="hidden" name="can_upload" value="<?php $can_upload = isset($can_upload) ? $can_upload : 1;
																																																																													echo "$can_upload"; ?>">

				</td>
			</tr>
			<tr bgcolor="#E6E6E6">
				<td width="40%"><?php echo "$strDetailDescription($strPrimaryLanguage)"; ?>:</td>
				<td width="60%"><input type="text" name="description" size="40" value="<?php echo "$description"; ?>">&nbsp;&nbsp;&nbsp;
				</td>
			</tr>
			<tr bgcolor="#E6E6E6">
				<td width="40%"><?php echo "$strDetailDescription ($strSecondLanguage)"; ?>:</td>
				<td width="60%"><input type="text" name="description_2" size="40" value="<?php echo "$description_2"; ?>"></td>
			</tr>
		</table>



		<p><input type="submit" value="<?php echo "$strSave"; ?>" name="save">
			<input type="reset" value="<?php echo "$strCancel"; ?>" name="reset">
			<input type="submit" value="<?php echo "$strDeleteMode"; ?>" name="delete">
		</p>
		<input type="hidden" name=device_name value="<?php echo "$device_name"; ?>">
		<input type="hidden" name=key_menu_id value="<?php echo "$key_menu_id"; ?>">
	</form>
	<?php
	adjust_content_tail();
	?>
</body>

</html>