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

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