Index: /branches/feature-module-update/data/class/pages/admin/design/LC_Page_Admin_Design_Template.php
===================================================================
--- /branches/feature-module-update/data/class/pages/admin/design/LC_Page_Admin_Design_Template.php	(revision 16430)
+++ /branches/feature-module-update/data/class/pages/admin/design/LC_Page_Admin_Design_Template.php	(revision 16430)
@@ -0,0 +1,316 @@
+<?php
+/*
+ * Copyright(c) 2000-2007 LOCKON CO.,LTD. All Rights Reserved.
+ *
+ * http://www.lockon.co.jp/
+ */
+
+  // {{{ requires
+require_once(CLASS_PATH . "pages/LC_Page.php");
+require_once(DATA_PATH . "module/Tar.php");
+
+/**
+ * テンプレート設定 のページクラス.
+ *
+ * @package Page
+ * @author LOCKON CO.,LTD.
+ * @version $Id$
+ */
+class LC_Page_Admin_Design_Template extends LC_Page {
+
+    // }}}
+    // {{{ functions
+
+    /** テンプレートデータ種別 */
+    var $arrSubnavi = array(
+                     'title' => array(
+                                1 => 'top',
+                                2 => 'product',
+                                3 => 'detail',
+                                4 => 'mypage'
+                                             ),
+                     'name' =>array(
+                                1 => 'TOPページ',
+                                2 => '商品一覧ページ',
+                                3 => '商品詳細ページ',
+                                4 => 'MYページ'
+                              )
+                     );
+
+    /**
+     * Page を初期化する.
+     *
+     * @return void
+     */
+    function init() {
+        parent::init();
+        $this->arrTemplateName = $this->arrSubnavi;
+        $this->tpl_mainpage = 'design/template.tpl';
+        $this->tpl_subnavi = 'design/subnavi.tpl';
+        $this->tpl_subno = 'template';
+        $this->tpl_subno_template = $this->arrSubnavi['title'][1];
+        $this->tpl_TemplateName = $this->arrTemplateName['name'][1];
+        $this->tpl_mainno = "design";
+        $this->tpl_subtitle = 'テンプレート設定';
+    }
+
+    /**
+     * Page のプロセス.
+     *
+     * @return void
+     */
+    function process() {
+        $objView = new SC_AdminView();
+        $objSess = new SC_Session();
+
+        // 認証可否の判定
+        $objSess = new SC_Session();
+        SC_Utils_Ex::sfIsSuccess($objSess);
+
+        // GETの値を受け取る
+        $get_tpl_subno_template = isset($_GET['tpl_subno_template']) 
+            ? $_GET['tpl_subno_template'] : "";
+        if (!isset($_POST['tpl_subno_template'])) $_POST['tpl_subno_template'] = "";
+        if (!isset($_POST['mode'])) $_POST['mode'] = "";
+
+        // GETで値が送られている場合にはその値を元に画面表示を切り替える
+        if ($get_tpl_subno_template != ""){
+            // 送られてきた値が配列に登録されていなければTOPを表示
+            if (in_array($get_tpl_subno_template,$this->arrSubnavi['title'])){
+                $tpl_subno_template = $get_tpl_subno_template;
+            }else{
+                $tpl_subno_template = $this->arrSubnavi['title'][1];
+            }
+        } else {
+            // GETで値がなければPOSTの値を使用する
+            if ($_POST['tpl_subno_template'] != ""){
+                $tpl_subno_template = $_POST['tpl_subno_template'];
+            }else{
+                $tpl_subno_template = $this->arrSubnavi['title'][1];
+            }
+        }
+        $this->tpl_subno_template = $tpl_subno_template;
+        $key = array_keys($this->arrSubnavi['title'], $tpl_subno_template);
+        $this->template_name = $this->arrSubnavi['name'][$key[0]];
+
+        // 登録を押された場合にはDBへデータを更新に行く
+        switch($_POST['mode']) {
+        case 'confirm':
+            // DBへデータ更新
+            $this->lfUpdData();
+
+            // テンプレートの上書き
+            $this->lfChangeTemplate();
+
+            // 完了メッセージ
+            $this->tpl_onload="alert('登録が完了しました。');";
+            break;
+        case 'download':
+            $this->lfDownloadTemplate($_POST['check_template']);
+            break;
+        default:
+            break;
+        }
+
+        // POST値の引き継ぎ
+        $this->arrForm = $_POST;
+
+        // 画像取得
+        $tpl_arrTemplate = array();
+        $this->arrTemplate = $this->lfgetTemplate();
+
+        // デフォルトチェック取得
+        $this->MainImage = $this->arrTemplate['check'];
+        $this->arrTemplate['check'] = array($this->arrTemplate['check']=>"check");
+
+        // 画面の表示
+        $objView->assignobj($this);
+        $objView->display(MAIN_FRAME);
+
+    }
+
+    /**
+     * デストラクタ.
+     *
+     * @return void
+     */
+    function destroy() {
+        parent::destroy();
+    }
+
+    /**
+     * 画面に表示する画像を取得する.
+     *
+     * @return array 画面に表示する画像の配列
+     */
+    function lfgetTemplate(){
+        $filepath = "user_data/templates/";
+
+        $arrTemplateImage = array();	// 画面表示画像格納用
+        $Image = "";					// イメージの配列要素名格納用
+        $disp = "";
+        $arrDefcheck = array();			// radioボタンのデフォルトチェック格納用
+
+        // DBから現在選択されているデータ取得
+        $arrDefcheck = $this->lfgetTemplaeBaseData();
+
+        // テンプレートデータを取得する
+        $objQuery = new SC_Query();
+        $sql = "SELECT template_code,template_name FROM dtb_templates ORDER BY create_date DESC";
+        $arrTemplate = $objQuery->getall($sql);
+
+        switch($this->tpl_subno_template) {
+            // TOP
+        case $this->arrSubnavi['title'][1]:
+            $Image = "TopImage.jpg";            // イメージの配列要素名格納用
+            $disp = $this->arrSubnavi['title'][1];
+            break;
+
+            // 商品一覧
+        case $this->arrSubnavi['title'][2]:
+            $Image = "ProdImage.jpg";           // イメージの配列要素名格納用
+            $disp = $this->arrSubnavi['title'][2];
+            break;
+
+            // 商品詳細
+        case $this->arrSubnavi['title'][3]:
+            $Image = "DetailImage.jpg";         // イメージの配列要素名格納用
+            $disp = $this->arrSubnavi['title'][3];
+            break;
+
+            // MYページ
+        case $this->arrSubnavi['title'][4]:
+            $Image = "MypageImage.jpg";         //イメージの配列要素名格納用
+            $disp = $this->arrSubnavi['title'][4];
+            break;
+        }
+
+        // 画像表示配列作成
+        foreach($arrTemplate as $key => $val){
+            $arrTemplateImage['image'][$val['template_code']] = $filepath . $val['template_code'] . "/" . $Image;
+            $arrTemplateImage['code'][$key] = $val['template_code'];
+        }
+
+        // 初期チェック
+        if (isset($arrDefcheck[$disp])){
+            $arrTemplateImage['check'] = $arrDefcheck[$disp];
+        }else{
+            $arrTemplateImage['check'] = 1;
+        }
+
+        return $arrTemplateImage;
+    }
+
+    /**
+     * DBに保存されているテンプレートデータを取得する.
+     *
+     * @return array DBに保存されているテンプレートデータの配列
+     */
+    function lfgetTemplaeBaseData(){
+        $objDBConn = new SC_DbConn;		// DB操作オブジェクト
+        $sql = "";						// データ取得SQL生成用
+        $arrRet = array();				// データ取得用
+
+        $sql = "SELECT top_tpl AS top, product_tpl AS product, detail_tpl AS detail, mypage_tpl AS mypage FROM dtb_baseinfo";
+        $arrRet = $objDBConn->getAll($sql);
+
+        return $arrRet[0];
+    }
+
+    /**
+     * DBにデータを保存する.
+     *
+     * @return integer 成功した場合 1
+     */
+    function lfUpdData(){
+        $objDBConn = new SC_DbConn;		// DB操作オブジェクト
+        $sql = "";						// データ取得SQL生成用
+        $arrRet = array();				// データ取得用(更新判定)
+
+        // データ取得
+        $sql = "SELECT top_tpl AS top, product_tpl AS product, detail_tpl AS detail, mypage_tpl AS mypage FROM dtb_baseinfo";
+        $arrRet = $objDBConn->getAll($sql);
+
+        $chk_tpl = $_POST['check_template'];
+        // データが取得できなければINSERT、できればUPDATE
+        if (isset($arrRet[0])){
+            // UPDATE
+            $arrVal = array($chk_tpl,$chk_tpl,$chk_tpl,$chk_tpl);
+            $sql= "update dtb_baseinfo set top_tpl = ?, product_tpl = ?, detail_tpl = ?, mypage_tpl = ?, update_date = now()";
+        }else{
+            // INSERT
+            $arrVal = array($chk_tpl,$chk_tpl,$chk_tpl,$chk_tpl);
+            $sql= "insert into dtb_baseinfo (top_tpl,product_tpl,detail_tpl,mypage_tpl, update_date) values (?,?,?,?,now());";
+        }
+
+        // SQL実行
+        $arrRet = $objDBConn->query($sql,$arrVal);
+
+        return $arrRet;
+    }
+
+    /**
+     * テンプレートを変更する.
+     *
+     * @return void
+     */
+    function lfChangeTemplate(){
+        $data = array();
+        $masterData = new SC_DB_MasterData_Ex();
+
+        // FIXME DBのデータを更新
+        $masterData->updateMasterData("mtb_constants", array(),
+                array("TEMPLATE_NAME" => '"' . $_POST['check_template'] . '"'));
+
+        // 更新したデータを取得
+        $mtb_constants = $masterData->getDBMasterData("mtb_constants");
+
+        // キャッシュを生成
+        $masterData->clearCache("mtb_constants");
+        $masterData->createCache("mtb_constants", $mtb_constants, true,
+                                 array("id", "remarks", "rank"));
+    }
+
+    /**
+     * テンプレートファイル圧縮してダウンロードする.
+     *
+     * @param string テンプレートコード
+     * @return void
+     */
+    function lfDownloadTemplate($template_code){
+        require_once(CLASS_EX_PATH . "helper_extends/SC_Helper_FileManager_Ex.php");
+        $objFileManager = new SC_Helper_FileManager_Ex();
+        $filename = $template_code. ".tar.gz";
+        $dl_file = USER_TEMPLATE_PATH.$filename;
+        $target_path = USER_TEMPLATE_PATH . $template_code . "/";
+
+        $mess = "";
+        // Smarty テンプレートをコピー
+        $target_smarty = $target_path . "Smarty/";
+        $mess .= SC_Utils_Ex::sfCopyDir(DATA_PATH . "Smarty/templates/" . $template_code . "/", $target_smarty, $mess);
+
+        // ファイルの圧縮
+        $tar = new Archive_Tar($dl_file, TRUE);
+        // ファイル一覧取得
+        $arrFileHash = $objFileManager->sfGetFileList(USER_TEMPLATE_PATH.$template_code);
+        foreach($arrFileHash as $val) {
+            $arrFileList[] = $val['file_name'];
+        }
+        // ディレクトリを移動
+        chdir(USER_TEMPLATE_PATH.$template_code);
+
+        //圧縮をおこなう
+        $zip = $tar->create($arrFileList);
+
+        // ダウンロード開始
+        Header("Content-disposition: attachment; filename=${filename}");
+        Header("Content-type: application/octet-stream; name=${dl_file}");
+        header("Content-Length: " .filesize($dl_file));
+        readfile ($dl_file);
+        // 圧縮ファイル削除
+        unlink($dl_file);
+
+        exit();
+    }
+}
+?>
Index: /branches/feature-module-update/data/class/pages/admin/design/LC_Page_Admin_Design_Upload.php
===================================================================
--- /branches/feature-module-update/data/class/pages/admin/design/LC_Page_Admin_Design_Upload.php	(revision 16430)
+++ /branches/feature-module-update/data/class/pages/admin/design/LC_Page_Admin_Design_Upload.php	(revision 16430)
@@ -0,0 +1,235 @@
+<?php
+/*
+ * Copyright(c) 2000-2007 LOCKON CO.,LTD. All Rights Reserved.
+ *
+ * http://www.lockon.co.jp/
+ */
+
+// {{{ requires
+require_once(CLASS_PATH . "pages/LC_Page.php");
+require_once(DATA_PATH. "module/Tar.php");
+
+/**
+ * テンプレートアップロード のページクラス.
+ *
+ * @package Page
+ * @author LOCKON CO.,LTD.
+ * @version $Id$
+ */
+class LC_Page_Admin_Design_Upload extends LC_Page {
+
+    // }}}
+    // {{{ functions
+
+    /**
+     * Page を初期化する.
+     *
+     * @return void
+     */
+    function init() {
+        parent::init();
+        $this->tpl_mainpage = 'design/upload.tpl';
+        $this->tpl_subnavi = 'design/subnavi.tpl';
+        $this->tpl_subno = 'template';
+        $this->tpl_subno_template = 'upload';
+        $this->tpl_mainno = "design";
+        $this->tpl_subtitle = 'アップロード';
+        $this->template_name = 'アップロード';
+    }
+
+    /**
+     * Page のプロセス.
+     *
+     * @return void
+     */
+    function process() {
+        $objView = new SC_AdminView();
+        $objSess = new SC_Session();
+        $objQuery = new SC_Query();
+
+        // 認証可否の判定
+        $objSess = new SC_Session();
+        SC_Utils_Ex::sfIsSuccess($objSess);
+
+        if (!isset($_POST['template_code'])) $_POST['template_code'] = "";
+        if (!isset($_POST['mode'])) $_POST['mode'] = "";
+
+        // アップロードしたファイルを格納するディレクトリ
+        $new_file_dir = USER_TEMPLATE_PATH . $_POST['template_code'];
+        $this->p($new_file_dir);
+        // ファイル管理クラス
+        $objUpFile = new SC_UploadFile(TEMPLATE_TEMP_DIR, $new_file_dir);
+        // ファイル情報の初期化
+        $this->lfInitFile($objUpFile);
+        // パラメータ管理クラス
+        $objFormParam = new SC_FormParam();
+        // パラメータ情報の初期化
+        $this->lfInitParam($objFormParam);
+
+        switch($_POST['mode']) {
+        case 'upload':
+            $objFormParam->setParam($_POST);
+            $arrRet = $objFormParam->getHashArray();
+
+            $this->arrErr = $this->lfErrorCheck($arrRet, $objQuery, $objFormParam);
+
+            // ファイルを一時フォルダへ保存
+            $ret = $objUpFile->makeTempFile('template_file', false);
+            if($ret != "") {
+                $this->arrErr['template_file'] = $ret;
+            } else if(count($this->arrErr) <= 0) {
+                // フォルダ作成
+                $ret = @mkdir($new_file_dir);
+                // 一時フォルダから保存ディレクトリへ移動
+                $objUpFile->moveTempFile();
+                // 解凍
+                $this->lfUnpacking($new_file_dir, $_FILES['template_file']['name'], $new_file_dir."/");
+
+                $mess = "";
+                // Smarty テンプレートをコピー
+                $target_smarty = $new_file_dir . "/Smarty/";
+                $mess .= SC_Utils_Ex::sfCopyDir($target_smarty, DATA_PATH . "Smarty/templates/" . $_POST['template_code'] . "/", $mess);
+
+                // DBにテンプレート情報を保存
+                $this->lfRegistTemplate($arrRet, $objQuery);
+                // 完了表示javascript
+                $this->tpl_onload = "alert('テンプレートファイルをアップロードしました。');";
+                // フォーム値をクリア
+                $objFormParam->setParam(array('template_code' => "", 'template_name' => ""));
+            }
+            break;
+        default:
+            break;
+        }
+        // 画面の表示
+        $this->arrForm = $objFormParam->getFormParamList();
+        $objView->assignobj($this);
+        $objView->display(MAIN_FRAME);
+    }
+
+    /**
+     * デストラクタ.
+     *
+     * @return void
+     */
+    function destroy() {
+        parent::destroy();
+    }
+
+    /**
+     * ファイル情報の初期化を行う.
+     *
+     * @param SC_UploadFile $objUpFile SC_UploadFile インスタンス
+     * @return void
+     */
+    function lfInitFile(&$objUpFile) {
+        $objUpFile->addFile("テンプレートファイル", 'template_file', array(), TEMPLATE_SIZE, true, 0, 0, false);
+    }
+
+    /**
+     * パラメータ情報の初期化を行う.
+     *
+     * @param SC_FormParam $objFormParam SC_FormParam インスタンス
+     * @return void
+     */
+    function lfInitParam(&$objFormParam) {
+
+        $objFormParam->addParam("テンプレートコード", "template_code", STEXT_LEN, "KVa", array("EXIST_CHECK","SPTAB_CHECK","MAX_LENGTH_CHECK", "ALNUM_CHECK"));
+        $objFormParam->addParam("テンプレート名", "template_name", STEXT_LEN, "KVa", array("EXIST_CHECK","SPTAB_CHECK","MAX_LENGTH_CHECK"));
+    }
+
+    /**
+     * エラーチェックを行う.
+     *
+     * @param array $arrList フォームの値の配列
+     * @param SC_Query $objQuery SC_Query インスタンス
+     * @param SC_FormParam $objFormParam SC_FormParam インスタンス
+     * @return array エラー情報の配列
+     */
+    function lfErrorCheck($arrList, &$objQuery, &$objFormParam) {
+
+        $objErr = new SC_CheckError($arrList);
+        $objErr->arrErr = $objFormParam->checkError();
+
+        if(count($objErr->arrErr) <= 0) {
+            // 同名のフォルダが存在する場合はエラー
+            if(file_exists(USER_TEMPLATE_PATH.$arrList['template_code'])) {
+                $objErr->arrErr['template_code'] = "※ 同名のファイルがすでに存在します。<br/>";
+            }
+            // DBにすでに登録されていないかチェック
+            $ret = $objQuery->get("dtb_templates", "template_code", "template_code = ?", array($arrList['template_code']));
+            if($ret != "") {
+                $objErr->arrErr['template_code'] = "※ すでに登録されているテンプレートコードです。<br/>";
+            }
+            // ファイルの拡張子チェック(.tar/tar.gzのみ許可)
+            $errFlag = true;
+            $array_ext = explode(".", $_FILES['template_file']['name']);
+            $ext = $array_ext[ count ( $array_ext ) - 1 ];
+            $ext = strtolower($ext);
+            // .tarチェック
+            if ($ext == 'tar') {
+                $errFlag = false;
+            }
+
+            $ext = $array_ext[ count ( $array_ext ) - 2 ].".".$ext;
+            $ext = strtolower($ext);
+            // .tar.gzチェック
+            if ($ext== 'tar.gz') {
+                $errFlag = false;
+            }
+
+            if($errFlag) {
+                $objErr->arrErr['template_file'] = "※ アップロードするテンプレートファイルで許可されている形式は、tar/tar.gzです。<br />";
+            }
+        }
+
+        return $objErr->arrErr;
+    }
+
+    /**
+     * テンプレートデータを登録する.
+     *
+     * @param array $arrList 登録するデータの配列
+     * @param SC_Query $objQuery SC_Query インスタンス
+     * @return void
+     */
+    function lfRegistTemplate($arrList, &$objQuery) {
+
+        // INSERTする値を作成する。
+        $sqlval['template_code'] = $arrList['template_code'];
+        $sqlval['template_name'] = $arrList['template_name'];
+        $sqlval['create_date'] = "now()";
+        $sqlval['update_date'] = "now()";
+
+        $objQuery->insert("dtb_templates", $sqlval);
+    }
+
+    /**
+     * テンプレートのアーカイブを展開する.
+     *
+     * @param string ディレクトリ名
+     * @param string ファイル名
+     * @param string 展開先ディレクトリ
+     * @return void
+     */
+    function lfUnpacking($dir, $file_name, $unpacking_dir) {
+
+        // 圧縮フラグTRUEはgzip解凍をおこなう
+        $tar = new Archive_Tar("$dir/$file_name", TRUE);
+
+        // 拡張子を切り取る
+        $unpacking_name = ereg_replace("\.tar$", "", $file_name);
+        $unpacking_name = ereg_replace("\.tar\.gz$", "", $file_name);
+
+        // 指定されたフォルダ内に解凍する
+        $err = $tar->extractModify($unpacking_dir, $unpacking_name);
+
+        // フォルダ削除
+        @SC_Utils_Ex::sfDelFile("$dir/$unpacking_name");
+        // 圧縮ファイル削除
+        @unlink("$dir/$file_name");
+
+        return $err;
+    }
+}
+?>
Index: /branches/feature-module-update/data/class_extends/page_extends/admin/design/LC_Page_Admin_Design_Upload_Ex.php
===================================================================
--- /branches/feature-module-update/data/class_extends/page_extends/admin/design/LC_Page_Admin_Design_Upload_Ex.php	(revision 16430)
+++ /branches/feature-module-update/data/class_extends/page_extends/admin/design/LC_Page_Admin_Design_Upload_Ex.php	(revision 16430)
@@ -0,0 +1,52 @@
+<?php
+/*
+ * Copyright(c) 2000-2007 LOCKON CO.,LTD. All Rights Reserved.
+ *
+ * http://www.lockon.co.jp/
+ */
+
+// {{{ requires
+require_once(CLASS_PATH . "pages/admin/design/LC_Page_Admin_Design_Upload.php");
+
+/**
+ * テンプレートアップロード のページクラス(拡張).
+ *
+ * LC_Page_Admin_Design_Upload をカスタマイズする場合はこのクラスを編集する.
+ *
+ * @package Page
+ * @author LOCKON CO.,LTD.
+ * @version $Id$
+ */
+class LC_Page_Admin_Design_Upload_Ex extends LC_Page_Admin_Design_Upload {
+
+    // }}}
+    // {{{ functions
+
+    /**
+     * Page を初期化する.
+     *
+     * @return void
+     */
+    function init() {
+        parent::init();
+    }
+
+    /**
+     * Page のプロセス.
+     *
+     * @return void
+     */
+    function process() {
+        parent::process();
+    }
+
+    /**
+     * デストラクタ.
+     *
+     * @return void
+     */
+    function destroy() {
+        parent::destroy();
+    }
+}
+?>
Index: /branches/feature-module-update/data/class_extends/page_extends/admin/design/LC_Page_Admin_Design_Template_Ex.php
===================================================================
--- /branches/feature-module-update/data/class_extends/page_extends/admin/design/LC_Page_Admin_Design_Template_Ex.php	(revision 16430)
+++ /branches/feature-module-update/data/class_extends/page_extends/admin/design/LC_Page_Admin_Design_Template_Ex.php	(revision 16430)
@@ -0,0 +1,52 @@
+<?php
+/*
+ * Copyright(c) 2000-2007 LOCKON CO.,LTD. All Rights Reserved.
+ *
+ * http://www.lockon.co.jp/
+ */
+
+// {{{ requires
+require_once(CLASS_PATH . "pages/admin/design/LC_Page_Admin_Design_Template.php");
+
+/**
+ * テンプレート設定 のページクラス(拡張).
+ *
+ * LC_Page_Admin_Design_Template をカスタマイズする場合はこのクラスを編集する.
+ *
+ * @package Page
+ * @author LOCKON CO.,LTD.
+ * @version $Id$
+ */
+class LC_Page_Admin_Design_Template_Ex extends LC_Page_Admin_Design_Template {
+
+    // }}}
+    // {{{ functions
+
+    /**
+     * Page を初期化する.
+     *
+     * @return void
+     */
+    function init() {
+        parent::init();
+    }
+
+    /**
+     * Page のプロセス.
+     *
+     * @return void
+     */
+    function process() {
+        parent::process();
+    }
+
+    /**
+     * デストラクタ.
+     *
+     * @return void
+     */
+    function destroy() {
+        parent::destroy();
+    }
+}
+?>
Index: /branches/feature-module-update/html/admin/design/template.php
===================================================================
--- /branches/feature-module-update/html/admin/design/template.php	(revision 15532)
+++ /branches/feature-module-update/html/admin/design/template.php	(revision 16430)
@@ -5,386 +5,15 @@
  * http://www.lockon.co.jp/
  */
+
+// {{{ requires
 require_once("../../require.php");
-require_once(DATA_PATH . "module/Tar.php");
-require_once(DATA_PATH . "include/file_manager.inc");
-require_once(DATA_PATH . "module/SearchReplace.php");
+require_once(CLASS_EX_PATH . "page_extends/admin/design/LC_Page_Admin_Design_Template_Ex.php");
 
-class LC_Page {
-	var $arrForm;
-	var $arrHidden;
-	var $arrSubnavi = array(
-		'title' => array(
-			1 => 'top',
-			2 => 'product',
-			3 => 'detail',
-			4 => 'mypage' 
-		),
-		'name' =>array(
-			1 => 'TOPページ',
-			2 => '商品一覧ページ',
-			3 => '商品詳細ページ',
-			4 => 'MYページ' 
-		)
-	);
+// }}}
+// {{{ generate page
 
-	function LC_Page() {
-		$this->tpl_mainpage = 'design/template.tpl';
-		$this->tpl_subnavi = 'design/subnavi.tpl';
-		$this->tpl_subno = 'template';
-		$this->tpl_subno_template = $this->arrSubnavi['title'][1];
-		$this->tpl_TemplateName = $this->arrTemplateName['name'][1];
-		$this->tpl_mainno = "design";
-		$this->tpl_subtitle = 'テンプレート設定';
-	}
-}
-
-$objPage = new LC_Page();
-$objView = new SC_AdminView();
-$objSess = new SC_Session();
-
-// 認証可否の判定
-$objSess = new SC_Session();
-sfIsSuccess($objSess);
-
-// GETの値を受け取る
-$get_tpl_subno_template = $_GET['tpl_subno_template'];
-
-// GETで値が送られている場合にはその値を元に画面表示を切り替える
-if ($get_tpl_subno_template != ""){
-	// 送られてきた値が配列に登録されていなければTOPを表示
-	if (in_array($get_tpl_subno_template,$objPage->arrSubnavi['title'])){
-		$tpl_subno_template = $get_tpl_subno_template;
-	}else{
-		$tpl_subno_template = $objPage->arrSubnavi['title'][1];
-	}
-} else {
-	// GETで値がなければPOSTの値を使用する
-	if ($_POST['tpl_subno_template'] != ""){
-		$tpl_subno_template = $_POST['tpl_subno_template'];
-	}else{
-		$tpl_subno_template = $objPage->arrSubnavi['title'][1];
-	}
-}
-$objPage->tpl_subno_template = $tpl_subno_template;
-$key = array_keys($objPage->arrSubnavi['title'], $tpl_subno_template);
-$objPage->template_name = $objPage->arrSubnavi['name'][$key[0]];
-
-// 登録を押されたばあにはDBへデータを更新に行く
-switch($_POST['mode']) {
-case 'confirm':
-	// DBへデータ更新
-	lfUpdData();
-	
-	// テンプレートの上書き
-	lfChangeTemplate();
-	
-	// 完了メッセージ
-	$objPage->tpl_onload="alert('登録が完了しました。');";
-	break;
-case 'download':
-	lfDownloadTemplate($_POST['check_template']);
-	break;
-default:
-	break;
-}
-
-// POST値の引き継ぎ
-$objPage->arrForm = $_POST;
-
-// 画像取得
-$tpl_arrTemplate = array();
-$objPage->arrTemplate = lfgetTemplate();
-
-// デフォルトチェック取得
-$objPage->MainImage = $objPage->arrTemplate['check'];
-$objPage->arrTemplate['check'] = array($objPage->arrTemplate['check']=>"check");
-
-// 画面の表示
-$objView->assignobj($objPage);
-$objView->display(MAIN_FRAME);
-
-//---------------------------------------------------------------------------------------------------------------------------------------------------------
-
-/**************************************************************************************************************
- * 関数名	：lfgetTemplate
- * 処理内容	：画面に表示する画像を取得する
- * 引数		：なし
- * 戻り値	：画面に表示する画像(配列)
- **************************************************************************************************************/
-function lfgetTemplate(){
-	global $objPage;
-	$filepath = "user_data/templates/";
-	
-	$arrTemplateImage = array();	// 画面表示画像格納用
-	$Image = "";					// イメージの配列要素名格納用
-	$disp = "";
-	$arrDefcheck = array();			// radioボタンのデフォルトチェック格納用
-	
-	// DBから現在選択されているデータ取得
-	$arrDefcheck = lfgetTemplaeBaseData();
-	
-	// テンプレートデータを取得する
-	$objQuery = new SC_Query();
-	$sql = "SELECT template_code,template_name FROM dtb_templates ORDER BY create_date DESC";
-	$arrTemplate = $objQuery->getall($sql);
-	
-	switch($objPage->tpl_subno_template) {
-		// TOP
-		case $objPage->arrSubnavi['title'][1]:
-			$Image = "TopImage.jpg";			// イメージの配列要素名格納用
-			$disp = $objPage->arrSubnavi['title'][1];
-			break;
-			
-		// 商品一覧
-		case $objPage->arrSubnavi['title'][2]:
-			$Image = "ProdImage.jpg";			// イメージの配列要素名格納用
-			$disp = $objPage->arrSubnavi['title'][2];
-			break;
-			
-		// 商品詳細
-		case $objPage->arrSubnavi['title'][3]:
-			$Image = "DetailImage.jpg";			// イメージの配列要素名格納用
-			$disp = $objPage->arrSubnavi['title'][3];
-			break;
-			
-		// MYページ
-		case $objPage->arrSubnavi['title'][4]:
-			$Image = "MypageImage.jpg";			//イメージの配列要素名格納用
-			$disp = $objPage->arrSubnavi['title'][4];
-			break;
-	}
-
-	// 画像表示配列作成
-	foreach($arrTemplate as $key => $val){
-		$arrTemplateImage['image'][$val['template_code']] = $filepath . $val['template_code'] . "/" . $Image;
-		$arrTemplateImage['code'][$key] = $val['template_code'];
-	}
-	
-	// 初期チェック
-	if (isset($arrDefcheck[$disp])){
-		$arrTemplateImage['check'] = $arrDefcheck[$disp];
-	}else{
-		$arrTemplateImage['check'] = 1;
-	}
-	
-	return $arrTemplateImage;
-}
-
-/**************************************************************************************************************
- * 関数名	：lfgetTemplaeBaseData
- * 処理内容	：DBに保存されているテンプレートデータを取得する
- * 引数		：なし
- * 戻り値	：DBに保存されているテンプレートデータ(配列)
- **************************************************************************************************************/
-function lfgetTemplaeBaseData(){
-	$objDBConn = new SC_DbConn;		// DB操作オブジェクト
-	$sql = "";						// データ取得SQL生成用
-	$arrRet = array();				// データ取得用
-	
-	$sql = "SELECT top_tpl AS top, product_tpl AS product, detail_tpl AS detail, mypage_tpl AS mypage FROM dtb_baseinfo";
-	$arrRet = $objDBConn->getAll($sql);
-	
-	return $arrRet[0];
-}
-
-/**************************************************************************************************************
- * 関数名	：lfUpdData
- * 処理内容	：DBにデータを保存する
- * 引数		：なし
- * 戻り値	：成功 TRUE、エラー FALSE
- **************************************************************************************************************/
-function lfUpdData(){
-	global $objPage;
-	$objDBConn = new SC_DbConn;		// DB操作オブジェクト
-	$sql = "";						// データ取得SQL生成用
-	$arrRet = array();				// データ取得用(更新判定)
-
-	// データ取得	
-	$sql = "SELECT top_tpl AS top, product_tpl AS product, detail_tpl AS detail, mypage_tpl AS mypage FROM dtb_baseinfo";
-	$arrRet = $objDBConn->getAll($sql);
-
-	$chk_tpl = $_POST['check_template'];
-	// データが取得できなければINSERT、できればUPDATE
-	if (isset($arrRet[0])){
-		// UPDATE
-		$arrVal = $arrRet[0];
-		
-		// TOPを変更した場合には全画面変更
-		if ($objPage->tpl_subno_template == $objPage->arrSubnavi['title'][1]){
-			$arrVal = array($chk_tpl,$chk_tpl,$chk_tpl,$chk_tpl);
-		}else{
-			$arrVal[$objPage->tpl_subno_template] = $chk_tpl;
-		}
-		$sql= "update dtb_baseinfo set top_tpl = ?, product_tpl = ?, detail_tpl = ?, mypage_tpl = ?, update_date = now()";
-	}else{
-		// INSERT
-		$arrVal = array(null,null,null,null);
-		
-		// TOPを変更した場合には全画面変更
-		if ($objPage->tpl_subno_template == $objPage->arrSubnavi['title'][1]){
-			$arrVal = array($chk_tpl,$chk_tpl,$chk_tpl,$chk_tpl);
-		}else{
-			$arrVal[$chk_tpl-1] =$chk_tpl;
-		}
-		$sql= "insert into dtb_baseinfo (top_tpl,product_tpl,detail_tpl,mypage_tpl, update_date) values (?,?,?,?,now());";
-	}
-
-	// SQL実行	
-	$arrRet = $objDBConn->query($sql,$arrVal);
-	
-	return $arrRet;
-}
-
-/**************************************************************************************************************
- * 関数名	：lfChangeTemplate
- * 処理内容	：テンプレートファイルを上書きする
- * 引数		：なし
- * 戻り値	：成功 TRUE、エラー FALSE
- **************************************************************************************************************/
-function lfChangeTemplate(){
-	global $objPage;
-	$tpl_path = USER_PATH . "templates/";
-	$inc_path = USER_PATH . "include/";
-	$css_path = USER_PATH . "css/";
-	
-	$tpl_name = "";
-	$tpl_element = "";
-	
-	$chk_tpl = $_POST['check_template'];
-	$path = $tpl_path . $chk_tpl . "/";
-	$taget_tpl_path = $path . "/templates/";
-	$taget_inc_path = $path . "/include/";
-	$taget_css_path = $path . "/css/";
-	$save_tpl_path = $tpl_path;
-	
-	switch($objPage->tpl_subno_template) {
-		// TOP
-		case $objPage->arrSubnavi['title'][1]:
-			$tpl_element = "TopTemplate";			// イメージの配列要素名格納用
-			$tpl_name = "top.tpl";
-			break;
-			
-		// 商品一覧
-		case $objPage->arrSubnavi['title'][2]:
-			$tpl_element = "ProdTemplate";			// イメージの配列要素名格納用
-			$tpl_name = "list.tpl";
-			break;
-			
-		// 商品詳細
-		case $objPage->arrSubnavi['title'][3]:
-			$tpl_element = "DetailTemplate";			// イメージの配列要素名格納用
-			$tpl_name = "detail.tpl";
-			break;
-			
-		// MYページ
-		case $objPage->arrSubnavi['title'][4]:
-			$tpl_element = "MypageTemplate";			//イメージの配列要素名格納用
-			$tpl_name = "mypage.tpl";
-			break;
-
-		default:
-			break;
-	}
-
-	// 画像パスを書き換え
-	$img_path = '<!--{$smarty.const.URL_DIR}-->img/';
-	$displace_path = '<!--{$smarty.const.URL_DIR}-->'. USER_DIR . 'templates/' . $chk_tpl . '/img/';
-	$fs = new File_SearchReplace($img_path, $displace_path, "", $path, true); 
-	$fs->doSearch(); 
-	
-	// TOPを変更した場合には全画面変更
-	if ($objPage->tpl_subno_template == $objPage->arrSubnavi['title'][1]){
-		// テンプレートファイルをコピー
-		copy($taget_tpl_path . "top.tpl", $save_tpl_path . "top.tpl");
-		copy($taget_tpl_path . "list.tpl", $save_tpl_path . "list.tpl");
-		copy($taget_tpl_path . "detail.tpl", $save_tpl_path . "detail.tpl");
-
-		// mypageはフォルダごとコピー
-		lfFolderCopy($taget_tpl_path."mypage/", $save_tpl_path . "mypage/");
-
-		// ブロックデータのコピー
-		lfFolderCopy($taget_inc_path."bloc/", $inc_path . "bloc/");
-
-		// ヘッダー,フッターコピー
-		copy($taget_inc_path . "header.tpl", $inc_path . "header.tpl");
-		copy($taget_inc_path . "footer.tpl", $inc_path . "footer.tpl");
-		
-		// CSSファイルのコピー
-		copy($taget_css_path . "contents.css", $css_path . "contents.css");
-
-	// mypageの場合にはフォルダごとコピーする
-	}elseif($objPage->tpl_subno_template == $objPage->arrSubnavi['title'][4]){
-		lfFolderCopy($taget_tpl_path."mypage/", $save_tpl_path."mypage/");
-	}else{
-		// テンプレートファイルをコピー
-		copy($taget_tpl_path . $tpl_name, $save_tpl_path . $tpl_name);
-	}
-
-	// 画像パスを元に戻す	
-	$fs = new File_SearchReplace($displace_path, $img_path, "", $path, true); 
-	$fs->doSearch(); 
-}
-
-/**************************************************************************************************************
- * 関数名	：lfDownloadTemplate
- * 処理内容	：テンプレートファイル圧縮してダウンロードする
- * 引数1	：テンプレートコード
- * 戻り値	：なし
- **************************************************************************************************************/
-function lfDownloadTemplate($template_code){
-	$filename = $template_code. ".tar.gz";
-	$dl_file = USER_TEMPLATE_PATH.$filename;
-	
-	// IMGフォルダをコピー
-	$mess = "";
-	$mess = sfCopyDir(HTML_PATH."img/", USER_TEMPLATE_PATH.$template_code."/img/", $mess);
-	
-	// ファイルの圧縮
-	$tar = new Archive_Tar($dl_file, TRUE);
-	// ファイル一覧取得
-	$arrFileHash = sfGetFileList(USER_TEMPLATE_PATH.$template_code);
-	foreach($arrFileHash as $val) {
-		$arrFileList[] = $val['file_name'];
-	}
-	// ディレクトリを移動
-	chdir(USER_TEMPLATE_PATH.$template_code);
-	
-	//圧縮をおこなう
-	$zip = $tar->create($arrFileList);
-		
-	// ダウンロード開始
-	Header("Content-disposition: attachment; filename=${filename}");
-	Header("Content-type: application/octet-stream; name=${dl_file}");
-	header("Content-Length: " .filesize($dl_file)); 
-	readfile ($dl_file);
-	// 圧縮ファイル削除
-	unlink($dl_file);
-	
-	exit();
-}
-
-/**************************************************************************************************************
- * 関数名	：lfFolderCopy
- * 処理内容	：フォルダをコピーする
- * 引数1	：コピー元パス
- * 引数2　　：コピー先パス
- * 戻り値	：なし
- **************************************************************************************************************/
-function lfFolderCopy($taget_path, $save_path){
-
-	// フォルダ内のファイルを取得する
-	$arrMypage=glob($taget_path . "*" );
-	
-	// フォルダがなければ作成する
-	if(!is_dir($save_path)){
-		mkdir($save_path);
-	}
-
-	// フォルダ内を全てコピー
-	foreach($arrMypage as $key => $val){
-		$matches = array();
-		mb_ereg("^(.*[\/])(.*)",$val, $matches);
-		$data=$matches[2];
-		copy($val, $save_path . $data);
-	}
-}
+$objPage = new LC_Page_Admin_Design_Template_Ex();
+$objPage->init();
+$objPage->process();
+register_shutdown_function(array($objPage, "destroy"));
+?>
Index: /branches/feature-module-update/html/admin/design/upload.php
===================================================================
--- /branches/feature-module-update/html/admin/design/upload.php	(revision 15532)
+++ /branches/feature-module-update/html/admin/design/upload.php	(revision 16430)
@@ -5,186 +5,15 @@
  * http://www.lockon.co.jp/
  */
+
+// {{{ requires
 require_once("../../require.php");
-require_once(DATA_PATH. "module/Tar.php");
+require_once(CLASS_EX_PATH . "page_extends/admin/design/LC_Page_Admin_Design_Upload_Ex.php");
 
-class LC_Page {
+// }}}
+// {{{ generate page
 
-	function LC_Page() {
-		$this->tpl_mainpage = 'design/upload.tpl';
-		$this->tpl_subnavi = 'design/subnavi.tpl';
-		$this->tpl_subno = 'template';
-		$this->tpl_subno_template = 'upload';
-		$this->tpl_mainno = "design";
-		$this->tpl_subtitle = 'アップロード';
-		$this->template_name = 'アップロード';
-	}
-}
-
-$objPage = new LC_Page();
-$objView = new SC_AdminView();
-$objSess = new SC_Session();
-$objQuery = new SC_Query();
-
-// 認証可否の判定
-$objSess = new SC_Session();
-sfIsSuccess($objSess);
-
-// アップロードしたファイルをフォルダ
-$new_file_dir = USER_TEMPLATE_PATH.$_POST['template_code'];
-
-// ファイル管理クラス
-$objUpFile = new SC_UploadFile(TEMPLATE_TEMP_DIR, $new_file_dir);
-// ファイル情報の初期化
-lfInitFile();
-// パラメータ管理クラス
-$objFormParam = new SC_FormParam();
-// パラメータ情報の初期化
-lfInitParam();
-
-switch($_POST['mode']) {
-case 'upload':
-	$objFormParam->setParam($_POST);
-	$arrRet = $objFormParam->getHashArray();
-	
-	$objPage->arrErr = lfErrorCheck($arrRet);
-
-	// ファイルを一時フォルダへ保存
-	$ret = $objUpFile->makeTempFile('template_file', false);
-	if($ret != "") {
-		$objPage->arrErr['template_file'] = $ret;
-	} else if(count($objPage->arrErr) <= 0) {
-		// フォルダ作成
-		$ret = @mkdir($new_file_dir);
-		// 一時フォルダから保存ディレクトリへ移動
-		$objUpFile->moveTempFile();
-		// 解凍
-		lfUnpacking($new_file_dir, $_FILES['template_file']['name'], $new_file_dir."/");
-		// DBにテンプレート情報を保存
-		lfRegistTemplate($arrRet);
-		// 完了表示javascript
-		$objPage->tpl_onload = "alert('テンプレートファイルをアップロードしました。');";
-		// フォーム値をクリア
-		$objFormParam->setParam(array('template_code' => "", 'template_name' => ""));
-	}
-	break;
-default:
-	break;
-}
-// 画面の表示
-$objPage->arrForm = $objFormParam->getFormParamList();
-$objView->assignobj($objPage);
-$objView->display(MAIN_FRAME);
-
-//---------------------------------------------------------------------------------------------------------------------------------------------------------
-
-/* 
- * 関数名：lfInitFile()
- * 説明　：ファイル情報の初期化
- */
-function lfInitFile() {
-	global $objUpFile;
-
-	$objUpFile->addFile("テンプレートファイル", 'template_file', array(), TEMPLATE_SIZE, true, 0, 0, false);
-}
-
-/* 
- * 関数名：lfInitParam()
- * 説明　：パラメータ情報の初期化
- */
-function lfInitParam() {
-	global $objFormParam;
-		
-	$objFormParam->addParam("テンプレートコード", "template_code", STEXT_LEN, "KVa", array("EXIST_CHECK","SPTAB_CHECK","MAX_LENGTH_CHECK", "ALNUM_CHECK"));
-	$objFormParam->addParam("テンプレート名", "template_name", STEXT_LEN, "KVa", array("EXIST_CHECK","SPTAB_CHECK","MAX_LENGTH_CHECK"));
-}
-
-/* 
- * 関数名：lfErrorCheck()
- * 引数1 ：フォームの値
- * 説明　：エラーチェック
- */
-function lfErrorCheck($arrList) {
-	global $objQuery;
-	global $objFormParam;
-	
-	$objErr = new SC_CheckError($arrList);
-	$objErr->arrErr = $objFormParam->checkError();
-	
-	if(count($objErr->arrErr) <= 0) {
-		// 同名のフォルダが存在する場合はエラー
-		if(file_exists(USER_TEMPLATE_PATH.$arrList['template_code'])) {
-			$objErr->arrErr['template_code'] = "※ 同名のファイルがすでに存在します。<br/>";
-		}
-		// DBにすでに登録されていないかチェック
-		$ret = $objQuery->get("dtb_templates", "template_code", "template_code = ?", array($arrList['template_code']));
-		if($ret != "") {
-			$objErr->arrErr['template_code'] = "※ すでに登録されているテンプレートコードです。<br/>";
-		}
-		// ファイルの拡張子チェック(.tar/tar.gzのみ許可)
-		$errFlag = true;
-		$array_ext = explode(".", $_FILES['template_file']['name']);
-		$ext = $array_ext[ count ( $array_ext ) - 1 ];
-		$ext = strtolower($ext);
-		// .tarチェック
-		if ($ext == 'tar') {
-			$errFlag = false;
-		}
-
-		$ext = $array_ext[ count ( $array_ext ) - 2 ].".".$ext;
-		$ext = strtolower($ext);
-		// .tar.gzチェック
-		if ($ext== 'tar.gz') {
-			$errFlag = false;
-		}
-		
-		if($errFlag) {
-			$objErr->arrErr['template_file'] = "※ アップロードするテンプレートファイルで許可されている形式は、tar/tar.gzです。<br />";		
-		}
-	}
-	
-	return $objErr->arrErr;
-}
-
-/* 
- * 関数名：lfErrorCheck()
- * 引数1 ：パラメータ
- * 説明　：テンプレートデータ登録
- */
-function lfRegistTemplate($arrList) {
-	global $objQuery;
-	
-	// INSERTする値を作成する。
-	$sqlval['template_code'] = $arrList['template_code'];
-	$sqlval['template_name'] = $arrList['template_name'];
-	$sqlval['create_date'] = "now()";
-	$sqlval['update_date'] = "now()";
-
-	$objQuery->insert("dtb_templates", $sqlval);
-}
-
-/* 
- * 関数名：lfUnpacking
- * 引数1 ：ディレクトリ
- * 引数2 ：ファイルネーム
- * 引数3 ：解凍ディレクトリ
- * 説明　：テンプレートデータ登録
- */
-function lfUnpacking($dir, $file_name, $unpacking_dir) {
-
-	// 圧縮フラグTRUEはgzip解凍をおこなう
-	$tar = new Archive_Tar("$dir/$file_name", TRUE);
-
-	// 拡張子を切り取る
-	$unpacking_name = ereg_replace("\.tar$", "", $file_name);
-	$unpacking_name = ereg_replace("\.tar\.gz$", "", $file_name);
-
-	// 指定されたフォルダ内に解凍する
-	$err = $tar->extractModify($unpacking_dir, $unpacking_name);
-
-	// フォルダ削除
-	@sfDelFile("$dir/$unpacking_name");
-	// 圧縮ファイル削除
-	@unlink("$dir/$file_name");
-
-	return $err;
-}
+$objPage = new LC_Page_Admin_Design_Upload_Ex();
+$objPage->init();
+$objPage->process();
+register_shutdown_function(array($objPage, "destroy"));
+?>
