1 | <?php |
---|
2 | /* |
---|
3 | * This file is part of EC-CUBE |
---|
4 | * |
---|
5 | * Copyright(c) 2000-2013 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 | require_once CLASS_EX_REALDIR . 'page_extends/admin/LC_Page_Admin_Ex.php'; |
---|
25 | |
---|
26 | /** |
---|
27 | * コンテンツ管理 のページクラス. |
---|
28 | * |
---|
29 | * @package Page |
---|
30 | * @author LOCKON CO.,LTD. |
---|
31 | * @version $Id$ |
---|
32 | */ |
---|
33 | class LC_Page_Admin_Contents extends LC_Page_Admin_Ex |
---|
34 | { |
---|
35 | /** |
---|
36 | * Page を初期化する. |
---|
37 | * |
---|
38 | * @return void |
---|
39 | */ |
---|
40 | public function init() |
---|
41 | { |
---|
42 | parent::init(); |
---|
43 | $this->tpl_mainpage = 'contents/index.tpl'; |
---|
44 | $this->tpl_subno = 'index'; |
---|
45 | $this->tpl_mainno = 'contents'; |
---|
46 | $this->arrForm = array( |
---|
47 | 'year' => date('Y'), |
---|
48 | 'month' => date('n'), |
---|
49 | 'day' => date('j'), |
---|
50 | ); |
---|
51 | $this->tpl_maintitle = 'コンテンツ管理'; |
---|
52 | $this->tpl_subtitle = '新着情報管理'; |
---|
53 | //---- 日付プルダウン設定 |
---|
54 | $objDate = new SC_Date_Ex(ADMIN_NEWS_STARTYEAR); |
---|
55 | $this->arrYear = $objDate->getYear(); |
---|
56 | $this->arrMonth = $objDate->getMonth(); |
---|
57 | $this->arrDay = $objDate->getDay(); |
---|
58 | } |
---|
59 | |
---|
60 | /** |
---|
61 | * Page のプロセス. |
---|
62 | * |
---|
63 | * @return void |
---|
64 | */ |
---|
65 | public function process() |
---|
66 | { |
---|
67 | $this->action(); |
---|
68 | $this->sendResponse(); |
---|
69 | } |
---|
70 | |
---|
71 | /** |
---|
72 | * Page のアクション. |
---|
73 | * |
---|
74 | * @return void |
---|
75 | */ |
---|
76 | public function action() |
---|
77 | { |
---|
78 | $objNews = new SC_Helper_News_Ex(); |
---|
79 | |
---|
80 | $objFormParam = new SC_FormParam_Ex(); |
---|
81 | $this->lfInitParam($objFormParam); |
---|
82 | $objFormParam->setParam($_POST); |
---|
83 | $objFormParam->convParam(); |
---|
84 | |
---|
85 | $news_id = $objFormParam->getValue('news_id'); |
---|
86 | |
---|
87 | //---- 新規登録/編集登録 |
---|
88 | switch ($this->getMode()) { |
---|
89 | case 'edit': |
---|
90 | $this->arrErr = $this->lfCheckError($objFormParam); |
---|
91 | if (!SC_Utils_Ex::isBlank($this->arrErr['news_id'])) { |
---|
92 | trigger_error('', E_USER_ERROR); |
---|
93 | |
---|
94 | return; |
---|
95 | } |
---|
96 | |
---|
97 | if (count($this->arrErr) <= 0) { |
---|
98 | // POST値の引き継ぎ |
---|
99 | $arrParam = $objFormParam->getHashArray(); |
---|
100 | // 登録実行 |
---|
101 | $res_news_id = $this->doRegist($news_id, $arrParam, $objNews); |
---|
102 | if ($res_news_id !== FALSE) { |
---|
103 | // 完了メッセージ |
---|
104 | $news_id = $res_news_id; |
---|
105 | $this->tpl_onload = "alert('登録が完了しました。');"; |
---|
106 | } |
---|
107 | } |
---|
108 | // POSTデータを引き継ぐ |
---|
109 | $this->tpl_news_id = $news_id; |
---|
110 | break; |
---|
111 | |
---|
112 | case 'pre_edit': |
---|
113 | $news = $objNews->getNews($news_id); |
---|
114 | list($news['year'],$news['month'],$news['day']) = $this->splitNewsDate($news['cast_news_date']); |
---|
115 | $objFormParam->setParam($news); |
---|
116 | |
---|
117 | // POSTデータを引き継ぐ |
---|
118 | $this->tpl_news_id = $news_id; |
---|
119 | break; |
---|
120 | |
---|
121 | case 'delete': |
---|
122 | //---- データ削除 |
---|
123 | $objNews->deleteNews($news_id); |
---|
124 | //自分にリダイレクト(再読込による誤動作防止) |
---|
125 | SC_Response_Ex::reload(); |
---|
126 | break; |
---|
127 | |
---|
128 | //---- 表示順位移動 |
---|
129 | case 'up': |
---|
130 | $objNews->rankUp($news_id); |
---|
131 | |
---|
132 | // リロード |
---|
133 | SC_Response_Ex::reload(); |
---|
134 | break; |
---|
135 | |
---|
136 | case 'down': |
---|
137 | $objNews->rankDown($news_id); |
---|
138 | |
---|
139 | // リロード |
---|
140 | SC_Response_Ex::reload(); |
---|
141 | break; |
---|
142 | |
---|
143 | case 'moveRankSet': |
---|
144 | //---- 指定表示順位移動 |
---|
145 | $input_pos = $this->getPostRank($news_id); |
---|
146 | if (SC_Utils_Ex::sfIsInt($input_pos)) { |
---|
147 | $objNews->moveRank($news_id, $input_pos); |
---|
148 | } |
---|
149 | SC_Response_Ex::reload(); |
---|
150 | break; |
---|
151 | |
---|
152 | default: |
---|
153 | break; |
---|
154 | } |
---|
155 | |
---|
156 | $this->arrNews = $objNews->getList(); |
---|
157 | $this->line_max = count($this->arrNews); |
---|
158 | |
---|
159 | $this->arrForm = $objFormParam->getFormParamList(); |
---|
160 | } |
---|
161 | |
---|
162 | /** |
---|
163 | * 入力されたパラメーターのエラーチェックを行う。 |
---|
164 | * @param Object $objFormParam |
---|
165 | * @return Array エラー内容 |
---|
166 | */ |
---|
167 | public function lfCheckError(&$objFormParam) |
---|
168 | { |
---|
169 | $objErr = new SC_CheckError_Ex($objFormParam->getHashArray()); |
---|
170 | $objErr->arrErr = $objFormParam->checkError(); |
---|
171 | $objErr->doFunc(array('日付', 'year', 'month', 'day'), array('CHECK_DATE')); |
---|
172 | |
---|
173 | return $objErr->arrErr; |
---|
174 | } |
---|
175 | |
---|
176 | /** |
---|
177 | * パラメーターの初期化を行う |
---|
178 | * @param Object $objFormParam |
---|
179 | */ |
---|
180 | public function lfInitParam(&$objFormParam) |
---|
181 | { |
---|
182 | $objFormParam->addParam('news_id', 'news_id'); |
---|
183 | $objFormParam->addParam('日付(年)', 'year', INT_LEN, 'n', array('EXIST_CHECK', 'NUM_CHECK', 'MAX_LENGTH_CHECK')); |
---|
184 | $objFormParam->addParam('日付(月)', 'month', INT_LEN, 'n', array('EXIST_CHECK', 'NUM_CHECK', 'MAX_LENGTH_CHECK')); |
---|
185 | $objFormParam->addParam('日付(日)', 'day', INT_LEN, 'n', array('EXIST_CHECK', 'NUM_CHECK', 'MAX_LENGTH_CHECK')); |
---|
186 | $objFormParam->addParam('タイトル', 'news_title', MTEXT_LEN, 'KVa', array('EXIST_CHECK','MAX_LENGTH_CHECK','SPTAB_CHECK')); |
---|
187 | $objFormParam->addParam('URL', 'news_url', URL_LEN, 'KVa', array('MAX_LENGTH_CHECK')); |
---|
188 | $objFormParam->addParam('本文', 'news_comment', LTEXT_LEN, 'KVa', array('MAX_LENGTH_CHECK')); |
---|
189 | $objFormParam->addParam('別ウィンドウで開く', 'link_method', INT_LEN, 'n', array('NUM_CHECK', 'MAX_LENGTH_CHECK')); |
---|
190 | } |
---|
191 | |
---|
192 | /** |
---|
193 | * 登録処理を実行. |
---|
194 | * |
---|
195 | * @param integer $news_id |
---|
196 | * @param array $sqlval |
---|
197 | * @param object $objNews |
---|
198 | * @return multiple |
---|
199 | */ |
---|
200 | public function doRegist($news_id, $sqlval, SC_Helper_News_Ex $objNews) |
---|
201 | { |
---|
202 | $sqlval['news_id'] = $news_id; |
---|
203 | $sqlval['creator_id'] = $_SESSION['member_id']; |
---|
204 | $sqlval['link_method'] = $this->checkLinkMethod($sqlval['link_method']); |
---|
205 | $sqlval['news_date'] = $this->getRegistDate($sqlval); |
---|
206 | unset($sqlval['year'], $sqlval['month'], $sqlval['day']); |
---|
207 | |
---|
208 | return $objNews->saveNews($sqlval); |
---|
209 | } |
---|
210 | |
---|
211 | /** |
---|
212 | * データの登録日を返す。 |
---|
213 | * @param Array $arrPost POSTのグローバル変数 |
---|
214 | * @return string 登録日を示す文字列 |
---|
215 | */ |
---|
216 | public function getRegistDate($arrPost) |
---|
217 | { |
---|
218 | $registDate = $arrPost['year'] .'/'. $arrPost['month'] .'/'. $arrPost['day']; |
---|
219 | |
---|
220 | return $registDate; |
---|
221 | } |
---|
222 | |
---|
223 | /** |
---|
224 | * チェックボックスの値が空の時は無効な値として1を格納する |
---|
225 | * @param int $link_method |
---|
226 | * @return int |
---|
227 | */ |
---|
228 | public function checkLinkMethod($link_method) |
---|
229 | { |
---|
230 | if (strlen($link_method) == 0) { |
---|
231 | $link_method = 1; |
---|
232 | } |
---|
233 | |
---|
234 | return $link_method; |
---|
235 | } |
---|
236 | |
---|
237 | /** |
---|
238 | * ニュースの日付の値をフロントでの表示形式に合わせるために分割 |
---|
239 | * @param String $news_date |
---|
240 | */ |
---|
241 | public function splitNewsDate($news_date) |
---|
242 | { |
---|
243 | return explode('-', $news_date); |
---|
244 | } |
---|
245 | |
---|
246 | /** |
---|
247 | * POSTされたランクの値を取得する |
---|
248 | * @param Object $objFormParam |
---|
249 | * @param Integer $news_id |
---|
250 | */ |
---|
251 | public function getPostRank($news_id) |
---|
252 | { |
---|
253 | if (strlen($news_id) > 0 && is_numeric($news_id) == true) { |
---|
254 | $key = 'pos-' . $news_id; |
---|
255 | $input_pos = $_POST[$key]; |
---|
256 | |
---|
257 | return $input_pos; |
---|
258 | } |
---|
259 | } |
---|
260 | } |
---|