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