| 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 | // {{{ requires |
|---|
| 25 | require_once(CLASS_PATH . "pages/LC_Page.php"); |
|---|
| 26 | |
|---|
| 27 | /** |
|---|
| 28 | * システム管理 のページクラス. |
|---|
| 29 | * |
|---|
| 30 | * @package Page |
|---|
| 31 | * @author LOCKON CO.,LTD. |
|---|
| 32 | * @version $Id: LC_Page_Admin_System_Rank.php 16582 2007-11-28 15:02:29Z satou $ |
|---|
| 33 | */ |
|---|
| 34 | class LC_Page_Admin_System_Rank extends LC_Page { |
|---|
| 35 | // }}} |
|---|
| 36 | // {{{ functions |
|---|
| 37 | |
|---|
| 38 | /** |
|---|
| 39 | * Page を初期化する. |
|---|
| 40 | * |
|---|
| 41 | * @return void |
|---|
| 42 | */ |
|---|
| 43 | function init() { |
|---|
| 44 | parent::init(); |
|---|
| 45 | } |
|---|
| 46 | |
|---|
| 47 | /** |
|---|
| 48 | * Page のプロセス. |
|---|
| 49 | * |
|---|
| 50 | * @return void |
|---|
| 51 | */ |
|---|
| 52 | function process() { |
|---|
| 53 | $conn = new SC_DbConn(); |
|---|
| 54 | |
|---|
| 55 | // ログインチェック |
|---|
| 56 | SC_Utils::sfIsSuccess(new SC_Session()); |
|---|
| 57 | |
|---|
| 58 | // ランキングの変更 |
|---|
| 59 | if($_GET['move'] == 'up') { |
|---|
| 60 | // 正当な数値であった場合 |
|---|
| 61 | if(SC_Utils::sfIsInt($_GET['id'])){ |
|---|
| 62 | $this->lfRunkUp($conn, $_GET['id']); |
|---|
| 63 | // エラー処理 |
|---|
| 64 | } else { |
|---|
| 65 | GC_Utils::gfPrintLog("error id=".$_GET['id']); |
|---|
| 66 | } |
|---|
| 67 | } else if($_GET['move'] == 'down') { |
|---|
| 68 | if(SC_Utils::sfIsInt($_GET['id'])){ |
|---|
| 69 | $this->lfRunkDown($conn, $_GET['id']); |
|---|
| 70 | // エラー処理 |
|---|
| 71 | } else { |
|---|
| 72 | GC_Utils::gfPrintLog("error id=".$_GET['id']); |
|---|
| 73 | } |
|---|
| 74 | } |
|---|
| 75 | |
|---|
| 76 | // ページの表示 |
|---|
| 77 | $this->sendRedirect($this->getLocation(URL_SYSTEM_TOP)); |
|---|
| 78 | } |
|---|
| 79 | |
|---|
| 80 | /** |
|---|
| 81 | * デストラクタ. |
|---|
| 82 | * |
|---|
| 83 | * @return void |
|---|
| 84 | */ |
|---|
| 85 | function destroy() { |
|---|
| 86 | parent::destroy(); |
|---|
| 87 | } |
|---|
| 88 | |
|---|
| 89 | // ランキングを上げる。 |
|---|
| 90 | function lfRunkUp($conn, $id) { |
|---|
| 91 | // 自身のランクを取得する。 |
|---|
| 92 | $rank = $conn->getOne("SELECT rank FROM dtb_member WHERE member_id = ".$id); |
|---|
| 93 | // ランクの最大値を取得する。 |
|---|
| 94 | $maxno = $conn->getOne("SELECT max(rank) FROM dtb_member"); |
|---|
| 95 | // ランクが最大値よりも小さい場合に実行する。 |
|---|
| 96 | if($rank < $maxno) { |
|---|
| 97 | // ランクがひとつ上のIDを取得する。 |
|---|
| 98 | $sqlse = "SELECT member_id FROM dtb_member WHERE rank = ?"; |
|---|
| 99 | $up_id = $conn->getOne($sqlse, $rank + 1); |
|---|
| 100 | // ランク入れ替えの実行 |
|---|
| 101 | $conn->query("BEGIN"); |
|---|
| 102 | $sqlup = "UPDATE dtb_member SET rank = ? WHERE member_id = ?"; |
|---|
| 103 | $conn->query($sqlup, array($rank + 1, $id)); |
|---|
| 104 | $conn->query($sqlup, array($rank, $up_id)); |
|---|
| 105 | $conn->query("COMMIT"); |
|---|
| 106 | } |
|---|
| 107 | } |
|---|
| 108 | |
|---|
| 109 | // ランキングを下げる。 |
|---|
| 110 | function lfRunkDown($conn, $id) { |
|---|
| 111 | // 自身のランクを取得する。 |
|---|
| 112 | $rank = $conn->getOne("SELECT rank FROM dtb_member WHERE member_id = ".$id); |
|---|
| 113 | // ランクの最小値を取得する。 |
|---|
| 114 | $minno = $conn->getOne("SELECT min(rank) FROM dtb_member"); |
|---|
| 115 | // ランクが最大値よりも大きい場合に実行する。 |
|---|
| 116 | if($rank > $minno) { |
|---|
| 117 | // ランクがひとつ下のIDを取得する。 |
|---|
| 118 | $sqlse = "SELECT member_id FROM dtb_member WHERE rank = ?"; |
|---|
| 119 | $down_id = $conn->getOne($sqlse, $rank - 1); |
|---|
| 120 | // ランク入れ替えの実行 |
|---|
| 121 | $conn->query("BEGIN"); |
|---|
| 122 | $sqlup = "UPDATE dtb_member SET rank = ? WHERE member_id = ?"; |
|---|
| 123 | $conn->query($sqlup, array($rank - 1, $id)); |
|---|
| 124 | $conn->query($sqlup, array($rank, $down_id)); |
|---|
| 125 | $conn->query("COMMIT"); |
|---|
| 126 | } |
|---|
| 127 | } |
|---|
| 128 | } |
|---|
| 129 | ?> |
|---|