function add_book($isbn, $quantity) { global $book; if ($quantity < 1) { return; } //if books already in cart update quantity if (isset($_SESSION['shop_cart'][$isbn])) { $quantity += $_SESSION['shop_cart'][$isbn]['qty']; update_book($isbn, $quantity); return; } //add book $price = $book[$isbn]['price']; $total = $price * $quantity; $book = array('title' => $book[$isbn]['title'], 'price' => $price, 'qty' => $quantity, 'total' => $total); $_SESSION['shop_cart'][$isbn] = $book; }
<?php // include function files for this application require_once 'book_sc_fns.php'; session_start(); do_html_header('Updating book'); if (check_admin_user()) { if (filled_out($HTTP_POST_VARS)) { $oldisbn = $HTTP_POST_VARS['oldisbn']; $isbn = $HTTP_POST_VARS['isbn']; $title = $HTTP_POST_VARS['title']; $author = $HTTP_POST_VARS['author']; $catid = $HTTP_POST_VARS['catid']; $price = $HTTP_POST_VARS['price']; $description = $HTTP_POST_VARS['description']; if (update_book($oldisbn, $isbn, $title, $author, $catid, $price, $description)) { echo 'Book was updated.<br />'; } else { echo 'Book could not be updated.<br />'; } } else { echo 'You have not filled out the form. Please try again.'; } do_html_url('admin.php', 'Back to administration menu'); } else { echo 'You are not authorised to view this page.'; } do_html_footer();
<?php require_once 'libcollection.php'; startSession(); $storyEdit = FALSE; if (isset($_POST['title']) && isset($_POST['hero']) && isset($_POST['villain']) && isset($_POST['story']) && isset($_POST['id'])) { $title = strip_tags($_POST['title']); if ($title != '') { $storyEdit = TRUE; $hero = $_POST['hero']; $villain = $_POST['villain']; $story = $_POST['story']; $id = $_POST['id']; $lair_list = array('Wolf' => 'Den', 'Witch' => 'Gingerbread-house', 'Giant' => 'Castle'); $lair = $lair_list[$villain]; //select appropriate lair with respect to villain update_book($id, $title, $story, $hero, $villain, $lair); $location = 'storygen.php?title=' . urlencode($title) . '&story=' . urlencode($story) . "&hero=" . urlencode($hero) . '&villain=' . urlencode($villain) . '&lair=' . urlencode($lair) . '&page=0'; header('location: ' . $location); } } if ($storyEdit == FALSE) { header('location: selection.php'); }
check_authorization(); $body = new Template("templates/items/items.book.tmpl.php"); $body->set('id', $_GET['id']); $body->set('name', $_GET['name']); $vars = book_info(); if ($vars) { foreach ($vars as $key => $value) { $body->set($key, $value); } } break; case 4: //Update Book Text check_authorization(); $id = $_POST['id']; update_book(); header("Location: index.php?editor=items&id={$id}&action=2"); exit; case 5: // Delete Item check_authorization(); delete_item(); header("Location: index.php?editor=items"); exit; case 6: // Update Item check_authorization(); $id = $_GET['id']; update_item(); header("Location: index.php?editor=items&id={$id}&action=2"); exit;
/** * Adds a book to the database. * @param string $query Query string containing the fields to add. * @return boolean True on success, false on failure. */ function add_book( $query ) { return update_book($query); }
if ($action === NULL) { $action = 'show_add_book'; } } //add and update cart if ($action == 'add') { $isbn = filter_input(INPUT_POST, 'isbn'); $bookqantity = filter_input(INPUT_POST, 'bookquantity'); add_book($isbn, $bookqantity); include 'cart_view.php'; } else { if ($action == 'update') { $new_qty_list = filter_input(INPUT_POST, 'newqty', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY); foreach ($new_qty_list as $isbn => $qty) { if ($_SESSION['shop_cart']['qty'] != $qty) { update_book($isbn, $qty); } } include 'cart_view.php'; } else { if ($action == 'show_cart') { include 'cart_view.php'; } else { if ($action == 'show_add_book') { include 'add_book_view.php'; } else { if ($action == 'empty_cart') { include 'cart_view.php'; } } }