Ejemplo n.º 1
0
/**
 * Detect accessable databases for the current SQL-User in $config-array and returns output-string with all dbs
 * Additionally it adds all found databases in the global var $databases
 *
 * @param boolean $printout Wether to return the output string or not
 * @param string  $db       Optional name of a database to add manually
 *
 * @return string Output string containing all found dbs
 */
function searchDatabases($printout = 0, $db = '')
{
    global $config, $lang, $dbo, $databases;
    $databases = array();
    $ret = '';
    $db_list = $dbo->getDatabases();
    // add manual added db to array, but only if it was not detected before
    if ($db > '' && !in_array($db, $db_list)) {
        $db_list[] = $db;
    }
    // now check if we can select the db - if not, we can't access the database
    if (sizeof($db_list) > 0) {
        foreach ($db_list as $db) {
            $res = $dbo->selectDb($db, true);
            if ($res === true) {
                addDatabaseToConfig($db);
                if ($printout == 1) {
                    $ret .= Html::getOkMsg($lang['L_FOUND_DB'] . ' `' . $db);
                }
            } elseif ($printout == 1) {
                $ret .= Html::getErrorMsg($lang['L_ERROR'] . ' : ' . $res);
            }
        }
    }
    return $ret;
}
Ejemplo n.º 2
0
        }
    }
    // manual adding of a database
    if ($_POST['add_db_manual'] > '') {
        $saveConfig = false;
        $blendInConnectionParams = true;
        $dbToAdd = trim($_POST['add_db_manual']);
        $found = false;
        // Check if we already have this one in our db list
        if (isset($databases[$dbToAdd])) {
            $addDbMessage = sprintf($lang['L_DB_IN_LIST'], $dbToAdd);
        } else {
            $dbo = MsdDbFactory::getAdapter($config['dbhost'], $config['dbuser'], $config['dbpass'], $config['dbport'], $config['dbsocket']);
            try {
                $dbo->selectDb($dbToAdd, true);
                addDatabaseToConfig($dbToAdd);
                $saveConfig = true;
            } catch (Exception $e) {
                $addDbMessage = $lang['L_ERROR'] . ': (' . $e->getCode() . ') ';
                $addDbMessage .= $e->getMessage();
            }
        }
    }
}
$tplConfigurationDatabases = new MSDTemplate();
$tplConfigurationDatabases->set_filenames(array('tplConfigurationDatabases' => 'tpl/configuration/databases.tpl'));
$tplConfigurationDatabases->assign_vars(array('ICON_SAVE' => $icon['small']['save'], 'DB_HOST' => $config['dbhost'], 'DB_USER' => $config['dbuser'], 'DB_PASS' => $config['dbpass'], 'DB_PORT' => $config['dbport'], 'DB_SOCKET' => $config['dbsocket'], 'ICON_EDIT' => $icon['edit'], 'ICON_DOWN' => $icon['arrow_down'], 'ICON_PLUS' => $icon['plus'], 'ICON_MINUS' => $icon['minus']));
if (isset($addDbMessage) && $addDbMessage > '') {
    $tplConfigurationDatabases->assign_block_vars('MANUAL_DB_ADD', array('MESSAGE' => $addDbMessage));
}
//Wenn Datenbanken vorhanden sind