Location: PHPKode > projects > Open Chamber of Commerce > ococ/content/directory_listing.php
<?php 
/*
    Consolidated Member Directory:
    Creates a paged, categorized
    listing of listed member companies.
*/

include '../inc/db.inc';
include '../inc/error.inc';
include '../inc/site_globals.inc';

// header
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<html>
<head>
  <title><?php echo ORG_NAME_BREV;?> Member Directory</title>

<?php
$isie = "all";
$agent = $_SERVER['HTTP_USER_AGENT'];
if(!eregi("msie",$agent))
{
  $isie = "screen";
?>
<link rel="stylesheet" href="../c/dirlst_prnt.css" type="text/css" media="print" />
<?php
}
?>
<link rel="stylesheet" href="../c/dirlst_scrn.css" type="text/css" media="<?php echo $isie;?>" />
<style type="text/css">img { border: none; }</style>
</head>

<body>

<div id="vertical">&nbsp;</div>

<h1><?php echo ORG_NAME_BREV;?> Member Directory</h1>

<div id="print_button">
<form><input type="button" value="Print" onClick="javascript:window.print();" /></form>
</div>
<h2><?php echo date("F j, Y, g:i a"); ?></h2>


<?php
# log in to the database
if (!($db = @ mysql_connect($hostName, $userName, $passWord)))
   showError();

if (!( @ mysql_select_db($databaseName,$db)))
   showError();

  $obuff = array();
  $p = 1; $c = 1; $r = 1;

# set the number of member listings per/column
define(NUM_LISTINGS, 8);

// begin the table
echo "<table cellspacing=\"1\"cellpadding=\"4\" width=\"100%\">\n";

$sql = "SELECT * FROM $categories WHERE Id>1 ORDER BY Category ASC";
if(!$result = mysql_query($sql, $db))
  showError();

# each category
while($catrow = mysql_fetch_array($result))
{
  $lines = 1;  // reset category print flag
  $cid = $catrow["Id"];
  // get members in this category
  $sql2 = "SELECT * FROM $members 
  WHERE (Cat1='$cid' or Cat2='$cid' or Cat3='$cid') 
  ORDER by Biz ASC";
  if(!$result2 = mysql_query($sql2, $db))
    showError();
  $rowsfound = mysql_num_rows($result2);
  if($rowsfound < 1)
    continue;  // no members in this category, try next category
  
  # each member
  while($member = mysql_fetch_array($result2))
  {
    $listing = "";

    if($lines == 1)
    {
      $listing .= "<span class=\"category\"> ".$catrow["Category"]." ".$rowsfound."</span><br />\n";
      $lines ++;  // don't print again until next category
    }
    
    // dress up by status ranking
    $status = $member["Status"]; // switch must have a simple var, not array element
    switch($status)
    {
      case '':  // fall-through to basic if null
      case 'basic':
        $listing .= "";
        break;
      case 'higher':
        $listing .= "<span class=\"enh\">";
        break;
      case 'preferred':
        $listing .= "<span class=\"pre\">";
        break;
    }
    
    // show preferred members' logo if present
    if($member["Status"] == "preferred" and $member["Logo_Url"] != NULL)
    {
      // resize if needed to keep it smaller than 125 pixels wide and high
      list($width_orig, $height_orig) = getImageSize("../i/member_logos/" .$member["Logo_Url"]);
      $width = 125;
      $height = 50;
      if (($width_orig > $width) or ($height_orig > $height))
      {
        // scale image to max size
        if ($width_orig > $height_orig)
        {
          $width_orig = (int)(($height / $height_orig) * $width_orig);
          $height_orig = $height;
        } else {
          $height_orig = (int)(($width / $width_orig) * $height_orig);
          $width_orig = $width;
        }
      } // end scaling
      $logo = "<div style=\"margin:0 1em;float:right;\"><a href=\"../i/member_logos/".$member["Logo_Url"]."\"><img src=\"../i/member_logos/".$member["Logo_Url"]."\" width=\"".$width_orig."\" height=\"".$height_orig."\" alt=\"\" /></a></div>";
    } else {
      $logo = "";
    }
    
    // name
    $listing .= $logo. "<strong>" .$member["Biz"]. "</strong><br />";
    
    // description
    // limit description to 'n' words
    $n = 25;
    $barry = array(explode(" ", $member["Descr"]));  // burst into words
    $member["Descr"] = "";
    for($i=0; $i<=$n-1; $i++)
    {
      $member["Descr"] .= $barry[$i]." ";    // now re-assemble
    }
    if($logo == "")
    {
      $listing .= "<div style=\"width:50%;margin:0 1em;float:right;\"><em>" .$member["Descr"]. "</em></div>";
    } else {
      $listing .= "<em>" .$member["Descr"]. "</em><br />";
    }
    
    // contact info
    $listing .= $member["Address1"]. "<br />\n";
    if($member["Address2"] != NULL)
    {
      $listing .= $member["Address2"]. "<br />\n";
    }
    $listing .= $member["City"]. ", ";
    $listing .= $member["State"]. " " .$member["Zip"]."<br />\n";
    $listing .= "Ph:" .$member["Phone"]. " <a href=\"mailto:" .$member["Email"]. "\">". $member["Email"]."<br />\n";
    $listing .= "</span>";
    
    stuffIt($listing);  // add to print array
    
  } // end while members in this category
  //echo "[$p][$c][$r] "; // DEBUG
  
} // end while there are categories

printObuff();

echo "</table>\n";  // final table closure
echo "<p>&nbsp;</p>\n\n";

#########################################################################################
# F U N C T I O N S
#

# s t u f f I t ( ) #####################################
# 
# Stuffs a member listing into the next available
# slot in the output buffer array. Array is a paged
# 6-high by 2-wide collector to simulate 2-columns
#
function stuffIt($listing)
{
  global $obuff, $p, $c, $r;
  
  $obuff[$p][$c][$r] = $listing;
  $r++;     // next row
  if($r>NUM_LISTINGS)
  {
    $c++;   // next column
    $r = 1;
  }
  if($c>2)
  {
    $c = 1;
    $r = 1;
    $p++;   // next page
  }
} # end stuffIt()

# p r i n t O b u f f () ###############################
#
# Prints the contents of the yellow pages buffer array
#
function printObuff()
{
  global $obuff, $p, $c, $r;
  
  for($page=1; $page<=$p; $page++)
  {
    for($row=1; $row<=NUM_LISTINGS; $row++)
    {
      echo "<tr>\n";
      echo "  <td class=\"left\" width=\"50%\">" .$obuff[$page][1][$row]. "</td>\n";
      echo "  <td width=\"50%\">" .$obuff[$page][2][$row]. "</td>\n";
      echo "</tr>\n";
    }
    echo "<tr><td colspan=\"2\" style=\"border: none;\">Page $page</td><td></td></tr>\n";
    echo "</table>\n";
    echo "<table cellspacing=\"1\"cellpadding=\"4\" width=\"100%\">\n";

  }
} # end printObuff()

############## end function reservoir ##################################################
?>
</body>

</html>
Return current item: Open Chamber of Commerce