Esempio n. 1
0
<?php

if (isset($_SESSION['user_id'])) {
    $user = getUserById($_SESSION['user_id']);
} else {
    redirect("index.php?controller=user&action=login");
}
if (isset($_GET['action'])) {
    $action = $_GET['action'];
    switch ($action) {
        case "new":
            newProduct();
            break;
        case "edit":
            editProduct($_GET['id']);
            break;
        case "view":
            viewProduct($_GET['id']);
            break;
        case "delete":
            deleteProduct($_GET['id']);
            break;
        default:
            echo "URL not found";
    }
} else {
    include "view/product/index.php";
}
function viewProduct($id)
{
    $product = getProductById($id);
Esempio n. 2
0
function newProductViaJS($exchange, $product)
{
    if ($_SESSION["instabid_userId"] == NULL) {
        return '{"result":"FAIL","msg":"Sorry but this user is unidentified creating a risk of outside fraudulent access. You have to call the function authorize_user_to_bid(userId) in instabid.php first"}';
    } else {
        //return $_SESSION["instabid_userId"];
        return newProduct($exchange, $product);
    }
}
Esempio n. 3
0
    } elseif (!is_numeric($_POST['price'])) {
        $erro = "Preço inválido.";
    } elseif ($_POST['expiration'] < 1 || !is_numeric($_POST['expiration'])) {
        $erro = "Dias de validade inválidos.";
    } elseif (strlen($_POST['description']) < 3) {
        $erro = "Descrição precisa ter pelo menos três caracteres.";
    }
    if (isset($erro)) {
        echo '
        <div class="alert alert-danger" role="alert">
            <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
            ' . $erro . '
        </div>';
        exit;
    } else {
        newProduct($_POST['comp_id'], $_POST['description'], $_POST['production'], $_POST['expiration'], $_POST['price'], $_POST['amount']);
    }
}
function newProduct($comp_id, $description, $production, $expiration, $price, $amount)
{
    global $conn;
    if ($stmt = $conn->prepare("INSERT INTO products (Companies_comp_id, prod_description, prod_production, prod_expiration, prod_price, prod_amount) VALUES (?, ?, ?, ?, ?, ?)")) {
        $stmt->bind_param("issssi", $comp_id, $description, $production, $expiration, $price, $amount);
        $stmt->execute();
        if ($stmt->affected_rows != 1) {
            if ($stmt->sqlstate == 23000) {
                $errorSTMT = "Violação de integridade identificada";
            }
            if ($stmt->errno == 1062) {
                $errorSTMT .= "<br>Talvez sua empresa já tenha cadastro.";
            }