$_SESSION['language'] = 'en_us'; } } // include the list of project database tables require DIR_FS_INCLUDES . 'database_tables.php'; // include the list of project security tokens require DIR_FS_INCLUDES . 'security_tokens.php'; // include the database functions if ($use_db) { require DIR_FS_FUNCTIONS . 'database.php'; // Load queryFactory db classes require DIR_FS_CLASSES . 'db/' . DB_TYPE . '/query_factory.php'; $db = new queryFactory(); $db->connect(DB_SERVER, DB_SERVER_USERNAME, DB_SERVER_PASSWORD, DB_SERVER_NAME); // set application wide parameters for phreebooks module $configuration = $db->Execute_return_error("select configuration_key as cfgKey, configuration_value as cfgValue\r\n\t\t\t\t\t\t\t\t from " . TABLE_CONFIGURATION); if ($db->error_number) { // there was a problem, report and halt die('There was an error returned while retrieving the configuration data.<br />PhreeBooks was able to connect to the database but could not find the configuration table. Looks like the table is missing! Options include deleting /includes/configure.php and re-installing (for new installations) or restoring the database tables (database crash).'); } while (!$configuration->EOF) { define($configuration->fields['cfgKey'], $configuration->fields['cfgValue']); $configuration->MoveNext(); } // Define the project version (must come after db class is loaded) require DIR_FS_INCLUDES . 'version.php'; // Determine the DATABASE patch level $project_db_info = $db->Execute("select * from " . TABLE_PROJECT_VERSION . " WHERE project_version_key = 'PhreeBooks Database' "); define('PROJECT_DB_VERSION_MAJOR', $project_db_info->fields['project_version_major']); define('PROJECT_DB_VERSION_MINOR', $project_db_info->fields['project_version_minor']); if (PROJECT_VERSION_MAJOR . PROJECT_VERSION_MINOR != PROJECT_DB_VERSION_MAJOR . PROJECT_DB_VERSION_MINOR) {
// use default $messageStack = new messageStack(); $toolbar = new toolbar(); // determine what company to connect to $db_company = isset($_SESSION['company']) ? $_SESSION['company'] : $_SESSION['companies'][$_POST['company']]; if ($db_company && file_exists(DIR_FS_MY_FILES . $db_company . '/config.php')) { define('DB_DATABASE', $db_company); require_once DIR_FS_MY_FILES . $db_company . '/config.php'; define('DB_SERVER_HOST', DB_SERVER); // for old PhreeBooks installs // Load queryFactory db classes require_once DIR_FS_INCLUDES . 'db/' . DB_TYPE . '/query_factory.php'; $db = new queryFactory(); $db->connect(DB_SERVER_HOST, DB_SERVER_USERNAME, DB_SERVER_PASSWORD, DB_DATABASE); // set application wide parameters for phreebooks module $result = $db->Execute_return_error("select configuration_key, configuration_value from " . DB_PREFIX . "configuration"); if ($db->error_number != '' || $result->RecordCount() == 0) { trigger_error(LOAD_CONFIG_ERROR, E_USER_ERROR); } while (!$result->EOF) { define($result->fields['configuration_key'], $result->fields['configuration_value']); $result->MoveNext(); } // search the list modules and load configuration files and language files gen_pull_language('phreedom', 'menu'); gen_pull_language('phreebooks', 'menu'); require_once DIR_FS_MODULES . 'phreedom/config.php'; $messageStack->debug_header(); $loaded_modules = array(); $dirs = scandir(DIR_FS_MODULES); foreach ($dirs as $dir) {
$cb_users = isset($_POST['users']) ? 1 : 0; // error check company name and company full name if (!$company || !$company_name) { $messageStack->add(SETUP_CO_MGR_ERROR_EMPTY_FIELD, 'error'); break; } if ($company == $_SESSION['company']) { $messageStack->add(SETUP_CO_MGR_DUP_DB_NAME, 'error'); break; } // check for database already exists $db_old = new queryFactory(); $db_old->connect($_SESSION['db_server'], $_SESSION['db_user'], $_SESSION['db_pw'], $_SESSION['company']); $db = new queryFactory(); if (!$db->connect($db_server, $db_user, $db_pw, $company)) { $result = $db_old->Execute_return_error("create database " . $company); if ($db_old->error_number) { $messageStack->add('DB Error # ' . $db_old->error_number . ' ' . $db_old->error_text, 'error'); $messageStack->add(SETUP_CO_MGR_NO_DB, 'error'); break; } else { if (!$db->connect(DB_SERVER, $db_user, $db_pw, $company)) { $messageStack->add(SETUP_CO_MGR_CANNOT_CONNECT, 'error'); break; } } } $result = db_executeSql(DIR_FS_MODULES . 'install/sql/current/tables.sql', $company, DB_PREFIX); if (count($result['errors']) > 0) { $messageStack->add(SETUP_CO_MGR_ERROR_1, 'error'); break;