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

Revision 19661, 6.5 KB checked in by nanasess, 13 years ago (diff)

source:branches/camp/camp-2_5-E のマージ

  • スマートフォン対応(#787)
  • プラグイン機能(#494)
  • 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_Recommend 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/recomend.tpl';
47        $this->tpl_mainno = 'contents';
48        $this->tpl_subnavi = 'contents/subnavi.tpl';
49        $this->tpl_subno = "recommend";
50        $this->tpl_subtitle = 'おすすめ商品管理';
51    }
52
53    /**
54     * Page のプロセス.
55     *
56     * @return void
57     */
58    function process() {
59        $this->action();
60        $this->sendResponse();
61    }
62
63    /**
64     * Page のアクション.
65     *
66     * @return void
67     */
68    function action() {
69        $objQuery = new SC_Query();
70        $objSess = new SC_Session();
71
72        $arrRegistColumn = array(
73                                 array(  "column" => "product_id", "convert" => "n" ),
74                                 array(  "column" => "category_id", "convert" => "n" ),
75                                 array(  "column" => "rank", "convert" => "n" ),
76                                 array(  "column" => "comment", "convert" => "aKV" ),
77                                 );
78
79        // 認証可否の判定
80        SC_Utils_Ex::sfIsSuccess($objSess);
81
82        //最大登録数の表示
83        $this->tpl_disp_max = RECOMMEND_NUM;
84
85        if (!isset($_POST['mode'])) $_POST['mode'] = "";
86        if (!isset($_POST['category_id'])) $_POST['category_id'] = "";
87
88        // 登録時
89        if ( $_POST['mode'] == 'regist' ){
90
91            // 入力文字の強制変換
92            $this->arrForm = $_POST;
93            $this->arrForm = $this->lfConvertParam($this->arrForm, $arrRegistColumn);
94            // エラーチェック
95            $this->arrErr[$this->arrForm['rank']] = $this->lfErrorCheck();
96            if ( ! $this->arrErr[$this->arrForm['rank']]) {
97                // 古いのを消す
98                $sql = "DELETE FROM dtb_best_products WHERE category_id = ? AND rank = ?";
99                $objQuery->query($sql, array($this->arrForm['category_id'] ,$this->arrForm['rank']));
100
101                // DB登録
102                $this->arrForm['creator_id'] = $_SESSION['member_id'];
103                $this->arrForm['update_date'] = "NOW()";
104                $this->arrForm['create_date'] = "NOW()";
105                $this->arrForm['best_id'] = $objQuery->nextVal('dtb_best_products_best_id');
106                $objQuery->insert("dtb_best_products", $this->arrForm );
107            }
108
109        } elseif ( $_POST['mode'] == 'delete' ){
110            // 削除時
111
112            $sql = "DELETE FROM dtb_best_products WHERE category_id = ? AND rank = ?";
113            $objQuery->query($sql, array($_POST['category_id'] ,$_POST['rank']));
114
115        }
116
117        // カテゴリID取得 無いときはトップページ
118        if ( SC_Utils_Ex::sfCheckNumLength($_POST['category_id']) ){
119            $this->category_id = $_POST['category_id'];
120        } else {
121            $this->category_id = 0;
122        }
123
124        // 既に登録されている内容を取得する
125        $sql = "SELECT B.name, B.main_list_image, A.* FROM dtb_best_products as A INNER JOIN dtb_products as B USING (product_id)
126         WHERE A.del_flg = 0 ORDER BY rank";
127        $arrItems = $objQuery->getAll($sql);
128        foreach( $arrItems as $data ){
129            $this->arrItems[$data['rank']] = $data;
130        }
131
132        // 商品変更時 or 登録エラー時は、選択された商品に一時的に置き換える
133        if (
134            $_POST['mode'] == 'set_item'
135            || $_POST['mode'] == 'regist' && !empty($this->arrErr[$this->arrForm['rank']])
136        ) {
137            $sql = "SELECT product_id, name, main_list_image FROM dtb_products WHERE product_id = ? AND del_flg = 0";
138            $result = $objQuery->getAll($sql, array($_POST['product_id']));
139            if ( $result ){
140                $data = $result[0];
141                foreach( $data as $key=>$val){
142                    $this->arrItems[$_POST['rank']][$key] = $val;
143                }
144                $this->arrItems[$_POST['rank']]['rank'] = $_POST['rank'];
145            }
146            $this->checkRank = $_POST['rank'];
147        }
148
149        //各ページ共通
150        $this->cnt_question = 6;
151        $this->arrActive = isset($arrActive) ? $arrActive : "";;
152        $this->arrQuestion = isset($arrQuestion) ? $arrQuestion : "";
153
154        // カテゴリ取得
155        $objDb = new SC_Helper_DB_Ex();
156        $this->arrCatList = $objDb->sfGetCategoryList("level = 1");
157    }
158
159    /**
160     * デストラクタ.
161     *
162     * @return void
163     */
164    function destroy() {
165        parent::destroy();
166    }
167
168    //---- 取得文字列の変換
169    function lfConvertParam($array, $arrRegistColumn) {
170
171        // カラム名とコンバート情報
172        foreach ($arrRegistColumn as $data) {
173            $arrConvList[ $data["column"] ] = $data["convert"];
174        }
175        // 文字変換
176        $new_array = array();
177        foreach ($arrConvList as $key => $val) {
178            $new_array[$key] = isset($array[$key]) ? $array[$key] : "";
179            if( strlen($val) > 0) {
180                $new_array[$key] = mb_convert_kana($new_array[$key] ,$val);
181            }
182        }
183        return $new_array;
184
185    }
186
187    /* 入力エラーチェック */
188    function lfErrorCheck() {
189        $objQuery = new SC_Query;
190        $objErr = new SC_CheckError();
191
192        $objErr->doFunc(array("コメント", "comment", LTEXT_LEN), array("EXIST_CHECK","MAX_LENGTH_CHECK"));
193
194        return $objErr->arrErr;
195    }
196
197}
198?>
Note: See TracBrowser for help on using the repository browser.