<?php
function err_handler ($errno, $errstr, $errfile, $errline) {
global $display_errors;
if(($errno != E_NOTICE && $errno != E_WARNING) && $display_errors){
echo '';
    }
  }
  $error_flags = E_ALL & ~E_NOTICE;
  @error_reporting($error_flags);
  @ini_set ('error_reporting', $error_flags);
  $old_error_handler = set_error_handler("err_handler");
define("DB", true);
define("FUNC_FILE", true);
if (!ini_get("register_globals")) {import_request_variables('GPC');}
if (isset($_COOKIE["lang"])) {
	include("language/lang-".$_COOKIE["lang"].".php");
} else {
	include("language/lang-russian.php");
}
require_once("../config/config.php");

function head() {
	global $title;
	echo "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n";
    echo "<html>\n";
    echo "<head>\n";
	echo "<meta http-equiv=\"content-type\" content=\"text/html; charset="._CHARSET."\">\n";
	echo "<title>"._SETUP."</title>\n";
	echo "<link rel=\"stylesheet\" href=\"../templates/Admin/style.css\" type=\"text/css\">\n";
	echo "</head>\n";
	echo "<body>\n";
	echo "<br><br><br><table width=\"60%\" align=\"center\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">";
	echo "<tr><td align=\"center\"><img src=\"../install/images/logo.gif\" border=\"0\" title=\"SLAED CMS\"></td></tr><tr><td align=\"center\"><br><br><br><font class=\"option\">$title</font><br><br></td></tr><tr><td>\n";

}

function foot() {
	echo "</td></tr></table>\n";
	echo "</body><br><br><br><br><br><br>";
	echo "<div align=\"center\"><img src=\"../images/blocks/icq.gif\" border=\"0\">&nbsp;<b>458692647</b></div>";
	echo "</html>";

}

function language() {
	global $title;
	$title = ""._LANG."";
	head();
	echo "<table align=\"center\" border=\"0\" cellspacing=\"0\" cellpadding=\"5\"><tr>"
	."<td><a href=\"index.php?op=english\" title=\"English\"><img src=\"../images/language/flag-english.gif\" border=\"0\"></a></td><td><a href=\"index.php?op=english\" title=\"English\">English</a></td>"
	."<td><a href=\"index.php?op=german\" title=\"German\"><img src=\"../images/language/flag-german.gif\" border=\"0\"></a></td><td><a href=\"index.php?op=german\" title=\"German\">German</a></td>"
	."<td><a href=\"index.php?op=russian\" title=\"Russian\"><img src=\"../images/language/flag-russian.gif\" border=\"0\"></a></td><td><a href=\"index.php?op=russian\" title=\"Russian\">Russian</a></td>"
	."</tr>";
	if (isset($_GET["lang"]) && $_GET["lang"] == 1) {
		echo "<tr><td align=\"center\" colspan=\"6\"><br><br><form action=\"index.php\" method=\"post\">"
		."<input type=\"hidden\" name=\"op\" value=\"license\">"
		."<input type=\"submit\" value=\""._NEXT."\"></td></tr>";
	}
	echo "</table>";
	foot();
}

function license() {
	global $title;
	$title = ""._INFO."";
	head();
	$bodytext = file_get_contents("text.txt");
	echo "<table align=\"center\" border=\"0\" cellspacing=\"0\" cellpadding=\"3\">"
	."<tr><td><textarea cols=\"45\" rows=\"15\" style=\"width:400px\">$bodytext</textarea></td></tr>"
	."<tr><td><form action=\"index.php\" method=\"post\">"
	."<tr><td align=\"center\"><br><br><input type=\"hidden\" name=\"op\" value=\"config\">"
	."<input type=\"submit\" value=\""._NEXT."\"></td></tr>";
	echo "</table>";
	foot();
}



function config() {
global $title, $dbhost, $version, $dbuname, $dbpass, $dbname, $prefix;
$title = ""._SETUP."<br> "._MODUL." &nbsp;";
	head();
	echo "<div align=\"center\">"._VERSSYS."</div><br>";
	echo "<table align=\"center\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">"
		."<form action=\"index.php\" method=\"post\">"
		."<tr><td><table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"3\">"
		."<tr><td>"._SETUP_NEW.":</td><td align=\"right\"><input type=\"radio\" name=\"setup\" value=\"new\" checked></td></tr>"
		."<tr><td colspan=\"2\"><hr></td></tr>"
		."</table></td></tr>"
		."<tr><td><table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"3\">"
		."<div align=\"center\">"._CONFIG."</div>"
		."<tr><td>"._CONF_1.":</td><td align=\"right\"><input type=\"text\" name=\"xdbhost\" value=\"$dbhost\" size=\"25\"></td></tr>"
		."<tr><td>"._CONF_2.":</td><td align=\"right\"><input type=\"text\" name=\"xdbuname\" value=\"$dbuname\" value=\"root\" size=\"25\"></td></tr>"
		."<tr><td>"._CONF_3.":</td><td align=\"right\"><input type=\"text\" name=\"xdbpass\" value=\"$dbpass\" size=\"25\"></td></tr>"
		."<tr><td>"._CONF_4.":</td><td align=\"right\"><input type=\"text\" name=\"xdbname\" value=\"$dbname\" size=\"25\"></td></tr>"
		."<tr><td colspan=\"2\"><hr></td></tr>"
		."</table></td></tr>"
		."<tr><td><table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"3\">"
		."<tr><td>"._CONF_7.":</td><td align=\"right\"><input type=\"text\" name=\"xprefix\" value=\"$prefix\" size=\"25\"></td></tr>"
		."<tr><td align=\"center\" colspan=\"2\"><br><br><input type=\"hidden\" name=\"op\" value=\"save\">"
		."<input type=\"submit\" value=\""._NEXT."\"></td></tr>"
		."</table></td></tr>";
		echo "</table>";
	foot();
}


function save($setup, $xdbhost, $xdbuname, $xdbpass, $xdbname, $xprefix) {
	global $admin_file, $title;

    $bodytext = "";
		$conectionid = @mysql_connect($xdbhost, $xdbuname, $xdbpass);
		if ($conectionid) {
			$db = @mysql_select_db($xdbname);
			if (!$db) {
				$title = ""._ERROR."";
				head();
				echo "<br><br><center>"._GOBACK."</center>";
				foot();
				exit;
			}
			if ($setup == "new") {
				$title = ""._SAVE_NEW."";
				$filename = "sql/table.sql";
				$readdump = fopen($filename, "r");
				$stringdump = fread($readdump, filesize($filename));
				fclose($readdump);
				$stringdump = split(";",$stringdump);
				$dump_count = count($stringdump);
				for ($i = 0; $i < $dump_count; $i++) {
				$string = str_replace("{pref}", $xprefix, $stringdump[$i]);
				$id = mysql_query($string);
				if (eregi("CREATE|ALTER", $string)) {
				$table = explode("`", $string);
				$bodytext .= "<tr><td>"._TABLE.":</td><td>".$table[1]." ".(($id) ? "</td><td><font color=\"green\">"._OK."</font></td>" : "<td><font color=\"red\">"._ALERT."</font></td>")."</tr>";
				}
				}
			mysql_close($conectionid);
		} else {
			$title = ""._ERROR2."";
			head();
			echo "<br><br><center>"._GOBACK."</center>";
			foot();
			exit;
		}
		}
		head();
		echo "<table align=\"center\" border=\"0\" cellspacing=\"0\" cellpadding=\"3\">".$bodytext."</table><br><br><br>";
		echo "<div align=\"center\">"._INF."</div>";
		echo "<form action=\"../".$admin_file.".php?op=modules\" method=\"post\"><br><center>"._GOBACK." <input type=\"submit\" value=\""._ADMIN."\"></center></form>";
		foot();
}
if (!isset($op)) $op = "";
switch($op) {
	default:
	language();
	break;

	case "english":
	setcookie ("lang", "english", time() + 3600);
	Header("Location: index.php?op=language&lang=1");
	break;

	case "german":
	setcookie ("lang", "german", time() + 3600);
	Header("Location: index.php?op=language&lang=1");
	break;

	case "russian":
	setcookie ("lang", "russian", time() + 3600);
	Header("Location: index.php?op=language&lang=1");
	break;

	case "license":
	license();
	break;

    case "config":
	config();
	break;

	case "save":
	save($setup, $xdbhost, $xdbuname, $xdbpass, $xdbname, $xprefix);
	break;
}
?>