<?
########## Confixx(R) 3.0 Professional ############
####### Copyright SWsoft, Inc. 2004-2005 ##########
#### http://www.sw-soft.com - info@sw-soft.com ####

/*
  -------------------- Name conventions --------------------
  Function names (except methods):

  ff_DescriptionOfFunction


  Constant names:

  cc_DescriptionOfConstant


  Variable names:

  $ST_DescriptionOfVariable

  where S is a scope, T is a type.

  The following scopes should be used:
  g - global
  s - static
  l - local
  m - member of class
  p - parameter

  The following types should be used:
  s - scalar
  a - array
  r - resource
  o - object
  m - mixed

  -------------------- end Name conventions --------------------
*/





class ListColumn
{

    /* -------------------- Members -------------------- */
    var $ms_Label; // label that should be used for this column
    var $ms_Width; // width of column
    var $ms_Align; // align of column

    var $ms_Value; // value of column
    var $ms_Name; // name of column
    var $ms_ID; // identifier of row
    var $ma_Attributes; // attributes

    var $ms_Input; // if TRUE, then input is allowed in this column

    var $ms_Sortable; // if TRUE, then user can sort by this column
    /* -------------------- end Members -------------------- */





    /* -------------------- Constructor -------------------- */
    function ListColumn ( $ps_Name, $ps_Label, $ps_Value, $pa_Attributes=array(), $ps_Width=NULL, $ps_Align=NULL,
		$ps_ID=NULL )
    {
	$this->ms_Label = $ps_Label;
	$this->ms_Width = $ps_Width;
	$this->ms_Align = $ps_Align;

	$this->ms_Name = $ps_Name;
	$this->ms_Value = $ps_Value;
	$this->ms_ID = $ps_ID;
	$this->ma_Attributes = $pa_Attributes;

	$this->ms_Input = TRUE;
    }
    /* -------------------- end Constructor -------------------- */





    /* -------------------- Get... -------------------- */
    function GetLabel()
    {
	return $this->ms_Label;
    }

    function GetWidth()
    {
	return is_null( $this->ms_Width ) ? "" : "width=\"".$this->ms_Width."\"";
    }

    function GetAlign()
    {
	return is_null( $this->ms_Align ) ? "" : "align=\"".$this->ms_Align."\"";
    }

    function GetName()
    {
	$ls_ID = $this->GetID();
	return strlen($ls_ID) ? $this->ms_Name."[".$ls_ID."]" : $this->ms_Name;
    }

    function GetPureName()
    {
	return $this->ms_Name;
    }

    function GetValue()
    {
	return $this->ms_Value;
    }

    function GetID()
    {
	return $this->ms_ID;
    }

    function GetAttributesHTML()
    {
	$ls_Result = "";
	foreach ( $this->ma_Attributes as $ls_Key => $ls_Value )
	    $ls_Result .= " $ls_Key=\"" . $ls_Value . "\"";
	return $ls_Result;
    }

    function GetURLQuery()
    {
	return urlencode( $this->GetName() ) . "=" . urlencode( $this->GetValue() );
    }

    function GetInput()
    {
	return $this->ms_Input;
    }

    function GetSortable()
    {
	return $this->ms_Sortable;
    }
    /* -------------------- end Get... -------------------- */





    /* -------------------- Set... -------------------- */
    function SetValue( $ps_Value )
    {
	$this->ms_Value = $ps_Value;
    }

    function SetID ( $ps_ID )
    {
	$this->ms_ID = $ps_ID;
    }

    function SetFromArray ( $pa_Data, $ps_ID )
    {
	if ( ! is_null($this->ms_Name) )
	    $this->SetValue ( array_key_exists ( $this->ms_Name, $pa_Data ) ? $pa_Data[$this->ms_Name] : NULL );
	$this->SetID ( $ps_ID );
    }

    function SetFromPostGet ()
    {
	if ( ! is_null($this->ms_Name) )
	{
	    if ( $_SERVER["REQUEST_METHOD"]=="POST" && array_key_exists( $this->ms_Name, $_POST ) &&
		    strlen( $_POST[$this->ms_Name] ) )
		$this->ms_Value = $_POST[$this->ms_Name];
	    else
		$this->ms_Value = array_key_exists( $this->ms_Name, $_GET ) ? $_GET[$this->ms_Name] : NULL;
	}
    }

    function SetInput ( $ps_Input )
    {
	$this->ms_Input = $ps_Input;
    }

    function SetSortable ( $ps_Sortable )
    {
	$this->ms_Sortable = $ps_Sortable;
    }
    /* -------------------- end Set... -------------------- */





    /* -------------------- Is... -------------------- */
    function IsSetInQuery ()
    {
	if ( is_null($this->ms_Name) )
	    return FALSE;
	if ( $_SERVER["REQUEST_METHOD"]=="POST" && array_key_exists( $this->ms_Name, $_POST ) &&
		strlen( $_POST[$this->ms_Name] ) )
	    return TRUE;
	return array_key_exists ( $this->ms_Name, $_GET ) && strlen( $_GET[$this->ms_Name] );
    }
    /* -------------------- end Is... -------------------- */





    /* -------------------- "abstract" methods -------------------- */
    function GetHTML()
    {
	echo ( "method GetHTML should return HTML of column" );
    }
    /* -------------------- end "abstract" methods -------------------- */

}
?>
