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

Revision 21743, 12.0 KB checked in by AMUAMU, 12 years ago (diff)

#1754 (exit;を個別の処理でしない) #1692 (プラグイン機能) 各ファイルでフックポイントの呼出を書かないで、自動的にフックポイントを呼び出すように修正。

  • 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
RevLine 
[15659]1<?php
2/*
[16582]3 * This file is part of EC-CUBE
4 *
[20764]5 * Copyright(c) 2000-2011 LOCKON CO.,LTD. All Rights Reserved.
[15659]6 *
7 * http://www.lockon.co.jp/
[16582]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.
[15659]22 */
23
24// {{{ requires
[20534]25require_once CLASS_EX_REALDIR . 'page_extends/admin/LC_Page_Admin_Ex.php';
[15659]26
27/**
28 * コンテンツ管理 のページクラス.
29 *
30 * @package Page
31 * @author LOCKON CO.,LTD.
32 * @version $Id$
33 */
[20345]34class LC_Page_Admin_Contents extends LC_Page_Admin_Ex {
[15659]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';
[20538]47        $this->tpl_subno = 'index';
[15659]48        $this->tpl_mainno = 'contents';
[19707]49        $this->arrForm = array(
50            'year' => date('Y'),
51            'month' => date('n'),
52            'day' => date('j'),
53        );
[20911]54        $this->tpl_maintitle = 'コンテンツ管理';
[15659]55        $this->tpl_subtitle = '新着情報管理';
[20265]56        //---- 日付プルダウン設定
[20499]57        $objDate = new SC_Date_Ex(ADMIN_NEWS_STARTYEAR);
[20265]58        $this->arrYear = $objDate->getYear();
59        $this->arrMonth = $objDate->getMonth();
60        $this->arrDay = $objDate->getDay();
[15659]61    }
62
63    /**
64     * Page のプロセス.
65     *
66     * @return void
67     */
68    function process() {
[19661]69        $this->action();
70        $this->sendResponse();
71    }
[15659]72
[19661]73    /**
74     * Page のアクション.
75     *
76     * @return void
77     */
78    function action() {
[21591]79
[20335]80        $objDb = new SC_Helper_DB_Ex();
[20501]81        $objFormParam = new SC_FormParam_Ex();
[20265]82        $this->lfInitParam($objFormParam);
83        $objFormParam->setParam($_POST);
84        $objFormParam->convParam();
85        $news_id = $objFormParam->getValue('news_id');
[15659]86
87        //---- 新規登録/編集登録
[20044]88        switch ($this->getMode()) {
[21526]89            case 'regist':
90                $arrPost = $objFormParam->getHashArray();
91                $this->arrErr = $this->lfCheckError($objFormParam);
92                if (SC_Utils_Ex::isBlank($this->arrErr)) {
93                    // ニュースIDの値がPOSTされて来た場合は既存データの編集とみなし、
94                    // 更新メソッドを呼び出す。
95                    // ニュースIDが存在しない場合は新規登録を行う。
96                    $arrPost['link_method'] = $this->checkLinkMethod($arrPost['link_method']);
97                    $arrPost['news_date'] = $this->getRegistDate($arrPost);
98                    $member_id = $_SESSION['member_id'];
99                    if (strlen($news_id) > 0 && is_numeric($news_id)) {
100                        $this->lfNewsUpdate($arrPost,$member_id);
101                    } else {
102                        $this->lfNewsInsert($arrPost,$member_id);
103                    }
104                    $news_id = '';
105                    $this->tpl_onload = "window.alert('編集が完了しました');";
[15659]106                } else {
[21526]107                    $this->arrForm = $arrPost;
[15659]108                }
[21526]109                break;
110            case 'search':
111                if (is_numeric($news_id)) {
112                    list($this->arrForm) = $this->getNews($news_id);
113                    list($this->arrForm['year'],$this->arrForm['month'],$this->arrForm['day']) = $this->splitNewsDate($this->arrForm['cast_news_date']);
114                    $this->edit_mode = 'on';
[20044]115                }
[21526]116                break;
117            case 'delete':
118            //---- データ削除
119                if (is_numeric($news_id)) {
120                    $pre_rank = $this->getRankByNewsId($news_id);
121                    $this->computeRankForDelete($news_id,$pre_rank);
[21591]122
[21526]123                    SC_Response_Ex::reload();             //自分にリダイレクト(再読込による誤動作防止)
124                }
125                break;
126            case 'move':
127            //---- 表示順位移動
128                if (strlen($news_id) > 0 && is_numeric($news_id) == true) {
129                    $term = $objFormParam->getValue('term');
130                    if ($term == 'up') {
131                        $objDb->sfRankUp('dtb_news', 'news_id', $news_id);
132                    } else if ($term == 'down') {
133                        $objDb->sfRankDown('dtb_news', 'news_id', $news_id);
134                    }
[21592]135
[21526]136                    $this->objDisplay->reload();
137                }
138                break;
139            case 'moveRankSet':
140            //---- 指定表示順位移動
141                $input_pos = $this->getPostRank($news_id);
142                if (SC_Utils_Ex::sfIsInt($input_pos)) {
143                    $objDb->sfMoveRank('dtb_news', 'news_id', $news_id, $input_pos);
[21591]144
[21526]145                    $this->objDisplay->reload();
146                }
147                break;
148            default:
149                break;
[15659]150        }
151
[20288]152        $this->arrNews = $this->getNews();
[20598]153        $this->tpl_news_id = $news_id;
[20288]154        $this->line_max = count($this->arrNews);
[20265]155        $this->max_rank = $this->getRankMax();
[21591]156
[15659]157    }
158
159    /**
160     * デストラクタ.
161     *
162     * @return void
163     */
164    function destroy() {
165        parent::destroy();
166    }
167
[20265]168    /**
[20970]169     * 入力されたパラメーターのエラーチェックを行う。
[20265]170     * @param Object $objFormParam
171     * @return Array エラー内容
172     */
[21479]173    function lfCheckError(&$objFormParam) {
[20503]174        $objErr = new SC_CheckError_Ex($objFormParam->getHashArray());
[20265]175        $objErr->arrErr = $objFormParam->checkError();
[21514]176        $objErr->doFunc(array('日付', 'year', 'month', 'day'), array('CHECK_DATE'));
[20265]177        return $objErr->arrErr;
178    }
[15659]179
[20265]180    /**
[20970]181     * パラメーターの初期化を行う
[20265]182     * @param Object $objFormParam
183     */
[21479]184    function lfInitParam(&$objFormParam) {
[21481]185        $objFormParam->addParam('news_id', 'news_id');
[21514]186        $objFormParam->addParam('日付(年)', 'year', INT_LEN, 'n', array('EXIST_CHECK', 'NUM_CHECK', 'MAX_LENGTH_CHECK'));
187        $objFormParam->addParam('日付(月)', 'month', INT_LEN, 'n', array('EXIST_CHECK', 'NUM_CHECK', 'MAX_LENGTH_CHECK'));
188        $objFormParam->addParam('日付(日)', 'day', INT_LEN, 'n', array('EXIST_CHECK', 'NUM_CHECK', 'MAX_LENGTH_CHECK'));
189        $objFormParam->addParam('タイトル', 'news_title', MTEXT_LEN, 'KVa', array('EXIST_CHECK','MAX_LENGTH_CHECK','SPTAB_CHECK'));
[21480]190        $objFormParam->addParam('URL', 'news_url', URL_LEN, 'KVa', array('MAX_LENGTH_CHECK'));
[21514]191        $objFormParam->addParam('本文', 'news_comment', LTEXT_LEN, 'KVa', array('MAX_LENGTH_CHECK'));
192        $objFormParam->addParam('別ウィンドウで開く', 'link_method', INT_LEN, 'n', array('NUM_CHECK', 'MAX_LENGTH_CHECK'));
193        $objFormParam->addParam('ランク移動', 'term', INT_LEN, 'n', array('NUM_CHECK', 'MAX_LENGTH_CHECK'));
[20265]194    }
[15659]195
[20265]196    /**
197     * 新着記事のデータの登録を行う
198     * @param Array $arrPost POSTデータの配列
199     * @param Integer $member_id 登録した管理者のID
200     */
[21479]201    function lfNewsInsert($arrPost,$member_id) {
[20507]202        $objQuery = $objQuery =& SC_Query_Ex::getSingletonInstance();
[20540]203
[20265]204        // rankの最大+1を取得する
205        $rank_max = $this->getRankMax();
206        $rank_max = $rank_max + 1;
[20540]207
[20265]208        $table = 'dtb_news';
209        $sqlval = array();
210        $news_id = $objQuery->nextVal('dtb_news_news_id');
211        $sqlval['news_id'] = $news_id;
212        $sqlval['news_date'] = $arrPost['news_date'];
213        $sqlval['news_title'] = $arrPost['news_title'];
214        $sqlval['creator_id'] = $member_id;
215        $sqlval['news_url'] = $arrPost['news_url'];
216        $sqlval['link_method'] = $arrPost['link_method'];
217        $sqlval['news_comment'] = $arrPost['news_comment'];
218        $sqlval['rank'] = $rank_max;
[21185]219        $sqlval['create_date'] = 'CURRENT_TIMESTAMP';
220        $sqlval['update_date'] = 'CURRENT_TIMESTAMP';
[20265]221        $objQuery->insert($table, $sqlval);
[15659]222    }
223
[21479]224    function lfNewsUpdate($arrPost,$member_id) {
[20507]225        $objQuery = $objQuery =& SC_Query_Ex::getSingletonInstance();
[15659]226
[20265]227        $table = 'dtb_news';
228        $sqlval = array();
229        $sqlval['news_date'] = $arrPost['news_date'];
230        $sqlval['news_title'] = $arrPost['news_title'];
231        $sqlval['creator_id'] = $member_id;
232        $sqlval['news_url'] = $arrPost['news_url'];
233        $sqlval['news_comment'] = $arrPost['news_comment'];
234        $sqlval['link_method'] = $arrPost['link_method'];
[21185]235        $sqlval['update_date'] = 'CURRENT_TIMESTAMP';
[20265]236        $where = 'news_id = ?';
237        $arrValIn = array($arrPost['news_id']);
238        $objQuery->update($table, $sqlval, $where, $arrValIn);
239    }
[15659]240
[20265]241    /**
242     * データの登録日を返す。
243     * @param Array $arrPost POSTのグローバル変数
244     * @return string 登録日を示す文字列
245     */
[21479]246    function getRegistDate($arrPost) {
[21515]247        $registDate = $arrPost['year'] .'/'. $arrPost['month'] .'/'. $arrPost['day'];
[20265]248        return $registDate;
[15659]249    }
250
[20265]251    /**
252     * チェックボックスの値が空の時は無効な値として1を格納する
253     * @param int $link_method
254     * @return int
255     */
[21479]256    function checkLinkMethod($link_method) {
[21441]257        if (strlen($link_method) == 0) {
[20265]258            $link_method = 1;
[15659]259        }
[20265]260        return $link_method;
261    }
[15659]262
[20265]263    /**
264     * ニュース記事を取得する。
265     * @param Integer news_id ニュースID
266     */
[21479]267    function getNews($news_id = '') {
[20507]268        $objQuery = $objQuery =& SC_Query_Ex::getSingletonInstance();
[20265]269        $col = '*, cast(news_date as date) as cast_news_date';
270        $table = 'dtb_news';
271        $order = 'rank DESC';
[21441]272        if (strlen($news_id) == 0) {
[20265]273            $where = 'del_flg = 0';
[21563]274            $arrWhereVal = array();
[21441]275        } else {
[20265]276            $where = 'del_flg = 0 AND news_id = ?';
[21563]277            $arrWhereVal = array($news_id);
[20265]278        }
279        $objQuery->setOrder($order);
[21563]280        return $objQuery->select($col, $table, $where, $arrWhereVal);
[20265]281    }
[15659]282
[20265]283    /**
284     * 指定されたニュースのランクの値を取得する。
285     * @param Integer $news_id
286     */
[21479]287    function getRankByNewsId($news_id) {
[20507]288        $objQuery = $objQuery =& SC_Query_Ex::getSingletonInstance();
[20265]289        $col = 'rank';
290        $table = 'dtb_news';
291        $where = 'del_flg = 0 AND news_id = ?';
[21563]292        $arrWhereVal = array($news_id);
293        list($rank) = $objQuery->select($col, $table, $where, $arrWhereVal);
[20265]294        return $rank['rank'];
295    }
[15659]296
[20265]297    /**
298     * 削除する新着情報以降のrankを1つ繰り上げる。
299     * @param Integer $news_id
300     * @param Integer $rank
301     */
[21479]302    function computeRankForDelete($news_id,$rank) {
[21608]303        SC_Helper_DB_Ex::sfDeleteRankRecord('dtb_news', 'news_id', $news_id);
[15659]304    }
305
[20265]306    /**
307     * ニュースの日付の値をフロントでの表示形式に合わせるために分割
308     * @param String $news_date
309     */
[21479]310    function splitNewsDate($news_date) {
[21514]311        return explode('-', $news_date);
[20265]312    }
[15659]313
[20265]314    /**
315     * ランクの最大値の値を返す。
316     * @return Intger $max ランクの最大値の値
317     */
[21479]318    function getRankMax() {
[20507]319        $objQuery =& SC_Query_Ex::getSingletonInstance();
[20637]320        $col = 'MAX(rank) as max';
[20265]321        $table = 'dtb_news';
322        $where = 'del_flg = 0';
323        list($result) = $objQuery->select($col, $table, $where);
324        return $result['max'];
325    }
[15659]326
[20265]327    /**
328     * POSTされたランクの値を取得する
329     * @param Object $objFormParam
330     * @param Integer $news_id
331     */
[21479]332    function getPostRank($news_id) {
[21441]333        if (strlen($news_id) > 0 && is_numeric($news_id) == true) {
[21527]334            $key = 'pos-' . $news_id;
335            $input_pos = $_POST[$key];
336            return $input_pos;
[20265]337        }
[15659]338    }
[20265]339
[15659]340}
Note: See TracBrowser for help on using the repository browser.