public function saveBook($val, $t = 'new', $admin = false)
{
$db = db();
$title = sanitizeText($val['title'] ?? '');
$description = sanitizeText($val['description'] ?? '');
$category = sanitizeText($val['category'] ?? '');
$privacy = (int)($val['privacy'] ?? 1);
$comment = (int)($val['comment'] ?? 1);
$genre = sanitizeText($val['genre'] ?? '');
$price = sanitizeText($val['price'] ?? '');
$author = sanitizeText($val['author'] ?? '');
$book = sanitizeText($val['book'] ?? '');
$slug = sanitizeText($val['slug'] ?? '');
$photo = sanitizeText($val['photo'] ?? '');
// GARANTIA: se não vier foto, não grava string inválida
if ($photo === null) {
$photo = '';
}
if ($t === 'new') {
$time = time();
$userId = get_userid();
$sql = "
INSERT INTO {$this->table_name}
(title, description, category, image, user_id, comment, privacy, price, author, genre, time, book, slug)
VALUES (
'{$title}',
'{$description}',
'{$category}',
'{$photo}',
'{$userId}',
'{$comment}',
'{$privacy}',
'{$price}',
'{$author}',
'{$genre}',
'{$time}',
'{$book}',
'{$slug}'
)
";
$db->query($sql);
if ($db->error) {
echo $db->error;
die();
}
$id = $db->insert_id;
if ($admin && isset($val['featured'])) {
$featured = (int)$val['featured'];
$db->query("UPDATE {$this->table_name} SET featured='{$featured}' WHERE id='{$id}'");
}
fire_hook("added.new.book", null, [$val, $id]);
return $id;
}
// UPDATE
$id = (int)$t;
$sql = "
UPDATE {$this->table_name}
SET
title='{$title}',
description='{$description}',
category='{$category}',
book='{$book}',
slug='{$slug}',
image='{$photo}',
comment='{$comment}',
privacy='{$privacy}',
price='{$price}',
author='{$author}',
genre='{$genre}'
WHERE id='{$id}'
";
$db->query($sql);
if ($db->error) {
echo $db->error;
die();
}
return $id;
}
Safenation - Paulo Loyola
link whatsapp
Novos feeds
Treinamento completo e pronto para a ação, desenvolvido por renomados especialistas da área. Este material é a chave para a maestria na NR 38.
Tem certeza de que deseja realizar esta ação?