diff --git a/doc/conf/LSobject/LSsearch.docbook b/doc/conf/LSobject/LSsearch.docbook
index d1dc2b66..65778c42 100644
--- a/doc/conf/LSobject/LSsearch.docbook
+++ b/doc/conf/LSobject/LSsearch.docbook
@@ -35,7 +35,6 @@ configuration des &LSobjects;, dans la variable LSsearch
'displayFormat' => [LSformat],
'nbObjectsByPage' => [integer],
'nbObjectsByPageChoices' => array([integer], [integer], ...),
- 'nbPageLinkByPage' => [integer],
'validPatternRegex' => '[regex]'
),
'predefinedFilters' => array(
@@ -243,15 +242,6 @@ contexte dans lequel cette recherche est effectuée.
-
- nbPageLinkByPage
-
- Entier déterminant le nombre maximum de liens vers d'autres pages
- affichés sous le résultat de la recherche.
- Par défaut : 10
-
-
-
validPatternRegex
diff --git a/src/includes/class/class.LSsearch.php b/src/includes/class/class.LSsearch.php
index ddc70831..73db7a5d 100644
--- a/src/includes/class/class.LSsearch.php
+++ b/src/includes/class/class.LSsearch.php
@@ -61,7 +61,6 @@ class LSsearch extends LSlog_staticLoggerClass {
'displayFormat' => NULL,
'nbObjectsByPage' => NB_LSOBJECT_LIST,
'nbObjectsByPageChoices' => NULL,
- 'nbPageLinkByPage' => 10,
'customInfos' => array(),
'withoutCache' => false,
'extraDisplayedColumns' => false,
@@ -335,7 +334,7 @@ class LSsearch extends LSlog_staticLoggerClass {
// nbObjectsByPage
if (isset($params['nbObjectsByPage'])) {
- if (((int)$params['nbObjectsByPage'])>1 ) {
+ if (((int)$params['nbObjectsByPage'])>=1 ) {
$this -> params['nbObjectsByPage'] = (int)$params['nbObjectsByPage'];
}
else {
@@ -1102,31 +1101,33 @@ class LSsearch extends LSlog_staticLoggerClass {
*
* @retval array The information of the page
**/
- public function getPage($page=0) {
+ public function getPage($page=1) {
if (!LSsession::loadLSclass('LSsearchEntry')) {
LSerror::addErrorCode('LSsession_05',$this -> LSobject);
return;
}
$page = (int)$page;
+ if ($page < 1)
+ $page = 1;
- $retval=array(
+ $retval = array(
'nb' => $page,
'nbPages' => 1,
'list' => array(),
'total' => $this -> total
);
- if ($retval['total']>0) {
+ if ($retval['total'] > 0) {
if (!$this->params['nbObjectsByPage']) {
- $this->params['nbObjectsByPage']=NB_LSOBJECT_LIST;
+ $this->params['nbObjectsByPage'] = NB_LSOBJECT_LIST;
}
- $retval['nbPages']=ceil($retval['total']/$this->params['nbObjectsByPage']);
+ $retval['nbPages'] = ceil($retval['total'] / $this->params['nbObjectsByPage']);
$sortTable=$this -> getSortTable();
$list = array_slice(
$sortTable,
- ($page * $this->params['nbObjectsByPage']),
+ (($page - 1) * $this->params['nbObjectsByPage']),
$this->params['nbObjectsByPage']
);
@@ -1625,7 +1626,7 @@ class LSsearch extends LSlog_staticLoggerClass {
}
else {
// Retrieve page
- $page = $search -> getPage(($page_nb-1));
+ $page = $search -> getPage($page_nb);
/*
* $page = array(
* 'nb' => $page,
@@ -1647,7 +1648,7 @@ class LSsearch extends LSlog_staticLoggerClass {
'total' => $search -> total,
);
if (!$all) {
- $export['page'] = $page['nb'] + 1;
+ $export['page'] = $page['nb'];
$export['nbPages'] = $page['nbPages'];
}
foreach(($all?$entries:$page['list']) as $obj) {
@@ -1707,7 +1708,7 @@ class LSsearch extends LSlog_staticLoggerClass {
if ($all)
echo "Total: ".$search -> total."\n";
else
- echo "Page ".($page['nb']+1)." on ".$page['nbPages']." / Total: ".$search -> total."\n";
+ echo "Page ".($page['nb'])." on ".$page['nbPages']." / Total: ".$search -> total."\n";
return true;
}
diff --git a/src/includes/routes.php b/src/includes/routes.php
index 381cb287..d61fb6e3 100644
--- a/src/includes/routes.php
+++ b/src/includes/routes.php
@@ -125,7 +125,7 @@ function handle_old_index_ajax_php($request) {
LSurl :: add_handler('#^index_ajax\.php#', 'handle_old_index_ajax_php', false);
/*
- * Handle global seearch request
+ * Handle global search request
*
* @param[in] $request LSurlRequest The request
*
@@ -181,7 +181,7 @@ function handle_global_search($request) {
$LSsearch -> run();
if ($LSsearch -> total > 0) {
- $page = $LSsearch -> getPage(0);
+ $page = $LSsearch -> getPage(1);
LStemplate :: assign('page', $page);
LStemplate :: assign('LSsearch', $LSsearch);
$pages[] = LSsession :: fetchTemplate('global_search_one_page.tpl');
@@ -496,8 +496,8 @@ function handle_LSobject_search($request) {
$LSsearch -> redirectWhenOnlyOneResult();
// Handle page parameter and retreive corresponding page from search
- $page = (isset($_REQUEST['page'])?(int)$_REQUEST['page']:0);
- $page = $LSsearch -> getPage($page);
+ $page_nb = (isset($_REQUEST['page'])?(int)$_REQUEST['page']:1);
+ $page = $LSsearch -> getPage($page_nb);
// Set template variables
LStemplate :: assign('page', $page);
@@ -691,7 +691,7 @@ function handle_LSobject_select($request) {
$LSsearch -> setParamsFromRequest();
$LSsearch -> setParam('nbObjectsByPage', NB_LSOBJECT_LIST_SELECT);
- $page = (isset($_REQUEST['page'])?(int)$_REQUEST['page']:0);
+ $page_nb = (isset($_REQUEST['page'])?(int)$_REQUEST['page']:1);
// Run search
$LSsearch -> run();
@@ -730,7 +730,7 @@ function handle_LSobject_select($request) {
)
)
);
- LStemplate :: assign('page', $LSsearch -> getPage($page));
+ LStemplate :: assign('page', $LSsearch -> getPage($page_nb));
LStemplate :: assign('LSsearch', $LSsearch);
LStemplate :: assign('LSselect_id', $request->LSselect_id);
LStemplate :: assign('selectable_object_types', LSselect :: getSelectableObjectTypes($request->LSselect_id));
@@ -1579,7 +1579,7 @@ function handle_api_LSobject_search($request) {
}
else {
// Retrieve page
- $page_nb = (isset($_REQUEST['page'])?(int)$_REQUEST['page']:0);
+ $page_nb = (isset($_REQUEST['page'])?(int)$_REQUEST['page']:1);
$page = $search -> getPage($page_nb);
/*
@@ -1603,7 +1603,7 @@ function handle_api_LSobject_search($request) {
'total' => $search -> total,
);
if (!$all) {
- $data['page'] = $page['nb'] + 1;
+ $data['page'] = $page['nb'];
$data['nbPages'] = $page['nbPages'];
}
foreach(($all?$entries:$page['list']) as $obj) {
diff --git a/src/templates/default/global_search_one_page.tpl b/src/templates/default/global_search_one_page.tpl
index 691630db..0ca90cfe 100644
--- a/src/templates/default/global_search_one_page.tpl
+++ b/src/templates/default/global_search_one_page.tpl
@@ -53,36 +53,5 @@
{/foreach}
{$LSsearch->label_total|escape:'htmlall'}
-{if $page.nbPages > 1}
-
-
- {if $page.nbPages > 10}
- {if $page.nb > 5}
- {if $page.nb > $page.nbPages-6}
- {assign var=start value=$page.nbPages-12}
- {else}
- {assign var=start value=$page.nb-6}
- {/if}
- {else}
- {assign var=start value=0}
- {/if}
- <
- {foreach from=0|range:10 item=i}
- {if $page.nb==$start+$i}
- {$page.nb+1}
- {else}
- {$i+$start+1}
- {/if}
- {/foreach}
- >
- {else}
- {section name=listpage loop=$page.nbPages step=1}
- {if $page.nb == $smarty.section.listpage.index}
- {$page.nb+1}
- {else}
- {$smarty.section.listpage.index+1}
- {/if}
- {/section}
- {/if}
-
-{/if}
+{assign var=pagination_url value="object/{$LSsearch->LSobject|escape:"url"}"}
+{include file='ls:pagination.tpl'}
diff --git a/src/templates/default/pagination.tpl b/src/templates/default/pagination.tpl
new file mode 100644
index 00000000..c24d5f49
--- /dev/null
+++ b/src/templates/default/pagination.tpl
@@ -0,0 +1,41 @@
+{if !isset($pagination_url)}
+{assign var=pagination_url value=$request->current_url}
+{/if}
+
+{if $page.nbPages > 1}
+
+
+ {if $page.nbPages > 9}
+ {if $page.nb > 5}
+ {if $page.nb+4 > $page.nbPages}
+ {assign var=start value=$page.nbPages-8}
+ {else}
+ {assign var=start value=$page.nb-4}
+ {/if}
+ {else}
+ {assign var=start value=1}
+ {/if}
+ {if $start != 1}
+ <
+ {/if}
+ {foreach from=0|range:8 item=i}
+ {if $page.nb==$start+$i}
+ {$page.nb}
+ {else}
+ {$start+$i}
+ {/if}
+ {/foreach}
+ {if $start + 9 <= $page.nbPages}
+ >
+ {/if}
+ {else}
+ {section name=listpage loop=$page.nbPages step=1}
+ {if $page.nb == $smarty.section.listpage.index+1}
+ {$page.nb}
+ {else}
+ {$smarty.section.listpage.index+1}
+ {/if}
+ {/section}
+ {/if}
+
+{/if}
diff --git a/src/templates/default/select_table.tpl b/src/templates/default/select_table.tpl
index eb133e39..211d10de 100644
--- a/src/templates/default/select_table.tpl
+++ b/src/templates/default/select_table.tpl
@@ -43,39 +43,7 @@
{/foreach}
-
-{if $page.nbPages > 1}
-
- {if $page.nbPages > 10}
- {if $page.nb > 5}
- {if $page.nb > $page.nbPages-6}
- {assign var=start value=$page.nbPages-12}
- {else}
- {assign var=start value=$page.nb-6}
- {/if}
- {else}
- {assign var=start value=0}
- {/if}
- <
- {foreach from=0|range:10 item=i}
- {if $page.nb==$start+$i}
- {$page.nb+1}
- {else}
- {$i+$start+1}
- {/if}
- {/foreach}
- >
- {else}
- {section name=listpage loop=$page.nbPages step=1}
- {if $page.nb == $smarty.section.listpage.index}
- {$page.nb+1}
- {else}
- {$smarty.section.listpage.index+1}
- {/if}
- {/section}
- {/if}
-
-{/if}
+{include file='ls:pagination.tpl'}
{$LSdebug_txt}
{$LSerror_txt}
diff --git a/src/templates/default/viewSearch.tpl b/src/templates/default/viewSearch.tpl
index 408fc2ea..ef18c511 100644
--- a/src/templates/default/viewSearch.tpl
+++ b/src/templates/default/viewSearch.tpl
@@ -121,37 +121,5 @@
{/if}
-{if $page.nbPages > 1}
-
-
- {if $page.nbPages > 10}
- {if $page.nb > 5}
- {if $page.nb > $page.nbPages-6}
- {assign var=start value=$page.nbPages-12}
- {else}
- {assign var=start value=$page.nb-6}
- {/if}
- {else}
- {assign var=start value=0}
- {/if}
- <
- {foreach from=0|range:10 item=i}
- {if $page.nb==$start+$i}
- {$page.nb+1}
- {else}
- {$i+$start+1}
- {/if}
- {/foreach}
- >
- {else}
- {section name=listpage loop=$page.nbPages step=1}
- {if $page.nb == $smarty.section.listpage.index}
- {$page.nb+1}
- {else}
- {$smarty.section.listpage.index+1}
- {/if}
- {/section}
- {/if}
-
-{/if}
+{include file='ls:pagination.tpl'}
{/block}