/**
  * DBのチェック
  * @return boolean
  * @access  private
  */
 function _chkDb()
 {
     $result = true;
     if (!$this->installCompmain->getSessionDb($database, $dbhost, $dbusername, $dbpass, $dbname, $dbprefix, $dbpersist, $dsn)) {
         // 接続エラー
         $result = false;
         $this->dbcheck_res_arr[] = INSTALL_IMG_NO . INSTALL_DBCHECK_SERVER_NOT_CONNECT;
         return $result;
     }
     //$base_dir = $this->session->getParameter("base_dir");
     //include_once $base_dir.'/maple/nccore/db/DbObjectAdodb.class.php';
     include_once BASE_DIR . '/maple/nccore/db/DbObjectAdodb.class.php';
     $conn =& NewADOConnection($database);
     // 接続チェック
     if (!$conn->Connect($dbhost, $dbusername, $dbpass)) {
         // 接続エラー
         $result = false;
         $this->dbcheck_res_arr[] = INSTALL_IMG_NO . INSTALL_DBCHECK_SERVER_NOT_CONNECT;
         return $result;
     } else {
         $this->dbcheck_res_arr[] = INSTALL_IMG_YES . INSTALL_DBCHECK_SERVER_CONNECT;
     }
     $dbObject = new DbObjectAdodb();
     $dbObject->setPrefix($dbprefix);
     $dbObject->setDsn($dsn);
     $conn_result = @$dbObject->connect();
     if ($conn_result == false) {
         // DBが存在しない場合、CREATE DATABASE
         $this->dbcheck_res_arr[] = INSTALL_IMG_NO . sprintf(INSTALL_DBCHECK_NOT_CONNECT, $dbname) . "<div class=\"install_checkdb_createdb\">" . INSTALL_DBCHECK_NOT_FOUND . "</div>" . "<div class=\"install_checkdb_createdb bold\">&nbsp;&nbsp;" . $dbname . "</div>" . "<div class=\"install_checkdb_createdb\">" . INSTALL_DBCHECK_CONFIRM_CREATE_DB . "</div>";
         $this->db_create_flag = true;
         $this->reload_flag = true;
         $result = false;
     } else {
         // DBが存在する場合
         $result_db = $dbObject->execute("SELECT * FROM {modules}", array(), 1);
         if ($result_db === false) {
             // モジュールテーブルが存在しない場合、正常終了
             // 1.1と同じテーブル名称のものを指定している
             $this->dbcheck_res_arr[] = INSTALL_IMG_YES . sprintf(INSTALL_DBCHECK_CONNECT, $dbname);
         } else {
             // モジュールテーブルが存在する場合
             $this->dbcheck_res_arr[] = INSTALL_IMG_YES . sprintf(INSTALL_DBCHECK_CONNECT, $dbname);
             $this->dbcheck_res_arr[] = INSTALL_IMG_NO . INSTALL_DBCHECK_EXIST_TABLE;
             $this->reload_flag = true;
             $result = false;
         }
     }
     return $result;
 }
 /**
  * Install サイト管理者についての設定セッション登録
  *
  * @access  public
  */
 function execute()
 {
     $base_dir = $this->session->getParameter("base_dir");
     $this->session->setParameter("install_handle", $this->handle);
     $this->session->setParameter("install_login_id", $this->login_id);
     $this->session->setParameter("install_pass", $this->password);
     $this->session->setParameter("install_confirm_pass", $this->confirm_pass);
     if (!$this->installCompmain->getSessionDb($database, $dbhost, $dbusername, $dbpass, $dbname, $dbprefix, $dbpersist, $dsn)) {
         // DB接続失敗
         $errorList->add(get_class($this), sprintf(INSTALL_DBCHECK_NOT_CONNECT, $dbname));
         return 'error';
     }
     $errorList =& $this->actionChain->getCurErrorList();
     //
     // DB接続
     //
     //include_once $base_dir.'/maple/nccore/db/DbObjectAdodb.class.php';
     include_once BASE_DIR . '/maple/nccore/db/DbObjectAdodb.class.php';
     $dbObject = new DbObjectAdodb();
     $dbObject->setPrefix($dbprefix);
     $dbObject->setDsn($dsn);
     $conn_result = @$dbObject->connect();
     if ($conn_result == false) {
         // DB接続失敗
         $errorList->add(get_class($this), sprintf(INSTALL_DBCHECK_NOT_CONNECT, $dbname));
         return 'error';
     }
     $result = $dbObject->selectExecute("users", array("system_flag" => _ON), null, 1);
     if ($result === false) {
         return 'error';
     }
     if (isset($result[0])) {
         // 既にデータが存在
         // ありえないので、エラーとする
         $errorList->add(get_class($this), sprintf(INSTALL_DBCHECK_NOT_CONNECT, $dbname));
         return 'error';
     } else {
         // インサート
         // insUserと同等の処理だが、_dbが使えないため、ここに記述
         // サイトIDもまだ生成されていないのでサイトIDから生成(insertSite)と同等の処理
         $sessionID = $this->session->getID();
         $new_site_id = sha1(uniqid($sessionID . microtime(), true));
         $id = $dbObject->nextSeq("users");
         $user_id = sha1(uniqid($new_site_id . $id, true));
         $this->session->setParameter("install_self_site_id", $new_site_id);
         $this->session->setParameter("install_user_id", $user_id);
         $params = array("site_id" => $new_site_id, "url" => "BASE_URL", "self_flag" => _ON, "commons_flag" => _ON, "certify_flag" => _ON, "insert_time " => "", "insert_site_id " => $new_site_id, "insert_user_id " => $user_id, "insert_user_name " => "", "update_time " => "", "update_site_id " => $new_site_id, "update_user_id " => $user_id, "update_user_name " => "");
         $result = $dbObject->insertExecute("sites", $params);
         if ($result === false) {
             return 'error';
         }
         $timezone_offset = -1 * INSTALL_DEFAULT_TIMEZONE;
         $time = date("YmdHis");
         $int_time = mktime(intval(substr($time, 8, 2)) + $timezone_offset, intval(substr($time, 10, 2)), intval(substr($time, 12, 2)), intval(substr($time, 4, 2)), intval(substr($time, 6, 2)), intval(substr($time, 0, 4)));
         $insert_time = date("YmdHis", $int_time);
         $params = array("user_id" => $user_id, "login_id" => $this->login_id, "password" => md5($this->password), "handle" => $this->handle, "role_authority_id" => _SYSTEM_ROLE_AUTH_ID, "active_flag" => _ON, "system_flag" => _ON, "activate_key" => "", "lang_dirname" => $this->session->getParameter("_lang"), "timezone_offset" => INSTALL_DEFAULT_TIMEZONE, "password_regist_time" => $insert_time, "last_login_time " => "", "previous_login_time " => "", "insert_time " => $insert_time, "insert_site_id " => $new_site_id, "insert_user_id " => $user_id, "insert_user_name " => $this->handle, "update_time " => $insert_time, "update_site_id " => $new_site_id, "update_user_id " => $user_id, "update_user_name " => $this->handle);
         $result = $dbObject->insertExecute("users", $params, false);
         if ($result === false) {
             return 'error';
         }
     }
     return 'success';
 }
 /**
  * テーブル作成
  * 
  * @return boolean
  * @access  private
  */
 function _createTable()
 {
     $base_dir = $this->session->getParameter("base_dir");
     if (!$this->installCompmain->getSessionDb($database, $dbhost, $dbusername, $dbpass, $dbname, $dbprefix, $dbpersist, $dsn)) {
         return false;
     }
     //
     // 共通テーブルCreate
     //
     $file_path = "/install/sql/" . $database . "/" . _SYS_TABLE_INI;
     if (!@file_exists(MODULE_DIR . $file_path)) {
         // mysqliならば、mysqlがあればそちらを使う
         if ($database != "mysqli") {
             return false;
         }
         $database = "mysql";
         $file_path = "/install/sql/" . $database . "/" . _SYS_TABLE_INI;
         if (!@file_exists(MODULE_DIR . $file_path)) {
             return false;
         }
     }
     //モジュールに使用するテーブルあり
     // SQLファイルの読み込み
     $handle = fopen(MODULE_DIR . $file_path, 'r');
     $sql_query = fread($handle, filesize(MODULE_DIR . $file_path));
     fclose($handle);
     $sql_query = trim($sql_query);
     // SQLユーティリティクラスにて各クエリを配列に格納する
     $this->databaseSqlutility->splitMySqlFile($pieces, $sql_query);
     //
     // DB接続
     //
     //include_once $base_dir.'/maple/nccore/db/DbObjectAdodb.class.php';
     include_once BASE_DIR . '/maple/nccore/db/DbObjectAdodb.class.php';
     $dbObject = new DbObjectAdodb();
     $dbObject->setPrefix($dbprefix);
     $dbObject->setDsn($dsn);
     $conn_result = @$dbObject->connect();
     if ($conn_result == false) {
         // DBが存在しない場合、CREATE DATABASE
         $this->res_arr[] = INSTALL_IMG_NO . sprintf(INSTALL_DBCHECK_NOT_CONNECT, $dbname) . "<div class=\"install_checkdb_createdb\">" . INSTALL_DBCHECK_NOT_FOUND . "</div>" . "<div class=\"install_checkdb_createdb bold\">&nbsp;&nbsp;" . $dbname . "</div>" . "<div class=\"install_checkdb_createdb\">" . INSTALL_DBCHECK_CONFIRM_CREATE_DB . "</div>";
         return false;
     }
     // DBが存在する場合
     $result = true;
     foreach ($pieces as $piece) {
         // SQLユーティリティクラスにてテーブル名にプレフィックスをつける
         // 配列としてリターンされ、
         // 	[0] プレフィックスをつけたクエリ
         // 	[4] プレフィックスをつけないテーブル名
         // が格納されている
         $prefixed_query = $this->databaseSqlutility->prefixQuery($piece, $dbObject->getPrefix());
         if (!$prefixed_query) {
             $this->res_arr[] = INSTALL_IMG_NO . sprintf(INSTALL_TBCREATE_FAILED_CREATE, $dbObject->getPrefix() . $prefixed_query[4]);
             $result = false;
             continue;
         }
         // 実行
         if (!$dbObject->execute($prefixed_query[0])) {
             $this->res_arr[] = INSTALL_IMG_NO . sprintf(INSTALL_TBCREATE_FAILED_CREATE, $dbObject->getPrefix() . $prefixed_query[4]);
             $result = false;
             continue;
         } else {
             // 成功
             $this->res_arr[] = INSTALL_IMG_YES . sprintf(INSTALL_TBCREATE_SUCCESS_CREATE, $dbObject->getPrefix() . $prefixed_query[4]);
         }
     }
     return $result;
 }
 /**
  * SQLファイル実行
  * param string $file_name
  * param string $type
  *
  * @access	public
  */
 function executeSqlFile($file_name, $type = "default")
 {
     $res_arr = array();
     $result = false;
     $_lang = $this->_session->getParameter("_lang");
     $base_dir = $this->_session->getParameter("base_dir");
     $sitename = addslashes($this->_session->getParameter("sitename"));
     $modulesView =& $this->_container->getComponent("modulesView");
     //$modules[$dir_name], $self_site_id, $private_room_name, $admin_user_id
     $self_site_id = $this->_session->getParameter("install_self_site_id");
     $admin_user_id = $this->_session->getParameter("install_user_id");
     $admin_login_id = $this->_session->getParameter("install_login_id");
     $admin_handle = addslashes($this->_session->getParameter("install_handle"));
     $permalink = preg_replace(_PERMALINK_PROHIBITION, _PERMALINK_PROHIBITION_REPLACE, $admin_handle);
     $this->getSessionDb($database, $dbhost, $dbusername, $dbpass, $dbname, $dbprefix, $dbpersist, $dsn);
     //
     // DB接続
     //
     //include_once $base_dir.'/maple/nccore/db/DbObjectAdodb.class.php';
     include_once BASE_DIR . '/maple/nccore/db/DbObjectAdodb.class.php';
     $dbObject = new DbObjectAdodb();
     $dbObject->setPrefix($dbprefix);
     $dbObject->setDsn($dsn);
     $conn_result = @$dbObject->connect();
     if ($conn_result == false) {
         // DB接続失敗
         $res_arr[] = INSTALL_IMG_NO . sprintf(INSTALL_DBCHECK_NOT_CONNECT, $dbname);
         return array($result, $res_arr);
     }
     // $modules[$dir_name]
     $modules = $dbObject->execute("SELECT {modules}.* FROM {modules}", array(), null, null, true, array($this, "_fetchcallbackModules"), array($modulesView));
     if ($modules === false) {
         // とりあえずDB接続失敗のエラーメッセージとする
         $res_arr[] = INSTALL_IMG_NO . sprintf(INSTALL_DBCHECK_NOT_CONNECT, $dbname);
         return array($result, $res_arr);
     }
     $databaseSqlutility =& $this->_container->getComponent("databaseSqlutility");
     $config_db_kind = $database;
     $lang_file_path = $base_dir . '/webapp/modules/install/language/' . $_lang . '/' . $file_name;
     if (!@file_exists($lang_file_path)) {
         $_lang = "english";
         $lang_file_path = $base_dir . '/webapp/modules/install/language/' . $_lang . '/' . $file_name;
     }
     include_once $lang_file_path;
     if (defined(strtoupper("INSTALL_CONF_ADD_PRIVATE_SPACE_NAME_" . $_lang))) {
         $private_room_name = str_replace("{X-HANDLE}", $admin_handle, constant(strtoupper('INSTALL_CONF_ADD_PRIVATE_SPACE_NAME_' . $_lang)));
         $this->_session->setParameter("install_private_room_name", $private_room_name);
     } else {
         $private_room_name = $this->_session->getParameter("install_private_room_name");
     }
     $file_path = $base_dir . '/webapp/modules/install/sql/' . $database . '/' . $type . "/" . $file_name;
     if (!@file_exists($file_path) && $database == "mysqli") {
         $database = "mysql";
         $file_path = $base_dir . '/webapp/modules/install/sql/' . $database . '/' . $type . "/" . $file_name;
     }
     $data = "";
     include_once $file_path;
     if ($file_name == INSTALL_CONFIG_DATA_FILENAME) {
         $config_lang_sql = '';
         $languages = array('japanese', 'english', 'chinese');
         $items = explode(',', _MULTI_LANG_CONFIG_ITEMS);
         foreach ($languages as $lang_dirname) {
             include_once $base_dir . '/webapp/modules/install/language/' . $lang_dirname . '/' . $file_name;
             foreach ($items as $item) {
                 if ($item == 'sitename') {
                     $conf_value = $sitename;
                 } else {
                     if ($item == 'from') {
                         $conf_value = 'netcommons';
                     } else {
                         $conf_value = constant(strtoupper('INSTALL_CONF_' . $item . '_' . $lang_dirname));
                     }
                 }
                 $config_lang_sql .= "INSERT INTO `config_language` (`conf_name`, `lang_dirname`, `conf_value`) VALUES ('" . $item . "', '" . $lang_dirname . "', '" . $conf_value . "');";
             }
         }
         $data .= $config_lang_sql;
     }
     $databaseSqlutility->splitMySqlFile($pieces, $data);
     $result = true;
     $config_success_count = 0;
     $config_failed_count = 0;
     $adodb =& $dbObject->getAdoDbObject();
     $savetable_name = "";
     foreach ($pieces as $piece) {
         // SQLユーティリティクラスにてテーブル名にプレフィックスをつける
         // 配列としてリターンされ、
         // 	[0] プレフィックスをつけたクエリ
         // 	[4] プレフィックスをつけないテーブル名
         // が格納されている
         $prefixed_query = $databaseSqlutility->prefixQuery($piece, $dbObject->getPrefix());
         //$prefixed_query_result = true;
         if (!$prefixed_query) {
             //$prefixed_query_result = false;
             $result = false;
             $res_arr[] = INSTALL_IMG_NO . sprintf(INSTALL_INSERT_DATA_FAILED_INSERT, 1, "Unknown Table");
             continue;
         }
         if ($savetable_name != $prefixed_query[4]) {
             // テーブルが変わった
             if ($savetable_name != "") {
                 // メッセージ
                 if ($config_success_count > 0) {
                     // 成功
                     $res_arr[] = INSTALL_IMG_YES . sprintf(INSTALL_INSERT_DATA_SUCCESS_INSERT, $config_success_count, $savetable_name);
                 }
                 if ($config_failed_count > 0) {
                     $result = false;
                     $res_arr[] = INSTALL_IMG_NO . sprintf(INSTALL_INSERT_DATA_FAILED_INSERT, $config_failed_count, $savetable_name);
                 }
                 $config_success_count = 0;
                 $config_failed_count = 0;
             }
             $savetable_name = $prefixed_query[4];
         }
         // 実行
         //$dbObject->executeはprefixの変換処理があるため使用しない
         if (!$adodb->Execute($prefixed_query[0])) {
             $config_failed_count++;
             $result = false;
             //continue;
         } else {
             // 成功
             $config_success_count++;
         }
     }
     if ($savetable_name != "") {
         // メッセージ
         if ($config_success_count > 0) {
             // 成功
             $res_arr[] = INSTALL_IMG_YES . sprintf(INSTALL_INSERT_DATA_SUCCESS_INSERT, $config_success_count, $savetable_name);
         }
         if ($config_failed_count > 0) {
             $result = false;
             $res_arr[] = INSTALL_IMG_NO . sprintf(INSTALL_INSERT_DATA_FAILED_INSERT, $config_failed_count, $savetable_name);
         }
         //$config_success_count = 0;
         //$config_failed_count = 0;
     }
     return array($result, $res_arr);
 }