Sådan benyttes komponenten ViewList klassen
Først skal du inkludere den fil der beskriver komponenten, som en klasse fil
<? require_once(HTML_PACKAGE_PATH.'/ViewList.php'); ?>
Dernæst kan du enten benytte komponenten som et taglib (statiske metoder):
<? ViewList::display($param1, $param2, $param3, ...); ?>
eller du kan lave en instance af komponenten og benytte metoderne direkte:
<? $object = new ViewList($param1, $param2, $param3, ...); print $object->getHtml(); ?>
Sådan vises komponenten ViewList klassen
Den fulde PHP kildekode for ViewList klassen
<?php/** * @package mvc * @see HTML_MVC_VIEW_PATH.'/ViewList.php' * @copyright (c) http://Finn-Rasmussen.com * @license http://Finn-Rasmussen.com/license/ myPHP License conditions * @author http://Finn-Rasmussen.com * @version 1.11 * @since 27-nov-2009 *//** * The required files */require_once(HTML_BASIC_UTIL_PATH.'/Rowcolor.php');require_once(HTML_BASE_UTIL_PATH.'/Htmlspecialchars.php');require_once(HTML_BASE_UTIL_PATH.'/Sortby.php');require_once(HTML_BASE_UTIL_PATH.'/Style.php');require_once(HTML_BASE_UTIL_PATH.'/Div.php');require_once(HTML_FORM_COMPONENT_PATH.'/ElementFactory.php');require_once(HTML_MVC_VIEW_PATH.'/ViewCommon.php');require_once(HTML_UTIL_COMPONENT_PATH.'/Params.php');require_once(HTML_UTIL_COMPONENT_PATH.'/Decrypt.php');require_once(HTML_UTIL_COMPONENT_PATH.'/Encrypt.php');require_once(HTML_UTIL_COMPONENT_PATH.'/Session.php');require_once(HTML_DB_COLUMNS_RESOURCE_PATH.'/Define.php'); // In order to assure you include thisif (defined('HTML_ECOMMERCE_COMPONENT_PATH')) { require_once(HTML_ECOMMERCE_COMPONENT_PATH.'/Tax.php');}/** * Generates the html for a View List, where the data are fetched from a mySQL database * <code> * Usage: * $sql = "SELECT * FROM images, links WHERE link_id = image_id"; * $database = new Database(); * $command = new Command(); * $datareader = $command->newDataReader($sql, $database); * * $view = new ViewList($datareader, $text, $width, $class, $border, * $cellpadding, $cellspacing, $summary, $caption, $layout); * print $view->getHtml(); * Or * ViewList::display($datareader, $text, $width, $class, $border, * $cellpadding, $cellspacing, $summary, $caption, $layout); * * Generates a complete View List interface * +------------------------------------------- * |>| Text header * +------------------------------------------- * | head1 | head2 | head3 | etc. * +------------------------------------------- * | dat1 | dat2 | dat3 | etc. * +------------------------------------------- * | subtotal 0.00 (optional) * | tax 0.00 (optional) * +------------------------------------------- * | Total 0.00 (optional) * +------------------------------------------- * </code> * @package mvc */class ViewList extends ViewCommon { /** * Constructor * @param DataReader / array $datareader The Data Reader object OR an array * @param String $text The text header for the table * @param String $width The Width for the table * @param String $class The Class * @param String $border The Border * @param String $cellpadding The CellSpacing * @param String $cellspacing The CellPadding * @param String $summary The Summary * @param String $caption The Caption * @param String $layout The layout to use */ function __construct($datareader=null, $text='', $width='', $class='', $border='', $cellpadding='', $cellspacing='', $summary='', $caption='', $layout='') { $theText = $text != '' ? $text : $this->getClassName(); // Global table characteristics $theWidth = $width != '' ? $width : LIST_VIEW_WIDTH; $theClass = $class != '' ? $class : LIST_VIEW_CLASS; $theBorder = $border != '' ? $border : LIST_VIEW_BORDER; $theCellPadding = $cellpadding != '' ? $cellpadding : LIST_VIEW_CELLPADDING; $theCellSpacing = $cellspacing != '' ? $cellspacing : LIST_VIEW_CELLSPACING; parent::__construct($datareader, $theText, $theWidth, $theClass, $theBorder, $theCellPadding, $theCellSpacing, $summary, $caption, $layout); } /** * Return the total as an object, like a basket or invoice * Overload this methode, if you need total * @param String $colspan The colspan to use * @return Object The subtotal as an object */ function newTotal($colspan) { $object = new Raw(); if ($this->subtotal !== null && ($this->subtotal != '' || $this->subtotal == 0)) { $total = 0; $total += $this->subtotal; $tr = new Tr(); $td = new Td(CSS_BORDER_TOP.' '.CSS_COLOR_DARK,'','',TEXT_BASKET_SUBTOTAL); $tr->add($td); $formattedSubtotal = $this->format($this->subtotal,FORMAT_STYLE_MONEY_SHORT); $td = new Td(CSS_BORDER_TOP.' '.CSS_COLOR_DARK.' '.CSS_ALIGN_RIGHT,'', $colspan, $formattedSubtotal); $tr->add($td); $object->add($tr); $tax = $this->subtotal * 0.25; // Default, use the Tax in Denmark if (defined('HTML_ECOMMERCE_COMPONENT_PATH')) { $tax = Tax::amount($this->subtotal); } $total += $tax; $tr = new Tr(); $td = new Td(CSS_COLOR_DARK,'','',TEXT_TAX); $tr->add($td); $formattedTax = $this->format($tax,FORMAT_STYLE_MONEY_SHORT); $td = new Td(CSS_COLOR_DARK.' '.CSS_ALIGN_RIGHT,'', $colspan, $formattedTax); $tr->add($td); $object->add($tr); $tr = new Tr(); $td = new Td(CSS_BORDER_TOP.' '.CSS_COLOR_LIGHT,'','',TEXT_TOTAL); $tr->add($td); $formattedTotal = $this->format($total,FORMAT_STYLE_MONEY_LONG); $td = new Td(CSS_BORDER_TOP.' '.CSS_COLOR_LIGHT.' '.CSS_ALIGN_RIGHT, '', $colspan, $formattedTotal); $tr->add($td); $object->add($tr); } return $object; } /** * Get a new Checkbox for multiple actions * In the head section, this checkbox will just be toggle / select all * Popup some dedicated buttons, figure out how * Where to post data?, figure this out * When this feature is selected, then dedicated buttons are used for multiple line actions * - Send an email to the selected lines * - Delete selected lines * - Update status for selected lines * @param String $id The value to use, this is in fact the ID * @return Object The Link to create as an object */ function newCheckbox($id='') { $checkbox = new Raw(); if (defined('LOGIN_ROLE_NAME') && LOGIN_ROLE_NAME & RoleType::VIEW_CHECKBOX) { $command = Request::get(REQUEST_COMMAND); if ($command === CRUD_VIEW_FORM_CHECKBOX) { $theId = Encrypt::it($id); $type = "checkbox"; $key = ""; $name = REQUEST_ID."[$theId]"; $value = ""; // TODO What? $onclick = ""; // $len $required = ""; $debug = "Debug text"; $checked = "checked"; $class = ""; $field = COLUMN_FIELD_TYPE_CHECKBOX; $checkbox = $this->newElement($type, $key, $name, $value, $onclick, $required, $debug, $checked, $class, $field); } } return $checkbox; } /** * Get the Link to Update All the lines as an object * @param String $css The CSS class to use * @param String $table The table name if present * @param String $text The text to use for the link * @return Object The Link to update all as an object */ function newLinkCheckbox($css='', $table='', $text='') { $imagelink = new Raw(); if (defined('LOGIN_ROLE_NAME') && LOGIN_ROLE_NAME & RoleType::VIEW_CHECKBOX) {// if ( count( $this->multipleEditColumns) > 0) { $view = CRUD_VIEW_FORM_CHECKBOX; $debug = 'CRUD_VIEW_FORM_CHECKBOX '; $href = $this->getHref($view); $imagelink = $this->newImageLink($text, $href, IMAGE_ANI_BEE, LINK_TITLE_CHECKBOX, $css, $table, $debug);// } } return $imagelink; } /** * Get the Link to create a new row as an object * @param String $value The value to use * @param String $css The CSS class to use * @param String $table The table name if present * @param String $text The text to use for the link * @return Object The Link to create as an object */ function newLinkCreate($css='', $table='', $text='') { $imagelink = new Raw(); if (defined('LOGIN_ROLE_NAME') && LOGIN_ROLE_NAME & RoleType::VIEW_CREATE) { $view = CRUD_VIEW_FORM_CREATE; $debug = 'CRUD_VIEW_FORM_CREATE '; $href = $this->getHref($view); $imagelink = $this->newImageLink($text, $href, IMAGE_NEW, LINK_TITLE_INSERT, $css, $table, $debug); } return $imagelink; } /** * Get the Link to Read details as new row as an object * @param String $value The value to use * @param String $css The CSS class to use * @param String $table The table name if present * @param String $text The text to use for the link * @return Object The Link to create as an object */ function newLinkRead($value='', $css='', $table='', $text='') { $imagelink = new Raw(); if (defined('LOGIN_ROLE_NAME') && LOGIN_ROLE_NAME & RoleType::VIEW_READ) { $view = CRUD_VIEW_FORM_DETAIL; $debug = 'CRUD_VIEW_FORM_DETAIL '; $id = $value; $href = $this->getHref($view, $id); $imagelink = $this->newImageLink($text, $href, IMAGE_DETAIL, LINK_TEXT_SHOW, $css, $table, $debug); } return $imagelink; } /** * Get the Link to update the single row as an object * @param String $value The value to use * @param String $css The CSS class to use * @param String $table The table name if present * @param String $text The text to use for the link * @return Object The Link to update as an object */ function newLinkUpdate($value='', $css='', $table='', $text='') { $imagelink = new Raw(); if (defined('LOGIN_ROLE_NAME') && LOGIN_ROLE_NAME & RoleType::VIEW_UPDATE) { $view = CRUD_VIEW_FORM_UPDATE; $debug = 'CRUD_VIEW_FORM_UPDATE '; $id = $value; $href = $this->getHref($view, $id); $imagelink = $this->newImageLink($text, $href, IMAGE_UPDATE, LINK_TITLE_UPDATE, $css, $table, $debug); } return $imagelink; } /** * Get the Link to Update All the lines as an object * @param String $css The CSS class to use * @param String $table The table name if present * @param String $text The text to use for the link * @return Object The Link to update all as an object */ function newLinkMultiple($css='', $table='', $text='') { $imagelink = new Raw(); if (defined('LOGIN_ROLE_NAME') && LOGIN_ROLE_NAME & RoleType::VIEW_MULTIPLE) { if ( count( $this->multipleEditColumns) > 0) { $view = CRUD_VIEW_FORM_MULTIPLE; $debug = 'CRUD_VIEW_FORM_MULTIPLE '; $href = $this->getHref($view); $imagelink = $this->newImageLink($text, $href, IMAGE_MULTIPLE, LINK_TITLE_MULTIPLE, $css, $table, $debug); } } return $imagelink; } /** * Get the Link to Remove All the lines as an object * Note: A confirm box is popup to the user, in order to accept/reject to remove all lines * @param String $value The value to use * @param String $css The CSS class to use * @param String $table The table name if present * @param String $text The text to use for the link * @return Object The Link to delete all as an object */ function newLinkRemove($value='', $css='', $table='', $text='') { $imagelink = new Raw(); if (defined('LOGIN_ROLE_NAME') && LOGIN_ROLE_NAME & RoleType::VIEW_REMOVE) { $view = CRUD_VIEW_FORM_REMOVE; $debug = 'CRUD_VIEW_FORM_REMOVE '; $id = ""; $sid = defined('LOGIN_SID') ? LOGIN_SID : ""; $href = $this->getHref($view, $id, $sid); $onclick = "if (confirm('".LINK_TITLE_DELETE_ALL."? (".$sid.")')) {location.href='$href';}"; // Confirm REMOVE ALL $imagelink = $this->newImageLink($text, "#", IMAGE_REMOVE, LINK_TITLE_DELETE_ALL, $css, $table, $debug, $onclick); } return $imagelink; } /** * Get the Link to delete a single row as an object * @param String $value The value to use * @param String $css The CSS class to use * @param String $table The table name if present * @param String $text The text to use for the link * @return Object The Link to delete as an object */ function newLinkDelete($value='', $css='', $table='', $text='') { $imagelink = new Raw(); if (defined('LOGIN_ROLE_NAME') && LOGIN_ROLE_NAME & RoleType::VIEW_DELETE) { $view = CRUD_VIEW_FORM_DELETE; $debug = 'CRUD_VIEW_FORM_DELETE '; $id = $value; $href = $this->getHref($view, $id); $imagelink = $this->newImageLink($text, $href, IMAGE_DELETE, LINK_TITLE_DELETE, $css, $table, $debug); } return $imagelink; } /** * Get the Image and Link as an object * @param String $text The text to use for the link * @param String $href The url inclusive the request parameters to use * @param String $image The image to use * @param String $title The title to use (alt text) * @param String $css The CSS class to use * @param String $table The table name if present * @param String $debug The debug info * @param String $onclick The onclick javascript, if present * @return ImageLink The Image Link as an object */ function newImageLink($text='', $href='', $image='', $title='', $css='', $table='', $debug='', $onclick='') { $theTitle = $title; if (defined('DEBUG_LEVEL_SHOW_DECRYPT') && (DEBUG_LEVEL & DEBUG_LEVEL_SHOW_DECRYPT)) { $theTitle = $debug.$title; } // The Image $width = ""; $height = ""; $theImage = new Images($image, $width, $height, $theTitle, $css); // The Link $aux = ""; $target = ""; $name = ""; $tabindex = ""; $theLink = new Link($text, $href, $css, $theTitle, $aux, $target, $name, $tabindex, $onclick); return new ImageLink($theImage, $theLink); } /** * Get the href for a link inclusive the requst parameters to use * @param String $command The next command to execute * @param String $id The ID to use, if present * @param String $sid The SID to use, if present * @return array The request parameters as a string */ function getHref($command, $id='', $sid='') { $href = Server::getPhpSelf(); $param = array(); $param[REQUEST_COMMAND] = $command; if ($id !== '') { $param[REQUEST_ID] = Encrypt::it($id); } if ($sid !=='') { $param[REQUEST_SID] = Encrypt::it($sid); } if ($this->table !== '') { $param[@REQUEST_TABLE] = Encrypt::it($this->table); } $urlencode = true; $params = Params::get($param, $urlencode, __FILE__, __LINE__); return $href.$params; } /** * Get the The Primary key as an object * @param String $key The key to use * @param String $value The value to use * @param String $rowcolor The CSS class to use * @param boolean $isHeader Is a header, if true * @param String $table The table name if present * @param String $text The text to use for a link * @return Object The Primary key as an object */ function newPrimaryKey($key, $value, $css, $isHeader, $table='', $text='') { $object = new Raw(); // Decide to use TD or TH and is allowed to Execute update or delete or insert if (defined('LOGIN_ROLE_NAME') && LOGIN_ROLE_NAME & (RoleType::VIEW_CREATE | RoleType::VIEW_REMOVE | RoleType::VIEW_READ | RoleType::VIEW_UPDATE | RoleType::VIEW_DELETE | RoleType::VIEW_MULTIPLE )) { $object = new Td($css); if ($isHeader) { $object = new Th($css); // Override } $command = Request::get(REQUEST_COMMAND); if ($command !== CRUD_VIEW_FORM_MULTIPLE) { if ($isHeader) { $width = $this->calculateWidth(); $class = "widthHeader"; $style = new Style(".".$class."{width:".$width."px}"); $object->add( $style ); $div = new Div("", $class); if (LOGIN_ROLE_NAME & RoleType::VIEW_CHECKBOX) { $div->add($this->newLinkCheckbox($css, $table, $text) ); } /** * Create a new entry utilizing the view form */ if (LOGIN_ROLE_NAME & RoleType::VIEW_CREATE) { $div->add( $this->newLinkCreate($css, $table, $text) ); } /** * Update all, like in a basket multiple list form view */ if (LOGIN_ROLE_NAME & RoleType::VIEW_MULTIPLE) { $div->add( $this->newLinkMultiple($css, $table, $text)); } /** * A confirm box is popup'ed to the user, before Removing all */ if (LOGIN_ROLE_NAME & RoleType::VIEW_REMOVE) { $encSid = Encrypt::it(Session::getId('', __FILE__, __LINE__)); $sid = Decrypt::it(Request::get(REQUEST_SID), $encSid); $div->add( $this->newLinkRemove($sid, $css, $table, $text) ); } $object->add( $div ); } else { $isTable = $this->isTable(); if ($isTable && LOGIN_ROLE_NAME & RoleType::VIEW_CHECKBOX) { $object->add($this->newCheckbox($value, $css, $table, $text) ); } if (LOGIN_ROLE_NAME & RoleType::VIEW_READ) { $object->add($this->newLinkRead($value, $css, $table, $text) ); } if (LOGIN_ROLE_NAME & RoleType::VIEW_UPDATE) { $object->add( $this->newLinkUpdate($value, $css, $table, $text) ); } if (LOGIN_ROLE_NAME & RoleType::VIEW_DELETE) { $object->add( $this->newLinkDelete($value, $css, $table, $text) ); } } } } return $object; } /** * Calculate the width of of the CRUD column, where the gif's are shown * The size of the gif's are as shown * @return int The calculated width of the TD */ private function calculateWidth() { $pixelsData = 0; $pixelsHead = 0; if (LOGIN_ROLE_NAME & RoleType::VIEW_CHECKBOX) { $pixelsData += $GLOBALS[IMAGE_NAME_WIDTH ][IMAGE_DETAIL] + 15; } if (LOGIN_ROLE_NAME & RoleType::VIEW_READ) { $pixelsData += $GLOBALS[IMAGE_NAME_WIDTH ][IMAGE_DETAIL]; } if (LOGIN_ROLE_NAME & RoleType::VIEW_UPDATE) { $pixelsData += $GLOBALS[IMAGE_NAME_WIDTH ][IMAGE_UPDATE]; } if (LOGIN_ROLE_NAME & RoleType::VIEW_DELETE) { $pixelsData += $GLOBALS[IMAGE_NAME_WIDTH ][IMAGE_DELETE]; } if (LOGIN_ROLE_NAME & RoleType::VIEW_CHECKBOX) { $pixelsHead += $GLOBALS[IMAGE_NAME_WIDTH ][IMAGE_NEW] + 15; } if (LOGIN_ROLE_NAME & RoleType::VIEW_CREATE) { $pixelsHead += $GLOBALS[IMAGE_NAME_WIDTH ][IMAGE_NEW]; } if (LOGIN_ROLE_NAME & RoleType::VIEW_MULTIPLE) { $pixelsHead += $GLOBALS[IMAGE_NAME_WIDTH ][IMAGE_UPDATE]; } if (LOGIN_ROLE_NAME & RoleType::VIEW_REMOVE) { $pixelsHead += $GLOBALS[IMAGE_NAME_WIDTH ][IMAGE_REMOVE]; } $pixels = 4 * $this->cellpadding; return $pixels + ( $pixelsHead < $pixelsData ? $pixelsData : $pixelsHead ); } /** * Get the Header link, where the sort order is defined * If sort is not allowed, then use a plain text header, else * if sort is enabled, then use a sort link * Note: The 'key' is the translated header text * @param String $key The key text to show * @return String The html */ function getHeaderLink($key) { $html = ''; $text = $key; if (defined('HTML_LANGUAGE_UTIL_PATH')) { $text = Translate::sql($key, TRANSLATE_TEXT); } $sort = $this->datareader->getSort(); if ($sort) { $link = new Sortby( $text, $this->table ); $html .= $link->getHtml(); } else { $html .= $key; } return $html; } /** * Return the header or data for a list view * @param String $key The key to use * @param String $value The value to use * @param String $rowcolor The CSS class to use * @param boolean $isHeader Is a header, if true * @param String $id * @return Object The html as an object */ function newDataList($key, $value, $css, $isHeader=false, $id='') {// $text = $value; $linkInsert = '';// $theCss = $css; $name = $this->datareader->getFieldName($key); $len = $this->datareader->getFieldLen($key); $type = $this->datareader->getFieldType($key); $flags = $this->datareader->getFieldFlags($key); $table = $this->datareader->getFieldTable($key); $debug = "\r\n\t$name\r\n\t$len\r\n\t$type\r\n\t$table\r\n"; if ($flags != '') { if (is_array($flags)) { foreach($flags as $flag) { $debug .= "\t$flag\r\n"; } } else { $debug .= "\t$flags\r\n"; } } else { // Ignore } $text = $this->getFormattedText($key, $value, $isHeader); $align = $this->getAlignment($key); $theCss = $this->getCss($key, $css, $isHeader, $value); // Decide to use TD or TH $object = new Td($theCss); if ($isHeader) { $object = new Th($theCss, '', $align); // Override $object->add(new Raw("\r\n<!-- ".$debug." -->\r\n")); } else { $text = $this->strip($text, __FILE__, __LINE__); } // Add the TD element $object->add($this->newTextElement($key, $text, $isHeader, $id)); return $object; } /** * Get a new plain element or a new Text element, * when SELECT_QUANTITY && RoleType::VIEW_MULTIPLE * @param String $key * @param String $text * @param boolean $isHeader * @param String $id * @return object */ private function newTextElement($key, $text, $isHeader, $id='') { $object = new Raw(); $element = new Raw($text != '' ? $text : ' '); if (defined('DATABASE_PREFIX') && $key === DATABASE_PREFIX.TABLE_NAME_SESSION.SELECT_TABLE_ID) { // TODO setSid() ?? instead $element = new Raw('<!-- TODO '.$text." --> "); } else { $isTable = $this->isTable(); $command = Request::get(REQUEST_COMMAND); if ($isTable && $command === CRUD_VIEW_FORM_MULTIPLE) { $realKey = Translate::sql($key, TRANSLATE_TEXT); if (!$isHeader && LOGIN_ROLE_NAME & RoleType::VIEW_MULTIPLE) { if (array_key_exists($realKey, $this->multipleEditColumns)) { $type = $this->multipleEditColumns[$realKey][0]; $name = $realKey."[$id]"; $len = $this->multipleEditColumns[$realKey][1]; $checked = $text !== CHECKBOX_VALUE_NO ? 'checked' : ''; $debug = "Debug $name"; $class = $this->multipleEditColumns[$realKey][2]; $onblur = ""; $element = ElementFactory::newInput($type, $name, $text, $len, $debug, $checked, $class, $onblur); if ($type === "checkbox") { // Checkbox, have to have a hidden field in order to toogle $onclick = "if(this.checked){this.form.elements['".$name."'].value='".CHECKBOX_VALUE_YES."';}else{this.form.elements['".$name."'].value='".CHECKBOX_VALUE_NO."';}"; $theValue = $text !== CHECKBOX_VALUE_NO ? CHECKBOX_VALUE_YES : CHECKBOX_VALUE_NO; $object->add(new Hidden($name, $theValue)); $element = ElementFactory::newInput($type, "", "", $onclick, $debug, $checked, $class, $onblur); } else { // Use already new element } // Use element } else { // Use plain text } } else { // Use plain text } } else { // Use plain text } } $object->add( $element ); return $object; } /** * Return the row data as html * <tr> * <td>data 1</td> * <td>data 2</td> * : * <td>data n</td> * </tr> ... * @param array $row The row to loop for columns * @param String $rowcolor The CSS class to use * @param boolean $isHeader Is a header, if true * @return Object The html as an object */ function newRow($row, $css, $isHeader=false) { $object = new Raw(); if (count($row) > 0) { $tr = new Tr(); $primaryKey = new Raw(); //$showDetail = new Raw(); $sid = 'TODO'; // TODO PROBLEMS Session::getId('', __FILE__, __LINE__); $id = ''; foreach($row as $key=>$rawvalue) { $value = stripslashes($rawvalue); $flags = $this->datareader->getFieldFlags($key); $table = $this->datareader->getFieldTable($key); if (defined('COLUMN_FIELD_FLAG_PRIMARY_KEY') && is_array($flags) && in_array(COLUMN_FIELD_FLAG_PRIMARY_KEY, $flags)) { $primaryKey = $this->newPrimaryKey($key, $value, $css, $isHeader, $table); $id = $value; } else { /** * Security, only allow the SID owner to delete and update own rows */ if (defined('DATABASE_PREFIX') && $key == DATABASE_PREFIX.$table.SELECT_TABLE_ID) { // TODO true || ?? logged in when in basket ??? defined('LOGIN_SID') && LOGIN_SID if ($sid == $value) { $tr->add($primaryKey); } else { $td = new Td($css); if ($isHeader) { $td = new Th($css); } $td->add(new Raw("<!-- $key=$value --> ")); $tr->add($td); // Dummy column } } else { // Ignore // TODO if ViewSearch => link to show details // TODO if email =>link, if mobil =>send sms // TODO if Basket, text+description in one and href link // TODO wait with $tr->add until all columns are fetched // TODO if Basket, $tr->add(new Td(delete link)) if (defined('DATABASE_PREFIX') && $key == DATABASE_PREFIX.TABLE_NAME_SESSION.SELECT_TABLE_ID) { $tr->add($primaryKey); if (defined('LOGIN_ROLE_NAME') && (LOGIN_ROLE_NAME & ( RoleType::ROOT | RoleType::ADMIN ) ) ) { $td = new Td($css); $urlencode = true; if ($isHeader) { $params = "#"; //Params::get( array( REQUEST_SID=>"" ), $urlencode, __FILE__, __LINE__ ); $td = new Th($css); $text = "Sid"; $href = "./"; $class = $css; $title = "Reset"; $link = new Link($text, $href.$params, $class, $title); $td->add( $link ); } else { $params = Params::get( array( REQUEST_SID=>Encrypt::it($rawvalue) ), $urlencode,__FILE__, __LINE__ ); $text = substr($rawvalue, 0, 5); $href = ""; $class = $css; $title = $rawvalue; $link = new Link($text, $href.$params, $class, $title); $td->add( $link ); } $tr->add($td); } } else { $tr->add($this->newDataList($key, $value, $css, $isHeader, $id)); } } } } $object->add($tr); } else { // TODO what } return $object; } /** * Return the TEXT NO DATA, with a return link if Role name is unknown * Return a Create link if Role name is RoleType::VIEW_CREATE * If execute Create is allowed, then popup a new link to add the firt item * @return Tr The TR object is returned with associated data */ private function newNoData() { $object = new Tr(); if (defined('LOGIN_ROLE_NAME') && LOGIN_ROLE_NAME & RoleType::VIEW_CREATE) { $table = ""; $text = LINK_TEXT_INSERT; $link = $this->newLinkCreate(CSS_COLOR_LIGHT, $table, $text); $valign = ""; $colspan = ""; $object->add(new Td(CSS_COLOR_LIGHT.' '.CSS_ALIGN_RIGHT, $valign, $colspan, $link)); } else { $object->add($this->newTextRow(TEXT_NO_DATA, LINK_BACK)); } return $object; } /** * Return the content as an object * @return Object The content as an object */ function newContent() { $object = new Raw(); $numrows = $this->datareader->getNumRows(); if ($numrows > 0) { $this->text .= $this->text != '' ? " ($numrows)" : ""; $count = 0; $colspan = 0; $i = 0; foreach($this->datareader->getRows() as $no=>$row) { if ($i === 0) { $colspan = count($row); $isHeader = true; $object->add($this->newRow($row, CSS_COLOR_HEADER, $isHeader)); } $rowcolor = Rowcolor::get($count++); $object->add($this->newRow($row, $rowcolor)); $i++; } $object->add($this->newTotal($colspan)); } else { $object = $this->newNoData(); } return $object; } /** * Return the html * @return String The html */ function getHtml() { $html = $this->html; if (defined('DEBUG_LEVEL_SHOW_INFO') && DEBUG_LEVEL & DEBUG_LEVEL_SHOW_SQL) { $html .= "<p>".$this->getClassName()." - DEBUG</p>\r\n"; $html .= $this->datareader->getHtml(); } $this->add($this->newContent()); // Render it if ($this->text != '') { $html .= $this->getTableHeader(); } $form = null; $isTable = $this->isTable(); $command = Request::get(REQUEST_COMMAND); if ($isTable && ( $command === CRUD_VIEW_FORM_MULTIPLE || $command === CRUD_VIEW_FORM_CHECKBOX ) ) { $form = new Form('', Form::METHOD_POST); $html .= $form->getStart(); } $html .= $this->getStart(); $html .= $this->getEnd(); if ($isTable && $command === CRUD_VIEW_FORM_MULTIPLE) { $hiddens = $this->newHiddens(CRUD_VIEW_BASKET_CREATE); $buttons = $this->newButtons(); $html .= $hiddens->getHtml(); $html .= $buttons->getHtml(); $html .= $form->getEnd(); } if ($isTable && $command === CRUD_VIEW_FORM_CHECKBOX) { $hiddens = $this->newHiddens(CRUD_VIEW_FORM_CHECKBOX); $buttons = $this->newButtons(); $html .= $hiddens->getHtml(); $html .= $buttons->getHtml(); $html .= $form->getEnd(); } return $html; } /** * Display html * <code> * Usage: * ViewList::display($datareader, $text, $width, $class, $border, $cellpadding, $cellspacing, $summary, $caption, $layout); * </code> * @static * @param DataReader / array $datareader The Data Reader object OR an array * @param String $text The text header for the table * @param String $width The width of the table * @param String $class The class of the table * @param String $border The border of the table * @param String $cellpadding The CellSpacing * @param String $cellspacing The CellPadding * @param String $summary The Summary * @param String $caption The Caption * @param String $layout The layout to use */ public static function display($datareader=null, $text='', $width='', $class='', $border='', $cellpadding='', $cellspacing='', $summary='', $caption='', $layout='') { $html = new ViewList($datareader, $text, $width, $class, $border, $cellpadding, $cellspacing, $summary, $caption, $layout); $html->addHtml(); }}?>
Den fulde HTML kildekode for ViewList klassen
<? <!-- DEBUG: ViewList --> <!-- DEBUG: TableHeader --> <table width="100%" class="tableListView baseBorder" border="0" cellpadding="2" cellspacing="0"> <tr> <td class="baseArrowHeader" valign="middle"><!-- DEBUG: Link --> <a class="baseLinkColor" href="/source-code/mvc/ViewList/index.php" title="Klik her for at Minimere ... TableHeader"><!-- DEBUG: Images --> <img src="http://web-expert.dk/images/arrow-headline.gif" width="4" height="7" alt="arrow-headline.gif" /> </a> </td> <th class="baseColorHeader" valign="top" align="left">ViewList (1) </th> </tr> </table> <table id="ViewListId" width="100%" class="tableListView baseBorder" border="0" cellpadding="2" cellspacing="0"> <tr> <th class="baseColorHeader baseNoWrap" valign="top"> <!-- --> <!-- DEBUG: Sortby --> <!-- Privat telefon --><a class="baseColorHeader" href="/source-code/mvc/ViewList/index.php?mvcSORT_BY=asc&mvcORDER_BY=private_phone" title="Mvcorder_by desc">Privat telefon</a> </th> <th class="baseColorHeader baseNoWrap" valign="top"> <!-- --> <!-- DEBUG: Sortby --> <!-- Kontakt person --><a class="baseColorHeader" href="/source-code/mvc/ViewList/index.php?mvcSORT_BY=asc&mvcORDER_BY=contact_person" title="Mvcorder_by desc">Kontakt person</a> </th> <th class="baseColorHeader baseNoWrap" valign="top"> <!-- --> <!-- DEBUG: Sortby --> <!-- Firmanavn --><a class="baseColorHeader" href="/source-code/mvc/ViewList/index.php?mvcSORT_BY=asc&mvcORDER_BY=company_name" title="Mvcorder_by desc">Firmanavn</a> </th> <th class="baseColorHeader baseNoWrap" valign="top"> <!-- --> <!-- DEBUG: Sortby --> <!-- Adresse --><a class="baseColorHeader" href="/source-code/mvc/ViewList/index.php?mvcSORT_BY=asc&mvcORDER_BY=address" title="Mvcorder_by desc">Adresse</a> </th> <th class="baseColorHeader baseNoWrap" valign="top"> <!-- --> <!-- DEBUG: Sortby --> <!-- Postnr --><a class="baseColorHeader" href="/source-code/mvc/ViewList/index.php?mvcSORT_BY=asc&mvcORDER_BY=zip" title="Mvcorder_by desc">Postnr</a> </th> <th class="baseColorHeader baseNoWrap" valign="top"> <!-- --> <!-- DEBUG: Sortby --> <!-- By --><a class="baseColorHeader" href="/source-code/mvc/ViewList/index.php?mvcSORT_BY=asc&mvcORDER_BY=city" title="Mvcorder_by desc">By</a> </th> <th class="baseColorHeader baseNoWrap" valign="top"> <!-- --> <!-- DEBUG: Sortby --> <!-- Land --><a class="baseColorHeader" href="/source-code/mvc/ViewList/index.php?mvcSORT_BY=asc&mvcORDER_BY=country" title="Mvcorder_by desc">Land</a> </th> </tr> <tr> <td class="baseColorDark" valign="top">48246030 </td> <td class="baseColorDark" valign="top">Finn Rasmussen </td> <td class="baseColorDark" valign="top">HvepseEksperten.dk ApS </td> <td class="baseColorDark" valign="top">Kongens Vænge 79 </td> <td class="baseColorDark" valign="top">3400 </td> <td class="baseColorDark" valign="top">Hillerød </td> <td class="baseColorDark" valign="top">Denmark </td> </tr> </table> ?>
Her er 'klasse metoderne' for ViewList klassen:
Her er 'objekt variable' for ViewList klassen: