$data = array('name' => $name, 'author' => $author, 'genre' => $genre, 'year' => $year); $id = $db->insert('books', $data); if ($id) { echo 'Книга была добавлена'; } } //Чтение действия из ajax-запроса $action = html_entity_decode(strip_tags($_POST['action'])); //Выполнение действий if ($action == 'show') { displayAll(); } if ($action == 'delete') { $id = html_entity_decode(strip_tags($_POST['id'])); deleteBook($id); } if ($action == 'edit') { $id = html_entity_decode(strip_tags($_POST['id'])); $name = html_entity_decode(strip_tags($_POST['name'])); $author = html_entity_decode(strip_tags($_POST['author'])); $genre = html_entity_decode(strip_tags($_POST['genre'])); $year = html_entity_decode(strip_tags($_POST['year'])); editBook($id, $name, $author, $genre, $year); } if ($action == 'add') { $name = html_entity_decode(strip_tags($_POST['name'])); $author = html_entity_decode(strip_tags($_POST['author'])); $genre = html_entity_decode(strip_tags($_POST['genre'])); $year = html_entity_decode(strip_tags($_POST['year'])); addBook($name, $author, $genre, $year); }
case "edit_review": $ids = explode(',', $bid[0]); edit_review($option, $ids[1], $ids[0]); break; case "update_review": $title = mosGetParam($_POST, 'title'); $comment = mosGetParam($_POST, 'comment'); $rating = mosGetParam($_POST, 'rating'); $book_id = mosGetParam($_POST, 'book_id'); $review_id = mosGetParam($_POST, 'review_id'); update_review($title, $comment, $rating, $review_id); editBook($option, $book_id); break; case "cancel_review_edit": $book_id = mosGetParam($_POST, 'book_id'); editBook($option, $book_id); break; default: showBooks($option); break; } } /* * CAT_Utils Class */ class CAT_Utils { static function categoryArray() { global $database; // get a list of the menu items
} // login asked if (isset($_GET['signin'])) { signin(); } // logout asked if (isset($_GET['signout'])) { signout(); } // new book asked if (isset($_GET['add'])) { addBook(); } // edit book asked if (isset($_GET['edit']) && !empty($_GET['edit'])) { editBook(); } // delete book asked if (isset($_GET['delete']) && !empty($_GET['delete'])) { deleteBook(); } // display writted log asked if (isset($_GET['logs'])) { logsPage(); } // display settings log asked if (isset($_GET['settings'])) { settingsPage(); } // display export page asked if (isset($_GET['export'])) {
$errors[] = "Autore non valido."; } if (filter_var($pages, FILTER_VALIDATE_INT) === false || $pages < 1) { $errors[] = "Campo pagine non valido."; } if (filter_var($price, FILTER_VALIDATE_FLOAT) === false || $price < 0.01) { $errors[] = "Prezzo non valido"; } if (count($errors) > 0) { $book = getBookFromId($id_book); //$errors[] = "Errore aggiornamento libro."; } else { //var_dump($availability); $price = number_format($price, 2); //Funzione che tronca a 2 cifre decimali... $res = editBook($id_book, $title, $isbn, $id_author, $pages, $availability, $price); if ($res == true) { $book = getBookFromId($id_book); //ricarica contenuto (?) $success_message = "Libro aggiornato con successo."; } else { $errors[] = "Errore aggiornamento libro."; //$book = getBookFromId($id_book); } } break; default: break; } } else { $book = getBookFromId($id_book);