Location: PHPKode > projects > The Online Web Library Site > towels/src/blocks/book.block.php
<?php
include_once('etc/vars.php');

// ******************************************************************
// BOOK BLOCKS
// Blocks Available:
//  - blockGetBookList
//    (Prints list of all books, including a modifier (filter).)
// ******************************************************************


// **** blockGetBookList Function ****
// Input: RowStart & author_id OR category_id OR format_id (optional)
// Output: To screen
// Description: Prints list of all books into a table, with author, category
//              or format modifiers (filters) to restrict list.
function blockGetBookList($rowStart, $author_id = NULL, $category_id = NULL, $format_id = NULL)
{
  global $displayLimit, $siteRoot;

  // Get book list and display it, starting at the passed in number, and displaying
  // a set number of items (plus to be able to check if there's extra beyond the displayed).
  
  if (!is_null($author_id))
    $bookList = getBookList($rowStart, $displayLimit + 1, $author_id);
  elseif (!is_null($category_id))
    $bookList = getBookList($rowStart, $displayLimit + 1, NULL, $category_id);
  elseif (!is_null($format_id))
    $bookList = getBookList($rowStart, $displayLimit + 1, NULL, NULL, $format_id);
  else
    $bookList = getBookList($rowStart, $displayLimit + 1);

  if (!$bookList == '')  // Display list if books are found in DB.
  {
    print '<h3>Book Listing</h3>';
    print '<table width="100%" cellpadding="3" class="titletable">';                      // <table>

    if (!is_null($author_id))                                                             // <tr><th></th></tr>
      print '<tr><th width="450">Title</th><th width="100">Formats</th></tr>';
    elseif (!is_null($format_id))
      print '<tr><th width="425">Title</th><th width="125">Author</th></tr>';
    else
      print '<tr><th width="325">Title</th><th width="125">Author</th><th width="100">Formats</th></tr>';
    
    $displayItems = 1;
    $evenRow = false;

    // Loop until total number of items are displayed.
    while ($displayItems <= $displayLimit)
    {

      // If there is another book in the table, display it.
      if ($book = dbGetRow($bookList))
      {
        if ($evenRow == false)                                                            // <tr>
          print '<tr class="darkrow">';
        else
          print '<tr class="lightrow">';

        // Print book info.
        print '<td><a href="' . $siteRoot . 'display.php?d=' . $book[0] .
          '">' . $book[1] . '</a></td>';                                                  // <td></td>
        
        if (is_null($author_id))
          print '<td>' . $book[5] . ' ' . $book[4] . '</td>';                             // <td></td>

        if (is_null($format_id))
        {
          print '<td>';                                                                   // <td>
          // Print all formats for a book.
          $formatList = getBookFormatList($book[0]);
          while ($format = dbGetRow($formatList))
          {

            print '<a href="' . $siteRoot . 'display.php?d=' . $book[0] . '&amp;f=' . $format[0] . '">';
            print '<img src="images/' . strtolower($format[0]) . '.gif" alt="' . $format[1] . '" title="' . $format[1] . '" border="0"></a>';

          }
          print '</td>';                                                                  // </td>
        }
        print '</tr>';                                                                    // </tr>
      }

      // Increment number of items displayed.
      $displayItems++;
      
      if ($evenRow == false)
        $evenRow = true;
      else
        $evenRow = false;
    }
    print '</table>';                                                                     // </table>

    // Display Page Navigation
    if (!is_null($author_id))
      blockPageNavigation('b', $rowStart, 'a', $author_id);
    elseif (!is_null($category_id))
      blockPageNavigation('b', $rowStart, 'c', $category_id);
    elseif (!is_null($format_id))
      blockPageNavigation('b', $rowStart, 'f', $format_id);
    else
      blockPageNavigation('b', $rowStart);

  }
  else  // Print error when book lookup returns no results.
  {
    print 'No books found.  Either there is a database problem, or this is a brand new installation that is working, but is simply empty!';
  }
}

?>
Return current item: The Online Web Library Site