	<script type="text/javascript" src="<?php echo $thisPage; ?>js/messages.js"></script>
	<link rel="stylesheet" type="text/css" href="<?php echo $thisPage; ?>css/messages.css" />
	<link rel="stylesheet" type="text/css" href="<?php echo $thisPage; ?>css/captcha.css" />

	<script>
	jQuery(document).ready(function() {
		//alert(jQuery('#idproduct').val());
		var button = '';
		jQuery('#image-container').html('');   
		jQuery.post(
			'listImage.php',{
				'idproduct':jQuery('#idproduct').val(),
				'id':jQuery('#id').val()
			}, function(data) {
				jQuery.each(data, function(index, value) {
				//alert (index);
				jQuery('#'+index).append('<img id-"' + index + '" src="' + value + '" width="200" border="0"><br> ');
				jQuery('#button-'+index).click(function() {
					jQuery.post(
						'deleteImage.php',{
							'imageID':index
						}
					);
					$('#button-'+index).remove();
				});
			}
		);
		},'json');
		

	});
    </script>        

    <?php
	$idEvent = "AddTransactionData";
	echo "<script>";
		echo "function validate(form) {";	
		$sql = "select designName from form_label, form_design where labelType='".$idEvent."' and labelID=labelParentID and validasi='YES' order by designORDER asc";
		//echo "<br> sql : ".$sql; 
		if ($hasil = mysql_query($sql)) {
			while ($rec = mysql_fetch_array($hasil)) {
				if ($rec["designName"] != "website") {
					echo "var ".$rec["designName"]." = form.".$rec["designName"].".value;";
					echo '
						if('.$rec["designName"].' == "") {
							inlineMsg("'.$rec["designName"].'","Field can not be empty.",2);
							return false;
					  	} else {
							var targetdiv = document.getElementById("'.$rec["designName"].'"); 
					  		targetdiv.style.backgroundColor = "white";
					  	}
					';	
				}
			}
		}	
		echo "
				return true;
			}
		";

	echo "</script>";
	
	$exhibitorID = $_POST["exhibitorID"];
	$tglNAMA = $_REQUEST["tglNAMA"];
	//echo "<br>exhibitorID: ".$exhibitorID;
	//echo "<br>tglNAMA: ".$tglNAMA;	
	//echo "<br>action: ".$action;
	$labelNameTitle = "";
	if ($action == "Add_Transaction_Header") {
		$labelNameTitle = "Insert New Data";
	} else if ($action == "Edit_Transaction_Header") {
		$labelNameTitle = "Update Existing Data";
	}
	
	$addProductData = $_POST["addProductData"];
	//echo "<br>addProductData: 	".$addProductData;
	$ctr = 0;
	if ($action == "Add_Transaction_Header" || $action == "Edit_Transaction_Header") {		
		$sql1 = "select designID, labelType, labelName, designName from 
				 form_label, form_design where 
				 labelType='".$idEvent."' and labelID=labelParentID 
				 order by designORDER asc";
		//echo "<br>sql: ".$sql1;
		$sql7 = '';
		$nmDB = "kontak_dagang_header";
		if ($hasil1 = mysql_query($sql1)) {
			while ($data1 = mysql_fetch_array($hasil1)) {
				$labelName = $data1["labelName"];
				$designName = $data1["designName"];
				$$designName = $_POST[$designName];

				if (!$sql7) {
					if ($action == "Add_Transaction_Header") {
						$sql7 = "INSERT INTO ".$nmDB." values(null, '".$exhibitorID."', '".$tglNAMA."' ";
					} else if ($action == "Edit_Transaction_Header") {
						$sql7 = "UPDATE ".$nmDB." set ";
					}
				} else {
					if ($action == "Edit_Transaction_Header") {
						$sql7 .= ", ";
					}
				}
				
				if ($action == "Add_Transaction_Header") {
					if ($$designName) {
						$sql7 .= ", '".$$designName."'";
					} else {
						$sql7 .= ", 0";
					}
				} else if ($action == "Edit_Transaction_Header") {
					if ($$designName) {
						$sql7 .= "$designName = '".$$designName."' ";
					} else {
						$sql7 .= "$designName = 0 ";
					}
				}
			}
			if ($action == "Add_Transaction_Header") {
				$sql7 .= ")";
			} else if ($action == "Edit_Transaction_Header") {
				$sql7 .= "WHERE kd_header_id = '".$kd_header_id."' ";
			}
		}
		//echo "<br><br>".$sql7."<br>";

		
		if ($result = mysql_query($sql7)) {
			echo '<script>';
			echo 'location.href="'.$thisPage.'adm1n/pages/input-transaksi/?action=addProduct&id='.$id.'"';
			echo '</script>';
		} else {
			die('<br>Invalid query: ' . mysql_error());
		}
	} else {		
		//echo "test";
		require_once ($thisUrl.'functions/form_creator.php');
		?>
        <br />
        <form name="form" id="form" method="post" class="form" action="" enctype="multipart/form-data" onsubmit="return validate(this)">
			<?php
			$sql = "select * from form_label where labelType='$idEvent'";
            //echo "<br> sql".$sql; 
            if ($hasil = mysql_query($sql)) {		
                while ($rec = mysql_fetch_array($hasil)) {
                    if ($rec["labelNameTitle"]) {
						echo "<h4 class='h4-teasers'>".$labelNameTitle."</h4>";
					}
					$sql2 = "select * from form_design, form_element where elementID = element AND labelParentID = ".$rec["labelID"]." order by designORDER asc";
                    // echo $sql2;
                    if ($hasil2 = mysql_query($sql2)) {
                        echo '
						<table width="100%" cellpadding="10" cellspacing="1" border="0" bgcolor="#999999">';
                        while ($rec2 = mysql_fetch_array($hasil2)) {
							$sql3 = "SELECT * FROM exhibitor_list_products WHERE listProductID = '$idproduct' ";
							if ($hasil3 = mysql_query($sql3)) {		
								while ($data3 = mysql_fetch_array($hasil3)) {
									${$rec2["designName"]} = $data3[$rec2["designName"]];
									//echo "<br>".$rec2["designName"]." : ".${$rec2["designName"]};
								}
							}
							echo '
							<tr valign="top" bgcolor="#e4e4e4">
								<td width="28%" style="background-color:#e4e4e4;">
									<strong>'
										.$rec2["labelName"].'<br>'
										.($rec2["labelNameEng"] ? '(<i>'.$rec2["labelNameEng"].'</i>)' : '').'	
									</strong>
								</td>';
                                echo '
								<td style="background-color:#e4e4e4;">
									'.$rec2["elementName"]($rec["labelID"], $rec2["designID"], 0, "form_design", "form_element", "elementID", "element", "labelParentID", "designID").'
									'.extention($rec2["designID"]).'
									'.others($rec2["designID"]).'
								</td>
							</tr>';
						}
						if ($action == "Insert Transaction") {
							$btnProductData = "Update Data";
						} else {
							$btnProductData = "Save Data";
						}
					    echo '
							<tr valign="top" bgcolor="#e4e4e4">
								<td align="center" colspan="2">
									<div style="margin:20px 0px" align="center">
										<input type="hidden" name="action" id="action" value="addProduct" />
										<input type="hidden" name="addProduct" id="addProduct" value="Manage Products">
										<input type="hidden" name="id" id="id" value="'.$id.'" />
										<input type="hidden" name="idproduct" id="idproduct" value="'.$idproduct.'" />
										<input type="submit" name="addProductData" id="addProductData" class="button" value="'.$btnProductData.'">
									</div>
								</td>
							</tr>
						</table>
						<br><br>';
					}
                }
            }									
            ?>
        </form>
        <?php
	}
	?>