<?php
include("nocache.inc");
?>
<HTML>
<HEAD>
<?php
include("header.inc");
if (!isset($language))
    $language = "eng";
?>
<SCRIPT language="JavaScript" type="text/javascript">
<!--
    var oldvalue=0;

    function show_status(status)
    {
       	window.status=status;
        if (status != "")
        {
            alert(status);
        }
    }
    function submit_form(data)
    {
        if ( data.document.object_form.modified_data.value == '')
        {
            window.status="Save not needed";
            return(false);
        }
        else
            return(true);
    }
    function b4_change(data)
    {
        if ( data.value != '' )
            oldvalue=data.value;
        else
            oldvalue='';
    }
    function change_made(data)
    {
        var parm_string=this.document.object_form.modified_data.value;

        if (data.value == oldvalue)
            return;
        if ( data.value == '')
        {
            alert("You must enter valid value");
            data.value = oldvalue;
            data.focus();
            return;
        }
        else if ( data.value == oldvalue ) //no Change
            return;

        if ( parm_string == '' )
        {
            this.document.object_form.modified_data.value = data.name;
        }
        else
        {
            if (parm_string.search(data.name) == -1)
                this.document.object_form.modified_data.value += ","+data.name;
        }
    }
    function deletebss()
    {
        var answer=confirm("Are you confirm to delete BSS?");
        if (answer == true)
        {
            window.status="";
            window.parent.parent.location.href=
            "mydropbss.php?language=<?=$language?>" +
            "&bssid=<?=$bssid?>&ip=<?=$ip?>";
        }
        else if (answer == false)
        {
            window.status="Abort";
        }
    }
//-->
</SCRIPT>
<TITLE> New BSS </TITLE>
</HEAD>
<BODY onLoad='show_status("<?=$status?>")'>
<HR SIZE=1>

<?php
$status="";
if (!isset($bssid))
{
    echo "The required information for this page is invalid.<br>\n";
    echo "</BODY>\n</HTML>";
    exit();
}
/*
if (!$objectid)
    $objectid = "_NewBss";
*/
if (!$tablename)
    $tablename = "OMCR_BSSTABLE";


include("display_type.inc");
include("login_parm.inc");

//
// Translate the value to string
// e.g. AdminState=2 --> AdminState=Unlocked
//
function translate($input,$data)
{
    $found=0;
    if ($data)
    {
        $items=split("[,=]",$data);
        $no_of_items=count($items);
        for ($i=1;$i<$no_of_items;$i+=2) {
            if ( $data == $items[$i] ) {
                $found=$i;
                break;
            }
        }
        return($items[$found]);
    }
    else
        return($input);
}
$db = mysql_connect($hostname, $username, $password);
mysql_select_db($dbname,$db);

if (!isset($language))
	$language = "eng";
$sqlstring = "select Object_Name,Attribute_Name,Attribute_Type,Display_Type," .
             "${language}Display_Name, ${language}Lookup, ${language}Help_Text" .
	         " from OMCR_Meta_Table " .
             "where Display_Type<>0 AND Object_Name='" . substr($tablename,5) . "'";

//echo $sqlstring . "<BR>";
$result = mysql_query($sqlstring,$db) or
          die("Invalid query: $sqlstring\n" . mysqli_error($pubConn));
while ( $row = mysqli_fetch_row($result) )
{
    if ($row[3] == PUSH_BUTTON) //For action item in NMI
        list($act_object_name[], $act_attribute_name[], $act_attribute_type[],
            $act_display_type[], $act_display_name[], $act_lookup[],
            $act_help_text[]) = $row;
    else
        list($object_name[],$attribute_name[],$attribute_type[],$display_type[],
            $display_name[],$lookup[],$help_text[]) = $row;
}
$no_of_parms = count($attribute_name);

if ($no_of_parms == 0)
    return;

$sqlstring = "select " . join(",",$attribute_name) .
             " from $tablename where bssid=$bssid";

//echo $sqlstring . "<BR>";
$result = mysql_query($sqlstring,$db) or
          die("Invalid query: $sqlstring\n" . mysqli_error($pubConn));
$no_of_instance = mysqli_num_rows($result);

while ( $row = mysqli_fetch_row($result) )
{
    echo "<FORM action=bsstable_old.php name='object_form' method=post\n" .
         "onSubmit='return submit_form(this);'>";
    echo "<TABLE border=0 cellspacing=1 cellpadding=0 width=600>\n";
    $no_of_fields = count($row);
    for($i=0;$i<$no_of_fields;$i++)
    {
        if(!strcasecmp(mysql_field_name($result,$i),"objectid"))
        {
            printf("<U><FONT color=#C0C0C0 size=+3pt>=) %s</FONT></U>\n",
                   $row[$i]);
            break;
        }
    }

    for ($i=0; $i<$no_of_parms; $i++)
    {
        //printf("%s%s %s\n",$display_type[$i],$attribute_name[$i],$lookup[$i]);
        switch($display_type[$i])
        {
            case DO_NOT_DISPLAY:    //do not display
                $widget="";
                continue;
            case PULLDOWN_MENU:    //pulldown menu
                $widget="<SELECT size=1 name='" . $attribute_name[$i] .
                    "' onBlur='change_made(this.document.object_form." .
                    $attribute_name[$i] . ")'>";
                $existed=0;
                $menu_items=split("[,=]", $lookup[$i]);
                $no_of_menu_items=count($menu_items);
                for($j=0;$j<$no_of_menu_items;$j+=2) {
                    $widget.="<option value=" . $menu_items[$j+1];
                    if ($row[$i] == $j) {
                        $widget.=" selected>";
                        $existed=1;
                    } else
                        $widget.=">";
                    $widget.=$menu_items[$j] . "</option>\n";
                }
                $widget.="</SELECT>";
                break;
            case TEXTBOX:    //text box
                $widget="<INPUT type=text name=" . $attribute_name[$i] .
                    " size=20 value='" . $row[$i] .
                    "' onFocus='b4_change(this.document.object_form." .
                    $attribute_name[$i] .
                    ")' onBlur='change_made(this.document.object_form." .
                    $attribute_name[$i] . ")'>";
                break;
            case LABEL:    //label
                $widget=translate($row[$i],$lookup[$i]);
                break;
            case RADIO_BUTTON:    //radio button
                $widget="<INPUT type=radio name=" . $attribute_name .
                    " value='" . translate($row[$i],$lookup[$i]) . 
                    "' onBlur='change_made(this.document.object_form." .
                    $attribute_name[$i] . ")'>" .
                    $row[$i] .  "\n";
                break;
            case CHECKBOX:    //check box
                $widget="<INPUT type=checkbox name=" . $attribute_name[$i] .
                    " value=1" .  ($row[$i]? " CHECKED":" ") .
                    "onBlur='change_made(this.document.object_form." .
                    $attribute_name[$i] . ")'>";
                break;
            case TEXTAREA:    //text area
                $widget="<TEXTAREA name=" . $attribute_name[$i] .
                    " rows=4 cols=45 " .
                    "onBlur='change_made(this.document.object_form." .
                    $attribute_name[$i] . ")'>" . $row[$i] . "</TEXTAREA>";
                break;
        }

        printf("  <TR><TD title=\"%s\">%s</TD><TD>%s</TD></TR>\n",
            $help_text[$i], $display_name[$i], $widget);
    }
    echo "</TABLE>\n<BR>\n";
    echo "<INPUT type=\"submit\" value='Create' name='save'>\n";
    echo "<INPUT type='reset' value='Reset' name=reset>\n";
    $no_of_actions = count($act_attribute_name);

    echo "<INPUT type=hidden name='modified_data' value=''>\n";
    echo "<INPUT type=hidden name='bssid'         value=$bssid>\n";
    echo "<INPUT type=hidden name='objectid'      value=$objectid>\n";
    echo "<INPUT type=hidden name='tablename'     value=$tablename>\n";
    echo "<INPUT type=hidden name='language'      value=$language>\n";
    echo "</FORM>\n";
    echo "<HR size=1>\n";
}
?>
    <INPUT type=button value='Delete BSS' name=B7 class=chinese onClick='deletebss()'>

</BODY>
</HTML>
