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

Revision 20116, 9.2 KB checked in by nanasess, 13 years ago (diff)
  • svn properties を再設定
  • 再設定用のスクリプト追加
  • 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// {{{ requires
25require_once(CLASS_REALDIR . "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        //---- 新規登録/編集登録
88        switch ($this->getMode()) {
89        case 'regist':
90            $_POST = $this->lfConvData($_POST);
91
92            if ($this->arrErr = $this->lfErrorCheck()) {       // 入力エラーのチェック
93                $this->arrForm = $_POST;
94            } else {
95
96                if (isset($_POST['link_method']) == ""){
97                    $_POST['link_method'] = 1;
98                }
99
100                $this->registDate = $_POST['year'] ."/". $_POST['month'] ."/". $_POST['day'];
101
102                //-- 編集登録
103                if (strlen($_POST["news_id"]) > 0 && is_numeric($_POST["news_id"])) {
104
105                    $this->lfNewsUpdate($objQuery);
106
107                    //-- 新規登録
108                } else {
109                    $this->lfNewsInsert($objQuery);
110                }
111
112                $this->tpl_onload = "window.alert('編集が完了しました');";
113            }
114            break;
115        case 'search':
116        //---- 編集データ取得
117            if (is_numeric($_POST["news_id"])) {
118                $sql = "SELECT *, cast(news_date as date) as cast_news_date FROM dtb_news WHERE news_id = ? ";
119                $result = $objQuery->getAll($sql, array($_POST["news_id"]));
120                $this->arrForm = $result[0];
121
122                $arrData = split("-", $result[0]["cast_news_date"]);
123                $this->arrForm['year']  = $arrData[0];
124                $this->arrForm['month'] = $arrData[1];
125                $this->arrForm['day']   = $arrData[2];
126
127                $this->edit_mode = "on";
128            }
129            break;
130        case 'delete':
131        //---- データ削除
132            if (is_numeric($_POST["news_id"])) {
133                // rankを取得
134                $pre_rank = $objQuery->getOne(" SELECT rank FROM dtb_news WHERE del_flg = 0 AND news_id = ? ", array( $_POST['news_id']  ));
135
136                //-- 削除する新着情報以降のrankを1つ繰り上げておく
137                $objQuery->begin();
138                $sql = "UPDATE dtb_news SET rank = rank - 1, update_date = NOW() WHERE del_flg = 0 AND rank > ?";
139                $objQuery->query( $sql, array( $pre_rank  ) );
140
141                $sql = "UPDATE dtb_news SET rank = 0, del_flg = 1, update_date = NOW() WHERE news_id = ?";
142                $objQuery->query( $sql, array( $_POST['news_id'] ) );
143                $objQuery->commit();
144
145                $this->objDisplay->reload();             //自分にリダイレクト(再読込による誤動作防止)
146            }
147            break;
148        case 'move':
149        //---- 表示順位移動
150            if (is_numeric($_POST["news_id"]) ) {
151                if ($_POST["term"] == "up") {
152                    $objDb->sfRankUp("dtb_news", "news_id", $_POST["news_id"]);
153                } else if ($_POST["term"] == "down") {
154                    $objDb->sfRankDown("dtb_news", "news_id", $_POST["news_id"]);
155                }
156                //sf_rebuildIndex($conn);
157                $this->objDisplay->reload();
158            }
159            break;
160        case 'moveRankSet':
161        //---- 指定表示順位移動
162            $key = "pos-".$_POST['news_id'];
163            $input_pos = mb_convert_kana($_POST[$key], "n");
164            if(SC_Utils_Ex::sfIsInt($input_pos)) {
165                $objDb->sfMoveRank("dtb_news", "news_id", $_POST['news_id'], $input_pos);
166                $this->objDisplay->reload();
167            }
168            break;
169        default:
170            break;
171        }
172
173        //---- 全データ取得
174        $sql = "SELECT *, cast(news_date as date) as cast_news_date FROM dtb_news WHERE del_flg = '0' ORDER BY rank DESC";
175        $this->list_data = $objQuery->getAll($sql);
176        $this->line_max = count($this->list_data);
177        $sql = "SELECT MAX(rank) FROM dtb_news WHERE del_flg = '0'";        // rankの最大値を取得
178        $this->max_rank = $objQuery->getOne($sql);
179    }
180
181
182    /**
183     * デストラクタ.
184     *
185     * @return void
186     */
187    function destroy() {
188        parent::destroy();
189    }
190
191
192    //---- 入力文字列を配列へ
193    function lfConvData( $data ){
194
195        // 文字列の変換(mb_convert_kanaの変換オプション)
196        $arrFlag = array(
197                         "year" => "n"
198                         ,"month" => "n"
199                         ,"day" => "n"
200                         ,"url" => "a"
201                         ,"news_title" => "aKV"
202                         ,"news_comment" => "aKV"
203                         ,"link_method" => "n"
204                         );
205
206        if ( is_array($data) ){
207            foreach ($arrFlag as $key=>$line) {
208                $data[$key] = isset($data[$key])
209                                      ? mb_convert_kana($data[$key], $line)
210                                      : "";
211            }
212        }
213
214        return $data;
215    }
216
217    //---- 入力エラーチェック
218    function lfErrorCheck(){
219
220        $objErr = new SC_CheckError();
221
222        $objErr->doFunc(array("日付(年)", "year"), array("EXIST_CHECK"));
223        $objErr->doFunc(array("日付(月)", "month"), array("EXIST_CHECK"));
224        $objErr->doFunc(array("日付(日)", "day"), array("EXIST_CHECK"));
225        $objErr->doFunc(array("日付", "year", "month", "day"), array("CHECK_DATE"));
226        $objErr->doFunc(array("タイトル", 'news_title', MTEXT_LEN), array("EXIST_CHECK","MAX_LENGTH_CHECK"));
227        $objErr->doFunc(array("本文", 'url', URL_LEN), array("MAX_LENGTH_CHECK"));
228        $objErr->doFunc(array("本文", 'news_comment', LTEXT_LEN), array("MAX_LENGTH_CHECK"));
229
230        return $objErr->arrErr;
231    }
232
233    //INSERT文
234    function lfNewsInsert(&$objQuery){
235
236        if ($_POST["link_method"] == "") {
237            $_POST["link_method"] = 1;
238        }
239
240        //rankの最大+1を取得する
241        $rank_max = $objQuery->getOne("SELECT MAX(rank) + 1 FROM dtb_news WHERE del_flg = '0'");
242
243        $sql = "INSERT INTO dtb_news (news_id, news_date, news_title, creator_id, news_url, link_method, news_comment, rank, create_date, update_date)
244            VALUES (?,?,?,?,?,?,?,?,now(),now())";
245        $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);
246
247        $objQuery->query($sql, $arrRegist);
248
249        // 最初の1件目の登録はrankにNULLが入るので対策
250        $sql = "UPDATE dtb_news SET rank = 1 WHERE del_flg = 0 AND rank IS NULL";
251        $objQuery->query($sql);
252    }
253
254    function lfNewsUpdate(&$objQuery){
255
256        if ($_POST["link_method"] == "") {
257            $_POST["link_method"] = 1;
258        }
259
260        $sql = "UPDATE dtb_news SET news_date = ?, news_title = ?, creator_id = ?, update_date = NOW(),  news_url = ?, link_method = ?, news_comment = ? WHERE news_id = ?";
261        $arrRegist = array($this->registDate, $_POST['news_title'], $_SESSION['member_id'], $_POST['news_url'], $_POST["link_method"], $_POST['news_comment'], $_POST['news_id']);
262
263        $objQuery->query($sql, $arrRegist);
264    }
265}
266?>
Note: See TracBrowser for help on using the repository browser.