<?php
 
 
 
class SelectBox extends Form_Element
 
{
 
 // description: Use with class_forms.php.
 
 //              Don't foget to select the id-column also in SQL-command.
 
 //              Show a selectbox with odbc-database-support.
 
 //              Show selectbox add id's and items to.
 
 //              Show selectbox filled with database-field-values.
 
 //              Show selectbox filled with hyperlinks to auto-jump to.
 
 // version:     1.4
 
 // history:     24-7-2003 release version 1.4
 
 // history:     7-8-2002 release version 1.0
 
 
 
 var $Connection;
 
 var $SQLQuery_items = "";
 
 var $SQLQuery_items_idcolnr = 1;
 
 var $ItemList = array();
 
 var $SQLQuery_selected = "";
 
 var $SQLQuery_selected_idcolnr = 1;
 
 var $SQLQuery_update;
 
 var $Selected = "";      // set selected item when no db available
 
 var $Hyperlinks = 0;
 
 var $Extra_URI_1 = "";
 
 var $Extra_URI_2 = "";
 
 var $ExtraProperties = "";
 
 
 
 // constructor (set form-element's name)
 
 function SelectBox($Name)
 
 {
 
  $this->Set_Element_Name($Name);
 
 }
 
 
 
 // show selectbox
 
 function Show()
 
 {
 
  // handle chosen input with db
 
  if (!empty($this->SQLQuery_update))
 
  {
 
   $result = odbc_exec($this->Connection,$this->SQLQuery_update);
 
  }
 
 
 
  // itemlist from db
 
  if ($this->SQLQuery_items != "")
 
  {
 
   $result = odbc_exec($this->Connection,$this->SQLQuery_items);
 
   $nrfields = odbc_num_fields($result);
 
   while(odbc_fetch_row($result))
 
   {
 
    // haal data per result-kolom
 
    for ($i = 1; $i <= $nrfields; $i++)
 
    {
 
     $showstring = odbc_result($result,$i);
 
     $id = odbc_result($result,$this->SQLQuery_items_idcolnr);
 
     $this->ItemList[$id] = $showstring;
 
    }
 
   }
 
  }
 
 
 
  // set selected value with a query (manual use: set $this->Selected to an id)
 
  if ($this->SQLQuery_selected != "")
 
  {
 
   $result = odbc_exec($this->Connection,$this->SQLQuery_selected);
 
   if (odbc_fetch_row($result))
 
   {
 
    $this->Selected = odbc_result($result,$this->SQLQuery_selected_idcolnr);
 
   }  
 
  }
 
 
 
  // show selectbox
 
  if ($this->Hyperlinks != 0) $OnChangeString = "OnChange=\"top.location.href='".$this->Extra_URI_1."'+this.options[this.selectedIndex].value+'".$this->Extra_URI_2."'\"";
 
  else $OnChangeString = "";
 
  print"<select name='".$this->Element_Name."' ".$OnChangeString." ".$this->ExtraProperties.">\n";
 
  reset($this->ItemList);
 
  // toon items als options via itemlist
 
  for ($i = 0; $i < count($this->ItemList); $i++)
 
  {
 
   print"<option value='".key($this->ItemList)."'";
 
   if (key($this->ItemList) == $this->Selected) print " selected";
 
   print ">".current($this->ItemList)."\n";
 
   next($this->ItemList);
 
  }
 
  print"</select>";
 
 }
 
 
 
 // add item manually
 
 function AddItem($Id,$ShowString)
 
 {
 
  $this->ItemList[$Id] = $ShowString;
 
 }
 
 
 
 // read a value
 
 function GetItem($Id)
 
 {
 
  print $this->ItemList[$Id];
 
 }
 
 
 
 // get number of items
 
 function ItemCount()
 
 {
 
  return count($this->ItemList);
 
 }
 
}
 
 
 
?>
 
 
 
 |