source: branches/rel/html/admin/design/upload.php @ 12157

Revision 12157, 5.3 KB checked in by uehara, 16 years ago (diff)
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.