Location: PHPKode > projects > The Referral Database > referralsdb/output_fns.php
<?php

function display_categories($cat_array)
/* Expects $cat-array as flat-to-flat array
   $cat_array[0][0] = Cat_ID
   $cat_array[0][1] = Cat_Name */
{
?>
<table border="0" cellspacing="0" width="100%" id="AutoNumber1" bgcolor="#FFFFFF" style="border-collapse: collapse" bordercolor="#FFFFFF" cellpadding="0">
  <tr>
    <td width="50%">
    <table>
      <tr>
	   <td style="font-family: Arial, Helvetica, sans-serif; font-size: 13px">
<?php

  if (!is_array($cat_array))
  {
     echo "No available categories.<br>";
     return;
  }
  echo "<ul>";
  foreach ($cat_array as $row)
  {
	#print $cat_array;
    $url = "show_cat.php?catid=".($row[0]);
    $title = stripslashes($row[1]); 
    echo "<li>";
    do_html_url($url, $title); 
  }    
  echo "</ul>";
   $logo = $GLOBALS['cfg']['biglogo'];
   $width = $GLOBALS['cfg']['biglogowidth'];
   $height = $GLOBALS['cfg']['biglogoheight'];

   if (empty($width) || empty($height)) {
	$logo = "<img border=\"0\" src=\"$logo\">";
   } else {
	$logo = "<img border=\"0\" src=\"$logo\" height=\"$height\" width=\"$width\">";
   }

   echo <<<END
          </td>
      </tr>
    </table>
    <p>&nbsp;</td>
    <td align="center">
    $logo
    </td>
  </tr>
</table>
END;
}

function display_organizations($organization_array)
/*  Expects $organizaiton_array as an flast-to-flat array
    $org_array[0][0] = Org_ID
    $org_array[0][1] = Org_Code 
    $org_array[0][2] = Org_Name 
    $org_array[0][3] = Org_Phone */
{
   /* If more more than one arguments are passed, 
      we are returning search results. */
  if (func_num_args() >= 2) {
    $searchterm = func_get_arg(1);
  }

  //display all organizations in the array passed in
  if (!is_array($organization_array))
  {
  	if ($searchterm) 
    { 
     echo "<br>No organizations available with this search criteria.<br><p>";
    } 
    else 
    { 
     echo "<br>No organizations available in this category.<br><p>";
    }
  }
  else
  {
    //create table
    echo "<table width = \"100%\" border = 0>";
?>
<TABLE border="0" cellpadding="2" cellspacing="0">
  <TR>
    <TH scope="col" align=left bbr="Name">Name</TH>
    <TH scope="col" align=left abbr="PhoneNum" width=125>Phone Number</TH>
    <TH scope="col" align=left>Description</TH>
    <TH scope="col" align=center>Referral Code</TH>
  </TR>
<?php
    
    //create a table row for each organization
    $bgcolor = array("#e8e8e8", "white");
    foreach ($organization_array as $row)
    {
	  list($orgid, $orgcode, $orgname, $orgrefnum, $orgdetails) = $row;
      $orgrefnum = ez_format_phone($orgrefnum, "517", 1);
      if ($searchterm) { // Do search term highlighting if it's a search
                $orgname = highlight($searchterm, $orgname);
                $orgdetails = highlight($searchterm, $orgdetails);
                $orgcode = highlight($searchterm, $orgcode);
      }
      $url = "show_organization.php?orgid=".($orgid);
      $title =  "$orgname";
      $orgname = return_html_url($url, $title);
      echo "<tr bgcolor=$bgcolor[0]>";
		echo "<td scope='row'>$orgname</td>";
		echo "<td width=125>$orgrefnum</td>";
		echo "<TD>$orgdetails</td>";
		echo "<TD align=center>$orgcode</td>";
      echo "</tr>";
      $bgcolor = array_reverse($bgcolor);
    }
    echo "</table>";
  }
}

function display_organization_details($organization, $categories)
// Expects unidimentional flat array $organization
// and enumerated to enumerated array $categories
// $organization[0] = Org_ID
// $organization[1] = Org_Code
// $organization[1] = Org_Name
// ... and so on (see list() function below for values)
{
/// FIX
  if (is_array($categories))
  {
    $iterations = count($categories);
    foreach ($categories as $row)
    {
      $x++;
      $url = "show_cat.php?catid=".($row[0]);
      $title = $row[2]; 
	  if ($x < $iterations) { $seperator = ", "; } else { $seperator = ""; } 
      $orgcats .= return_html_URL($url, $title). $seperator; 
    }    
  }
    else
  {
    $orgcats = "The details of this organization cannot be displayed at this time.";
}
  // display all details about this organization
  if (is_array($organization))
  {
	list($orgid, $orgcode, $orgtitle, $orgreferralnum, $orglastupdated, $orgdetails, $orghours, $orgbusinessphone, $orgaddress, $orgcity, $orgstate, $orgzip, $orgemail, $orgwebsite, $orgcseligibility, $orgfeesins, $orgdirector, $orgcontact, $orgspecialinst) = $organization;

    $orgreferralnum = ez_format_phone($orgreferralnum, "517", 1);
    $orgbusinessphone = ez_format_phone($orgbusinessphone, "517", 1);
   $orgemail = email_to_mailto($orgemail);
   $orgwebsite = url_to_link($orgwebsite);
    echo "<table><tr>"; 
    //display the picture if there is one 
    if (@file_exists("images/".($organization["orgid"]).".jpg"))
    {
      $size = GetImageSize("images/".$organization["orgid"].".jpg");
      if($size[0]>0 && $size[1]>0)
        echo "<td><img src=\"images/".$organization["orgid"].".jpg\" border=0 ".$size[3]."></td>";
    }
    echo "<td><ul>";
    echo "<li><b>Title:</b> ";
    echo $orgtitle;
    echo "<li><b>Referral Code:</b> ";
    echo $orgcode;
    echo "<li><b>Database ID:</b> ";
    echo $orgid;
    echo "<li><b>Referral Number:</b> ";
    echo $orgreferralnum;
    echo "<li><b>Details:</b> ";
    echo $orgdetails;
    echo "<li><b>Hours of Operation:</b> ";
    echo $orghours;
    echo "<li><b>Business Phone Number:</b> ";
    echo $orgbusinessphone;
    echo "<li><b>Address:</b> ";
    echo $orgaddress;
    echo "<li><b>City:</b> ";
    echo $orgcity;
    echo "<li><b>State:</b> ";
    echo $orgstate;
    echo "<li><b>Zip:</b> ";
    echo $orgzip;
    echo "<li><b>Email Address:</b> ";
    echo $orgemail;
    echo "<li><b>Web Site:</b> ";
    echo $orgwebsite;
    echo "<li><b>Clients Served/Eligibility:</b> ";
    echo $orgcseligibility;
    echo "<li><b>Fees for Service/Insurance:</b> ";
    echo $orgfeesins;
    echo "<li><b>Organization Director:</b> ";
    echo $orgdirector;
    echo "<li><b>Contact Person:</b> ";
    echo $orgcontact;
    echo "<li><b>Special Instructions:</b> ";
    echo $orgspecialinst;
    echo "<li><b>Last Updated:</b> ";
    echo $orglastupdated;
    echo "<li><b>Listed under categories:</b> ";
    echo $orgcats;
    echo "</ul></td></tr></table>"; 
  }
  else
    echo "The details of this organization cannot be displayed at this time.";
}

function display_login_form()
{
  // dispaly form asking for name and password
?>
  <form method=post action="admin.php">
  <table bgcolor=#cccccc>
   <tr>
     <td>Username:</td>
     <td><input type=text name=username></td></tr>
   <tr>
     <td>Password:</td>
     <td><input type=password name=passwd></td></tr>
   <tr>
     <td colspan=2 align=center>
     <input type=submit value="Log in"></td></tr>
   <tr>
 </table></form>
<?php
}

function display_admin_menu()
{

echo <<<HTML
<br>
<a href="index.php">Browse and Edit</a><br>
<a href="insert_category_form.php">Add a new category</a><br>
<a href="insert_organization_form.php">Add a new organization</a><br>
<a href="change_password_form.php">Change admin password</a><br>
<a href="pdf.php">Create PDF file</a><br>
HTML;
#Removed until it actually works

}

function display_button($target, $image, $alt)
{
  echo "<center><a href=\"$target\"><img src=\"images/$image".".gif\" 
           alt=\"$alt\" border=0 height = 50 width = 135></a></center>";
}

function display_form_button($image, $alt)
{
  echo "<center><input type = image src=\"images/$image".".gif\" 
           alt=\"$alt\" border=0 height = 50 width = 135></center>";
}

function do_html_header($title = '')
{
  // print an HTML header
 
?>
  <html>
  <head>
    <title><?php echo $title?></title>
    <link rel="stylesheet" type="text/css" href="referrals-default.css" />
  </head>
  <body>
  <table width=100% border=0 cellspacing = 0 bgcolor="e8e8e8">
  <tr>
  <td rowspan = 2>
  <!-- <a href = "index.php"><img src="images/Listening_Ear.jpg" alt="Listening Ear" border=0
       align=left valign=bottom height = 55 width = 325></a> -->
  <?php if(session_is_registered("admin_user"))
       {
          echo "You are logged in as admin.<br>";
          $logoutURL = do_html_URL("logout.php","Logout");
       }
     else
		?>
  </td>
  <td align = right valign = bottom>
       <?php echo date("g:i a"); ?>
  </td>
  <td align = right rowspan = 2 width = 135>
  <form action="results.php" method="post">
    <input name="searchterm" type=text>
    <input type=submit value="Search">
  </form>
 </tr>
  <tr>
  <td align = right valign = top>
       <?php echo date("F jS Y"); ?>
  </td>
  </tr>
  </table>
<?php
  if($title)
    do_html_heading($title);
}

function do_html_footer()
{
  echo "<HR>";
  // print an HTML footer
  $currentpage = $_SERVER["REQUEST_URI"]; 
  ?>

   <table width="100%">
   <tr>
   <td align="left">   
  <?php
  if (!strstr($currentpage, "index.php") && !strstr($currentpage, "admin.php"))
  {
    do_html_url("index.php", "Back to Categores List");
  }
  if (!check_admin_user() && !strstr($currentpage, "login.php"))
  {
    do_html_url("login.php", "Resource Director Login");
  }
  if (check_admin_user())
  {
    if (strstr($currentpage,"show_cat.php")) 
    {
      do_html_url("edit_category_form.php?catid=$_GET[catid]", "Rename/Delete Category");
    }
    if (strstr($currentpage,"show_organization.php")) 
    {
      do_html_url("edit_organization_form.php?orgid=$_GET[orgid]", "Edit/Delete Organization");
    }

    if (!strstr($currentpage,"admin.php")) 
    {
      do_html_url("admin.php", "Resource Director Administration Menu");
    }
  }
   $version = $GLOBALS['version'];
echo <<<HTML
   </td>
   <td align="right">
   <a href="http://www.referraldatabase.org">Referral Database</a> v$version
   <br>
   <FONT color="#666666"><small> &copy; Copyright 2003 Joseph Glass</small></FONT>
   </td>
   </tr>
   </table>

   </body>
   </html>
HTML;
}

function do_html_heading($heading)
{
  // print heading
?>
  <h2><?php echo $heading;?></h2>
<?php
}

function do_html_URL($url, $name)
{
  // display URL as link and br
?>
  <a href="<?php echo $url;?>"><?php echo $name;?></a><br>
<?php
}

function &ez_format_phone($str, $area = "", $paren = false) {
    $len = strlen(($ret = preg_replace("/[^0-9]+/i", "", $str)));
    if($len == 7 && strlen($area) == 3) { $ret = $area.$ret; $len += 3; }
    if($len == 7) {
        return substr($ret, 0, 3)."-".substr($ret, 3);
    } else if($len == 10) {
        if($paren) {
            return "(".substr($ret, 0, 3).") ".substr($ret, 3, 3)."-".substr($ret, 6);
        } else {
            return substr($ret, 0, 3)."-".substr($ret, 3, 3)."-".substr($ret, 6);
        }
    } else {
        return $str;
    }
}

function email_to_mailto($email) {
   $email = preg_replace('/[^@\s]+@([-a-z0-9]+\.)+[a-z]{2,}/i',
                         '<a href="mailto:$0">$0</a>', $email);
   return $email;
}

function url_to_link($url) {
$url = preg_replace( "/\b((http(s?):\/\/)|(www\.)?)([\w-]+.)([\/\w+\.~]+)\b/i", "<a href=\"http$3://$4$5$6\">http://$4$5$6</a>",
$url);
   return $url;
}

function highlight($word, $haystack){
return preg_replace('|('.quotemeta($word).')|iU',
                    // '<b style="color: black; background-color: #ffff66">\\1</b>', $haystack);
                    '<b style="color: black">\\1</b>', $haystack);
}

function return_html_URL($url, $name)
{
  // return URL as link
  $link = "<a href='$url'>$name</a>";
  return $link;
}

?>
Return current item: The Referral Database