All pastes #14716 Raw Edit

Stuff

public php v1 · immutable
#14716 ·published 2005-06-15 21:48 UTC
rendered paste body
<?php	// Local class.	class Data_Grid	{				var $parent; // Parent instance reference.		var $table; // Table name		var $where; // Optional where clause		var $data; // Array of data.		var $sort; // Sort (by field)		var $order; // Order (Asc, Desc)		var $page; // Page (default 0)		var $perpage; // Records per page.		var $script; // Script name				var $html; // Html		var $fieldlist; // Field listing		var $title; // Title of table		var $whichcolor; // Color offset					// Constructor		function __construct($title, &$parent, $table, $fieldlist = "*", $where = "1", $sort = "client_id", $order = "ASC", $page = 0, $perpage = 25)		{					// Global stuff.			$this->parent =& $parent;			$this->table = $table;			$this->where = $where;			$this->sort = $sort;			$this->order = $order;			$this->page = $page;			$this->perpage = $perpage;			$this->fieldlist = $fieldlist;			$this->html = "";			$this->title = $title;			$this->whichcolor = 0;			$this->script = getenv("SCRIPT_NAME");			$this->load_data();		}				// Adds data to the grid.		function add($string)		{			$this->html .= $string ."\n\n";		}				// Loads data into array.		function load_data()		{			$offset = (int)$this->page * $this->perpage;			$sql = "SELECT ". $this->fieldlist ." FROM ". SQL_DB .".`". $this->table ."` WHERE ". $this->where ." ORDER BY ". $this->sort ." ". $this->order ." LIMIT $offset, ". $this->perpage;			$this->data =& $this->parent->database->FetchDataSet($sql);		}				// Switches colors		function switch_color()		{			if($this->whichcolor == 0)			{				$this->whichcolor = 1;				return FORM_COLOR_TWO;			}			else			{				$this->whichcolor = 0;				return FORM_COLOR_ONE;			}		}				// Fetches the html table.		function get()		{			$this->add("<table cellspacing='0' width='95%' align='center' style='border: 1px solid black;'>");			$this->add("<tr style='background-color: #". FORM_COLOR_HEADER .";'>");			$this->add("<td colspan=15 style='border-bottom: 1px solid black; padding: 6px;' align=center><b>". $this->title ."</b></td>");			$this->add("</tr>");						if($this->data !== false)			{				$i=0;				foreach($this->data AS $row)				{									if($i == 0)					{						$this->add("<tr style='background-color: #". $this->switch_color() .";'>");						foreach($row AS $key=>$dontcare)							$this->add("<td align='right' valign=top style='padding: 6px;'><b>". ucwords(str_replace('_', ' ', $key)) ."</b></td>");						$this->add("</tr>");					}										$this->add("<tr style='background-color: #". $this->switch_color() .";'>");					foreach($row AS $key=>$val)						$this->add("<td align='right' valign=top style='padding: 6px;'><b>$val</b></td>");					$this->add("</tr>");										$i++;				}								return $this->html;			}			else			{				return "Sorry, your query returned zero results.";			}		}	}	?>