示例#1
0
 /**
  * Get records for a recordlist without actually rendering the recordlist.
  *
  * @param array $recordset the list of records
  * @param array $actions the default actions array
  * @param array $suppressList fields we don't display
  *
  * @return string The rendered recordlist
  */
 private function getRecordlistData($recordset, $actions, $suppressList = array())
 {
     $grid = $this->getGrid();
     $page = $this->getPage();
     $sm = SessionManager::getInstance();
     $edit = $grid->isEditing();
     $page->register_script(Config::getGlobal('assets_url') . 'javascript/recordlist.js');
     $listName = $grid->getName();
     $defaulthighlight = Config::getGlobal('highlight');
     $selectcolor = Config::getGlobal('select');
     /* retrieve list array */
     $list = $this->listArray($recordset, '', $actions, $suppressList);
     /* Check if some flags are still valid or not... */
     $hasMRA = $grid->hasFlag(DataGrid::MULTI_RECORD_ACTIONS);
     if ($hasMRA && (count($list['mra']) == 0 || count($list['rows']) == 0)) {
         $hasMRA = false;
     }
     $hasSearch = $grid->hasFlag(DataGrid::SEARCH) && !$grid->isEditing();
     if ($hasSearch && count($list['search']) == 0) {
         $hasSearch = false;
     }
     if ($grid->hasFlag(DataGrid::MULTI_RECORD_PRIORITY_ACTIONS) && (count($grid->getNode()->m_priority_actions) == 0 || count($list['rows']) == 0)) {
         $grid->removeFlag(DataGrid::MULTI_RECORD_PRIORITY_ACTIONS);
     } else {
         if ($grid->hasFlag(DataGrid::MULTI_RECORD_PRIORITY_ACTIONS)) {
             $grid->removeFlag(DataGrid::MULTI_RECORD_ACTIONS);
             if ($grid->getNode()->m_priority_max == 0) {
                 $grid->getNode()->m_priority_max = $grid->getNode()->m_priority_min + count($list['rows']) - 1;
             }
         }
     }
     $hasActionCol = $this->_hasActionColumn($list, $hasSearch);
     $orientation = Config::getGlobal('recordlist_orientation');
     /*         * *********** */
     /* HEADER ROW */
     /*         * *********** */
     $headercols = [];
     if ($hasActionCol && count($list['rows']) == 0) {
         if ($orientation == 'left' || $orientation == 'both') {
             // empty cell above search button, if zero rows
             // if $orientation is empty, no search button is shown, so no empty cell is needed
             $headercols[] = array('content' => ' ');
         }
     }
     if (!$edit && ($hasMRA || $grid->hasFlag(DataGrid::MULTI_RECORD_PRIORITY_ACTIONS))) {
         $headercols[] = array('content' => '');
         // Empty leader on top of mra action list.
     }
     if (($orientation == 'left' || $orientation == 'both') && ($hasActionCol && count($list['rows']) > 0)) {
         $headercols[] = array('content' => '');
     }
     foreach (array_values($list['heading']) as $head) {
         if (!$grid->hasFlag(DataGrid::SORT) || empty($head['order'])) {
             $headercols[] = array('content' => $head['title']);
         } else {
             $call = $grid->getUpdateCall(array('atkorderby' => $head['order'], 'atkstartat' => 0));
             $headercols[] = array('content' => $this->_getHeadingAnchorHtml($call, $head['title']));
         }
     }
     if (($orientation == 'right' || $orientation == 'both') && ($hasActionCol && count($list['rows']) > 0)) {
         $headercols[] = array('content' => '');
     }
     if ($hasActionCol && count($list['rows']) == 0) {
         if ($orientation == 'right' || $orientation == 'both') {
             // empty cell above search button, if zero rows
             // if $orientation is empty, no search button is shown, so no empty cell is needed
             $headercols[] = array('content' => ' ');
         }
     }
     /*         * *********** */
     /* SORT   ROW */
     /*         * *********** */
     $sortcols = [];
     $sortstart = '';
     $sortend = '';
     if ($grid->hasFlag(DataGrid::EXTENDED_SORT)) {
         $call = htmlentities($grid->getUpdateCall(array('atkstartat' => 0), [], 'ATK.DataGrid.extractExtendedSortOverrides'));
         $button = '<input type="button" value="' . Tools::atktext('sort') . '" onclick="' . $call . '">';
         if (!$edit && ($hasMRA || $grid->hasFlag(DataGrid::MULTI_RECORD_PRIORITY_ACTIONS))) {
             $sortcols[] = array('content' => '');
             // Empty leader on top of mra action list.
         }
         if ($orientation == 'left' || $orientation == 'both') {
             $sortcols[] = array('content' => $button);
         }
         foreach (array_keys($list['heading']) as $key) {
             if (isset($list['sort'][$key])) {
                 $sortcols[] = array('content' => $list['sort'][$key]);
             }
         }
         if ($orientation == 'right' || $orientation == 'both') {
             $sortcols[] = array('content' => $button);
         }
     }
     /*         * *********** */
     /* SEARCH ROW */
     /*         * *********** */
     $searchcols = [];
     $searchstart = '';
     $searchend = '';
     if ($hasSearch) {
         $call = htmlentities($grid->getUpdateCall(array('atkstartat' => 0), [], 'ATK.DataGrid.extractSearchOverrides'));
         $buttonType = $grid->isEmbedded() ? 'button' : 'submit';
         $button = '<input type="' . $buttonType . '" class="btn btn-default btn_search" value="' . Tools::atktext('search') . '" onclick="' . $call . ' return false;">';
         if ($grid->hasFlag(DataGrid::EXTENDED_SEARCH)) {
             $button .= ' ' . Tools::href(Config::getGlobal('dispatcher') . '?atknodeuri=' . $grid->getActionNode()->atkNodeUri() . '&atkaction=' . $grid->getActionNode()->getExtendedSearchAction(), '(' . Tools::atktext('search_extended') . ')', SessionManager::SESSION_NESTED);
         }
         $button = '<div class="search-buttons">' . $button . '</div>';
         // $searchstart = '<a name="searchform"></a>';
         $searchstart = '';
         if (!$edit && ($hasMRA || $grid->hasFlag(DataGrid::MULTI_RECORD_PRIORITY_ACTIONS))) {
             $searchcols[] = array('content' => '');
         }
         if ($orientation == 'left' || $orientation == 'both') {
             $searchcols[] = array('content' => $button);
         }
         foreach (array_keys($list['heading']) as $key) {
             if (isset($list['search'][$key])) {
                 $searchcols[] = array('content' => $list['search'][$key]);
             } else {
                 $searchcols[] = array('content' => '');
             }
         }
         if ($orientation == 'right' || $orientation == 'both') {
             $searchcols[] = array('content' => $button);
         }
     }
     /*         * **************************************** */
     /* MULTI-RECORD-(PRIORITY-)ACTIONS FORM DATA */
     /*         * **************************************** */
     $liststart = '';
     $listend = '';
     if (!$edit && ($hasMRA || $grid->hasFlag(DataGrid::MULTI_RECORD_PRIORITY_ACTIONS))) {
         $page->register_script(Config::getGlobal('assets_url') . 'javascript/formselect.js');
         if ($hasMRA) {
             $liststart .= '<script language="javascript" type="text/javascript">var ' . $listName . ' = new Object();</script>';
         }
     }
     /*         * ***** */
     /* ROWS */
     /*         * ***** */
     $records = [];
     $keys = array_keys($actions);
     $actionurl = count($actions) > 0 ? $actions[$keys[0]] : '';
     $actionloader = "rl_a['" . $listName . "'] = {};";
     $actionloader .= "\nrl_a['" . $listName . "']['base'] = '" . $sm->sessionVars($grid->getActionSessionStatus(), 1, $actionurl) . "';";
     $actionloader .= "\nrl_a['" . $listName . "']['embed'] = " . ($grid->isEmbedded() ? 'true' : 'false') . ';';
     for ($i = 0, $_i = count($list['rows']); $i < $_i; ++$i) {
         $record = [];
         /* Special rowColor method makes it possible to change the row color based on the record data.
          * the method can return a simple value (which will be used for the normal row color), or can be
          * an array, in which case the first element will be the normal row color, and the second the mouseover
          * row color, example: function rowColor(&$record, $num) { return array('red', 'blue'); }
          */
         $method = 'rowColor';
         $bgn = '';
         $bgh = $defaulthighlight;
         if (method_exists($grid->getNode(), $method)) {
             $bgn = $grid->getNode()->{$method}($recordset[$i], $i);
             if (is_array($bgn)) {
                 list($bgn, $bgh) = $bgn;
             }
         }
         $record['class'] = $grid->getNode()->rowClass($recordset[$i], $i);
         foreach ($grid->getNode()->getRowClassCallback() as $callback) {
             $record['class'] .= ' ' . call_user_func_array($callback, array($recordset[$i], $i));
         }
         /* alternate colors of rows */
         $record['background'] = $bgn;
         $record['highlight'] = $bgh;
         $record['rownum'] = $i;
         $record['id'] = $listName . '_' . $i;
         $record['type'] = $list['rows'][$i]['type'];
         /* multi-record-priority-actions -> priority selection */
         if (!$edit && $grid->hasFlag(DataGrid::MULTI_RECORD_PRIORITY_ACTIONS)) {
             $select = '<select name="' . $listName . '_atkselector[]" class="form-control select-standard">' . '<option value="' . htmlentities($list['rows'][$i]['selector']) . '"></option>';
             for ($j = $grid->getNode()->m_priority_min; $j <= $grid->getNode()->m_priority_max; ++$j) {
                 $select .= '<option value="' . $j . '">' . $j . '</option>';
             }
             $select .= '</select>';
             $record['cols'][] = array('content' => $select, 'type' => 'mrpa');
         } elseif (!$edit && $hasMRA) {
             if (count($list['rows'][$i]['mra']) > 0) {
                 switch ($grid->getMRASelectionMode()) {
                     case Node::MRA_SINGLE_SELECT:
                         $inputHTML = '<input type="radio" name="' . $listName . '_atkselector[]" value="' . $list['rows'][$i]['selector'] . '" class="atkradiobutton" onclick="if (this.disabled) this.checked = false">';
                         break;
                     case Node::MRA_NO_SELECT:
                         $inputHTML = '<input type="checkbox" disabled="disabled" checked="checked">' . '<input type="hidden" name="' . $listName . '_atkselector[]" value="' . $list['rows'][$i]['selector'] . '">';
                         break;
                     case Node::MRA_MULTI_SELECT:
                     default:
                         $inputHTML = '<input type="checkbox" name="' . $listName . '_atkselector[' . $i . ']" value="' . $list['rows'][$i]['selector'] . '" class="atkcheckbox" onclick="if (this.disabled) this.checked = false">';
                 }
                 $record['cols'][] = array('content' => $inputHTML . '
           <script language="javascript"  type="text/javascript">' . $listName . '["' . htmlentities($list['rows'][$i]['selector']) . '"] =
               new Array("' . implode($list['rows'][$i]['mra'], '","') . '");
           </script>', 'type' => 'mra');
             } else {
                 $record['cols'][] = array('content' => '');
             }
         } else {
             if ($edit && $list['rows'][$i]['edit']) {
                 $liststart .= '<input type="hidden" name="atkdatagriddata_AE_' . $i . '_AE_atkprimkey" value="' . htmlentities($list['rows'][$i]['selector']) . '">';
             }
         }
         $str_actions = '<span class="actions">';
         $actionloader .= "\nrl_a['" . $listName . "'][" . $i . '] = {};';
         $icons = Config::getGlobal('recordlist_icons');
         foreach ($list['rows'][$i]['actions'] as $name => $url) {
             if (substr($url, 0, 11) == 'javascript:') {
                 $call = substr($url, 11);
                 $actionloader .= "\nrl_a['{$listName}'][{$i}]['{$name}'] = function() { {$call}; };";
             } else {
                 $actionloader .= "\nrl_a['{$listName}'][{$i}]['{$name}'] = '{$url}';";
             }
             $module = $grid->getNode()->m_module;
             $nodetype = $grid->getNode()->m_type;
             $actionKeys = array('action_' . $module . '_' . $nodetype . '_' . $name, 'action_' . $nodetype . '_' . $name, 'action_' . $name, $name);
             $link = htmlentities($this->text($actionKeys));
             if ($icons == true) {
                 $normalizedName = strtolower(str_replace('-', '_', $name));
                 $icon = Config::get($module, 'icon_' . $nodetype . '_' . $normalizedName, false);
                 if (!$icon) {
                     $icon = Config::getGlobal('icon_' . $nodetype . '_' . $normalizedName, false);
                 }
                 if (!$icon) {
                     $icon = Config::getGlobal('icon_' . $normalizedName, false);
                 }
                 if ($icon) {
                     $link = '<i class="' . $icon . '" title="' . $link . '"></i>';
                 }
             }
             $confirmtext = 'false';
             if (Config::getGlobal('recordlist_javascript_delete') && $name == 'delete') {
                 $confirmtext = "'" . $grid->getNode()->confirmActionText($name) . "'";
             }
             $str_actions .= $this->_renderRecordActionLink($url, $link, $listName, $i, $name, $confirmtext);
         }
         $str_actions .= '</span>';
         /* actions (left) */
         if ($orientation == 'left' || $orientation == 'both') {
             if (!empty($list['rows'][$i]['actions'])) {
                 $record['cols'][] = array('content' => $str_actions, 'type' => 'actions');
             } else {
                 if ($hasActionCol) {
                     $record['cols'][] = array('content' => '');
                 }
             }
         }
         /* columns */
         foreach ($list['rows'][$i]['data'] as $html) {
             $record['cols'][] = array('content' => $html, 'type' => 'data');
         }
         /* actions (right) */
         if ($orientation == 'right' || $orientation == 'both') {
             if (!empty($list['rows'][$i]['actions'])) {
                 $record['cols'][] = array('content' => $str_actions, 'type' => 'actions');
             } else {
                 if ($hasActionCol) {
                     $record['cols'][] = array('content' => '');
                 }
             }
         }
         $records[] = $record;
     }
     $page->register_scriptcode($actionloader);
     $this->m_actionloader = $actionloader;
     /*************/
     /* TOTAL ROW */
     /*************/
     $totalcols = [];
     if (count($list['total']) > 0) {
         if (!$edit && ($hasMRA || $grid->hasFlag(DataGrid::MULTI_RECORD_PRIORITY_ACTIONS))) {
             $totalcols[] = array('content' => '');
         }
         if (($orientation == 'left' || $orientation == 'both') && ($hasActionCol && count($list['rows']) > 0)) {
             $totalcols[] = array('content' => '');
         }
         foreach (array_keys($list['heading']) as $key) {
             $totalcols[] = array('content' => isset($list['total'][$key]) ? $list['total'][$key] : '');
         }
         if (($orientation == 'right' || $orientation == 'both') && ($hasActionCol && count($list['rows']) > 0)) {
             $totalcols[] = array('content' => '');
         }
     }
     /*         * ********************************************** */
     /* MULTI-RECORD-PRIORITY-ACTION FORM (CONTINUED) */
     /*         * ********************************************** */
     $mra = '';
     if (!$edit && $grid->hasFlag(DataGrid::MULTI_RECORD_PRIORITY_ACTIONS)) {
         $target = $sm->sessionUrl(Config::getGlobal('dispatcher') . '?atknodeuri=' . $grid->getActionNode()->atkNodeUri(), SessionManager::SESSION_NESTED);
         /* multiple actions -> dropdown */
         if (count($grid->getNode()->m_priority_actions) > 1) {
             $mra = '<select name="' . $listName . '_atkaction" class="form-control select-standard">' . '<option value="">' . Tools::atktext('with_selected') . ':</option>';
             foreach ($grid->getNode()->m_priority_actions as $name) {
                 $mra .= '<option value="' . $name . '">' . Tools::atktext($name) . '</option>';
             }
             $mra .= '</select>&nbsp;' . $this->getCustomMraHtml() . '<input type="button" class="btn" value="' . Tools::atktext('submit') . '" onclick="atkSubmitMRPA(\'' . $listName . '\', this.form, \'' . $target . '\')">';
         } else {
             $mra = $this->getCustomMraHtml() . '<input type="hidden" name="' . $listName . '_atkaction" value="' . $grid->getNode()->m_priority_actions[0] . '">' . '<input type="button" class="btn" value="' . Tools::atktext($grid->getNode()->m_priority_actions[0]) . '" onclick="atkSubmitMRPA(\'' . $listName . '\', this.form, \'' . $target . '\')">';
         }
     } elseif (!$edit && $hasMRA) {
         $postvars = $grid->getNode()->m_postvars;
         $target = $sm->sessionUrl(Config::getGlobal('dispatcher') . '?atknodeuri=' . $grid->getNode()->atkNodeUri() . '&atktarget=' . (!empty($postvars['atktarget']) ? $postvars['atktarget'] : '') . '&atktargetvar=' . (!empty($postvars['atktargetvar']) ? $postvars['atktargetvar'] : '') . '&atktargetvartpl=' . (!empty($postvars['atktargetvartpl']) ? $postvars['atktargetvartpl'] : ''), SessionManager::SESSION_NESTED);
         $mra = count($list['rows']) > 1 && $grid->getMRASelectionMode() == Node::MRA_MULTI_SELECT ? '<a href="javascript:void(0)" onclick="updateSelection(\'' . $listName . '\', $(this).up(\'form\'), \'all\')">' . Tools::atktext('select_all') . '</a> | ' . '<a href="javascript:void(0)" onclick="updateSelection(\'' . $listName . '\', $(this).up(\'form\'), \'none\')">' . Tools::atktext('deselect_all') . '</a> | ' . '<a href="javascript:void(0)" onclick="updateSelection(\'' . $listName . '\', $(this).up(\'form\'), \'invert\')">' . Tools::atktext('select_invert') . '</a> ' : '';
         $module = $grid->getNode()->m_module;
         $nodetype = $grid->getNode()->m_type;
         /* multiple actions -> dropdown */
         if (count($list['mra']) > 1) {
             $default = $this->getGrid()->getMRADefaultAction();
             $mra .= '<select name="' . $listName . '_atkaction" onchange="javascript:updateSelectable(\'' . $listName . '\', this.form)" class="form-control select-standard">' . '<option value="">' . Tools::atktext('with_selected') . '</option>';
             foreach ($list['mra'] as $name) {
                 if ($grid->getNode()->allowed($name)) {
                     $actionKeys = array('action_' . $module . '_' . $nodetype . '_' . $name, 'action_' . $nodetype . '_' . $name, 'action_' . $name, $name);
                     $mra .= '<option value="' . $name . '"';
                     if ($default == $name) {
                         $mra .= 'selected="selected"';
                     }
                     $mra .= '>' . Tools::atktext($actionKeys, $grid->getNode()->m_module, $grid->getNode()->m_type) . '</option>';
                 }
             }
             $embedded = $this->getGrid()->isEmbedded() ? 'true' : 'false';
             $mra .= '</select>&nbsp;' . $this->getCustomMraHtml() . '<input type="button" class="btn" value="' . Tools::atktext('submit') . '" onclick="atkSubmitMRA(\'' . $listName . '\', this.form, \'' . $target . '\', ' . $embedded . ', false)">';
         } else {
             if ($grid->getNode()->allowed($list['mra'][0])) {
                 $name = $list['mra'][0];
                 $actionKeys = array('action_' . $module . '_' . $nodetype . '_' . $name, 'action_' . $nodetype . '_' . $name, 'action_' . $name, $name);
                 $embedded = $this->getGrid()->isEmbedded() ? 'true' : 'false';
                 $mra .= '<input type="hidden" name="' . $listName . '_atkaction" value="' . $name . '">' . $this->getCustomMraHtml() . '<input type="button" class="btn" value="' . Tools::atktext($actionKeys, $grid->getNode()->m_module, $grid->getNode()->m_type) . '" onclick="atkSubmitMRA(\'' . $listName . '\', this.form, \'' . $target . '\', ' . $embedded . ', false)">';
             }
         }
     } else {
         if ($edit) {
             $mra = '<input type="button" class="btn" value="' . Tools::atktext('save') . '" onclick="' . htmlentities($this->getGrid()->getSaveCall()) . '">';
         }
     }
     $recordListData = array('rows' => $records, 'header' => $headercols, 'search' => $searchcols, 'sort' => $sortcols, 'total' => $totalcols, 'searchstart' => $searchstart, 'searchend' => $searchend, 'sortstart' => $sortstart, 'sortend' => $sortend, 'liststart' => $liststart, 'listend' => $listend, 'listid' => $listName, 'mra' => $mra, 'editing' => $this->getGrid()->isEditing());
     // print_r($recordListData);
     return $recordListData;
 }