Version: 1

Type: Full Script

Category: HTTP

License: GNU General Public License

Description: Simply FAQ - is a fully functional easy to use FAQ program with seach capability, unlimited categories, NO NEED for mysql database only text base and with NO compicated setup just upload it and its done, it uses only one(1) PHP file. How simple to add the content of your FAQ, just open your favorite text editor and start typing in the first line the Question and in the next line the answer and so on, save it with .faq extension and the script will automatically read this, the filename of this file will be the Category name in the FAQ section. To sort which categories to be first, just add a number on the first character of your filename ( ex. 1how_to.faq, 2Others.faq )



/*
Created by http://smallcapitalbusiness.com

Other Scripts we made:
 - Traffic Exchange Link (The New Generation)
 - Simply FAQ Script
 - Write Text to the Image
 - Image Resizer
 - Simple Web Monitoring
 - Capture TGP New listing
 - Exit Popup Exchange Service
 - Domain Redirection Service
 - TGP or Thumbnail Gallery Post

GNU : Do not remove our signature at the bottom page
*/
<?php
$err="";
$totfound=0;
if(!isset($idx)) $idx=0;
function QuestionHere($cnt,$Q)
{
	print "<b>$cnt. $Q</b><br>";
}

function AnswerHere($cnt,$A)
{
	print "$A <font size=1><br><br></font>";
}

//read all with .faq ext.
$currdir=getcwd();
$dir=@opendir($currdir);
if(!$dir) print "Error dir $currdir";
$aCategory=array();
$n=0;
while($file=@readdir($dir))
	{
	if(substr($file,-4)==".faq")
		{
		$aCategory[]=$file;
		//print substr($file,-4)." = $n. $aCategory[$n]<br>"; $n++;
		}
	}

sort($aCategory);
$nMaxCate=count($aCategory);

//Search
if(isset($searchtxt) && strlen($searchtxt)<3)
{
$err="Search at least 3 characters.";
$idx=-1;
$aFound=array();
}
elseif(isset($searchtxt) && $searchtxt!="")
{
$idx=-1;
$aFound=array();
for($a=0;$a<$nMaxCate;$a++)
	{
	$nFirst=0;
	$ccfile=$currdir."/".$aCategory[$a];
	$fp=@fopen($ccfile,"r");
	if(!@fp) {print "Error reading ".$currdir."/".$aCategory[$a]; exit;}
	$QorA=0;
	$cnt=1;
	$TempQ="";
	$okenter=0;
	while(!feof($fp))
		{
		$ln=fgets($fp,5000);
		if(trim($ln)!="")
			{

				if(stristr($ln,$searchtxt) || $okenter==1)
				{
					if($nFirst==0) 
					{
						$cCate=str_replace("_"," ",$aCategory[$a]);
						$cCate=substr(substr($cCate,1),0,-4);
				
						$aFound[]="@CATEGORY@$cCate";
						$nFirst=1;
					}

			
					if($QorA==0) //Question
						{
						$QorA=1;
						$okenter=1;
						$totfound++;
						}
					else
						{
						$QorA=0;
						if($okenter==0) 
							{
							$totfound++;
							$TempQ=str_replace($searchtxt,"<font color='000080'>$searchtxt</font>",$TempQ);
							$aFound[]=$TempQ;
							}
						$okenter=0;
						}
					$ln=str_replace($searchtxt,"<font color='000080'>$searchtxt</font>",$ln);
					$aFound[]=$ln;

				}
				else
				{
					if($QorA==0) {$TempQ=$ln; $QorA=1;}
					elseif($QorA==1) {$QorA=0; $TempQ="";}
				}
			}
	
		}
	}
}

?>


<html>
<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>FAQ</title>
<STYLE type="text/css">
<!--
A { text-decoration:none; color: #0000cc }
-->
</STYLE>

<style fprolloverstyle>A:hover {color: #cc0000;}</style>

</head>

<body>
<center>
<table border="0" width="750" style="font-family: Arial; font-size: 10pt" cellspacing="0" cellpadding="5">
  <tr>
    <td width="100%" bgcolor="#000080">
      <p align="center"><font color="#FFFFFF" size="4"><b>FAQ</b></font></td>
  </tr>
  <tr>
    <td width="100%">
      <p align="center"><b>Categories :</b><br>&nbsp; 

<?php
for($a=0;$a<$nMaxCate;$a++)
{
$cCate=str_replace("_","<font color=#ffffff>_</font>",$aCategory[$a]);
$cCate=substr(substr($cCate,1),0,-4);
$$cCate=strtoupper($file);

if($a==$idx) {print "[<b><font color='#008080'>$cCate</font></b>] &nbsp;"; $cSelectedCate=$cCate;}
else print "[<a href='faq.php?idx=$a'>$cCate</a>] &nbsp;";
}
?>

</p>
    </td>
  </tr>
  <tr>
    <td width="100%">
<form method="POST" action="faq.php">

      <p align="center"><b>Search :</b> 
        <input type="text" name="searchtxt" size="20" style="font-family: Arial; font-size: 8pt">
      <input type="submit" value="Go" name="Search" style="font-family: Arial; font-size: 8pt">
      </form>
      </p>
    </td>
  </tr>
  <tr>
    <td width="100%">
      <hr width="95%" size="1" color="#777777">


<?php 
if($idx>=0)
{
print "<font size='3' color='#008080'><b>$cSelectedCate<br><br></b></font>";

$fp=@fopen($aCategory[$idx],"r");
if(!$fp) {print "Error reading ".$currdir."/".$aCategory[$a]; exit;}
$QorA=0;
$cnt=1;
while(!feof($fp))
	{
	$ln=fgets($fp,500);
	if(trim($ln)!="")
		{
		if($QorA==0) {QuestionHere($cnt,$ln); $QorA=1;}
		else {AnswerHere($cnt,$ln); $QorA=0; $cnt++;}
		}
	}
}
else 
{ // SEARCH MODULE
$nMaxFound=count($aFound);

if($nMaxFound==0) 
{
if($err!="") print "<br><font color='cc0000'>$err</font>";
else print "No search found for <b>$searchtxt</b>";
}

else
	{
	print "<font color=#000080 size=3>Search \"<b>$searchtxt</b>\", found <b>$totfound</b> topics.<br></font>";
	$cnt=1;
	$QorA=0;
	for($a=0;$a<$nMaxFound;$a++)
		{
		if(substr($aFound[$a],0,10)=="@CATEGORY@")
			{
			$cSelectedCate=substr($aFound[$a],10);
			print "<br><font size='3' color='#008080'><b>$cSelectedCate<br></b></font>";	
			$QorA=0;		
			}
		else
			{
			if($QorA==0) {QuestionHere($cnt,$aFound[$a]); $QorA=1;}
			else {AnswerHere($cnt,$aFound[$a]); $QorA=0; $cnt++;}
			}		
		}

	}
}
?>

<br><br><font size=1>Powered by <a href='http://smallcapitalbusiness.com'>SmallCapitalBusiness.com</a></font>
</td>
  </tr>
</table>

</body>

</html>