source: branches/version-2_5-dev/html/install/index.php @ 19802

Revision 19802, 35.1 KB checked in by Seasoft, 13 years ago (diff)

#834(パラメータの定数名に「URL」を含むにもかかわらず、パスのみのものがある) 一部改修

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Id
  • Property svn:mime-type set to text/x-httpd-php; charset=UTF-8
Line 
1<?php
2/*
3 * This file is part of EC-CUBE
4 *
5 * Copyright(c) 2000-2010 LOCKON CO.,LTD. All Rights Reserved.
6 *
7 * http://www.lockon.co.jp/
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22 */
23// ▼require.php 相当
24// rtrim は PHP バージョン依存対策
25define('HTML_FILE_PATH', rtrim(realpath(rtrim(realpath(dirname(__FILE__)), '/\\') . '/../'), '/\\') . '/');
26
27require_once HTML_FILE_PATH . 'define.php';
28define('INSTALL_FUNCTION', true);
29require_once HTML_FILE_PATH . HTML2DATA_DIR . 'require_base.php';
30// ▲require.php 相当
31
32$INSTALL_DIR = realpath(dirname( __FILE__));
33require_once(DATA_FILE_PATH . "module/Request.php");
34
35define("INSTALL_LOG", "./temp/install.log");
36ini_set("max_execution_time", 300);
37
38$objPage = new StdClass;
39$objPage->arrDB_TYPE = array(
40    'pgsql' => 'PostgreSQL',
41    'mysql' => 'MySQL'
42);
43$objPage->arrDB_PORT = array(
44    'pgsql' => '',
45    'mysql' => ''
46);
47
48$objDb = new SC_Helper_DB_Ex();
49
50// テンプレートコンパイルディレクトリの書込み権限チェック
51$temp_dir = $INSTALL_DIR . '/temp';
52
53if(!is_writable($temp_dir)) {
54    SC_Utils_Ex::sfErrorHeader($temp_dir . "にユーザ書込み権限(777, 707等)を付与して下さい。", true);
55    exit;
56}
57
58$objView = new SC_InstallView($INSTALL_DIR . '/templates', $INSTALL_DIR . '/temp');
59
60// パラメータ管理クラス
61$objWebParam = new SC_FormParam();
62$objDBParam = new SC_FormParam();
63// パラメータ情報の初期化
64$objWebParam = lfInitWebParam($objWebParam);
65$objDBParam = lfInitDBParam($objDBParam);
66
67//フォーム配列の取得
68$objWebParam->setParam($_POST);
69$objDBParam->setParam($_POST);
70
71$mode = isset($_POST['mode_overwrite']) ? $_POST['mode_overwrite'] : $_POST['mode'];
72
73switch($mode) {
74// ようこそ
75case 'welcome':
76    //$objPage = lfDispAgreement($objPage);
77    $objPage = lfDispStep0($objPage);
78    //$objPage->tpl_onload .= "fnChangeVisible('agreement_yes', 'next');";
79    break;
80
81/* 現在保留中
82
83// 使用許諾契約書の同意
84case 'agreement':
85    $objPage = lfDispStep0($objPage);
86    break;
87*/
88
89// アクセス権限のチェック
90case 'step0':
91    $objPage = lfDispStep0_1($objPage);
92    break;
93// ファイルのコピー
94case 'step0_1':
95    $objPage = lfDispStep1($objPage);
96    break;
97// WEBサイトの設定
98case 'step1':
99    //入力値のエラーチェック
100    $objPage->arrErr = lfCheckWEBError($objWebParam);
101    if(count($objPage->arrErr) == 0) {
102        $objPage = lfDispStep2($objPage);
103    } else {
104        $objPage = lfDispStep1($objPage);
105    }
106    break;
107// データベースの設定
108case 'step2':
109    //入力値のエラーチェック
110    $objPage->arrErr = lfCheckDBError($objDBParam);
111    if(count($objPage->arrErr) == 0) {
112        // 設定ファイルの生成
113        lfMakeConfigFile();
114        $objPage = lfDispStep3($objPage);
115    } else {
116        $objPage = lfDispStep2($objPage);
117    }
118    break;
119// テーブルの作成
120case 'step3':
121    // 入力データを渡す。
122    $arrRet =  $objDBParam->getHashArray();
123    define("DB_TYPE", $arrRet['db_type']);
124    $dsn = $arrRet['db_type']."://".$arrRet['db_user'].":".$arrRet['db_password']."@".$arrRet['db_server'].":".$arrRet['db_port']."/".$arrRet['db_name'];
125
126    if(count($objPage->arrErr) == 0) {
127        // スキップする場合には次画面へ遷移
128        $skip = $_POST["db_skip"];
129        if ($skip == "on") {
130            $objPage = lfDispComplete($objPage);
131            //$objPage = lfDispStep4($objPage);
132            break;
133        }
134    }
135
136    // テーブルの作成
137    $objPage->arrErr = lfExecuteSQL("./sql/create_table_".$arrRet['db_type'].".sql", $dsn);
138    if(count($objPage->arrErr) == 0) {
139        $objPage->tpl_message.="○:テーブルの作成に成功しました。<br>";
140    } else {
141        $objPage->tpl_message.="×:テーブルの作成に失敗しました。<br>";
142    }
143
144    // ビューの作成
145    if(count($objPage->arrErr) == 0 and $arrRet['db_type'] == 'pgsql') {
146        // ビューの作成
147        $objPage->arrErr = lfExecuteSQL("./sql/create_view.sql", $dsn);
148        if(count($objPage->arrErr) == 0) {
149            $objPage->tpl_message.="○:ビューの作成に成功しました。<br>";
150        } else {
151            $objPage->tpl_message.="×:ビューの作成に失敗しました。<br>";
152        }
153    }
154
155    // 初期データの作成
156    if(count($objPage->arrErr) == 0) {
157        $objPage->arrErr = lfExecuteSQL("./sql/insert_data.sql", $dsn);
158        if(count($objPage->arrErr) == 0) {
159            $objPage->tpl_message.="○:初期データの作成に成功しました。<br>";
160        } else {
161            $objPage->tpl_message.="×:初期データの作成に失敗しました。<br>";
162        }
163    }
164
165    // カラムコメントの書込み
166    if(count($objPage->arrErr) == 0) {
167        $objPage->arrErr = lfExecuteSQL("./sql/column_comment.sql", $dsn);
168        if(count($objPage->arrErr) == 0) {
169            $objPage->tpl_message.="○:カラムコメントの書込みに成功しました。<br>";
170        } else {
171            $objPage->tpl_message.="×:カラムコメントの書込みに失敗しました。<br>";
172        }
173    }
174
175    // テーブルコメントの書込み
176    if(count($objPage->arrErr) == 0) {
177        $objPage->arrErr = lfExecuteSQL("./sql/table_comment.sql", $dsn);
178        if(count($objPage->arrErr) == 0) {
179            $objPage->tpl_message.="○:テーブルコメントの書込みに成功しました。<br>";
180        } else {
181            $objPage->tpl_message.="×:テーブルコメントの書込みに失敗しました。<br>";
182        }
183    }
184
185    // シーケンスの作成
186    if (count($objPage->arrErr) == 0) {
187        $objPage->arrErr = lfCreateSequence(getSequences(), $dsn);
188        if(count($objPage->arrErr) == 0) {
189            $objPage->tpl_message.="○:シーケンスの作成に成功しました。<br>";
190        } else {
191            $objPage->tpl_message.="×:シーケンスの作成に失敗しました。<br>";
192        }
193    }
194
195    if(count($objPage->arrErr) == 0) {
196        $objPage = lfDispStep3($objPage);
197        $objPage->tpl_mode = 'step4';
198    } else {
199        $objPage = lfDispStep3($objPage);
200    }
201    break;
202case 'step4':
203    $objPage = lfDispStep4($objPage);
204    break;
205
206// テーブル類削除
207case 'drop':
208    // 入力データを渡す。
209    $arrRet =  $objDBParam->getHashArray();
210    if (!defined("DB_TYPE")) {
211        define("DB_TYPE", $arrRet['db_type']);
212    }
213    $dsn = $arrRet['db_type']."://".$arrRet['db_user'].":".$arrRet['db_password']."@".$arrRet['db_server'].":".$arrRet['db_port']."/".$arrRet['db_name'];
214
215    if ($arrRet['db_type'] == 'pgsql'){
216        // ビューの削除
217        $objPage->arrErr = lfExecuteSQL("./sql/drop_view.sql", $dsn, false);
218        if(count($objPage->arrErr) == 0) {
219            $objPage->tpl_message.="○:ビューの削除に成功しました。<br>";
220        } else {
221            $objPage->tpl_message.="×:ビューの削除に失敗しました。<br>";
222        }
223    }
224
225    // テーブルの削除
226    if(count($objPage->arrErr) == 0) {
227        $objPage->arrErr = lfExecuteSQL("./sql/drop_table.sql", $dsn, false);
228        if(count($objPage->arrErr) == 0) {
229            $objPage->tpl_message.="○:テーブルの削除に成功しました。<br>";
230        } else {
231            $objPage->tpl_message.="×:テーブルの削除に失敗しました。<br>";
232        }
233    }
234
235    // シーケンスの削除
236    if(count($objPage->arrErr) == 0) {
237        $objPage->arrErr = lfDropSequence(getSequences(), $dsn);
238        if(count($objPage->arrErr) == 0) {
239            $objPage->tpl_message.="○:シーケンスの削除に成功しました。<br>";
240        } else {
241            $objPage->tpl_message.="×:シーケンスの削除に失敗しました。<br>";
242        }
243    }
244
245    $objPage = lfDispStep3($objPage);
246    break;
247// 完了画面
248case 'complete':
249    // ショップマスタ情報の書き込み
250    $arrRet =  $objDBParam->getHashArray();
251
252    $dsn = $arrRet['db_type']."://".$arrRet['db_user'].":".$arrRet['db_password']."@".$arrRet['db_server'].":".$arrRet['db_port']."/".$arrRet['db_name'];
253    $sqlval['shop_name'] = $objWebParam->getValue('shop_name');
254    $sqlval['email01'] = $objWebParam->getValue('admin_mail');
255    $sqlval['email02'] = $objWebParam->getValue('admin_mail');
256    $sqlval['email03'] = $objWebParam->getValue('admin_mail');
257    $sqlval['email04'] = $objWebParam->getValue('admin_mail');
258    $sqlval['email05'] = $objWebParam->getValue('admin_mail');
259    $sqlval['top_tpl'] = "default1";
260    $sqlval['product_tpl'] = "default1";
261    $sqlval['detail_tpl'] = "default1";
262    $sqlval['mypage_tpl'] = "default1";
263    $objQuery = new SC_Query($dsn);
264    $cnt = $objQuery->count("dtb_baseinfo");
265    if($cnt > 0) {
266        $objQuery->update("dtb_baseinfo", $sqlval);
267    } else {
268        $objQuery->insert("dtb_baseinfo", $sqlval);
269    }
270
271    // 管理者登録
272    $login_id = $objWebParam->getValue('login_id');
273    $login_pass = sha1($objWebParam->getValue('login_pass') . ":" . AUTH_MAGIC);
274
275    $objQuery->delete("dtb_member", "login_id = ?", array($login_id));
276
277    $member_id = $objQuery->nextVal("dtb_member_member_id");
278    $objQuery->insert("dtb_member", array("member_id" => $member_id,
279                                          "name" => "管理者",
280                                          "login_id" => $login_id,
281                                          "password" => $login_pass,
282                                          "creator_id" => 0,
283                                          "authority" => 0,
284                                          "work" => 1,
285                                          "del_flg" => 0,
286                                          "rank" => 1,
287                                          "create_date" => "now()",
288                                          "update_date" => "now()"));
289
290    $GLOBAL_ERR = "";
291    $objPage = lfDispComplete($objPage);
292
293    if(isset($_POST['send_info']) && $_POST['send_info'] === 'true'){
294        // サイト情報を送信
295        $req = new HTTP_Request("http://www.ec-cube.net/mall/use_site.php");
296        $req->setMethod(HTTP_REQUEST_METHOD_POST);
297
298        $arrSendData = array();
299        foreach($_POST as $key => $val){
300            if (ereg("^senddata_*", $key)){
301                $arrSendDataTmp = array(str_replace("senddata_", "", $key) => $val);
302                $arrSendData = array_merge($arrSendData, $arrSendDataTmp);
303            }
304        }
305
306        $req->addPostDataArray($arrSendData);
307
308        if (!PEAR::isError($req->sendRequest())) {
309            $response1 = $req->getResponseBody();
310        } else {
311            $response1 = "";
312        }
313        $req->clearPostData();
314    }
315
316    break;
317case 'return_step0':
318    $objPage = lfDispStep0($objPage);
319    break;
320case 'return_step1':
321    $objPage = lfDispStep1($objPage);
322    break;
323case 'return_step2':
324    $objPage = lfDispStep2($objPage);
325    break;
326case 'return_step3':
327    $objPage = lfDispStep3($objPage);
328    break;
329case 'return_agreement':
330    $objPage = lfDispAgreement($objPage);
331    $objPage->tpl_onload .= "fnChangeVisible('agreement_yes', 'next');";
332    break;
333case 'return_welcome':
334default:
335    $objPage = lfDispWelcome($objPage);
336    break;
337}
338
339//フォーム用のパラメータを返す
340$objPage->arrForm = $objWebParam->getFormParamList();
341$objPage->arrForm = array_merge($objPage->arrForm, $objDBParam->getFormParamList());
342
343// SiteInfoを読み込まない
344$objView->assignobj($objPage);
345$objView->display('install_frame.tpl');
346//-----------------------------------------------------------------------------------------------------------------------------------
347// ようこそ画面の表示
348function lfDispWelcome($objPage) {
349    global $objWebParam;
350    global $objDBParam;
351    // hiddenに入力値を保持
352    $objPage->arrHidden = $objWebParam->getHashArray();
353    // hiddenに入力値を保持
354    $objPage->arrHidden = array_merge($objPage->arrHidden, $objDBParam->getHashArray());
355    $objPage->arrHidden['db_skip'] = $_POST['db_skip'];
356    $objPage->arrHidden['agreement'] = $_POST['agreement'];
357    $objPage->tpl_mainpage = 'welcome.tpl';
358    $objPage->tpl_mode = 'welcome';
359    return $objPage;
360}
361
362// 使用許諾契約書の表示
363function lfDispAgreement($objPage) {
364    global $objWebParam;
365    global $objDBParam;
366    // hiddenに入力値を保持
367    $objPage->arrHidden = $objWebParam->getHashArray();
368    // hiddenに入力値を保持
369    $objPage->arrHidden = array_merge($objPage->arrHidden, $objDBParam->getHashArray());
370    $objPage->arrHidden['db_skip'] = $_POST['db_skip'];
371    $objPage->arrHidden['agreement'] = $_POST['agreement'];
372    $objPage->tpl_mainpage = 'agreement.tpl';
373    $objPage->tpl_mode = 'agreement';
374    return $objPage;
375}
376
377// STEP0画面の表示(チェック)
378function lfDispStep0($objPage) {
379    global $objWebParam;
380    global $objDBParam;
381    // hiddenに入力値を保持
382    $objPage->arrHidden = $objWebParam->getHashArray();
383    // hiddenに入力値を保持
384    $objPage->arrHidden = array_merge($objPage->arrHidden, $objDBParam->getHashArray());
385    $objPage->arrHidden['db_skip'] = $_POST['db_skip'];
386    $objPage->arrHidden['agreement'] = $_POST['agreement'];
387    $objPage->tpl_mainpage = 'step0.tpl';
388
389    // プログラムで書込みされるファイル・ディレクトリ
390    $arrWriteFile = array(
391        DATA_FILE_PATH . "install.php",
392        USER_PATH,
393        HTML_FILE_PATH . "upload",
394        DATA_FILE_PATH . "cache/",
395        DATA_FILE_PATH . "class/",
396        DATA_FILE_PATH . "Smarty/",
397        DATA_FILE_PATH . "logs/",
398        DATA_FILE_PATH . "downloads/",
399        DATA_FILE_PATH . "upload/",
400    );
401
402    $mess = "";
403    $hasErr = false;
404    foreach($arrWriteFile as $val) {
405        // listdirsの保持データを初期化
406        initdirs();
407        if (is_dir($val)) {
408           $arrDirs = listdirs($val);
409        } else {
410            $arrDirs = array($val);
411        }
412
413        foreach ($arrDirs as $path) {
414            if(file_exists($path)) {
415                $filemode = lfGetFileMode($path);
416                $real_path = realpath($path);
417
418                // ディレクトリの場合
419                if(is_dir($path)) {
420                    if(!is_writable($path)) {
421                        $mess.= ">> ×:$real_path($filemode) <br>ユーザ書込み権限(777, 707等)を付与して下さい。<br>";
422                        $hasErr = true;
423                    } else {
424                        GC_Utils_Ex::gfPrintLog("WRITABLE:".$path, INSTALL_LOG);
425                    }
426                } else {
427                    if(!is_writable($path)) {
428                        $mess.= ">> ×:$real_path($filemode) <br>ユーザ書込み権限(666, 606等)を付与して下さい。<br>";
429                        $hasErr = true;
430                    } else {
431                        GC_Utils_Ex::gfPrintLog("WRITABLE:".$path, INSTALL_LOG);
432                    }
433                }
434            } else {
435                $mess.= ">> ×:$path が見つかりません。<br>";
436                $hasErr = true;
437            }
438        }
439    }
440
441    if (ini_get('safe_mode')) {
442        $mess .= ">> ×:PHPのセーフモードが有効になっています。<br>";
443        $hasErr = true;
444    }
445
446    if (get_magic_quotes_gpc()) {
447        $mess .= ">> ×:PHPの設定ディレクティブ「magic_quotes_gpc」が有効になっています。<br>";
448        $hasErr = true;
449    }
450
451    // 問題点を検出している場合
452    if ($hasErr) {
453        $objPage->tpl_mode = 'return_step0';
454    }
455    // 問題点を検出していない場合
456    else {
457        $objPage->tpl_mode = 'step0';
458        umask(0);
459        $path = HTML_FILE_PATH . "upload/temp_template";
460        if(!file_exists($path)) {
461            mkdir($path);
462        }
463        $path = HTML_FILE_PATH . "upload/save_image";
464        if(!file_exists($path)) {
465            mkdir($path);
466        }
467        $path = HTML_FILE_PATH . "upload/temp_image";
468        if(!file_exists($path)) {
469            mkdir($path);
470        }
471        $path = HTML_FILE_PATH . "upload/graph_image";
472        if(!file_exists($path)) {
473            mkdir($path);
474        }
475        $path = HTML_FILE_PATH . "upload/mobile_image";
476        if(!file_exists($path)) {
477            mkdir($path);
478        }
479        $path = DATA_FILE_PATH . "downloads/module";
480        if(!file_exists($path)) {
481            mkdir($path);
482        }
483        $path = DATA_FILE_PATH . "downloads/update";
484        if(!file_exists($path)) {
485            mkdir($path);
486        }
487        $path = DATA_FILE_PATH . "upload/csv";
488        if(!file_exists($path)) {
489            mkdir($path);
490        }
491        $mess.= ">> ○:アクセス権限は正常です。<br>";
492    }
493
494    $objPage->mess = $mess;
495    $objPage->hasErr = $hasErr;
496
497    return $objPage;
498}
499
500// STEP0_1画面の表示(ファイルのコピー)
501function lfDispStep0_1($objPage) {
502    global $objWebParam;
503    global $objDBParam;
504
505    // hiddenに入力値を保持
506    $objPage->arrHidden = $objWebParam->getHashArray();
507    // hiddenに入力値を保持
508    $objPage->arrHidden = array_merge($objPage->arrHidden, $objDBParam->getHashArray());
509    $objPage->arrHidden['db_skip'] = $_POST['db_skip'];
510    $objPage->arrHidden['agreement'] = $_POST['agreement'];
511    $objPage->tpl_mainpage = 'step0_1.tpl';
512    $objPage->tpl_mode = 'step0_1';
513    // ファイルコピー
514    $objPage->copy_mess = SC_Utils_Ex::sfCopyDir("./user_data/", USER_PATH, $objPage->copy_mess);
515    $objPage->copy_mess = SC_Utils_Ex::sfCopyDir("./save_image/", HTML_FILE_PATH . "upload/save_image/", $objPage->copy_mess);
516    return $objPage;
517}
518
519function lfGetFileMode($path) {
520    $mode = substr(sprintf('%o', fileperms($path)), -3);
521    return $mode;
522}
523
524// STEP1画面の表示
525function lfDispStep1($objPage) {
526    global $objDBParam;
527    // hiddenに入力値を保持
528    $objPage->arrHidden = $objDBParam->getHashArray();
529    $objPage->arrHidden['db_skip'] = $_POST['db_skip'];
530    $objPage->arrHidden['agreement'] = $_POST['agreement'];
531    $objPage->tpl_mainpage = 'step1.tpl';
532    $objPage->tpl_mode = 'step1';
533    return $objPage;
534}
535
536// STEP2画面の表示
537function lfDispStep2($objPage) {
538    global $objWebParam;
539    global $objDBParam;
540    // hiddenに入力値を保持
541    $objPage->arrHidden = $objWebParam->getHashArray();
542    $objPage->arrHidden['db_skip'] = $_POST['db_skip'];
543    $objPage->arrHidden['agreement'] = $_POST['agreement'];
544    $objPage->tpl_mainpage = 'step2.tpl';
545    $objPage->tpl_mode = 'step2';
546    return $objPage;
547}
548
549// STEP3画面の表示
550function lfDispStep3($objPage) {
551    global $objWebParam;
552    global $objDBParam;
553    // hiddenに入力値を保持
554    $objPage->arrHidden = $objWebParam->getHashArray();
555    // hiddenに入力値を保持
556    $objPage->arrHidden = array_merge($objPage->arrHidden, $objDBParam->getHashArray());
557    $objPage->arrHidden['agreement'] = $_POST['agreement'];
558    $objPage->tpl_db_skip = $_POST['db_skip'];
559    $objPage->tpl_mainpage = 'step3.tpl';
560    $objPage->tpl_mode = 'step3';
561    return $objPage;
562}
563
564// STEP4画面の表示
565function lfDispStep4($objPage) {
566    global $objWebParam;
567    global $objDBParam;
568    global $objDb;
569
570    // hiddenに入力値を保持
571    $objPage->arrHidden = $objWebParam->getHashArray();
572    $objPage->arrHidden = array_merge($objPage->arrHidden, $objDBParam->getHashArray());
573    // hiddenに入力値を保持
574    $objPage->arrHidden['agreement'] = $_POST['agreement'];
575
576    $normal_url = $objWebParam->getValue('normal_url');
577    // 語尾に'/'をつける
578    if (!ereg("/$", $normal_url)) $normal_url = $normal_url . "/";
579
580    $arrDbParam = $objDBParam->getHashArray();
581    if (!defined("DB_TYPE")) {
582        define("DB_TYPE", $arrDbParam['db_type']);
583    }
584    $dsn = $arrDbParam['db_type']."://".$arrDbParam['db_user'].":".$arrDbParam['db_password']."@".$arrDbParam['db_server'].":".$arrDbParam['db_port']."/".$arrDbParam['db_name'];
585
586    $objPage->tpl_site_url = $normal_url;
587    $objPage->tpl_shop_name = $objWebParam->getValue('shop_name');
588    $objPage->tpl_cube_ver = ECCUBE_VERSION;
589    $objPage->tpl_php_ver = phpversion();
590    $objPage->tpl_db_ver = $objDb->sfGetDBVersion($dsn);
591    $objPage->tpl_db_skip = $_POST['db_skip'];
592    $objPage->tpl_mainpage = 'step4.tpl';
593    $objPage->tpl_mode = 'complete';
594    return $objPage;
595}
596
597// 完了画面の表示
598function lfDispComplete($objPage) {
599    global $objWebParam;
600    global $objDBParam;
601    // hiddenに入力値を保持
602    $objPage->arrHidden = $objWebParam->getHashArray();
603    // hiddenに入力値を保持
604    $objPage->arrHidden = array_merge($objPage->arrHidden, $objDBParam->getHashArray());
605    $objPage->arrHidden['db_skip'] = $_POST['db_skip'];
606    $objPage->tpl_mainpage = 'complete.tpl';
607    $objPage->tpl_mode = 'complete';
608
609    $secure_url = $objWebParam->getValue('secure_url');
610    // 語尾に'/'をつける
611    if (!ereg("/$", $secure_url)) {
612        $secure_url = $secure_url . "/";
613    }
614    $objPage->tpl_sslurl = $secure_url;
615    return $objPage;
616}
617
618// WEBパラメータ情報の初期化
619function lfInitWebParam($objWebParam) {
620    global $objDb;
621
622    if(defined('HTTP_URL')) {
623        $normal_url = HTTP_URL;
624    } else {
625        $dir = ereg_replace("install/.*$", "", $_SERVER['REQUEST_URI']);
626        $normal_url = "http://" . $_SERVER['HTTP_HOST'] . $dir;
627    }
628
629    if(defined('HTTPS_URL')) {
630        $secure_url = HTTPS_URL;
631    } else {
632        $dir = ereg_replace("install/.*$", "", $_SERVER['REQUEST_URI']);
633        $secure_url = "http://" . $_SERVER['HTTP_HOST'] . $dir;
634    }
635
636    // 店名、管理者メールアドレスを取得する。(再インストール時)
637    if(defined('DEFAULT_DSN')) {
638        $objQuery = new SC_Query();
639        $tables = $objQuery->listTables();
640
641        if(!PEAR::isError($tables) && in_array("dtb_baseinfo", $tables)) {
642            $arrRet = $objQuery->select("shop_name, email01", "dtb_baseinfo");
643            $shop_name = $arrRet[0]['shop_name'];
644            $admin_mail = $arrRet[0]['email01'];
645        }
646    }
647
648    $objWebParam->addParam("店名", "shop_name", MTEXT_LEN, "", array("EXIST_CHECK","MAX_LENGTH_CHECK"), $shop_name);
649    $objWebParam->addParam("管理者:メールアドレス", "admin_mail", MTEXT_LEN, "", array("EXIST_CHECK","EMAIL_CHECK","EMAIL_CHAR_CHECK","MAX_LENGTH_CHECK"), $admin_mail);
650    $objWebParam->addParam("管理者:ログインID", "login_id", ID_MAX_LEN, "", array("EXIST_CHECK","SPTAB_CHECK", "ALNUM_CHECK"));
651    $objWebParam->addParam("管理者:パスワード", "login_pass", ID_MAX_LEN, "", array("EXIST_CHECK","SPTAB_CHECK", "ALNUM_CHECK"));
652    $objWebParam->addParam("URL(通常)", "normal_url", MTEXT_LEN, "", array("EXIST_CHECK","URL_CHECK","MAX_LENGTH_CHECK"), $normal_url);
653    $objWebParam->addParam("URL(セキュア)", "secure_url", MTEXT_LEN, "", array("EXIST_CHECK","URL_CHECK","MAX_LENGTH_CHECK"), $secure_url);
654    $objWebParam->addParam("ドメイン", "domain", MTEXT_LEN, "", array("MAX_LENGTH_CHECK"));
655
656    return $objWebParam;
657}
658
659// DBパラメータ情報の初期化
660function lfInitDBParam($objDBParam) {
661
662    if(defined('DB_SERVER')) {
663        $db_server = DB_SERVER;
664    } else {
665        $db_server = "127.0.0.1";
666    }
667
668    if(defined('DB_TYPE')) {
669        $db_type = DB_TYPE;
670    } else {
671        $db_type = "";
672    }
673
674    if(defined('DB_PORT')) {
675        $db_port = DB_PORT;
676    } else {
677        $db_port = "";
678    }
679
680    if(defined('DB_NAME')) {
681        $db_name = DB_NAME;
682    } else {
683        $db_name = "eccube_db";
684    }
685
686    if(defined('DB_USER')) {
687        $db_user = DB_USER;
688    } else {
689        $db_user = "eccube_db_user";
690    }
691
692    $objDBParam->addParam("DBの種類", "db_type", INT_LEN, "", array("EXIST_CHECK","MAX_LENGTH_CHECK"), $db_type);
693    $objDBParam->addParam("DBサーバ", "db_server", MTEXT_LEN, "", array("EXIST_CHECK","MAX_LENGTH_CHECK"), $db_server);
694    $objDBParam->addParam("DBポート", "db_port", INT_LEN, "", array("MAX_LENGTH_CHECK"), $db_port);
695    $objDBParam->addParam("DB名", "db_name", MTEXT_LEN, "", array("EXIST_CHECK","MAX_LENGTH_CHECK"), $db_name);
696    $objDBParam->addParam("DBユーザ", "db_user", MTEXT_LEN, "", array("EXIST_CHECK","MAX_LENGTH_CHECK"), $db_user);
697    $objDBParam->addParam("DBパスワード", "db_password", MTEXT_LEN, "", array("EXIST_CHECK","MAX_LENGTH_CHECK"));
698
699    return $objDBParam;
700}
701
702// 入力内容のチェック
703function lfCheckWebError($objFormParam) {
704    // 入力データを渡す。
705    $arrRet =  $objFormParam->getHashArray();
706    $objErr = new SC_CheckError($arrRet);
707    $objErr->arrErr = $objFormParam->checkError();
708
709    // ディレクトリ名のみ取得する
710    $normal_dir = ereg_replace("^https?://[a-zA-Z0-9_~=&\?\.\-]+", "", $arrRet['normal_url']);
711    $secure_dir = ereg_replace("^https?://[a-zA-Z0-9_~=&\?\.\-]+", "", $arrRet['secure_url']);
712
713    if($normal_dir != $secure_dir) {
714        $objErr->arrErr['normal_url'] = "URLに異なる階層を指定することはできません。";
715        $objErr->arrErr['secure_url'] = "URLに異なる階層を指定することはできません。";
716    }
717
718    // ログインIDチェック
719    $objErr->doFunc(array("管理者:ログインID",'login_id',ID_MIN_LEN , ID_MAX_LEN) ,array("SPTAB_CHECK" ,"NUM_RANGE_CHECK"));
720
721    // パスワードのチェック
722    $objErr->doFunc( array("管理者:パスワード",'login_pass',ID_MIN_LEN ,ID_MAX_LEN ) ,array("SPTAB_CHECK" ,"NUM_RANGE_CHECK" ));
723
724    return $objErr->arrErr;
725}
726
727// 入力内容のチェック
728function lfCheckDBError($objFormParam) {
729    global $objPage;
730
731    // 入力データを渡す。
732    $arrRet =  $objFormParam->getHashArray();
733
734    $objErr = new SC_CheckError($arrRet);
735    $objErr->arrErr = $objFormParam->checkError();
736
737    if(count($objErr->arrErr) == 0) {
738        // 接続確認
739        $dsn = $arrRet['db_type']."://".$arrRet['db_user'].":".$arrRet['db_password']."@".$arrRet['db_server'].":".$arrRet['db_port']."/".$arrRet['db_name'];
740        // Debugモード指定
741        $options['debug'] = PEAR_DB_DEBUG;
742        $objDB = MDB2::connect($dsn, $options);
743        // 接続成功
744        if(!PEAR::isError($objDB)) {
745            $dbFactory = SC_DB_DBFactory_Ex::getInstance();
746            // データベースバージョン情報の取得
747            $objPage->tpl_db_version = $dbFactory->sfGetDBVersion($dsn);
748        } else {
749            $objErr->arrErr['all'] = ">> " . $objDB->message . "<br>";
750            // エラー文を取得する
751            ereg("\[(.*)\]", $objDB->userinfo, $arrKey);
752            $objErr->arrErr['all'].= $arrKey[0] . "<br>";
753            GC_Utils_Ex::gfPrintLog($objDB->userinfo, INSTALL_LOG);
754        }
755    }
756    return $objErr->arrErr;
757}
758
759// SQL文の実行
760function lfExecuteSQL($filepath, $dsn, $disp_err = true) {
761    $arrErr = array();
762
763    if(!file_exists($filepath)) {
764        $arrErr['all'] = ">> スクリプトファイルが見つかりません";
765    } else {
766        if($fp = fopen($filepath,"r")) {
767            $sql = fread($fp, filesize($filepath));
768            fclose($fp);
769        }
770        // Debugモード指定
771        $options['debug'] = PEAR_DB_DEBUG;
772        $objDB = MDB2::connect($dsn, $options);
773        // 接続エラー
774        if(!PEAR::isError($objDB)) {
775            $sql_split = split(";",$sql);
776            foreach($sql_split as $key => $val){
777                SC_Utils::sfFlush();
778                if (trim($val) != "") {
779                    $ret = $objDB->query($val);
780                    if(PEAR::isError($ret) && $disp_err) {
781                        $arrErr['all'] = ">> " . $ret->message . "<br>";
782                        // エラー文を取得する
783                        ereg("\[(.*)\]", $ret->userinfo, $arrKey);
784                        $arrErr['all'].= $arrKey[0] . "<br>";
785                        $objPage->update_mess.=">> テーブル構成の変更に失敗しました。<br>";
786                        GC_Utils_Ex::gfPrintLog($ret->userinfo, INSTALL_LOG);
787                    } else {
788                        GC_Utils_Ex::gfPrintLog("OK:". $val, INSTALL_LOG);
789                    }
790                }
791            }
792        } else {
793            $arrErr['all'] = ">> " . $objDB->message;
794            GC_Utils_Ex::gfPrintLog($objDB->userinfo, INSTALL_LOG);
795        }
796    }
797    return $arrErr;
798}
799
800/**
801 * シーケンスを削除する.
802 *
803 * @param array $arrSequences シーケンスのテーブル名, カラム名の配列
804 * @param string $dsn データソース名
805 * @return array エラーが発生した場合はエラーメッセージの配列
806 */
807function lfDropSequence($arrSequences, $dsn) {
808    $arrErr = array();
809
810    // Debugモード指定
811    $options['debug'] = PEAR_DB_DEBUG;
812    $objDB = MDB2::connect($dsn, $options);
813    $objManager =& $objDB->loadModule('Manager');
814
815    // 接続エラー
816    if (!PEAR::isError($objDB)) {
817
818        $exists = $objManager->listSequences();
819        foreach ($arrSequences as $seq) {
820            $seq_name = $seq[0] . "_" . $seq[1];
821            if (in_array($seq_name, $exists)) {
822                $result = $objManager->dropSequence($seq_name);
823                if (PEAR::isError($result)) {
824                    $arrErr['all'] = ">> " . $result->message . "<br />";
825                    GC_Utils_Ex::gfPrintLog($result->userinfo, INSTALL_LOG);
826                } else {
827                    GC_Utils_Ex::gfPrintLog("OK:". $seq_name, INSTALL_LOG);
828                }
829            }
830        }
831    } else {
832        $arrErr['all'] = ">> " . $objDB->message;
833        GC_Utils_Ex::gfPrintLog($objDB->userinfo, INSTALL_LOG);
834    }
835    return $arrErr;
836}
837
838/**
839 * シーケンスを生成する.
840 *
841 * @param array $arrSequences シーケンスのテーブル名, カラム名の配列
842 * @param string $dsn データソース名
843 * @return array エラーが発生した場合はエラーメッセージの配列
844 */
845function lfCreateSequence($arrSequences, $dsn) {
846   $arrErr = array();
847
848    // Debugモード指定
849    $options['debug'] = PEAR_DB_DEBUG;
850    $objDB = MDB2::connect($dsn, $options);
851    $objManager =& $objDB->loadModule('Manager');
852
853    // 接続エラー
854    if (!PEAR::isError($objDB)) {
855
856        $exists = $objManager->listSequences();
857        foreach ($arrSequences as $seq) {
858            $res = $objDB->query("SELECT max(" . $seq[1] . ") FROM ". $seq[0]);
859            if (PEAR::isError($res)) {
860                $arrErr['all'] = ">> " . $res->userinfo . "<br />";
861                GC_Utils_Ex::gfPrintLog($res->userinfo, INSTALL_LOG);
862                return $arrErr;
863            }
864            $max = $res->fetchOne();
865
866            $seq_name = $seq[0] . "_" . $seq[1];
867            $result = $objManager->createSequence($seq_name, $max + 1);
868            if (PEAR::isError($result)) {
869                $arrErr['all'] = ">> " . $result->message . "<br />";
870                GC_Utils_Ex::gfPrintLog($result->userinfo, INSTALL_LOG);
871            } else {
872                GC_Utils_Ex::gfPrintLog("OK:". $seq_name, INSTALL_LOG);
873            }
874        }
875    } else {
876        $arrErr['all'] = ">> " . $objDB->message;
877        GC_Utils_Ex::gfPrintLog($objDB->userinfo, INSTALL_LOG);
878    }
879    return $arrErr;
880}
881
882// 設定ファイルの作成
883function lfMakeConfigFile() {
884    global $objWebParam;
885    global $objDBParam;
886   
887    $normal_url = $objWebParam->getValue('normal_url');
888    // 語尾に'/'をつける
889    if (!ereg("/$", $normal_url)) {
890        $normal_url = $normal_url . "/";
891    }
892
893    $secure_url = $objWebParam->getValue('secure_url');
894    // 語尾に'/'をつける
895    if (!ereg("/$", $secure_url)) {
896        $secure_url = $secure_url . "/";
897    }
898
899    // ディレクトリの取得
900    $url_dir = ereg_replace("^https?://[a-zA-Z0-9_:~=&\?\.\-]+", "", $normal_url);
901
902    $filepath = DATA_FILE_PATH . "install.php";
903
904    $config_data =
905    "<?php\n".
906    "    define ('ECCUBE_INSTALL', 'ON');\n" .
907    "    define ('HTTP_URL', '" . $normal_url . "');\n" .
908    "    define ('HTTPS_URL', '" . $secure_url . "');\n" .
909    "    define ('URL_PATH', '" . $url_dir . "');\n" .
910    "    define ('DOMAIN_NAME', '" . $objWebParam->getValue('domain') . "');\n" .
911    "    define ('DB_TYPE', '" . $objDBParam->getValue('db_type') . "');\n" .
912    "    define ('DB_USER', '" . $objDBParam->getValue('db_user') . "');\n" .
913    "    define ('DB_PASSWORD', '" . $objDBParam->getValue('db_password') . "');\n" .
914    "    define ('DB_SERVER', '" . $objDBParam->getValue('db_server') . "');\n" .
915    "    define ('DB_NAME', '" . $objDBParam->getValue('db_name') . "');\n" .
916    "    define ('DB_PORT', '" . $objDBParam->getValue('db_port') .  "');\n" .
917    "?>";
918
919    if($fp = fopen($filepath,"w")) {
920        fwrite($fp, $config_data);
921        fclose($fp);
922    }
923}
924
925/**
926 * $dir を再帰的に辿ってパス名を配列で返す.
927 *
928 * @param string 任意のパス名
929 * @return array $dir より下層に存在するパス名の配列
930 * @see http://www.php.net/glob
931 */
932$alldirs = array();
933function listdirs($dir) {
934    global $alldirs;
935    $dirs = glob($dir . '/*');
936    if (is_array($dirs) && count($dirs) > 0) {
937        foreach ($dirs as $d) {
938            $alldirs[] = $d;
939            listdirs($d);
940        }
941    }
942    return $alldirs;
943}
944
945/**
946 * 保持したスタティック変数をクリアする。
947 */
948function initdirs() {
949    global $alldirs;
950    $alldirs = array();
951}
952
953/**
954 * シーケンスを使用するテーブル名とカラム名の配列を返す.
955 *
956 * @return array シーケンスを使用するテーブル名とカラム名の配列
957 */
958function getSequences() {
959    return array(array("dtb_best_products","best_id"),
960                 array("dtb_bloc", "bloc_id"),
961                 array("dtb_category", "category_id"),
962                 array("dtb_class", "class_id"),
963                 array("dtb_classcategory", "classcategory_id"),
964                 array("dtb_csv", "no"),
965                 array("dtb_csv_sql", "sql_id"),
966                 array("dtb_customer", "customer_id"),
967                 array("dtb_deliv", "deliv_id"),
968                 array("dtb_holiday", "holiday_id"),
969                 array("dtb_kiyaku", "kiyaku_id"),
970                 array("dtb_mail_history", "send_id"),
971                 array("dtb_maker", "maker_id"),
972                 array("dtb_member", "member_id"),
973                 array("dtb_mobile_kara_mail", "kara_mail_id"),
974                 array("dtb_module_update_logs", "log_id"),
975                 array("dtb_news", "news_id"),
976                 array("dtb_order", "order_id"),
977                 array("dtb_other_deliv", "other_deliv_id"),
978                 array("dtb_pagelayout", "page_id"),
979                 array("dtb_payment", "payment_id"),
980                 array("dtb_products_class", "product_class_id"),
981                 array("dtb_products", "product_id"),
982                 array("dtb_class_combination", "class_combination_id"),
983                 array("dtb_review", "review_id"),
984                 array("dtb_send_history", "send_id"),
985                 array("dtb_site_control", "control_id"),
986                 array("dtb_table_comment", "id"),
987                 array("dtb_trackback", "trackback_id"));
988}
989?>
Note: See TracBrowser for help on using the repository browser.