PHP Classes
elePHPant
Icontem

File: class_supertable.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Frits Bergman  >  SuperTable  >  class_supertable.php  >  Download  
File: class_supertable.php
Role: Class source
Content type: text/plain
Description: Show nice table filled with fields from odbc-source. Many usefull options available.
Class: SuperTable
Interactive table representing database-values
Author: By
Last change: 26-01-2005 Popup-text from database-column.
Date: 10 years ago
Size: 7,099 bytes
 

Contents

Class file image Download
<?php

class SuperTable
{
   
// description: Show a table filled with database-values by sqlquery.
    // Order-by and many other options available.
    // files: Use with class_forms.php.
    // Use with class_windowlink.php.
    // Make a rootfolder images with edit16.gif,del16.gif,order16.gif.
    // version: 2.4
    // author: Ing. M. van Oort
    // history: 26-05-2003 Delquery-debug.
    // 15-12-2003 Format floats 2-decimal.
    // 25-01-2005 Extra-uri also at edits.
    // 26-01-2005 Popup-text from column.

   
var $Name;
    var
$Borderwidth = 1;
    var
$Cellpadding = 1;
    var
$Cellspacing = 1;
    var
$Background_color = "white";
    var
$Connection = 13;
    var
$SQLQuery;
    var
$ID_column = 1; // Column-name or number.
   
var $Popup_text_column = 1; // Column-name or number.
   
var $Font = "Arial";
    var
$Font_size = 2;
    var
$Font_color = "black";
    var
$Row_color_odd = "white";
    var
$Row_color_even = "D6E3D3";
    var
$Header_fields = array();
    var
$Header_color = "336633";
    var
$Cell_align = array();
    var
$Header_font = "Arial";
    var
$Header_font_size = 2;
    var
$Header_font_color = "white";
    var
$Header_font_bold = 1;
    var
$Edits = 0;
    var
$Edits_icon_url = "/images/edit16.gif";
    var
$Edits_page = "wijzig.php";
    var
$Edits_id_var = "wijzig_id";
    var
$Edits_win_width = 600;
    var
$Edits_win_height = 400;
    var
$Edits_win_left = 200;
    var
$Edits_win_top = 200;
    var
$Deletes = 0;
    var
$Deletes_icon_url = "/images/del16.gif";
    var
$Delete_question = 1;
    var
$Current_page;
    var
$SQLQuery_delete;
    var
$Session_varname;
    var
$Session_id;
    var
$Extra_URI = ""; // Keep empty, set with SuperTable(params)
   
var $SQLQuery_new_row;
    var
$Hidecols = array(); // kolomnummers die niet getoond moeten worden
   
var $Hide_zeros = 0;
    var
$Order_columns = array();
    var
$Order_icon_url = "/images/order16.gif";
    var
$Order_by_col_nr;

    function
SuperTable($current_page,$extrauri = "",$delquestion = 0)
    {
       
$this->Current_page = $current_page;
       
$this->Extra_URI = $extrauri;
        if (
$delquestion == 1)
        {
            print
"<script language=\"Javascript\">\n";
            print
"function rusure(id,txt)\n";
            print
"{\n";
            print
"question = confirm(\"Weet u zeker dat u \"+txt+\" wilt verwijderen ?\")\n";
            print
"if (question !=\"0\")\n";
            print
"{\n";
            print
"top.location = \"".$this->Current_page."?del_id=\"+id+'".$extrauri."'\n";
            print
"}\n";
            print
"}\n";
            print
"</script>";
        }
    }

    function
Show()
    {
       
// maak vast een edit-window-object
       
$winEen = new WindowLink();
       
$winEen->Image = $this->Edits_icon_url;
       
$winEen->Description = "";
       
$winEen->Scrollbar = "yes";
       
$winEen->Width = $this->Edits_win_width;
       
$winEen->Height = $this->Edits_win_height;
       
$winEen->Left = $this->Edits_win_left;
       
$winEen->Top = $this->Edits_win_top;
       
$winEen->WindowStyle = 1;
       
       
// handel deletes af
       
if (!empty($this->SQLQuery_delete))
        {
           
// SQL Query voor verwijderen
           
odbc_exec($this->Connection,$this->SQLQuery_delete);
        }

       
// handel niewe rij af
       
if (!empty($this->SQLQuery_new_row))
        {
           
// SQL Query voor nieuwe rij
           
odbc_exec($this->Connection,$this->SQLQuery_new_row);
        }
       
       
// html table definitie
       
print"<table";
        print
" border=".$this->Borderwidth;
        print
" cellpadding=".$this->Cellpadding;
        print
" cellspacing=".$this->Cellspacing;
        print
" bgcolor=".$this->Background_color;
        print
">";

       
// toon header
       
if (!empty($this->Header_fields))
        {
            print
"<tr";
            print
" bgcolor=".$this->Header_color;
            print
">";
           
$size = sizeof($this->Header_fields);
            for (
$i = 0; $i < $size; $i++)
            {
                print
"<td>";
                print
"<font";
                print
" face='".$this->Header_font."'";
                print
" size=".$this->Header_font_size;
                print
" color='".$this->Header_font_color."'";
                print
">";
                if (
$this->Header_font_bold) print"<b>";
                print
$this->Header_fields[$i];
                if (
$this->Header_font_bold) print"</b>";
                print
"</font>";
               
// order-icons and links
               
if (in_array($i+1,$this->Order_columns))
                {
                    print
"<a href='".$this->Current_page."?orderby=".($i+1).$this->Extra_URI."'><img src='".$this->Order_icon_url."' border=0></a>";
                }
                print
"</td>";
            }
            print
"</tr>";
        }

       
// use order_by_col_nr
       
if (!empty($this->Order_by_col_nr))
        {
           
$this->SQLQuery = $this->SQLQuery." order by ".$this->Order_by_col_nr.";";
           
//print $this->SQLQuery; // TOON QUERY BIJ ORDERBY-FUNCTIE TESTEN
       
}

       
// do the query
       
$result = odbc_exec($this->Connection,$this->SQLQuery);
       
$nrfields = odbc_num_fields($result);

       
// show rows
       
$rownr = 0;
        while (
odbc_fetch_row($result))
        {
            print
"<tr>";
           
$rownr++;
           
// show fields
           
for ($i = 1; $i <= $nrfields; $i++)
            {
                if (!
in_array($i,$this->Hidecols))
                {
                   
// show field
                   
print"<td";
                   
// cell-style
                   
print" bgcolor=";
                    if (
$rownr%2) print $this->Row_color_odd;
                        else print
$this->Row_color_even;
                    if (!empty(
$this->Cell_align[$i-1]))
                        print
" align=".$this->Cell_align[$i-1];
                    else print
" align=right";
                    print
">";
                    print
"<font";
                    print
" face='".$this->Font."'";
                    print
" size=".$this->Font_size;
                    print
" color='".$this->Font_color."'";
                    print
">";
                   
// show value
                   
$dbveld = odbc_result($result,$i);
                   
$fieldtype = odbc_field_type($result,$i);
                    if (
$this->Hide_zeros == 1)
                    {
                        if (
$dbveld == 0) $dbveld = " ";
                    }
                    if (
$fieldtype == "datetime")
                    {
                       
$jaar = substr($dbveld,0,4);
                       
$maand = substr($dbveld,5,2);
                       
$dag = substr($dbveld,8,2);
                       
$showvar = sprintf("%s-%s-%s",$dag,$maand,$jaar);
                    }
                    else if (
$fieldtype == "float")
                    {
                       
$showvar = round($dbveld,2);
                    }
                    else
                   
$showvar = $dbveld; // onbekend type, gewone kopie
                   
print $showvar;
                    print
"</font>";
                    print
"</td>";
                }
            }

           
// edits-column tonen
           
if ($this->Edits == 1)
            {
                print
"<td";
                print
" bgcolor=";
                if (
$rownr%2) print $this->Row_color_odd;
                    else print
$this->Row_color_even;
                print
">";
               
$winEen->URL = $this->Edits_page."?".$this->Edits_id_var."=".odbc_result($result,$this->ID_column).$this->Extra_URI;
               
$winEen->Show();
                print
"</td>";
            }

           
// deletes-column tonen
           
if ($this->Deletes == 1)
            {
                print
"<td";
                print
" bgcolor=";
                if (
$rownr%2) print $this->Row_color_odd;
                    else print
$this->Row_color_even;
                print
">";
               
// hyperlink voor delete
               
if ($this->Delete_question == 1)
                {
                    print
"<a href='' onClick=\"rusure('".odbc_result($result,$this->ID_column)."','".odbc_result($result,$this->Popup_text_column)."'); return false;\">";
                }
                else
                print
"<a href='".$this->Current_page."?del_id=".odbc_result($result,$this->ID_column).$extrauri."'>\n";
                print
"<img src='".$this->Deletes_icon_url."' border=0></a>\n";
                print
"</td>";
            }
            print
"</tr>";
        }
        print
"</table>";

    }
}




?>