示例#1
0
        foreach ($this->records as $book) {
            // print_r($book);
            if ($book['isbn'] !== $isbn) {
                continue;
            }
            echo "<p><b>{$book['title']}</b> by " . implode(', ', $book['author']) . "</br>";
            echo "ISBN: {$book['isbn']}<br/>";
            echo "Comment: {$book['comment']}</p>\n";
        }
        echo "<p>Back to the <a href=\"{$_SERVER['PHP_SELF']}\"> list of books </a><p>\n";
    }
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>My Library</title>
</head>
<body>
<?php 
$library = new BookList("books.xml");
if (isset($_GET['isbn'])) {
    $library->showBook($_GET['isbn']);
} else {
    $library->showMenu();
}
?>
</body>
</html>
示例#2
0
文件: admin.php 项目: AliEksi/DokuDok
}
include_once "client_functions.php";
include_once "users.php";
include_once "admin_functions.php";
include_once "list.php";
if (admin_logged_in()) {
    if (isset($_POST['create'])) {
        echo '<div class="login-card">';
        echo "<center>Password : "******"</center>";
        echo '</div>';
        direct("admin.php", 3);
    } elseif (isset($_POST['log_out'])) {
        session_destroy();
        direct('admin.php', 0);
    } elseif (isset($_POST['update_book'])) {
        $list = new BookList(get_pathname());
        $list->saveList();
        echo '<div class="login-card">';
        echo "<center>List has been updated.</center>";
        echo '</div>';
        direct('admin.php', 3);
    } else {
        echo '<div class="login-card">';
        echo "<form method='post' action=''>\n\t\t<input type='submit' name='create' value='Create User' class='login login-submit' />\n\t\t<br/>\n\t\t<input type='submit' name='update_book' value='Update List' class='login login-submit' />\n\t\t<br/>\n\t\t<input type='submit' name='log_out' value='Logout' class='login login-submit' />\n\t\t</form>";
        echo '</div>';
    }
} else {
    if (isset($_POST['sub'])) {
        verify_admin();
        direct('admin.php', 0);
    } else {
 /**
  * (PHP 5 &gt;= 5.0.0)<br/>
  * Rewind the Iterator to the first element
  * @link http://php.net/manual/en/iterator.rewind.php
  * @return void Any returned value is ignored.
  */
 public function rewind()
 {
     $this->currentBook = $this->bookList->count() - 1;
 }
示例#4
0
<?php

ini_set('display_errors', '1');
function __autoload($class_name)
{
    set_include_path('class');
    include_once $class_name . '.php';
}
writeln('BEGIN TESTING INTERPRETER PATTERN');
writeln('');
//load BookList for test data
$bookList = new BookList();
$inBook1 = new Book('PHP for Cats', 'Larry Truett');
$inBook2 = new Book('MySQL for Cats', 'Larry Truett');
$bookList->addBook($inBook1);
$bookList->addBook($inBook2);
$interpreter = new Interpreter($bookList);
writeln('test 1 - invalid request missing "book"');
writeln($interpreter->interpret('author 1'));
writeln('');
writeln('test 2 - valid book author request');
writeln($interpreter->interpret('book author 1'));
writeln('');
writeln('test 3 - valid book title request');
writeln($interpreter->interpret('book title 2'));
writeln('');
writeln('test 4 - valid book author title request');
writeln($interpreter->interpret('book author title 1'));
writeln('');
writeln('test 5 - invalid request with invalid book number');
writeln($interpreter->interpret('book title 3'));
 /**
  * (PHP 5 &gt;= 5.0.0)<br/>
  * Checks if current position is valid
  * @link http://php.net/manual/en/iterator.valid.php
  * @return boolean The return value will be casted to boolean and then evaluated.
  *       Returns true on success or false on failure.
  */
 public function valid()
 {
     return null !== $this->bookList->getBook($this->currentBook);
 }
示例#6
0
<?php

require 'Book.php';
require 'BookList.php';
require 'BookListIterator.php';
$firstBook = new Book('Core PHP Programming, Third Edition', 'Atkinson and Suraski');
$secondBook = new Book('PHP Bible', 'Converse and Park');
$thirdBook = new Book('Design Patterns', 'Gamma, Helm, Johnson, and Vlissides');
$books = new BookList();
$books->addBook($firstBook);
$books->addBook($secondBook);
$books->addBook($thirdBook);
$booksIterator = new BookListIterator($books);
while ($booksIterator->hasNextBook()) {
    $book = $booksIterator->getNextBook();
    echo $book->getAuthorAndTitle();
}
示例#7
0
});
$app->patch("/booklist/{authorId}/{bookId}", function ($authorId, $bookId) use($app) {
    $update_book = BookList::find('id', $_POST['booklist_id']);
    $due_date = $_POST['due_date'];
    $patron_id = $_POST['patron_id'];
    $update_book[0]->update($due_date, $patron_id);
    $author = Author::find($authorId);
    $author_id = $author->getId();
    $book = Book::find($bookId);
    $book_id = $book->getId();
    $book_list = BookList::findBookList($author_id, $book_id);
    return $app['twig']->render('booklist.html.twig', array('book_list' => $book_list, 'book' => $book, 'author' => $author, 'patrons' => Patron::getAll()));
});
$app->get("booklist/{bookId}/out/", function ($bookId) use($app) {
    $column_id = 'id';
    $books = BookList::find($column_id, intval($bookId));
    $patrons = Patron::getAll();
    return $app['twig']->render('checkout.html.twig', array('book' => $books[0], 'patrons' => $patrons));
});
//----------------------------Add a Book functionality Begin -------------------------
//Redirect for add a book page.
$app->get("/add", function () use($app) {
    $patrons = Patron::getAll();
    return $app['twig']->render('add.html.twig', array('patrons' => $patrons));
});
$app->post("/add", function () use($app) {
    $patron_name = $_POST['patron_name'];
    $new_patron = new Patron($patron_name);
    $new_patron->save();
    $patrons = Patron::getAll();
    return $app['twig']->render('add.html.twig', array('patrons' => $patrons));
 /**
  * (PHP 5 &gt;= 5.0.0)<br/>
  * Checks if current position is valid
  * @link http://php.net/manual/en/iterator.valid.php
  * @return boolean The return value will be casted to boolean and then evaluated.
  *       Returns true on success or false on failure.
  */
 public function valid()
 {
     return $this->currentBook < $this->bookList->count();
 }
示例#9
0
 function test_updateBookList()
 {
     //Arrange
     $book_name = "Gattica";
     $book_id = 2;
     $test_book = new Book($book_name, $book_id);
     $test_book->save();
     $author_name = "Aristole";
     $author_id2 = 1;
     $test_author = new Author($author_name, $author_id2);
     $test_author->save();
     $book_name = "Battlestar";
     $book_id = 2;
     $test_book2 = new Book($book_name, $book_id);
     $test_book2->save();
     $author_name = "Plato";
     $author_id2 = 1;
     $test_author2 = new Author($author_name, $author_id2);
     $test_author2->save();
     $author_id = $test_author->getId();
     $book_id = $test_book->getId();
     $due_date = "2015-08-29";
     $id = 3;
     $checkout_patron_id = 1;
     $test_book_list = new BookList($author_id, $book_id, $due_date, $checkout_patron_id, $id);
     $test_book_list->save();
     $author_id2 = $test_author2->getId();
     $book_id2 = $test_book2->getId();
     $due_date2 = "2015-08-27";
     $id2 = 4;
     $checkout_patron_id2 = 2;
     $test_book_list2 = new BookList($author_id2, $book_id2, $due_date2, $checkout_patron_id2, $id2);
     $test_book_list2->save();
     $due_date3 = "2015-08-27";
     $id3 = 5;
     $checkout_patron_id3 = 3;
     $test_book_list3 = new BookList($author_id, $book_id, $due_date3, $checkout_patron_id3, $id3);
     $test_book_list3->save();
     //Act
     $new_due_date = "2016-07-26";
     $new_checkout_patron_id = 99;
     $test_book_list->update($new_due_date, $new_checkout_patron_id);
     $result = $test_book_list->getCheckoutPatronId();
     //Assert
     $this->assertEquals($new_checkout_patron_id, $result);
 }