Example #1
0
 private function __construct()
 {
     $this->auth = false;
     $this->user_info = false;
     if (array_key_exists('uk', $_COOKIE)) {
         $uk = $this->decodeString($_COOKIE['uk']);
         $uk_arr = explode("_", $uk);
         $sql = SQL::getInst();
         $data = $sql->query("SELECT * FROM users WHERE id = :id", [["name" => ":id", "val" => $uk_arr[0], "type" => SQL::PARAM_INT]]);
         if ($data !== false && !empty($data)) {
             if ($data[0]["ukey"] == $uk_arr[1]) {
                 $this->auth = true;
                 $this->user_info = ["id" => $data[0]["id"], "name" => $data[0]["name"], "soname" => $data[0]["soname"], "mail" => $data[0]["c_mail"] ? $data[0]["mail"] : false, "sex" => $data[0]["sex"], "birthday" => $data[0]["birthday"], "growth" => $data[0]["growth"], "weight" => $data[0]["weight"], "lifestyle" => $data[0]["lifestyle"], "norm_k" => $data[0]["norm_k"], "norm_b" => $data[0]["norm_b"], "norm_z" => $data[0]["norm_z"], "norm_u" => $data[0]["norm_u"], "norm_auto" => $data[0]["norm_auto"], "favorite_list" => $data[0]["favorite_list"], "black_list" => $data[0]["black_list"]];
             }
         }
     }
 }
Example #2
0
<?php

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'];
}
Example #3
0
function calcRecipesEnergy($recipe_ids)
{
    $sql = SQL::getInst();
    $comp = [];
    $products = [];
    $product_ids = [];
    $recipes = [];
    $result = $sql->query("SELECT * FROM composition WHERE id_r IN (:ids)", [["name" => ":ids", "val" => substr(json_encode(array_keys($recipe_ids)), 1, -1), "type" => SQL::PARAM_STR]]);
    foreach ($result as $row) {
        $comp[$row['id_r']][$row['id_p']] = $row['weight'];
        $product_ids[$row['id_p']] = true;
    }
    $result = $sql->query("SELECT * FROM products WHERE id IN (:ids)", [["name" => ":ids", "val" => substr(json_encode(array_keys($product_ids)), 1, -1), "type" => SQL::PARAM_STR]]);
    foreach ($result as $row) {
        $products[$row['id']] = $row;
    }
    foreach ($recipe_ids as $key => $t_) {
        $r_en = ['protein' => 0, 'fat' => 0, 'nzk' => 0, 'chol' => 0, 'carb' => 0, 'pv' => 0, 'na' => 0, 'k' => 0, 'ca' => 0, 'mg' => 0, 'p' => 0, 'fe' => 0, 'a' => 0, 'car' => 0, 're' => 0, 'te' => 0, 'b1' => 0, 'b2' => 0, 'ne' => 0, 'c' => 0, 'cal' => 0];
        foreach ($comp[$key] as $id_p => $weight) {
            foreach ($r_en as $name_cell => $num) {
                $num += $products[$id_p][$name_cell] * $weight / 100;
                $r_en[$name_cell] = $num;
            }
        }
        $params = [];
        $query = "UPDATE recipes SET ";
        $val_id = 0;
        foreach ($r_en as $name_cell => $val) {
            $val_id++;
            $params[] = ["name" => ":val" . $val_id, "val" => $val, "type" => SQL::PARAM_FLOAT];
            $query .= $name_cell . "=:val" . $val_id . ", ";
        }
        $query = substr($query, 0, -2) . " WHERE id = :id";
        $params[] = ["name" => ":id", "val" => $key, "type" => SQL::PARAM_INT];
        $sql->execute($query, $params);
    }
}
<?php

include "../php/config.php";
include "../php/sql.php";
$word = array_key_exists("word", $_GET) ? $_GET['word'] : "";
$results = [];
if ($word) {
    $results = SQL::getInst()->query("SELECT * FROM products WHERE name LIKE '%{$word}%'");
}
?>

<?php 
if (!empty($results)) {
    ?>
    <tbody>
  	<?php 
    foreach ($results as $row) {
        ?>
  	<tr>
  		<td><?php 
        echo $row['id'];
        ?>
</td>
  		<td><?php 
        echo $row['name'];
        ?>
</td>
  	</tr>
  	<?php 
    }
    ?>