function get_conn_data()
{
if (file_exists("../conn_data.php")) {
$old_conn_file = file_get_contents("../conn_data.php");
} else {
$old_conn_file = file_get_contents("../conn.php");
}
$old_conn_file = str_replace(" ", "", $old_conn_file);
$db_host = get_text_between_tags('$db_host=\'', "';", $old_conn_file);
$db_username = get_text_between_tags('$db_username=\'', "';", $old_conn_file);
$db_password = get_text_between_tags('$db_password=\'', "';", $old_conn_file);
$db_name = get_text_between_tags('$db_name=\'', "';", $old_conn_file);
return array('db_host' => $db_host, 'db_username' => $db_username, 'db_password' =>
$db_password, 'db_name' => $db_name);
}
function get_emp_version($dbname)
{
$tables = mysql_list_tables($dbname);
$num_tables = @mysql_numrows($tables);
$i = 0;
$exist = 0;
while ($i < $num_tables) {
$tablename = mysql_tablename($tables, $i);
if ($tablename == 'tbloptions')
$exist = 1;
$i++;
}
if ($exist == 1) {
//it is 1.3 or 1.4
$result = mysql_query("SELECT option_value FROM tbloptions WHERE option_name='emp-version'");
$version = mysql_result($result, 0);
} else {
//version 2.0 or greater
$result = mysql_query("SELECT `nScriptVersion` FROM tblsitesettings;");
$version = mysql_result($result, 0);
}
return $version;
}
/*
*/
function get_text_between_tags($tag_start, $tag_end, $text)
{
$text = explode($tag_start, $text);
$text = explode($tag_end, $text[1]);
return $text[0];
}
function emp_checkActivationKey($sKey, &$sMsg, $ver_nr)
{
$sUrl = sprintf("http://www.easymemberpro.com/licensing/upgradecheck.php?cmd=CHECK&key=%s&server=%s&ver_nr=%s",
$sKey, $_SERVER['HTTP_HOST'], $ver_nr);
$result = @file_get_contents($sUrl);
if (strpos($result, 'error') !== false) {
$sMsg = substr($result, strpos($result, "=") + 1);
return false;
} else {
return true;
}
}
//===========added random string generator function ===========
function getUniqueCode($length = "")
{
$code = md5(uniqid(rand(), true));
if ($length != "")
return substr($code, 0, $length);
else
return $code;
}
//=============================================================
function emp_saveConnectionDataFile($sServer, $sUserName, $sPassword, $sDbName,
$sFileName = 'conn_data.php')
{
$sConnFile = @file_get_contents(dirname(__file__) . '/install_conn_data.txt');
$sConnFile = str_replace('[[SERVER]]', $sServer, $sConnFile);
$sConnFile = str_replace('[[USER]]', $sUserName, $sConnFile);
$sConnFile = str_replace('[[PASSWORD]]', $sPassword, $sConnFile);
$sConnFile = str_replace('[[DBNAME]]', $sDbName, $sConnFile);
//==================== added random SALT
$sConnFile = str_replace('[[SALT]]', getUniqueCode(7), $sConnFile);
@unlink(dirname(__file__) . '/conn_data.php');
@file_put_contents(dirname(__file__) . '/conn_data.php', $sConnFile);
}
function emp_saveConnFile()
{
$sConnFile = @file_get_contents(dirname(__file__) . '/install_conn.txt');
@unlink(dirname(__file__) . '/conn.php');
@file_put_contents(dirname(__file__) . '/conn.php', $sConnFile);
}
function emp_checkPHPVersion($sRequired)
{
$sVersion = phpversion();
$sVersion = substr($sVersion, 0, strpos($sVersion, '.', 3));
if ($sVersion < 5) {
define('EMP_PHP_4', true);
} else {
define('EMP_PHP_4', false);
}
return $sVersion >= $sRequired;
}
function emp_checkMySQLVersion($sRequired)
{
$sVersion = mysql_get_server_info();
$sVersion = substr($sVersion, 0, strpos($sVersion, '.', 3));
if ($sVersion < 5) {
define('EMP_MYSQL_4', true);
} else {
define('EMP_MYSQL_4', false);
}
return $sVersion >= $sRequired;
}
function emp_checkGetFileContents($sPath)
{
//TODO: check permisions first
$sFile = @file_get_contents($sPath, true);
if (strlen($sFile) > 10) {
return true;
} else {
return false;
}
}
function emp_checkFolderIsWritable($sPath)
{
//TODO: Check permisions;
$sFileName = rand(100000, 10000000) . '.txt';
$sFilePath = $sPath . '/' . $sFileName;
$sFileContent = rand(100000, 10000000);
$f = @fopen($sFilePath, 'a+');
if ($f) {
fputs($f, $sFileContent);
fclose($f);
$sContentCheck = @file_get_contents($sFilePath, true);
unlink($sFilePath);
if ($sContentCheck == $sFileContent) {
return true;
} else {
return false;
}
} else {
return false;
}
}
function emp_executeSql($nConn, $sSQLFile, &$aError){
$aError = array();
$fSQL = @file_get_contents($sSQLFile);
if (!$fSQL) {
$aError[] = array('msg' => 'Unable to open file SQL file', 'err' => 0);
} else {
$sSQLCommand = '';
$fSQL = explode("\n", $fSQL);
foreach ($fSQL as $sLine) {
$sLine = trim($sLine);
if ((substr($sLine, 0, 2) != '--') && (strlen($sLine) > 3) && (substr($sLine, 0,
2) != '/*')) {
$sSQLCommand .= ' ' . $sLine;
if (substr($sSQLCommand, strlen($sSQLCommand) - 1) == ';') {
if (!@mysql_query($sSQLCommand)) {
$sErrMessage = mysql_error();
$sErrNumber = mysql_errno();
$aError[] = array('msg' => $sErrMessage, 'err' => $sErrNumber, 'sql' => $sSQLCommand);
}
$sSQLCommand = '';
}
}
}
return (sizeof($aError) == 0);
}}
function run_sql_code($sql_code)
{
$lines_array = explode(";\n", $sql_code);
foreach ($lines_array as $line) {
$line = trim($line);
if (strlen($line) > 1) {
mysql_query($line) or die($sql_code . "
" . mysql_error());
}
}
}
?>