Location: PHPKode > projects > OpenCabling > opencabling/new_object.php
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"></meta>
<link rel="stylesheet" href="css/opencabling.css" type="text/css"></link>

<?php
        require_once 'js/functions.js';
        require_once 'phplayersmenu.inc.php';
        $mid->printHeader();
        include "opendb.php";
?>

<script language="javascript">

function setCategory() {
  form=document.getElementById('choose');
  brandindex=form.brand.selectedIndex;
  brand=form.brand.options[brandindex].value;
  form.category.options.length=0;
  form.obj_type.options.length=0;
  <?php
  $sql="select distinct brand,category from objtypes order by brand,category";
  $query=mysql_query($sql,$mysql_conn);
  $oldbrand="";
  while ($result=mysql_fetch_assoc($query)) {
    $brand=$result['brand'];
    $category=$result['category'];
    if ($brand!=$oldbrand) {
      if ($oldbrand<>"") {
	print "  }\n";
      }
      $oldbrand=$brand;
      print "  if (brand == '$brand') {\n";
      print "    form.category.options[0]= new Option('Choose','Choose');\n";
      $i=1;
    }
    print "    form.category.options[$i]= new Option('$category','$category');\n";
    $i++;
    
  }
  ?>
  }
form.category.selectedIndex=0;
}

function setType() {
  form=document.getElementById('choose');
  brandindex=form.brand.selectedIndex;
  brand=form.brand.options[brandindex].value;
  categoryindex=form.category.selectedIndex;
  category=form.category.options[categoryindex].value;
  form.obj_type.options.length=0;

  <?php
  $sql="select id_obj_type,brand,category,type from objtypes order by brand,category,type";
  $query=mysql_query($sql,$mysql_conn);
  $oldbrand="";
  $oldcategory="";
  while ($result=mysql_fetch_assoc($query)) {
    $brand=$result['brand'];
    $category=$result['category'];
    $type=$result['type'];
    $id_obj_type=$result['id_obj_type'];
    if ($brand!=$oldbrand || $category!=$oldcategory) {
      if ($oldbrand<>"") {
	print "  }\n";
      }
      $oldbrand=$brand;
      $oldcategory=$category;
      print "  if (brand == '$brand' && category == '$category') {\n";
      print "    form.obj_type.options[0]= new Option('Choose','Choose');\n";
      $i=1;
    }
    print "    form.obj_type.options[$i]= new Option('$type','$id_obj_type');\n";
    $i++;
  }
    ?>
  }
form.obj_type.selectedIndex=0;
}

</script>

</head>
<body>
<?php

$mid->printMenu('hormenu1');

print "<B>New Object definition</B>";

$parent_object=$_REQUEST['parent_object'];
$position=$_REQUEST['position'];
$towards=$_REQUEST['towards'];

print "<form name='choose' id='choose' action='create_object.php'>";
print "<br>";
print "<table border=0>";

// Brand
print "<tr><td align=right><span class=normaltext>Brand:</span></td>";
print "<td><select name='brand' onChange='setCategory()'>\n";
print "<option value='Choose'>Choose</option>\n";
$sql="select distinct brand from objtypes order by brand";
$query=mysql_query($sql,$mysql_conn);
while ($result=mysql_fetch_assoc($query)) {
  print "<option value='".$result['brand']."'>".$result['brand']."</option>\n";
}
print "</select></td></tr>";

// Category
print "<tr><td align=right><span class=normaltext>Category:</span></td>";
print "<td><select name='category' onChange='setType($maxtype)'>";
print "</select></td></tr>";

// Type
print "<tr><td align=right><span class=normaltext>Type:</span></td>";
print "<td><select name='obj_type'>";
print "</select></td></tr>";

print "<tr><td align=right><span class=normaltext>Name:</span></td>";
print "<td><textarea name='obj_name' rows=2 cols=25></textarea></td>";
print "</tr>";
print "<tr><td align=right><span class=normaltext>Description:</span></td>";
print "<td><textarea name='obj_description' rows=4 cols=25></textarea></td>";
print "</tr>";
print "<tr><td align=right><span class=normaltext>Extra values:</span></td>";
print "<td><input type=text size=20 name='obj_extravalues'></input></td>";
print "</tr>";
print "<tr><td align=right><span class=normaltext>Inside object:</span></td>";
print "<td><input type=text size=5 name=parent_object_id id='parent_object_id' value=\"$parent_object\" onchange='ShowObjectName(\"parent_object_id\",\"parent_name\")'></input>";
print "<input type=text readonly name=parent_name id='parent_name'></input></td>";
print "<td><button onClick='ChooseObject(\"parent_object_id\",\"parent_name\")' type='button'>Browse</button></td>";
print "</tr>";
print "<tr><td align=right><span class=normaltext>Position:</span></td>";
print "<td><input type=text name=obj_position value=\"$position\"></input></td>";
print "</tr>";
print "<tr><td align=right><span class=normaltext>Towards:</span></td>";
print "<td><input type=radio name=obj_towards value=\"F\" ";
if ($towards=="F")
     print "CHECKED";
print "><span class=normaltext>Front</span></input>";
print "<input type=radio name=obj_towards value=\"B\" ";
if ($towards=="B")
     print "CHECKED";
print "><span class=normaltext>Back Mount</span></input></td>";
print "</tr>";
print "<tr><td></td><td><input type=submit name='action' value='Create Object'></input></td></tr>";
print "</table>";

mysql_close($mysql_conn);

if ($parent_object<>"") {
     echo "<script lang=javascript>ShowObjectName(\"parent_object_id\",\"parent_name\");</script>";
}     
?>

<?php
$mid->printFooter();
?>

</body>
</html>
Return current item: OpenCabling