Location: PHPKode > projects > OpenCabling > opencabling/search_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>

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');

$obj_type=$_REQUEST['obj_type'];
$obj_name=$_REQUEST['obj_name'];
$obj_description=$_REQUEST['obj_description'];
$brand=$_REQUEST['brand'];
$category=$_REQUEST['category'];
$order=$_REQUEST['order'];

if ($brand=="" && $category=="" && $obj_type=="" && $obj_name=="" && $obj_description=="" && $order=="") {

print "<B>Search object:</B>";

print "<form name='choose' id='choose' action='search_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></td><td><input type=submit name='action' value='Search Object'></input></td></tr>";
print "</table>";
}
else {

if ($brand=="Choose") $brand="";
if ($category=="Choose") $category="";
if ($obj_type=="Choose") $obj_type="";

$select="select * from objects,objtypes ";
$filter="where objtypes.id_obj_type=objects.obj_type";

if ($obj_type<>"") $filter=$filter." and type='".$obj_type."'";
if ($brand<>"") $filter=$filter." and brand='".$brand."'";
if ($category<>"") $filter=$filter." and category='".$category."'";
if ($obj_name<>"") $filter=$filter." and upper(name) like upper('%".$obj_name."%')";
if ($obj_description<>"") $filter=$filter." and upper(obj_description) like upper('%".$obj_description."%')";

$sql=$select.$filter;

if ($order!="") {
$sql=$sql." order by ".$order;
}

$query=mysql_query($sql,$mysql_conn);

$link="search_object.php?id_object=$id_object&brand=$brand&category=$category&type=$type&obj_name=".htmlentities($obj_name)."&obj_description=".htmlentities($obj_description);

echo "<table><tr class=smalltext>";
echo "<td><b><a href=\"".$link."&order=id_object\">ID</a></td>";
echo "<td><b><a href=\"".$link."&order=brand\">Brand</a></td>";
echo "<td><b><a href=\"".$link."&order=category\">Category</a></td>";
echo "<td><b><a href=\"".$link."&order=type\">Type</a></td>";
echo "<td><b><a href=\"".$link."&order=name\">Name</a></td>";
echo "<td><b><a href=\"".$link."&order=obj_description\">Description</td></tr>";

while ($result=mysql_fetch_assoc($query)) {
if ($bgcolor=='#aaaaaa')
     $bgcolor='#cccccc';
else
     $bgcolor='#aaaaaa';
echo "<tr bgcolor=$bgcolor class=smalltext>";
echo "<td><a href='javascript:select_obj(".$result['id_object'].")'>".$result['id_object']."</a></td>";
echo "<td><a href='javascript:select_obj(".$result['id_object'].")'>".$result['brand']."</a></td>";
echo "<td><a href='javascript:select_obj(".$result['id_object'].")'>".$result['category']."</a></td>";
echo "<td><a href='javascript:select_obj(".$result['id_object'].")'>".$result['type']."</a></td>";
echo "<td><a href='javascript:select_obj(".$result['id_object'].")'>".$result['name']."</a></td>";
echo "<td class=verysmalltext><a href='javascript:select_obj(".$result['id_object'].")'>".$result['obj_description']."</a></td>";
echo "</tr>";
}
echo "</table>";

//echo $sql;

}

mysql_close($mysql_conn);

?>

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

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