Cs-Cart admin pagination

Notes on how pagination is done in admin section of cs-cart.

In the controller:

if ($mode == 'under') {
 
    $params = $_REQUEST;
    $params['paginate'] = true;
    if (!empty($params['paginate'])) {
        $params['page'] = empty($params['page']) ? 1 : $params['page'];
        $params['total_items'] = db_get_field("HERE GOES THE TOTAL LINES COUNT QUERY", DESCR_SL
        );
        $params['items_per_page'] = $params['items_per_page'] ? $params['items_per_page'] : Registry::get('settings.Appearance.admin_elements_per_page');
        $limit = db_paginate(
            $params['page'], 
            $params['items_per_page']
            );
    }
    $rows = db_get_array("SELECT ...[HERE GOES THE ROW SELECTION QUERY AND limit IS ADDED ON THE END]... $limit", DESCR_SL
    );
    Registry::get('view')->assign('search', $params);
    Registry::get('view')->assign('rows', $rows);
}

In the corresponding view:

{capture name="mainbox"}
 
<div id="content_manage_undercost">
 
<form action="{""|fn_url}" method="post" name="shopfeed_form" class="cm-hide-inputs">
<input type="hidden" name="fake" value="1" />
 
{include file="common/pagination.tpl" save_current_page=true save_current_url=true div_id=$smarty.request.content_id}
 
{if $rows}
  <table cellpadding="0" cellspacing="0" border="0" width="100%" class="table sortable hidden-inputs">
    <tr>
      <th>Product</th>
      <th>Cost</th>
      <th>Price</th>
    </tr>
      {foreach from=$rows item="row"}
        <tr {cycle values="class=\"table-row\", "}>
          <td><a href="{"products.update?product_id=`$row.product_id`"|fn_url}" target="_blank">{$row.product}</a></td>
          <td>{$row.cost}</td>
          <td>{$row.price}</td>
        </tr>
      {/foreach}
  </table>
{else}
    <p>{__("no_data")}</p>
{/if}
 
<div class="clearfix">
    {include file="common/pagination.tpl" div_id=$smarty.request.content_id}
</div>
 
</form>
<!--content_manage_undercost--></div>
 
 
{/capture}
{include file="common/mainbox.tpl" title=__("products_under_cost") buttons=$smarty.capture.buttons sidebar=$smarty.capture.sidebar content=$smarty.capture.mainbox}