function getLanguages($conn) { $selQ = new selectSQL($conn); $selQ->select = array("abreviation"); $selQ->tableNames = array("languages"); if (!$selQ->executeQuery() || $selQ->getNumberOfResults() == 0) { $GLOBALS['statusMessage'] = makeStatusMessage(2, "error"); mysqli_close($conn); return null; } else { $lang = array(); while ($r = $selQ->result->fetch_assoc()) { $lang[] = $r['abreviation']; } return $lang; } }
function checkLoginAttempts($conn, $seconds, $user = null) { $timeout = time() - $seconds; $ip = ip2long($_SERVER['REMOTE_ADDR']); $selQ = new selectSQL($conn); $selQ->select = array("date"); $selQ->tableNames = array("login_logs"); if (isset($user)) { $selQ->where = "(user = '******' OR ip = '" . $ip . "')"; } else { $selQ->where = "ip = '" . $ip . "'"; } $selQ->where .= " AND date > '" . $timeout . "' AND result = '0'"; if (!$selQ->executeQuery()) { return -1; } else { return $selQ->getNumberOfResults(); } }
function getCat($where, $conn, $lang, $langArr) { $selQ = new selectSQL($conn); if (!empty($lang)) { $selQ->select = array("id", "parentid", "name" . $lang . " as nameEN", "desc" . $lang . " as descEN", "imgurl"); } else { $selQ->select = array("id", "parentid"); foreach ($langArr as $l) { $selQ->select[] = "name" . $l; $selQ->select[] = "desc" . $l; } $selQ->select[] = "imgurl"; } $selQ->tableNames = array("categories"); $selQ->where = $where; if (isset($_POST['deleted'])) { $selQ->where .= " AND visible = 0"; } else { $selQ->where .= " AND visible = 1"; } if (!$selQ->executeQuery()) { return; } if ($selQ->getNumberOfResults() > 0) { while ($row = $selQ->result->fetch_assoc()) { $subCats = getCat("parentid = '" . $row['id'] . "'", $conn, $lang, $langArr); if ($subCats) { $data[] = array_merge($row, array("subCategories" => $subCats)); } else { $data[] = $row; } } return $data; } else { return; } }
mysqli_close($coon); return; } $propNames = array(); $propLangName = array(); while ($row = $selQ->result->fetch_assoc()) { if ($row['ld']) { $propNames[] = $row['n'] . $language; } else { $propNames[] = $row['n']; } $propLangName[] = $row['lang']; } include_once 'variables/productVariables.php'; unset($selQ); $selQ = new selectSQL($conn); $selQ->select = array("imgurl as " . $propNamesLang["imgurl"][$language]); foreach ($propNamesLang as $key => $p) { if ($key != "imgurl" and !empty($p)) { $selQ->select = array_merge($selQ->select, array($key . " as " . $p[$language])); } } $selQ->where = "p.promo != '0'"; $cleanProps = array(); for ($i = 0; $i < count($propNames); $i++) { $selQ->select = array_merge($selQ->select, array($propNames[$i] . " as `" . $propLangName[$i] . "`")); } $selQ->tableNames = array("products as p"); $selQ->joins = array(); $selQ->joinTypes = array(); if (checkTable($conn, "products_" . $catid)) {
function getLogVisits($conn, $dateStart = null, $dateEnd = null, $unique = null, $item = null) { $selQ = new selectSQL($conn); $selQ->tableNames = array("visit_logs"); switch ($item) { case "category": $selQ->select = array("visit_logs.catid as Category ID", "nameEN as Name"); $selQ->tableNames[] = "categories"; $selQ->joins = array("visit_logs.catid = categories.id"); $selQ->joinTypes = array("RIGHT JOIN"); $selQ->groupby = "visit_logs.catid"; break; case "product": $selQ->select = array("visit_logs.prodid as Product ID", "namesEN as Name"); $selQ->tableNames[] = "products"; $selQ->joins = array("visit_logs.prodid = products.id"); $selQ->joinTypes = array("RIGHT JOIN"); $selQ->groupby = "visit_logs.prodid"; break; case "page": $selQ->select = array("visit_logs.url as Page"); $selQ->groupby = "visit_logs.page"; break; default: $selQ->select = array(); } if ($unique) { $selQ->select[] = "count(DISTINCT visit_logs.ip) as Visits"; } else { $selQ->select[] = "count(visit_logs.id) as Visits"; } if (isset($dateStart)) { $selQ->where .= "date > '" . $conn->real_escape_string($dateStart) . "' AND "; } if (isset($dateEnd)) { $selQ->where .= "date < '" . $conn->real_escape_string($dateEnd) . "' AND "; } $selQ->where = rtrim($selQ->where, " AND "); if (!$selQ->executeQuery()) { return null; } else { $data = array(); while ($r = $selQ->result->fetch_assoc()) { $data[] = $r; } return $data; } }
$deliveryPayment = $r['type']; $address = $conn->real_escape_string($_POST['address']); $totalPrice = 0; foreach ($productInfo as $pi) { $totalPrice += $pi[$priceLang[$language]]; } $insQ = new insertSQL($conn); $insQ->cols = array("userid", "payment", "delivery", "deliverypayment", "date", "ip", "address", "totalprice"); $insQ->insertData = array($userid, $payment, $delivery, $deliveryPayment, time(), ip2long($_SERVER['REMOTE_ADDR']), $address, $totalPrice); $insQ->tableName = "orders"; if (!$insQ->executeQuery()) { $statusMessage = $insQ->status; mysqli_close($conn); return; } $selQlast = new selectSQL($conn); $selQlast->select = array("id as lastid"); $selQlast->where = "id = LAST_INSERT_ID()"; $selQlast->tableNames = array("orders"); if (!$selQlast->executeQuery()) { $statusMessage = $selQlast->status; mysqli_close($conn); return; } $row = $selQlast->result->fetch_assoc(); $lastID = $row['lastid']; foreach ($prodids as $prod) { unset($insQ); $insQ = new insertSQL($conn); $insQ->cols = array("orderid", "productid", "productcount"); $insQ->insertData = array($lastID, $prod, $prodQuantity[$prod]);
function insCat($conn) { require_once 'languageConfig.php'; $insQ = new insertSQL($conn); $insQ->insertData = array(); $insQ->cols = array(); foreach ($langArr as $l) { if (isset($_POST['names'][$l])) { $insQ->insertData[] = $conn->real_escape_string($_POST['names'][$l]); $insQ->cols[] = "name" . $l; } if (isset($_POST['desc'][$l])) { $insQ->insertData[] = $conn->real_escape_string($_POST['desc'][$l]); $insQ->cols[] = "desc" . $l; } } if (isset($_POST['imgUrl'])) { $insQ->insertData[] = $conn->real_escape_string($_POST['imgUrl']); $insQ->cols[] = "imgurl"; } if (isset($_POST['parentid'])) { $insQ->insertData[] = $conn->real_escape_string($_POST['parentid']); $insQ->cols[] = "parentid"; } $insQ->tableName = "categories"; if (!$insQ->executeQuery()) { $statusMessage = $insQ->status; } else { $selQid = new selectSQL($conn); $selQid->where = ""; foreach ($langArr as $l) { if (isset($_POST['names'][$l])) { $selQid->where = "name" . $l . " = '" . $conn->real_escape_string($_POST['names'][$l]) . "' OR "; } } $selQid->where = substr($selQid->where, 0, -4); $selQid->order = "id DESC"; $selQid->tableNames = array("categories"); $selQid->select = array("id"); if (!$selQid->executeQuery()) { $statusMessage = $selQid->status; } else { $row = $selQid->result->fetch_assoc(); $catid = $row['id']; $selQ = new selectSQL($conn); $selQ->select = array("name", "langDependant"); $selQ->tableNames = array("properties"); $tmp = array(); foreach ($_POST['fid'] as $f) { $tmp[] = $conn->real_escape_string($f); } $selQ->where = "id IN (" . arrToQueryString($tmp, null) . ")"; if (!$selQ->executeQuery() or $selQ->getNumberOfResults() == 0) { $statusMessage = makeStatusMessage(53, "error"); } else { $propsDef = array(); $propsLang = array(); while ($row = $selQ->result->fetch_assoc()) { if ($row['langDependant']) { $propsLang[] = $row['name']; } else { $propsDef[] = $row['name']; } } $ctQ = new createTableSQL($conn); $ctQ->cols = array(); $ctQ->cols[] = "infoid"; $ctQ->colTypes = array(); $ctQ->colTypes[] = "int(11) NOT NULL"; $ctQ->name = "products_" . $catid; if (count($propsDef)) { foreach ($propsDef as $pr) { $ctQ->cols[] = $pr; $ctQ->colTypes[] = "varchar(40) COLLATE utf8_unicode_ci DEFAULT NULL"; } if (!$ctQ->executeQuery()) { $statusMessage = $ctQ->status; mysqli_close($conn); return; } } if (count($propsLang)) { foreach ($langArr as $l) { unset($ctQ->cols); $ctQ->cols[] = "infoid"; unset($ctQ->colTypes); $ctQ->colTypes[] = "int(11) NOT NULL"; $ctQ->name = "products_" . $catid . "_" . $l; foreach ($propsLang as $pr) { $ctQ->cols[] = $pr . $l; $ctQ->colTypes[] = "varchar(40) COLLATE utf8_unicode_ci DEFAULT NULL"; } if (!$ctQ->executeQuery()) { $GLOBALS['statusMessage'] = $ctQ->status; mysqli_close($conn); return; } } } $insQ = new insertSQL($conn); $insQ->cols = array("catid", "propid"); $insQ->tableName = "props_to_prods"; foreach ($_POST['fid'] as $f) { $insQ->insertData = array($catid, $conn->real_escape_string($f)); if (!$insQ->executeQuery()) { $resultAddProps = true; } } if (isset($resultAddProps)) { $statusMessage = makeStatusMessage(103, "error"); } else { $statusMessage = makeStatusMessage(11, "success"); } } } } $GLOBALS['statusMessage'] = $statusMessage; }
function getPropsForCat($conn, $catid, $langArr = null, $insertQueryLangArr = null) { $language = $GLOBALS['language']; include_once 'variables/productVariables.php'; if (isset($langArr)) { $propNamesDefld = array(); foreach ($propNamesDefldtemp as $tmp) { foreach ($langArr as $lan) { $propNamesDefld[] = $tmp . $lan; } } } else { $propNamesDefld = $propNamesDefldtemp; } $propNames = array(); $propNamesld = array(); if (isset($insertQueryLangArr)) { $langArr = $insertQueryLangArr; } $conn = sqlConnectDefault(); if (is_null($conn)) { $statusMessage = makeStatusMessage(1, "error"); return; } $selQ = new selectSQL($conn); $selQ->tableNames = array("props_to_prods as ptp", "properties as p"); $selQ->joins = array("p.id = ptp.propid"); $selQ->joinTypes = array("INNER JOIN"); $selQ->select = array("p.name as propName", "p.langDependant as ld", "p.name" . $language . " as `langName`"); $selQ->where = "ptp.catid = '" . $catid . "'"; if (!$selQ->executeQuery()) { $GLOBALS['statusMessage'] = $selQ->status; return null; } elseif ($selQ->getNumberOfResults() == 0) { $GLOBALS['statusMessage'] = makeStatusMessage(53, "error"); return null; } elseif (isset($langArr)) { while ($r = $selQ->result->fetch_assoc()) { if ($r['ld']) { if (isset($insertQueryLangArr)) { $propNamesld[] = $r['propName'] . " as `" . $r['langName'] . "`"; } else { foreach ($langArr as $lan) { $propNamesld[] = $r['propName'] . $lan . " as `" . $r['langName'] . "`"; } } } else { $propNames[] = $r['propName'] . " as `" . $r['langName'] . "`"; } } } else { while ($r = $selQ->result->fetch_assoc()) { if ($r['ld']) { $propNamesld[] = $r['propName']; } else { $propNames[] = $r['propName']; } } } return array("propNamesDefld" => $propNamesDefld, "propNamesDef" => $propNamesDef, "propNamesld" => $propNamesld, "propNames" => $propNames); }