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

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