$savedSearchList = array();
$savedSearch = null;
$currentSearchId = null;
if ($cfgRelation['savedsearcheswork']) {
$header = $response->getHeader();
$scripts = $header->getScripts();
$scripts->addFile('db_qbe.js');
//Get saved search list.
$savedSearch = new SavedSearches($GLOBALS);
$savedSearch->setUsername($GLOBALS['cfg']['Server']['user'])->setDbname($_REQUEST['db']);
if (!empty($_REQUEST['searchId'])) {
$savedSearch->setId($_REQUEST['searchId']);
}
//Action field is sent.
if (isset($_REQUEST['action'])) {
$savedSearch->setSearchName($_REQUEST['searchName']);
if ('create' === $_REQUEST['action']) {
$saveResult = $savedSearch->setId(null)->setCriterias($_REQUEST)->save();
} elseif ('update' === $_REQUEST['action']) {
$saveResult = $savedSearch->setCriterias($_REQUEST)->save();
} elseif ('delete' === $_REQUEST['action']) {
$deleteResult = $savedSearch->delete();
//After deletion, reset search.
$savedSearch = new SavedSearches($GLOBALS);
$savedSearch->setUsername($GLOBALS['cfg']['Server']['user'])->setDbname($_REQUEST['db']);
$_REQUEST = array();
} elseif ('load' === $_REQUEST['action']) {
if (empty($_REQUEST['searchId'])) {
//when not loading a search, reset the object.
$savedSearch = new SavedSearches($GLOBALS);
$savedSearch->setUsername($GLOBALS['cfg']['Server']['user'])->setDbname($_REQUEST['db']);