"Fossies" - the Fresh Open Source Software Archive

Member "impresscms-1.4.2/htdocs/libraries/icms/ipf/view/Table.php" (24 Dec 2020, 25425 Bytes) of package /linux/www/impresscms-1.4.2.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) PHP source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "Table.php" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes reports: 1.4.2_rc_vs_1.4.2 or 1.4.1_vs_1.4.2.

    1 <?php
    2 /**
    3  * icms_ipf_Object Table Listing
    4  *
    5  * Contains the classes responsible for displaying a highly configurable and features rich listing of IcmseristableObject objects
    6  *
    7  * @copyright   The ImpressCMS Project http://www.impresscms.org/
    8  * @license     http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU General Public License (GPL)
    9  * @since       1.1
   10  * @author      marcan <marcan@impresscms.org>
   11  */
   12 
   13 defined('ICMS_ROOT_PATH') or die('ImpressCMS root path not defined');
   14 
   15 /**
   16  * icms_ipf_view_Table base class
   17  *
   18  * Base class representing a table for displaying icms_ipf_Object objects
   19  *
   20  * @copyright   The ImpressCMS Project http://www.impresscms.org/
   21  * @license     http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU General Public License (GPL)
   22  * @package ICMS\IPF\View
   23  * @since       1.1
   24  * @author      marcan <marcan@impresscms.org>
   25  * @todo        Properly declare all vars with their visibility (private, protected, public) and follow naming convention
   26  */
   27 class icms_ipf_view_Table {
   28 
   29     var $_id;
   30     var $_objectHandler;
   31     var $_columns;
   32     var $_criteria;
   33     var $_actions;
   34     var $_objects = false;
   35     var $_aObjects;
   36     var $_custom_actions;
   37     var $_sortsel;
   38     var $_ordersel;
   39     var $_limitsel;
   40     var $_filtersel;
   41     var $_filterseloptions;
   42     var $_filtersel2;
   43     var $_filtersel2options;
   44     var $_filtersel2optionsDefault;
   45 
   46     var $_tempObject;
   47     var $_tpl;
   48     var $_introButtons;
   49     var $_quickSearch = false;
   50     var $_actionButtons = false;
   51     var $_head_css_class = 'bg3';
   52     var $_hasActions = false;
   53     var $_userSide = false;
   54     var $_printerFriendlyPage = false;
   55     var $_tableHeader = false;
   56     var $_tableFooter = false;
   57     var $_showActionsColumnTitle = true;
   58     var $_isTree = false;
   59     var $_showFilterAndLimit = true;
   60     var $_enableColumnsSorting = true;
   61     var $_customTemplate = false;
   62     var $_withSelectedActions = array();
   63 
   64     /**
   65      * Constructor
   66      *
   67      * @param object $objectHandler {@link icms_ipf_Handler}
   68      * @param array $columns array representing the columns to display in the table
   69      * @param object $criteria
   70      * @param array $actions array representing the actions to offer
   71      *
   72      * @return array
   73      */
   74     public function __construct(&$objectHandler, $criteria = false, $actions = array('edit', 'delete'), $userSide = false) {
   75         $this->_id = $objectHandler->className;
   76         $this->_objectHandler = $objectHandler;
   77 
   78         if (!$criteria) {
   79             $criteria = new icms_db_criteria_Compo();
   80         }
   81         $this->_criteria = $criteria;
   82         $this->_actions = $actions;
   83         $this->_custom_actions = array();
   84         $this->_userSide = $userSide;
   85         if ($userSide) {
   86             $this->_head_css_class = 'head';
   87         }
   88     }
   89 
   90     /**
   91      *
   92      * @param $op
   93      * @param $caption
   94      * @param $text
   95      */
   96     public function addActionButton($op, $caption = false, $text = false) {
   97         $action = array(
   98                     'op' => $op,
   99                     'caption' => $caption,
  100                     'text' => $text
  101         );
  102         $this->_actionButtons[] = $action;
  103     }
  104 
  105     /**
  106      *
  107      * @param $columnObj
  108      */
  109     public function addColumn($columnObj) {
  110         $this->_columns[] = $columnObj;
  111     }
  112 
  113     /**
  114      *
  115      * @param $name
  116      * @param $location
  117      * @param $value
  118      */
  119     public function addIntroButton($name, $location, $value) {
  120         $introButton = array();
  121         $introButton['name'] = $name;
  122         $introButton['location'] = $location;
  123         $introButton['value'] = $value;
  124         $this->_introButtons[] = $introButton;
  125         unset($introButton);
  126     }
  127 
  128     /**
  129      *
  130      */
  131     public function addPrinterFriendlyLink() {
  132         global $impresscms;
  133 
  134         $current_url = $impresscms->urls['full'];
  135         $this->_printerFriendlyPage = $current_url . '&print';
  136     }
  137 
  138     /**
  139      *
  140      * @param $fields
  141      * @param $caption
  142      */
  143     public function addQuickSearch($fields, $caption = _CO_ICMS_QUICK_SEARCH) {
  144         $this->_quickSearch = array('fields' => $fields, 'caption' => $caption);
  145     }
  146 
  147     /**
  148      *
  149      * @param unknown_type $content
  150      */
  151     public function addHeader($content) {
  152         $this->_tableHeader = $content;
  153     }
  154 
  155     /**
  156      *
  157      * @param $content
  158      */
  159     public function addFooter($content) {
  160         $this->_tableFooter = $content;
  161     }
  162 
  163     /**
  164      *
  165      * @param $caption
  166      */
  167     public function addDefaultIntroButton($caption) {
  168         $this->addIntroButton($this->_objectHandler->_itemname, $this->_objectHandler->_page . "?op=mod", $caption);
  169     }
  170 
  171     /**
  172      *
  173      * @param $method
  174      */
  175     public function addCustomAction($method) {
  176         $this->_custom_actions[] = $method;
  177     }
  178 
  179     /**
  180      *
  181      * @param $default_sort
  182      */
  183     public function setDefaultSort($default_sort) {
  184         $this->_sortsel = $default_sort;
  185     }
  186 
  187     /**
  188      * get the default sorting
  189      */
  190     public function getDefaultSort() {
  191         return $this->getCookie(
  192             $this->_id . '_sortsel',
  193             $this->_sortsel ? : $this->_objectHandler->identifierName
  194         );
  195     }
  196 
  197 
  198     /**
  199      *
  200      * @param unknown_type $default_order
  201      */
  202     public function setDefaultOrder($default_order) {
  203         $this->_ordersel = $default_order;
  204     }
  205 
  206     /**
  207      * @return string the default order returned from a cookie
  208      */
  209     public function getDefaultOrder() {
  210         return $this->getCookie($this->_id . '_ordersel', $this->_ordersel ?: 'ASC');
  211     }
  212 
  213     /**
  214      *
  215      * @param $actions
  216      */
  217     public function addWithSelectedActions($actions = array()) {
  218         $this->addColumn(new icms_ipf_view_Column('checked', 'center', 20, false, false, '&nbsp;'));
  219         $this->_withSelectedActions = $actions;
  220     }
  221 
  222     /**
  223      * Adding a filter in the table
  224      *
  225      * @param string $key key to the field that will be used for sorting
  226      * @param string $method method of the handler that will be called to populate the options when this filter is selected
  227      */
  228     public function addFilter($key, $method, $default = false) {
  229         $this->_filterseloptions[$key] = $method;
  230         $this->_filtersel2optionsDefault = $default;
  231     }
  232 
  233     /**
  234      *
  235      * @param $default_filter
  236      */
  237     public function setDefaultFilter($default_filter) {
  238         $this->_filtersel = $default_filter;
  239     }
  240 
  241     /**
  242      *
  243      */
  244     public function isForUserSide() {
  245         $this->_userSide = true;
  246     }
  247 
  248     /**
  249      *
  250      * @param $template
  251      */
  252     public function setCustomTemplate($template) {
  253         $this->_customTemplate = $template;
  254     }
  255 
  256     /**
  257      *
  258      * @todo    Switch to dependency injection
  259      */
  260     public function setSortOrder() {
  261         $this->_sortsel = isset($_GET[$this->_objectHandler->_itemname . '_' . 'sortsel']) ? $_GET[$this->_objectHandler->_itemname . '_' . 'sortsel'] : $this->getDefaultSort();
  262         //$this->_sortsel = isset($_POST['sortsel']) ? $_POST['sortsel'] : $this->_sortsel;
  263 
  264         $this->setCookie($this->_id . '_sortsel', $this->_sortsel);
  265         $fieldsForSorting = $this->_tempObject->getFieldsForSorting($this->_sortsel);
  266 
  267         if (isset($this->_tempObject->vars[$this->_sortsel]['itemName'])) {
  268             $this->_criteria->setSort($this->_tempObject->vars[$this->_sortsel]['itemName'] . "." . $this->_sortsel);
  269         } else {
  270             $this->_criteria->setSort($this->_objectHandler->_itemname . "." . $this->_sortsel);
  271         }
  272 
  273         $this->_ordersel = isset($_GET[$this->_objectHandler->_itemname . '_' . 'ordersel']) ? $_GET[$this->_objectHandler->_itemname . '_' . 'ordersel'] : $this->getDefaultOrder();
  274         //$this->_ordersel = isset($_POST['ordersel']) ? $_POST['ordersel'] :$this->_ordersel;
  275         $this->setCookie($this->_id . '_ordersel', $this->_ordersel);
  276         $this->getOrdersArray();
  277         $this->_criteria->setOrder($this->_ordersel);
  278     }
  279 
  280     /**
  281      *
  282      * @param $id
  283      */
  284     public function setTableId($id) {
  285         $this->_id = $id;
  286     }
  287 
  288     /**
  289      *
  290      * @param $objects
  291      */
  292     public function setObjects($objects) {
  293         $this->_objects = $objects;
  294     }
  295 
  296     /**
  297      *
  298      */
  299     public function createTableRows() {
  300         $this->_aObjects = array();
  301 
  302         $doWeHaveActions = false;
  303 
  304         $objectclass = 'odd';
  305 
  306         if (count($this->_objects) > 0) {
  307             foreach ($this->_objects as $object) {
  308 
  309                 $aObject = array();
  310 
  311                 $i = 0;
  312 
  313                 $aColumns = array();
  314 
  315                 foreach ($this->_columns as $column) {
  316 
  317                     $aColumn = array();
  318 
  319                     if ($i==0) {
  320                         $class = "head";
  321                     } elseif ($i % 2 == 0) {
  322                         $class = "even";
  323                     } else {
  324                         $class = "odd";
  325                     }
  326                     if (method_exists($object, 'initiateCustomFields')) {
  327                         //$object->initiateCustomFields();
  328                     }
  329                     if ($column->_keyname == 'checked') {
  330                         $value = '<input type ="checkbox" name="selected_icms_persistableobjects[]" value="' . $object->id() . '" />';
  331                     } elseif ($column->_customMethodForValue && method_exists($object, $column->_customMethodForValue)) {
  332                         $method = $column->_customMethodForValue;
  333                         if ($column->_param) {
  334                             $value = $object->$method($column->_param);
  335                         } else {
  336                             $value = $object->$method();
  337                         }
  338                     } else {
  339                         /**
  340                          * If the column is the identifier, then put a link on it
  341                          */
  342                         if ($column->getKeyName() == $this->_objectHandler->identifierName) {
  343                             $value = $object->getViewItemLink(false, false, $this->_userSide);
  344                         } else {
  345                             $value = $object->getVar($column->getKeyName());
  346                         }
  347                     }
  348 
  349                     $aColumn['keyname'] = $column->getKeyName();
  350                     $aColumn['value'] = $value;
  351                     $aColumn['class'] = $class;
  352                     $aColumn['width'] = $column->getWidth();
  353                     $aColumn['align'] = $column->getAlign();
  354 
  355                     $aColumns[] = $aColumn;
  356                     $i++;
  357                 }
  358 
  359                 $aObject['columns'] = $aColumns;
  360                 $aObject['id'] = $object->id();
  361 
  362                 $objectclass = ($objectclass == 'even') ? 'odd' : 'even';
  363 
  364                 $aObject['class'] = $objectclass;
  365 
  366                 $actions = array();
  367 
  368                 // Adding the custom actions if any
  369                 foreach ($this->_custom_actions as $action) {
  370                     if (method_exists($object, $action)) {
  371                         $actions[] = $object->$action();
  372                     }
  373                 }
  374 
  375                 if ((!is_array($this->_actions)) || in_array('edit', $this->_actions)) {
  376                     $actions[] = $object->getEditItemLink(false, true, $this->_userSide);
  377                 }
  378                 if ((!is_array($this->_actions)) || in_array('delete', $this->_actions)) {
  379                     $actions[] = $object->getDeleteItemLink(false, true, $this->_userSide);
  380                 }
  381                 $aObject['actions'] = $actions;
  382 
  383                 $this->_tpl->assign('icms_actions_column_width', count($actions) * 30);
  384 
  385                 $doWeHaveActions = $doWeHaveActions ? true : count($actions) > 0;
  386 
  387                 $this->_aObjects[] = $aObject;
  388             }
  389             $this->_tpl->assign('icms_persistable_objects', $this->_aObjects);
  390         } else {
  391             $colspan = count($this->_columns) + 1;
  392             $this->_tpl->assign('icms_colspan', $colspan);
  393         }
  394         $this->_hasActions = $doWeHaveActions;
  395     }
  396 
  397     /**
  398      *
  399      * @param unknown_type $debug
  400      */
  401     public function fetchObjects($debug = false) {
  402         return $this->_objectHandler->getObjects($this->_criteria, true,true, false, $debug);
  403     }
  404 
  405     /**
  406      * @todo    change to dependency injection methods
  407      */
  408     public function getDefaultFilter() {
  409         return $this->getCookie($this->_id . '_filtersel', $this->_filtersel ?: 'default');
  410     }
  411 
  412     /**
  413      *
  414      */
  415     public function getFiltersArray() {
  416         $ret = array();
  417         $field = array();
  418         $field['caption'] = _CO_ICMS_NONE;
  419         $field['selected'] = '';
  420         $ret['default'] = $field;
  421         unset($field);
  422 
  423         if ($this->_filterseloptions) {
  424             foreach ($this->_filterseloptions as $key=>$value) {
  425                 $field = array();
  426                 if (is_array($value)) {
  427                     $field['caption'] = $key;
  428                     $field['selected'] = $this->_filtersel == $key ? "selected='selected'" : '';
  429                 } else {
  430                     $field['caption'] = $this->_tempObject->vars[$key]['form_caption'];
  431                     $field['selected'] = $this->_filtersel == $key ? "selected='selected'" : '';
  432                 }
  433                 $ret[$key] = $field;
  434                 unset($field);
  435             }
  436         } else {
  437             $ret = false;
  438         }
  439         return $ret;
  440     }
  441 
  442     /**
  443      *
  444      * @param unknown_type $default_filter2
  445      */
  446     public function setDefaultFilter2($default_filter2) {
  447         $this->_filtersel2 = $default_filter2;
  448     }
  449 
  450     /**
  451      * @todo    change to dependency injection methods
  452      */
  453     public function getDefaultFilter2() {
  454         return $this->getCookie('filtersel2', $this->_filtersel2 ?: 'default');
  455     }
  456      /**
  457       *
  458       */
  459     public function getFilters2Array() {
  460         $ret = array();
  461 
  462         foreach ($this->_filtersel2options as $key=>$value) {
  463             $field = array();
  464             $field['caption'] = $value;
  465             $field['selected'] = $this->_filtersel2 == $key ? "selected='selected'" : '';
  466             $ret[$key] = $field;
  467             unset($field);
  468         }
  469         return $ret;
  470     }
  471 
  472     /**
  473      *
  474      * @param $limitsArray
  475      * @param $params_of_the_options_sel
  476      */
  477     public function renderOptionSelection($limitsArray, $params_of_the_options_sel) {
  478         global $impresscms;
  479         // Rendering the form to select options on the table
  480         $current_url = $impresscms->urls['full'];
  481 
  482         /**
  483          * What was $params_of_the_options_sel doing again ?
  484          */
  485         //$this->_tpl->assign('icms_optionssel_action', $_SERVER['SCRIPT_NAME'] . "?" . implode('&', $params_of_the_options_sel));
  486         $this->_tpl->assign('icms_optionssel_action', $current_url);
  487         $this->_tpl->assign('icms_optionssel_limitsArray', $limitsArray);
  488     }
  489 
  490     /**
  491      *
  492      */
  493     public function getLimitsArray() {
  494         $ret = array();
  495         $ret['all']['caption'] = _CO_ICMS_LIMIT_ALL;
  496         $ret['all']['selected'] = ('all' == $this->_limitsel) ? "selected='selected'" : "";
  497 
  498         $ret['5']['caption'] = icms_conv_nr2local('5');
  499         $ret['5']['selected'] = ('5' == $this->_limitsel) ? "selected='selected'" : "";
  500 
  501         $ret['10']['caption'] = icms_conv_nr2local('10');
  502         $ret['10']['selected'] = ('10' == $this->_limitsel) ? "selected='selected'" : "";
  503 
  504         $ret['15']['caption'] = icms_conv_nr2local('15');
  505         $ret['15']['selected'] = ('15' == $this->_limitsel) ? "selected='selected'" : "";
  506 
  507         $ret['20']['caption'] = icms_conv_nr2local('20');
  508         $ret['20']['selected'] = ('20' == $this->_limitsel) ? "selected='selected'" : "";
  509 
  510         $ret['25']['caption'] = icms_conv_nr2local('25');
  511         $ret['25']['selected'] = ('25' == $this->_limitsel) ? "selected='selected'" : "";
  512 
  513         $ret['30']['caption'] = icms_conv_nr2local('30');
  514         $ret['30']['selected'] = ('30' == $this->_limitsel) ? "selected='selected'" : "";
  515 
  516         $ret['35']['caption'] = icms_conv_nr2local('35');
  517         $ret['35']['selected'] = ('35' == $this->_limitsel) ? "selected='selected'" : "";
  518 
  519         $ret['40']['caption'] = icms_conv_nr2local('40');
  520         $ret['40']['selected'] = ('40' == $this->_limitsel) ? "selected='selected'" : "";
  521         return $ret;
  522     }
  523 
  524     /**
  525      *
  526      */
  527     public function getObjects() {
  528         return $this->_objects;
  529     }
  530 
  531     /**
  532      *
  533      */
  534     public function hideActionColumnTitle() {
  535         $this->_showActionsColumnTitle = false;
  536     }
  537 
  538     /**
  539      *
  540      */
  541     public function hideFilterAndLimit() {
  542         $this->_showFilterAndLimit = false;
  543     }
  544 
  545     /**
  546      *
  547      */
  548     public function getOrdersArray() {
  549         $ret = array();
  550         $ret['ASC']['caption'] = _CO_ICMS_SORT_ASC;
  551         $ret['ASC']['selected'] = ('ASC' == $this->_ordersel) ? "selected='selected'" : "";
  552 
  553         $ret['DESC']['caption'] = _CO_ICMS_SORT_DESC;
  554         $ret['DESC']['selected'] = ('DESC' == $this->_ordersel) ? "selected='selected'" : "";
  555 
  556         return $ret;
  557     }
  558 
  559     /**
  560      *
  561      */
  562     public function renderD() {
  563         return $this->render(false, true);
  564     }
  565 
  566     /**
  567      *
  568      */
  569     public function renderForPrint() {
  570 
  571     }
  572 
  573     /**
  574      * Gets from cookie
  575      *
  576      * @param string $fieldName Field name read from cookie
  577      * @param string|null $defaultValue Default value
  578      *
  579      * @return string
  580      */
  581     protected function getCookie($fieldName, $defaultValue = null) {
  582         $name = 'tbl_' . str_replace('.', '_', $fieldName);
  583 
  584         return isset($_COOKIE[$name]) ? $_COOKIE[$name] : $defaultValue;
  585     }
  586 
  587     /**
  588      * Sets cookie
  589      *
  590      * @param string $fieldName
  591      * @param string $value
  592      */
  593     protected function setCookie($fieldName, $value) {
  594         setcookie(
  595             'tbl_' . $fieldName,
  596             $value,
  597             time() + 3600 * 24 * 365,
  598             parse_url(ICMS_URL, PHP_URL_PATH),
  599             parse_url(ICMS_URL, PHP_URL_HOST),
  600             false,
  601             true
  602         );
  603     }
  604 
  605     /**
  606      * Render the table of records for an IPF object
  607      *
  608      * @todo    change to dependency injection methods
  609      * @todo    remove the rest of the HTML and move it to the templates
  610      *
  611      * @param $fetchOnly
  612      * @param $debug
  613      */
  614     public function render($fetchOnly = false, $debug = false) {
  615         global $impresscms;
  616 
  617         /* Filters. First, some variable variables */
  618         $start = 'start' . $this->_objectHandler->keyName;
  619         $sortsel = $this->_objectHandler->_itemname . '_' . 'sortsel';
  620         $ordersel = $this->_objectHandler->_itemname . '_' . 'ordersel';
  621         $quicksearch = 'quicksearch_' . $this->_id;
  622 
  623         $filter_get = array(
  624                 $start => 'int',
  625                 'limitsel' => 'int',
  626                 'filtersel' => 'str',
  627                 'filtersel2' => 'str',
  628                 $sortsel => 'str',
  629                 $ordersel => 'str',
  630                 $quicksearch => 'special',
  631                 'fct' => 'str',
  632         );
  633 
  634         $filter_post = array(
  635                 'limitsel' => 'int',
  636                 'filtersel' => 'str',
  637                 'filtersel2' => 'str',
  638                 $quicksearch => 'special',
  639                 'fct' => 'str',
  640         );
  641 
  642         $filter_server = array(
  643                 'SCRIPT_NAME' => 'str',
  644         );
  645         /* default values */
  646         $$start = 0;
  647         $limitsel = 15;
  648         $filtersel = $this->getDefaultFilter();
  649         $filtersel2 = $this->getDefaultFilter2();
  650         $$sortsel = $$ordersel = '';
  651         $$quicksearch = '';
  652 
  653         /* filter the user input - only allow specified variables */
  654         if (!empty($_GET)) {
  655             $clean_GET = icms_core_DataFilter::checkVarArray($_GET, $filter_get, true);
  656             extract($clean_GET);
  657         }
  658         if (!empty($_POST)) {
  659             $clean_POST = icms_core_DataFilter::checkVarArray($_POST, $filter_post, true);
  660             extract($clean_POST);
  661         }
  662 
  663         $server_vars = icms_core_DataFilter::checkVarArray($_SERVER, $filter_server, true);
  664         $script_name = $server_vars['SCRIPT_NAME'];
  665 
  666         $this->_tpl = new icms_view_Tpl();
  667 
  668         /**
  669          * We need access to the protected vars of the icms_ipf_Object for a few things in the table creation.
  670          * Since we may not have an icms_ipf_Object to look into now, let's create one for this purpose
  671          * and we will free it after
  672          */
  673         $this->_tempObject =& $this->_objectHandler->create();
  674 
  675         $this->_criteria->setStart($$start);
  676 
  677         $this->setSortOrder();
  678 
  679         $this->_limitsel = isset($_GET['limitsel'])  ? $_GET['limitsel'] :  $this->getCookie('limitsel', '15');
  680 
  681         if ($this->_isTree) {
  682             $this->_limitsel = 'all';
  683         }
  684 
  685         $this->setCookie('limitsel', $this->_limitsel);
  686 
  687         $limitsArray = $this->getLimitsArray();
  688         $this->_criteria->setLimit($this->_limitsel);
  689 
  690         $this->_filtersel = $filtersel;
  691 
  692         $this->setCookie($this->_id . '_filtersel', $this->_filtersel);
  693         $filtersArray = $this->getFiltersArray();
  694 
  695         if ($filtersArray) {
  696             $this->_tpl->assign('icms_optionssel_filtersArray', $filtersArray);
  697         }
  698 
  699         // Check if the selected filter is defined and if so, create the selfilter2
  700         if (!empty($this->_filterseloptions[$this->_filtersel])) {
  701             // check if method associate with this filter exists in the handler
  702             if (is_array($this->_filterseloptions[$this->_filtersel])) {
  703                 $filter = $this->_filterseloptions[$this->_filtersel];
  704                 $this->_criteria->add($filter['criteria']);
  705             } else {
  706                 if (method_exists($this->_objectHandler, $this->_filterseloptions[$this->_filtersel])) {
  707 
  708                     // then we will create the selfilter2 options by calling this method
  709                     $method = $this->_filterseloptions[$this->_filtersel];
  710                     $this->_filtersel2options = $this->_objectHandler->$method();
  711 
  712                     $this->_filtersel2 = $filtersel2;
  713 
  714                     $filters2Array = $this->getFilters2Array();
  715                     $this->_tpl->assign('icms_optionssel_filters2Array', $filters2Array);
  716 
  717                     $this->setCookie('filtersel2', $this->_filtersel2);
  718                     if ($this->_filtersel2 !== 'default') {
  719                         $this->_criteria->add(new icms_db_criteria_Item($this->_filtersel, $this->_filtersel2));
  720                     }
  721                 }
  722             }
  723         }
  724         // Check if we have a quicksearch
  725 
  726         if (!empty($$quicksearch)) {
  727             $quicksearch_criteria = new icms_db_criteria_Compo();
  728             if (is_array($this->_quickSearch['fields'])) {
  729                 foreach ($this->_quickSearch['fields'] as $v) {
  730                     $quicksearch_criteria->add(new icms_db_criteria_Item($v, '%' . $$quicksearch . '%', 'LIKE'), 'OR');
  731                 }
  732             } else {
  733                 $quicksearch_criteria->add(new icms_db_criteria_Item($this->_quickSearch['fields'], '%' . $$quicksearch . '%', 'LIKE'));
  734             }
  735             $this->_criteria->add($quicksearch_criteria);
  736         }
  737 
  738         $this->_objects = $this->fetchObjects($debug);
  739 
  740         /**
  741          * $params_of_the_options_sel is an array with all the parameters of the page
  742          * but without the pagenave parameters. This array will be used in the
  743          * OptionsSelection
  744          */
  745         $params_of_the_options_sel = array();
  746         if ($this->_criteria->getLimit() > 0) {
  747 
  748             /**
  749              * Geeting rid of the old params
  750              * $new_get_array is an array containing the new GET parameters
  751              */
  752             $new_get_array = array();
  753 
  754             $not_needed_params = array('sortsel', 'limitsel', 'ordersel', 'start' . $this->_objectHandler->keyName);
  755             foreach ($clean_GET as $k => $v) {
  756                 if (!in_array($k, $not_needed_params)) {
  757                     $new_get_array[] = "$k=$v";
  758                     $params_of_the_options_sel[] = "$k=$v";
  759                 }
  760             }
  761 
  762             /**
  763              * Adding the new params of the pagenav
  764              */
  765             $new_get_array[] = "sortsel=" . $this->_sortsel;
  766             $new_get_array[] = "ordersel=" . $this->_ordersel;
  767             $new_get_array[] = "limitsel=" . $this->_limitsel;
  768             $otherParams = implode('&', $new_get_array);
  769 
  770             $pagenav = new icms_view_PageNav($this->_objectHandler->getCount($this->_criteria), $this->_criteria->getLimit(), $this->_criteria->getStart(), 'start' . $this->_objectHandler->keyName, $otherParams);
  771             $this->_tpl->assign('icms_pagenav', $pagenav->renderNav());
  772         }
  773         $this->renderOptionSelection($limitsArray, $params_of_the_options_sel);
  774 
  775         // retreive the current url and the query string
  776         $current_url = $impresscms->urls['full_phpself'];
  777         $query_string = $impresscms->urls['querystring'];
  778         if ($query_string) {
  779             $query_string = str_replace('?', '',$query_string);
  780         }
  781         $query_stringArray = explode('&', $query_string);
  782         $new_query_stringArray = array();
  783         foreach ($query_stringArray as $query_string) {
  784             if (strpos($query_string, 'sortsel') == FALSE && strpos($query_string, 'ordersel') == FALSE) {
  785                 $new_query_stringArray[] = $query_string;
  786             }
  787         }
  788         $new_query_string = implode('&', $new_query_stringArray);
  789 
  790         $orderArray = array();
  791         $orderArray['ASC']['image'] = 'desc.png';
  792         $orderArray['ASC']['neworder'] = 'DESC';
  793         $orderArray['DESC']['image'] = 'asc.png';
  794         $orderArray['DESC']['neworder'] = 'ASC';
  795 
  796         $aColumns = array();
  797 
  798         foreach ($this->_columns as $column) {
  799             $aColumn = array();
  800             $aColumn['width'] = $column->getWidth();
  801             $aColumn['align'] = $column->getAlign();
  802             $aColumn['key'] = $column->getKeyName();
  803 
  804             if ($column->_keyname == 'checked') {
  805                 $aColumn['caption'] = '<input type ="checkbox" id="checkall_icmspersistableobjects" name="checkall_icmspersistableobjects"' .
  806                         ' value="checkall_icmspersistableobjects" onclick="icms_checkall(window.document.form_' . $this->_id . ', \'selected_icmspersistableobjects\');" />';
  807             } elseif ($column->getCustomCaption()) {
  808                 $aColumn['caption'] = $column->getCustomCaption();
  809             } else {
  810                 $aColumn['caption'] = $this->_tempObject->getVarInfo($column->getKeyName(), 'form_caption') ? $this->_tempObject->getVarInfo($column->getKeyName(), 'form_caption') : $column->getKeyName();
  811             }
  812             // Are we doing a GET sort on this column ?
  813             $getSort = (!empty($$sortsel) && $$sortsel == $column->getKeyName()) || ($this->_sortsel == $column->getKeyName());
  814             $order = !empty($$ordersel) ? $$ordersel : 'DESC';
  815 
  816             if (!empty($$quicksearch)) {
  817                 $filter = !empty($$quicksearch) ? INPUT_POST : INPUT_GET;
  818                 $qs_param = "&amp;quicksearch_".$this->_id."=".filter_input($filter, 'quicksearch_' . $this->_id, FILTER_SANITIZE_SPECIAL_CHARS);
  819             } else {
  820                 $qs_param = '';
  821             }
  822             if (!$this->_enableColumnsSorting || $column->_keyname == 'checked' || !$column->_sortable) {
  823                 $aColumn['caption'] =  $aColumn['caption'];
  824             } elseif ($getSort) {
  825                 $aColumn['caption'] =  '<a href="' . $current_url . '?' . $this->_objectHandler->_itemname . '_' . 'sortsel=' . $column->getKeyName() . '&amp;' . $this->_objectHandler->_itemname . '_' . 'ordersel=' . $orderArray[$order]['neworder'] . $qs_param . '&amp;' . $new_query_string . '">' . $aColumn['caption'] . ' <img src="' . ICMS_IMAGES_SET_URL .'/actions/' . $orderArray[$order]['image'] . '" alt="ASC" /></a>';
  826             } else {
  827                 $aColumn['caption'] =  '<a href="' . $current_url . '?' . $this->_objectHandler->_itemname . '_' . 'sortsel=' . $column->getKeyName() . '&amp;' . $this->_objectHandler->_itemname . '_' . 'ordersel=ASC' . $qs_param . '&amp;' . $new_query_string . '">' . $aColumn['caption'] . '</a>';
  828             }
  829             $aColumns[] = $aColumn;
  830         }
  831         $this->_tpl->assign('icms_columns', $aColumns);
  832 
  833         if ($this->_quickSearch) {
  834             $this->_tpl->assign('icms_quicksearch', $this->_quickSearch['caption']);
  835         }
  836 
  837         $this->createTableRows();
  838 
  839         $this->_tpl->assign('icms_showFilterAndLimit', $this->_showFilterAndLimit);
  840         $this->_tpl->assign('icms_isTree', $this->_isTree);
  841         $this->_tpl->assign('icms_show_action_column_title', $this->_showActionsColumnTitle);
  842         $this->_tpl->assign('icms_table_header', $this->_tableHeader);
  843         $this->_tpl->assign('icms_table_footer', $this->_tableFooter);
  844         $this->_tpl->assign('icms_printer_friendly_page', $this->_printerFriendlyPage);
  845         $this->_tpl->assign('icms_user_side', $this->_userSide);
  846         $this->_tpl->assign('icms_has_actions', $this->_hasActions);
  847         $this->_tpl->assign('icms_head_css_class', $this->_head_css_class);
  848         $this->_tpl->assign('icms_actionButtons', $this->_actionButtons);
  849         $this->_tpl->assign('icms_introButtons', $this->_introButtons);
  850         $this->_tpl->assign('icms_id', $this->_id);
  851         if (!empty($this->_withSelectedActions)) {
  852             $this->_tpl->assign('icms_withSelectedActions', $this->_withSelectedActions);
  853         }
  854 
  855         $icms_table_template = $this->_customTemplate ? $this->_customTemplate : 'system_persistabletable_display.html';
  856         if ($fetchOnly) {
  857             return $this->_tpl->fetch('db:' . $icms_table_template);
  858         } else {
  859             $this->_tpl->display('db:' . $icms_table_template);
  860         }
  861     }
  862 
  863     /**
  864      *
  865      */
  866     public function disableColumnsSorting() {
  867         $this->_enableColumnsSorting = false;
  868     }
  869 
  870     /**
  871      *
  872      * @param $debug
  873      */
  874     public function fetch($debug = false) {
  875         return $this->render(true, $debug);
  876     }
  877 }
  878