1 | <?php |
---|
2 | /* |
---|
3 | * Copyright(c) 2000-2007 LOCKON CO.,LTD. All Rights Reserved. |
---|
4 | * |
---|
5 | * http://www.lockon.co.jp/ |
---|
6 | */ |
---|
7 | |
---|
8 | // {{{ requires |
---|
9 | require_once(CLASS_PATH . "pages/LC_Page.php"); |
---|
10 | |
---|
11 | /** |
---|
12 | * おすすめ管理 のページクラス. |
---|
13 | * |
---|
14 | * @package Page |
---|
15 | * @author LOCKON CO.,LTD. |
---|
16 | * @version $Id$ |
---|
17 | */ |
---|
18 | class LC_Page_Admin_Contents_Recommend extends LC_Page { |
---|
19 | |
---|
20 | // }}} |
---|
21 | // {{{ functions |
---|
22 | |
---|
23 | /** |
---|
24 | * Page を初期化する. |
---|
25 | * |
---|
26 | * @return void |
---|
27 | */ |
---|
28 | function init() { |
---|
29 | parent::init(); |
---|
30 | $this->tpl_mainpage = 'contents/recomend.tpl'; |
---|
31 | $this->tpl_mainno = 'contents'; |
---|
32 | $this->tpl_subnavi = 'contents/subnavi.tpl'; |
---|
33 | $this->tpl_subno = "recommend"; |
---|
34 | $this->tpl_subtitle = 'オススメ管理'; |
---|
35 | } |
---|
36 | |
---|
37 | /** |
---|
38 | * Page のプロセス. |
---|
39 | * |
---|
40 | * @return void |
---|
41 | */ |
---|
42 | function process() { |
---|
43 | $conn = new SC_DBConn(); |
---|
44 | $objView = new SC_AdminView(); |
---|
45 | $objSess = new SC_Session(); |
---|
46 | |
---|
47 | $arrRegistColumn = array( |
---|
48 | array( "column" => "product_id", "convert" => "n" ), |
---|
49 | array( "column" => "category_id", "convert" => "n" ), |
---|
50 | array( "column" => "rank", "convert" => "n" ), |
---|
51 | array( "column" => "title", "convert" => "aKV" ), |
---|
52 | array( "column" => "comment", "convert" => "aKV" ), |
---|
53 | ); |
---|
54 | |
---|
55 | // 認証可否の判定 |
---|
56 | SC_Utils_Ex::sfIsSuccess($objSess); |
---|
57 | |
---|
58 | //最大登録数の表示 |
---|
59 | $this->tpl_disp_max = RECOMMEND_NUM; |
---|
60 | |
---|
61 | if (!isset($_POST['mode'])) $_POST['mode'] = ""; |
---|
62 | if (!isset($_POST['category_id'])) $_POST['category_id'] = ""; |
---|
63 | |
---|
64 | // 登録時 |
---|
65 | if ( $_POST['mode'] == 'regist' ){ |
---|
66 | |
---|
67 | // 入力文字の強制変換 |
---|
68 | $this->arrForm = $_POST; |
---|
69 | $this->arrForm = lfConvertParam($this->arrForm, $arrRegistColumn); |
---|
70 | // エラーチェック |
---|
71 | $this->arrErr[$this->arrForm['rank']] = lfErrorCheck(); |
---|
72 | if ( ! $this->arrErr[$this->arrForm['rank']]) { |
---|
73 | // 古いのを消す |
---|
74 | $sql = "DELETE FROM dtb_best_products WHERE category_id = ? AND rank = ?"; |
---|
75 | $conn->query($sql, array($this->arrForm['category_id'] ,$this->arrForm['rank'])); |
---|
76 | |
---|
77 | // DB登録 |
---|
78 | $this->arrForm['creator_id'] = $_SESSION['member_id']; |
---|
79 | $this->arrForm['update_date'] = "NOW()"; |
---|
80 | $this->arrForm['create_date'] = "NOW()"; |
---|
81 | |
---|
82 | $objQuery = new SC_Query(); |
---|
83 | $objQuery->insert("dtb_best_products", $this->arrForm ); |
---|
84 | // $conn->autoExecute("dtb_best_products", $this->arrForm ); |
---|
85 | } |
---|
86 | |
---|
87 | } elseif ( $_POST['mode'] == 'delete' ){ |
---|
88 | // 削除時 |
---|
89 | |
---|
90 | $sql = "DELETE FROM dtb_best_products WHERE category_id = ? AND rank = ?"; |
---|
91 | $conn->query($sql, array($_POST['category_id'] ,$_POST['rank'])); |
---|
92 | |
---|
93 | } |
---|
94 | |
---|
95 | // カテゴリID取得 無いときはトップページ |
---|
96 | if ( SC_Utils_Ex::sfCheckNumLength($_POST['category_id']) ){ |
---|
97 | $this->category_id = $_POST['category_id']; |
---|
98 | } else { |
---|
99 | $this->category_id = 0; |
---|
100 | } |
---|
101 | |
---|
102 | // 既に登録されている内容を取得する |
---|
103 | $sql = "SELECT B.name, B.main_list_image, A.* FROM dtb_best_products as A INNER JOIN dtb_products as B USING (product_id) |
---|
104 | WHERE A.del_flg = 0 ORDER BY rank"; |
---|
105 | $arrItems = $conn->getAll($sql); |
---|
106 | foreach( $arrItems as $data ){ |
---|
107 | $this->arrItems[$data['rank']] = $data; |
---|
108 | } |
---|
109 | |
---|
110 | // 商品変更時は、選択された商品に一時的に置き換える |
---|
111 | if ( $_POST['mode'] == 'set_item'){ |
---|
112 | $sql = "SELECT product_id, name, main_list_image FROM dtb_products WHERE product_id = ? AND del_flg = 0"; |
---|
113 | $result = $conn->getAll($sql, array($_POST['product_id'])); |
---|
114 | if ( $result ){ |
---|
115 | $data = $result[0]; |
---|
116 | foreach( $data as $key=>$val){ |
---|
117 | $this->arrItems[$_POST['rank']][$key] = $val; |
---|
118 | } |
---|
119 | $this->arrItems[$_POST['rank']]['rank'] = $_POST['rank']; |
---|
120 | } |
---|
121 | $this->checkRank = $_POST['rank']; |
---|
122 | } |
---|
123 | |
---|
124 | //各ページ共通 |
---|
125 | $this->cnt_question = 6; |
---|
126 | $this->arrActive = isset($arrActive) ? $arrActive : "";; |
---|
127 | $this->arrQuestion = isset($arrQuestion) ? $arrQuestion : ""; |
---|
128 | |
---|
129 | // カテゴリ取得 |
---|
130 | $objDb = new SC_Helper_DB_Ex(); |
---|
131 | $this->arrCatList = $objDb->sfGetCategoryList("level = 1"); |
---|
132 | |
---|
133 | //---- ページ表示 |
---|
134 | $objView->assignobj($this); |
---|
135 | $objView->display(MAIN_FRAME); |
---|
136 | } |
---|
137 | |
---|
138 | /** |
---|
139 | * デストラクタ. |
---|
140 | * |
---|
141 | * @return void |
---|
142 | */ |
---|
143 | function destroy() { |
---|
144 | parent::destroy(); |
---|
145 | } |
---|
146 | |
---|
147 | //---- 取得文字列の変換 |
---|
148 | function lfConvertParam($array, $arrRegistColumn) { |
---|
149 | |
---|
150 | // カラム名とコンバート情報 |
---|
151 | foreach ($arrRegistColumn as $data) { |
---|
152 | $arrConvList[ $data["column"] ] = $data["convert"]; |
---|
153 | } |
---|
154 | // 文字変換 |
---|
155 | $new_array = array(); |
---|
156 | foreach ($arrConvList as $key => $val) { |
---|
157 | $new_array[$key] = $array[$key]; |
---|
158 | if( strlen($val) > 0) { |
---|
159 | $new_array[$key] = mb_convert_kana($new_array[$key] ,$val); |
---|
160 | } |
---|
161 | } |
---|
162 | return $new_array; |
---|
163 | |
---|
164 | } |
---|
165 | |
---|
166 | /* 入力エラーチェック */ |
---|
167 | function lfErrorCheck() { |
---|
168 | $objQuery = new SC_Query; |
---|
169 | $objErr = new SC_CheckError(); |
---|
170 | |
---|
171 | $objErr->doFunc(array("見出しコメント", "title", STEXT_LEN), array("MAX_LENGTH_CHECK")); |
---|
172 | $objErr->doFunc(array("オススメコメント", "comment", LTEXT_LEN), array("EXIST_CHECK","MAX_LENGTH_CHECK")); |
---|
173 | |
---|
174 | return $objErr->arrErr; |
---|
175 | } |
---|
176 | |
---|
177 | } |
---|
178 | ?> |
---|