source: temp/trunk/html/install/index.php @ 6052

Revision 6052, 18.2 KB checked in by naka, 20 years ago (diff)

* empty log message *

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1<?php
2/*
3 * Copyright(c) 2000-2006 LOCKON CO.,LTD. All Rights Reserved.
4 *
5 * http://www.lockon.co.jp/
6 */
7require_once("../require.php");
8$INSTALL_DIR = realpath(dirname( __FILE__));
9
10class LC_Page {
11    function LC_Page() {
12        $this->arrDB_TYPE = array(
13            'pgsql' => 'PostgreSQL',
14            'mysql' => 'MySQL' 
15        );
16        $this->arrDB_PORT = array(
17            'pgsql' => '',
18            'mysql' => ''   
19        );
20    }
21}
22
23$objPage = new LC_Page();
24
25// ¥Æ¥ó¥×¥ì¡¼¥È¥³¥ó¥Ñ¥¤¥ë¥Ç¥£¥ì¥¯¥È¥ê¤Î½ñ¹þ¤ß¸¢¸Â¥Á¥§¥Ã¥¯
26$temp_dir = $INSTALL_DIR . '/temp';
27$mode = lfGetFileMode($temp_dir);
28
29if($mode != '777') {
30    sfErrorHeader($temp_dir . "¤Ë¥æ¡¼¥¶½ñ¹þ¤ß¸¢¸Â(777)¤òÉÕÍ¿¤·¤Æ²¼¤µ¤¤¡£", true);
31    exit;
32}
33
34$objView = new SC_InstallView($INSTALL_DIR . '/templates', $INSTALL_DIR . '/temp');
35
36// ¥Ñ¥é¥á¡¼¥¿´ÉÍý¥¯¥é¥¹
37$objWebParam = new SC_FormParam();
38$objDBParam = new SC_FormParam();
39// ¥Ñ¥é¥á¡¼¥¿¾ðÊó¤Î½é´ü²½
40$objWebParam = lfInitWebParam($objWebParam);
41$objDBParam = lfInitDBParam($objDBParam);
42
43//¥Õ¥©¡¼¥àÇÛÎó¤Î¼èÆÀ
44$objWebParam->setParam($_POST);
45$objDBParam->setParam($_POST);
46
47switch($_POST['mode']) {
48// ¤è¤¦¤³¤½
49case 'welcome':
50    $objPage = lfDispStep0($objPage);
51    break;
52// ¥¢¥¯¥»¥¹¸¢¸Â¤Î¥Á¥§¥Ã¥¯
53case 'step0':
54    $objPage = lfDispStep0_1($objPage);
55    break; 
56// ¥Õ¥¡¥¤¥ë¤Î¥³¥Ô¡¼
57case 'step0_1':
58    $objPage = lfDispStep1($objPage);
59    break; 
60// WEB¥µ¥¤¥È¤ÎÀßÄê
61case 'step1':
62    //ÆþÎÏÃͤΥ¨¥é¡¼¥Á¥§¥Ã¥¯
63    $objPage->arrErr = lfCheckWEBError($objWebParam);
64    if(count($objPage->arrErr) == 0) {
65        $objPage = lfDispStep2($objPage);
66    } else {
67        $objPage = lfDispStep1($objPage);
68    }
69    break;
70// ¥Ç¡¼¥¿¥Ù¡¼¥¹¤ÎÀßÄê
71case 'step2':
72    //ÆþÎÏÃͤΥ¨¥é¡¼¥Á¥§¥Ã¥¯
73    $objPage->arrErr = lfCheckDBError($objDBParam);
74    if(count($objPage->arrErr) == 0) {
75        $objPage = lfDispStep3($objPage);
76    } else {
77        $objPage = lfDispStep2($objPage);
78    }
79    break;
80// ¥Æ¡¼¥Ö¥ë¤ÎºîÀ®
81case 'step3':
82    // ÆþÎϥǡ¼¥¿¤òÅϤ¹¡£
83    $arrRet =  $objDBParam->getHashArray();
84   
85    $skip = $_POST["db_skip"];
86
87    // ¥¹¥­¥Ã¥×¤¹¤ë¾ì¹ç¤Ë¤Ï´°Î»²èÌ̤ØÁ«°Ü
88    if ($skip == "on") {
89        // ÀßÄê¥Õ¥¡¥¤¥ë¤ÎÀ¸À®
90        lfMakeConfigFile();
91        $objPage = lfDispComplete($objPage);
92        break;
93    }
94   
95    // ¥Æ¡¼¥Ö¥ë¤ÎºîÀ®
96    $objPage->arrErr = lfExecuteSQL("./create_table_".$arrRet['db_type'].".sql", $arrRet['db_user'], $arrRet['db_password'], $arrRet['db_server'], $arrRet['db_name'], $arrRet['db_type'], $arrRet['db_port']);
97    if(count($objPage->arrErr) == 0) {
98        $objPage->tpl_message.="¡û¡§¥Æ¡¼¥Ö¥ë¤ÎºîÀ®¤ËÀ®¸ù¤·¤Þ¤·¤¿¡£<br>";
99    } else {
100        $objPage->tpl_message.="¡ß¡§¥Æ¡¼¥Ö¥ë¤ÎºîÀ®¤Ë¼ºÇÔ¤·¤Þ¤·¤¿¡£<br>";       
101    }
102
103    // ¥Ó¥å¡¼¤ÎºîÀ®
104    if(count($objPage->arrErr) == 0 and $arrRet['db_type'] == 'pgsql') {
105        // ¥Ó¥å¡¼¤ÎºîÀ®
106        $objPage->arrErr = lfExecuteSQL("./create_view.sql", $arrRet['db_user'], $arrRet['db_password'], $arrRet['db_server'], $arrRet['db_name'], $arrRet['db_type'], $arrRet['db_port']);
107        if(count($objPage->arrErr) == 0) {
108            $objPage->tpl_message.="¡û¡§¥Ó¥å¡¼¤ÎºîÀ®¤ËÀ®¸ù¤·¤Þ¤·¤¿¡£<br>";
109        } else {
110            $objPage->tpl_message.="¡ß¡§¥Ó¥å¡¼¤ÎºîÀ®¤Ë¼ºÇÔ¤·¤Þ¤·¤¿¡£<br>";     
111        }
112    }   
113   
114    // ½é´ü¥Ç¡¼¥¿¤ÎºîÀ®
115    if(count($objPage->arrErr) == 0) {
116        $objPage->arrErr = lfExecuteSQL("./insert_data.sql", $arrRet['db_user'], $arrRet['db_password'], $arrRet['db_server'], $arrRet['db_name'], $arrRet['db_type'], $arrRet['db_port']);
117        if(count($objPage->arrErr) == 0) {
118            $objPage->tpl_message.="¡û¡§½é´ü¥Ç¡¼¥¿¤ÎºîÀ®¤ËÀ®¸ù¤·¤Þ¤·¤¿¡£<br>";
119        } else {
120            $objPage->tpl_message.="¡ß¡§½é´ü¥Ç¡¼¥¿¤ÎºîÀ®¤Ë¼ºÇÔ¤·¤Þ¤·¤¿¡£<br>";     
121        }
122    }   
123   
124    // ¥«¥é¥à¥³¥á¥ó¥È¤Î½ñ¹þ¤ß
125    if(count($objPage->arrErr) == 0) {
126        $objPage->arrErr = lfExecuteSQL("./column_comment.sql", $arrRet['db_user'], $arrRet['db_password'], $arrRet['db_server'], $arrRet['db_name'], $arrRet['db_type'], $arrRet['db_port']);
127        if(count($objPage->arrErr) == 0) {
128            $objPage->tpl_message.="¡û¡§¥«¥é¥à¥³¥á¥ó¥È¤Î½ñ¹þ¤ß¤ËÀ®¸ù¤·¤Þ¤·¤¿¡£<br>";
129        } else {
130            $objPage->tpl_message.="¡ß¡§¥«¥é¥à¥³¥á¥ó¥È¤Î½ñ¹þ¤ß¤Ë¼ºÇÔ¤·¤Þ¤·¤¿¡£<br>";       
131        }
132    }   
133   
134    // ¥Æ¡¼¥Ö¥ë¥³¥á¥ó¥È¤Î½ñ¹þ¤ß
135    if(count($objPage->arrErr) == 0) {
136        $objPage->arrErr = lfExecuteSQL("./table_comment.sql", $arrRet['db_user'], $arrRet['db_password'], $arrRet['db_server'], $arrRet['db_name'], $arrRet['db_type'], $arrRet['db_port']);
137        if(count($objPage->arrErr) == 0) {
138            $objPage->tpl_message.="¡û¡§¥Æ¡¼¥Ö¥ë¥³¥á¥ó¥È¤Î½ñ¹þ¤ß¤ËÀ®¸ù¤·¤Þ¤·¤¿¡£<br>";
139        } else {
140            $objPage->tpl_message.="¡ß¡§¥Æ¡¼¥Ö¥ë¥³¥á¥ó¥È¤Î½ñ¹þ¤ß¤Ë¼ºÇÔ¤·¤Þ¤·¤¿¡£<br>";     
141        }
142    }
143
144
145    if(count($objPage->arrErr) == 0) {
146        // ÀßÄê¥Õ¥¡¥¤¥ë¤ÎÀ¸À®
147        lfMakeConfigFile();
148        $objPage = lfDispStep3($objPage);
149        $objPage->tpl_mode = 'complete';
150    } else {
151        $objPage = lfDispStep3($objPage);
152    }
153    break;
154// ¥Æ¡¼¥Ö¥ëÎàºï½ü
155case 'drop':
156    // ÆþÎϥǡ¼¥¿¤òÅϤ¹¡£
157    $arrRet =  $objDBParam->getHashArray();
158   
159    if ($arrRet['db_type'] == 'pgsql'){
160        // ¥Ó¥å¡¼¤Îºï½ü
161        $objPage->arrErr = lfExecuteSQL("./drop_view.sql", $arrRet['db_user'], $arrRet['db_password'], $arrRet['db_server'], $arrRet['db_name'], $arrRet['db_type'], $arrRet['db_port'], false);
162        if(count($objPage->arrErr) == 0) {
163            $objPage->tpl_message.="¡û¡§¥Ó¥å¡¼¤Îºï½ü¤ËÀ®¸ù¤·¤Þ¤·¤¿¡£<br>";
164        } else {
165            $objPage->tpl_message.="¡ß¡§¥Ó¥å¡¼¤Îºï½ü¤Ë¼ºÇÔ¤·¤Þ¤·¤¿¡£<br>";     
166        }
167    }
168
169
170    // ¥Æ¡¼¥Ö¥ë¤Îºï½ü
171    if(count($objPage->arrErr) == 0) {
172        $objPage->arrErr = lfExecuteSQL("./drop_table.sql", $arrRet['db_user'], $arrRet['db_password'], $arrRet['db_server'], $arrRet['db_name'], $arrRet['db_type'], $arrRet['db_port'], false);
173        if(count($objPage->arrErr) == 0) {
174            $objPage->tpl_message.="¡û¡§¥Æ¡¼¥Ö¥ë¤Îºï½ü¤ËÀ®¸ù¤·¤Þ¤·¤¿¡£<br>";
175        } else {
176            $objPage->tpl_message.="¡ß¡§¥Æ¡¼¥Ö¥ë¤Îºï½ü¤Ë¼ºÇÔ¤·¤Þ¤·¤¿¡£<br>";       
177        }
178    }
179    $objPage = lfDispStep3($objPage);
180    break;
181// ´°Î»²èÌÌ
182case 'complete':
183
184    // ¥·¥ç¥Ã¥×¥Þ¥¹¥¿¾ðÊó¤Î½ñ¤­¹þ¤ß
185    $arrRet =  $objDBParam->getHashArray();
186   
187    $dsn = $arrRet['db_type']."://".$arrRet['db_user'].":".$arrRet['db_password']."@".$arrRet['db_server'].":".$arrRet['db_port']."/".$arrRet['db_name'];
188    $sqlval['shop_name'] = $objWebParam->getValue('shop_name');
189    $sqlval['email01'] = $objWebParam->getValue('admin_mail');
190    $sqlval['email02'] = $objWebParam->getValue('admin_mail');
191    $sqlval['email03'] = $objWebParam->getValue('admin_mail');
192    $sqlval['email04'] = $objWebParam->getValue('admin_mail');
193    $sqlval['email05'] = $objWebParam->getValue('admin_mail');
194    $sqlval['top_tpl'] = "default1";
195    $sqlval['product_tpl'] = "default1";
196    $sqlval['detail_tpl'] = "default1";
197    $sqlval['mypage_tpl'] = "default1";
198    $objQuery = new SC_Query($dsn);
199    $cnt = $objQuery->count("dtb_baseinfo");
200    if($cnt > 0) {
201        $objQuery->update("dtb_baseinfo", $sqlval);
202    } else {       
203        $objQuery->insert("dtb_baseinfo", $sqlval);     
204    }
205    global $GLOBAL_ERR;
206    $GLOBAL_ERR = "";
207    $objPage = lfDispComplete($objPage);
208    break;
209case 'return_step0':
210    $objPage = lfDispStep0($objPage);
211    break; 
212case 'return_step1':
213    $objPage = lfDispStep1($objPage);
214    break;
215case 'return_step2':
216    $objPage = lfDispStep2($objPage);
217    break;
218case 'return_welcome':
219default:
220    $objPage = lfDispWelcome($objPage);
221    break;
222}
223
224//¥Õ¥©¡¼¥àÍѤΥѥé¥á¡¼¥¿¤òÊÖ¤¹
225$objPage->arrForm = $objWebParam->getFormParamList();
226$objPage->arrForm = array_merge($objPage->arrForm, $objDBParam->getFormParamList());
227
228// SiteInfo¤òÆÉ¤ß¹þ¤Þ¤Ê¤¤
229$objView->assignobj($objPage);
230$objView->display('install_frame.tpl');
231//-----------------------------------------------------------------------------------------------------------------------------------
232// ¤è¤¦¤³¤½²èÌ̤Îɽ¼¨
233function lfDispWelcome($objPage) {
234    global $objWebParam;
235    global $objDBParam;
236    // hidden¤ËÆþÎÏÃͤòÊÝ»ý
237    $objPage->arrHidden = $objWebParam->getHashArray();
238    // hidden¤ËÆþÎÏÃͤòÊÝ»ý
239    $objPage->arrHidden = array_merge($objPage->arrHidden, $objDBParam->getHashArray());
240    $objPage->arrHidden['db_skip'] = $_POST['db_skip'];
241    $objPage->tpl_mainpage = 'welcome.tpl';
242    $objPage->tpl_mode = 'welcome';
243    return $objPage;
244}
245
246// STEP0²èÌ̤Îɽ¼¨(¥Õ¥¡¥¤¥ë¸¢¸Â¥Á¥§¥Ã¥¯)
247function lfDispStep0($objPage) {
248    global $objWebParam;
249    global $objDBParam;
250    // hidden¤ËÆþÎÏÃͤòÊÝ»ý
251    $objPage->arrHidden = $objWebParam->getHashArray();
252    // hidden¤ËÆþÎÏÃͤòÊÝ»ý
253    $objPage->arrHidden = array_merge($objPage->arrHidden, $objDBParam->getHashArray());
254    $objPage->arrHidden['db_skip'] = $_POST['db_skip'];
255    $objPage->tpl_mainpage = 'step0.tpl';
256    $objPage->tpl_mode = 'step0';
257   
258    // ¥×¥í¥°¥é¥à¤Ç½ñ¹þ¤ß¤µ¤ì¤ë¥Õ¥¡¥¤¥ë¡¦¥Ç¥£¥ì¥¯¥È¥ê
259    $arrWriteFile = array(
260        "data/install.inc",
261        "html/user_data",
262        "html/upload",
263        "data/Smarty/templates_c",     
264        "data/update",
265        "data/logs",
266    );
267   
268    $mess = "";
269    $err_file = false;
270    foreach($arrWriteFile as $val) {
271        $path = "../../" . $val;       
272        if(file_exists($path)) {
273            $mode = lfGetFileMode("../../" . $val);
274           
275            // ¥Ç¥£¥ì¥¯¥È¥ê¤Î¾ì¹ç
276            if(is_dir($path)) {
277                if($mode == "777") {
278                    $mess.= ">> ¡û¡§$val($mode) ¤ÏÌäÂꤢ¤ê¤Þ¤»¤ó¡£<br>";                   
279                } else {
280                    $mess.= ">> ¡ß¡§$val($mode) ¤Ë¥æ¡¼¥¶½ñ¹þ¤ß¸¢¸Â(777)¤òÉÕÍ¿¤·¤Æ²¼¤µ¤¤¡£<br>";
281                    $err_file = true;                                       
282                }
283            } else {
284                if($mode == "666") {
285                    $mess.= ">> ¡û¡§$val($mode) ¤ÏÌäÂꤢ¤ê¤Þ¤»¤ó¡£<br>";                   
286                } else {
287                    $mess.= ">> ¡ß¡§$val($mode) ¤Ë¥æ¡¼¥¶½ñ¹þ¤ß¸¢¸Â(666)¤òÉÕÍ¿¤·¤Æ²¼¤µ¤¤¡£<br>";
288                    $err_file = true;                           
289                }
290            }   
291           
292        } else {
293            $mess.= ">> ¡ß¡§$val ¤¬¸«¤Ä¤«¤ê¤Þ¤»¤ó¡£<br>";
294            $err_file = true;
295        }
296    }
297   
298    // ¸¢¸Â¥¨¥é¡¼Åù¤¬È¯À¸¤·¤Æ¤¤¤Ê¤¤¾ì¹ç
299    if(!$err_file) {
300        $path = "../../data/Smarty/templates_c/admin";
301        if(!file_exists($path)) {
302            mkdir($path);
303        }
304        $path = "../../html/upload/save_image";
305        if(!file_exists($path)) {
306            mkdir($path);
307        }
308        $path = "../../html/upload/temp_image";
309        if(!file_exists($path)) {
310            mkdir($path);
311        }
312        $path = "../../html/upload/graph_image";
313        if(!file_exists($path)) {
314            mkdir($path);
315        }
316        $path = "../../html/upload/csv";
317        if(!file_exists($path)) {
318            mkdir($path);
319        }
320    }
321   
322    $objPage->mess = $mess;
323    $objPage->err_file = $err_file;
324
325    return $objPage;
326}
327
328
329// STEP0_1²èÌ̤Îɽ¼¨(¥Õ¥¡¥¤¥ë¤Î¥³¥Ô¡¼)
330function lfDispStep0_1($objPage) {
331    global $objWebParam;
332    global $objDBParam;
333    // hidden¤ËÆþÎÏÃͤòÊÝ»ý
334    $objPage->arrHidden = $objWebParam->getHashArray();
335    // hidden¤ËÆþÎÏÃͤòÊÝ»ý
336    $objPage->arrHidden = array_merge($objPage->arrHidden, $objDBParam->getHashArray());
337    $objPage->arrHidden['db_skip'] = $_POST['db_skip'];
338    $objPage->tpl_mainpage = 'step0_1.tpl';
339    $objPage->tpl_mode = 'step0_1';
340    // ¥Õ¥¡¥¤¥ë¥³¥Ô¡¼
341    $objPage->copy_mess = sfCopyDir("./user_data/", "../../html/user_data/", $objPage->copy_mess);
342    $objPage->copy_mess = sfCopyDir("./save_image/", "../../html/upload/save_image/", $objPage->copy_mess);
343    return $objPage;
344}
345
346function lfGetFileMode($path) {
347    $mode = substr(sprintf('%o', fileperms($path)), -3);
348    return $mode;
349}
350
351// STEP1²èÌ̤Îɽ¼¨
352function lfDispStep1($objPage) {
353    global $objDBParam;
354    // hidden¤ËÆþÎÏÃͤòÊÝ»ý
355    $objPage->arrHidden = $objDBParam->getHashArray();
356    $objPage->arrHidden['db_skip'] = $_POST['db_skip'];
357    $objPage->tpl_mainpage = 'step1.tpl';
358    $objPage->tpl_mode = 'step1';
359    return $objPage;
360}
361
362// STEP2²èÌ̤Îɽ¼¨
363function lfDispStep2($objPage) {
364    global $objWebParam;
365    global $objDBParam;
366    // hidden¤ËÆþÎÏÃͤòÊÝ»ý
367    $objPage->arrHidden = $objWebParam->getHashArray();
368    $objPage->arrHidden['db_skip'] = $_POST['db_skip'];
369    $objPage->tpl_mainpage = 'step2.tpl';
370    $objPage->tpl_mode = 'step2';
371    return $objPage;
372}
373
374// STEP3²èÌ̤Îɽ¼¨
375function lfDispStep3($objPage) {
376    global $objWebParam;
377    global $objDBParam;
378    // hidden¤ËÆþÎÏÃͤòÊÝ»ý
379    $objPage->arrHidden = $objWebParam->getHashArray();
380    // hidden¤ËÆþÎÏÃͤòÊÝ»ý
381    $objPage->arrHidden = array_merge($objPage->arrHidden, $objDBParam->getHashArray());
382    $objPage->tpl_db_skip = $_POST['db_skip'];
383    $objPage->tpl_mainpage = 'step3.tpl';
384    $objPage->tpl_mode = 'step3';
385    return $objPage;
386}
387
388// ´°Î»²èÌ̤Îɽ¼¨
389function lfDispComplete($objPage) {
390    global $objWebParam;
391    global $objDBParam;
392    // hidden¤ËÆþÎÏÃͤòÊÝ»ý
393    $objPage->arrHidden = $objWebParam->getHashArray();
394    // hidden¤ËÆþÎÏÃͤòÊÝ»ý
395    $objPage->arrHidden = array_merge($objPage->arrHidden, $objDBParam->getHashArray());
396    $objPage->arrHidden['db_skip'] = $_POST['db_skip'];
397    $objPage->tpl_mainpage = 'complete.tpl';
398    $objPage->tpl_mode = 'complete';
399    return $objPage;
400}
401
402// WEB¥Ñ¥é¥á¡¼¥¿¾ðÊó¤Î½é´ü²½
403function lfInitWebParam($objWebParam) {
404   
405    if(defined('ROOT_DIR')) {
406        $install_dir = ROOT_DIR;
407    } else {
408        $install_dir = realpath(dirname( __FILE__) . "/../") . "/";
409    }
410   
411    if(defined('SITE_URL')) {
412        $normal_url = SITE_URL;
413    } else {
414        $dir = ereg_replace("install/.*$", "", $_SERVER['REQUEST_URI']);
415        $normal_url = "http://" . $_SERVER['HTTP_HOST'] . $dir;
416    }
417   
418    if(defined('SSL_URL')) {
419        $secure_url = SSL_URL;
420    } else {
421        $dir = ereg_replace("install/.*$", "", $_SERVER['REQUEST_URI']);
422        $secure_url = "http://" . $_SERVER['HTTP_HOST'] . $dir;
423    }
424   
425    // Ź̾¡¢´ÉÍý¼Ô¥á¡¼¥ë¥¢¥É¥ì¥¹¤ò¼èÆÀ¤¹¤ë¡£(ºÆ¥¤¥ó¥¹¥È¡¼¥ë»þ)
426    if(defined('DEFAULT_DSN')) {
427        $objQuery = new SC_Query();
428        $arrRet = $objQuery->select("shop_name, email01", "dtb_baseinfo");
429        $shop_name = $arrRet[0]['shop_name'];
430        $admin_mail = $arrRet[0]['email01'];
431    }
432
433    $objWebParam->addParam("Ź̾", "shop_name", MTEXT_LEN, "", array("EXIST_CHECK","MAX_LENGTH_CHECK"), $shop_name);
434    $objWebParam->addParam("´ÉÍý¼Ô¥á¡¼¥ë¥¢¥É¥ì¥¹", "admin_mail", MTEXT_LEN, "", array("EXIST_CHECK","EMAIL_CHECK","EMAIL_CHAR_CHECK","MAX_LENGTH_CHECK"), $admin_mail);
435    $objWebParam->addParam("¥¤¥ó¥¹¥È¡¼¥ë¥Ç¥£¥ì¥¯¥È¥ê", "install_dir", MTEXT_LEN, "", array("EXIST_CHECK","MAX_LENGTH_CHECK"), $install_dir);
436    $objWebParam->addParam("URL(Ä̾ï)", "normal_url", MTEXT_LEN, "", array("EXIST_CHECK","URL_CHECK","MAX_LENGTH_CHECK"), $normal_url);
437    $objWebParam->addParam("URL(¥»¥­¥å¥¢)", "secure_url", MTEXT_LEN, "", array("EXIST_CHECK","URL_CHECK","MAX_LENGTH_CHECK"), $secure_url);
438    $objWebParam->addParam("¥É¥á¥¤¥ó", "domain", MTEXT_LEN, "", array("MAX_LENGTH_CHECK"));
439
440    return $objWebParam;
441}
442
443// DB¥Ñ¥é¥á¡¼¥¿¾ðÊó¤Î½é´ü²½
444function lfInitDBParam($objDBParam) {
445   
446    if(defined('DB_SERVER')) {
447        $db_server = DB_SERVER;
448    } else {
449        $db_server = "127.0.0.1";
450    }
451   
452    if(defined('DB_PORT')) {
453        $db_port = DB_PORT;
454    } else {
455        $db_port = "";
456    }
457       
458    if(defined('DB_NAME')) {
459        $db_name = DB_NAME;
460    } else {
461        $db_name = "eccube_db";
462    }
463       
464    if(defined('DB_USER')) {
465        $db_user = DB_USER;
466    } else {
467        $db_user = "eccube_db_user";               
468    }
469   
470    if(defined('DB_PASSWORD')) {
471        $db_password = DB_PASSWORD;
472    } else {
473        $db_password = "";             
474    }
475           
476    $objDBParam->addParam("DB¤Î¼ïÎà", "db_type", INT_LEN, "", array("EXIST_CHECK","MAX_LENGTH_CHECK"));
477    $objDBParam->addParam("DB¥µ¡¼¥Ð", "db_server", MTEXT_LEN, "", array("EXIST_CHECK","MAX_LENGTH_CHECK"), $db_server);
478    $objDBParam->addParam("DB¥Ý¡¼¥È", "db_port", INT_LEN, "", array("MAX_LENGTH_CHECK"), $db_port);
479    $objDBParam->addParam("DB̾", "db_name", MTEXT_LEN, "", array("EXIST_CHECK","MAX_LENGTH_CHECK"), $db_name);
480    $objDBParam->addParam("DB¥æ¡¼¥¶", "db_user", MTEXT_LEN, "", array("EXIST_CHECK","MAX_LENGTH_CHECK"), $db_user);
481    $objDBParam->addParam("DB¥Ñ¥¹¥ï¡¼¥É", "db_password", MTEXT_LEN, "", array("EXIST_CHECK","MAX_LENGTH_CHECK"), $db_password);
482       
483    return $objDBParam;
484}
485
486// ÆþÎÏÆâÍÆ¤Î¥Á¥§¥Ã¥¯
487function lfCheckWebError($objFormParam) {
488    // ÆþÎϥǡ¼¥¿¤òÅϤ¹¡£
489    $arrRet =  $objFormParam->getHashArray();
490    $objErr = new SC_CheckError($arrRet);
491    $objErr->arrErr = $objFormParam->checkError();
492   
493    // ¥Ç¥£¥ì¥¯¥È¥ê¤ÎÈæ³Ó
494    $normal_dir = ereg_replace("^https?://+($|[a-zA-Z0-9_~=&\?\.\-])+", "", $arrRet['normal_url']);
495   
496    print($normal_dir);
497   
498    $objErr->arrErr['normal_dir'] = $normal_dir;
499   
500    return $objErr->arrErr;
501}
502
503// ÆþÎÏÆâÍÆ¤Î¥Á¥§¥Ã¥¯
504function lfCheckDBError($objFormParam) {
505    // ÆþÎϥǡ¼¥¿¤òÅϤ¹¡£
506    $arrRet =  $objFormParam->getHashArray();
507   
508    $objErr = new SC_CheckError($arrRet);
509    $objErr->arrErr = $objFormParam->checkError();
510   
511    if(count($objErr->arrErr) == 0) {
512        // Àܳ³Îǧ
513        $dsn = $arrRet['db_type']."://".$arrRet['db_user'].":".$arrRet['db_password']."@".$arrRet['db_server'].":".$arrRet['db_port']."/".$arrRet['db_name'];
514        // Debug¥â¡¼¥É»ØÄê
515        $options['debug'] = 3;
516        $objDB = DB::connect($dsn, $options);
517        // Àܳ¥¨¥é¡¼
518        if(PEAR::isError($objDB)) {
519            $objErr->arrErr['all'] = ">> " . $objDB->message . "<br>";
520            // ¥¨¥é¡¼Ê¸¤ò¼èÆÀ¤¹¤ë
521            ereg("\[(.*)\]", $objDB->userinfo, $arrKey);
522            $objErr->arrErr['all'].= $arrKey[0] . "<br>";
523            gfPrintLog($objDB->userinfo, "./temp/install.log");
524        }
525    }
526    return $objErr->arrErr;
527}
528
529// SQLʸ¤Î¼Â¹Ô
530function lfExecuteSQL($filepath, $db_user, $db_password, $db_server, $db_name, $db_type, $db_port, $disp_err = true) {
531    $arrErr = array();
532
533    if(!file_exists($filepath)) {
534        $arrErr['all'] = ">> ¥¹¥¯¥ê¥×¥È¥Õ¥¡¥¤¥ë¤¬¸«¤Ä¤«¤ê¤Þ¤»¤ó";
535    } else {
536        if($fp = fopen($filepath,"r")) {
537            $sql = fread($fp, filesize($filepath));
538            fclose($fp);
539        }
540
541        $dsn = $db_type."://".$db_user.":".$db_password."@".$db_server.":".$db_port."/".$db_name;
542       
543        $objDB = DB::connect($dsn);
544        // Àܳ¥¨¥é¡¼
545        if(!PEAR::isError($objDB)) {
546            // ²þ¹Ô¡¢¥¿¥Ö¤ò1¥¹¥Ú¡¼¥¹¤ËÊÑ´¹
547            $sql = preg_replace("/[\r\n\t]/"," ",$sql);
548            $sql_split = split(";",$sql);
549            foreach($sql_split as $key => $val){
550                if (trim($val) != "") {
551                    $ret = $objDB->query($val);
552                    if(PEAR::isError($ret) and $disp_err) {
553                        $arrErr['all'] = ">> " . $ret->message . "<br>";
554                        // ¥¨¥é¡¼Ê¸¤ò¼èÆÀ¤¹¤ë
555                        ereg("\[(.*)\]", $ret->userinfo, $arrKey);
556                        $arrErr['all'].= $arrKey[0] . "<br>";
557                        $objPage->update_mess.=">> ¥Æ¡¼¥Ö¥ë¹½À®¤ÎÊѹ¹¤Ë¼ºÇÔ¤·¤Þ¤·¤¿¡£<br>";
558                        gfPrintLog($ret->userinfo, "./temp/install.log");
559                    }
560                }
561            }
562           
563        } else {
564            $arrErr['all'] = ">> " . $objDB->message;
565            gfPrintLog($objDB->userinfo, "./temp/install.log");
566        }
567    }
568    return $arrErr;
569}
570
571// ÀßÄê¥Õ¥¡¥¤¥ë¤ÎºîÀ®
572function lfMakeConfigFile() {
573    global $objWebParam;
574    global $objDBParam;
575    global $port;
576       
577    $root_dir = $objWebParam->getValue('install_dir');
578    // ¸ìÈø¤Ë'/'¤ò¤Ä¤±¤ë
579    if (!ereg("/$", $root_dir)) {
580        $root_dir = $root_dir . "/";
581    }
582   
583    $filepath = $objWebParam->getValue('install_dir') . "../data/install.inc";
584   
585    $config_data =
586    "<?php\n".
587    "    define ('ECCUBE_INSTALL', 'ON');\n" .
588    "    define ('ROOT_DIR', '" . $root_dir . "');\n" .
589    "    define ('SITE_URL', '" . $objWebParam->getValue('normal_url') . "');\n" .
590    "    define ('SSL_URL', '" . $objWebParam->getValue('secure_url') . "');\n" .
591    "    define ('DOMAIN_NAME', '" . $objWebParam->getValue('domain') . "');\n" .
592    "    define ('DB_TYPE', '" . $objDBParam->getValue('db_type') . "');\n" .
593    "    define ('DB_USER', '" . $objDBParam->getValue('db_user') . "');\n" .
594    "    define ('DB_PASSWORD', '" . $objDBParam->getValue('db_password') . "');\n" .
595    "    define ('DB_SERVER', '" . $objDBParam->getValue('db_server') . "');\n" .
596    "    define ('DB_NAME', '" . $objDBParam->getValue('db_name') . "');\n" .
597    "    define ('DB_PORT', '" . $objDBParam->getValue('db_port') .  "');\n" .
598    "?>";
599   
600    if($fp = fopen($filepath,"w")) {
601        fwrite($fp, $config_data);
602        fclose($fp);
603    }
604}
605
606?>
Note: See TracBrowser for help on using the repository browser.