	<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" />
	
    <?php
	$idEvent = "ConfirmExhibitor";
	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>";


	$addExhibitor = $_POST["addExhibitor"];
	$ctr = 0;
	if ($addExhibitor == "Add Exhibitor") {		
		$companyName = $_POST["companyName"];
		//echo $companyName;
		$query = "select * from exhibitor_list where LOWER(companyName)=LOWER('$companyName')";
		//echo $query;
		if (mysql_num_rows(mysql_query($query)) > 0) {
			echo '
			Record sudah ada.
			';
		} else {
			$sql1 = "select labelType, labelName, designName from form_label, form_design where labelType='".$idEvent."' and labelID=labelParentID order by designORDER asc";
			//echo "<br>sql: ".$sql;
			if ($hasil1 = mysql_query($sql1)) {
				while ($data1 = mysql_fetch_array($hasil1)) {
					$ctr++;
					$labelName = $data1["labelName"];
					$designName = $data1["designName"];
					$$designName = $_POST[$designName];
					//echo "<br> $designName : ".$$designName;
				}
			}
			$query1 = "insert into exhibitor_list values (null, '".$companyName."') ";
			if ($hasil1 = mysql_query($query1)) {
				$idNext = mysql_insert_id();
				if ($hallNumber) {
					$designName = "hallNumber";
					InsertData($designName,"exhibitor_list_hallstand","",$idNext);
				}
				echo "<script>";
				echo "location.href = '?action=addProduct&id=".$idNext."'";
				echo "</script>";
			} else {
				echo "<script>";
				echo "location.href = ''";
				echo "</script>";
			}
		}
	} else if ($addExhibitor == "Update Data") {		
		$sql1 = "select labelType, labelName, designName from form_label, form_design where labelType='".$idEvent."' and labelID=labelParentID order by designORDER asc";
		//echo "<br>sql: ".$sql;
		if ($hasil1 = mysql_query($sql1)) {
			while ($data1 = mysql_fetch_array($hasil1)) {
				$ctr++;
				$labelName = $data1["labelName"];
				$designName = $data1["designName"];
				$$designName = $_POST[$designName];
				//echo "<br> $designName : ".$$designName;
				//var_dump($hallNumber);
			}
			$sql3 = "UPDATE exhibitor_list SET companyName='$companyName' WHERE  exhibitorID='$exhibitorID' ";
			//echo $query1;
			$sql4 = "exhibitor_list_hallstand";
			if ($hallNumber) {
				$delete = DeleteData("exhibitor_list_hallstand","to_exhibitor_id",$exhibitorID);
				if ($delete) {
					$designName = "hallNumber";
					InsertData($designName, "exhibitor_list_hallstand", "", $exhibitorID);
					echo "<script>";
					echo "location.href = '?action=addProduct&id=".$exhibitorID."'";
					echo "</script>";
				} else {
					echo 'Data Gagal diUpdate';
				}
			}
		}	
	} else {
		?>
        <h3>Add Exhibitor</h3>
        <form name="form" id="form" class="form" action="?action=addRecord" onsubmit="return validate(this)" method="post">
            <p>
                <?php
                $sql = "select * from form_label where labelType='$idEvent'";
                //echo "<br> sql".$sql; 
                if ($hasil = mysql_query($sql)) {		
                    while ($rec = mysql_fetch_array($hasil)) {
                        echo "<h2 class='h2-teasers'>".$rec["labelNameTitle"]."</h2>";
                        $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)) {
                                // Link ke Element
                                $sql4 = "select * from form_element, form_element_link, form_element_sub where elementID='".$rec2["element"]."' 
                                         and elementShow='1' and linkDesignID='".$rec2["designID"]."' and linkElementSubID=elementSubID";
                                // echo $sql4;
                                if($hasil4 = mysql_query($sql4)) {
                                    while ($rec4 = mysql_fetch_array($hasil4)) {
                                        $elementSubID = $rec4["elementSubID"];
                                        $elementSubName = $rec4["elementSubName"];
                                        $elementSubStat = $rec4["elementSubStat"];
                                        $elementName = $rec4["elementName"];
                                    }
                                }
                                // Link ke Element
                                //echo $elementSubStat;
                                if ($rec2["elementName"] != "hidden") {
                                    //echo "$designName : ".$$designName;
                                    echo '<tr valign="top" bgcolor="#e4e4e4">';
                                    echo '	<td style="background-color:#e4e4e4;">
                                                <strong>
                                                    '.$rec2["labelName"];
                                                    if ($rec2["labelNameEng"]) {
                                                        echo '
                                                        (<i>'.$rec2["labelNameEng"].'</i>)';
                                                    }
                                                echo '	
                                                </strong>													
                                            </td>';
                                    echo '	<td style="background-color:#e4e4e4;">';
                                            $inputName = $rec2["designName"];
                                            if ($elementName == "checkbox") $inputName .= "[]";

                                            if($rec2["elementShow"] == "1") {
                                                if($elementSubStat == "single") {
                                                    if ($elementName == "select") {
                                                        $opsi = '';
                                                        $sql3="select * from form_element_value where elementSubParentID=".$elementSubID." order by valueID ";
                                                        // echo $sql3;
                                                        if($hasil3 = mysql_query($sql3)) {
                                                            while ($rec3 = mysql_fetch_array($hasil3)) {
                                                                $elementSubParentID = $rec3["elementSubParentID"];
                                                                if ($opsi == '') {
                                                                    $opsi  = '<select style="height:33px;" name="'.$inputName.'" id="'.$inputName.'">';
                                                                    $opsi .= "	<option value = ''>- select (pilih) -</option>";
                                                                    if ($elementSubParentID == '1') {
                                                                        $opsi .= "	<option style='font-size:10px' value = '77'>Indonesia</option>";
                                                                        $opsi .= "	<option style='font-size:10px' value = '' disabled></option>";
                                                                    }
                                                                }
                                                                $opsi .= '<option style="font-size:10px" ';
                                                                //echo "<br>".$$designName;
                                                                if ($$rec2["designName"]==$rec3["valueID"]) $opsi .= ' selected ';
                                                                $opsi .= 'value = "'.$rec3["valueID"].'">'.$rec3["valueName"].'</option>';
                                                            }
                                                            if ($opsi != '') {
                                                                $opsi .= '</select>';
                                                                echo $opsi;
                                                                if ($elementSubParentID == '4') {
                                                                    echo '<p style="padding:0; margin:10px 0px 0px 0px"><strong>For other city, please specify (untuk kota lain, masukkan disini</strong>)</p>';
                                                                    echo '<textarea style="width:100%; font-size:15px" name="kota_propinsi_lain" id="kota_propinsi_lain" cols="'.$rec2["cols"].'" rows="'.$rec2["row"].'">'.$kota_propinsi_lain.'</textarea>';
                                                                }
                                                            }
                                                        }
                                                    } else {
                                                        $opsi = '';
                                                        $sql3 = "select * from form_element_link, form_element_sub, form_element_value
                                                                 where linkDesignID = '".$rec2["designID"]."' and linkElementSubID = elementSubID and
                                                                 elementSubID = elementSubParentID order by valueID";															
                                                        //where elementSubParentID=".$elementSubID." order by valueID ";
                                                        //	echo "<br> sql3: ".$sql3;
                                                        $ctr = 0;
                                                        $SubParent = "";
                                                        if($hasil3 = mysql_query($sql3)) {
                                                            while ($rec3 = mysql_fetch_array($hasil3)) {																	
                                                                if ($opsi == '' || $SubParent != $rec3["elementSubParentID"]) {
                                                                    if ($opsi == '') {
                                                                        $opsi = '
                                                                        <table width="100%" celpadding="0" celspacing="0" border="0"> 
                                                                        ';
                                                                    } 
                                                                    
                                                                    if ($rec3["elementSubParentID"] == 18) {
                                                                        //echo $rec3["elementSubDescription"];	
                                                                        if ($SubParent != '')
                                                                        $opsi .= '
                                                                            </tr>
                                                                            <tr>
                                                                                <td colspan="2" style="height:10px; font-size:1px; padding:3px; background-color:#e4e4e4;"></td>
                                                                            </tr>
                                                                        ';
                                                                        $opsi .= '
                                                                        <tr>
                                                                            <td colspan="2">
                                                                                <strong>'.$rec3["elementSubDescription"].'</strong>
                                                                            </td>
                                                                        </tr>
                                                                        <tr height="5px"><td></td></tr>
                                                                        ';
                                                                    }
                                                                    $SubParent = $rec3["elementSubParentID"];
                                                                    $opsi .= '
                                                                        <tr>
                                                                    ';
                                                                } else if ($ctr%2 == 0) {
                                                                    $opsi .= '
                                                                        </tr>
                                                                        <tr>
                                                                    ';
                                                                }
                                                                
                                                                $opsi .= '	
                                                                        <td width="2%" style="background-color:#e4e4e4; padding-top:0; padding-bottom:10px">
                                                                            <input ';
                                                                            //$dsName = $rec2["designName"];
                                                                            if ($elementName == "checkbox") {
                                                                                if ($rec2["designName"]=="hallNumber") {
                                                                                    //echo "<br>".$$rec2["designName"][0];
                                                                                    foreach ($$rec2["designName"] as &$value) {
                                                                                        $val = $value[1];
                                                                                        //echo "<br> val: ".$val."  valueID: ".$rec3["valueID"]; 
                                                                                        if ($val==$rec3["valueID"]) {
                                                                                            $opsi .= 'checked ';
                                                                                        }
                                                                                    }
                                                                                }
                                                                            } else {
                                                                                if ($$rec2["designName"]==$rec3["valueID"]) {
                                                                                    $opsi .= 'checked ';
                                                                                }
                                                                            }

                                                                            $opsi .= 'type="'.$elementName.'" id="'.$inputName.'" name="'.$inputName.'" ';
                                                                            
                                                                            if ($elementName == "checkbox") {
                                                                                $val = $rec3["elementSubParentID"]."-".$rec3["valueID"];
                                                                            } else {
                                                                                $val = $rec3["valueID"];
                                                                            }
                                                                            $opsi .= 'value="'.$val.'">
                                                                        </td>';
                                                                $opsi .= '	
                                                                        <td width="43%" style="background-color:#e4e4e4; padding-top:0; padding-bottom:10px">
                                                                            '.$rec3["valueName"];
                                                                            if ($rec3["elementSubParentID"] == 18) {
                                                                                $opsi .= '&nbsp; <input type="text" name="standNo_'.$rec3["valueID"].'" id="standNo_'.$rec3["valueID"].'" size="25">';	
                                                                            }																				
                                                                $opsi .= '	
                                                                        </td>
                                                                ';
                                                                $ctr++;    
                                                            }
                                                            if ($opsi != '') {
                                                                $opsi .= '		
                                                                        </tr>
                                                                    </table>';
                                                                echo $opsi;
                                                            }
                                                        }
                                                    }
                                                } else if($elementSubStat == "multiple") {
                                                    //echo "Element Name : ".$elementName;
                                                    
                                                    if ($elementName == "select") {
                                                        //echo "test";
                                                    } else {
                                                        $sql3="select * from $elementSubName ";
                                                        //echo $sql3;
                                                        if ($hasil3 = mysql_query($sql3)) {
                                                            $tabelContent = '';
                                                            $rows_count = mysql_num_rows($hasil3);							
                                                            // echo '<br>Nomor : '.$rows_count;
                                                            for($i=0; $i<$rows_count; $i++) {
                                                                $rec3 = mysql_fetch_row($hasil3);
                                                                if ($i==0) {
                                                                    $tabelContent = '
                                                                    <table width="100%" cellpadding="6" cellspacing="1" bgcolor="#CCCCCC">
                                                                        <tr bgcolor="#FFFFCC">
                                                                            <td></td>
                                                                    ';
                                                                } else {
                                                                    $inputType = '<input ';
                                                                    if ($$rec2["designName"]==$rec3[0]) $inputType .= ' checked ';
                                                                    $inputType .= ' type="'.$elementName.'" name="'.$inputName.'" value="'.$rec3[0].'">';
                                                                    
                                                                    $tabelContent .= '
                                                                        <tr bgcolor="#f8f3d3">
                                                                            <td align="center">'.$inputType.'</td>
                                                                    ';
                                                                }
                                                                for($r=0;$r<count($rec3)-1;$r++) {
                                                                    if ($r==0) {
                                                                        $tabelContent .= '
                                                                        <td	align="center">';
                                                                        if ($i==0) 
                                                                            $tabelContent .= '	
                                                                                <strong>ID</strong></td>';
                                                                        else {
                                                                            $tabelContent .= '	
                                                                                <strong>'.$i.'</strong></td>';
                                                                        }
                                                                    } else {
                                                                        //echo $rec3[$r];
                                                                        $tabelContent .= '
                                                                        <td>';
                                                                        if ($i==0) 
                                                                        $tabelContent .= '
                                                                            <strong>';
                                                                        $tabelContent .= 
                                                                                $rec3[$r];
                                                                        if ($i==0) 
                                                                        $tabelContent .= '
                                                                            </strong>';
                                                                        $tabelContent .= '
                                                                        </td>';
                                                                    }
                                                                }
                                                                $tabelContent .= '</tr>';
                                                            }
                                                            if ($tabelContent != '') {
                                                                $tabelContent .= '
                                                                    </table>';
                                                                echo $tabelContent;
                                                            }	
                                                        }
                                                    }
                                                }
                                            } else if($rec2["elementShow"] == "2") {
                                                $sql5 = "select * from form_element where elementID='".$rec2["element"]."' 
                                                         and elementShow='2' ";
                                                //echo $sql4;
                                                if($hasil5 = mysql_query($sql5)) {
                                                    while ($rec5 = mysql_fetch_array($hasil5)) {
                                                        $elementName = $rec5["elementName"];
                                                    }
                                                }	

                                                //echo "<br> elementName : ".$elementName."<br>"; 
                                                //echo "<br>designID : ". $rec2["designID"];
                                                if ($elementName == "textarea")	{
                                                    echo '<textarea style="width:100%; font-size:15px" name="'.$rec2["designName"].'" id="'.$rec2["designName"].'">'.$$rec2["designName"].'</textarea>';
                                                } else {
                                                    if ($rec2["designID"] == '7' || $rec2["designID"] == '13') {
                                                        
                                                        echo '
                                                        <div style="width:100%; display:block">
                                                            <div style="width:38%; margin-right:2%; display:inline-block; float:left">
                                                            ';
                                                                $sql7 = "select * from form_element_value where elementSubParentID = '5' and valueID <> '375'";
                                                                //echo "<br>sql7 : ".$sql7;
                                                                if ($hasil7 = mysql_query($sql7)) {
                                                                    $num_rows = mysql_num_rows($hasil7);
                                                                    //echo "<br> num_rows: ".$num_rows;
                                                                    if ($num_rows > 0) {
                                                                        $cekBox = "";
                                                                        if (${"kdNegara".$rec2["designID"]} == "Indonesia (62)")
                                                                            $cekBox = 'selected="selected" ';
                                                                        //echo "<br>cekBox: ".$cekBox;	
                                                                        echo '
                                                                        <select style="width:100%; height:33px;" name="kdNegara'.$rec2["designID"].'" id="kdNegara'.$rec2["designID"].'" class="decodeIt">';
                                                                        echo '
                                                                            <option value="">- select (pilih) -</option>
                                                                            <option '.$cekBox.' style="font-size:10px" value = "Indonesia (62)">Indonesia (62)</option>
                                                                            <option style="font-size:10px" value = "" disabled></option>
                                                                        ';
                                                                        
                                                                        while ($data7 = mysql_fetch_array($hasil7)) {
                                                                            echo '
                                                                            <option ';
                                                                            
                                                                            if (!$cekBox) {
                                                                                //echo "Test : ".${"kdNegara".$rec2["designID"]};
                                                                                if (${"kdNegara".$rec2["designID"]} == $data7["valueName"]) {
                                                                                    $cekBox = 'selected="selected" ';
                                                                                    echo $cekBox;
                                                                                }
                                                                            }
                                                                            echo 'style="font-size:10px" value="'.$data7["valueName"].'">';
                                                                            echo 	$data7["valueName"];
                                                                            echo '</option>';
                                                                        }
                                                                        echo '
                                                                        </select>
                                                                        ';
                                                                    }
                                                                }
                                                            echo '
                                                            </div>
                                                            <div style="width:60%; display:inline-block; float:left">
                                                                <input style="width:100%; height:33px;" class="decodeIt" type="'.$rec2["elementName"].'" name="'.$rec2["designName"].'" id="'.$rec2["designName"].'" max-size="'.$rec2["size"].'" value="'.$$rec2["designName"].'">
                                                            </div>
                                                        </div>
                                                        ';
                                                    } else {
                                                        echo '<input style="';
                                                        echo '<input style="';
                                                        if ($rec2["designID"] == '6')
                                                            echo 'width:20%;';
                                                        else 
                                                            echo 'width:100%;';
                                                        echo 'height:33px;" class="decodeIt" type="'.$rec2["elementName"].'" name="'.$rec2["designName"].'" id="'.$rec2["designName"].'" maxlength="'.$rec2["size"].'" size="'.$rec2["size"].'" value="'.$$rec2["designName"].'">';
                                                    }
                                                }
                                            }
                                    echo '	</td>';
                                    echo '</tr>';
                                }
                            }
                            echo '</table>';
                        }
                    }
                }									
                ?>
                <table width="100%" cellpadding="15" cellspacing="1" border="0">
                    <tr>
                        <td align="center">
                            <input type="submit" name="addExhibitor" id="addExhibitor" class="button" value="Add Exhibitor">								
                        </td>
                    </tr>
                </table>
            </p>
        </form>
        <?php
	}
	?>





