diff --git a/app/helpers/database.php b/app/helpers/database.php index db56adc..a97e86c 100644 --- a/app/helpers/database.php +++ b/app/helpers/database.php @@ -13,10 +13,9 @@ function connectDB($config, $database = '', $dbFile = '', $platformId = '') { 'type' => 'sqlite', 'dbFile' => $dbFile, ]); + return ['db' => $db, 'error' => null]; } catch (Exception $e) { - $error = getError('Error connecting to DB.', $e->getMessage()); - include '../app/templates/block-message.php'; - exit(); + return ['db' => null, 'error' => getError('Error connecting to DB.', $e->getMessage())]; } // connecting to a jilo-web database of the web app @@ -30,10 +29,12 @@ function connectDB($config, $database = '', $dbFile = '', $platformId = '') { 'dbFile' => $config['db']['sqlite_file'], ]); $pdo = $db->getConnection(); + return $db; } catch (Exception $e) { $error = getError('Error connecting to DB.', $e->getMessage()); - include '../app/templates/block-message.php'; - exit(); + return $error; +// include '../app/templates/block-message.php'; +// exit(); } // mysql/mariadb database } elseif ($config['db']['db_type'] === 'mysql' || $config['db']['db_type'] === 'mariadb') { @@ -47,10 +48,12 @@ function connectDB($config, $database = '', $dbFile = '', $platformId = '') { 'password' => $config['db']['sql_password'], ]); $pdo = $db->getConnection(); + return $db; } catch (Exception $e) { $error = getError('Error connecting to DB.', $e->getMessage()); - include '../app/templates/block-message.php'; - exit(); + return $error; +// include '../app/templates/block-message.php'; +// exit(); } // unknown database } else { @@ -61,6 +64,6 @@ function connectDB($config, $database = '', $dbFile = '', $platformId = '') { } - return $db; +// return $db; } ?> diff --git a/app/pages/dashboard.php b/app/pages/dashboard.php index a8e268a..32b0097 100644 --- a/app/pages/dashboard.php +++ b/app/pages/dashboard.php @@ -4,8 +4,13 @@ require '../app/classes/conference.php'; require '../app/classes/participant.php'; // connect to database -$db = connectDB($config, 'jilo', $platformDetails[0]['jilo_database'], $platform_id); - +$response = connectDB($config, 'jilo', $platformDetails[0]['jilo_database'], $platform_id); +if ($response['db'] === null) { + $error = $response['error']; + include '../app/templates/block-message.php'; +} else { + $db = $response['db']; +} // // dashboard widget listings diff --git a/app/templates/block-message.php b/app/templates/block-message.php index 35d52f0..c078db0 100644 --- a/app/templates/block-message.php +++ b/app/templates/block-message.php @@ -1,13 +1,24 @@ ' . $_SESSION['error'] . ''; } -// 'error' for errors +// 'notice' for all non-critical messages if (isset($_SESSION['notice'])) { echo "\t\t" . '
' . $_SESSION['notice'] . '
'; } +// 'error' for errors +if (isset($error)) { + echo "\t\t" . '
' . $error . '
'; +} + +// 'notice' for all non-critical messages +if (isset($_SESSION['notice'])) { + echo "\t\t" . '
' . $_SESSION['notice'] . '
'; +} + + ?>