Page
[ class tree: Page ] [ index: Page ] [ all elements ]

Source for file LC_Page_Admin_Design_CSS.php

Documentation is available at LC_Page_Admin_Design_CSS.php

  1. <?php
  2. /*
  3.  * This file is part of EC-CUBE
  4.  *
  5.  * Copyright(c) 2000-2011 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_EX_REALDIR . 'page_extends/admin/LC_Page_Admin_Ex.php';
  26. require_once CLASS_EX_REALDIR . 'helper_extends/SC_Helper_FileManager_Ex.php';
  27.  
  28. /**
  29.  * CSS設定 のページクラス.
  30.  *
  31.  * @package Page
  32.  * @author LOCKON CO.,LTD.
  33.  * @version $Id: LC_Page_Admin_Design_CSS.php 20970 2011-06-10 10:27:24Z Seasoft $
  34.  */
  35. class LC_Page_Admin_Design_CSS extends LC_Page_Admin_Ex {
  36.  
  37.     // }}}
  38.     // {{{ functions
  39.  
  40.     /**
  41.      * Page を初期化する.
  42.      *
  43.      * @return void 
  44.      */
  45.     function init() {
  46.         parent::init();
  47.         $this->tpl_mainpage = 'design/css.tpl';
  48.         $this->area_row = 30;
  49.         $this->tpl_subno = 'css';
  50.         $this->tpl_mainno = 'design';
  51.         $this->tpl_maintitle = 'デザイン管理';
  52.         $this->tpl_subtitle = 'CSS設定';
  53.         $masterData = new SC_DB_MasterData_Ex();
  54.         $this->arrDeviceType = $masterData->getMasterData('mtb_device_type');
  55.     }
  56.  
  57.     /**
  58.      * Page のプロセス.
  59.      *
  60.      * @return void 
  61.      */
  62.     function process() {
  63.         $this->action();
  64.         $this->sendResponse();
  65.     }
  66.  
  67.     /**
  68.      * Page のアクション.
  69.      *
  70.      * @return void 
  71.      */
  72.     function action() {
  73.         $objLayout = new SC_Helper_PageLayout_Ex();
  74.  
  75.         $objFormParam = new SC_FormParam_Ex();
  76.         $this->lfInitParam($objFormParam);
  77.         $objFormParam->setParam($_REQUEST);
  78.         $objFormParam->convParam();
  79.         $this->arrErr = $objFormParam->checkError();
  80.         $is_error = (!SC_Utils_Ex::isBlank($this->arrErr));
  81.  
  82.         // CSSファイル名を取得
  83.         $this->css_name = $objFormParam->getValue('css_name');
  84.         $this->old_css_name = $objFormParam->getValue('old_css_name', $this->css_name);
  85.         $this->device_type_id = $objFormParam->getValue('device_type_id', DEVICE_TYPE_PC);
  86.  
  87.         $css_dir = $objLayout->getTemplatePath($this->device_type_id, true) . "css/";
  88.         $css_path = $css_dir . $this->css_name . '.css';
  89.  
  90.         switch($this->getMode()) {
  91.             // データ更新処理
  92.             case 'confirm':
  93.                 if (!$is_error) {
  94.                     $this->arrErr = $this->lfCheckError($objFormParam, $this->arrErr);
  95.                     if (SC_Utils_Ex::isBlank($this->arrErr)) {
  96.                         if ($this->doRegister($css_dir, $this->css_name, $this->old_css_name, $css_path,
  97.                                               $objFormParam->getValue('css_data'))) {
  98.                             $this->tpl_onload = "alert('登録が完了しました。');";
  99.                         }
  100.                     }
  101.                 }
  102.                 break;
  103.             case 'delete':
  104.                 if (!$is_error) {
  105.                     if ($this->doDelete($css_path)) {
  106.                         SC_Response_Ex::reload(array('device_type_id' => $this->device_type_id,
  107.                                                      'msg' => 'on'), true);
  108.                     }
  109.                 }
  110.                 break;
  111.             default:
  112.                 if (isset($_GET['msg']) && $_GET['msg'] == 'on') {
  113.                     // 完了メッセージ
  114.                     $this->tpl_onload = "alert('登録が完了しました。');";
  115.                 }
  116.                 break;
  117.         }
  118.  
  119.         if (!$is_error) {
  120.             // CSSファイルの読み込み
  121.             if (!SC_Utils_Ex::isBlank($this->css_name)) {
  122.                 $objFormParam->setValue('css_data', file_get_contents($css_path));
  123.             }
  124.             // ファイルリストを取得
  125.             $this->arrCSSList = $this->getCSSList($css_dir);
  126.         } else {
  127.             // 画面にエラー表示しないため, ログ出力
  128.             GC_Utils_Ex::gfPrintLog('Error: ' . print_r($this->arrErr, true));
  129.  
  130.         }
  131.         $this->tpl_subtitle = $this->arrDeviceType[$this->device_type_id] . '>' . $this->tpl_subtitle;
  132.         $this->arrForm = $objFormParam->getFormParamList();
  133.     }
  134.  
  135.     /**
  136.      * デストラクタ.
  137.      *
  138.      * @return void 
  139.      */
  140.     function destroy() {
  141.         parent::destroy();
  142.     }
  143.  
  144.     /**
  145.      * パラメーター情報の初期化
  146.      *
  147.      * @param object $objFormParam SC_FormParamインスタンス
  148.      * @return void 
  149.      */
  150.     function lfInitParam(&$objFormParam) {
  151.         $objFormParam->addParam("端末種別ID", "device_type_id", INT_LEN, 'n', array("NUM_CHECK", "MAX_LENGTH_CHECK"));
  152.         $objFormParam->addParam("CSSファイル名", "css_name", STEXT_LEN, 'a', array("MAX_LENGTH_CHECK"));
  153.         $objFormParam->addParam("旧CSSファイル名", "old_css_name", STEXT_LEN, 'a', array("MAX_LENGTH_CHECK"));
  154.         $objFormParam->addParam("CSSデータ", "css_data");
  155.  
  156.     }
  157.  
  158.     /**
  159.      * 登録を実行する.
  160.      *
  161.      * ファイルの作成に失敗した場合は, エラーメッセージを出力する.
  162.      *
  163.      * @param string $css_dir CSS ディレクトリ
  164.      * @param string $css_name CSSファイル名
  165.      * @param string $old_css_name 旧CSSファイル名
  166.      * @param string $css_path CSSファイルの絶対パス
  167.      * @param string $css_data 書き込みを行うデータ
  168.      * @return boolean 登録が成功した場合 true; 失敗した場合 false
  169.      */
  170.     function doRegister($css_dir, $css_name, $old_css_name, $css_path, $css_data) {
  171.         $objFileManager = new SC_Helper_FileManager_Ex();
  172.  
  173.         if (!SC_Utils_Ex::isBlank($old_css_name)
  174.             && $old_css_name != $css_name) {
  175.             if (!unlink($css_dir . $old_css_name . '.css')) {
  176.                 $this->arrErr['err'] = '※ 旧ファイルの削除に失敗しました<br />';
  177.                 return false;
  178.             }
  179.         }
  180.  
  181.         if (!SC_Helper_FileManager_Ex::sfWriteFile($css_path, $css_data)) {
  182.             $this->arrErr['err'] = '※ CSSの書き込みに失敗しました<br />';
  183.             return false;
  184.         }
  185.         return true;
  186.     }
  187.  
  188.     /**
  189.      * 削除を実行する.
  190.      *
  191.      * @param string $css_path CSSファイルの絶対パス
  192.      * @return boolean 削除が成功した場合 true; 失敗した場合 false
  193.      */
  194.     function doDelete($css_path) {
  195.         if (!unlink($css_path)) {
  196.             $this->arrErr['err'] = '※ CSSの削除に失敗しました<br />';
  197.             return false;
  198.         }
  199.         return true;
  200.     }
  201.  
  202.     /**
  203.      * CSSファイルのリストを取得.
  204.      *
  205.      * @param array $css_dir CSSディレクトリ
  206.      * @return array ファイルリスト
  207.      */
  208.     function getCSSList($css_dir) {
  209.         $objFileManager = new SC_Helper_FileManager_Ex();
  210.  
  211.         $arrFileList = $objFileManager->sfGetFileList($css_dir);
  212.         foreach ($arrFileList as $val) {
  213.             if (!$val['is_dir']) {
  214.                 $arrCSSList[] = array(
  215.                     'file_name' => $val['file_name'],
  216.                     'css_name'  => preg_replace('/(.+)\.(.+?)$/','$1',$val['file_name']),
  217.                 );
  218.             }
  219.         }
  220.         return $arrCSSList;
  221.     }
  222.  
  223.     /**
  224.      * エラーチェックを行う.
  225.      *
  226.      * @param SC_FormParam $objFormParam SC_FormParam インスタンス
  227.      * @return array エラーメッセージの配列
  228.      */
  229.     function lfCheckError(&$objFormParam, &$arrErr) {
  230.         $arrParams = $objFormParam->getHashArray();
  231.         $objErr = new SC_CheckError_Ex($arrParams);
  232.         $objErr->arrErr =& $arrErr;
  233.         $objErr->doFunc(array('CSSファイル名', 'css_name', STEXT_LEN), array("EXIST_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK","FILE_NAME_CHECK_BY_NOUPLOAD"));
  234.  
  235.         $device_type_id = $objFormParam->getValue('device_type_id');
  236.         $css_name = $objFormParam->getValue('css_name');
  237.         $old_css_name = $objFormParam->getValue('old_css_name', $css_name);
  238.  
  239.         $is_error = false;
  240.         // 重複チェック
  241.         if(!SC_Utils_Ex::isBlank(($objErr->arrErr['css_name']))) {
  242.             $arrCSSList = $this->getCSSList($this->getCSSDir());
  243.             foreach ($arrCSSList as $val) {
  244.                 if ($val['css_name'] == $css_name) {
  245.                     if (SC_Utils_Ex::isBlank($old_css_name)
  246.                         || $old_css_name != $css_name) {
  247.                         $is_error = true;
  248.                     }
  249.                 }
  250.             }
  251.             if ($is_error) {
  252.                 $objErr->arrErr['css_name'] = '※ 同じファイル名のデータが存在しています。別の名称を付けてください。<br />';
  253.             }
  254.         }
  255.         return $objErr->arrErr;
  256.     }
  257.  
  258.     /**
  259.      * CSSディレクトリを取得する.
  260.      *
  261.      * @param integer $device_type_id 端末種別ID
  262.      * @return string CSSディレクトリ
  263.      */
  264.     function getCSSDir($device_type_id) {
  265.         return SC_Helper_PageLayout_Ex::getTemplatePath($device_type_id, true) . "css/";
  266.     }
  267. }
  268. ?>

Documentation generated on Fri, 24 Feb 2012 14:01:16 +0900 by Seasoft