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

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

#869(create_date, update_date 列の定義が、表やDBによるバラツキがある)

  • 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_REALDIR', rtrim(realpath(rtrim(realpath(dirname(__FILE__)), '/\\') . '/../'), '/\\') . '/');
26
27require_once HTML_REALDIR . 'define.php';
28define('INSTALL_FUNCTION', true);
29require_once HTML_REALDIR . HTML2DATA_DIR . 'require_base.php';
30// ▲require.php 相当
31
32$INSTALL_DIR = realpath(dirname( __FILE__));
33require_once(DATA_REALDIR . "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    $sqlval['update_date'] = 'now()';
264    $objQuery = new SC_Query($dsn);
265    $cnt = $objQuery->count("dtb_baseinfo");
266    if($cnt > 0) {
267        $objQuery->update("dtb_baseinfo", $sqlval);
268    } else {
269        $objQuery->insert("dtb_baseinfo", $sqlval);
270    }
271
272    // 管理者登録
273    $login_id = $objWebParam->getValue('login_id');
274    $login_pass = sha1($objWebParam->getValue('login_pass') . ":" . AUTH_MAGIC);
275
276    $objQuery->delete("dtb_member", "login_id = ?", array($login_id));
277
278    $member_id = $objQuery->nextVal("dtb_member_member_id");
279    $objQuery->insert("dtb_member", array("member_id" => $member_id,
280                                          "name" => "管理者",
281                                          "login_id" => $login_id,
282                                          "password" => $login_pass,
283                                          "creator_id" => 0,
284                                          "authority" => 0,
285                                          "work" => 1,
286                                          "del_flg" => 0,
287                                          "rank" => 1,
288                                          "create_date" => "now()",
289                                          "update_date" => "now()"));
290
291    $GLOBAL_ERR = "";
292    $objPage = lfDispComplete($objPage);
293
294    if(isset($_POST['send_info']) && $_POST['send_info'] === 'true'){
295        // サイト情報を送信
296        $req = new HTTP_Request("http://www.ec-cube.net/mall/use_site.php");
297        $req->setMethod(HTTP_REQUEST_METHOD_POST);
298
299        $arrSendData = array();
300        foreach($_POST as $key => $val){
301            if (ereg("^senddata_*", $key)){
302                $arrSendDataTmp = array(str_replace("senddata_", "", $key) => $val);
303                $arrSendData = array_merge($arrSendData, $arrSendDataTmp);
304            }
305        }
306
307        $req->addPostDataArray($arrSendData);
308
309        if (!PEAR::isError($req->sendRequest())) {
310            $response1 = $req->getResponseBody();
311        } else {
312            $response1 = "";
313        }
314        $req->clearPostData();
315    }
316
317    break;
318case 'return_step0':
319    $objPage = lfDispStep0($objPage);
320    break;
321case 'return_step1':
322    $objPage = lfDispStep1($objPage);
323    break;
324case 'return_step2':
325    $objPage = lfDispStep2($objPage);
326    break;
327case 'return_step3':
328    $objPage = lfDispStep3($objPage);
329    break;
330case 'return_agreement':
331    $objPage = lfDispAgreement($objPage);
332    $objPage->tpl_onload .= "fnChangeVisible('agreement_yes', 'next');";
333    break;
334case 'return_welcome':
335default:
336    $objPage = lfDispWelcome($objPage);
337    break;
338}
339
340//フォーム用のパラメータを返す
341$objPage->arrForm = $objWebParam->getFormParamList();
342$objPage->arrForm = array_merge($objPage->arrForm, $objDBParam->getFormParamList());
343
344// SiteInfoを読み込まない
345$objView->assignobj($objPage);
346$objView->display('install_frame.tpl');
347//-----------------------------------------------------------------------------------------------------------------------------------
348// ようこそ画面の表示
349function lfDispWelcome($objPage) {
350    global $objWebParam;
351    global $objDBParam;
352    // hiddenに入力値を保持
353    $objPage->arrHidden = $objWebParam->getHashArray();
354    // hiddenに入力値を保持
355    $objPage->arrHidden = array_merge($objPage->arrHidden, $objDBParam->getHashArray());
356    $objPage->arrHidden['db_skip'] = $_POST['db_skip'];
357    $objPage->arrHidden['agreement'] = $_POST['agreement'];
358    $objPage->tpl_mainpage = 'welcome.tpl';
359    $objPage->tpl_mode = 'welcome';
360    return $objPage;
361}
362
363// 使用許諾契約書の表示
364function lfDispAgreement($objPage) {
365    global $objWebParam;
366    global $objDBParam;
367    // hiddenに入力値を保持
368    $objPage->arrHidden = $objWebParam->getHashArray();
369    // hiddenに入力値を保持
370    $objPage->arrHidden = array_merge($objPage->arrHidden, $objDBParam->getHashArray());
371    $objPage->arrHidden['db_skip'] = $_POST['db_skip'];
372    $objPage->arrHidden['agreement'] = $_POST['agreement'];
373    $objPage->tpl_mainpage = 'agreement.tpl';
374    $objPage->tpl_mode = 'agreement';
375    return $objPage;
376}
377
378// STEP0画面の表示(チェック)
379function lfDispStep0($objPage) {
380    global $objWebParam;
381    global $objDBParam;
382    // hiddenに入力値を保持
383    $objPage->arrHidden = $objWebParam->getHashArray();
384    // hiddenに入力値を保持
385    $objPage->arrHidden = array_merge($objPage->arrHidden, $objDBParam->getHashArray());
386    $objPage->arrHidden['db_skip'] = $_POST['db_skip'];
387    $objPage->arrHidden['agreement'] = $_POST['agreement'];
388    $objPage->tpl_mainpage = 'step0.tpl';
389
390    // プログラムで書込みされるファイル・ディレクトリ
391    $arrWriteFile = array(
392        DATA_REALDIR . "install.php",
393        USER_REALDIR,
394        HTML_REALDIR . "upload",
395        DATA_REALDIR . "cache/",
396        DATA_REALDIR . "class/",
397        DATA_REALDIR . "Smarty/",
398        DATA_REALDIR . "logs/",
399        DATA_REALDIR . "downloads/",
400        DATA_REALDIR . "upload/",
401    );
402
403    $mess = "";
404    $hasErr = false;
405    foreach($arrWriteFile as $val) {
406        // listdirsの保持データを初期化
407        initdirs();
408        if (is_dir($val)) {
409           $arrDirs = listdirs($val);
410        } else {
411            $arrDirs = array($val);
412        }
413
414        foreach ($arrDirs as $path) {
415            if(file_exists($path)) {
416                $filemode = lfGetFileMode($path);
417                $real_path = realpath($path);
418
419                // ディレクトリの場合
420                if(is_dir($path)) {
421                    if(!is_writable($path)) {
422                        $mess.= ">> ×:$real_path($filemode) <br>ユーザ書込み権限(777, 707等)を付与して下さい。<br>";
423                        $hasErr = true;
424                    } else {
425                        GC_Utils_Ex::gfPrintLog("WRITABLE:".$path, INSTALL_LOG);
426                    }
427                } else {
428                    if(!is_writable($path)) {
429                        $mess.= ">> ×:$real_path($filemode) <br>ユーザ書込み権限(666, 606等)を付与して下さい。<br>";
430                        $hasErr = true;
431                    } else {
432                        GC_Utils_Ex::gfPrintLog("WRITABLE:".$path, INSTALL_LOG);
433                    }
434                }
435            } else {
436                $mess.= ">> ×:$path が見つかりません。<br>";
437                $hasErr = true;
438            }
439        }
440    }
441
442    if (ini_get('safe_mode')) {
443        $mess .= ">> ×:PHPのセーフモードが有効になっています。<br>";
444        $hasErr = true;
445    }
446
447    if (get_magic_quotes_gpc()) {
448        $mess .= ">> ×:PHPの設定ディレクティブ「magic_quotes_gpc」が有効になっています。<br>";
449        $hasErr = true;
450    }
451
452    // 問題点を検出している場合
453    if ($hasErr) {
454        $objPage->tpl_mode = 'return_step0';
455    }
456    // 問題点を検出していない場合
457    else {
458        $objPage->tpl_mode = 'step0';
459        umask(0);
460        $path = HTML_REALDIR . "upload/temp_template";
461        if(!file_exists($path)) {
462            mkdir($path);
463        }
464        $path = HTML_REALDIR . "upload/save_image";
465        if(!file_exists($path)) {
466            mkdir($path);
467        }
468        $path = HTML_REALDIR . "upload/temp_image";
469        if(!file_exists($path)) {
470            mkdir($path);
471        }
472        $path = HTML_REALDIR . "upload/graph_image";
473        if(!file_exists($path)) {
474            mkdir($path);
475        }
476        $path = HTML_REALDIR . "upload/mobile_image";
477        if(!file_exists($path)) {
478            mkdir($path);
479        }
480        $path = DATA_REALDIR . "downloads/module";
481        if(!file_exists($path)) {
482            mkdir($path);
483        }
484        $path = DATA_REALDIR . "downloads/update";
485        if(!file_exists($path)) {
486            mkdir($path);
487        }
488        $path = DATA_REALDIR . "upload/csv";
489        if(!file_exists($path)) {
490            mkdir($path);
491        }
492        $mess.= ">> ○:アクセス権限は正常です。<br>";
493    }
494
495    $objPage->mess = $mess;
496    $objPage->hasErr = $hasErr;
497
498    return $objPage;
499}
500
501// STEP0_1画面の表示(ファイルのコピー)
502function lfDispStep0_1($objPage) {
503    global $objWebParam;
504    global $objDBParam;
505
506    // hiddenに入力値を保持
507    $objPage->arrHidden = $objWebParam->getHashArray();
508    // hiddenに入力値を保持
509    $objPage->arrHidden = array_merge($objPage->arrHidden, $objDBParam->getHashArray());
510    $objPage->arrHidden['db_skip'] = $_POST['db_skip'];
511    $objPage->arrHidden['agreement'] = $_POST['agreement'];
512    $objPage->tpl_mainpage = 'step0_1.tpl';
513    $objPage->tpl_mode = 'step0_1';
514    // ファイルコピー
515    $objPage->copy_mess = SC_Utils_Ex::sfCopyDir("./user_data/", USER_REALDIR, $objPage->copy_mess);
516    $objPage->copy_mess = SC_Utils_Ex::sfCopyDir("./save_image/", HTML_REALDIR . "upload/save_image/", $objPage->copy_mess);
517    return $objPage;
518}
519
520function lfGetFileMode($path) {
521    $mode = substr(sprintf('%o', fileperms($path)), -3);
522    return $mode;
523}
524
525// STEP1画面の表示
526function lfDispStep1($objPage) {
527    global $objDBParam;
528    // hiddenに入力値を保持
529    $objPage->arrHidden = $objDBParam->getHashArray();
530    $objPage->arrHidden['db_skip'] = $_POST['db_skip'];
531    $objPage->arrHidden['agreement'] = $_POST['agreement'];
532    $objPage->tpl_mainpage = 'step1.tpl';
533    $objPage->tpl_mode = 'step1';
534    return $objPage;
535}
536
537// STEP2画面の表示
538function lfDispStep2($objPage) {
539    global $objWebParam;
540    global $objDBParam;
541    // hiddenに入力値を保持
542    $objPage->arrHidden = $objWebParam->getHashArray();
543    $objPage->arrHidden['db_skip'] = $_POST['db_skip'];
544    $objPage->arrHidden['agreement'] = $_POST['agreement'];
545    $objPage->tpl_mainpage = 'step2.tpl';
546    $objPage->tpl_mode = 'step2';
547    return $objPage;
548}
549
550// STEP3画面の表示
551function lfDispStep3($objPage) {
552    global $objWebParam;
553    global $objDBParam;
554    // hiddenに入力値を保持
555    $objPage->arrHidden = $objWebParam->getHashArray();
556    // hiddenに入力値を保持
557    $objPage->arrHidden = array_merge($objPage->arrHidden, $objDBParam->getHashArray());
558    $objPage->arrHidden['agreement'] = $_POST['agreement'];
559    $objPage->tpl_db_skip = $_POST['db_skip'];
560    $objPage->tpl_mainpage = 'step3.tpl';
561    $objPage->tpl_mode = 'step3';
562    return $objPage;
563}
564
565// STEP4画面の表示
566function lfDispStep4($objPage) {
567    global $objWebParam;
568    global $objDBParam;
569    global $objDb;
570
571    // hiddenに入力値を保持
572    $objPage->arrHidden = $objWebParam->getHashArray();
573    $objPage->arrHidden = array_merge($objPage->arrHidden, $objDBParam->getHashArray());
574    // hiddenに入力値を保持
575    $objPage->arrHidden['agreement'] = $_POST['agreement'];
576
577    $normal_url = $objWebParam->getValue('normal_url');
578    // 語尾に'/'をつける
579    if (!ereg("/$", $normal_url)) $normal_url = $normal_url . "/";
580
581    $arrDbParam = $objDBParam->getHashArray();
582    if (!defined("DB_TYPE")) {
583        define("DB_TYPE", $arrDbParam['db_type']);
584    }
585    $dsn = $arrDbParam['db_type']."://".$arrDbParam['db_user'].":".$arrDbParam['db_password']."@".$arrDbParam['db_server'].":".$arrDbParam['db_port']."/".$arrDbParam['db_name'];
586
587    $objPage->tpl_site_url = $normal_url;
588    $objPage->tpl_shop_name = $objWebParam->getValue('shop_name');
589    $objPage->tpl_cube_ver = ECCUBE_VERSION;
590    $objPage->tpl_php_ver = phpversion();
591    $objPage->tpl_db_ver = $objDb->sfGetDBVersion($dsn);
592    $objPage->tpl_db_skip = $_POST['db_skip'];
593    $objPage->tpl_mainpage = 'step4.tpl';
594    $objPage->tpl_mode = 'complete';
595    return $objPage;
596}
597
598// 完了画面の表示
599function lfDispComplete($objPage) {
600    global $objWebParam;
601    global $objDBParam;
602    // hiddenに入力値を保持
603    $objPage->arrHidden = $objWebParam->getHashArray();
604    // hiddenに入力値を保持
605    $objPage->arrHidden = array_merge($objPage->arrHidden, $objDBParam->getHashArray());
606    $objPage->arrHidden['db_skip'] = $_POST['db_skip'];
607    $objPage->tpl_mainpage = 'complete.tpl';
608    $objPage->tpl_mode = 'complete';
609
610    $secure_url = $objWebParam->getValue('secure_url');
611    // 語尾に'/'をつける
612    if (!ereg("/$", $secure_url)) {
613        $secure_url = $secure_url . "/";
614    }
615    $objPage->tpl_sslurl = $secure_url;
616    return $objPage;
617}
618
619// WEBパラメータ情報の初期化
620function lfInitWebParam($objWebParam) {
621    global $objDb;
622
623    if(defined('HTTP_URL')) {
624        $normal_url = HTTP_URL;
625    } else {
626        $dir = ereg_replace("install/.*$", "", $_SERVER['REQUEST_URI']);
627        $normal_url = "http://" . $_SERVER['HTTP_HOST'] . $dir;
628    }
629
630    if(defined('HTTPS_URL')) {
631        $secure_url = HTTPS_URL;
632    } else {
633        $dir = ereg_replace("install/.*$", "", $_SERVER['REQUEST_URI']);
634        $secure_url = "http://" . $_SERVER['HTTP_HOST'] . $dir;
635    }
636
637    // 店名、管理者メールアドレスを取得する。(再インストール時)
638    if(defined('DEFAULT_DSN')) {
639        $objQuery = new SC_Query();
640        $tables = $objQuery->listTables();
641
642        if(!PEAR::isError($tables) && in_array("dtb_baseinfo", $tables)) {
643            $arrRet = $objQuery->select("shop_name, email01", "dtb_baseinfo");
644            $shop_name = $arrRet[0]['shop_name'];
645            $admin_mail = $arrRet[0]['email01'];
646        }
647    }
648
649    $objWebParam->addParam("店名", "shop_name", MTEXT_LEN, "", array("EXIST_CHECK","MAX_LENGTH_CHECK"), $shop_name);
650    $objWebParam->addParam("管理者:メールアドレス", "admin_mail", MTEXT_LEN, "", array("EXIST_CHECK","EMAIL_CHECK","EMAIL_CHAR_CHECK","MAX_LENGTH_CHECK"), $admin_mail);
651    $objWebParam->addParam("管理者:ログインID", "login_id", ID_MAX_LEN, "", array("EXIST_CHECK","SPTAB_CHECK", "ALNUM_CHECK"));
652    $objWebParam->addParam("管理者:パスワード", "login_pass", ID_MAX_LEN, "", array("EXIST_CHECK","SPTAB_CHECK", "ALNUM_CHECK"));
653    $objWebParam->addParam("URL(通常)", "normal_url", MTEXT_LEN, "", array("EXIST_CHECK","URL_CHECK","MAX_LENGTH_CHECK"), $normal_url);
654    $objWebParam->addParam("URL(セキュア)", "secure_url", MTEXT_LEN, "", array("EXIST_CHECK","URL_CHECK","MAX_LENGTH_CHECK"), $secure_url);
655    $objWebParam->addParam("ドメイン", "domain", MTEXT_LEN, "", array("MAX_LENGTH_CHECK"));
656
657    return $objWebParam;
658}
659
660// DBパラメータ情報の初期化
661function lfInitDBParam($objDBParam) {
662
663    if(defined('DB_SERVER')) {
664        $db_server = DB_SERVER;
665    } else {
666        $db_server = "127.0.0.1";
667    }
668
669    if(defined('DB_TYPE')) {
670        $db_type = DB_TYPE;
671    } else {
672        $db_type = "";
673    }
674
675    if(defined('DB_PORT')) {
676        $db_port = DB_PORT;
677    } else {
678        $db_port = "";
679    }
680
681    if(defined('DB_NAME')) {
682        $db_name = DB_NAME;
683    } else {
684        $db_name = "eccube_db";
685    }
686
687    if(defined('DB_USER')) {
688        $db_user = DB_USER;
689    } else {
690        $db_user = "eccube_db_user";
691    }
692
693    $objDBParam->addParam("DBの種類", "db_type", INT_LEN, "", array("EXIST_CHECK","MAX_LENGTH_CHECK"), $db_type);
694    $objDBParam->addParam("DBサーバ", "db_server", MTEXT_LEN, "", array("EXIST_CHECK","MAX_LENGTH_CHECK"), $db_server);
695    $objDBParam->addParam("DBポート", "db_port", INT_LEN, "", array("MAX_LENGTH_CHECK"), $db_port);
696    $objDBParam->addParam("DB名", "db_name", MTEXT_LEN, "", array("EXIST_CHECK","MAX_LENGTH_CHECK"), $db_name);
697    $objDBParam->addParam("DBユーザ", "db_user", MTEXT_LEN, "", array("EXIST_CHECK","MAX_LENGTH_CHECK"), $db_user);
698    $objDBParam->addParam("DBパスワード", "db_password", MTEXT_LEN, "", array("EXIST_CHECK","MAX_LENGTH_CHECK"));
699
700    return $objDBParam;
701}
702
703// 入力内容のチェック
704function lfCheckWebError($objFormParam) {
705    // 入力データを渡す。
706    $arrRet =  $objFormParam->getHashArray();
707    $objErr = new SC_CheckError($arrRet);
708    $objErr->arrErr = $objFormParam->checkError();
709
710    // ディレクトリ名のみ取得する
711    $normal_dir = ereg_replace("^https?://[a-zA-Z0-9_~=&\?\.\-]+", "", $arrRet['normal_url']);
712    $secure_dir = ereg_replace("^https?://[a-zA-Z0-9_~=&\?\.\-]+", "", $arrRet['secure_url']);
713
714    if($normal_dir != $secure_dir) {
715        $objErr->arrErr['normal_url'] = "URLに異なる階層を指定することはできません。";
716        $objErr->arrErr['secure_url'] = "URLに異なる階層を指定することはできません。";
717    }
718
719    // ログインIDチェック
720    $objErr->doFunc(array("管理者:ログインID",'login_id',ID_MIN_LEN , ID_MAX_LEN) ,array("SPTAB_CHECK" ,"NUM_RANGE_CHECK"));
721
722    // パスワードのチェック
723    $objErr->doFunc( array("管理者:パスワード",'login_pass',ID_MIN_LEN ,ID_MAX_LEN ) ,array("SPTAB_CHECK" ,"NUM_RANGE_CHECK" ));
724
725    return $objErr->arrErr;
726}
727
728// 入力内容のチェック
729function lfCheckDBError($objFormParam) {
730    global $objPage;
731
732    // 入力データを渡す。
733    $arrRet =  $objFormParam->getHashArray();
734
735    $objErr = new SC_CheckError($arrRet);
736    $objErr->arrErr = $objFormParam->checkError();
737
738    if(count($objErr->arrErr) == 0) {
739        // 接続確認
740        $dsn = $arrRet['db_type']."://".$arrRet['db_user'].":".$arrRet['db_password']."@".$arrRet['db_server'].":".$arrRet['db_port']."/".$arrRet['db_name'];
741        // Debugモード指定
742        $options['debug'] = PEAR_DB_DEBUG;
743        $objDB = MDB2::connect($dsn, $options);
744        // 接続成功
745        if(!PEAR::isError($objDB)) {
746            $dbFactory = SC_DB_DBFactory_Ex::getInstance();
747            // データベースバージョン情報の取得
748            $objPage->tpl_db_version = $dbFactory->sfGetDBVersion($dsn);
749        } else {
750            $objErr->arrErr['all'] = ">> " . $objDB->message . "<br>";
751            // エラー文を取得する
752            ereg("\[(.*)\]", $objDB->userinfo, $arrKey);
753            $objErr->arrErr['all'].= $arrKey[0] . "<br>";
754            GC_Utils_Ex::gfPrintLog($objDB->userinfo, INSTALL_LOG);
755        }
756    }
757    return $objErr->arrErr;
758}
759
760// SQL文の実行
761function lfExecuteSQL($filepath, $dsn, $disp_err = true) {
762    $arrErr = array();
763
764    if(!file_exists($filepath)) {
765        $arrErr['all'] = ">> スクリプトファイルが見つかりません";
766    } else {
767        if($fp = fopen($filepath,"r")) {
768            $sql = fread($fp, filesize($filepath));
769            fclose($fp);
770        }
771        // Debugモード指定
772        $options['debug'] = PEAR_DB_DEBUG;
773        $objDB = MDB2::connect($dsn, $options);
774        // 接続エラー
775        if(!PEAR::isError($objDB)) {
776            $sql_split = split(";",$sql);
777            foreach($sql_split as $key => $val){
778                SC_Utils::sfFlush();
779                if (trim($val) != "") {
780                    $ret = $objDB->query($val);
781                    if(PEAR::isError($ret) && $disp_err) {
782                        $arrErr['all'] = ">> " . $ret->message . "<br>";
783                        // エラー文を取得する
784                        ereg("\[(.*)\]", $ret->userinfo, $arrKey);
785                        $arrErr['all'].= $arrKey[0] . "<br>";
786                        $objPage->update_mess.=">> テーブル構成の変更に失敗しました。<br>";
787                        GC_Utils_Ex::gfPrintLog($ret->userinfo, INSTALL_LOG);
788                    } else {
789                        GC_Utils_Ex::gfPrintLog("OK:". $val, INSTALL_LOG);
790                    }
791                }
792            }
793        } else {
794            $arrErr['all'] = ">> " . $objDB->message;
795            GC_Utils_Ex::gfPrintLog($objDB->userinfo, INSTALL_LOG);
796        }
797    }
798    return $arrErr;
799}
800
801/**
802 * シーケンスを削除する.
803 *
804 * @param array $arrSequences シーケンスのテーブル名, カラム名の配列
805 * @param string $dsn データソース名
806 * @return array エラーが発生した場合はエラーメッセージの配列
807 */
808function lfDropSequence($arrSequences, $dsn) {
809    $arrErr = array();
810
811    // Debugモード指定
812    $options['debug'] = PEAR_DB_DEBUG;
813    $objDB = MDB2::connect($dsn, $options);
814    $objManager =& $objDB->loadModule('Manager');
815
816    // 接続エラー
817    if (!PEAR::isError($objDB)) {
818
819        $exists = $objManager->listSequences();
820        foreach ($arrSequences as $seq) {
821            $seq_name = $seq[0] . "_" . $seq[1];
822            if (in_array($seq_name, $exists)) {
823                $result = $objManager->dropSequence($seq_name);
824                if (PEAR::isError($result)) {
825                    $arrErr['all'] = ">> " . $result->message . "<br />";
826                    GC_Utils_Ex::gfPrintLog($result->userinfo, INSTALL_LOG);
827                } else {
828                    GC_Utils_Ex::gfPrintLog("OK:". $seq_name, INSTALL_LOG);
829                }
830            }
831        }
832    } else {
833        $arrErr['all'] = ">> " . $objDB->message;
834        GC_Utils_Ex::gfPrintLog($objDB->userinfo, INSTALL_LOG);
835    }
836    return $arrErr;
837}
838
839/**
840 * シーケンスを生成する.
841 *
842 * @param array $arrSequences シーケンスのテーブル名, カラム名の配列
843 * @param string $dsn データソース名
844 * @return array エラーが発生した場合はエラーメッセージの配列
845 */
846function lfCreateSequence($arrSequences, $dsn) {
847   $arrErr = array();
848
849    // Debugモード指定
850    $options['debug'] = PEAR_DB_DEBUG;
851    $objDB = MDB2::connect($dsn, $options);
852    $objManager =& $objDB->loadModule('Manager');
853
854    // 接続エラー
855    if (!PEAR::isError($objDB)) {
856
857        $exists = $objManager->listSequences();
858        foreach ($arrSequences as $seq) {
859            $res = $objDB->query("SELECT max(" . $seq[1] . ") FROM ". $seq[0]);
860            if (PEAR::isError($res)) {
861                $arrErr['all'] = ">> " . $res->userinfo . "<br />";
862                GC_Utils_Ex::gfPrintLog($res->userinfo, INSTALL_LOG);
863                return $arrErr;
864            }
865            $max = $res->fetchOne();
866
867            $seq_name = $seq[0] . "_" . $seq[1];
868            $result = $objManager->createSequence($seq_name, $max + 1);
869            if (PEAR::isError($result)) {
870                $arrErr['all'] = ">> " . $result->message . "<br />";
871                GC_Utils_Ex::gfPrintLog($result->userinfo, INSTALL_LOG);
872            } else {
873                GC_Utils_Ex::gfPrintLog("OK:". $seq_name, INSTALL_LOG);
874            }
875        }
876    } else {
877        $arrErr['all'] = ">> " . $objDB->message;
878        GC_Utils_Ex::gfPrintLog($objDB->userinfo, INSTALL_LOG);
879    }
880    return $arrErr;
881}
882
883// 設定ファイルの作成
884function lfMakeConfigFile() {
885    global $objWebParam;
886    global $objDBParam;
887   
888    $normal_url = $objWebParam->getValue('normal_url');
889    // 語尾に'/'をつける
890    if (!ereg("/$", $normal_url)) {
891        $normal_url = $normal_url . "/";
892    }
893
894    $secure_url = $objWebParam->getValue('secure_url');
895    // 語尾に'/'をつける
896    if (!ereg("/$", $secure_url)) {
897        $secure_url = $secure_url . "/";
898    }
899
900    // ディレクトリの取得
901    $url_dir = ereg_replace("^https?://[a-zA-Z0-9_:~=&\?\.\-]+", "", $normal_url);
902
903    $filepath = DATA_REALDIR . "install.php";
904
905    $config_data =
906    "<?php\n".
907    "    define ('ECCUBE_INSTALL', 'ON');\n" .
908    "    define ('HTTP_URL', '" . $normal_url . "');\n" .
909    "    define ('HTTPS_URL', '" . $secure_url . "');\n" .
910    "    define ('URL_PATH', '" . $url_dir . "');\n" .
911    "    define ('DOMAIN_NAME', '" . $objWebParam->getValue('domain') . "');\n" .
912    "    define ('DB_TYPE', '" . $objDBParam->getValue('db_type') . "');\n" .
913    "    define ('DB_USER', '" . $objDBParam->getValue('db_user') . "');\n" .
914    "    define ('DB_PASSWORD', '" . $objDBParam->getValue('db_password') . "');\n" .
915    "    define ('DB_SERVER', '" . $objDBParam->getValue('db_server') . "');\n" .
916    "    define ('DB_NAME', '" . $objDBParam->getValue('db_name') . "');\n" .
917    "    define ('DB_PORT', '" . $objDBParam->getValue('db_port') .  "');\n" .
918    "?>";
919
920    if($fp = fopen($filepath,"w")) {
921        fwrite($fp, $config_data);
922        fclose($fp);
923    }
924}
925
926/**
927 * $dir を再帰的に辿ってパス名を配列で返す.
928 *
929 * @param string 任意のパス名
930 * @return array $dir より下層に存在するパス名の配列
931 * @see http://www.php.net/glob
932 */
933$alldirs = array();
934function listdirs($dir) {
935    global $alldirs;
936    $dirs = glob($dir . '/*');
937    if (is_array($dirs) && count($dirs) > 0) {
938        foreach ($dirs as $d) {
939            $alldirs[] = $d;
940            listdirs($d);
941        }
942    }
943    return $alldirs;
944}
945
946/**
947 * 保持したスタティック変数をクリアする。
948 */
949function initdirs() {
950    global $alldirs;
951    $alldirs = array();
952}
953
954/**
955 * シーケンスを使用するテーブル名とカラム名の配列を返す.
956 *
957 * @return array シーケンスを使用するテーブル名とカラム名の配列
958 */
959function getSequences() {
960    return array(array("dtb_best_products","best_id"),
961                 array("dtb_bloc", "bloc_id"),
962                 array("dtb_category", "category_id"),
963                 array("dtb_class", "class_id"),
964                 array("dtb_classcategory", "classcategory_id"),
965                 array("dtb_csv", "no"),
966                 array("dtb_csv_sql", "sql_id"),
967                 array("dtb_customer", "customer_id"),
968                 array("dtb_deliv", "deliv_id"),
969                 array("dtb_holiday", "holiday_id"),
970                 array("dtb_kiyaku", "kiyaku_id"),
971                 array("dtb_mail_history", "send_id"),
972                 array("dtb_maker", "maker_id"),
973                 array("dtb_member", "member_id"),
974                 array("dtb_mobile_kara_mail", "kara_mail_id"),
975                 array("dtb_module_update_logs", "log_id"),
976                 array("dtb_news", "news_id"),
977                 array("dtb_order", "order_id"),
978                 array("dtb_other_deliv", "other_deliv_id"),
979                 array("dtb_pagelayout", "page_id"),
980                 array("dtb_payment", "payment_id"),
981                 array("dtb_products_class", "product_class_id"),
982                 array("dtb_products", "product_id"),
983                 array("dtb_class_combination", "class_combination_id"),
984                 array("dtb_review", "review_id"),
985                 array("dtb_send_history", "send_id"),
986                 array("dtb_site_control", "control_id"),
987                 array("dtb_table_comment", "id"),
988                 array("dtb_trackback", "trackback_id"));
989}
990?>
Note: See TracBrowser for help on using the repository browser.