source: branches/feature-module-update/html/admin/design/upload.php @ 15078

Revision 15078, 5.8 KB checked in by nanasess, 17 years ago (diff)

r15064 から svn cp
とりあえず暫定コミット.

  • UTF-8 に変更
  • slib.php, glib.php のクラス化
  • LC_Page の抽象化(一部)
Line 
1<?php
2/*
3 * Copyright(c) 2000-2007 LOCKON CO.,LTD. All Rights Reserved.
4 *
5 * http://www.lockon.co.jp/
6 */
7require_once("../../require.php");
8require_once(DATA_PATH. "module/Tar.php");
9
10class LC_Page {
11
12    function LC_Page() {
13        $this->tpl_mainpage = 'design/upload.tpl';
14        $this->tpl_subnavi = 'design/subnavi.tpl';
15        $this->tpl_subno = 'template';
16        $this->tpl_subno_template = 'upload';
17        $this->tpl_mainno = "design";
18        $this->tpl_subtitle = 'アップロード';
19        $this->template_name = 'アップロード';
20    }
21}
22
23$objPage = new LC_Page();
24$objView = new SC_AdminView();
25$objSess = new SC_Session();
26$objQuery = new SC_Query();
27
28// 認証可否の判定
29$objSess = new SC_Session();
30sfIsSuccess($objSess);
31
32// アップロードしたファイルをフォルダ
33$new_file_dir = USER_TEMPLATE_PATH.$_POST['template_code'];
34
35// ファイル管理クラス
36$objUpFile = new SC_UploadFile(TEMPLATE_TEMP_DIR, $new_file_dir);
37// ファイル情報の初期化
38lfInitFile();
39// パラメータ管理クラス
40$objFormParam = new SC_FormParam();
41// パラメータ情報の初期化
42lfInitParam();
43
44switch($_POST['mode']) {
45case 'upload':
46    $objFormParam->setParam($_POST);
47    $arrRet = $objFormParam->getHashArray();
48   
49    $objPage->arrErr = lfErrorCheck($arrRet);
50
51    // ファイルを一時フォルダへ保存
52    $ret = $objUpFile->makeTempFile('template_file', false);
53    if($ret != "") {
54        $objPage->arrErr['template_file'] = $ret;
55    } else if(count($objPage->arrErr) <= 0) {
56        // フォルダ作成
57        $ret = @mkdir($new_file_dir);
58        // 一時フォルダから保存ディレクトリへ移動
59        $objUpFile->moveTempFile();
60        // 解凍
61        lfUnpacking($new_file_dir, $_FILES['template_file']['name'], $new_file_dir."/");
62        // DBにテンプレート情報を保存
63        lfRegistTemplate($arrRet);
64        // 完了表示javascript
65        $objPage->tpl_onload = "alert('テンプレートファイルをアップロードしました。');";
66        // フォーム値をクリア
67        $objFormParam->setParam(array('template_code' => "", 'template_name' => ""));
68    }
69    break;
70default:
71    break;
72}
73// 画面の表示
74$objPage->arrForm = $objFormParam->getFormParamList();
75$objView->assignobj($objPage);
76$objView->display(MAIN_FRAME);
77
78//---------------------------------------------------------------------------------------------------------------------------------------------------------
79
80/*
81 * 関数名:lfInitFile()
82 * 説明 :ファイル情報の初期化
83 */
84function lfInitFile() {
85    global $objUpFile;
86
87    $objUpFile->addFile("テンプレートファイル", 'template_file', array(), TEMPLATE_SIZE, true, 0, 0, false);
88}
89
90/*
91 * 関数名:lfInitParam()
92 * 説明 :パラメータ情報の初期化
93 */
94function lfInitParam() {
95    global $objFormParam;
96       
97    $objFormParam->addParam("テンプレートコード", "template_code", STEXT_LEN, "KVa", array("EXIST_CHECK","SPTAB_CHECK","MAX_LENGTH_CHECK", "ALNUM_CHECK"));
98    $objFormParam->addParam("テンプレート名", "template_name", STEXT_LEN, "KVa", array("EXIST_CHECK","SPTAB_CHECK","MAX_LENGTH_CHECK"));
99}
100
101/*
102 * 関数名:lfErrorCheck()
103 * 引数1 :フォームの値
104 * 説明 :エラーチェック
105 */
106function lfErrorCheck($arrList) {
107    global $objQuery;
108    global $objFormParam;
109   
110    $objErr = new SC_CheckError($arrList);
111    $objErr->arrErr = $objFormParam->checkError();
112   
113    if(count($objErr->arrErr) <= 0) {
114        // 同名のフォルダが存在する場合はエラー
115        if(file_exists(USER_TEMPLATE_PATH.$arrList['template_code'])) {
116            $objErr->arrErr['template_code'] = "※ 同名のファイルがすでに存在します。<br/>";
117        }
118        // DBにすでに登録されていないかチェック
119        $ret = $objQuery->get("dtb_templates", "template_code", "template_code = ?", array($arrList['template_code']));
120        if($ret != "") {
121            $objErr->arrErr['template_code'] = "※ すでに登録されているテンプレートコードです。<br/>";
122        }
123        // ファイルの拡張子チェック(.tar/tar.gzのみ許可)
124        $errFlag = true;
125        $array_ext = explode(".", $_FILES['template_file']['name']);
126        $ext = $array_ext[ count ( $array_ext ) - 1 ];
127        $ext = strtolower($ext);
128        // .tarチェック
129        if ($ext == 'tar') {
130            $errFlag = false;
131        }
132
133        $ext = $array_ext[ count ( $array_ext ) - 2 ].".".$ext;
134        $ext = strtolower($ext);
135        // .tar.gzチェック
136        if ($ext== 'tar.gz') {
137            $errFlag = false;
138        }
139       
140        if($errFlag) {
141            $objErr->arrErr['template_file'] = "※ アップロードするテンプレートファイルで許可されている形式は、tar/tar.gzです。<br />";       
142        }
143    }
144   
145    return $objErr->arrErr;
146}
147
148/*
149 * 関数名:lfErrorCheck()
150 * 引数1 :パラメータ
151 * 説明 :テンプレートデータ登録
152 */
153function lfRegistTemplate($arrList) {
154    global $objQuery;
155   
156    // INSERTする値を作成する。
157    $sqlval['template_code'] = $arrList['template_code'];
158    $sqlval['template_name'] = $arrList['template_name'];
159    $sqlval['create_date'] = "now()";
160    $sqlval['update_date'] = "now()";
161
162    $objQuery->insert("dtb_templates", $sqlval);
163}
164
165/*
166 * 関数名:lfUnpacking
167 * 引数1 :ディレクトリ
168 * 引数2 :ファイルネーム
169 * 引数3 :解凍ディレクトリ
170 * 説明 :テンプレートデータ登録
171 */
172function lfUnpacking($dir, $file_name, $unpacking_dir) {
173
174    // 圧縮フラグTRUEはgzip解凍をおこなう
175    $tar = new Archive_Tar("$dir/$file_name", TRUE);
176
177    // 拡張子を切り取る
178    $unpacking_name = ereg_replace("\.tar$", "", $file_name);
179    $unpacking_name = ereg_replace("\.tar\.gz$", "", $file_name);
180
181    // 指定されたフォルダ内に解凍する
182    $err = $tar->extractModify($unpacking_dir, $unpacking_name);
183
184    // フォルダ削除
185    @sfDelFile("$dir/$unpacking_name");
186    // 圧縮ファイル削除
187    @unlink("$dir/$file_name");
188
189    return $err;
190}
Note: See TracBrowser for help on using the repository browser.