if (!empty($_POST) && strpos($_SERVER['HTTP_REFERER'], $_SERVER['SERVER_NAME'] . "/account/registration") !== false) { $user_name = strlen($_POST["name"]) < 1 ? "Пользователь" : $_POST["name"]; $user_soname = $_POST["surname"]; $mail = $_POST["mail"]; $pass = $_POST["pass"]; if (User::getInst()->registration([$mail, $pass, $user_name, $user_soname])) { header("Location: http://" . $_SERVER["SERVER_NAME"] . "/account/settings.php"); exit; } $error = true; } $fb_url = Config::getFbUrl(); $vk_url = Config::getVkUrl(); $app = array_key_exists("app", $_GET); $header = $app ? "" : render(__DIR__ . "/../views/header.php", ["fb_url" => $fb_url, "vk_url" => $vk_url, "user" => User::getInst()->isAuthorized() ? User::getInst()->getUserInfo()["name"] : false]); $sidebar = $app ? "" : render(__DIR__ . "/../views/sidebar.php", ["fb_url" => $fb_url, "vk_url" => $vk_url, "user" => User::getInst()->isAuthorized() ? User::getInst()->getUserInfo()["name"] : false]); $footer = $app ? "" : render(__DIR__ . "/../views/footer.php", []); ?> <!DOCTYPE html> <html lang="ru"> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"> <head> <title>FitEat Registration</title> <link rel="StyleSheet" type="text/css" href="../stylesheets/main.css"/> <link rel="StyleSheet" type="text/css" href="../stylesheets/datepicker.css"/> <script type="text/JavaScript" src="../javascript/jquery-2.1.0.js"></script> <script type="text/JavaScript" src="../javascript/jquery-ui.min.js"></script> <script type="text/javascript" src="../javascript/datepicker.js"></script> <script type="text/javascript" src="../javascript/jquery.mask.js"></script>
include_once "../php/basic.php"; include_once "../php/config.php"; include_once "../php/sql.php"; include_once "../php/user.php"; if (!User::getInst()->isAuthorized()) { header("Location: http://" . $_SERVER['SERVER_NAME'] . "/account/login.php"); exit; } $fb_url = Config::getFbUrl(); $vk_url = Config::getVkUrl(); $app = array_key_exists("app", $_GET); $header = $app ? "" : render(__DIR__ . "/../views/header.php", ["fb_url" => $fb_url, "vk_url" => $vk_url, "user" => User::getInst()->isAuthorized() ? User::getInst()->getUserInfo()["name"] : false]); $sidebar = $app ? "" : render(__DIR__ . "/../views/sidebar.php", ["fb_url" => $fb_url, "vk_url" => $vk_url, "user" => User::getInst()->isAuthorized() ? User::getInst()->getUserInfo()["name"] : false]); $footer = $app ? "<p> </p>" : render(__DIR__ . "/../views/footer.php", []); $user_info = User::getInst()->getUserInfo(); list($year, $month, $day) = explode("-", $user_info["birthday"]); list($year_t, $month_t, $day_t) = explode("-", date('Y-m-d')); $old = $year_t - $year - 1; if (mktime(0, 0, 0, $month_t, $day_t, $year_t) >= mktime(0, 0, 0, $month, $day, $year_t)) { $old++; } $old_str = "лет"; if (floor($old / 10) % 10 != 1) { switch ($old % 10) { case 1: $old_str = "год"; break; case 2: case 3: case 4:
$product["productID"] = $result[0]['id']; } } $sql->execute("INSERT INTO composition VALUE (:id_r, :id_p, :weight)", [["name" => ":id_r", "val" => $new_ids[$recipe["recipeID"]], "type" => SQL::PARAM_INT], ["name" => ":id_p", "val" => $product["productID"], "type" => SQL::PARAM_INT], ["name" => ":weight", "val" => $product["weight"], "type" => SQL::PARAM_INT]]); } } } else { if ($recipe["recipeName"] != $user_rescipes[$recipe["recipeID"]]) { $sql->execute("UPDATE recipes SET name = ':name' WHERE id = :id", [["name" => ":name", "val" => $recipe["recipeName"], "type" => SQL::PARAM_STR], ["name" => ":id", "val" => $recipe["recipeID"], "type" => SQL::PARAM_INT]]); } $user_rescipes[$recipe["recipeID"]] = false; foreach ($recipe["products"] as $product) { if ($product["productID"] < 0) { $result = $sql->query("SELECT id FROM products WHERE name = ':name'", [["name" => ":name", "val" => $product["productName"], "type" => SQL::PARAM_STR]]); if (empty($result)) { $sql->execute("INSERT INTO products (name, uid) VALUE (':name', :uid)", [["name" => ":name", "val" => $product["productName"], "type" => SQL::PARAM_STR], ["name" => ":uid", "val" => User::getInst()->getUserInfo()['id'], "type" => SQL::PARAM_INT]]); $new_ids[$product["productID"]] = $sql->getInsertID(); $product["productID"] = $sql->getInsertID(); } else { $new_ids[$product["productID"]] = $result[0]['id']; $product["productID"] = $result[0]['id']; } } if (!array_key_exists($recipe["recipeID"] . '-' . $product["productID"], $compositions)) { $sql->execute("INSERT INTO composition VALUE (:id_r, :id_p, :weight)", [["name" => ":weight", "val" => $product["weight"], "type" => SQL::PARAM_INT], ["name" => "id_r", "val" => $recipe["recipeID"], "type" => SQL::PARAM_INT], ["name" => ":id_p", "val" => $product["productID"], "type" => SQL::PARAM_INT]]); } elseif ($compositions[$recipe["recipeID"] . '-' . $product["productID"]] != $product["weight"]) { $sql->execute("UPDATE composition SET weight = :weight WHERE id_r = :id_r AND id_p = :id_p", [["name" => ":weight", "val" => $product["weight"], "type" => SQL::PARAM_INT], ["name" => ":id_r", "val" => $recipe["recipeID"], "type" => SQL::PARAM_INT], ["name" => ":id_p", "val" => $product["productID"], "type" => SQL::PARAM_INT]]); $recalc_ids[$recipe["recipeID"]] = true; } $compositions[$recipe["recipeID"] . '-' . $product["productID"]] = false; }
ini_set("display_errors", "Off"); include_once "../php/basic.php"; include_once "../php/config.php"; include_once "../php/sql.php"; include_once "../php/user.php"; header("Content-Type: application/json"); if (!User::getInst()->isAuthorized()) { exit; } $sql = SQL::getInst(); $recipes = []; $products = []; $p_ids = []; $composition = []; $result = $sql->query("SELECT id, name FROM recipes WHERE uid = " . User::getInst()->getUserInfo()['id']); foreach ($result as $row) { $recipes[$row['id']] = $row['name']; } $r_ids = substr(json_encode(array_keys($recipes)), 1, -1); $result = $sql->query("SELECT * FROM composition WHERE id_r IN ({$r_ids})"); foreach ($result as $row) { $composition[$row['id_r']][$row['id_p']] = $row['weight']; $p_ids[$row['id_p']] = true; } $p_ids_str = substr(json_encode(array_keys($p_ids)), 1, -1); $result = $sql->query("SELECT id, name FROM products WHERE id IN ({$p_ids_str})"); foreach ($result as $row) { $products[$row['id']] = $row['name']; } $data = [];
<?php include_once "../php/basic.php"; include_once "../php/config.php"; include_once "../php/sql.php"; include_once "../php/user.php"; $user = User::getInst(); if (!$user->isAuthorized()) { echo json_encode(["state" => false]); exit; } $new_user_data = []; $birthday = []; $json = array_key_exists("json", $_POST) ? json_decode($_POST["json"], true) : exit; foreach ($json as $row) { $new_user_data[$row["name"]] = $row["value"]; } if (array_key_exists("calculate_calories", $new_user_data)) { $norm = ceil(getNormHB($new_user_data["height"], $new_user_data["weight"], (int) date('Y') - $new_user_data["year"], $new_user_data["gender"]) * User::getNormCoefficient($new_user_data["lifestyle"])); $new_user_data["calories"] = $norm - $norm % 10; } if (array_key_exists("calculate_balance", $new_user_data)) { $new_user_data["proteins"] = 30; $new_user_data["fats"] = 20; $new_user_data["carbohydrates"] = 50; } if (!$user->updateUserSettings($new_user_data)) { echo json_encode(["state" => false]); //write LOG exit; }
include_once $_SERVER['DOCUMENT_ROOT'] . '/php/user.php'; header("Content-Type: application/json"); $key = array_key_exists('word', $_GET) ? $_GET['word'] : printDefAndExit(); $words = explode(" ", $key); $keys = ""; if (count($words) < 4) { foreach ($words as $word) { if (strlen($word) > 1) { $keys .= $word . '%'; } } } if (strlen($keys) == 0) { $keys = '%' . $key . '%'; } if (!User::getInst()->isAuthorized()) { printDefAndExit(); } $sql = SQL::getInst(); $result = $sql->query("SELECT id, name FROM products WHERE name LIKE ':word' LIMIT 10", [["name" => ":word", "val" => $keys, "type" => SQL::PARAM_STR]]); $list = []; if (!empty($result)) { foreach ($result as $row) { $list[] = ["id" => $row['id'], "value" => $row['name']]; } } echo json_encode(["answers" => $list]); //$data = file_get_contents(__DIR__ . "/answerList.json"); //echo $data; function printDefAndExit() {
include_once "../php/config.php"; include_once "../php/sql.php"; include_once "../php/user.php"; if (array_key_exists("exit", $_GET)) { setcookie("uk", "", time() - 24 * 3600, "/"); } elseif (User::getInst()->isAuthorized()) { $h_add = array_key_exists("app", $_GET) ? "?app=on" : ""; header("Location: http://" . $_SERVER['SERVER_NAME'] . "/account/" . $h_add); exit; } $error = false; $mail = ""; if (!empty($_POST)) { $mail = array_key_exists("mail", $_POST) ? $_POST["mail"] : exit; $pass = array_key_exists("pass", $_POST) ? $_POST["pass"] : exit; $result = User::getInst()->requestAuth($mail, $pass); if ($result["state"]) { header("Location: " . $_SERVER['HTTP_REFERER']); exit; } $error = $result["error"]; } ?> <!DOCTYPE html> <html lang="ru"> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"> <head> <title>FitEat Login</title> </head>