source: branches/version-2_5-dev/data/class/pages/admin/contents/LC_Page_Admin_Contents.php @ 19707

Revision 19707, 11.3 KB checked in by Seasoft, 13 years ago (diff)

#866(新着情報管理でテンプレート変数不整合) 改修

  • Property svn:eol-style set to LF
  • Property svn:keywords set to "Id Revision Date"
  • 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// {{{ requires
25require_once(CLASS_PATH . "pages/admin/LC_Page_Admin.php");
26
27/**
28 * コンテンツ管理 のページクラス.
29 *
30 * @package Page
31 * @author LOCKON CO.,LTD.
32 * @version $Id$
33 */
34class LC_Page_Admin_Contents extends LC_Page_Admin {
35
36    // }}}
37    // {{{ functions
38
39    /**
40     * Page を初期化する.
41     *
42     * @return void
43     */
44    function init() {
45        parent::init();
46        $this->tpl_mainpage = 'contents/index.tpl';
47        $this->tpl_subnavi = 'contents/subnavi.tpl';
48        $this->tpl_subno = "index";
49        $this->tpl_mainno = 'contents';
50        $this->arrForm = array(
51            'year' => date('Y'),
52            'month' => date('n'),
53            'day' => date('j'),
54        );
55        $this->tpl_subtitle = '新着情報管理';
56    }
57
58    /**
59     * Page のプロセス.
60     *
61     * @return void
62     */
63    function process() {
64        $this->action();
65        $this->sendResponse();
66    }
67
68    /**
69     * Page のアクション.
70     *
71     * @return void
72     */
73    function action() {
74
75        //---- ページ初期設定
76        $objQuery = new SC_Query();
77        $objDate = new SC_Date(ADMIN_NEWS_STARTYEAR);
78        $objDb = new SC_Helper_DB_Ex();
79
80        SC_Utils_Ex::sfIsSuccess(new SC_Session());
81
82        //---- 日付プルダウン設定
83        $this->arrYear = $objDate->getYear();
84        $this->arrMonth = $objDate->getMonth();
85        $this->arrDay = $objDate->getDay();
86
87        if (!isset($_POST['mode'])) $_POST['mode'] = "";
88
89        //---- 新規登録/編集登録
90        if ( $_POST['mode'] == 'regist'){
91            $_POST = $this->lfConvData($_POST);
92
93            if ($this->arrErr = $this->lfErrorCheck()) {       // 入力エラーのチェック
94                $this->arrForm = $_POST;
95            } else {
96
97                if (isset($_POST['link_method']) == ""){
98                    $_POST['link_method'] = 1;
99                }
100
101                $this->registDate = $_POST['year'] ."/". $_POST['month'] ."/". $_POST['day'];
102
103                //-- 編集登録
104                if (strlen($_POST["news_id"]) > 0 && is_numeric($_POST["news_id"])) {
105
106                    $this->lfNewsUpdate($objQuery);
107
108                    //-- 新規登録
109                } else {
110                    $this->lfNewsInsert($objQuery);
111                }
112
113                $this->tpl_onload = "window.alert('編集が完了しました');";
114            }
115        }
116
117        //---- 編集データ取得
118        if ($_POST["mode"] == "search" && is_numeric($_POST["news_id"])) {
119            $sql = "SELECT *, cast(news_date as date) as cast_news_date FROM dtb_news WHERE news_id = ? ";
120            $result = $objQuery->getAll($sql, array($_POST["news_id"]));
121            $this->arrForm = $result[0];
122
123            $arrData = split("-", $result[0]["cast_news_date"]);
124            $this->arrForm['year']  = $arrData[0];
125            $this->arrForm['month'] = $arrData[1];
126            $this->arrForm['day']   = $arrData[2];
127
128            $this->edit_mode = "on";
129        }
130
131        //---- データ削除
132        if ( $_POST['mode'] == 'delete' && is_numeric($_POST["news_id"])) {
133
134            // rankを取得
135            $pre_rank = $objQuery->getOne(" SELECT rank FROM dtb_news WHERE del_flg = 0 AND news_id = ? ", array( $_POST['news_id']  ));
136
137            //-- 削除する新着情報以降のrankを1つ繰り上げておく
138            $objQuery->begin();
139            $sql = "UPDATE dtb_news SET rank = rank - 1, update_date = NOW() WHERE del_flg = 0 AND rank > ?";
140            $objQuery->query( $sql, array( $pre_rank  ) );
141
142            $sql = "UPDATE dtb_news SET rank = 0, del_flg = 1, update_date = NOW() WHERE news_id = ?";
143            $objQuery->query( $sql, array( $_POST['news_id'] ) );
144            $objQuery->commit();
145
146            $this->objDisplay->reload();             //自分にリダイレクト(再読込による誤動作防止)
147        }
148
149        //---- 表示順位移動
150
151        if ( $_POST['mode'] == 'move' && is_numeric($_POST["news_id"]) ) {
152            if ($_POST["term"] == "up") {
153                $objDb->sfRankUp("dtb_news", "news_id", $_POST["news_id"]);
154            } else if ($_POST["term"] == "down") {
155                $objDb->sfRankDown("dtb_news", "news_id", $_POST["news_id"]);
156            }
157            //sf_rebuildIndex($conn);
158            $this->objDisplay->reload();
159        }
160
161        //---- 指定表示順位移動
162        if ($_POST['mode'] == 'moveRankSet') {
163            $key = "pos-".$_POST['news_id'];
164            $input_pos = mb_convert_kana($_POST[$key], "n");
165            if(SC_Utils_Ex::sfIsInt($input_pos)) {
166                $objDb->sfMoveRank("dtb_news", "news_id", $_POST['news_id'], $input_pos);
167                $this->objDisplay->reload();
168            }
169        }
170
171        //---- 全データ取得
172        $sql = "SELECT *, cast(news_date as date) as cast_news_date FROM dtb_news WHERE del_flg = '0' ORDER BY rank DESC";
173        $this->list_data = $objQuery->getAll($sql);
174        $this->line_max = count($this->list_data);
175        $sql = "SELECT MAX(rank) FROM dtb_news WHERE del_flg = '0'";        // rankの最大値を取得
176        $this->max_rank = $objQuery->getOne($sql);
177    }
178
179
180    /**
181     * デストラクタ.
182     *
183     * @return void
184     */
185    function destroy() {
186        parent::destroy();
187    }
188
189
190    //---- 入力文字列を配列へ
191    function lfConvData( $data ){
192
193        // 文字列の変換(mb_convert_kanaの変換オプション)
194        $arrFlag = array(
195                         "year" => "n"
196                         ,"month" => "n"
197                         ,"day" => "n"
198                         ,"url" => "a"
199                         ,"news_title" => "aKV"
200                         ,"news_comment" => "aKV"
201                         ,"link_method" => "n"
202                         );
203
204        if ( is_array($data) ){
205            foreach ($arrFlag as $key=>$line) {
206                $data[$key] = isset($data[$key])
207                                      ? mb_convert_kana($data[$key], $line)
208                                      : "";
209            }
210        }
211
212        return $data;
213    }
214
215    //---- 指定順位へ移動
216    function sf_setRankPosition(&$objQuery, $tableName, $keyIdColumn, $keyId, $position) {
217
218        // 自身のランクを取得する
219        $objQuery->begin();
220        $rank = $objQuery->getOne("SELECT rank FROM $tableName WHERE $keyIdColumn = ?", array($keyId));
221
222        if( $position > $rank ) $term = "- 1";  //入れ替え先の順位が入れ換え元の順位より大きい場合
223        if( $position < $rank ) $term = "+ 1";  //入れ替え先の順位が入れ換え元の順位より小さい場合
224
225        //-- 指定した順位の商品から移動させる商品までのrankを1つずらす
226        $sql = "UPDATE $tableName SET rank = rank $term, update_date = NOW() WHERE rank BETWEEN ? AND ? AND del_flg = 0";
227        if( $position > $rank ) $objQuery->query( $sql, array( $rank + 1, $position ) );
228        if( $position < $rank ) $objQuery->query( $sql, array( $position, $rank - 1 ) );
229
230        //-- 指定した順位へrankを書き換える。
231        $sql  = "UPDATE $tableName SET rank = ?, update_date = NOW() WHERE $keyIdColumn = ? AND del_flg = 0 ";
232        $objQuery->query( $sql, array( $position, $keyId ) );
233        $objQuery->commit();
234    }
235
236    //---- 入力エラーチェック(順位移動用)
237    function sf_errorCheckPosition(&$objQuery, $tableName, $position, $keyIdColumn, $keyId) {
238
239        $objErr = new SC_CheckError();
240        $objErr->doFunc( array("移動順位", "moveposition", 4 ), array( "ZERO_CHECK", "NUM_CHECK", "EXIST_CHECK", "MAX_LENGTH_CHECK" ) );
241
242        // 自身のランクを取得する。
243        $rank = $objQuery->getOne("SELECT rank FROM $tableName WHERE $keyIdColumn = ?", array($keyId));
244        if ($rank == $position ) $objErr->arrErr["moveposition"] .= "※ 指定した移動順位は現在の順位です。";
245
246        // rankの最大値以上の入力を許容しない
247        if( ! $objErr->arrErr["position"] ) {
248            $sql = "SELECT MAX( rank ) FROM " .$tableName. " WHERE del_flg = 0";
249            $result = $objQuery->getOne($sql);
250            if( $position > $result ) $objErr->arrErr["moveposition"] .= "※ 入力された順位は、登録数の最大値を超えています。";
251        }
252
253        return $objErr->arrErr;
254    }
255
256    //---- 入力エラーチェック
257    function lfErrorCheck(){
258
259        $objErr = new SC_CheckError();
260
261        $objErr->doFunc(array("日付(年)", "year"), array("EXIST_CHECK"));
262        $objErr->doFunc(array("日付(月)", "month"), array("EXIST_CHECK"));
263        $objErr->doFunc(array("日付(日)", "day"), array("EXIST_CHECK"));
264        $objErr->doFunc(array("日付", "year", "month", "day"), array("CHECK_DATE"));
265        $objErr->doFunc(array("タイトル", 'news_title', MTEXT_LEN), array("EXIST_CHECK","MAX_LENGTH_CHECK"));
266        $objErr->doFunc(array("本文", 'url', URL_LEN), array("MAX_LENGTH_CHECK"));
267        $objErr->doFunc(array("本文", 'news_comment', LTEXT_LEN), array("MAX_LENGTH_CHECK"));
268
269        return $objErr->arrErr;
270    }
271
272    //INSERT文
273    function lfNewsInsert(&$objQuery){
274
275        if ($_POST["link_method"] == "") {
276            $_POST["link_method"] = 1;
277        }
278
279        //rankの最大+1を取得する
280        $rank_max = $objQuery->getOne("SELECT MAX(rank) + 1 FROM dtb_news WHERE del_flg = '0'");
281
282        $sql = "INSERT INTO dtb_news (news_id, news_date, news_title, creator_id, news_url, link_method, news_comment, rank, create_date, update_date)
283            VALUES (?,?,?,?,?,?,?,?,now(),now())";
284        $arrRegist = array($objQuery->nextVal('dtb_news_news_id'), $this->registDate, $_POST["news_title"], $_SESSION['member_id'],  $_POST["news_url"], $_POST["link_method"], $_POST["news_comment"], $rank_max);
285
286        $objQuery->query($sql, $arrRegist);
287
288        // 最初の1件目の登録はrankにNULLが入るので対策
289        $sql = "UPDATE dtb_news SET rank = 1 WHERE del_flg = 0 AND rank IS NULL";
290        $objQuery->query($sql);
291    }
292
293    function lfNewsUpdate(&$objQuery){
294
295        if ($_POST["link_method"] == "") {
296            $_POST["link_method"] = 1;
297        }
298
299        $sql = "UPDATE dtb_news SET news_date = ?, news_title = ?, creator_id = ?, update_date = NOW(),  news_url = ?, link_method = ?, news_comment = ? WHERE news_id = ?";
300        $arrRegist = array($this->registDate, $_POST['news_title'], $_SESSION['member_id'], $_POST['news_url'], $_POST["link_method"], $_POST['news_comment'], $_POST['news_id']);
301
302        $objQuery->query($sql, $arrRegist);
303    }
304}
305?>
Note: See TracBrowser for help on using the repository browser.