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

Revision 6879, 20.4 KB checked in by kakinaka, 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    $dsn = $arrRet['db_type']."://".$arrRet['db_user'].":".$arrRet['db_password']."@".$arrRet['db_server'].":".$arrRet['db_port']."/".$arrRet['db_name'];
85   
86    /*
87        lfAddTable¤Ï¡¢¥Ð¡¼¥¸¥ç¥ó¥¢¥Ã¥×Åù¤ÇÄɲåơ¼¥Ö¥ë¤¬È¯À¸¤·¤¿¾ì¹ç¤Ë¼Â¹Ô¤¹¤ë¡£
88        ¡Ê£Ä£Â¹½À®¤Î²¼°Ì¸ß´¹¤Î¤¿¤á¥¹¥­¥Ã¥×»þ¤â¶¯À©¡Ë
89    */
90    // ¥Æ¡¼¥Ö¥ë¤¬Â¸ºß¤·¤Ê¤¤¾ì¹ç¤ËÄɲ䵤ì¤ë¡£
91    $objPage->arrErr = lfAddTable("dtb_session", $dsn); // ¥»¥Ã¥·¥ç¥ó´ÉÍý¥Æ¡¼¥Ö¥ë
92       
93    if(count($objPage->arrErr) == 0) {
94        // ¥¹¥­¥Ã¥×¤¹¤ë¾ì¹ç¤Ë¤Ï¼¡²èÌ̤ØÁ«°Ü
95        $skip = $_POST["db_skip"];
96        if ($skip == "on") {
97            // ÀßÄê¥Õ¥¡¥¤¥ë¤ÎÀ¸À®
98            lfMakeConfigFile();
99            //$objPage = lfDispComplete($objPage);
100            $objPage = lfDispStep4($objPage);
101            break;
102        }
103    }
104   
105    // ¥Æ¡¼¥Ö¥ë¤ÎºîÀ®
106    $objPage->arrErr = lfExecuteSQL("./sql/create_table_".$arrRet['db_type'].".sql", $dsn);
107    if(count($objPage->arrErr) == 0) {
108        $objPage->tpl_message.="¡û¡§¥Æ¡¼¥Ö¥ë¤ÎºîÀ®¤ËÀ®¸ù¤·¤Þ¤·¤¿¡£<br>";
109    } else {
110        $objPage->tpl_message.="¡ß¡§¥Æ¡¼¥Ö¥ë¤ÎºîÀ®¤Ë¼ºÇÔ¤·¤Þ¤·¤¿¡£<br>";       
111    }
112
113    // ¥Ó¥å¡¼¤ÎºîÀ®
114    if(count($objPage->arrErr) == 0 and $arrRet['db_type'] == 'pgsql') {
115        // ¥Ó¥å¡¼¤ÎºîÀ®
116        $objPage->arrErr = lfExecuteSQL("./sql/create_view.sql", $dsn);
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("./sql/insert_data.sql", $dsn);
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("./sql/column_comment.sql", $dsn);
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        $objPage->arrErr = lfExecuteSQL("./sql/table_comment.sql", $dsn);
147        if(count($objPage->arrErr) == 0) {
148            $objPage->tpl_message.="¡û¡§¥Æ¡¼¥Ö¥ë¥³¥á¥ó¥È¤Î½ñ¹þ¤ß¤ËÀ®¸ù¤·¤Þ¤·¤¿¡£<br>";
149        } else {
150            $objPage->tpl_message.="¡ß¡§¥Æ¡¼¥Ö¥ë¥³¥á¥ó¥È¤Î½ñ¹þ¤ß¤Ë¼ºÇÔ¤·¤Þ¤·¤¿¡£<br>";     
151        }
152    }
153
154    if(count($objPage->arrErr) == 0) {
155        // ÀßÄê¥Õ¥¡¥¤¥ë¤ÎÀ¸À®
156        lfMakeConfigFile();
157        $objPage = lfDispStep3($objPage);
158        $objPage->tpl_mode = 'step4';
159    } else {
160        $objPage = lfDispStep3($objPage);
161    }
162    break;
163case 'step4':
164    $objPage = lfDispStep4($objPage);
165    break;
166   
167// ¥Æ¡¼¥Ö¥ëÎàºï½ü
168case 'drop':
169    // ÆþÎϥǡ¼¥¿¤òÅϤ¹¡£
170    $arrRet =  $objDBParam->getHashArray();
171    $dsn = $arrRet['db_type']."://".$arrRet['db_user'].":".$arrRet['db_password']."@".$arrRet['db_server'].":".$arrRet['db_port']."/".$arrRet['db_name'];
172       
173    if ($arrRet['db_type'] == 'pgsql'){
174        // ¥Ó¥å¡¼¤Îºï½ü
175        $objPage->arrErr = lfExecuteSQL("./sql/drop_view.sql", $dsn, false);
176        if(count($objPage->arrErr) == 0) {
177            $objPage->tpl_message.="¡û¡§¥Ó¥å¡¼¤Îºï½ü¤ËÀ®¸ù¤·¤Þ¤·¤¿¡£<br>";
178        } else {
179            $objPage->tpl_message.="¡ß¡§¥Ó¥å¡¼¤Îºï½ü¤Ë¼ºÇÔ¤·¤Þ¤·¤¿¡£<br>";     
180        }
181    }
182
183    // ¥Æ¡¼¥Ö¥ë¤Îºï½ü
184    if(count($objPage->arrErr) == 0) {
185        $objPage->arrErr = lfExecuteSQL("./sql/drop_table.sql", $dsn, false);
186        if(count($objPage->arrErr) == 0) {
187            $objPage->tpl_message.="¡û¡§¥Æ¡¼¥Ö¥ë¤Îºï½ü¤ËÀ®¸ù¤·¤Þ¤·¤¿¡£<br>";
188        } else {
189            $objPage->tpl_message.="¡ß¡§¥Æ¡¼¥Ö¥ë¤Îºï½ü¤Ë¼ºÇÔ¤·¤Þ¤·¤¿¡£<br>";       
190        }
191    }
192    $objPage = lfDispStep3($objPage);
193    break;
194// ´°Î»²èÌÌ
195case 'complete':
196
197    // ¥·¥ç¥Ã¥×¥Þ¥¹¥¿¾ðÊó¤Î½ñ¤­¹þ¤ß
198    $arrRet =  $objDBParam->getHashArray();
199   
200    $dsn = $arrRet['db_type']."://".$arrRet['db_user'].":".$arrRet['db_password']."@".$arrRet['db_server'].":".$arrRet['db_port']."/".$arrRet['db_name'];
201    $sqlval['shop_name'] = $objWebParam->getValue('shop_name');
202    $sqlval['email01'] = $objWebParam->getValue('admin_mail');
203    $sqlval['email02'] = $objWebParam->getValue('admin_mail');
204    $sqlval['email03'] = $objWebParam->getValue('admin_mail');
205    $sqlval['email04'] = $objWebParam->getValue('admin_mail');
206    $sqlval['email05'] = $objWebParam->getValue('admin_mail');
207    $sqlval['top_tpl'] = "default1";
208    $sqlval['product_tpl'] = "default1";
209    $sqlval['detail_tpl'] = "default1";
210    $sqlval['mypage_tpl'] = "default1";
211    $objQuery = new SC_Query($dsn);
212    $cnt = $objQuery->count("dtb_baseinfo");
213    if($cnt > 0) {
214        $objQuery->update("dtb_baseinfo", $sqlval);
215    } else {       
216        $objQuery->insert("dtb_baseinfo", $sqlval);     
217    }
218    global $GLOBAL_ERR;
219    $GLOBAL_ERR = "";
220    $objPage = lfDispComplete($objPage);
221    break;
222case 'return_step0':
223    $objPage = lfDispStep0($objPage);
224    break; 
225case 'return_step1':
226    $objPage = lfDispStep1($objPage);
227    break;
228case 'return_step2':
229    $objPage = lfDispStep2($objPage);
230    break;
231case 'return_step3':
232    $objPage = lfDispStep3($objPage);
233    break;
234case 'return_welcome':
235default:
236    $objPage = lfDispWelcome($objPage);
237    break;
238}
239
240//¥Õ¥©¡¼¥àÍѤΥѥé¥á¡¼¥¿¤òÊÖ¤¹
241$objPage->arrForm = $objWebParam->getFormParamList();
242$objPage->arrForm = array_merge($objPage->arrForm, $objDBParam->getFormParamList());
243
244// SiteInfo¤òÆÉ¤ß¹þ¤Þ¤Ê¤¤
245$objView->assignobj($objPage);
246$objView->display('install_frame.tpl');
247//-----------------------------------------------------------------------------------------------------------------------------------
248// ¤è¤¦¤³¤½²èÌ̤Îɽ¼¨
249function lfDispWelcome($objPage) {
250    global $objWebParam;
251    global $objDBParam;
252    // hidden¤ËÆþÎÏÃͤòÊÝ»ý
253    $objPage->arrHidden = $objWebParam->getHashArray();
254    // hidden¤ËÆþÎÏÃͤòÊÝ»ý
255    $objPage->arrHidden = array_merge($objPage->arrHidden, $objDBParam->getHashArray());
256    $objPage->arrHidden['db_skip'] = $_POST['db_skip'];
257    $objPage->tpl_mainpage = 'welcome.tpl';
258    $objPage->tpl_mode = 'welcome';
259    return $objPage;
260}
261
262// STEP0²èÌ̤Îɽ¼¨(¥Õ¥¡¥¤¥ë¸¢¸Â¥Á¥§¥Ã¥¯)
263function lfDispStep0($objPage) {
264    global $objWebParam;
265    global $objDBParam;
266    // hidden¤ËÆþÎÏÃͤòÊÝ»ý
267    $objPage->arrHidden = $objWebParam->getHashArray();
268    // hidden¤ËÆþÎÏÃͤòÊÝ»ý
269    $objPage->arrHidden = array_merge($objPage->arrHidden, $objDBParam->getHashArray());
270    $objPage->arrHidden['db_skip'] = $_POST['db_skip'];
271    $objPage->tpl_mainpage = 'step0.tpl';
272    $objPage->tpl_mode = 'step0';
273   
274    // ¥×¥í¥°¥é¥à¤Ç½ñ¹þ¤ß¤µ¤ì¤ë¥Õ¥¡¥¤¥ë¡¦¥Ç¥£¥ì¥¯¥È¥ê
275    $arrWriteFile = array(
276        "../../data/install.inc",
277        "../user_data",
278        "../upload",
279        "../../data/Smarty/templates_c",       
280        "../../data/logs",
281    );
282   
283    $mess = "";
284    $err_file = false;
285    foreach($arrWriteFile as $val) {
286        if(file_exists($val)) {
287            $mode = lfGetFileMode($val);
288            $real_path = realpath($val);
289                       
290            // ¥Ç¥£¥ì¥¯¥È¥ê¤Î¾ì¹ç
291            if(is_dir($val)) {
292                if($mode == "777") {
293                    $mess.= ">> ¡û¡§$real_path($mode) <br>¥¢¥¯¥»¥¹¸¢¸Â¤ÏÀµ¾ï¤Ç¤¹¡£<br>";                   
294                } else {
295                    $mess.= ">> ¡ß¡§$real_path($mode) <br>¥æ¡¼¥¶½ñ¹þ¤ß¸¢¸Â(777)¤òÉÕÍ¿¤·¤Æ²¼¤µ¤¤¡£<br>";
296                    $err_file = true;                                       
297                }
298            } else {
299                if($mode == "666") {
300                    $mess.= ">> ¡û¡§$real_path($mode) <br>¥¢¥¯¥»¥¹¸¢¸Â¤ÏÀµ¾ï¤Ç¤¹¡£<br>";                   
301                } else {
302                    $mess.= ">> ¡ß¡§$real_path($mode) <br>¥æ¡¼¥¶½ñ¹þ¤ß¸¢¸Â(666)¤òÉÕÍ¿¤·¤Æ²¼¤µ¤¤¡£<br>";
303                    $err_file = true;                           
304                }
305            }           
306        } else {
307            $mess.= ">> ¡ß¡§$val ¤¬¸«¤Ä¤«¤ê¤Þ¤»¤ó¡£<br>";
308            $err_file = true;
309        }
310    }
311   
312    // ¸¢¸Â¥¨¥é¡¼Åù¤¬È¯À¸¤·¤Æ¤¤¤Ê¤¤¾ì¹ç
313    if(!$err_file) {
314        $path = "../../data/Smarty/templates_c/admin";
315        if(!file_exists($path)) {
316            mkdir($path);
317        }
318        $path = "../upload/save_image";
319        if(!file_exists($path)) {
320            mkdir($path);
321        }
322        $path = "../upload/temp_image";
323        if(!file_exists($path)) {
324            mkdir($path);
325        }
326        $path = "../upload/graph_image";
327        if(!file_exists($path)) {
328            mkdir($path);
329        }
330        $path = "../upload/csv";
331        if(!file_exists($path)) {
332            mkdir($path);
333        }
334    }
335   
336    $objPage->mess = $mess;
337    $objPage->err_file = $err_file;
338
339    return $objPage;
340}
341
342
343// STEP0_1²èÌ̤Îɽ¼¨(¥Õ¥¡¥¤¥ë¤Î¥³¥Ô¡¼)
344function lfDispStep0_1($objPage) {
345    global $objWebParam;
346    global $objDBParam;
347    // hidden¤ËÆþÎÏÃͤòÊÝ»ý
348    $objPage->arrHidden = $objWebParam->getHashArray();
349    // hidden¤ËÆþÎÏÃͤòÊÝ»ý
350    $objPage->arrHidden = array_merge($objPage->arrHidden, $objDBParam->getHashArray());
351    $objPage->arrHidden['db_skip'] = $_POST['db_skip'];
352    $objPage->tpl_mainpage = 'step0_1.tpl';
353    $objPage->tpl_mode = 'step0_1';
354    // ¥Õ¥¡¥¤¥ë¥³¥Ô¡¼
355    $objPage->copy_mess = sfCopyDir("./user_data/", "../user_data/", $objPage->copy_mess);
356    $objPage->copy_mess = sfCopyDir("./save_image/", "../upload/save_image/", $objPage->copy_mess);
357    return $objPage;
358}
359
360function lfGetFileMode($path) {
361    $mode = substr(sprintf('%o', fileperms($path)), -3);
362    return $mode;
363}
364
365// STEP1²èÌ̤Îɽ¼¨
366function lfDispStep1($objPage) {
367    global $objDBParam;
368    // hidden¤ËÆþÎÏÃͤòÊÝ»ý
369    $objPage->arrHidden = $objDBParam->getHashArray();
370    $objPage->arrHidden['db_skip'] = $_POST['db_skip'];
371    $objPage->tpl_mainpage = 'step1.tpl';
372    $objPage->tpl_mode = 'step1';
373    return $objPage;
374}
375
376// STEP2²èÌ̤Îɽ¼¨
377function lfDispStep2($objPage) {
378    global $objWebParam;
379    global $objDBParam;
380    // hidden¤ËÆþÎÏÃͤòÊÝ»ý
381    $objPage->arrHidden = $objWebParam->getHashArray();
382    $objPage->arrHidden['db_skip'] = $_POST['db_skip'];
383    $objPage->tpl_mainpage = 'step2.tpl';
384    $objPage->tpl_mode = 'step2';
385    return $objPage;
386}
387
388// STEP3²èÌ̤Îɽ¼¨
389function lfDispStep3($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->tpl_db_skip = $_POST['db_skip'];
397    $objPage->tpl_mainpage = 'step3.tpl';
398    $objPage->tpl_mode = 'step3';
399    return $objPage;
400}
401
402// STEP4²èÌ̤Îɽ¼¨
403function lfDispStep4($objPage) {
404    global $objWebParam;
405    global $objDBParam;
406    // hidden¤ËÆþÎÏÃͤòÊÝ»ý
407    $objPage->arrHidden = $objWebParam->getHashArray();
408    $objPage->arrHidden = array_merge($objPage->arrHidden, $objDBParam->getHashArray());
409    // hidden¤ËÆþÎÏÃͤòÊÝ»ý
410   
411    $normal_url = $objWebParam->getValue('normal_url');
412    // ¸ìÈø¤Ë'/'¤ò¤Ä¤±¤ë
413    if (!ereg("/$", $normal_url)) $normal_url = $normal_url . "/";
414   
415    $arrDbParam = $objDBParam->getHashArray();
416    $dsn = $arrDbParam['db_type']."://".$arrDbParam['db_user'].":".$arrDbParam['db_password']."@".$arrDbParam['db_server'].":".$arrDbParam['db_port']."/".$arrDbParam['db_name'];
417   
418    $objPage->tpl_site_url = $normal_url;
419    $objPage->tpl_shop_name = $objWebParam->getValue('shop_name');
420    $objPage->tpl_cube_ver = ECCUBE_VERSION;
421    $objPage->tpl_php_ver = phpversion();
422    $objPage->tpl_db_ver = sfGetDBVersion($dsn);
423    $objPage->tpl_db_skip = $_POST['db_skip'];
424    $objPage->tpl_mainpage = 'step4.tpl';
425    $objPage->tpl_mode = 'complete';
426    return $objPage;
427}
428
429// ´°Î»²èÌ̤Îɽ¼¨
430function lfDispComplete($objPage) {
431    global $objWebParam;
432    global $objDBParam;
433    // hidden¤ËÆþÎÏÃͤòÊÝ»ý
434    $objPage->arrHidden = $objWebParam->getHashArray();
435    // hidden¤ËÆþÎÏÃͤòÊÝ»ý
436    $objPage->arrHidden = array_merge($objPage->arrHidden, $objDBParam->getHashArray());
437    $objPage->arrHidden['db_skip'] = $_POST['db_skip'];
438    $objPage->tpl_mainpage = 'complete.tpl';
439    $objPage->tpl_mode = 'complete';
440   
441    $secure_url = $objWebParam->getValue('secure_url');
442    // ¸ìÈø¤Ë'/'¤ò¤Ä¤±¤ë
443    if (!ereg("/$", $secure_url)) {
444        $secure_url = $secure_url . "/";
445    }
446    $objPage->tpl_sslurl = $secure_url;     
447    return $objPage;
448}
449
450// WEB¥Ñ¥é¥á¡¼¥¿¾ðÊó¤Î½é´ü²½
451function lfInitWebParam($objWebParam) {
452   
453    if(defined('HTML_PATH')) {
454        $install_dir = HTML_PATH;
455    } else {
456        $install_dir = realpath(dirname( __FILE__) . "/../") . "/";
457    }
458   
459    if(defined('SITE_URL')) {
460        $normal_url = SITE_URL;
461    } else {
462        $dir = ereg_replace("install/.*$", "", $_SERVER['REQUEST_URI']);
463        $normal_url = "http://" . $_SERVER['HTTP_HOST'] . $dir;
464    }
465   
466    if(defined('SSL_URL')) {
467        $secure_url = SSL_URL;
468    } else {
469        $dir = ereg_replace("install/.*$", "", $_SERVER['REQUEST_URI']);
470        $secure_url = "http://" . $_SERVER['HTTP_HOST'] . $dir;
471    }
472
473    // Ź̾¡¢´ÉÍý¼Ô¥á¡¼¥ë¥¢¥É¥ì¥¹¤ò¼èÆÀ¤¹¤ë¡£(ºÆ¥¤¥ó¥¹¥È¡¼¥ë»þ)
474    if(defined('DEFAULT_DSN')) {
475        $ret = sfTabaleExists("dtb_baseinfo", DEFAULT_DSN);
476        if($ret) {
477            $objQuery = new SC_Query();
478            $arrRet = $objQuery->select("shop_name, email01", "dtb_baseinfo");
479            $shop_name = $arrRet[0]['shop_name'];
480            $admin_mail = $arrRet[0]['email01'];
481        }
482    }
483
484    $objWebParam->addParam("Ź̾", "shop_name", MTEXT_LEN, "", array("EXIST_CHECK","MAX_LENGTH_CHECK"), $shop_name);
485    $objWebParam->addParam("´ÉÍý¼Ô¥á¡¼¥ë¥¢¥É¥ì¥¹", "admin_mail", MTEXT_LEN, "", array("EXIST_CHECK","EMAIL_CHECK","EMAIL_CHAR_CHECK","MAX_LENGTH_CHECK"), $admin_mail);
486    $objWebParam->addParam("¥¤¥ó¥¹¥È¡¼¥ë¥Ç¥£¥ì¥¯¥È¥ê", "install_dir", MTEXT_LEN, "", array("EXIST_CHECK","MAX_LENGTH_CHECK"), $install_dir);
487    $objWebParam->addParam("URL(Ä̾ï)", "normal_url", MTEXT_LEN, "", array("EXIST_CHECK","URL_CHECK","MAX_LENGTH_CHECK"), $normal_url);
488    $objWebParam->addParam("URL(¥»¥­¥å¥¢)", "secure_url", MTEXT_LEN, "", array("EXIST_CHECK","URL_CHECK","MAX_LENGTH_CHECK"), $secure_url);
489    $objWebParam->addParam("¥É¥á¥¤¥ó", "domain", MTEXT_LEN, "", array("MAX_LENGTH_CHECK"));
490
491    return $objWebParam;
492}
493
494// DB¥Ñ¥é¥á¡¼¥¿¾ðÊó¤Î½é´ü²½
495function lfInitDBParam($objDBParam) {
496       
497    if(defined('DB_SERVER')) {
498        $db_server = DB_SERVER;
499    } else {
500        $db_server = "127.0.0.1";
501    }
502   
503    if(defined('DB_TYPE')) {
504        $db_type = DB_TYPE;
505    } else {
506        $db_type = "";
507    }
508   
509    if(defined('DB_PORT')) {
510        $db_port = DB_PORT;
511    } else {
512        $db_port = "";
513    }
514       
515    if(defined('DB_NAME')) {
516        $db_name = DB_NAME;
517    } else {
518        $db_name = "eccube_db";
519    }
520       
521    if(defined('DB_USER')) {
522        $db_user = DB_USER;
523    } else {
524        $db_user = "eccube_db_user";               
525    }
526           
527    $objDBParam->addParam("DB¤Î¼ïÎà", "db_type", INT_LEN, "", array("EXIST_CHECK","MAX_LENGTH_CHECK"), $db_type);
528    $objDBParam->addParam("DB¥µ¡¼¥Ð", "db_server", MTEXT_LEN, "", array("EXIST_CHECK","MAX_LENGTH_CHECK"), $db_server);
529    $objDBParam->addParam("DB¥Ý¡¼¥È", "db_port", INT_LEN, "", array("MAX_LENGTH_CHECK"), $db_port);
530    $objDBParam->addParam("DB̾", "db_name", MTEXT_LEN, "", array("EXIST_CHECK","MAX_LENGTH_CHECK"), $db_name);
531    $objDBParam->addParam("DB¥æ¡¼¥¶", "db_user", MTEXT_LEN, "", array("EXIST_CHECK","MAX_LENGTH_CHECK"), $db_user);
532    $objDBParam->addParam("DB¥Ñ¥¹¥ï¡¼¥É", "db_password", MTEXT_LEN, "", array("EXIST_CHECK","MAX_LENGTH_CHECK"));   
533       
534    return $objDBParam;
535}
536
537// ÆþÎÏÆâÍÆ¤Î¥Á¥§¥Ã¥¯
538function lfCheckWebError($objFormParam) {
539    // ÆþÎϥǡ¼¥¿¤òÅϤ¹¡£
540    $arrRet =  $objFormParam->getHashArray();
541    $objErr = new SC_CheckError($arrRet);
542    $objErr->arrErr = $objFormParam->checkError();
543   
544    // ¥Ç¥£¥ì¥¯¥È¥ê̾¤Î¤ß¼èÆÀ¤¹¤ë
545    $normal_dir = ereg_replace("^https?://[a-zA-Z0-9_~=&\?\.\-]+", "", $arrRet['normal_url']);
546    $secure_dir = ereg_replace("^https?://[a-zA-Z0-9_~=&\?\.\-]+", "", $arrRet['secure_url']);
547   
548    if($normal_dir != $secure_dir) {
549        $objErr->arrErr['normal_url'] = "URL¤Ë°Û¤Ê¤ë³¬Áؤò»ØÄꤹ¤ë¤³¤È¤Ï¤Ç¤­¤Þ¤»¤ó¡£";
550        $objErr->arrErr['secure_url'] = "URL¤Ë°Û¤Ê¤ë³¬Áؤò»ØÄꤹ¤ë¤³¤È¤Ï¤Ç¤­¤Þ¤»¤ó¡£";     
551    }
552   
553    return $objErr->arrErr;
554}
555
556// ÆþÎÏÆâÍÆ¤Î¥Á¥§¥Ã¥¯
557function lfCheckDBError($objFormParam) {
558    global $objPage;
559   
560    // ÆþÎϥǡ¼¥¿¤òÅϤ¹¡£
561    $arrRet =  $objFormParam->getHashArray();
562   
563    $objErr = new SC_CheckError($arrRet);
564    $objErr->arrErr = $objFormParam->checkError();
565   
566    if(count($objErr->arrErr) == 0) {
567        // Àܳ³Îǧ
568        $dsn = $arrRet['db_type']."://".$arrRet['db_user'].":".$arrRet['db_password']."@".$arrRet['db_server'].":".$arrRet['db_port']."/".$arrRet['db_name'];
569        // Debug¥â¡¼¥É»ØÄê
570        $options['debug'] = PEAR_DB_DEBUG;
571        $objDB = DB::connect($dsn, $options);
572        // ÀܳÀ®¸ù
573        if(!PEAR::isError($objDB)) {
574            // ¥Ç¡¼¥¿¥Ù¡¼¥¹¥Ð¡¼¥¸¥ç¥ó¾ðÊó¤Î¼èÆÀ
575            $objPage->tpl_db_version = sfGetDBVersion($dsn);           
576        } else {
577            $objErr->arrErr['all'] = ">> " . $objDB->message . "<br>";
578            // ¥¨¥é¡¼Ê¸¤ò¼èÆÀ¤¹¤ë
579            ereg("\[(.*)\]", $objDB->userinfo, $arrKey);
580            $objErr->arrErr['all'].= $arrKey[0] . "<br>";
581            gfPrintLog($objDB->userinfo, "./temp/install.log");
582        }
583    }
584    return $objErr->arrErr;
585}
586
587// SQLʸ¤Î¼Â¹Ô
588function lfExecuteSQL($filepath, $dsn, $disp_err = true) {
589    $arrErr = array();
590   
591    if(!file_exists($filepath)) {
592        $arrErr['all'] = ">> ¥¹¥¯¥ê¥×¥È¥Õ¥¡¥¤¥ë¤¬¸«¤Ä¤«¤ê¤Þ¤»¤ó";
593    } else {
594        if($fp = fopen($filepath,"r")) {
595            $sql = fread($fp, filesize($filepath));
596            fclose($fp);
597        }
598        // Debug¥â¡¼¥É»ØÄê
599        $options['debug'] = PEAR_DB_DEBUG;
600        $objDB = DB::connect($dsn, $options);
601        // Àܳ¥¨¥é¡¼
602        if(!PEAR::isError($objDB)) {
603            // ²þ¹Ô¡¢¥¿¥Ö¤ò1¥¹¥Ú¡¼¥¹¤ËÊÑ´¹
604            $sql = preg_replace("/[\r\n\t]/"," ",$sql);
605            $sql_split = split(";",$sql);
606            foreach($sql_split as $key => $val){
607                if (trim($val) != "") {
608                    $ret = $objDB->query($val);
609                    if(PEAR::isError($ret) && $disp_err) {
610                        $arrErr['all'] = ">> " . $ret->message . "<br>";
611                        // ¥¨¥é¡¼Ê¸¤ò¼èÆÀ¤¹¤ë
612                        ereg("\[(.*)\]", $ret->userinfo, $arrKey);
613                        $arrErr['all'].= $arrKey[0] . "<br>";
614                        $objPage->update_mess.=">> ¥Æ¡¼¥Ö¥ë¹½À®¤ÎÊѹ¹¤Ë¼ºÇÔ¤·¤Þ¤·¤¿¡£<br>";
615                        gfPrintLog($ret->userinfo, "./temp/install.log");
616                    }
617                }
618            }           
619        } else {
620            $arrErr['all'] = ">> " . $objDB->message;
621            gfPrintLog($objDB->userinfo, "./temp/install.log");
622        }
623    }
624    return $arrErr;
625}
626
627// ÀßÄê¥Õ¥¡¥¤¥ë¤ÎºîÀ®
628function lfMakeConfigFile() {
629    global $objWebParam;
630    global $objDBParam;
631       
632    $root_dir = $objWebParam->getValue('install_dir');
633    // ¸ìÈø¤Ë'/'¤ò¤Ä¤±¤ë
634    if (!ereg("/$", $root_dir)) {
635        $root_dir = $root_dir . "/";
636    }
637   
638    $normal_url = $objWebParam->getValue('normal_url');
639    // ¸ìÈø¤Ë'/'¤ò¤Ä¤±¤ë
640    if (!ereg("/$", $normal_url)) {
641        $normal_url = $normal_url . "/";
642    }
643   
644    $secure_url = $objWebParam->getValue('secure_url');
645    // ¸ìÈø¤Ë'/'¤ò¤Ä¤±¤ë
646    if (!ereg("/$", $secure_url)) {
647        $secure_url = $secure_url . "/";
648    }
649   
650    // ¥Ç¥£¥ì¥¯¥È¥ê¤Î¼èÆÀ
651    $url_dir = ereg_replace("^https?://[a-zA-Z0-9_~=&\?\.\-]+", "", $normal_url);
652   
653    $data_path = $root_dir . "../data/";
654    $filepath = $data_path . "install.inc";
655   
656    $config_data =
657    "<?php\n".
658    "    define ('ECCUBE_INSTALL', 'ON');\n" .
659    "    define ('HTML_PATH', '" . $root_dir . "');\n" .     
660    "    define ('SITE_URL', '" . $normal_url . "');\n" .
661    "    define ('SSL_URL', '" . $secure_url . "');\n" .
662    "    define ('URL_DIR', '" . $url_dir . "');\n" .   
663    "    define ('DOMAIN_NAME', '" . $objWebParam->getValue('domain') . "');\n" .
664    "    define ('DB_TYPE', '" . $objDBParam->getValue('db_type') . "');\n" .
665    "    define ('DB_USER', '" . $objDBParam->getValue('db_user') . "');\n" .
666    "    define ('DB_PASSWORD', '" . $objDBParam->getValue('db_password') . "');\n" .
667    "    define ('DB_SERVER', '" . $objDBParam->getValue('db_server') . "');\n" .
668    "    define ('DB_NAME', '" . $objDBParam->getValue('db_name') . "');\n" .
669    "    define ('DB_PORT', '" . $objDBParam->getValue('db_port') .  "');\n" .
670    "    define ('DATA_PATH', '".$data_path."');\n" .
671    "?>";
672   
673    if($fp = fopen($filepath,"w")) {
674        fwrite($fp, $config_data);
675        fclose($fp);
676    }
677}
678
679// ¥Æ¡¼¥Ö¥ë¤ÎÄɲáʴû¤Ë¥Æ¡¼¥Ö¥ë¤¬Â¸ºß¤¹¤ë¾ì¹ç¤ÏºîÀ®¤·¤Ê¤¤¡Ë
680function lfAddTable($table_name, $dsn) {
681    $arrErr = array();
682    if(!sfTabaleExists($table_name, $dsn)) {
683        list($db_type) = split(":", $dsn);
684        $sql_path = "./sql/add/". $table_name . "_" .$db_type .".sql";
685        $arrErr = lfExecuteSQL($sql_path, $dsn);
686    }
687    return $arrErr;
688}
689?>
Note: See TracBrowser for help on using the repository browser.