PageRenderTime 42ms CodeModel.GetById 14ms RepoModel.GetById 1ms app.codeStats 0ms

/data/class/pages/admin/contents/LC_Page_Admin_Contents.php

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