<?
// Class Listbox V 1.0
// Created by DejiTaru
// 16 october 2005
// email: hide@address.com
// Email me please!!
//
class classListbox
{
var $LB_query;
var $LB_name;
var $LB_primary_key;
var $listBox;
var $LB_selectedItemValue;
var $LB_selectedItemKey;
var $LB_postback;
var $LB_getback;
function classListbox($pName)
{
$this->listBox="";
$this->LB_name=$pName;
$this->LB_selectedItemValue='';
$this->LB_selectedItemKey='';
}
function set_selectedItemValue($pItem)
{
$this->LB_selectedItemValue=$pItem;
}
function set_selectedItemKey($pItem)
{
$this->LB_selectedItemKey=$pItem;
}
function get_selectedItemValue()
{
return $this->LB_selectedItemValue;
}
function get_selectedItemKey(){
return $this->LB_selectedItemKey;
}
function set_query($pSQLquery,$pPrimaryKey)
{
$this->LB_query=$pSQLquery;
$this->LB_primary_key=$pPrimaryKey;
}
function set_postback($pBool){
$this->LB_postback=$pBool;
}
function set_getback($pBool){
$this->LB_getback=$pBool;
}
function display_checked()
{
$SQLresult=mysql_query($this->LB_query);
if(!empty($_GET[$this->LB_name])){
$this->set_selectedItemKey($_GET[$this->LB_name]);
}
$rowCount=0;
while($row=mysql_fetch_array($SQLresult)){
if ($row[0] == 'unchecked') {
$listBox = "<INPUT type = checkbox onchange='this.form.submit()' name='alertid' value = '".$row[$this->LB_primary_key]."'>\n";
} elseif ($row[0] == 'checked') {
$listBox = "<INPUT type = checkbox onchange='this.form.submit()' name='alertid' value = '".$row[$this->LB_primary_key]."' CHECKED>\n";
}
$listBox.="<INPUT type = 'hidden' name='check' value = '$row[0]'>";
$rowCount++;
}
echo $listBox;
}
function display()
{
$SQLresult=mysql_query($this->LB_query);
//user change selected item
if(!empty($_GET[$this->LB_name])){
$this->set_selectedItemKey($_GET[$this->LB_name]);
$listBox="<select class='input' name='".$this->LB_name."' class='lbStyle'";
if($this->LB_getback=="true")
$listBox.="onchange='this.form.submit()'>";
$listBox.="<option class='input' value='null'>All $this->LB_name</option>";
} else {
$listBox="<select class='input' name='".$this->LB_name."' class='lbStyle'";
if($this->LB_getback=="true")
$listBox.="onchange='this.form.submit()'>";
$listBox.="<option class='input' value='null' selected>All $this->LB_name</option>";
}
$rowCount=0;
if($this->LB_getback=="true")
$listBox.="onchange='this.form.submit()'";
$listBox.=">";
$rowCount=0;
while($row=mysql_fetch_array($SQLresult)){
$listBox.="<option class='input' value='".$row[$this->LB_primary_key]."' ";
if($rowCount==0 | $this->get_selectedItemKey()==$row[$this->LB_primary_key]){
if($this->get_selectedItemKey()==''){
$this->set_selectedItemKey($row[$this->LB_primary_key]);
}
if($this->get_selectedItemValue()=='' & $this->get_selectedItemKey()==$row[$this->LB_primary_key]){
$this->set_selectedItemValue($row[0]);
}
}
if ($row[0]==$this->get_selectedItemValue() && !empty($_GET[$this->LB_name]) ){
$this->set_selectedItemKey($row[$this->LB_primary_key]);
$listBox.="selected ";
}
$listBox.=">".$row[0]."</option>";
$rowCount++;
}
$listBox.="</select>";
echo $listBox;
}
}
?>