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

Revision 18790, 34.4 KB checked in by nanasess, 14 years ago (diff)

#801 の改善に伴い MDB2 の関数に置き替えと, 未使用関数の削除

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