Source for file LC_Page_Admin_Contents_Recommend.php

Documentation is available at LC_Page_Admin_Contents_Recommend.php

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

Documentation generated on Tue, 28 Apr 2009 18:10:59 +0900 by phpDocumentor 1.4.2