Location: PHPKode > projects > OpenCabling > opencabling/edit_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');

$object=$_REQUEST['object'];

if ($object=="") {
  print "<script lang=javascript>";
  print "object=top.left.document.getElementById('selobject');";
  print "selobject=object.value;";
  print "if (selobject=='') {";
  print "  selobject='null';";
  print "}";
  print "top.right.document.location.href='edit_object.php?object='+selobject;";
  print "</script>";
}
if ($object!="null") {
  print "<B>Edit Object definition</B>";
  $objsql="select * from objects,objtypes where id_object='$object' and obj_type=id_obj_type";
  $objquery=mysql_query($objsql,$mysql_conn);
  $objresult=mysql_fetch_assoc($objquery);
  print "<form name='choose' id='choose' action='create_object.php'>";
  print "<input type=hidden name='id_object' value=".$objresult['id_object']."></input>";
  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']."'";
    if ($objresult['brand']==$result['brand']) print "selected";
    print ">".$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)'>";
  $sql="select distinct category from objtypes where brand='".$objresult['brand']."' order by category";
  $query=mysql_query($sql,$mysql_conn);
  while ($result=mysql_fetch_assoc($query)) {
    print "<option value='".$result['category']."'";
    if ($objresult['category']==$result['category']) print "selected";
    print ">".$result['category']."</option>\n"; 
  }  print "</select></td></tr>";

  // Type
  print "<tr><td align=right><span class=normaltext>Type:</span></td>";
  print "<td><select name='obj_type'>";
  $sql="select distinct type,id_obj_type from objtypes where category='".$objresult['category']."' and brand='".$objresult['brand']."' order by type";
  $query=mysql_query($sql,$mysql_conn);
  while ($result=mysql_fetch_assoc($query)) {
    print "<option value='".$result['id_obj_type']."'";
    if ($objresult['type']==$result['type']) print "selected";
    print ">".$result['type']."</option>\n"; 
  }
  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>".$objresult['name']."</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>".$objresult['obj_description']."</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' value=\"".$objresult['obj_extravalues']."\"></input></td>";
  print "</tr>";
  print "<tr><td align=right><span class=normaltext>External Link URLs:</span></td>";
  print "<td><textarea rows=2 cols=25 name='obj_links' >".$objresult['obj_links']."</textarea></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=\"".$objresult['parent_obj']."\" 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=\"".$objresult['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 ($objresult['towards']=="F")
     print "CHECKED";
  print "><span class=normaltext>Front</span></input>";
  print "<input type=radio name=obj_towards value=\"B\" ";
  if ($objresult['towards']=="B")
     print "CHECKED";
  print "><span class=normaltext>Back Mount</span></input></td>";
  print "</tr>";
  print "<tr><td></td><td><input type=submit value='Save Object'></input></td></tr>";
  print "</table>";

  mysql_close($mysql_conn);

  if ($objresult['parent_obj']<>"") {
     echo "<script lang=javascript>ShowObjectName(\"parent_object_id\",\"parent_name\");</script>";
  }     
}
?>

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

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