/**
  * This function returns all not expired records from one category
  *
  * @param integer $categoryId Category ID
  * @param string  $orderby    Order by
  * @param string  $sortby     Sorty by
  *
  * @return string
  */
 public function showAllRecords($categoryId, $orderby = 'id', $sortby = 'ASC')
 {
     global $sids;
     $numPerPage = $this->_config->get('records.numberOfRecordsPerPage');
     $page = PMF_Filter::filterInput(INPUT_GET, 'seite', FILTER_VALIDATE_INT, 1);
     $output = '';
     $title = '';
     if ($orderby == 'visits') {
         $currentTable = 'fv';
     } else {
         $currentTable = 'fd';
     }
     // If random FAQs are activated, we don't need an order
     if (true === $this->_config->get('records.randomSort')) {
         $order = '';
     } else {
         $order = sprintf("ORDER BY fd.sticky DESC, %s.%s %s", $currentTable, $this->_config->getDb()->escape($orderby), $this->_config->getDb()->escape($sortby));
     }
     $now = date('YmdHis');
     $query = sprintf("\n            SELECT\n                fd.id AS id,\n                fd.lang AS lang,\n                fd.sticky AS sticky,\n                fd.thema AS thema,\n                fcr.category_id AS category_id,\n                fv.visits AS visits\n            FROM\n                %sfaqdata AS fd\n            LEFT JOIN\n                %sfaqcategoryrelations AS fcr\n            ON\n                fd.id = fcr.record_id\n            AND\n                fd.lang = fcr.record_lang\n            LEFT JOIN\n                %sfaqvisits AS fv\n            ON\n                fd.id = fv.id\n            AND\n                fv.lang = fd.lang\n            LEFT JOIN\n                %sfaqdata_group AS fdg\n            ON\n                fd.id = fdg.record_id\n            LEFT JOIN\n                %sfaqdata_user AS fdu\n            ON\n                fd.id = fdu.record_id\n            WHERE\n                fd.date_start <= '%s'\n            AND\n                fd.date_end   >= '%s'\n            AND\n                fd.active = 'yes'\n            AND\n                fcr.category_id = %d\n            AND\n                fd.lang = '%s'\n            %s\n            %s", PMF_Db::getTablePrefix(), PMF_Db::getTablePrefix(), PMF_Db::getTablePrefix(), PMF_Db::getTablePrefix(), PMF_Db::getTablePrefix(), $now, $now, $categoryId, $this->_config->getLanguage()->getLanguage(), $this->queryPermission($this->groupSupport), $order);
     $result = $this->_config->getDb()->query($query);
     $num = $this->_config->getDb()->numRows($result);
     $pages = (int) ceil($num / $numPerPage);
     if ($page == 1) {
         $first = 0;
     } else {
         $first = $page * $numPerPage - $numPerPage;
     }
     if ($num > 0) {
         if ($pages > 1) {
             $output .= sprintf('<p><strong>%s %s %s</strong></p>', $this->pmf_lang['msgPage'] . $page, $this->pmf_lang['msgVoteFrom'], $pages . $this->pmf_lang['msgPages']);
         }
         $output .= '<ul class="phpmyfaq_ul">';
         $counter = 0;
         $displayedCounter = 0;
         $renderedItems = array();
         while (($row = $this->_config->getDb()->fetchObject($result)) && $displayedCounter < $numPerPage) {
             $counter++;
             if ($counter <= $first) {
                 continue;
             }
             $displayedCounter++;
             if (empty($row->visits)) {
                 $visits = 0;
             } else {
                 $visits = $row->visits;
             }
             $title = $row->thema;
             $url = sprintf('%s?%saction=artikel&amp;cat=%d&amp;id=%d&amp;artlang=%s', PMF_Link::getSystemRelativeUri(), $sids, $row->category_id, $row->id, $row->lang);
             $oLink = new PMF_Link($url, $this->_config);
             $oLink->itemTitle = $oLink->text = $oLink->tooltip = $title;
             // If random FAQs are activated, we don't need sticky FAQs
             if (true === $this->_config->get('records.randomSort')) {
                 $row->sticky = 0;
             }
             $renderedItems[$row->id] = sprintf('<li%s>%s<span id="viewsPerRecord"><br /><small>(%s)</small></span></li>', $row->sticky == 1 ? ' class="sticky-faqs"' : '', $oLink->toHtmlAnchor(), $this->plr->GetMsg('plmsgViews', $visits));
         }
         // If random FAQs are activated, shuffle the FAQs :-)
         if (true === $this->_config->get('records.randomSort')) {
             shuffle($renderedItems);
         }
         $output .= implode("\n", $renderedItems);
         $output .= '</ul><span class="totalFaqRecords hide">' . $num . '</span>';
     } else {
         return false;
     }
     if ($pages > 1) {
         // Set rewrite URL, if needed
         if ($this->_config->get('main.enableRewriteRules')) {
             $link = new PMF_Link(PMF_Link::getSystemRelativeUri('index.php'), $this->_config);
             $useRewrite = true;
             $rewriteUrl = sprintf("%scategory/%d/%%d/%s.html", PMF_Link::getSystemRelativeUri('index.php'), $categoryId, $link->getSEOItemTitle($title));
         } else {
             $useRewrite = false;
             $rewriteUrl = '';
         }
         $baseUrl = sprintf("%s?%saction=show&amp;cat=%d&amp;seite=%d", PMF_Link::getSystemRelativeUri(), empty($sids) ? '' : $sids, $categoryId, $page);
         $options = array('baseUrl' => $baseUrl, 'total' => $num, 'perPage' => $this->_config->get('records.numberOfRecordsPerPage'), 'useRewrite' => $useRewrite, 'rewriteUrl' => $rewriteUrl, 'pageParamName' => 'seite');
         $pagination = new PMF_Pagination($this->_config, $options);
         $output .= $pagination->render();
     }
     return $output;
 }