From 3ff03dc4f0a72432b34c00da620272cf011e4ddd Mon Sep 17 00:00:00 2001 From: Yuchen Pei Date: Thu, 29 Jul 2021 14:17:20 +1000 Subject: Publishing h-node.org code. - this is the h-node.org code, except - removed a js file (3x copies at three different locations) without license / copyright headers - /Js/linkToForm.js - /Public/Js/linkToForm.js - /admin/Public/Js/linkToForm.js - removed config files containing credentials - /Application/Include/params.php - /Config/Config.php - /admin/Application/Include/params.php - /admin/Config/Config.php - added license and copyright header to one php file - /admin/Library/ErrorReporting.php (almost identical to /Library/ErrorReporting.php which has the headers) --- h-source/Library/Helper/List.php | 288 +++++++-------------------------------- 1 file changed, 46 insertions(+), 242 deletions(-) (limited to 'h-source/Library/Helper/List.php') diff --git a/h-source/Library/Helper/List.php b/h-source/Library/Helper/List.php index 81b5345..ba59643 100755 --- a/h-source/Library/Helper/List.php +++ b/h-source/Library/Helper/List.php @@ -2,7 +2,7 @@ // EasyGiant is a PHP framework for creating and managing dynamic content // -// Copyright (C) 2009 - 2014 Antonio Gallo (info@laboratoriolibero.com) +// Copyright (C) 2009 - 2011 Antonio Gallo // See COPYRIGHT.txt and LICENSE.txt. // // This file is part of EasyGiant @@ -25,9 +25,6 @@ if (!defined('EG')) die('Direct access not allowed!'); //class to create the HTML of a list of records class Helper_List extends Helper_Html { - //table attributes - static public $tableAttributes = array('class'=>'listTable','cellspacing'=>'0'); - private $__rowArray = array(); //the current associative array representing the database record protected $_itemsList = array(); //2-dimensional associative array containing the list items @@ -37,7 +34,7 @@ class Helper_List extends Helper_Html { protected $_recordNumber = null; //number of records from the table - protected $_allowedItems = array('simpleLink','simpleText','delForm','editForm','associateForm','moveupForm','movedownForm','Form','ledit','link','text','checkbox','input'); //type of items allowed + protected $_allowedItems = array('simpleLink','simpleText','delForm','editForm','associateForm','moveupForm','movedownForm','Form','ledit','link','text'); //type of items allowed //it can be: both, top, bottom, none protected $_boundaries = 'none'; @@ -45,12 +42,6 @@ class Helper_List extends Helper_Html { //array of filters protected $_filters = array(); - //array of bulk actions - protected $_bulkActions = array(); - - //set to false if you don't want that the filters are created inside the table - public $showFilters = true; - //set if the submit buttons have to be images or not (it can be yse or not) public $submitImageType = 'yes'; @@ -63,6 +54,9 @@ class Helper_List extends Helper_Html { //properties of columns public $colProperties = array(); + //table attributes + public $tableAttributes = array('class'=>'listTable','cellspacing'=>'0'); + //$position: array. First element: page number, second element: number of pages public $position = array(); @@ -74,15 +68,12 @@ class Helper_List extends Helper_Html { public $pageArg = null; //the key of the viewArgs array representing the page number. $this->viewArgs[$this->pageArg] is set to 1 if $this->pageArg !== null - //if the filter forms have to be aggregated in a unique form or if they have to be left separated - public $aggregateFilters = false; - public function __construct() { //get the generic language class $this->strings = Factory_Strings::generic(Params::$language); - $baseUrl = Url::getRoot().'Public/Img/Icons/elementary_2_5/'; + $baseUrl = 'http://'.DOMAIN_NAME.'/Public/Img/Icons/elementary_2_5/'; //set the files of the images $this->submitImages = array( @@ -156,39 +147,17 @@ class Helper_List extends Helper_Html { //set the filters //$filters: array whose elements are the viewArgs to be used for the filters forms - //or null public function setFilters($filters) { $this->_filters = $filters; } - - //set $this->aggregateFilters equal to true - public function aggregateFilters() - { - $this->aggregateFilters = true; - } - - //set the bulk actions - //$bulkActions: associative array. - //key: class of the inputs whose elements have to be selected and serialized by javascript in the following way: data-primary-key:value_attribute|data-primary-key:value_attribute|data-primary-key:value_attribute|... - //value: array with two elements whose first element is the bulk action to be sent as a key of $_POST, second element is the human readable name of the action, third element can be the string "confirm" (if the user has to confirm the action) or undefined - //example: - // $bulkActions = array( - // "input_category_id_order" => array("sortAction","Sort elements"), - // "checkbox_category_id" => array("deleteAction","Delete elements","confirm"), - // ); - public function setBulkActions($bulkActions) - { - $this->_bulkActions = $bulkActions; - } //check that the ViewArgs array is complete public function checkViewArgs() { foreach ($this->_filters as $field) { - $key = !is_array($field) ? $field : $field[0]; - if (!array_key_exists($key,$this->viewArgs) and strcmp($key,null) !== 0) return false; + if (!array_key_exists($field,$this->viewArgs) and strcmp($field,null) !== 0) return false; } return true; } @@ -203,48 +172,47 @@ class Helper_List extends Helper_Html { public function replaceFields($string,$rowArray) { $this->__rowArray = $rowArray; //used by the replaceField method - $string = preg_replace_callback('/(\;)(.*?)(\;)/', array($this, 'replaceField') ,$string); + $string = preg_replace_callback('/(\;)(.*?)(\;)/', 'Helper_List::replaceField' ,$string); return $string; } - //get : or . as char used to separate table and field - public function getChar($string) - { - return strstr($string,':') ? ':' : '.'; - } - //replace a single string wrapped by ; with its correspondent value taken by the $recordArray associative array (a row of the select query) public function replaceField($match) { $string = $match[2]; - //check if a function has been indicated - if (strstr($string,'|')) - { - //get the function - $firstArray = explode('|',$string); - if (strstr($firstArray[1],':') or strstr($firstArray[1],'.')) + if (strstr($string,':') or strstr($string,'.')) { + if (strstr($string,':')) + { + $char = ':'; + } + else { + $char = '.'; + } + //check if a function has been indicated + if (strstr($string,'|')) + { + //get the function + $firstArray = explode('|',$string); $func = $firstArray[0]; //replace the fields - $char = $this->getChar($firstArray[1]); $temp = explode($char,$firstArray[1]); $string = $this->__rowArray[$temp[0]][$temp[1]]; - $string = callFunction($func,$string,__METHOD__); + if (!function_exists($func)) { + throw new Exception('Error in '.__METHOD__.': function '.$func.' does not exists..'); + } + //apply the function + $string = call_user_func($func,$string); } - } - else - { - if (strstr($string,':') or strstr($string,'.')) + else { - $char = $this->getChar($string); $temp = explode($char,$string); $string = $this->__rowArray[$temp[0]][$temp[1]]; } } - return $string; } @@ -259,8 +227,8 @@ class Helper_List extends Helper_Html { } //wrap the column with the tag td - public function wrapColumn($string, $className = null, $tag = "td") { - return wrap($string,array($tag=>$className)); + public function wrapColumn($string, $className = null) { + return wrap($string,array('td'=>$className)); } //wrap the row with the tag tr @@ -269,7 +237,7 @@ class Helper_List extends Helper_Html { } public function wrapList($string) { - return wrap($string,array('table'=>self::$tableAttributes)); + return wrap($string,array('table'=>$this->tableAttributes)); } //method to create the HTML of the head of the table @@ -280,18 +248,13 @@ class Helper_List extends Helper_Html { foreach ($this->_head as $item) { $temp = $item['action']; - if (preg_match('/\[\[bulkselect:(.*?)\]\]/',$temp,$matches)) - { - $temp = Html_Form::checkbox("bulkselect_".$matches[1],"","BS","bulk_select_checkbox",null,"data-class='".$matches[1]."'"); - } - $prop = $item['type']; if (isset($this->colProperties[$count])) { $prop = $this->colProperties[$count]; } - $htmlHead .= $this->wrapColumn($temp, $prop, "th"); + $htmlHead .= $this->wrapColumn($temp,$prop); $count++; } @@ -299,27 +262,7 @@ class Helper_List extends Helper_Html { return $htmlHead; } - //return an array with all the filters in a 1-dimensional array - public function getFiltersList() - { - $filterList = array(); - - foreach ($this->_filters as $f) - { - if (is_array($f)) - { - $filterList[] = $f[0]; - } - else - { - $filterList[] = $f; - } - } - - return $filterList; - } - - //method to create the HTML of the filters input + //method to create the HTML of the head of the table public function createFilters() { $htmlFilters = null; @@ -339,91 +282,18 @@ class Helper_List extends Helper_Html { $html = ' '; if (isset($this->_filters[$count])) { - if (!is_array($this->_filters[$count])) - { - $html = $this->filterForm($this->_filters[$count]); - } - else - { - $html = call_user_func_array(array($this,"filterForm"),$this->_filters[$count]); -// $html = $this->filterForm($this->_filters[$count][0],$this->_filters[$count][1]); - } - } - - //wrap single cell if filters doesn't have to be aggregate - if (!$this->aggregateFilters) - { - $htmlFilters .= !$this->showFilters ? $html : $this->wrapColumn($html,$prop); + $html = $this->filterForm($this->_filters[$count]); } - else - { - $htmlFilters .= $html; - } - + $htmlFilters .= $this->wrapColumn($html,$prop); + $count++; } - - //wrap an aggregate cell if filters have to be aggregate - if ($this->aggregateFilters) - { - $colspan = count($this->_itemsList); - $formTop = "
\n"; - $imgSrc = Url::getRoot('Public/Img/Icons/elementary_2_5/find.png'); - - $formBottom = ""; - $emptyFilterStatusArray = array(); - $filtersList = $this->getFiltersList(); - foreach ($this->viewArgs as $k => $v) - { - if (!in_array($k,$filtersList)) - { - $emptyFilterStatusArray[] = "$k=$v"; - $formBottom .= ""; - } - } - $emptyFilterStatus = implode("&",$emptyFilterStatusArray); - - $formBottom .= ""; - - $formBottom .= "\n"; - - $formBottom .= "
"; - - $htmlFilters = !$this->showFilters ? $formTop.$htmlFilters.$formBottom : $this->wrapColumn($formTop.$htmlFilters.$formBottom,array("class"=>"aggregate_filters_td","colspan"=>$colspan)); - - } } } return $htmlFilters; } - //create the HTML of the select of the bulk actions - public function createBulkActionsSelect() - { - $htmlBulkSelect = null; - $colspan = count($this->_itemsList); - - if (count($this->_bulkActions) > 0) - { - $htmlBulkSelect .= "".$this->strings->gtext('Actions').": "; - $htmlBulkSelect = $this->wrapColumn($htmlBulkSelect,array("class"=>"bulk_actions_td","colspan"=>$colspan)); - } - - return $htmlBulkSelect; - } - //create the HTML of a single row (values taken from the associative array $rowArray) public function getRowList($rowArray) { $htmlList = null; @@ -482,32 +352,16 @@ class Helper_List extends Helper_Html { $this->_recordNumber = count($queryResult); $htmlList = null; //create the HTML of the head of the record list - $htmlList .= "\n".$this->wrapRow($this->createHead(),'listHead')."\n"; + $htmlList .= $this->wrapRow($this->createHead(),'listHead'); //create the HTML of the filters - $htmlList .= "\n"; - - $bulkActionsHtml = $this->createBulkActionsSelect(); - if (isset($bulkActionsHtml)) - { - $htmlList .= $this->wrapRow($bulkActionsHtml,'bulk_actions_tr'); - } - - if ($this->showFilters) - { - $filtersHtml = $this->createFilters(); - if (isset($filtersHtml)) - { - $htmlList .= $this->wrapRow($filtersHtml,'listFilters'); - } - } - + $htmlList .= $this->wrapRow($this->createFilters(),'listFilters'); for ($i = 0; $i < count($queryResult); $i++) { $this->ifInBoundaries($i); $temp = $this->getRowList($queryResult[$i]); $htmlList .= $this->wrapRow($temp,'listRow'); } - return $this->wrapList($htmlList."\n"); + return $this->wrapList($htmlList); } public function generalForm($itemArray, $submitName, $submitValue) @@ -604,20 +458,8 @@ class Helper_List extends Helper_Html { return $string; } - //create the HTML of a checkbox - public function checkbox($itemArray) - { - return Html_Form::checkbox($itemArray['action'],$itemArray['field'],$itemArray['name'],"checkbox_".encode($itemArray['action']),null,"data-primary-key='".$itemArray['value']."'"); - } - - //create the HTML of an input text - public function input($itemArray) - { - return Html_Form::input($itemArray['action'],$itemArray['field'],"input_".encode($itemArray['action']),null,"data-primary-key='".$itemArray['name']."'"); - } - //create the HTML of the filter - public function filterForm($viewArgsName, $filterString = null, $filterValues = null) + public function filterForm($viewArgsName) { $cleanName = str_replace('n!',null,$viewArgsName); $cleanName = str_replace('-',null,$cleanName); @@ -632,15 +474,8 @@ class Helper_List extends Helper_Html { if (Params::$nullQueryValue) { $this->viewArgs[$viewArgsName] = Params::$nullQueryValue; - $viewStatus = Url::createUrl($this->viewArgs); - if (strcmp($value,Params::$nullQueryValue) === 0 and !isset($filterValues)) - { - $value = ''; - } - } - else - { - $viewStatus = $this->viewStatus; + $viewStatus = Url::createUrl(array_values($this->viewArgs)); + if (strcmp($value,Params::$nullQueryValue) === 0) $value = ''; } $this->viewArgs[$viewArgsName] = $temp; @@ -649,42 +484,11 @@ class Helper_List extends Helper_Html { $title = $this->strings->gtext('filter'); $clearLinkTitle = $this->strings->gtext('clear the filter'); - $html = null; - - if (!$this->aggregateFilters) - { - $html .= "
\n"; - } - - $html .= isset($filterString) ? " ".$filterString." " : null; - - if (!isset($filterValues)) - { - $html .= ""; - } - else - { - $filterValues = array_merge(array(Params::$nullQueryValue => $this->strings->gtext('All')),$filterValues); - $html .= Html_Form::select($viewArgsName,$value,$filterValues,"list_filter_input list_filter_input_$cleanName",null,"yes"); - } - - if (!$this->aggregateFilters) - { - $html .= ""; - $html .= "\n"; - - if (!Params::$rewriteStatusVariables) - { - foreach ($this->viewArgs as $k => $v) - { - if (strcmp($k,"$viewArgsName") !== 0) - { - $html .= ""; - } - } - } - $html .= "
\n"; - } + $html = "
\n"; + $html .= ""; + $html .= ""; + $html .= "\n"; + $html .= "
\n"; return $html; } -- cgit v1.2.3