Source for file dbctrls.inc.php
Documentation is available at dbctrls.inc.php
* This file is part of the VCL for PHP project
* Copyright (c) 2004-2007 qadram software <support@qadram.com>
* Checkout AUTHORS file for more information on the developers
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
define ('noHorizontal', 'noHorizontal');
define ('noVertical', 'noVertical');
* A control to browse through the records of a datasource.
private $_currentpos = - 1;
//Calls inherited constructor
parent::__construct($aowner);
$this->ControlStyle= "csRenderOwner=1";
$this->ControlStyle= "csRenderAlso=StyleSheet";
$owner = $this->readOwner();
$prefix = $owner->readNamePath(). ".". $this->_name. ".";
$_SESSION[$prefix. "CurrentPos"] = $this->_currentpos;
$owner = $this->readOwner();
$prefix = $owner->readNamePath(). ".". $this->_name. ".";
$this->_currentpos = $_SESSION[$prefix. "CurrentPos"];
//TODO: can we move that to loaded()? Is the data source ready there?
if ($this->_currentpos > 0)
$this->gotoPos($this->_currentpos);
$ds = $this->_datasource->DataSet;
for ($x = 0; $x < $this->_currentpos; $x++)
$value = $submittedValue->asString();
private function gotoPos($pos)
if ($pos >= 0 /*&& $this->_datasource->Dataset->Active*/)
for ($x = 0; $x < $pos; $x++ )
* Execute the $action of a clicked link.
* @param mixed $action This param defines which action should be performed.
* If $action is a string then the matching operation
* on the data set is performed. Currently
* first, prev, next and last are supported.
* If $action is a integer the data set cursor is moved
// check which link was clicked
case "first": $ds->First(); $val = $action; $this->_currentpos = 0; break;
case "prev": /*$ds->Prior();*/ $val = $action; $this->_currentpos-- ; $this->gotoPos($this->_currentpos); break;
case "next": $ds->Next(); $val = $action; if($this->_currentpos < $ds->RecordCount- 1) $this->_currentpos++ ; break;
case "last": $ds->Last(); $val = $action; $this->_currentpos = $ds->RecordCount- 1; break;
// check if it is a integer
$diff = $val - $this->_currentpos;
for ($x = 0; $x < abs($diff); $x++ )
// move to the clicked record number
//$ds->MoveBy($val - $this->_currentpos);
$this->_currentpos = $val;
$this->callEvent('onclick', array("action", $val));
* Simulates a link click on the database navigator, invoking the action of the link.
* @param mixed $action This param defines which action should be performed.
* If $action is a string then the matching operation
* on the data set is performed. Currently
* first, prev, next and last are supported.
* If $action is a integer the data set cursor is moved
* Returns an array with all record numbers to display.
* Each record number has following properties:
* - recordnumber => record number to display
* - currentrecord => true if current record
* - first => true if first
* The returned array looks like this:
* @return array Returns an array with all record numbers to display.
protected function getArrayOfRecordNumbers()
// check if DS is set and active
//TODO: Check if DS is active
$currentRecord = $this->_currentpos; //$ds->RecNo;
$recordCount = $ds->RecordCount;
// we want to have the current record number in the center (if possible)
// Calculate the range to show (0 = first; $recordCount-1 = last).
// The first few records (till $centeroffset) are treated differently ($end is $this->_shownrecordscount-1).
if ($currentRecord < $centeroffset)
// check if record count is lower than $this->_shownrecordscount
// if yes, then $end is $recordCount-1, otherwise $this->_shownrecordscount-1
// $end is either $recordCount-1 or the current record plus the offset ($centeroffset floored is case _shownrecordscount is odd)
// go no lower than 0 (first) and always show as many numbers as possible
$currentRecord - max($centeroffset - 1,
// add the record numbers to the result array
for ($x = $start; $x <= $end; $x++ )
// use the real record number as key
$result[$x] = array("recordnumber" => ($x+ 1), // record index starts at 0, so add 1 to the number to print
"currentrecord" => ($x == $currentRecord),
"first" => ($x == 0), // record index starts at 0
"last" => ($x == $recordCount- 1)
// only return dummy values when at design-time
// let's add some dummy values for design-time
// use the real record number (starting at 0) as key
$result[$x- 1] = array("recordnumber" => $x,
"currentrecord" => ($x == 1), // first is current record
"last" => false // last not reached
* Returns a correctly formatted URL string with the given action.
* @param string $action Action to include in the URL.
* @return string URL including the given action. Points to the script where
* the DBNavigator is used.
if (isset ($_SERVER['PHP_SELF']))
$script = basename($_SERVER['PHP_SELF']);
* Get the contents of one cell (of the table).
* @param string $caption Caption of the item to add to the cell content.
* @param string $link Link to wrap arounf the caption.
* @param string $cellalign The cell align depends on the orientation of the DBNavigator.
* If noVertical it's valign, if noHorizontal it's align.
* @param bool $enabled Set this argument to enable/disable the link.
* @return string Returns a string with the cell contents.
protected function cellContents($caption, $link, $cellalign, $enabled = true)
$result .= "<tr valign=\"$cellalign\">\n";
$result .= " <td align=\"center\"><a href=\"$link\">$caption</a></td>\n";
$result .= " <td align=\"center\">$caption</td>\n";
$result .= " <td align=\"$cellalign\"><a href=\"$link\">$caption</a></td>\n";
$result .= " <td align=\"$cellalign\">$caption</td>\n";
// get the Font attributes
$style = $this->Font->FontString;
$style .= "background-color: " . $this->_color . ";";
// add the cursor to the style
$style .= "cursor: $cr;";
if ($style != "") $style = "style=\"$style\"";
$hint = $this->getHintAttribute();
$class = ($this->Style != "") ? "class=\"$this->StyleClass\"" : "";
// call on show here so the output can be influenced
// get the contents of the record numbers first
$numbers = $this->getArrayOfRecordNumbers();
foreach ($numbers as $number)
$this->dbNavLink($number['recordnumber']), // create a link to the record number
$cellalign, // align of the
!(bool) $number['currentrecord']); // enable all numbers except the current record
//TODO: Check if DS is active
// check if DS is set and active
$currentRecord = $this->_currentpos; //$ds->RecNo;
// show the first record at design time
// check if the first number is shown => disable the first and previous links
$firstshown = ($currentRecord > - 1 && array_key_exists($currentRecord, $numbers) && $numbers[$currentRecord]['first']);
// check if the last number is shown => disable the next and last links
$lastshown = ($currentRecord > - 1 && array_key_exists($currentRecord, $numbers) && $numbers[$currentRecord]['last']);
//echo "first: $firstshown last: $lastshown";
echo "<table id=\"{$this->_name}_table\" height=\" $this->_height\" width=\" $this->_width\" cellpadding=\"0\" cellspacing=\"0\" $hint $style $class>\n ";
// add the page numbers here...
echo "<tr valign=\"middle\">\n";
// add the page numbers here...
* Occurs when a link on the database navigator is clicked,
* after the action is executed.
* It passes the executed action as parameter to the event handler. The
* name of the parameter is "action".
function getOnClick() { return $this->_onclick; }
* Occurs when a link on the database navigator is clicked,
* after the action is executed.
* It passes the executed action as parameter to the event handler. The
* name of the parameter is "action".
function setOnClick($value) { $this->_onclick= $value; }
function defaultOnClick() { return null; }
* Caption of "First" link. Clicking on this link will show the first record
function setCaptionFirst($value) { $this->_captionfirst= $value; }
function defaultCaptionFirst() { return "First"; }
* Caption of "Prev" link. Clicking on this link will show the previous record
* in regard to the current record of the datasource.
function defaultCaptionPrevious() { return "Prev"; }
* Caption of "Next" link. Clicking on this link will show the next record
* in regard to the current record of the datasource.
function setCaptionNext($value) { $this->_captionnext= $value; }
function defaultCaptionNext() { return "Next"; }
* Caption of "Last" link. Clicking on this link will show the last record
function setCaptionLast($value) { $this->_captionlast= $value; }
function defaultCaptionLast() { return "Last"; }
function getColor() { return $this->readColor(); }
function setColor($value) { $this->writeColor($value); }
function getDataSource() { return $this->_datasource; }
function setDataSource($value)
function getFont() { return $this->readFont(); }
function setFont($value) { $this->writeFont($value); }
* Orientation of the Paginator.
* @return enum (noHorizontal, noVertical)
function setOrientation($value) { $this->_orientation = $value; }
function defaultOrientation() { return noHorizontal; }
* Format of the page numbers. %d defines the location of the number.
function defaultPageNumberFormat() { return "%d"; }
function getParentColor() { return $this->readParentColor(); }
function setParentColor($value) { $this->writeParentColor($value); }
function getParentFont() { return $this->readParentFont(); }
function setParentFont($value) { $this->writeParentFont($value); }
function getShowHint() { return $this->readShowHint(); }
function setShowHint($value) { $this->writeShowHint($value); }
* Indicates if the "First" link is shown.
function getShowFirst() { return $this->_showfirst; }
function setShowFirst($value) { $this->_showfirst= $value; }
function defaultShowFirst() { return 1; }
* Indicates if the "Last" link is shown.
function getShowLast() { return $this->_showlast; }
function setShowLast($value) { $this->_showlast= $value; }
function defaultShowLast() { return 1; }
* Indicates if the "Next" link is shown.
function getShowNext() { return $this->_shownext; }
function setShowNext($value) { $this->_shownext= $value; }
function defaultShowNext() { return 1; }
* Indicates if the "Prev" link is shown.
function setShowPrevious($value) { $this->_showprevious= $value; }
function defaultShowPrevious() { return 1; }
* Indicates if the control shows the number of records or not
function defaultShownRecordsCount() { return 10; }
function getStyle() { return $this->readstyle(); }
function setStyle($value) { $this->writestyle($value); }
function getVisible() { return $this->readVisible(); }
function setVisible($value) { $this->writeVisible($value); }
define ('rkHorizontal', 'rkHorizontal');
define ('rkVertical', 'rkVertical');
* A class to iterate througha dataset and repeat controls inside it
class <a href="../VCL/DBRepeater.html">DBRepeater</a> extends <a href="../VCL/Panel.html">Panel</a>
private $_kind=<a href="../VCL/_dbctrls.inc.php.html#definerkVertical">rkVertical</a>;
* Specifies the orientation of the repeater, horizontal or vertical
function getKind() { return $this->_kind; }
function setKind($value) { $this->_kind=$value; }
function defaultKind() { return <a href="../VCL/_dbctrls.inc.php.html#definerkVertical">rkVertical</a>; }
private $_restartdataset=true;
* Specifies if the dataset is restarted or not when beginning to dump code
function getRestartDataset() { return $this->_restartdataset; }
function setRestartDataset($value) { $this->_restartdataset=$value; }
function defaultRestartDataset() { return true; }
* Specifies how many records are going to be shown on the repeater
function getLimit() { return $this->_limit; }
function setLimit($value) { $this->_limit=$value; }
function defaultLimit() { return 0; }
private $_datasource=null;
* DataSource to attach to this component
function getDataSource() { return $this->_datasource; }
function setDataSource($value)
if (($this->ControlState & <a href="../VCL/_classes.inc.php.html#definecsDesigning">csDesigning</a>)==<a href="../VCL/_classes.inc.php.html#definecsDesigning">csDesigning</a>)
if ($this->_restartdataset) $ds->first();
$class = ($this->Style != "") ? "class=\" $this->StyleClass\" " : "";
echo "< table id=\"{ $this->_name}_table\" width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" $class> ";
if ($this->_kind==rkHorizontal) echo "<tr>";
if ($this->_kind==<a href="../VCL/_dbctrls.inc.php.html#definerkVertical">rkVertical</a>) echo "<tr>";
if ($this->_kind==<a href="../VCL/_dbctrls.inc.php.html#definerkVertical">rkVertical</a>) echo "</tr>";
if ($render>=$this->_limit) break;
if ($this->_kind==<a href="../VCL/_dbctrls.inc.php.html#definerkHorizontal">rkHorizontal</a>) echo "</tr>";
//Calls inherited constructor
parent::__construct($aowner);
$this->Layout->Type=<a href="../VCL/_graphics.inc.php.html#defineXY_LAYOUT">XY_LAYOUT</a>;
|