0) {
$SQL_ARRAY = file($sf);
}
}
/**
* Saves a new query to the Sql-Library
*
* @return void
*/
function saveQueryToSqlLibrary()
{
global $SQL_ARRAY, $config;
$sf = './' . $config['paths']['config'] . 'sql_statements';
$str = "";
for ($i = 0; $i < count($SQL_ARRAY); $i++)
{
$str .= $SQL_ARRAY[$i];
if (substr($str, -1) != "\n" && $i != (count($SQL_ARRAY) - 1)) $str .= "\n";
}
if ($config['magic_quotes_gpc']) $str = stripslashes($str);
$fp = fopen($sf, "wb");
fwrite($fp, $str);
fclose($fp);
}
/**
* Gets the name of query nr $index from the Sql-Library.
*
* @param integer $index
* @return string
*/
function getQueryNameFromSqlLibrary($index)
{
global $SQL_ARRAY;
$s = explode('|', $SQL_ARRAY[$index]);
return $s[0];
}
/**
* Gets the query nr $index from the Sql-Library.
*
* @param integer $index
* @return string
*/
function getQueryFromSqlLibrary($index)
{
global $SQL_ARRAY;
if (!is_array($SQL_ARRAY)) getSqlLibrary();
if (isset($SQL_ARRAY[$index]) && !empty($SQL_ARRAY[$index]))
{
$s = explode('|', $SQL_ARRAY[$index], 2);
return (isset($s[1])) ? $s[1] : '';
}
else
return '';
}
/**
* Creates a html option list from the Sql-Library
*
* @return string
*/
function getSqlLibraryComboBox()
{
global $SQL_ARRAY, $tablename;
$s = '';
if (count($SQL_ARRAY) > 0)
{
$s = "\n\n" . '' . "\n\n";
}
return $s;
}
/**
* Detects if a query returns rows as result or just true or false
* Used in SQLBrowser to decide wether a list of records must be shown
*
* @param $sql the query to discover
* return bool
**/
function queryReturnsRecords($sql)
{
global $mysql_SQLhasRecords;
$s = explode(' ', $sql);
if (!is_array($s)) return false;
return in_array(strtoupper($s[0]), $mysql_SQLhasRecords) ? true : false;
}
function splitSQLStatements2Array($sql)
{
$z = 0;
$sqlArr = array();
$tmp = '';
$sql = str_replace("\n", '', $sql);
$l = strlen($sql);
$inQuotes = false;
for ($i = 0; $i < $l; $i++)
{
$tmp .= $sql[$i];
if ($sql[$i] == "'" || $sql[$i] == '"') $inQuotes = !$inQuotes;
if ($sql[$i] == ';' && $inQuotes == false)
{
$z++;
$sqlArr[] = $tmp;
$tmp = '';
}
}
if (trim($tmp) != '') $sqlArr[] = $tmp;
return $sqlArr;
}
/**
* Build HTML-Selectbox from saved SQL-Commands
*
* @param string $when Before backup = 0, After Backup =1
* @param integer $index Index of database
* @return string HTML as string
*/
function getCommandDumpComboBox($when, $index, $db_name)
{
global $SQL_ARRAY, $databases, $lang;
if (count($SQL_ARRAY) == 0)
{
if ($when == 0) $r = '';
else $r = '';
}
else
{
if ($when == 0)
{
$r = '';
$csql = trim($databases[$db_name]['command_before_dump']);
}
else
{
$r = '';
$csql = trim($databases[$db_name]['command_after_dump']);
}
$r .= ' ' . "\n";
for ($i = 0; $i < count($SQL_ARRAY); $i++)
{
$s = trim(getQueryFromSqlLibrary($i));
$r .= '