source: trunk/data/class/SC_PageNavi.php @ 18758

Revision 18758, 5.4 KB checked in by kajiwara, 14 years ago (diff)

EC-CUBE Ver2.4.4 分コミット。詳細はこちら( http://www.ec-cube.net/release/detail.php?release_id=223

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Id
  • Property svn:mime-type set to text/x-httpd-php; charset=UTF-8
Line 
1<?php
2/*
3 * This file is part of EC-CUBE
4 *
5 * Copyright(c) 2000-2010 LOCKON CO.,LTD. All Rights Reserved.
6 *
7 * http://www.lockon.co.jp/
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22 */
23
24/* ※使用条件※
25    ・formタグに以下を追加する。
26        <input type="hidden" name="pageno" value="<!--{$tpl_pageno}-->">
27    ・ソースの最初に以下を記述する。
28        $objPage->tpl_pageno = $_POST['pageno'];
29    ・$func_nameに指定するJavaScriptの例
30        // ページナビで使用する
31        function fnNaviPage(pageno) {
32            document.form1['pageno'].value = pageno;
33            document.form1.submit();
34        }
35*/
36class SC_PageNavi {
37    var $now_page;      // 現在のページ番号
38    var $max_page;      // 最終のページ番号
39    var $start_row;     // 開始レコード
40    var $strnavi;       // ページ送り文字列
41    var $arrPagenavi = array(); // ページ
42
43    // コンストラクタ
44    function SC_PageNavi($now_page, $all_row, $page_row, $func_name, $navi_max = NAVI_PMAX) {
45        $this->arrPagenavi['mode'] = 'search';
46        $ps = htmlspecialchars($_SERVER['PHP_SELF'], ENT_QUOTES);
47
48        //現在ページ($now_page)が正しい数値でない場合
49        if (!eregi("^[[:digit:]]+$", $now_page) || $now_page < 1 || $now_page == "") {
50            $this->now_page = 1;
51        } else {
52            $this->now_page = $now_page;
53        }
54        $this->arrPagenavi['now_page'] = $this->now_page;
55
56        // 最終ページの計算
57        $this->max_page = ceil($all_row/$page_row);
58
59        // 最終ページよりも現在ページが大きい場合は、最初に戻す。
60        if($this->max_page < $this->now_page) {
61            $this->now_page = 1;
62        }
63
64        $this->start_row = ($this->now_page - 1) * $page_row;
65
66        // 開始行が不正な場合
67        if (!($this->start_row < $all_row && $this->start_row >= 0)) {
68            $this->start_row = 0;
69        }
70
71        if($all_row > 1) {
72
73            //「前へ」「次へ」の設定
74            $before = "";
75            $next = "";
76            if ($this->now_page > 1) {
77                $before="<a href=\"". $ps . "\" onclick=\"$func_name('" . (($this->now_page) - 1) . "'); return false;\">&lt;&lt;前へ</a> ";
78                $this->arrPagenavi['before'] = ($this->now_page) - 1;
79            }else{
80                $this->arrPagenavi['before'] = $this->now_page;
81            }
82
83            if ($this->now_page < $this->max_page) {
84                $next=" <a href=\"". $ps . "\" onclick=\"$func_name('" . (($this->now_page) + 1) ."'); return false;\">次へ&gt;&gt;</a>";
85                $this->arrPagenavi['next'] = ($this->now_page) + 1;
86            }else{
87                $this->arrPagenavi['next'] = $this->now_page;
88            }
89
90            // 表示する最大ナビ数を決める。
91            if($navi_max == "" || $navi_max > $this->max_page) {
92                // 制限ナビ数の指定がない。ページ最大数が制限ナビ数より少ない。
93                $disp_max = $this->max_page;
94            } else {
95                // 現在のページ+制限ナビ数が表示される。
96                $disp_max = $this->now_page + $navi_max - 1;
97                // ページ最大数を超えている場合は、ページ最大数に合わせる。
98                if($disp_max > $this->max_page) {
99                    $disp_max = $this->max_page;
100                }
101            }
102
103            // 表示する最小ナビ数を決める。
104            if($navi_max == "" || $navi_max > $this->now_page) {
105                // 制限ナビ数の指定がない。現在ページ番号が制限ナビ数より少ない。
106                $disp_min = 1;
107            } else {
108                // 現在のページ-制限ナビ数が表示される。
109                $disp_min = $this->now_page - $navi_max + 1;
110            }
111
112            $this->arrPagenavi['arrPageno'] = array();
113            $page_number = "";
114            for ($i=$disp_min; $i <= $disp_max; $i++) {
115
116                if($i != $disp_max) {
117                    $sep = " | ";
118                } else {
119                    $sep = "";
120                }
121
122                if ($i == $this->now_page) {
123                    $page_number .= "<strong>$i</strong>";
124                } else {
125                    $page_number.="<a href=\"".  $ps . "\" onclick=\"$func_name('$i'); return false;\">$i</a>";
126                }
127
128                $page_number.=$sep;
129
130                $this->arrPagenavi['arrPageno'][$i] = $i;
131            }
132
133            if ($before || $next) {
134                $this->strnavi = $before .$page_number .$next;
135            }
136        }else{
137            $this->arrPagenavi['arrPageno'][0] = 1;
138            $this->arrPagenavi['before'] = 1;
139            $this->arrPagenavi['next'] = 1;
140        }
141    }
142}
143
144?>
Note: See TracBrowser for help on using the repository browser.