14 if (!defined(
'IN_PEEL')) {
82 function Multipage($sqlRequest, $nombre_session_var_name =
'default_results_per_page', $DefaultResultsPerPage = 50, $LinkPerPage = 7, $AddToColspan = 0, $always_show =
true, $template_name = null, $round_elements_per_page = 1, $external_results_to_merge_at_beginning = null, $no_pagination_displayed =
false)
84 if (empty($template_name)) {
85 if(defined(
'IN_PEEL_ADMIN')) {
87 $template_name =
'default_admin';
90 $template_name =
vb(
$GLOBALS[
'site_parameters'][
'template_multipage']);
93 $this->tpl_name = $template_name;
97 if ($this->DefaultResultsPerPage !=
'*') {
98 if($this->DefaultResultsPerPage<20) {
103 $this->nb1 = max($round_elements_per_page, round($this->DefaultResultsPerPage / $divisor) - round($this->DefaultResultsPerPage / $divisor) % $round_elements_per_page);
104 $this->nb2 = max(2 * $round_elements_per_page, round($this->DefaultResultsPerPage) - round($this->DefaultResultsPerPage) % $round_elements_per_page);
105 $this->nb3 = max(10, 3*$round_elements_per_page, round($this->DefaultResultsPerPage * 5) - round($this->DefaultResultsPerPage * 5) % $round_elements_per_page);
111 if(!empty($nombre_session_var_name)){
126 if (!empty($_GET[
'start'])) {
127 if(!empty($this->ResultPerPage)) {
128 $this->page = round($_GET[
'start'] / $this->ResultPerPage);
141 $this->pages_count = 1;
151 if ($this->DefaultResultsPerPage !=
'*') {
152 if (isset($_GET[
'nombre']) && is_numeric($_GET[
'nombre']) && $_GET[
'nombre'] >= $this->nb1 && $_GET[
'nombre'] <= $this->nb3) {
153 if(!empty($this->nombre_session_var_name)){
156 if (empty($_POST) && !defined(
'IN_PEEL_ADMIN') &&
String::strpos(
get_current_url(
true),
'nombre=' . urlencode($_GET[
'nombre'])) !==
false && (empty($_GET[
'multipage']) || $_GET[
'multipage'] == $this->nombre_session_var_name)) {
163 if (!empty($this->nombre_session_var_name) && isset(
$_SESSION[$this->nombre_session_var_name])) {
164 if ((
$_SESSION[$this->nombre_session_var_name] <= $this->nb1) || (
$_SESSION[$this->nombre_session_var_name] < (($this->nb2 + $this->nb1) / 2))) {
166 }
elseif ((
$_SESSION[$this->nombre_session_var_name] < $this->nb3) && (
$_SESSION[$this->nombre_session_var_name] < (($this->nb3 + $this->nb2) / 2))) {
172 $this->ResultPerPage = $ResultsPerPage;
187 if ($this->DefaultResultsPerPage !=
'*') {
188 $this->page = max(1, intval($page));
200 function Query($return_objects =
false)
203 $lines_begin = max(0, intval($this->ResultPerPage * ($this->page - 1)) - count($this->external_results_to_merge_at_beginning));
204 $lines_count = max(0, intval($this->ResultPerPage) + min(0, intval($this->ResultPerPage * ($this->page - 1)) - count($this->external_results_to_merge_at_beginning)));
206 if($lines_count > 0) {
209 if ($this->DefaultResultsPerPage !=
'*') {
212 $this->LimitSQL .=
" LIMIT " . intval($lines_begin) .
", " . intval($lines_count);
221 for(
$i=max(0, intval($this->ResultPerPage * ($this->page - 1)));isset($this->external_results_to_merge_at_beginning[
$i]) && $i<max(0, intval($this->ResultPerPage * $this->page));$i++) {
224 if ($return_objects) {
242 function Calcul($query_without_error =
true)
244 if($query_without_error) {
246 if($this->sql_count === null) {
247 $this->sql_count =
"SELECT FOUND_ROWS() AS rows_count";
249 if(!empty($this->sql_count)) {
250 $query_count_rs =
query($this->sql_count);
252 $this->nbRecord = $query_count_row[
'rows_count'];
253 $this->nbRecord += count($this->external_results_to_merge_at_beginning);
256 $this->nbRecord = count($this->external_results_to_merge_at_beginning);
258 if (!empty($this->ResultPerPage) && ($this->ResultPerPage < $this->nbRecord)) {
259 $this->pages_count = ceil($this->nbRecord / $this->ResultPerPage);
262 $GLOBALS[
'all_multipage_limit'] = max($this->pages_count,
vn(
$GLOBALS[
'all_multipage_limit']));
263 if (empty(
$GLOBALS[
'multipage_avoid_redirect_if_page_over_limit']) && $this->page >
$GLOBALS[
'all_multipage_limit']) {
264 $new_url = $this->
getPageURL($this->pages_count);
270 if ($this->LinkPerPage ==
'*') {
273 if (($this->always_show && $this->DefaultResultsPerPage !=
'*') || $this->pages_count > 1) {
277 $this->tpl_data =
'';
290 if (strpos($link,
'[PAGE]') !==
false) {
293 $link .= (strstr($link,
'?') ?
'&' :
'?') .
'page=' . urlencode($page);
295 if ($nombre !== null) {
296 if (strpos($link,
'[NOMBRE]') !==
false) {
312 if(empty($this->tpl_name) || $this->no_pagination_displayed) {
315 $tpl =
$GLOBALS[
'tplEngine']->createTemplate(
'multipage_template_' . $this->tpl_name .
'.tpl');
317 $tpl->assign(
'current_page', $this->page);
318 $tpl->assign(
'nbrecord', $this->nbRecord);
319 $tpl->assign(
'total_page', $this->pages_count);
320 $tpl->assign(
'colspan', $this->pages_count + ($this->AddToColspan));
321 $tpl->assign(
'show_page_if_only_one', $show_page_if_only_one);
323 $tpl->assign(
'previous_page', ($this->page > 1 ?
'<a href="' .
String::str_form_value($this->
getPageURL(min($this->page - 1, $this->pages_count))) .
'"><img src="' . $GLOBALS[
'wwwroot'] .
'/images/previous_page.png" alt="' . $GLOBALS[
'STR_PREVIOUS_PAGE'] .
'" /></a>' :
''));
324 $tpl->assign(
'first_page', ($this->page != 1 ?
'<a href="' .
String::str_form_value($this->
getPageURL(1)) .
'"><img src="' . $GLOBALS[
'wwwroot'] .
'/images/first_page.png" alt="' . $GLOBALS[
'STR_FIRST_PAGE'] .
'" /></a>' :
''));
325 $tpl->assign(
'last_page', (!
is_user_bot() && $this->page < $this->pages_count ?
'<a href="' .
String::str_form_value($this->
getPageURL($this->pages_count)) .
'"><img src="' . $GLOBALS[
'wwwroot'] .
'/images/last_page.png" alt="' . $GLOBALS[
'STR_LAST_PAGE'] .
'" /></a>' :
''));
328 $links_per_page = null;
330 $links_per_page = $GLOBALS[
'STR_PER_PAGE'] . $GLOBALS[
'STR_BEFORE_TWO_POINTS'] .
': ' .
332 (($this->nb2 != $this->ResultPerPage)?(
'<a href="' .
String::str_form_value($this->
getPageURL(1, $this->nb2)) .
'" rel="nofollow">' . $this->nb2 .
'</a>'):(
'<b>' . $this->nb2 .
'</b>')) .
' ' .
333 (($this->nb3 != $this->ResultPerPage)?(
'<a href="' .
String::str_form_value($this->
getPageURL(1, $this->nb3)) .
'" rel="nofollow">' . $this->nb3 .
'</a>'):(
'<b>' . $this->nb3 .
'</b>')) .
' ' .
334 (($this->nb1 != $this->ResultPerPage && $this->nb2 != $this->ResultPerPage && $this->nb3 != $this->ResultPerPage)?(
' (' . $this->ResultPerPage .
')'):
'');
336 $tpl->assign(
'results_per_page', $links_per_page);
338 if ($this->pages_count > 1) {
339 $this->first_link_page = max(1, min($this->page - ceil($this->LinkPerPage / 2) + 1, $this->pages_count - $this->LinkPerPage + 1));
340 for ($this_page = $this->first_link_page; $this_page <= min($this->first_link_page + $this->LinkPerPage - 1, $this->pages_count) ;$this_page++) {
342 if ($this_page == $this->page) {
343 $page .=
'<span class="current_page_number">' . $this_page .
'</span>';
347 $liens[] = array(
'i' => $this_page,
'page' => $page);
349 }
elseif($show_page_if_only_one) {
351 $this->first_link_page = 1;
352 $liens[][
'page'] = array(
'i' => 1,
'page' =>
'<span class="current_page_number">1</span>');
354 $tpl->assign(
'first_link_page', $this->first_link_page);
355 $tpl->assign(
'loop', $liens);
356 $tpl->assign(
'STR_MULTIPAGE_SEPARATOR', $GLOBALS[
'STR_MULTIPAGE_SEPARATOR']);
357 $this->tpl_data =
$tpl->fetch();
389 foreach($this->HeaderTitlesArray as $key => $this_title) {
390 if (!empty($last_title) && $last_title == $this_title) {
391 unset($this->HeaderTitlesArray[$last_key]);
392 $add_colspan[$key] =
vn($add_colspan[$last_key]) + 1;
394 $last_title = $this_title;
397 foreach($this->HeaderTitlesArray as $key => $this_title) {
398 if (!empty($add_colspan[$key])) {
399 $colspan_text =
' colspan="' . ($add_colspan[$key] + 1) .
'"';
405 <th class="menu center multipage_selected_field"' . $colspan_text .
'>';
408 <th class="menu center"' . $colspan_text .
'>';
411 $link_url = $_SERVER[
'REQUEST_URI'];
412 if (empty($_GET[$this->order_get_variable])) {
416 $link_url .=
'&';
418 $link_url .= $this->order_get_variable.
'=' . $key;
420 $link_url = str_replace($this->order_get_variable.
'=' . $_GET[$this->order_get_variable], $this->order_get_variable.
'=' . $key, $link_url);
422 if (!isset($_GET[$this->sort_get_variable])) {
423 $url_desc = $link_url .
'&'.$this->sort_get_variable.
'=desc';
424 $url_asc = $link_url .
'&'.$this->sort_get_variable.
'=asc';
427 $url_desc = str_replace($this->sort_get_variable.
'=' . $_GET[$this->sort_get_variable], $this->sort_get_variable.
'=desc', $link_url);
428 $url_asc = str_replace($this->sort_get_variable.
'=' . $_GET[$this->sort_get_variable], $this->sort_get_variable.
'=asc', $link_url);
430 $output .=
'<a href="' . $url_desc .
'"><img src="' .
$GLOBALS[
'administrer_url'] .
'/images/desc.gif" width="7" height="7" alt="-" /></a> ' . $this_title .
' <a href="' . $url_asc .
'"><img src="' .
$GLOBALS[
'administrer_url'] .
'/images/up.gif" width="7" height="7" alt="+" /></a>';
448 if (!empty($_GET[$this->sort_get_variable]) && $this->allow_get_sort) {
450 }
elseif (!empty($this->SortDefault)) {
458 if (!empty($this->forced_before_first_order_by_string)) {
461 if ($this->forced_order_by_string === null) {
465 $columns = array_values(explode(
',', str_replace(
' ',
'', ($this->allow_get_sort && !empty($_GET[$this->order_get_variable]) && (!isset($this->HeaderTitlesArray) || isset($this->HeaderTitlesArray[$_GET[$this->order_get_variable]]))?$_GET[$this->order_get_variable] .
',':
'') . $this->OrderDefault)));
466 foreach($columns as $this_column) {
467 if (!empty($this_column)) {
470 if(!empty($this->order_sql_prefix) &&
String::strpos($this_column,
'.') ===
false) {
473 $order_by[] = $this_order_by;
476 }
elseif (!empty($this->forced_order_by_string)) {
478 }
elseif (!empty($this->OrderDefault)) {
481 if (!empty($this->forced_second_order_by_string)) {
484 if(!empty($order_by)) {
485 foreach($order_by as $this_key => $this_value) {
486 if(!empty($this_sort) &&
String::strpos($this_value,
' ') ===
false) {
488 $order_by[$this_key] .=
' ' . $this_sort;
492 if (!empty($order_by)) {
493 return 'ORDER BY ' . implode(
', ', $order_by);
static strtoupper($string)
Returns string with all alphabetic characters converted to uppercase.
setResultsNumberPerPage()
Multipage::setResultsNumberPerPage()
static strpos($haystack, $needle, $offset=0)
Returns the numeric position of the first occurrence of needle in the haystack string.
pMultipage()
Affiche directement en sortie le contenu du template après traitement.
get_current_url($with_get=true, $get_short_url=false, $take_away_get_args_array=null)
get_current_url()
redirect_and_die($url, $permanent_redirection=false, $avoid_loop=false)
Redirige vers l'URL demandée et arrête le programme.
getHeaderRow()
Multipage::getHeaderRow()
Multipage($sqlRequest, $nombre_session_var_name= 'default_results_per_page', $DefaultResultsPerPage=50, $LinkPerPage=7, $AddToColspan=0, $always_show=true, $template_name=null, $round_elements_per_page=1, $external_results_to_merge_at_beginning=null, $no_pagination_displayed=false)
Constructeur.
word_real_escape_string($value)
Applique real_escape_string dans le cas où on n'insère qu'un seul mot, de moins de 30 caractères...
static strtolower($string)
Returns string with all alphabetic characters converted to lowercase.
get_current_generic_url()
get_current_generic_url()
ParseTemplate($show_page_if_only_one=false)
Cherche et remplace dans le template les variables connues en lançant les traitements associés...
getOrderBy()
Multipage::getOrderBy()
getPageURL($page, $nombre=null)
Multipage::getPageURL()
if(!empty($_GET['id'])) if(isset($_POST['form_name'], $_POST['form_subject'], $_POST['form_text'], $_POST['form_lang'])&&empty($_GET['id'])) if(empty($_GET['id'])) $tpl
if(!function_exists('ipGet')) if(!function_exists('isPublicIP')) is_user_bot($ip=null, $user_agent=null)
Renvoie si le visiteur est un robot ou non.
Initialize()
Paramétrage et construction.
query($query, $die_if_error=false, $database_object=null, $silent_if_error=false, $security_sql_filter=true)
The query() function is meant to be called anywhere you want to make a query.
static str_form_value($value, $flags=ENT_COMPAT)
Encode une chaine de caractères pour affichage dans un value="".
$external_results_to_merge_at_beginning
if(strlen($date2)== '10') if($type== 'users-by-age'&&a_priv('admin_users', true)) elseif($type== 'forums-count'&&a_priv('admin_content', true)) elseif($type== 'forums-categories'&&a_priv('admin_content', true)) elseif($type== 'users-count'&&a_priv('admin_users', true)) elseif($type== 'product-categories'&&a_priv('admin_products', true)) elseif($type== 'users-by-sex'&&a_priv('admin_users', true)) elseif($type== 'users-by-country'&&a_priv('admin_users', true)) elseif($type== 'sales'&&a_priv('admin_sales', true))
CurrentPage($page)
Calcule les paramètres Limit de la requete SQL en fonction de la page en cours.
fetch_object($query_result)
fetch_object()
fetch_assoc($query_result)
fetch_assoc()
Calcul($query_without_error=true)
Calcule la position - sur la barre de liens - du lien correspondant à la page en cours.
GetMultipage()
Renvoie le résultat du template une fois parsé
$forced_before_first_order_by_string
$GLOBALS['page_columns_count']
$forced_second_order_by_string
static substr($string, $start, $length=null)
Returns the portion of string specified by the start and length parameters.
static substr_count($string, $searched)
Returns the number of times the needle substring occurs in the haystack string.
Query($return_objects=false)
Exécute le SQL avec LIMIT pour retourner les résultats, et calcule juste après car on a besoin que FO...
if(defined('IN_PEEL_ADMIN')||IN_INSTALLATION) $_SESSION['session_langue']
static rawurlencode($string, $avoid_slash=true)
Returns string compatible with Apache without the AllowEncodedSlashes directive ON => avoids systemat...