From 990976986e501d77bc7c3e4e084aeb70c20c2ce0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Lucas?= Date: Mon, 25 Nov 2013 21:35:02 +0100 Subject: [PATCH] Fix the redirect in case of multiple databases and if the failing database is not the first. re #116 --- index.php | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/index.php b/index.php index 8bc5e93..5fc64c7 100644 --- a/index.php +++ b/index.php @@ -23,16 +23,27 @@ exit (); } - // Access the database ASAP to be sure it's readable, redirect if that's not the case. - // It has to be done before any header is sent. - $test = Base::getDb (); - - header ("Content-Type:text/html;charset=utf-8"); $page = getURLParam ("page", Base::PAGE_INDEX); $query = getURLParam ("query"); $qid = getURLParam ("id"); $n = getURLParam ("n", "1"); $database = GetUrlParam (DB); + + + // Access the database ASAP to be sure it's readable, redirect if that's not the case. + // It has to be done before any header is sent. + if (is_array ($config['calibre_directory']) && is_null ($database)) { + $i = 0; + foreach (array_keys ($config['calibre_directory']) as $key) { + $test = Base::getDb ($i); + Base::clearDb (); + $i++; + } + } else { + $test = Base::getDb (); + } + + header ("Content-Type:text/html;charset=utf-8"); ?>