- Code: Select all
<?php
//check for passed variables
$item = ''; //variable to hold the individual helpfile currently in view
if(isset($_GET['item']))
{
$item = $_GET['item'];
}
$category = ''; //variable to hold the selected category to be listed
if(isset($_GET['category']))
{
$category = $_GET['category'];
}
$letter = ''; //variable to hold the selected letter to be listed
if(isset($_GET['letter']))
{
$letter = $_GET['letter'];
}
$keyword = ''; //variable to hold the entered search criteria to be listed
if(isset($_GET['keyword']))
{
$keyword = $_GET['keyword'];
}
?>
<div id="content">
<div align="center">
<br>
<?php
//if an item has been chosen show the individual helpfile
//--------------------------------------------------------------------------------------------------//
if($item != '')
{
//get the details of the selected helpfile
$helpQry = "SELECT * FROM DB1.helpfiles WHERE name = \"".$item."\"";
$helpRes = mysql_query($helpQry) or die(mysql_error());
$helpArr = mysql_fetch_array($helpRes);
echo("<h3 id='help' title='help'>".$item."</h3>");
echo("<table align='center'>");
echo("<tr><th align='left'>".$item."</th></tr>");
echo("<tr><td align='left'>".parse_string($helpArr['entry'])."</td></tr>");
echo("<tr><th align='left'>Related entries:");
//split the related entries string into seperate strings to be used as links
$related_entries_array = explode(" ", $helpArr['related_entries']);
//write a link for each related entry
for($i=0;$i<count($related_entries_array);$i++)
{
echo(" <a href='index.php?location=help&item=".$related_entries_array[$i]."'>".parse_string(
$related_entries_array[$i])."</a>");
}
echo("</th></tr>");
echo("<tr><td> </td></tr>");
echo("</table>");
echo("<hr>");
}
//------------------------------------------------------------------------------------------------//
//if a category has been chosen show the helpfiles for that category
//-----------------------------------------------------------------------------------------------//
if($category != '')
{
//get all of the helpfiles for this category
$fileQry = "SELECT distinct name FROM DB1.helpfiles WHERE category = \"".$category."\""
." AND required_level = '0' ORDER BY name";
$fileRes = mysql_query($fileQry) or die(mysql_error());
echo("<h3 id='help' title='help'>".$category."</h3>");
echo("<table align='center'>");
echo("<tr>");
$i = 0;//variable to count the categories written on this row
while($fileArr = mysql_fetch_array($fileRes))
{
// if this is the first item of the row, write row start tags
if($i == 0)
{
echo("<tr>");
}
//write the category link
echo("<td align='center' width='100'><a href='index.php?location=help&item="
.$fileArr['name']."'>");
echo($fileArr['name']);
echo("</a></td>");
$i++; //incriment count
//if this is the fourth item of the row, start a new row
if($i==4)
{
echo("</tr>");
$i = 0;// reset count to zero for the next row
}
}
echo("<tr><td> </td></tr>");
echo("</table>");
echo("<hr>");
}
//------------------------------------------------------------------------------------------------//
//if a letter has been chosen show the helpfiles beginning with that letter
//-----------------------------------------------------------------------------------------------//
if($letter != '')
{
//get all of the helpfiles for this letter
$fileQry = "SELECT distinct name FROM DB1.helpfiles WHERE SUBSTRING(name, 1, 1) = \"".$letter."\""
." AND category != 'Staff'"
." AND category != 'Building'"
." AND required_level = '0' ORDER BY name";
$fileRes = mysql_query($fileQry) or die(mysql_error());
echo("<h3 id='help' title='help'>Helpfiles beginning with ".$letter."</h3>");
echo("<table align='center'>");
echo("<tr>");
$i = 0;//variable to count the helpfiles written on this row
while($fileArr = mysql_fetch_array($fileRes))
{
// if this is the first item of the row, write row start tags
if($i == 0)
{
echo("<tr>");
}
//write the category link
echo("<td align='center' width='100'><a href='index.php?location=help&item="
.$fileArr['name']."'>");
echo($fileArr['name']);
echo("</a></td>");
$i++; //incriment count
//if this is the fourth item of the row, start a new row
if($i==4)
{
echo("</tr>");
$i = 0;// reset count to zero for the next row
}
}
echo("<tr><td> </td></tr>");
echo("</table>");
echo("<hr>");
}
//------------------------------------------------------------------------------------------------//
//if a keyword has been entered show the matching helpfiles
//-----------------------------------------------------------------------------------------------//
if($keyword != '')
{
//get all of the helpfiles for this keyword
$fileQry = "SELECT distinct name FROM DB1.helpfiles WHERE LOCATE(\"".$keyword."\", name)"
." AND category != 'Staff'"
." AND category != 'Building'"
." AND required_level = '0' ORDER BY name";
$fileRes = mysql_query($fileQry) or die(mysql_error());
echo("<h3 id='help' title='help'>Search Results For <i>".$keyword."</i></h3>");
echo("<table align='center'>");
echo("<tr>");
$i = 0;//variable to count the helpfiles written on this row
$count = 0;
while($fileArr = mysql_fetch_array($fileRes))
{
// if this is the first item of the row, write row start tags
if($i == 0)
{
echo("<tr>");
}
//write the category link
echo("<td align='center' width='100'><a href='index.php?location=help&item="
.$fileArr['name']."'>");
echo($fileArr['name']);
echo("</a></td>");
$i++; //incriment count
$count++;
//if this is the fourth item of the row, start a new row
if($i==4)
{
echo("</tr>");
$i = 0;// reset count to zero for the next row
}
}
//if no helpfiles have been written, there are no matches, so display an error message
if($count == 0)
{
echo("<tr><td>No helpfiles could be found to match the criteria you entered.</td></tr>");
}
echo("<tr><td> </td></tr>");
echo("</table>");
echo("<hr>");
}
//------------------------------------------------------------------------------------------------//
//show the main contents of the helpfiles
//-------------------------------------------------------------------------------------------------//
//get a list of categories to display as links
$catQry = "SELECT distinct category FROM DB1.helpfiles WHERE category != 'Staff'"
." AND category != 'Building'"
." AND required_level = '0' ORDER BY category";
$catRes = mysql_query($catQry) or die(mysql_error());
//Write the categorical index
echo("<h3 id='help' title='help'>Categorical Index</h3>");
echo("<table align='center'>");
echo("<tr><td> </td></tr>");
echo("<tr>");
$i = 0;//variable to count the categories written on this row
while($catArr = mysql_fetch_array($catRes))
{
// if this is the first item of the row, write row start tags
if($i == 0)
{
echo("<tr>");
}
//write the category link
echo("<td align='center' width='100'><a href='index.php?location=help&category="
.$catArr['category']."'>");
echo($catArr['category']);
echo("</a></td>");
$i++; //incriment count
//if this is the fourth item of the row, start a new row
if($i==4)
{
echo("</tr>");
$i = 0;// reset count to zero for the next row
}
}
echo("</table>");
//write the alphabetical index
echo("<h3 id='help' title='help'>Alphabetical Index</h3>");
$alphabet = array("A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L"
," M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z");
echo("<table align='center'>");
echo("<tr>");
for($n=0;$n<count($alphabet);$n++)
{
echo("<td width='5'><a href='index.php?location=help&letter="
.$alphabet[$n]."'>".$alphabet[$n]."</a></td>");
}
echo("</tr>");
echo("</table>");
//write the search index
echo("<h3 id='help' title='help'>Helpfile Search</h3>");
echo("<Form name='searchForm' method='get' action=".$_SERVER[PHP_SELF].">");
echo("<input type='hidden' name='location' value='help'>");
echo("<table align='center'>");
echo("<tr><td><input type='text' size='30' name='keyword'></td></tr>");
echo("<tr><td><button type='submit'>Search</button></td></tr>");
echo("</table>");
echo("</form>");
//-----------------------------------------------------------------------------------------------//
?>
</div>
<div align="center">
<h3 id="help" title="help">Featured helpfile</h3>
<?php
//This section of code selects a random helpfile from the database at every page load
//array to hold names of helpfiles
$namesArr = array();
$entryArr = array();
$count = 0;
//get the details of helpfiles in the database and count them
$numQry = "SELECT name, entry FROM DB1.helpfiles WHERE category != 'Staff'"
." AND category != 'Building'"
." AND required_level = '0'";
$numRes = mysql_query($numQry) or die(mysql_error());
while($numArr = mysql_fetch_array($numRes))
{
//add the names to the array
array_push($namesArr, $numArr['name']);
//add the entries to the array
array_push($entryArr, $numArr['entry']);
$count++; //incriment the count of entries
}
//randomise a number between 1 and the number of helpfiles in the database
$number = rand(1, $count);
//write the data using the randomised number
echo("<table align='center'>");
echo("<tr><th align='left'>".$namesArr[$number]."</th></tr>");
echo("<tr><td align='left'>".parse_string($entryArr[$number])."</td></tr>");
echo("</table>");
?>
</div>
</div>
<?php
//String Parsing function - Remove #n and replaces with <b>or</b>
function parse_string($string_to_parse)
{
//check the string for #0 and replace them with </b>
$string_to_parse = str_replace("#0","</b>", $string_to_parse);
//check the string for any #n remaining <b>
$string_to_parse = str_replace("#1","<b>", $string_to_parse);
$string_to_parse = str_replace("#2","<b>", $string_to_parse);
$string_to_parse = str_replace("#3","<b>", $string_to_parse);
$string_to_parse = str_replace("#4","<b>", $string_to_parse);
$string_to_parse = str_replace("#5","<b>", $string_to_parse);
$string_to_parse = str_replace("#6","<b>", $string_to_parse);
$string_to_parse = str_replace("#7","<b>", $string_to_parse);
$string_to_parse = str_replace("#8","<b>", $string_to_parse);
$string_to_parse = str_replace("#9","<b>", $string_to_parse);
$string_to_parse = str_replace("(null)"," ", $string_to_parse);
//insert line breaks where needed
$string_to_parse = nl2br($string_to_parse);
//return the parsed string
return $string_to_parse;
}
?>
