diff --git a/app/classes/database.php b/app/classes/database.php index b5b3519..01f14a9 100644 --- a/app/classes/database.php +++ b/app/classes/database.php @@ -1,17 +1,19 @@ connectMysql($options); break; default: - throw newException("Database type \"{$options['type']}\" is not supported."); + $error = getError("Database type \"{$options['type']}\" is not supported."); } } private function connectSqlite($options) { // pdo_sqlite extension is needed if (!extension_loaded('pdo_sqlite')) { - throw new Exception('PDO extension for SQLite not loaded.'); + $error = getError('PDO extension for SQLite not loaded.'); } // SQLite options if (empty($options['dbFile']) || !file_exists($options['dbFile'])) { - throw new Exception('SQLite database file not found.'); + $error = getError("SQLite database file \"{$dbFile}\" not found."); } // connect to SQLite @@ -43,19 +45,19 @@ class Database { $this->pdo = new PDO("sqlite:" . $options['dbFile']); $this->pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); } catch (PDOException $e) { - throw new Exception('SQLite connection failed: ' . $e->getMessage()); + $error = getError('SQLite connection failed: ', $e->getMessage()); } } private function connectMysql($options) { // pdo_mysql extension is needed if (!extension_loaded('pdo_mysql')) { - throw new Exception('PDO extension for MySQL not loaded.'); + $error = getError('PDO extension for MySQL not loaded.'); } // MySQL options if (empty($options['host']) || empty($options['dbname']) || empty($options['user'])) { - throw new Exception('MySQL connection data is missing.'); + $error = getError('MySQL connection data is missing.'); } // Connect to MySQL @@ -64,7 +66,7 @@ class Database { $this->pdo = new PDO($dsn, $options['user'], $options['password'] ?? ''); $this->pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); } catch (PDOException $e) { - throw new Exception('MySQL connection failed: ' . $e->getMessage()); + $error = getError('MySQL connection failed: ', $config['environment'], $e->getMessage()); } } diff --git a/app/config/jilo-web.conf.php b/app/config/jilo-web.conf.php index 2a0c975..a5dfd11 100644 --- a/app/config/jilo-web.conf.php +++ b/app/config/jilo-web.conf.php @@ -29,7 +29,7 @@ return [ // system info 'version' => '0.1.1', // development has verbose error messages, production has not - 'environment' => 'production', + 'environment' => 'production1', // ************************************* // Maintained by the app, edit with care diff --git a/app/helpers/database.php b/app/helpers/database.php index fa13a4e..c32b0ad 100644 --- a/app/helpers/database.php +++ b/app/helpers/database.php @@ -7,19 +7,15 @@ function connectDB($config, $database = '', $platform_id = '') { if ($database === 'jilo') { try { $dbFile = $config['platforms'][$platform_id]['jilo_database'] ?? null; - if (!$dbFile) { - throw new Exception("Invalid platform ID \"$platform_id\", database file not found."); + if (!$dbFile || !file_exists($dbFile)) { + throw new Exception(getError("Invalid platform ID \"{$platform_id}\", database file \"{$dbFile}\"not found.")); } $db = new Database([ 'type' => 'sqlite', 'dbFile' => $dbFile, ]); } catch (Exception $e) { - if ($config['environment'] === 'production') { - $error = 'There was an unexpected error. Please try again.'; - } else { - $error = 'Error: ' . $e->getMessage(); - } + $error = getError('Error connecting to DB.', $e->getMessage()); include '../app/templates/block-message.php'; exit(); } @@ -36,7 +32,7 @@ function connectDB($config, $database = '', $platform_id = '') { ]); $pdo = $db->getConnection(); } catch (Exception $e) { - $error = 'Error: ' . $e->getMessage(); + $error = getError('Error connecting to DB.', $e->getMessage()); include '../app/templates/block-message.php'; exit(); } @@ -53,7 +49,7 @@ function connectDB($config, $database = '', $platform_id = '') { ]); $pdo = $db->getConnection(); } catch (Exception $e) { - $error = 'Error: ' . $e->getMessage(); + $error = getError('Error connecting to DB.', $e->getMessage()); include '../app/templates/block-message.php'; exit(); } diff --git a/app/helpers/errors.php b/app/helpers/errors.php new file mode 100644 index 0000000..6695a64 --- /dev/null +++ b/app/helpers/errors.php @@ -0,0 +1,14 @@ + diff --git a/app/pages/components.php b/app/pages/components.php index bc2fbf1..3e5f0b9 100644 --- a/app/pages/components.php +++ b/app/pages/components.php @@ -5,7 +5,7 @@ require '../app/classes/component.php'; // connect to database require '../app/helpers/database.php'; -$db = connectDB($config, 'jilo'); +$db = connectDB($config, 'jilo', $platform_id); // specify time range include '../app/helpers/time_range.php'; diff --git a/app/pages/conferences.php b/app/pages/conferences.php index f67a6d0..f023ffb 100644 --- a/app/pages/conferences.php +++ b/app/pages/conferences.php @@ -5,7 +5,7 @@ require '../app/classes/conference.php'; // connect to database require '../app/helpers/database.php'; -$db = connectDB($config, 'jilo'); +$db = connectDB($config, 'jilo', $platform_id); // specify time range include '../app/helpers/time_range.php'; diff --git a/app/pages/front.php b/app/pages/front.php index 01683ff..b2f4143 100644 --- a/app/pages/front.php +++ b/app/pages/front.php @@ -4,9 +4,6 @@ require_once '../app/classes/database.php'; require '../app/classes/conference.php'; require '../app/classes/participant.php'; -// by default we connect ot the first configured platform -$platform_id = $_REQUEST['platform'] ?? '0'; - // connect to database require '../app/helpers/database.php'; $db = connectDB($config, 'jilo', $platform_id); diff --git a/app/pages/login.php b/app/pages/login.php index 6d9f5ef..f731813 100644 --- a/app/pages/login.php +++ b/app/pages/login.php @@ -57,7 +57,7 @@ try { } } } catch (Exception $e) { - $error = $e->getMessage(); + $error = getError('There was an unexpected error. Please try again.', $e->getMessage()); } if (!empty($config['login_message'])) { diff --git a/app/pages/participants.php b/app/pages/participants.php index 0a0966b..f9f546a 100644 --- a/app/pages/participants.php +++ b/app/pages/participants.php @@ -5,7 +5,7 @@ require '../app/classes/participant.php'; // connect to database require '../app/helpers/database.php'; -$db = connectDB($config, 'jilo'); +$db = connectDB($config, 'jilo', $platform_id); // specify time range include '../app/helpers/time_range.php'; diff --git a/app/pages/register.php b/app/pages/register.php index d6be857..ae5ff1b 100644 --- a/app/pages/register.php +++ b/app/pages/register.php @@ -32,7 +32,7 @@ if ($config['registration_enabled'] === true) { } } } catch (Exception $e) { - $error = $e->getMessage(); + $error = getError('There was an unexpected error. Please try again.', $e->getMessage()); } include '../app/templates/block-message.php'; diff --git a/public_html/index.php b/public_html/index.php index fa28216..94e1c80 100644 --- a/public_html/index.php +++ b/public_html/index.php @@ -87,6 +87,9 @@ if (isset($_SESSION['error'])) { $error = $_SESSION['error']; } +// by default we connect ot the first configured platform +$platform_id = $_REQUEST['platform'] ?? '0'; + // page building if (in_array($page, $allowed_urls)) { // logout is a special case, as we can't use session vars for notices