section var $add_extra; ## Call extra cell functions var $map_cols; ## remap database columns to new names #========================================================================== ## Public functions #========================================================================== #========================================================================== ## Page functions #========================================================================== #========================================================================== # Function : start #-------------------------------------------------------------------------- # Purpose : Starts the display of a two-dimensional array in an HTML table # format. # Arguments: $ary - The 2D array to display. # $class - [optional] Used for CSS control. # Returns : The number of rows displayed. # Comments : See function: show # History : #========================================================================== function start($ary, $class="") { return ($this->show($ary, $class)); } #========================================================================== # Function : start_result #-------------------------------------------------------------------------- # Purpose : Starts the display of a database query result in an HTML table # format. # Arguments: $db - The database result. # $class - [optional] Used for CSS control. # Returns : The number of rows displayed. # Comments : See function: show_result # History : #========================================================================== function start_result($db, $class="") { return ($this->show_result($db, $class)); } #========================================================================== # Function : show #-------------------------------------------------------------------------- # Purpose : Starts the display of a two-dimensional array in an HTML table # format. # Arguments: $ary - The 2D array to diaplay. # $class - [optional] Used for CSS control. # Returns : The number of rows displayed. # Comments : # History : 990616 - removed redundant code.(JSG) #========================================================================== function show($ary, $class="") { global $debug; if (!$this->verify_2d_array($ary)) return 0; $rows = 0; $this->table_open($class); if ($this->show_table_heading_row($ary, $class)) $rows = $this->show_table_rows($ary, $class); $this->table_close($class); return $rows; } #========================================================================== # Function : show_result #-------------------------------------------------------------------------- # Purpose : Starts the display of a database query result in an HTML table # format. # Arguments: $db - The database result. # $class - [optional] Used for CSS control. # Returns : The number of rows displayed. # Comments : # History : #========================================================================== function show_result($db, $class="") { if (!$this->verify_db($db)) return 0; $rows = 0; $this->table_open($class); if ($this->show_table_heading_row_result($db, $class)) $rows = $this->show_table_rows_result($db, $class); $this->table_close($class); return $rows; } #========================================================================== # Function : show_page #-------------------------------------------------------------------------- # Purpose : Starts the display of a two-dimensional array in an HTML table # format. Only the rows $start to $start+$num are displayed. # Arguments: $ary - The 2D array to diaplay. # $start - The starting row to display. # $num - The number of rows to display. # $class - [optional] Used for CSS control. # Returns : The number of rows displayed. # Comments : # History : #========================================================================== function show_page($ary, $start, $num, $class ="") { global $debug; if (!$this->verify_2d_array($ary)) return 0; $rows = 0; $this->table_open($class); if ($this->show_table_heading_row($ary, $class)) $rows = $this->show_table_page_rows($ary, $start, $num, $class=""); $this->table_close($class); return $rows; } #========================================================================== # Function : show_result_page #-------------------------------------------------------------------------- # Purpose : Starts the display of a database object in an HTML table # format. Only the rows $start to $start+$num are displayed. # Arguments: $db - The database result. # $start - The starting row to display. # $num - The number of rows to display. # $class - [optional] Used for CSS control. # Returns : The number of rows displayed. # Comments : # History : #========================================================================== function show_result_page($db, $start, $num, $class="") { global $debug; if (!$this->verify_db($db)) return 0; $rows = 0; $this->table_open($class); if ($this->show_table_heading_row_result($db, $class)) $rows = $this->show_table_page_rows_result($db, $start, $num, $class); $this->table_close($class); return $rows; } #========================================================================== ## Row functions #========================================================================== #========================================================================== # Function : show_table_heading_row #-------------------------------------------------------------------------- # Purpose : Uses the passed array to create an HTML header row. # Arguments: $ary - The array to use. # $class - [optional] Used for CSS control. # Returns : 1 on success, 0 on error. # Comments : # History : #========================================================================== function show_table_heading_row($ary, $class="") { if (!$this->verify_2d_array($ary)) return 0; if (isset($this->heading) && $this->heading) { reset($ary); list($key, $val) = each($ary); $this->table_heading_row($val, $class); } return 1; } #========================================================================== # Function : show_table_heading_row_result #-------------------------------------------------------------------------- # Purpose : Uses the passed database object to create an HTML header row. # Arguments: $db - The database object # $class - [optional] Used for CSS control. # Returns : 1 on success, 0 on error. # Comments : # History : #========================================================================== function show_table_heading_row_result($db, $class="") { if (!$this->verify_db($db)) return 0; if ($this->heading) { // (Jeff) ------------------------------ // if ($db->num_rows() > 0 && $db->next_record()) // rows are confirmed in $this->verify_db(), so no need to reverify // ------------------------------------- if ($db->next_record()) { $this->table_heading_row($db->Record, $class); $db->seek($db->Row-1); return 1; } else { // (Jeff) ------------------------------ // Shouldn't do this! Breaks modularity! // Call: table_close() instead from // calling function. Comments to // be removed in next release. // ------------------------------------- // $this->table_close($class); // ------------------------------------- return 0; } } return 1; } #========================================================================== # Function : table_heading_row #-------------------------------------------------------------------------- # Purpose : Outputs HTML code to create a table heading row. # Arguments: $data - The array of data that represents cells within a row. # $class - [optional] Used for CSS control. # Returns : # Comments : # History : 990618 - Fixed return on select_colnames (JSG). #========================================================================== function table_heading_row($data, $class="") { if (!is_array($data)) return; $d = $this->select_colnames($data); $this->table_row_open($row, $d, $class); $this->set_checkbox_heading($class); $this->show_table_heading_cells($data, $class); # call virtual function if ($this->add_extra) $this->table_heading_row_add_extra($data, $class); $this->table_row_close(0, $class); } #========================================================================== # Function : show_table_rows #-------------------------------------------------------------------------- # Purpose : Walks the passed array displaying each row of data as an HTML # table row. # Arguments: $ary - The array of data to display. # $class - [optional] Used for CSS control. # Returns : # Comments : # History : #========================================================================== function show_table_rows($ary, $class="") { global $debug; if ($debug) printf("
show_table_rows()
\n");
if (!$this->verify_2d_array($ary))
return 0;
$row = 0;
reset($ary);
while(list($key, $val) = each($ary))
{
## Process a single row
$this->table_row($row++, $key, $val, $class);
}
return $row;
}
#==========================================================================
# Function : show_table_rows_result
#--------------------------------------------------------------------------
# Purpose : Walks the passed database object displaying each record as an
# HTML table row.
# Arguments: $db - The database object
# $class - [optional] Used for CSS control.
# Returns :
# Comments :
# History : 990617 - fixed return. Was "row" changed to "$row".
#==========================================================================
function show_table_rows_result($db, $class="")
{
global $debug;
if ($debug)
printf("
show_table_rows_result()
\n");
if (!$this->verify_db($db))
return 0;
$row = 0;
while($db->next_record())
{
## Process a table row
$this->table_row($row, $row, $db->Record, $class);
$row++;
}
return $row;
}
#==========================================================================
# Function : show_table_page_rows
#--------------------------------------------------------------------------
# Purpose : Walks the passed array displaying each row of data as an HTML
# table row. However, data does not start displaying until
# $start element and end after $num rows.
# Arguments: $ary - The array object.
# $start - Start row displaying at this element.
# $num - The number of rows to display.
# $class - [optional] Used for CSS control.
# Returns :
# Comments :
# History : 990616 - $row was incrementing (++) in for loop and within
# the table_row function call.
#==========================================================================
function show_table_page_rows($ary, $start, $num, $class="")
{
global $debug;
if ($debug)
printf("
show_table_page_rows()
\n");
if (!$this->verify_2d_array($ary))
return 0;
$row = 0;
$max = count($ary);
if (($start < 0 ) || ($start > $max))
return 0;
$max = min($start+$num, $max);
for ($row = $start; $row < $max; $row++)
{
## Process a single row
$this->table_row($row, $key, $val, $class);
}
return ($row - $start);
}
#==========================================================================
# Function : show_table_page_rows_result
#--------------------------------------------------------------------------
# Purpose : Walks the passed database object displaying each record as an
# HTML table row. However, data does not start displaying until
# $start record and ends after $num records have been displayed.
# Arguments: $db - The database object.
# $start - Start row displaying at this record.
# $num - The number of rows to display.
# $class - [optional] Used for CSS control.
# Returns : The number of rows displayed
# Comments :
# History :
#==========================================================================
function show_table_page_rows_result($db, $start, $num, $class="")
{
global $debug;
if ($debug)
printf("
show_table_page_rows_result()
\n");
if (!$this->verify_db($db))
return 0;
$row = $start;
$fin = $start + $num;
$db->seek($start);
while($db->next_record() && ($row < $fin))
{
## Process a table row
$this->table_row($row, $row, $db->Record, $class);
$row++;
}
return ($row - $start);
}
#==========================================================================
# Function : table_row
#--------------------------------------------------------------------------
# Purpose : Outputs HTML code to create a table row. Calls all of the
# cell-related functions.
# Arguments: $row -
# $row_key -
# $data - The array of data that represents cells within a row.
# $class - [optional] Used for CSS control.
# Returns :
# Comments :
# History :
#==========================================================================
function table_row($row, $row_key, $data, $class="")
{
global $debug;
if ($debug)
printf("
table_row()
\n");
$d = $this->select_colnames($data);
$this->table_row_open($row, $d, $class);
$this->set_checkbox($row, $row_key, $data, $class);
$this->show_table_cells($row, $row_key, $data, $class);
# call virtual function
if ($this->add_extra)
$this->table_row_add_extra($row, $row_key, $data, $class);
$this->table_row_close($row, $class);
}
#==========================================================================
## Field/Cell functions
#==========================================================================
#==========================================================================
# Function : set_checkbox_heading
#--------------------------------------------------------------------------
# Purpose : This function creates an empty header cell to coincide with
# the checkbox option for that column.
# Arguments: $class - [optional] Used for CSS control.
# Returns :
# Comments :
# History :
#==========================================================================
function set_checkbox_heading($class="")
{
global $debug;
if ($debug)
printf("
set_checkbox_heading()
\n");
## Checkbox handling...
if ($this->check)
$this->table_heading_cell(0, " ", $class);
}
#==========================================================================
# Function : set_checkbox
#--------------------------------------------------------------------------
# Purpose : Creates an HTML checkbox based on the passed data, only if
# the member variable $check is set.
# Arguments: $row - The row number.
# $row_key - The row key.
# $data - The data array.
# $class - [optional] Used for CSS control.
# Returns :
# Comments :
# History :
#==========================================================================
function set_checkbox($row, $row_key, $data, $class="")
{
global $debug;
if ($debug)
printf("
set_checkbox()
\n");
## Checkbox handling...
if ($this->check)
$this->table_checkbox_cell($row, $row_key, $data, $class);
}
#==========================================================================
# Function : show_table_heading_cells
#--------------------------------------------------------------------------
# Purpose : Walks the passed array and displays each item in an HTML table
# header cell.
# Arguments: $data - The data array.
# $class - [optional] Used for CSS control.
# Returns : 1 on success, 0 on error.
# Comments :
# History : 990618 - Fixed problem with filtering headers (JSG).
#==========================================================================
function show_table_heading_cells($data, $class="")
{
global $debug;
if ($debug)
printf("
show_table_heading_cells()
\n");
if (!$this->verify_array($data))
return 0;
$cell = 0;
$d = $this->select_colnames($data);
## Create regular cells
reset($d);
while(list($key, $val) = each($d))
{
$this->table_heading_cell($col++, $val, $class);
}
return 1;
}
#==========================================================================
# Function : show_table_cells
#--------------------------------------------------------------------------
# Purpose : Walks the passed array and displays each item in an HTML table
# cell.
# Arguments: $row - The row number.
# $row_key - The row key. [for derived classes]
# $data - The data array.
# $class - [optional] Used for CSS control.
# Returns : 1 on success, 0 on error.
# Comments :
# History :
#==========================================================================
function show_table_cells($row, $row_key, $data, $class="")
{
global $debug;
if ($debug)
printf("
show_table_cells()
\n");
if (!$this->verify_array($data))
return 0;
$cell = 0;
$d = $this->select_colnames($data);
## Create regular cells
reset($d);
while(list($key, $val) = each($d))
{
$this->table_cell($row, $cell++, $val, $data[$val], $class);
}
return 1;
}
#==========================================================================
# Function : table_cell
#--------------------------------------------------------------------------
# Purpose : Outputs HTML code to render a single cell.
# Arguments: $row - The row number. [for derived classes]
# $col - The column number. [for derived classes]
# $key - The key value. [for derived classes]
# $val - The data value.
# $class - [optional] Used for CSS control.
# Returns : Nothing
# Comments :
# History :
#==========================================================================
function table_cell($row, $col, $key, $val, $class="")
{
$this->table_cell_open($class);
printf("%s", $val);
$this->table_cell_close($class);
}
function table_cell_open($class="")
{
printf("
select_colnames()
\n");
if (!is_array($this->fields) && is_array($data))
{
reset($data);
while(list($key, $val) = each($data))
{
if (ereg($this->filter, $key))
$this->fields[] = $key;
}
}
$d = $this->fields;
if ($debug)
{
print_array($d);
printf("select_colnames() return
");
}
return $d;
}
#==========================================================================
# Misc. functions
#==========================================================================
#--------------------------------------------------------------------------
## The following functions provide a very basic rendering
## of a HTML table with CSS class tags. Table is useable
## with them or the functions can be overridden for a
## more complex functionality.
#--------------------------------------------------------------------------
#--------------------------------------------------------------------------
## Table open and close functions.
#--------------------------------------------------------------------------
#==========================================================================
# Function : table_open
#--------------------------------------------------------------------------
# Purpose : Outputs HTML code to open a table.
# Arguments: $class - [optional] Used for CSS control.
# Returns : Nothing
# Comments :
# History :
#==========================================================================
function table_open($class="")
{
global $debug;
if ($debug)
printf("
table_open()
\n");
printf("