Revision 430 | Revision 432 | Zur aktuellen Revision | Blame | Vergleich mit vorheriger | Letzte Änderung | Log anzeigen | RSS feed
<?php/*** @author Lars Tiefland* @copyright 2016*/function getVersandLaender(){// ME: Länder raus, und die bit-Schiebeoperation ungestört durchzählen lasssen// LT: für Smarty umgebaut$CI = &get_instance();$forbiddenLands = array();if (table_exists("bestelladresse", $GLOBALS["INI"]["dbConnect"]["order_db"]) &&$GLOBALS["INI"]["modules"]["adresssystem"] == "neu"){$old = false;if (table_exists("shippinggroups")){$cTable = "countries";$cField = "`name-ger";$coTable = "cotinents";$coField = "name_de";if (table_exists("countries")){$cField = "country";$cTable = $GLOBALS["INI"]["dbConnect"]["database"].".".$cTable;$coTable = "";$coField = "continent";}$sql = "SELECTc.id,c.shipping,".$coField." AS continent,c.".$cField." AS countryFROM".$cTable." cJOIN".$GLOBALS["INI"]["dbConnect"]["database"].".shippinggroups sgONsg.id = c.shipping";if ($coTable){$sql .= "JOIN".$coTable."ONco.id=c.continent";}}else{$old = true;$sql = "SELECTid,weban_lcode,`name-ger` AS countryFROMcontent_management.countriesWHEREweban_lcode!=''";}$res = $GLOBALS["db_red"]->query($sql);while ($row = $res->fetchRow()){$land_name = $row["country"];if (!in_array($land_name, $forbiddenLands)){if ($old === true){$land = $row["weban_lcode"];$gewicht = getBasketGewicht();$preis = getBasketSumme();// gibt es für dieses Land Versandoptionen?$sql = "SELECTIDFROMartikelWHERELieferstatus & ".$land." = ".$land."ANDFather=-3ANDstatus = ".$GLOBALS['INI']['shops_ID']."";if (count($_SESSION["SHOP"]["BASKET"])){$sql .= "AND((".$gewicht." between preis_neu1 and preis_neu2))AND((".$preis." BETWEEN preis_neu3 AND preis_neu4)OR(preis_neu3=preis_neu4))";}if (count($_SESSION["SHOP"]["BASKET"])){foreach ($GLOBALS["Eigenschaften"] as $nr){if (Eigenschaft($nr) == true){$sql .= " AND Eigenschaft_$nr = 1 ";}else{$sql .= "AND((Eigenschaft_$nr = 0)OR(Eigenschaft_$nr IS NULL))";}}}$q = mysql_query($sql);if ($q){$n = mysql_num_rows($q);if ($n){if ($GLOBALS["INI"]["charset"] == "utf-8" && $GLOBALS["INI"]["dbConnect"]["db_is_utf8"] !=1){$land_name = utf8_encode($land_name);}$laender[$row["id"]] = $land_name;}}}else{$continent = $row["continent"];$sql = "SELECTIDFROMartikelWHEREkennung = ".$row["shipping"]."ANDFather=-3ANDstatus = ".$GLOBALS['INI']['shops_ID']."";if (count($_SESSION["SHOP"]["BASKET"])){$sql .= "AND((".$gewicht." between preis_neu1 and preis_neu2))AND((".$preis." BETWEEN preis_neu3 AND preis_neu4)OR(preis_neu3=preis_neu4))";}if (count($_SESSION["SHOP"]["BASKET"])){foreach ($GLOBALS["Eigenschaften"] as $nr){if (Eigenschaft($nr) == true){$sql .= " AND Eigenschaft_$nr = 1 ";}else{$sql .= "AND((Eigenschaft_$nr = 0)OR(Eigenschaft_$nr IS NULL))";}}}$q = mysql_query($sql);if ($q){$n = mysql_num_rows($q);if ($n){if ($GLOBALS["INI"]["charset"] == "utf-8" && $GLOBALS["INI"]["dbConnect"]["order_db_is_utf8"] !=1){$land_name = utf8_encode($land_name);$continent = utf8_encode($continent);}$laender[$continent][$row["id"]] = $land_name;}}}}}}else{for ($i = 0; $i < 64; $i++){$land = 1 << $i;$land_name = getCountryById($land);if ($land_name){if (!in_array($land_name, $forbiddenLands)){$gewicht = getBasketGewicht();$preis = getBasketSumme();// gibt es für dieses Land Versandoptionen?$sql = "SELECTIDFROMartikelWHERELieferstatus & ".$land." = ".$land."ANDFather=-3ANDstatus = ".$GLOBALS['INI']['shops_ID']."";if (count($_SESSION["SHOP"]["BASKET"])){$sql .= "AND((".$gewicht." between preis_neu1 and preis_neu2))AND((".$preis." BETWEEN preis_neu3 AND preis_neu4)OR(preis_neu3=preis_neu4))";}if (count($_SESSION["SHOP"]["BASKET"])){foreach ($GLOBALS["Eigenschaften"] as $nr){if (Eigenschaft($nr) == true){$sql .= " AND Eigenschaft_$nr = 1 ";}else{$sql .= "AND((Eigenschaft_$nr = 0)OR(Eigenschaft_$nr IS NULL))";}}}$q = mysql_query($sql);if ($q){$n = mysql_num_rows($q);if ($n){$shopsNoEncode = array("ababum.de","etoh24.de",);if ($GLOBALS["INI"]["charset"] == "utf-8" && !in_array(__SHOP__, $shopsNoEncode)){$land_name = utf8_encode($land_name);}$laender[$land] = ($land_name);}}}}}}if (is_array($laender)){$laender = array_unique($laender);}else{$laender = array();}return $laender;}function table_exists($table, $db = null, $c = null){$ini = $GLOBALS['INI'];if ($db){$db = trim($db, '.');}if (!$c){$conn = $GLOBALS['order_db'];}else{$conn = $c;}if (!$db || $db == $ini["dbConnect"]["database"]){$db = $ini["dbConnect"]["database"];if (!$c){$CI = &get_instance();$conn = $CI->db;}else{$conn = $c;}}$sql = "SELECTengineFROMinformation_schema.TABLESWHEREtable_name='".$table."'ANDtable_schema='".$db."'";$res = $conn->query($sql);if ($res->num_rows()){return true;}return false;}function column_exists($table, $column, $db = null, $c = null){$ini = $GLOBALS['INI'];if ($db){$db = trim($db, '.');}if (!$c){$conn = $GLOBALS['order_db'];}else{$conn = $c;}if (!$db || $db == $ini["dbConnect"]["database"]){$db = $ini["dbConnect"]["database"];if (!$c){$CI = &get_instance();$conn = $CI->db;}else{$conn = $c;}}$t_exists = table_exists($table, $db, $conn);if ($t_exists){$sql = "SELECTdata_typeFROMinformation_schema.COLUMNSWHEREcolumn_name='".$column."'ANDtable_name='".$table."'ANDtable_schema='".$db."'";$res = $conn->query($sql);if ($res->num_rows()){return true;}return false;}return false;}/*** getColumnInfo()** Holt Informationen zu einer Spalte (inklusive dem f?r diese Spalte definierten Fremdschl?ssel)** @param mixed $table* @param mixed $column* @param mixed $db* @param mixed $c* @return*/function getColumnInfo($table, $column, $db = null, $c = null){global $remoteServer_dbh, $localhost_dbh;if (!is_array($_SESSION["INI"])){$ini = $GLOBALS["INI"];}else{$ini = $_SESSION["INI"];}if ($db){$db = trim($db, '.');}if (!$c){if (__USE_MDB2__ === true){$conn = $GLOBALS["order_db"];}elseif (is_resource($GLOBALS["order_dbh"])){$conn = $GLOBALS["order_dbh"];}elseif (is_resource($remoteServer_dbh)){$conn = $remoteServer_dbh;}}else{$conn = $c;}if (!$db || $db == $ini["dbConnect"]["database"]){$db = $ini["dbConnect"]["database"];if (!$c){if (__USE_MDB2__ === true){$conn = $GLOBALS["db"];}elseif (is_resource($GLOBALS["dbh"])){$conn = $GLOBALS["dbh"];}elseif (is_resource($localhost_dbh)){$conn = $localhost_dbh;}}else{$conn = $c;}}if (column_exists($table, $column, $db, $conn)){//Hole Informationen zur Spalte$sql = "SELECT*FROMinformation_schema.COLUMNSWHEREcolumn_name='".$column."'ANDtable_name='".$table."'ANDtable_schema='".$db."'";if (__USE_MDB2__ === true){$res = $conn->query($sql);if ($res->numRows()){$row = $res->fetchRow();}}else{$res = mysql_query($sql, $conn);if (mysql_num_rows($res)){$row = mysql_fetch_assoc($res);}}$t = getTableInfo($table, $db, $conn);$row["engine"] = $t["ENGINE"];if ($row["engine"] == "InnoDB"){//Hole Informationen zu einem definierten Fremdschl?ssel$sql = "SELECTREFERENCED_TABLE_SCHEMA,REFERENCED_TABLE_NAME,REFERENCED_COLUMN_NAME,CONSTRAINT_NAMEFROMinformation_schema.KEY_COLUMN_USAGEWHEREcolumn_name='".$column."'ANDtable_name='".$table."'ANDtable_schema='".$db."'";if (__USE_MDB2__ === true){$res = $conn->query($sql);if ($res->numRows()){$row_k = $res->fetchRow();}}else{$res = mysql_query($sql, $conn);if (mysql_num_rows($res)){$row_k = mysql_fetch_assoc($res);}}if (is_array($row_k)){$row = array_merge($row, $row_k);}}}return $row;}/*** getTableInfo()** Liest Informationen zu einer Tabelle** @param mixed $table* @param mixed $db* @param mixed $c* @return*/function getTableInfo($table, $db = null, $c = null){global $remoteServer_dbh, $localhost_dbh;if (!is_array($_SESSION["INI"])){$ini = $GLOBALS["INI"];}else{$ini = $_SESSION["INI"];}if ($db){$db = trim($db, '.');}if (!$c){if (__USE_MDB2__ === true){$conn = $GLOBALS["order_db"];}elseif (is_resource($GLOBALS["order_dbh"])){$conn = $GLOBALS["order_dbh"];}elseif (is_resource($remoteServer_dbh)){$conn = $remoteServer_dbh;}}else{$conn = $c;}if (!$db || $db == $ini["dbConnect"]["database"]){$db = $ini["dbConnect"]["database"];if (!$c){if (__USE_MDB2__ === true){$conn = $GLOBALS["db"];}elseif (is_resource($GLOBALS["dbh"])){$conn = $GLOBALS["dbh"];}elseif (is_resource($localhost_dbh)){$conn = $localhost_dbh;}}else{$conn = $c;}}if (table_exists($table, $db, $conn)){//Hole Informationen zur Tabelle$sql = "SELECT*FROMinformation_schema.TABLESWHEREtable_name='".$table."'ANDtable_schema='".$db."'";if (__USE_MDB2__ === true){$res = $conn->query($sql);if ($res->numRows()){$row = $res->fetchRow();}}else{$res = mysql_query($sql, $conn);if (mysql_num_rows($res)){$row = mysql_fetch_assoc($res);}}}return $row;}/*** createDBField()** legt eine neue Spalte $name in der durch $table bestimmten Tabelle an* $config ist ein Array mit folgenden Schl?sseln* type ==> Typ der Spalte (z. B. varchar)* length ==> L?nge der Spalte (z. B. 255)* extra ==> zus?tliche Optionen f?r das Feld (z. B. UNSIGNED bei Zahlen)* nullable ==> kann Feld den Wert NULL enthalten?* default ==> Wert, der in der Spalte gespeichert wird, wenn kein Wert* ?bergeben wird* index ==> Soll ein Index angelegt werden und wenn ja, welcher?* Beispiele: index, unique* after ==> Bestimmt hinter welcher Spalte die neue angelegt wird* Wenn kein Wert angegeben wird, wird die Spalte am Ende der Tabelle* angelegt** @param string $name* @param string $table* @param resource $conn* @param array $config* @return void*/function createDBField($name, $table, $conn, $config){$typ = $config["type"];if ($config["length"]){$typ .= "(".$config["length"].")";}if ($config["extra"]){$typ .= " ".$config["extra"];}if ($config["nullable"] == 1){$typ .= " NULL DEFAULT NULL";}else{$default = '';if ($config["default"]){$default = $config["default"];}$typ .= " NOT NULL DEFAULT '".$default."'";}if ($config["after"]){$typ .= " AFTER ".$config["after"];}if ($config["index"]){$typ .= ", ADD ".$config["index"]."(".$name.")";}$sql = "ALTER TABLE".$table."ADD".$name." ".$typ."";$conn->exec($sql);}?>