function ereg2($pattern, $string, &$regs = "") {
return (preg_match("/" . str_replace("/", "\/", $pattern) . "/", $string, $regs));
}
function eregi2($pattern, $string, &$regs = "") {
return (preg_match("/" . $pattern . "/i", $string, $regs));
}
function include_all($file, $lang, $require_global = 0, $require_site = 0, $require_dev = 0) {
if ($require_site)
require (t_file($file, 1, 0, $lang));
else if (file_exists(t_file($file, 1, 0, $lang)))
include (t_file($file, 1, 0, $lang));
if ($require_dev)
require (t_file($file, 1, 1, $lang));
else if (file_exists(t_file($file, 1, 1, $lang)))
include (t_file($file, 1, 1, $lang));
if ($require_global)
require (t_file($file, 0, 0, $lang));
else if (file_exists(t_file($file, 0, 0, $lang)))
include (t_file($file, 0, 0, $lang));
}
function include_one($file, $lang, $require = 1) {
if (file_exists(t_file($file, 1, 1, $lang)))
require (t_file($file, 1, 1, $lang));
else {
if (file_exists(t_file($file, 1, 0, $lang)))
require (t_file($file, 1, 0, $lang));
else {
if ($require)
require (t_file($file, 0, 0, $lang));
else
include (t_file($file, 0, 0, $lang));
}
}
}
function flush2() {
echo(str_repeat(' ', 512));
// check that buffer is actually set before flushing
if (ob_get_length()) {
@ob_flush();
@flush();
@ob_end_flush();
}
@ob_start();
}
function mysql_error_log($e, $request) {
$serror = "Env: " . $_SERVER['SERVER_NAME'] . "\r\n" .
"timestamp: " . Date('m/d/Y H:i:s') . "\r\n" .
"script: " . $_SERVER['PHP_SELF'] . "\r\n" .
"error: " . $e . "\r\n" .
"request: " . $request . "\r\n\r\n";
// open a log file and write error
$fhandle = fopen(MYSQL_PHP_LOG, "a");
if ($fhandle) {
fwrite($fhandle, $serror);
fclose(($fhandle));
};
// determine last error time
clearstatcache();
$last_err = filemtime(MYSQL_PHP_TIMESTAMP);
$d = date("U");
// e-mail error to system operator
if (($d - $last_err) > 60) { // max. 1 emal per minute
while (filemtime(MYSQL_PHP_TIMESTAMP) < $d) {
$fhandle = fopen(MYSQL_PHP_TIMESTAMP, "a");
fwrite($fhandle, " ");
fclose(($fhandle));
clearstatcache();
sleep(1);
}
//mail(ADMIN_EMAIL, 'Database Error', $serror, 'From: ' . ADMIN_EMAIL);
mime_versenden("", ADMIN_EMAIL, "", ADMIN_EMAIL, 'Database Error', $serror);
}
}
function mysql_error_check($request = "") {
global $db;
$e = mysql_error();
if ($e != "") {
if (DEVELOPMENT) {
mysql_error_log($e, $request);
echo "\n
MSYQL ERROR: ";
echo $e, " ORIGINAL REQUEST: ", $request, "
\n";
die();
} else {
mysql_error_log($e, $request);
}
}
}
function dolog($request, $remarks = "", $schluessel = "", $user = "") {
global $db;
if ($user == "" and ! empty($_SERVER["PHP_AUTH_USER"])) {
$user = $_SERVER["PHP_AUTH_USER"];
};
$user = mysql_escape_string($user);
$remarks = mysql_escape_string($remarks);
$file = mysql_escape_string($_SERVER["PHP_SELF"]);
$schluessel = mysql_escape_string($schluessel);
$request2 = mysql_escape_string($request);
$ip = ip2long($_SERVER["REMOTE_ADDR"]);
mysql_query2("insert into log (request, user, ip, file, schluessel, remarks) values ('$request2', '$user', $ip, '$file', '$schluessel', '$remarks')");
}
function debug() {
if (!DEVELOPMENT)
return;
$numParams = func_num_args();
$params = func_get_args();
$s = "";
for ($i = 0; $i < $numParams; $i++) {
if ($i == 0)
$s .= "";
else
$s .= " ";
$s .= "$i ---> " . $params[$i];
if ($i + 1 == $numParams)
$s .= "
";
}
//echo htmlspecialchars($s);
echo $s;
flush2();
//file_put_contents ( "/tmp/debugoutput.txt", $s, FILE_APPEND);
}
;
function debug_p() {
// for productive environment
$numParams = func_num_args();
$params = func_get_args();
for ($i = 0; $i < $numParams; $i++) {
if ($i == 0)
echo "";
else
echo " ";
echo "$i ---> ", $params[$i];
if ($i + 1 == $numParams)
echo "
";
}
flush2();
}
function debug_t() {
// for text/batch mode
if (!DEVELOPMENT)
return;
$numParams = func_num_args();
$params = func_get_args();
for ($i = 0; $i < $numParams; $i++) {
echo "$i: ", $params[$i], "\n";
if ($i + 1 == $numParams)
echo "\n";
}
}
function debug_m() {
// by Email
if (!DEVELOPMENT)
return;
$s = "";
$numParams = func_num_args();
$params = func_get_args();
for ($i = 0; $i < $numParams; $i++) {
$s .= "$i: " . $params[$i] . "\n";
if ($i + 1 == $numParams)
$s .= "\n";
}
mime_versenden("", ADMIN_EMAIL, "", ADMIN_EMAIL, 'Debug', $s);
}
function debug_tab() {
if (!DEVELOPMENT)
return;
$numParams = func_num_args();
$params = func_get_args();
for ($i = 0; $i < $numParams; $i++) {
echo '';
if ($i == 0)
echo "";
else
echo " ";
echo "$i ---> ", $params[$i];
if ($i + 1 == $numParams)
echo "
";
echo " ";
}
flush2();
}
/*
function mysql_query_log ($request, $remarks = "", $schluessel = "", $user = "") {
global $db;
$numParams = func_num_args();
$params = func_get_args();
dolog ($request, $remarks, $schluessel, $user);
$params2 = array_merge (array($request) , array_slice ($params, 4));
$r = call_user_func_array('mysql_query2', $params2);
return ($r);
}
*/
function mysql_query_log($query, $remarks = "", $schluessel = "", $user = "") {
global $db;
$numParams = func_num_args();
$params = func_get_args();
if ($numParams > 4) {
for ($i = 4; $i < $numParams; $i++) {
if (get_magic_quotes_gpc()) {
$params[$i] = stripslashes($params[$i]);
}
if ($params[$i] != "NULL") {
$params[$i] = "'" . mysql_real_escape_string($params[$i]) . "'";
}
}
$query = call_user_func_array('sprintf', array_merge(array($query), array_slice($params, 4)));
}
if (preg_match("/UNION.{1,100}SELECT/i", $query) && !DEVELOPMENT) {
mysql_error_log("UNION SELECT prevented", $query);
return FALSE; // prevent sql injection
}
dolog($query, $remarks, $schluessel, $user);
$r = mysql_query($query);
mysql_error_check($query);
return ($r);
}
function mysql_query2($query) {
// ACHTUNG: Änderungen auch in mysql_query_log durchführen!
global $db, $debug;
$numParams = func_num_args();
$params = func_get_args();
if ($numParams > 1) {
for ($i = 1; $i < $numParams; $i++) {
if (get_magic_quotes_gpc()) {
$params[$i] = stripslashes($params[$i]);
}
if ($params[$i] != "NULL") {
$params[$i] = "'" . mysql_real_escape_string($params[$i]) . "'";
}
}
$query = call_user_func_array('sprintf', $params);
}
if (preg_match("/UNION.{1,100}SELECT/i", $query) && !DEVELOPMENT) {
mysql_error_log("UNION SELECT prevented", $query);
return FALSE; // prevent sql injection
}
if (isset($debug)) {
if ($debug == 1) {
debug(htmlentities($query));
}
if ($debug == 2) {
debug_m(htmlentities($query));
}
}
$r = mysql_query($query, $db);
mysql_error_check($query);
return ($r);
}
function quote_smart($value, $null = FALSE) {
// Stripslashes
if (get_magic_quotes_gpc()) {
$value = stripslashes($value);
}
// Quote if not a number or a numeric string
//if (!ctype_digit((string)$value) && ($value != "NULL")) {
if ($value != "NULL") {
$value = "'" . mysql_real_escape_string($value) . "'";
}
return $value;
}
function money($r, $precision = 2) {
$f = str_replace(".", ",", sprintf("%0." . $precision . "f", round($r, $precision)));
return ($f);
}
function t3($trans_id, $prod_id = 0, $echo = 1, $p1 = "", $p2 = "", $p3 = "", $p4 = "", $sect = "", $country = "DE", $simple = FALSE, $isName = FALSE) {
global $db, $language, $macro, $debug;
if (empty($language)) {
$language = "DE";
}
if (!preg_match("/(DE|EN|FR|ES|IT|US)/i", $language)) {
$language = "EN"; // AR -> EN
}
$product = new products;
if ($prod_id) {
$product->get($prod_id);
}
$is_parent = FALSE;
$is_child = FALSE;
if ($isName) {
$selector = 0;
$colors = 0;
$sizes = 0;
if ($product->parent) {
$is_child = TRUE;
} else {
$r2 = mysql_query2("select * from products where parent=%s", $prod_id);
if (mysql_numrows($r2) > 0) {
$is_parent = TRUE;
}
}
if ($is_child)
$selector = $product->parent;
/*
if ($is_child) {
$r = mysql_query2("select * from txtvals where id=(select nameTxt from products where id=%s) and mandant=%s", $product->parent, MANDANT);
} else {
$r = mysql_query2("select * from txtvals where id=%s and mandant=%s", $trans_id, MANDANT);
}
*
*/
$r = mysql_query2("select * from txtvals where id=%s and mandant=%s", $trans_id, MANDANT);
if ($selector) {
$r2 = mysql_query2("select distinct color from products where parent=%s and active", $selector);
$colors = mysql_numrows($r2);
$r2 = mysql_query2("select * from countries where iso=%s", $country);
$country_id = mysql_fetch_object($r2)->id;
$r2 = mysql_query2("select distinct size from products_sizes ps, products p where p.active and ps.product=p.id and p.parent=%s and ps.country=%s and is_map=0 and size is not null", $selector, $country_id);
$sizes = mysql_numrows($r2);
}
} else {
$r = mysql_query2("select * from txtvals where id=%s and mandant=%s", $trans_id, MANDANT);
}
if ($row = mysql_fetch_object($r)) {
$language_sort = "name_" . $language;
$s = trim($row->$language_sort);
}
if ($is_child) {
if ($sizes > 1) {
$r2 = mysql_query2("select * from countries where iso=%s", $country);
$country_id = mysql_fetch_object($r2)->id;
$r2 = mysql_query2("select s.name from products_sizes ps, sizes s where ps.size=s.id and ps.product=%s and ps.country=%s and ps.is_map=%s", $product->id, $country_id, 0);
$row = mysql_fetch_object($r2);
$s .= ", " . $row->name;
}
if ($colors > 1) {
$color = new colors;
$color->get($product->color);
$s .= ", " . $color->{'name_' . $language};
}
}
if ($is_parent && !preg_match('/(HA-01)/', $product->sku)) {
$r2 = mysql_query2("select distinct color from products where parent=%s and active", $product->id);
$colors = mysql_numrows($r2);
$r2 = mysql_query2("select * from countries where iso=%s", $country);
$country_id = mysql_fetch_object($r2)->id;
$r2 = mysql_query2("select distinct size from products_sizes ps, products p where p.active and ps.product=p.id and p.parent=%s and ps.country=%s and is_map=0 and size is not null", $product->id, $country_id);
$sizes = mysql_numrows($r2);
if ($sizes > 1) {
if ($colors > 1) {
if ($colors > 3) {
$s .= " - " . t("vieleVerschGrFarben", 0);
} else {
$s .= " - " . t("verschGrFarben", 0);
}
} else {
$s .= ", " . t("verschGr", 0);
}
} else {
if ($colors > 1) {
if ($colors > 3) {
$s .= " - " . t("vieleVerschFarben", 0);
} else {
$s .= " - " . t("verschFarben", 0);
}
} else {
// nix
}
}
}
$i = 0;
$l = strlen($s);
$mark = 0;
$const = "";
$result = "";
while ($i < $l) {
$c = substr($s, $i, 1);
if ($c == "$") {
switch ($mark) {
case 0:
$mark = 1;
break;
case 1:
$mark = 2;
break;
case 2:
$mark = 3;
break;
case 3:
if (ctype_digit((string) $const)) {
$result .= ${"p" . $const};
} else {
if (ereg2("^PP", $const)) {
$const = substr($const, 2);
switch ($const) {
case "color":
$r2 = mysql_query2("select * from colors where id=%s", $product->color);
$row = mysql_fetch_object($r2);
$name = "name_" . $language;
$result .= $row->$name;
break;
case "weight":
$result .= $product->content_weight;
break;
case "country":
$r2 = mysql_query2("select * from countries where id=%s", $product->country);
$row = mysql_fetch_object($r2);
$name = "name_" . $language;
$result .= $row->$name;
break;
case "season":
$r2 = mysql_query2("select s.name FROM products_seasons ps, seasons s where ps.product=%s and ps.language=%s and ps.season=s.id", $product->id, $language);
$row = mysql_fetch_object($r2);
$result .= $row->name;
break;
case "size":
case "size_map":
$r2 = mysql_query2("select * from countries where iso=%s", $country);
$country_id = mysql_fetch_object($r2)->id;
if ($const == "size")
$ismap = 0;
else
$ismap = 1;
$r2 = mysql_query2("select s.name from products_sizes ps, sizes s where ps.size=s.id and ps.product=%s and ps.country=%s and ps.is_map=%s", $product->id, $country_id, $ismap);
$row = mysql_fetch_object($r2);
$result .= $row->name;
break;
case "brand":
$r2 = mysql_query2("select * from brands where id=%s", $product->brand);
$row = mysql_fetch_object($r2);
$result .= $row->name;
break;
case "name":
$result .= t2($product->$const, $prod_id, 0);
break;
case "series":
case "material":
case "care":
if ($is_child) {
$r4 = mysql_query2("select * from products where id=%s", $product->parent);
$parent = mysql_fetch_object($r4);
$result .= t2($parent->$const, $parent->id, 0);
} else {
$result .= t2($product->$const, $prod_id, 0);
}
break;
default:
$result .= $product->$const;
break;
}
} else {
$result .= $macro[$const];
}
}
$const = "";
$mark = 0;
break;
}
} else {
switch ($mark) {
case 1:
$mark = 0;
$result .= "$";
case 0:
$result .= $c;
break;
case 2:
$const .= $c;
break;
}
}
$i++;
}
if ($echo)
echo $result;
return ($result);
}
;
function t2($trans_id, $prod_id = 0, $echo = 1, $p1 = "", $p2 = "", $p3 = "", $p4 = "", $sect = "", $country = "DE", $simple = FALSE) {
global $db, $language, $macro, $debug;
if (empty($language))
$language = "DE";
if (!preg_match("/(DE|EN|FR|ES|IT|US)/i", $language))
$language = "EN"; // AR -> EN
if ($sect == "")
$r = mysql_query2("select id, translation from translations where schluessel=(select schluessel from translations where id=%s) and sect=(select sect from translations where id=%s) and language=%s and mandant=%s", $trans_id, $trans_id, $language, MANDANT);
else
$r = mysql_query2("select id, translation from translations where schluessel=(select schluessel from translations where id=%s) and sect=%s and language=%s and mandant=%s", $trans_id, $sect, $language, MANDANT);
if ($row = mysql_fetch_object($r)) {
$s = $row->translation;
// don't update for admin requests
if (!preg_match('/adX7561u/', $_SERVER["REQUEST_URI"]))
mysql_query2("update translations set lastuse=now(), uri=%s where id=%s", $_SERVER["REQUEST_URI"], $row->id);
} else {
$s = $schluessel;
}
if ($prod_id) {
$r = mysql_query2("select * from products where id=%s and mandant=%s", $prod_id, MANDANT);
if (mysql_numrows($r))
$product = mysql_fetch_object($r);
}
$i = 0;
$l = strlen($s);
$mark = 0;
$const = "";
$result = "";
while ($i < $l) {
$c = substr($s, $i, 1);
if ($c == "$") {
switch ($mark) {
case 0:
$mark = 1;
break;
case 1:
$mark = 2;
break;
case 2:
$mark = 3;
break;
case 3:
if (ctype_digit((string) $const)) {
$result .= ${"p" . $const};
} else {
if (ereg2("^PP", $const)) {
$const = substr($const, 2);
switch ($const) {
case "color":
$r2 = mysql_query2("select * from colors where id=%s", $product->color);
$row = mysql_fetch_object($r2);
$name = "name_" . $language;
$result .= $row->$name;
break;
case "weight":
$result .= $product->content_weight;
break;
case "country":
$r2 = mysql_query2("select * from countries where id=%s", $product->country);
$row = mysql_fetch_object($r2);
$name = "name_" . $language;
$result .= $row->$name;
break;
case "season":
$r2 = mysql_query2("select s.name FROM products_seasons ps, seasons s where ps.product=%s and ps.language=%s and ps.season=s.id", $product->id, $language);
$row = mysql_fetch_object($r2);
$result .= $row->name;
break;
case "size":
case "size_map":
$r2 = mysql_query2("select * from countries where iso=%s", $country);
$country_id = mysql_fetch_object($r2)->id;
if ($const == "size")
$ismap = 0;
else
$ismap = 1;
$r2 = mysql_query2("select s.name from products_sizes ps, sizes s where ps.size=s.id and ps.product=%s and ps.country=%s and ps.is_map=%s", $product->id, $country_id, $ismap);
$row = mysql_fetch_object($r2);
$result .= $row->name;
break;
case "brand":
$r2 = mysql_query2("select * from brands where id=%s", $product->brand);
$row = mysql_fetch_object($r2);
$result .= $row->name;
break;
case "name":
case "series":
case "material":
case "care":
$result .= t2($product->$const, $prod_id, 0);
break;
default:
$result .= $product->$const;
break;
}
} else {
$result .= $macro[$const];
}
}
$const = "";
$mark = 0;
break;
}
} else {
switch ($mark) {
case 1:
$mark = 0;
$result .= "$";
case 0:
$result .= $c;
break;
case 2:
$const .= $c;
break;
}
}
$i++;
}
//$result = stripcslashes ($result);
if ($echo)
echo $result;
return ($result);
}
;
function t($schluessel, $echo = 1, $p1 = "", $p2 = "", $p3 = "", $p4 = "") {
global $db, $language, $macro;
if (empty($language))
$language = "DE";
if (!preg_match("/(DE|EN|ES|FR|IT|US)/i", $language))
$language = "EN"; // AR -> EN
$r = mysql_query2("select id, translation from translations where schluessel=%s and language=%s and sect='site' and mandant=%s", $schluessel, $language, MANDANT);
if ($row = mysql_fetch_object($r)) {
$s = $row->translation;
mysql_query2("update translations set lastuse=now(), uri=%s where id=%s", $_SERVER["REQUEST_URI"], $row->id);
} else {
$s = $schluessel;
}
$i = 0;
$l = strlen($s);
$mark = 0;
$const = "";
$result = "";
while ($i < $l) {
$c = substr($s, $i, 1);
if ($c == "$") {
switch ($mark) {
case 0:
$mark = 1;
break;
case 1:
$mark = 2;
break;
case 2:
$mark = 3;
break;
case 3:
if (ctype_digit((string) $const)) {
$result .= ${"p" . $const};
} else {
$result .= $macro[$const];
}
$const = "";
$mark = 0;
break;
}
} else {
switch ($mark) {
case 1:
$mark = 0;
$result .= "$";
case 0:
$result .= $c;
break;
case 2:
$const .= $c;
break;
}
}
$i++;
}
//$result = stripcslashes ($result);
if ($echo)
echo $result;
return ($result);
}
;
function t_direct($trans, $echo = 1) {
global $language;
if (array_key_exists($language, $trans)) {
$ret = $trans [$language];
} else {
// Keine Übersetzung für die gewählte Sprache --> dann Deutsch
if (array_key_exists("DE", $trans)) {
$ret = $trans ["DE"];
} else {
// Auch kein Deutsch --> dann erstes Element
$ret = $trans [0];
};
}
if ($echo)
echo $ret;
return ($ret);
}
;
function t_description($row, $name = "description") {
global $language;
if (preg_match("/(DE|EN|ES|FR|IT|US)/i", $language))
$name .= "_" . $language;
else
$name .= "_DE";
$description = $row->$name;
return ($description);
}
;
function lock_batch($tables, $what) {
global $db;
if ($what) {
// lock
$str = "lock tables ";
while (list ($key, $var) = each($tables)) {
$str .= $var . " write,";
};
$str = substr($str, 0, strlen($str) - 1); // strip last comma
$result = mysql_query2($str);
} else {
mysql_query2("unlock tables");
};
}
;
function setorblank($name, $type = "", $scope = "LPCSG", $blank = "") {
$ret = $blank;
$type = strtoupper($type);
$scope = strtoupper($scope);
if (isset($_COOKIE[$name]) && ereg2("C", $scope)) {
$ret = $_COOKIE[$name];
};
if (isset($_SESSION[$name]) && ereg2("S", $scope)) {
$ret = $_SESSION[$name];
};
if (isset($GLOBALS[$name]) && ereg2("L", $scope)) {
$ret = $GLOBALS[$name];
};
if (isset($_GET[$name]) && ereg2("G", $scope)) {
$ret = $_GET[$name];
};
if (isset($_POST[$name]) && ereg2("P", $scope)) {
$ret = $_POST[$name];
};
if (!is_array($ret))
$ret = strip_tags($ret);
switch ($type) {
case "I":
// integer
$ret = intval($ret);
break;
case "F":
// floating point
$ret = floatval(str_replace(",", ".", $ret));
break;
case "M":
// mysql query string
// Stripslashes
if (get_magic_quotes_gpc()) {
$ret = stripslashes($ret);
}
$ret = mysql_real_escape_string($ret);
break;
};
return ($ret);
}
;
function setorblank_list($names, $type = "", $scope = "LPCSG") {
while (list ($key, $var) = each($names)) {
$GLOBALS[$var] = setorblank($var, $type, $scope);
};
}
;
function setsession($names, $vals = array()) {
if (count($vals) == 0) {
while (list ($key, $var) = each($names)) {
$_SESSION[$var] = $GLOBALS[$var];
};
} else {
while (list ($key, $var) = each($names)) {
$_SESSION[$var] = $vals[$key];
};
}
}
;
function cleanup($nr) {
$l = strlen($nr);
$newnr = "";
for ($i = 0; $i < $l; $i++) {
$c = substr($nr, $i, 1);
$a = ord($c);
if (($a >= 48) && ($a <= 57)) { // numerisch
$newnr .= $c;
};
};
return ($newnr);
}
;
function wartungsende() {
if (WARTUNGSENDE > date("U"))
return(WARTUNGSENDE);
else
return(date("U") + 60 * 60 * 2);
}
function check_wartungsflag($level) {
global $wartungsips;
if (WARTUNGSFLAG >= $level) {
if (!array_search($_SERVER["REMOTE_ADDR"], $wartungsips)) {
// KEINE Wartungs IP
if (WARTUNGSFLAG >= 2) {
header("Retry-After: " . date("r", wartungsende()), TRUE, 503);
require ("notavail.php");
exit();
};
return (FALSE);
};
};
return (TRUE);
}
;
function check_country($country, $what) {
global $db;
$what = mysql_escape_string($what);
$r = mysql_query2("select * from countries where iso=%s and `" . $what . "`>0", $country);
return (mysql_numrows($r) > 0);
}
;
function check_blocked_ip() {
global $geoip_country, $gip, $wartungsips;
//if (array_search($_SERVER["REMOTE_ADDR"], $wartungsips)) return;
$block = 0;
$admin = FALSE;
$r = mysql_query2("select count(*) as cnt from `access` where ip=%s", $_SERVER["REMOTE_ADDR"]);
$row = mysql_fetch_object($r);
if ($row->cnt > MAX_PAGES_6)
$block++;
if (preg_match("/^" . preg_quote(ADMINPREFIX . "/", "/") . "/", $_SERVER["REQUEST_URI"])) {
$r = mysql_query2("select count(*) as cnt from `access` where ip=%s and admin=1", $_SERVER["REMOTE_ADDR"]);
$row = mysql_fetch_object($r);
if ($row->cnt > 4) {
$block++;
$admin = TRUE;
}
}
if ($block) {
$r = mysql_query2("select if(date_add(upd, interval 30 second)>now(),0,1) as again from `ip_blocked_email_sent` where ip=%s", $_SERVER["REMOTE_ADDR"]);
if ($row = mysql_fetch_object($r))
$again = $row->again;
else
$again = TRUE;
if ($again) {
if ($admin) {
mime_versenden2(ADMIN_BRAND, ADMIN_EMAIL, ADMIN_BRAND, ADMIN_EMAIL, "ADMIN IP Blocked", "IP: " . $_SERVER["REMOTE_ADDR"] . " | " . $geoip_country);
} else {
mime_versenden2(ADMIN_BRAND, ADMIN_EMAIL, ADMIN_BRAND, ADMIN_EMAIL, "IP Blocked", "IP: " . $_SERVER["REMOTE_ADDR"] . " | " . $geoip_country);
}
mysql_query2('insert into `ip_blocked_email_sent` (`ip`, `upd`) values (%s, now()) on duplicate key update `ip`=%s, `upd`=now()', $_SERVER["REMOTE_ADDR"], $_SERVER["REMOTE_ADDR"]);
}
header('HTTP/1.1 403 Forbidden');
echo "Forbidden";
exit();
};
}
;
function check_new_session($step, $display = 1) {
if ((!setorblank("product", "I", "S")) || ($step > setorblank("ordertoken_step", "I", "S"))) {
// Session lost
if ($display) {
t("txt87");
exit();
} else {
return (FALSE);
};
};
return (TRUE);
}
;
function valid_email($email) {
// from: http://www.phpit.net/code/valid-email/
// First, we check that there's one @ symbol, and that the lengths are right
if (!ereg2("^[^@]{1,64}@[^@]{1,255}$", $email)) {
// Email invalid because wrong number of characters in one section, or wrong number of @ symbols.
return false;
}
// Split it into sections to make life easier
$email_array = explode("@", $email);
$local_array = explode(".", $email_array[0]);
for ($i = 0; $i < sizeof($local_array); $i++) {
if (!ereg2("^(([A-Za-z0-9!#$%&'*+/=?^_`{|}~-][A-Za-z0-9!#$%&'*+/=?^_`{|}~\.-]{0,63})|(\"[^(\\|\")]{0,62}\"))$", $local_array[$i])) {
return false;
}
}
if (!ereg2("^\[?[0-9\.]+\]?$", $email_array[1])) { // Check if domain is IP. If not, it should be valid domain name
$domain_array = explode(".", $email_array[1]);
if (sizeof($domain_array) < 2) {
return false; // Not enough parts to domain
}
for ($i = 0; $i < sizeof($domain_array); $i++) {
if (!ereg2("^(([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])|([A-Za-z0-9]+))$", $domain_array[$i])) {
return false;
}
}
}
return true;
}
function ordertoken($new = FALSE) {
if ($new or ! isset($_SESSION["ordertoken"])) {
$rows = 0;
while (!$rows) {
$ordertoken = TOKEN_PREFIX . mt_rand(10000, 99999) . mt_rand(10000000, 99999999) . mt_rand(10000000, 99999999) . mt_rand(10000000, 99999999);
$r = mysql_query2("insert ignore into ordertokens (token) values (%s)", $ordertoken);
$rows = mysql_affected_rows();
}
$_SESSION["ordertoken"] = $ordertoken;
$_SESSION["ordertoken_step"] = 0;
};
return (setorblank("ordertoken", "", "S"));
}
;
function check_dev_price($price) {
if (DEV_PRICE > 0) {
return (DEV_PRICE);
} else {
return ($price);
};
}
;
function iframepayments($nr, $price, $addbatch = TRUE) {
global $echo;
$tid = "";
$price = check_dev_price($price);
$price2 = $price - 0.02; // 2 Cent Toleranz wg. Rundungen etc.
$nr = intval($nr);
$r = mysql_query2("select * from ordertokens, iframepayments where ordertokens.sub=%s and ordertokens.token=iframepayments.tid and currency='EUR' and price>=%s and used=0 and (status='BILLED' or status='RESERVED' or status='Completed')", $nr, $price2);
if (mysql_numrows($r) > 0) {
$row = mysql_fetch_object($r);
mysql_query_log("update iframepayments set used=1, sub=%s where nr=%s", "iframepayments", $nr, "", $nr, $row->nr);
mysql_query_log("insert into abbuchungen (subscription, created, paymethod, amount, mypaytid)
values (%s, now(), %s, %s, %s)", "iframepayments", $nr, "", $nr, $row->paymethod, $price, $row->mpaytid);
if ($addbatch)
mysql_query_log("insert into batch (task, earliest, timeout) values ('01_job.php?action=bezahlt&what=$nr', now(), 50)", "iframepayments", $nr, "");
// $nr has already been converted to INT value, so no quotation necessary
return (TRUE);
} else {
return (FALSE);
}
}
;
function email_subject_nr($nr, $show_order = 1) {
global $language;
if ($show_order) {
switch ($language) {
case "DE":
return " (Bestell-Nr. " . $nr . ")";
break;
case "EN":
default:
return " (Order #" . $nr . ")";
break;
}
} else {
return " (" . $nr . ")";
}
}
function mime_versenden($to_name, $to_address, $from_name, $from_address, $subject, $message, $priority = 3, $cc = 1, $html = 0, $mailer = MAILER_REGULAR) {
// old function
$mail = new osimail;
$mail->to_name = $to_name;
$mail->to_address = $to_address;
$mail->from_name = $from_name;
$mail->from_address = $from_address;
$mail->subject = $subject;
$mail->body = $message;
$mail->priority = $priority;
$mail->cc = $cc;
$mail->prefix = "";
$mail->Mailer = $mailer;
$mail->send();
}
function mime_versenden2($to_name, $to_address, $from_name, $from_address, $subject, $message, $priority = 3, $cc = 1, $html = 0) {
// old function with sendmail
$mail = new osimail;
$mail->to_name = $to_name;
$mail->to_address = $to_address;
$mail->from_name = $from_name;
$mail->from_address = $from_address;
$mail->subject = $subject;
$mail->body = $message;
$mail->priority = $priority;
$mail->cc = $cc;
$mail->prefix = "";
$mail->Mailer = MAILER_REGULAR;
$mail->send();
}
class osimail {
// required
public $to_address;
// or
public $id = 0; //ID in table mailings_emails
// optional
public $to_name = "";
public $from_address = ADMIN_EMAIL;
public $from_name = ADMIN_BRAND;
public $bounce_email = BOUNCE_EMAIL;
public $reply_to_email = "";
public $subject = "no subject";
public $priority = 3;
public $cc = 1;
public $prefix = EMAIL_SUBJ;
// optionally used to update mailings_emails table
public $language = "";
public $country = "";
public $html = "";
public $txt = "";
// for xml/xsl messages
// either
public $mailref = 0; // id of table 'mailings'
// or
public $xml_src = "";
public $html_xsl_src = ""; // either a string or record # in table mailings_xsls
public $txt_xsl_src = ""; // either a string or record # in table mailings_xsls
// for simple text messages
public $message = "";
// errors
public $errorNo = 0;
public $errMsg = "";
// misc
public $Mailer = MAILER_REGULAR;
public $report = TRUE; // report errors to admin
public function send() {
global $debug, $coupon, $smtp_host, $smtp_auth, $smtp_username, $smtp_password, $smtp_port, $smtp_secure;
$coupon = "";
switch ($this->Mailer) {
case "smtp2":
$smtp_id = 2;
require "smtp.php";
$mail->Mailer = "smtp";
break;
default:
$smtp_id = 1;
require "smtp.php";
$mail->Mailer = "smtp";
break;
}
if ($this->mailref > 0) {
$r = mysql_query2("select * from mailings where id=%s", $this->mailref);
if ($row = mysql_fetch_object($r)) {
$this->xml_src = $row->xml;
$r = mysql_query2("select * from mailings_xsls where id=%s", $row->html_xsl);
$this->html_xsl_src = mysql_fetch_object($r)->code;
$r = mysql_query2("select * from mailings_xsls where id=%s", $row->txt_xsl);
$this->txt_xsl_src = mysql_fetch_object($r)->code;
}
}
if ($this->xml_src != "") {
// Load the XML source
$xml = new DOMDocument;
$xml->loadXML($this->xml_src);
$html = "";
$txt = "";
if ($this->html_xsl_src != "") {
$xsl = new DOMDocument;
$xsl->substituteEntities = TRUE;
if (is_numeric($this->html_xsl_src)) {
// is a record #
$r = mysql_query2("select * from mailings_xsls where id=%s", $this->html_xsl_src);
$xsl->loadXML(mysql_fetch_object($r)->code);
} else
$xsl->loadXML($this->html_xsl_src);
$proc = new XSLTProcessor;
$proc->importStyleSheet($xsl);
$html = $proc->transformToXML($xml);
$html = trans_inx($html, $this->to_address, $this->id, $this->mailref, $this->to_name, 1);
};
if ($this->txt_xsl_src != "") {
$xsl = new DOMDocument;
$xsl->substituteEntities = TRUE;
if (is_numeric($this->txt_xsl_src)) {
// is a record #
$r = mysql_query2("select * from mailings_xsls where id=%s", $this->txt_xsl_src);
$xsl->loadXML(mysql_fetch_object($r)->code);
} else
$xsl->loadXML($this->txt_xsl_src);
$proc = new XSLTProcessor;
$proc->importStyleSheet($xsl);
$txt = $proc->transformToXML($xml);
$txt = trans_inx($txt, $this->to_address, $this->id, $this->mailref, $this->to_name, 0);
}
if ($html == "") {
$mail->IsHTML(FALSE);
$mail->Body = $txt;
} else {
$mail->IsHTML(TRUE);
$mail->Body = $html;
$mail->AltBody = $txt;
}
} else {
if ($this->html == "") {
$mail->IsHTML(FALSE);
if ($this->txt == "")
$mail->Body = $this->body;
else
$mail->Body = $this->txt;
} else {
$mail->IsHTML(TRUE);
$mail->Body = $this->html;
$mail->AltBody = $this->txt;
}
}
if ((DEVELOPMENT or TEST_MODUS) and ( $this->to_address != ADMIN_EMAIL)) {
$this->to_name .= "/" . str_replace("@", "-at-", $this->to_address);
$this->to_address = ADMIN_EMAIL;
}
$mail->AddAddress($this->to_address, $this->to_name);
if ($this->reply_to_email != "")
$mail->AddReplyTo($this->reply_to_email, $this->from_name);
$mail->SetFrom($this->from_address, $this->from_name);
$mail->Sender = $this->bounce_email;
$mail->addCustomHeader("Sender: <" . $this->bounce_email . ">");
$mail->addCustomHeader("Return-Path: <" . $this->bounce_email . ">");
$mail->addCustomHeader(X_HEADER . ": ||" . md5b($this->to_address) . "||");
if ($this->mailref > 0)
$mail->addCustomHeader(X_HEADER2 . ": ||" . md5b($this->mailref) . "||");
$mail->Subject = mb_encode_mimeheader($this->prefix . $this->subject, "UTF-8", "Q");
$mail->Priority = $this->priority;
$mail->CharSet = "utf-8";
if ($this->cc) {
$mail->AddCC(ADMIN_EMAIL, ADMIN_BRAND);
}
$mail->DKIM_domain = substr($this->bounce_email, strpos($this->bounce_email, "@") + 1);
$mail->DKIM_private = HTDOCS . '/include/sites/' . SITE . '/keys/.htkeyprivate';
$mail->DKIM_selector = 'phpmailer';
$mail->DKIM_passphrase = '';
$result = $mail->Send();
if (!$result) { // error
if ($this->Mailer == "amazonses") {
$this->errorNo = $mail->AWSErrNo;
$this->errMsg = $mail->AWSErrMsg;
} else {
$this->errorNo = 400;
$this->errMsg = "misc. mail error";
}
debug($this->errorNo, $this->errMsg);
}
return ($result);
}
}
function trans_inx($s, $email, $id = 0, $mailref = 0, $name = "", $is_html = 1) {
// id = ID in table mailings_emails
// mailref = ID in table mailings
//return ($s);
global $email_mailing_id, $mailing_id, $coupon, $db;
if (($id > 0) && ($email == "")) {
$r = mysql_query2("select email from mailings_emails where id=%s", $id);
$email = mysql_fetch_object($r)->email;
}
$body_add_txt = "\n\n||" . md5b($email) . "||\n";
if ($mailref > 0)
$body_add_txt .= "||" . md5b($mailref) . "||\n";
$body_add_html = "\n" . '' . "\n||" . md5b($email) . "||\n";
if ($mailref > 0)
$body_add_html .= " ||" . md5b($mailref) . "||";
$body_add_html .= "
\n";
$email_mailing_id = $id;
$mailing_id = $mailref;
$email_md5 = md5b($email);
$search[] = '/\[%body_add_txt\]/i';
$search[] = '/\[%body_add_html\]/i';
$search[] = '/</';
$search[] = '/>/';
if (!$is_html) {
$search[] = '|<[A-Za-z0-9]+>|';
$search[] = '|[A-Za-z0-9]+>|';
}
$search[] = '/\[email\]/i';
$search[] = '/\[%listcharset\]/i';
$search[] = '/\[%id\]/i';
$search[] = '/\[%code\]/i';
$search[] = '/\[%mailref\]/i';
$search[] = '/\[name\]/i';
$search[] = <<';
if (!$is_html) {
$replace[] = '';
$replace[] = '';
}
$replace[] = $email;
$replace[] = 'UTF-8';
$replace[] = $id;
$replace[] = $email_md5;
$replace[] = $mailref;
$replace[] = $name;
if ($name == "")
$replace[] = '$1';
else
$replace[] = '$2' . $name;
$replace[] = "\n" . str_repeat("=", 75) . "\n";
$s = preg_replace($search, $replace, $s);
$search2 = <<id, $e, $code);
$r2 = mysql_query2("select * from mailings_links_emails_mailing where link=%s and email_mailing=%s", $row->id, $e);
$rows = mysql_numrows($r2);
}
$code = mysql_fetch_object($r2)->code;
$s .= $code;
}
return ($s);
}
function x2($params) {
global $coupon;
$description = $params[1];
$from_date = $params[2];
$to_date = $params[3];
$gb = $params[4];
mysql_query2("START TRANSACTION");
mysql_query2("insert into coupons (description, valid_from, valid_until, gb) values (%s, %s, %s, %s)", $description, $from_date, $to_date, $gb);
$nr = mysql_insert_id();
//$code = md5b ($nr);
$code = shortcode();
mysql_query2("update coupons set code=%s where nr=%s", $code, $nr);
mysql_query2("COMMIT");
$coupon = $code;
return ($code);
}
function telnum_blacklist($telnum, $telcode) {
$err = FALSE;
if ((substr($telcode . $telnum, 0, 4) == "+439") || // 0900 Mehrwert Nummer
(substr($telcode . $telnum, 0, 5) == "+4382") // SMS.at etc.
)
$err = TRUE;
return ($err);
}
function adresse_email($language) {
if ($language == "DE") {
$adresse = "aus Deutschland: " . ADMIN_PHONE_DE . NL . "(0,09 Euro pro Minute aus den deutschen Festnetz, ggf. abweichende Preise aus dem Mobilfunk)" . NL . "aus Österreich: " . ADMIN_PHONE_AT . NL . "aus anderen Ländern: " . ADMIN_PHONE;
} else {
$adresse = "Austria: " . ADMIN_PHONE;
}
return ($adresse);
}
function t_select($default, $prod_id, $with_blank = 0, $section = "", $lang = "DE") {
global $db, $language, $debug;
if ($lang == "")
$lang = $language;
if ($with_blank) {
echo ' ";
echo " \n";
}
if ($section == "")
$r = mysql_query2("select id, schluessel from translations where language=%s and mandant=%s order by schluessel", $lang, MANDANT);
else
$r = mysql_query2("select id, schluessel from translations where sect=%s and language=%s and mandant=%s order by schluessel", $section, $lang, MANDANT);
while ($row = mysql_fetch_object($r)) {
echo "id, "\"";
if ($default == $row->id)
echo ' selected="selected"';
echo ">", strip_tags($row->schluessel . " - " . substr(t2($row->id, $prod_id, 0), 0, 200)); //, "($row->id)";
echo " \n";
}
}
function parent_select($default, $prod_id, $with_blank = 0, $what = 0) {
global $db, $language;
if ($with_blank) {
echo ' ";
echo " \n";
}
switch ($what) {
case 1:
$r = mysql_query2("select id, sku, nameTxt, active from products where parent is NULL and mandant=%s and active order by sku", MANDANT);
break;
case 2:
$r = mysql_query2("select id, sku, nameTxt, active from products where parent is NULL and mandant=%s and not active order by sku", MANDANT);
break;
case 0:
$r = mysql_query2("select id, sku, nameTxt, active from products where parent is NULL and mandant=%s order by sku", MANDANT);
break;
}
while ($row = mysql_fetch_object($r)) {
$t = t3($row->nameTxt, $row->id, 0, "", "", "", "", "", "DE", TRUE, TRUE);
echo "id, "\"";
if ($row->active)
echo ' style="background-color:#ffe49b;" ';
if ($default == $row->id)
echo ' selected="selected"';
//echo ">", $row->sku, " - ", $row->id, " - ", substr(t2($row->name, $row->id, 0), 0, 25);
//echo ">", $row->sku, " - ", $row->id, " - ", substr($row2->translation, 0, 25);
echo ">", $row->sku, " - ", $row->id, " - ", mb_substr($t, 0, 25);
echo " \n";
}
}
function subparent_select($default, $prod_id, $with_blank = 0) {
global $db, $language;
if ($with_blank) {
echo ' ";
echo " \n";
}
$r = mysql_query2("select * from subparents where parent=%s", $prod_id);
while ($row = mysql_fetch_object($r)) {
echo "id, "\"";
if ($default == $row->id) {
echo ' selected="selected"';
}
echo ">", $row->sku, " - ", $row->id;
echo " \n";
}
}
function color_select($default, $with_blank = 0, $ismap = FALSE, $product = FALSE) {
global $db, $language, $language_sort;
if ($with_blank) {
echo ' ";
echo " \n";
}
if ($ismap) {
$r = mysql_query2("select id, `$language_sort` from colors where is_map order by `$language_sort`");
} else {
if ($product->parent) {
if ($product->id) {
$r = mysql_query2("select c.id, c.`$language_sort` from colors c left join products p on p.parent=%s and p.id<>%s and p.color=c.id where p.id is null order by `$language_sort`", $product->parent, $product->id);
} else {
$r = mysql_query2("select c.id, c.`$language_sort` from colors c left join products p on p.parent=%s and p.color=c.id where p.id is null order by `$language_sort`", $product->parent);
}
} else {
$r = mysql_query2("select id, `$language_sort` from colors order by `$language_sort`");
}
// FIX - funktioniert so nicht :-(
$r = mysql_query2("select id, `$language_sort` from colors order by `$language_sort`");
}
while ($row = mysql_fetch_object($r)) {
echo "id, "\"";
if ($default == $row->id)
echo ' selected="selected"';
echo ">", $row->$language_sort;
echo " \n";
}
}
function display_unit_select($default, $with_blank = 0, $typ = "") {
global $db, $language, $language_sort;
if ($with_blank) {
echo ' ";
echo " \n";
}
if ($typ == "")
$r = mysql_query2("select id, `$language_sort` from units order by `$language_sort`");
else
$r = mysql_query2("select id, `$language_sort` from units where typ=%s order by `$language_sort`", $typ);
while ($row = mysql_fetch_object($r)) {
echo "id, "\"";
if ($default == $row->id)
echo ' selected="selected"';
echo ">", $row->$language_sort;
echo " \n";
}
}
function category_select($default, $with_blank = 0) {
global $db, $language, $language_sort;
if ($with_blank) {
echo ' ";
echo " \n";
}
$r = mysql_query2("select SQL_NO_CACHE id, name_DE from categories where mandant=%s order by `name_DE`", MANDANT);
while ($row = mysql_fetch_object($r)) {
echo "id, "\"";
if ($default == $row->id)
echo ' selected="selected"';
echo ">", $row->name_DE;
echo " \n";
}
}
function outer_material_select($default, $with_blank = 0) {
global $db, $language, $language_sort;
if ($with_blank) {
echo ' ";
echo " \n";
}
$r = mysql_query2("select * from outer_materials order by `name_DE`");
while ($row = mysql_fetch_object($r)) {
echo "id, "\"";
if ($default == $row->id)
echo ' selected="selected"';
echo ">", $row->name_DE;
echo " \n";
}
}
function template_select($default, $with_blank = 0, $only_existing = FALSE) {
global $db, $language, $language_sort;
if ($with_blank) {
echo ' ";
echo "\n";
}
if ($only_existing) {
$r = mysql_query2("select t.* from templates t, products p, browse_nodes b where (t.all_products or (p.mandant=%s and p.browse_node=b.id and b.template=t.id)) and t.active group by t.id order by t.id", MANDANT);
} else {
$r = mysql_query2("select * from templates where active order by id");
}
while ($row = mysql_fetch_object($r)) {
echo ' id)
echo " Selected";
echo ">", addslashes($row->$language_sort);
echo " \n";
}
}
function imagefiles($parent, $existing_images) {
$result = array();
$r = mysql_query2("select fname from photos p, photos_parents pp where pp.photo=p.id and pp.parent=%s", $parent);
while ($row = mysql_fetch_object($r)) {
$result[] = $row->fname;
}
$r = mysql_query2("select fname from photos p left join photos_parents pp on pp.photo=p.id where pp.id is null");
while ($row = mysql_fetch_object($r)) {
$result[] = $row->fname;
}
$result = array_merge($result, $existing_images);
$result = array_unique($result);
sort($result);
return ($result);
}
function image_select($default, $with_blank = 0, $imagefiles) {
global $db;
if ($with_blank) {
echo ' ";
echo " \n";
}
while (list(, $file) = each($imagefiles)) {
if (preg_match("/^[^.].*\.(gif|jpg|jpeg|png)$/i", $file)) {
echo "", htmlspecialchars($file);
echo " \n";
}
}
}
function xmlfiles() {
global $db;
return ($result);
}
function season_select($default, $with_blank = 0, $language) {
global $db;
if ($with_blank) {
echo ' ";
echo " \n";
}
$r = mysql_query2("select * from seasons where language=%s order by name", $language);
while ($row = mysql_fetch_object($r)) {
echo "id, "\"";
if ($default == $row->id)
echo ' selected="selected"';
echo ">", $row->name;
echo " \n";
}
}
function special_size_select($default, $with_blank = 0, $language) {
global $db, $language_sort;
if ($with_blank) {
echo ' ";
echo " \n";
}
$r = mysql_query2("select * from special_sizes order by `$language_sort`");
while ($row = mysql_fetch_object($r)) {
echo "id, "\"";
if ($default == $row->id)
echo ' selected="selected"';
echo ">", $row->$language_sort;
echo " \n";
}
}
function size_select($default, $with_blank = 0, $country = "DE", $is_map = FALSE) {
global $db;
if ($with_blank) {
echo ' ";
echo " \n";
}
if ($is_map)
$r = mysql_query2("select * from sizes where country=%s and is_map order by name", $country);
else
$r = mysql_query2("select * from sizes where country=%s order by name", $country);
while ($row = mysql_fetch_object($r)) {
echo "id, "\"";
if ($default == $row->id)
echo ' selected="selected"';
echo ">", $row->name;
echo " \n";
}
}
function style_keyword_select($default, $with_blank = 0) {
global $db, $language, $language_sort;
if ($with_blank) {
echo ' ";
echo " \n";
}
$r = mysql_query2("select id, `$language_sort` from style_keywords order by `$language_sort`");
while ($row = mysql_fetch_object($r)) {
echo "id, "\"";
if ($default == $row->id)
echo ' selected="selected"';
echo ">", $row->$language_sort;
echo " \n";
}
}
function clothing_type_select($default, $with_blank = 0) {
global $db, $language;
if ($with_blank) {
echo ' ";
echo " \n";
}
$r = mysql_query2("select id, name from clothing_types order by `name`");
while ($row = mysql_fetch_object($r)) {
echo "id, "\"";
if ($default == $row->id)
echo ' selected="selected"';
echo ">", $row->name;
echo " \n";
}
}
function style_name_select($default, $with_blank = 0) {
global $db, $language;
if ($with_blank) {
echo ' ";
echo " \n";
}
$r = mysql_query2("select id, name_DE from style_names order by `name_DE`");
while ($row = mysql_fetch_object($r)) {
echo "id, "\"";
if ($default == $row->id)
echo ' selected="selected"';
echo ">", $row->name_DE;
echo " \n";
}
}
function length_name_select($default, $with_blank = 0) {
global $db, $language;
if ($with_blank) {
echo ' ";
echo " \n";
}
$r = mysql_query2("select id, name_DE from length_names order by `name_DE`");
while ($row = mysql_fetch_object($r)) {
echo "id, "\"";
if ($default == $row->id)
echo ' selected="selected"';
echo ">", $row->name_DE;
echo " \n";
}
}
function apparel_closure_select($default, $with_blank = 0) {
global $db, $language;
if ($with_blank) {
echo ' ";
echo " \n";
}
$r = mysql_query2("select id, name_DE from apparel_closure_type order by `name_DE`");
while ($row = mysql_fetch_object($r)) {
echo "id, "\"";
if ($default == $row->id)
echo ' selected="selected"';
echo ">", $row->name_DE;
echo " \n";
}
}
function browse_node_select($default, $with_blank = 0) {
global $db, $language;
if ($with_blank) {
echo ' ";
echo " \n";
}
$r = mysql_query2("select id, name from browse_nodes where `active` order by `name`");
while ($row = mysql_fetch_object($r)) {
echo "id, "\"";
if ($default == $row->id)
echo ' selected="selected"';
echo ">", $row->name;
echo " \n";
}
}
function department_select($default, $with_blank = 0) {
global $db, $language, $language_sort;
if ($with_blank) {
echo ' ";
echo " \n";
}
$r = mysql_query2("select id, `$language_sort` from departments order by `$language_sort`");
while ($row = mysql_fetch_object($r)) {
echo "id, "\"";
if ($default == $row->id)
echo ' selected="selected"';
echo ">", $row->$language_sort;
echo " \n";
}
}
function opacity_select($default, $with_blank = 0) {
global $db, $language, $language_sort;
if ($with_blank) {
echo ' ";
echo " \n";
}
$r = mysql_query2("select * from opacity order by `$language_sort`");
while ($row = mysql_fetch_object($r)) {
echo "id, "\"";
if ($default == $row->id)
echo ' selected="selected"';
echo ">", $row->$language_sort;
echo " \n";
}
}
function pattern_select($default, $with_blank = 0) {
global $db, $language, $language_sort;
if ($with_blank) {
echo ' ";
echo " \n";
}
$r = mysql_query2("select * from patterns order by `$language_sort`");
while ($row = mysql_fetch_object($r)) {
echo "id, "\"";
if ($default == $row->id)
echo ' selected="selected"';
echo ">", $row->$language_sort;
echo " \n";
}
}
function brand_select($default, $with_blank = 0) {
global $db, $language;
if ($with_blank) {
echo ' ";
echo " \n";
}
$r = mysql_query2("select id, name from brands where mandant=%s order by name", MANDANT);
while ($row = mysql_fetch_object($r)) {
echo "id, "\"";
if ($default == $row->id)
echo ' selected="selected"';
echo ">", $row->name;
echo " \n";
}
}
function year_select($default, $with_blank = 0) {
if ($with_blank) {
echo ' ";
echo " \n";
}
$start = 2011;
$end = date("Y") + 3;
$i = $start;
while ($i <= $end) {
echo "", $i;
echo " \n";
$i++;
}
}
function country_select($default, $with_blank = 0, $export = FALSE) {
global $db, $language, $language_sort;
$language_sort = mysql_real_escape_string($language_sort);
if ($with_blank) {
echo ' ";
echo " \n";
}
if ($export)
$r = mysql_query2("select c.* from countries c, mandanten_countries m where m.mandant=%s and m.marketplace and m.country=c.id and c.export group by c.id order by `" . $language_sort . "`", MANDANT);
else
$r = mysql_query2("select * from countries order by `" . $language_sort . "`");
while ($row = mysql_fetch_object($r)) {
echo "id, "\"";
if ($default == $row->id)
echo ' selected="selected"';
echo ">", addslashes($row->$language_sort), " ";
echo "\n";
}
}
function mandant_select($default, $with_blank = 0) {
global $db;
if ($with_blank) {
echo ' ";
echo " \n";
}
$r = mysql_query2("select * from mandanten where active");
while ($row = mysql_fetch_object($r)) {
echo "id, "\"";
if ($default == $row->id)
echo ' selected="selected"';
echo ">", addslashes($row->name);
echo "\n";
}
}
function lager_select($default, $with_blank = 0) {
global $db;
if ($with_blank) {
echo ' ";
echo " \n";
}
$r = mysql_query2("select * from lager where active and mandant=%s order by kurzname, id", MANDANT);
while ($row = mysql_fetch_object($r)) {
echo "id, "\"";
if ($default == $row->id)
echo ' selected="selected"';
echo ">", addslashes($row->kurzname);
echo "\n";
}
}
function language_select($default, $with_blank = 0) {
global $db, $language, $language_sort;
$language_sort = mysql_real_escape_string($language_sort);
if ($with_blank) {
echo ' ";
echo " \n";
}
$r = mysql_query2("select SQL_NO_CACHE * from languages order by `" . $language_sort . "`");
while ($row = mysql_fetch_object($r)) {
echo "id, "\"";
if ($default == $row->id)
echo ' selected="selected"';
echo ">", addslashes($row->$language_sort);
echo "\n";
}
}
function country_name($country, $language_sort_overwrite = "") {
global $db, $language_sort;
$ls = $language_sort_overwrite == "" ? $language_sort : $language_sort_overwrite;
$r = mysql_query2("select * from countries where iso=%s", $country);
if ($row = mysql_fetch_object($r)) {
return ($row->$ls);
} else
return ("");
}
function href($href = "", $ssl = -1, $arguments = "", $lang = "", $what = "", $echo = 1) {
global $language;
$ssl = 1; // immer SSL
if ($lang == "")
$lang = $language;
//if ($href == "") $href = "index";
$ret = "";
if ($ssl == 1)
$ret .= HOSTS;
if ($ssl == 0)
$ret .= HOST;
$ret .= HREF_START;
switch ($lang) {
case "EN":
$ret .= "english/";
break;
case "ES":
$ret .= "espanol/";
break;
case "FR":
$ret .= "francais/";
break;
case "IT":
$ret .= "italiano/";
break;
default:
$ret .= "deutsch/";
break;
}
if ($href <> "")
$ret .= $href . "/";
if ($what <> "")
$ret .= $what . "/";
if ($arguments <> "") {
$ret .= $arguments;
if (substr($arguments, 0, 1) <> '?')
$ret .= '/';
}
if ($echo)
echo $ret;
return ($ret);
}
function ahref($href = "", $ssl = -1, $arguments = "", $lang = "", $what = "", $echo = 1) {
$ret = "";
$ret .= '';
if ($echo)
echo $ret;
return ($ret);
}
function days_to_months($days) {
switch ($days) {
case 29:
case 30:
$months = 1;
break;
case 89:
case 90:
$months = 3;
break;
case 179:
case 180:
$months = 6;
break;
case 731:
$months = 24;
break;
case 1825:
case 1830:
$months = 60;
break;
default:
$months = round($days / 30, 0);
break;
}
return ($months);
}
function interval($days, $paymethod) {
switch ($paymethod) {
/*
case "P":
$i = days_to_months ($days) * 30 . " day";
break;
*/
default:
$i = days_to_months($days) . " month";
break;
}
return ($i);
}
function message_bar($html, $type = 0) {
echo '
';
}
function curr($amount, $from = "EUR", $to = "", $print = 1) {
global $language, $scurrency;
if ($to == "")
$to = $scurrency;
$r = mysql_query2("select * from currencies where iso=%s", $from);
$from_rate = mysql_fetch_object($r)->rate;
$r = mysql_query2("select * from currencies where iso=%s", $to);
$row = mysql_fetch_object($r);
$to_rate = $row->rate;
$result = $to_rate / $from_rate * $amount;
if ($print) {
$result = sprintf("%0.2f", $result);
if ($language == "DE") {
$result = str_replace(".", ",", $result);
};
$result = $row->html_symbol . $result;
};
return ($result);
}
;
function htmlentities2($str) {
return (htmlentities($str, ENT_COMPAT, "UTF-8"));
}
function geoip_country_code_by_addr($gip, $ip) {
// return $gip->lookupCountryCode ($ip);
$record = $gip->city($ip);
return $record->country->isoCode;
}
function detectLanguage($defaultlang = 'DE') {
global $gip;
$lang = "";
if (array_key_exists('HTTP_ACCEPT_LANGUAGE', $_SERVER)) {
$langlist = explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']);
// $lang = $defaultlang;
foreach ($langlist as $curLang) {
$curLang = explode(';', $curLang);
/* use regular expression for language detection */
if (preg_match('/(en|de)-?.*/', $curLang[0], $reg)) {
$lang = $reg[1];
break;
}
}
}
if ($lang == "") {
$country = geoip_country_code_by_addr($gip, $_SERVER["REMOTE_ADDR"]);
switch ($country) {
case "US":
case "CA":
case "UK":
case "AU":
case "NZ":
$lang = "EN";
break;
case "DE":
case "AT":
case "CH":
$lang = "DE";
break;
case "ES":
$lang = "ES";
break;
case "FR":
$lang = "FR";
break;
case "IT":
$lang = "IT";
break;
}
}
if ($lang == "") {
$lang = $defaultlang;
}
return strtoupper($lang);
}
;
function no_cache() {
header('Expires: Thu, 19 Nov 1981 08:52:00 GMT');
header('Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0');
header('Pragma: no-cache');
}
function check_captcha($captcha) {
global $err;
$captcha = strtoupper($captcha);
if (isset($_SESSION["captcha"])) {
if ($_SESSION["captcha"] != $captcha) {
$err[] = t("Zeichenfolge nicht korrekt", 0);
} else {
$_SESSION["captcha2"] = $captcha;
}
} else {
$err[] = t("Zeichenfolge nicht korrekt", 0);
}
}
function payflag($paymethod, $flag) {
$flag = mysql_real_escape_string($flag);
$r = mysql_query2("select `$flag` as flag from paymethods where id=%s", $paymethod);
$row = mysql_fetch_object($r);
return ($row->flag);
}
function check_call($telnum) {
$request = CHECK_CALL_URL . "?number=" . urlencode($telnum);
$ch = curl_init($request);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_FAILONERROR, TRUE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_VERBOSE, TRUE);
curl_setopt($ch, CURLOPT_TIMEOUT, 15);
$result = curl_exec($ch);
$errorMsg = curl_error($ch);
$errorNumber = curl_errno($ch);
curl_close($ch);
parse_str($result, $result_a);
if (intval($result_a["calls"]) == 0)
return (FALSE);
else
return (TRUE);
}
function paytext($paymethod, $long = 0) {
global $db, $language;
if (empty($language))
$lang = "DE";
else
$lang = $language;
if ($long)
$name = "longname_" . $lang;
else
$name = "name_" . $lang;
$r = mysql_query2("select * from paymethods where id=%s", $paymethod);
if ($row = mysql_fetch_object($r)) {
return ($row->$name);
} else {
return (FALSE);
}
}
function md5b($s) {
return (md5(MD5STR . strtolower($s)));
}
function md5cs($s) {
return (md5(MD5STR . $s));
}
$globalshortcodecount = 0;
function shortcode() {
global $globalshortcodecount;
$globalshortcodecount++;
$len = 8;
$base = 'ABCDEFGHKLMNOPQRSTWXYZabcdefghjkmnpqrstwxyz123456789';
$max = strlen($base) - 1;
$code = '';
while (strlen($code) < $len)
$code .= $base{mt_rand(0, $max)};
//if (DEVELOPMENT && ($globalshortcodecount < 5)) return (str_repeat("A", $len));
return ($code);
}
function title_select($default, $with_blank = 0) {
global $db, $language, $language_sort;
if ($with_blank) {
echo ' ";
echo "\n";
}
$r = mysql_query2("select * from titles order by order1");
while ($row = mysql_fetch_object($r)) {
if (($row->abbrev == "X") && (!$with_male_female))
continue;
echo ' id)
echo ' selected="selected"';
echo ">", addslashes($row->$language_sort);
echo "\n";
}
}
function title_translate($id, $language2 = "") {
global $db, $language;
$name = "";
if ($language2 == "")
$language2 = $language;
$language_sort = "name_" . $language2;
$r = mysql_query2("select * from titles where id=%s", $id);
if ($row = mysql_fetch_object($r)) {
if ($default == $row->id)
echo ' selected="selected"';
$name = $row->$language_sort;
}
return ($name);
}
function xml_start($gift_template = "") {
global $language;
$s = <<
EOT;
$s .= "$language \n";
$s .= "" . SITE . " \n";
$s .= <<y
n
EOT;
$s .= "" . href("", 0, GOOGLE_UTM, $language, "", 0) . " \n";
if ($gift_template != "")
$s .= "" . $gift_template . " ";
$s .= "\n";
return ($s);
}
function xml_end() {
global $language;
$s = <<
EOT;
return ($s);
}
function shortlink($url) {
$rows = 0;
while (!$rows) {
$code = shortcode();
mysql_query2("insert ignore into shortlinks (code, url) values (%s, %s)", $code, $url);
$r = mysql_query2("select * from shortlinks where url=%s", $url);
$rows = mysql_numrows($r);
}
return (mysql_fetch_object($r)->code);
}
class order {
public
$nr = "",
$title = "",
$firstname = "",
$lastname = "",
$company = "",
$address1 = "",
$address2 = "",
$zip = "",
$city = "",
$state = "",
$country = "",
$email = "",
$geoip_country = "",
$telnum = "",
$captcha1 = "",
$captcha2 = "",
$username = "",
$password = "",
$product = "",
$gb_max = "",
$rebills = "",
$customer = "",
$description = "",
$price1 = 0,
$days1 = 0,
$days2 = 0,
$paymethod = "",
$account = "",
$accountname = "",
$bankno = "",
$expiresm = "",
$expiresy = "",
$cvv = "",
$discountcode = "",
$hostname = "",
$referrersite = "",
$referrersite2 = "",
$kto_nicht_gepr = "",
$gb_base = "",
$language = "",
$srv1 = "",
$srv2 = "",
$srv3 = "",
$srv4 = "",
$srv5 = "",
$tokendays = "",
$affid = "",
$affprog = "",
$gift = "",
$gift_email = "",
$gift_template = "",
$gift_text = "",
$m_traffic = "",
$m_payment = "",
$m_laufzeit = "";
public function xml($isgift = FALSE) {
if ($isgift)
$xml = xml_start($this->gift_template);
else
$xml = xml_start();
$xml .= "";
if ($isgift)
$xml .= t("Herzlichen Glückwunsch!", 0);
else
$xml .= t("Herzlich willkommen!", 0);
$xml .= " ";
if ($isgift) {
$xml .= "";
if (strlen($this->firstname . $this->lastname) > 0) {
$giftname = $this->firstname . " " . $this->lastname;
} else {
$giftname = $this->email;
}
if ($this->gift_text == "")
$xml .= t("gift01", 0, $giftname) . ":";
else
$xml .= $this->gift_text;
$xml .= " ";
} else {
if (strlen($this->lastname) > 0) {
$xml .= "" . t("An", 0) . NL . $this->firstname . " " . $this->lastname . NL .
$this->city . NL . country_name($this->country) . " " . NL;
};
$xml .= "" . t("txt50", 0, $this->nr) . " ";
$xml .= "" . t("Sie haben folgende Leistung bestellt:", 0) . " ";
}
$xml .= "" . t("product_descr", 0) . " " . $this->description . " ";
$xml .= "";
if ($isgift)
$xml .= t("Ein Geschenk", 0);
else
$xml .= "EUR " . money($this->price1);
$xml .= " ";
if (!$isgift && $this->gift_template)
$xml .= "" . t("gift02", 0, $this->gift_email) . " ";
$xml .= "" . t("Ihre Zugangsdaten lauten wir folgt:", 0) . " ";
$xml .= "";
$xml .= '' . t("Benutzername", 0) . " " . full_username($this->username, $this->gb_max) . " ";
$xml .= '' . t("Passwort", 0) . " ";
if ($this->password != "")
$xml .= $this->password;
else
$xml .= t("unverändert", 0);
$xml .= " ";
$xml .= server_address_xml();
$xml .= " ";
if ($this->gb_max > 999900) { // Flatrate
$xml .= "" . t("txt51b", 0) . " ";
};
if (!$isgift) {
if ($this->paymethod == "U") {
$xml .= "" . t("txt55", 0) . " ";
$xml .= zahlungsinfo($this->country, t("Bestellung", 0) . " " . $this->nr, $this->price1, TRUE, $this->nr);
};
if ($this->paymethod == "S") {
$xml .= "" . t("txt59a", 0) . " ";
//$xml .= zahlungsinfo ($this->country, "Bestellung" . $this->nr, $this->price1, TRUE);
};
}
$xml .= "" . t("txt51", 0) . " " . href("install", 1, GOOGLE_UTM, $this->language, "", 0) . " " . t("Technische Hilfe", 0) . " ";
if ($isgift) {
$xml .= "" . t("txt52a", 0) . " " . href("traffic", 0, GOOGLE_UTM, $this->language, "", 0) . " " . t("Kundenbereich", 0) . " ";
} else {
$xml .= "" . t("txt52", 0) . " " . href("traffic", 0, GOOGLE_UTM, $this->language, "", 0) . " " . t("Kundenbereich", 0) . " ";
if ($this->paymethod == "D") {
$xml .= "" . t("test3", 0) . ": " . href("", 1, GOOGLE_UTM, $this->language, "", 0) . " " . t("Bestellen", 0) . " ";
}
if ($this->paymethod == "K") {
$xml .= "" . t("txt53", 0) . " ";
};
if ($this->paymethod == "L") {
$xml .= "" . t("txt54", 0) . " ";
};
if ($this->paymethod == "P") {
$xml .= "" . t("txt60", 0) . " " . t("txt61", 0) . " ";
$xml .= "" . HOSTS . "/pp2/" . $this->nr . " ";
$xml .= "" . t("txt58", 0) . " ";
};
if ($this->paymethod <> "D") {
// kein Demo Account
$xml .= t("txt62", 0) . " ";
if ($this->rebills) {
$xml .= "" . t("txt63", 0) . " " . t("txt64", 0) . " ";
} else {
$xml .= "" . t("txt65", 0) . " ";
};
if ($this->paymethod == "L") {
$xml .= "" . t("txt66", 0) . " " . t("txt67", 0) . " ";
};
if (ereg2($this->paymethod, "L|K|S|P")) {
$xml .= "" . t("Leistungsbeginn", 0) . ": " . date("Y-m-d") . " ";
} else {
$xml .= "" . t("txt68", 0) . " ";
};
$xml .= "" . t("Erfüllungsort", 0) . ": " . ADMIN_CITY . NL . t("txt70", 0) . NL . t("txt71", 0) . NL . t("txt72", 0) . " ";
$xml .= "" . href("agbs", 0, GOOGLE_UTM, $this->language, "", 0) . " " . t("AGBs", 0) . " ";
};
$xml .= "" . t("txt73", 0) . " ";
$xml .= "" . ADMIN_COMPANY . NL . ADMIN_STREET . NL . ADMIN_ZIP . " " . ADMIN_CITY . NL . "Tel.: " . ADMIN_PHONE;
if (URLAUB)
$xml .= " " . t("txt407", 0);
$xml .= NL . "Fax: " . ADMIN_FAX . NL . "E-Mail: " . SUPPORT_EMAIL . NL . "Web: http://www.simonconsulting.at" . NL .
t("Mitglied der Wirtschaftskammer Steiermark", 0) . NL . ADMIN_FN . NL . "UID: " . ADMIN_UID . NL .
t("Geschäftsführer", 0) . ": " . HERAUSGEBER . " ";
}
if (!$isgift)
$xml .= t("Schluss_XML", 0);
$xml .= xml_end();
return ($xml);
}
}
function prodprice($nr, $mutation1 = 0) {
global $db, $mutation;
$price = 0;
if ($mutation1 == 0)
$mutation1 = $mutation;
$r = mysql_query2("select * from products where nr=%s", $nr);
if ($row = mysql_fetch_object($r)) {
$price = $row->price1;
if ($mutation1 != 0) {
$r2 = mysql_query2("select * from prices where mutation=%s and product=%s", $mutation1, $nr);
if ($row2 = mysql_fetch_object($r2))
if ($row2->price > 0)
$price = $row2->price;
}
};
return ($price);
}
function timer($mode) {
// 1 = start | 2 = stop
global $timer_time;
switch ($mode) {
case 1:
$timer_time = microtime(TRUE);
break;
case 2:
$diff = microtime(TRUE) - $timer_time;
break;
}
}
function is_blank_or_null($n) {
return ((($n == "") or ( $n == "0") or ( strtoupper($n) == "NULL")) ? TRUE : FALSE);
}
function makenull($n) {
return (is_blank_or_null($n) ? "NULL" : $n);
}
function makeblank($n) {
return ((($n == "") or ( substr($n, 0, 1) == "0") or ( strtoupper($n) == "NULL")) ? "" : $n);
}
function makezero($n) {
return ((($n == "") or ( $n == "0") or ( strtoupper($n) == "0")) ? "" : $n);
}
function number_format2($num, $dec = 0) {
global $language;
if ($language == "DE")
return (number_format($num, $dec, ",", "."));
else
return (number_format($num, $dec, ".", ","));
}
function make_url($url, $country) {
global $db;
$r = "";
if (substr($url, 0, 4) == "http")
$r = $url;
else {
$r = mysql_query2("select * from countries where id=%s", $country);
$country = mysql_fetch_object($r);
$r = $country->amazon_url . "/dp/" . $url;
$r .= preg_match("/\?/", $url) ? "&" : "?";
$r .= "tag=" . $country->amazon_partner_id;
}
return ($r);
}
function buildEAN13Checksum($ean) {
$s = preg_replace("/([^\d])/", "", $ean);
if (strlen($s) != 12) {
return false;
}
$check = 0;
for ($i = 0; $i < 12; $i++) {
$check += (($i % 2) * 2 + 1) * $s{$i};
}
$check = (10 - ($check % 10)) % 10;
return $check;
}
class price {
public $price = 0;
public $sale_price = 0;
public $sale_from = "";
public $sale_to = "";
public $actual = 0;
}
function price_country($country, $product, $parent = TRUE) {
global $db;
$price = new price;
if ($parent) {
$r = mysql_query2("select *, if(sale_from<=now() and sale_to>=now() and sale_price>0, sale_price, price) as actual from prices p, countries c where c.iso=%s and p.country=c.id and p.product=%s", $country, $product);
} else {
$r = mysql_query2("select avg(price) as price, 0 as sale_price, NULL as sale_from, NULL as sale_to, avg(price) as actual from prices p, countries c, products pp where c.iso=%s and p.country=c.id and p.product=pp.id and pp.parent=%s", $country, $product);
}
if ($row = mysql_fetch_object($r)) {
$price->price = $row->price;
$price->sale_price = $row->sale_price;
$price->sale_from = $row->sale_from;
$price->sale_to = $row->sale_to;
$price->actual = $row->actual;
}
return ($price);
}
function myhtmlspecialchars($s) {
return (htmlspecialchars($s, ENT_QUOTES | ENT_HTML5, "UTF-8"));
}
function url_key($id, $section = "P") {
global $debug, $language;
$url_key = "";
switch ($section) {
case "P":
// product
$r = mysql_query2('select p2.url_key from products p, products p2 where p.parent=p2.id and p.id=%s', $id);
if ($product = mysql_fetch_object($r)) {
$url_key = urlencode(myhtmlspecialchars(t2($product->url_key, $id, 0)));
}
break;
case "C":
// category
$r = mysql_query2('select * from categories where id=%s', $id);
if ($category = mysql_fetch_object($r)) {
$url_key = rawurlencode(str_replace("&", "_", str_replace(" ", "_", $category->{'name_' . $language})));
}
break;
}
//if ($url_key != "") $url_key .= "/";
return ($url_key);
}
function category_link($id, $echo = TRUE) {
global $db;
$url_key = url_key($id, "C");
$r = mysql_query2('select id from products p where parent is null and active and category=%s and (select if(sum(pr.qty)>0,1,0) from products pr where pr.parent=p.id and active)>0', $id);
if (mysql_numrows($r) > 1) {
$url = ahref("category", -1, $url_key, "", $id, 0);
} else {
$parent = mysql_fetch_object($r);
$url = ahref("parent", -1, $url_key, "", $parent->id, 0);
}
if ($echo)
echo $url;
return ($url);
}
function remove_size($s) {
global $language;
switch ($language) {
case "DE":
$s = preg_replace('/(.*), (Gr.|Größe) *(S|M|L|XL)(.*)/i', '$1$4', $s);
break;
case "EN":
$s = preg_replace('/(.*), (size) *(S|M|L|XL)(.*)/i', '$1$4', $s);
break;
case "FR":
$s = preg_replace('/(.*), (taille) *(S|M|L|XL)(.*)/i', '$1$4', $s);
break;
}
return ($s);
}
function authorized($show_dialog = FALSE) {
global $db, $v_user, $cookie_name, $geoip_ip;
$username = setorblank("username", "", "GP");
$password = setorblank("password", "", "GP");
$code = setorblank("code", "", "GP");
$google_secret = setorblank("google_secret", "", "GP");
$code = str_replace(" ", "", $code);
if (isset($_COOKIE[$cookie_name]))
$browser_keys = explode("|", $_COOKIE[$cookie_name]);
else
$browser_keys = array();
if (!empty($username) && !empty($password)) {
unset($_SESSION["v_user"]);
$r = mysql_query2("select * from users where username=%s and password_md5=%s and active", $username, md5cs($password));
if ($row = mysql_fetch_object($r)) {
$_SESSION["v_user"] = $username;
if (preg_match('/admin/', $row->access)) {
$_SESSION["v_user_is_admin"] = 1;
} else {
$_SESSION["v_user_is_admin"] = 0;
};
} else {
mysql_query2("insert into `access` (ip, dat, admin) values (%s, now(), 1)", $geoip_ip);
}
};
if (!isset($_SESSION["v_user"])) {
if ($show_dialog)
require "authorize.php";
else
require "authorize_top.php";
return (FALSE);
} else {
$v_user = $_SESSION["v_user"];
if ($v_user == "") {
if ($show_dialog)
require "authorize.php";
else
require "authorize_top.php";
return (FALSE);
};
}
$r = mysql_query2("select * from users where username=%s", $v_user);
if ($row = mysql_fetch_object($r)) {
if ($row->twofactor) {
if (empty($row->google_secret)) {
// noch kein GS in der DB
if (strlen($google_secret) == 16) {
// Barcode wurde dem User schon gezeigt und er hat bestätigt
$key = bin2hex(openssl_random_pseudo_bytes(128));
mysql_query2("update users set google_secret=%s where id=%s", $google_secret, $row->id);
mysql_query2("insert into browser_keys (user, key1) values (%s, %s)", $row->id, $key);
$browser_keys[] = $key;
setcookie($cookie_name, implode("|", $browser_keys), time() + 3600 * 24 * 365, "/"); // 1 year
require "authorize_code.php";
} else {
require "authorize_google_secret.php";
return (FALSE);
}
} else {
$ok = FALSE;
$r2 = mysql_query2("select * from browser_keys where user=%s", $row->id);
while (($row2 = mysql_fetch_object($r2)) && (!$ok)) {
if (array_search($row2->key1, $browser_keys) !== FALSE)
$ok = TRUE;
}
if ($ok) {
return (TRUE);
} else {
if (strlen($code) == 6) {
$ga = new PHPGangsta_GoogleAuthenticator();
if ($ga->verifyCode($row->google_secret, $code, 2)) { // 2 = 2*30sec clock tolerance
$key = bin2hex(openssl_random_pseudo_bytes(128));
mysql_query2("insert into browser_keys (user, key1) values (%s, %s)", $row->id, $key);
$browser_keys[] = $key;
setcookie($cookie_name, implode("|", $browser_keys), time() + 3600 * 24 * 365, "/"); // 1 year
return (TRUE);
} else {
$error[] = "Fehlerhafter Code";
require "authorize_code.php";
}
} else {
require "authorize_code.php";
}
}
}
} else {
return (TRUE);
}
}
}
function set_lanuage_to_mandanten() {
global $language;
$language = "DE";
$r = mysql_query2("select c.language from mandanten m, countries c where m.id=%s and m.primary_country=c.id", MANDANT);
if ($row = mysql_fetch_object($r)) {
$language = $row->language;
}
}
?>
COVID-19 Grafik Plattform Österreich - Main
require "include/nav.php" ?>