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

// ******************************************************************
// CATEGORY BLOCKS
// Blocks Available:
//  - blockGetTop2LevelCategoryList
//    (Prints top two levels of categories from DB.)
//  - blockGetSubCategoryList
//    (Prints subcategories of inputted category.)
//  - blockGetRelatedCategoryList
//    (Prints related categories of inputted category.)
//  - blockGetCategoryDetails
//    (Prints details of inputted category.)
// ******************************************************************

// **** blockGetTop2LevelCategoryList Function ****
// Input: --
// Output: To screen
// Description: Prints list of the top two levels of categories into a table.
function blockGetTop2LevelCategoryList()
{
  // ** Major Categories
  $categoryList = getCategoryList();
  if (!$categoryList == '')
  {
    print '<h2>Topic Listing</h2>';
    print '<ul>';
    while ($category = dbGetRow($categoryList))
    {
      print '<li><a href="topic.php?c=' . $category[0] . '">' . $category[1] . '</a>';

      // ** Subcategories
      $subCategoryList = getSubCategoryList($category[0]);
      if (!$subCategoryList == '')
      {
        print '<ul>';
        while ($subCategory = dbGetRow($subCategoryList))
        {
          print '<li><a href="topic.php?c=' . $subCategory[0] . '">' . $subCategory[1] . '</a></li>';
        } 
        print '</ul>';
      }
      print '</li>';
    }
    print '</ul>';
  }
  else
  {
    print 'No categories found.';
  }
}

// **** blockGetSubCategoryList Function ****
// Input: Category_id
// Output: To screen
// Description: Prints subcategories of a given category in an unordered list.
function blockGetSubCategoryList($category_id)
{
  // ** Subcategories
  $subCategoryList = getSubCategoryList($category_id);
  if (!$subCategoryList == '')
  {
    print '<table width="100%" cellpadding="3" class="titletable">';                      // <table>
    print '<tr><th>Sub-categories</th></tr>';                                             // <tr><th></th></tr>

    while ($subCategory = dbGetRow($subCategoryList))
    {
        if ($evenRow == false)                                                            // <tr>
          print '<tr class="darkrow">';
        else
          print '<tr class="lightrow">';

        // Print subcategory info.
        print '<td><a href="topic.php?c=' . $subCategory[0] . '">'
        . $subCategory[1] . '</a></td>';                                                  // <td></td>
        print '</tr>';                                                                    // </tr>

      if ($evenRow == false)
        $evenRow = true;
      else
        $evenRow = false;
    }
    print '</table>';                                                                     // </table>
  }
}


// **** blockGetRelatedCategoryList Function ****
// Input: Category_id
// Output: To screen
// Description: Prints related categories of a given category in an unordered list.
function blockGetRelatedCategoryList($category_id)
{
  // ** Related Categories
  $relatedCategoryList = getRelatedCategoryList($category_id);
  if (!$relatedCategoryList == '')
  {
    print '<table width="100%" cellpadding="3" class="titletable">';                      // <table>
    print '<tr><th>Related Categories</th></tr>';                                         // <tr><th></th></tr>

    while ($category = dbGetRow($relatedCategoryList))
    {
        if ($evenRow == false)                                                            // <tr>
          print '<tr class="darkrow">';
        else
          print '<tr class="lightrow">';

        // Print subcategory info.
        print '<td><a href="topic.php?c=' . $category[0] . '">'
        . $category[1] . '</a></td>';                                                     // <td></td>
        print '</tr>';                                                                    // </tr>

      if ($evenRow == false)
        $evenRow = true;
      else
        $evenRow = false;
    }
    print '</table>';                                                                     // </table>
  }
}

// **** blockGetCategoryDetails Function ****
// Input: Category_id
// Output: To screen
// Description: Prints details of a given category (Name, Description, etc).
function blockGetCategoryDetails($category_id)
{
  $categories = getCategory($category_id);
  if ($category = dbGetRow($categories))
  {
    print '<h2>' . $category[1] . '</h2>';
    print '<h3><i>' . $category[2] . '</i></h3>';
  }
}
?>
Return current item: The Online Web Library Site