<?php
///////////////////////////////////////////////////////////////////////////////////
//	Wak's Ask&Answer/FAQs Script
//
//	Script by Katie http://luved.org - Teljes magyar felület by Adliz 
//
//	This script is linkware and can be used or modified as long as all credit is
//	left attached to this file and a link is placed on your website to
//	http://www.luved.org
//	You are forbidden to sell or distribute this script without permission by
//	it's creator and if a bug is found, report to scripts@luved.org
///////////////////////////////////////////////////////////////////////////////////

// -----------------------------------------------------------------
//	PROCESS QUESTIONS
// -----------------------------------------------------------------
// Below, you can change what response is given when the ASK button is
// pressed
//	Question was successful:
$qSuccess = "<p><b>Hamarosan válaszolok a kérdésedre :)</b></p>";
// Question failed due to double posting:
$qFailed_DoublePost = "<p><b>Csak egy kérdést tehetsz fel minden $sec másodpercben.</b></p>";
// Question failed due to a blank post
$qFailed_BlankPost = "<p><b>Üresen hagytad a kérdés rublikát, így nem lesz mire válaszolnom.</b></p>";

// process questions when button is pressed
if (isSet($_POST['ask'])) {
	$question = $_POST['question'];
	addQuestion($question);
}


// -----------------------------------------------------------------
//	DISPLAYS QUESTIONS AND ANSWERS X Entries Per Page
//
//	Try to read through my comments (any line with a leading //)
//	To customize the script to your liking
// -----------------------------------------------------------------
// Number of all answered questions
$totalAnswered = count(getTotalAnswered());
// Number of all entries in the database (answered and unanswered)
$total = total(DBFILE);
// Number of all unanswered questions
$totalUnAnswered = count(getTotalUnanswered());
// grab data from config.txt file
list($id, $key, $url, $email, $notify, $entryPerPage, $dtFormat, $display) = getFileRow(CONFIGFILE);
// if $entryPerPage is less than 1, set to the default number of entries per page
if ($entryPerPage < 1)
	$entryPerPage = $defaultEntryPerPage;
// --> Status
// display how many answered questions out of total questions asked, how many
// entries per page and the number of unanswered questions in database
echo "<b>$totalAnswered</b> megválaszolt kérdés a <b>$total</b> kérdésből.<br />";
echo "<b>$entryPerPage</b> kérdést találhatsz egy lapon.<br />";
echo "Jelenleg <b>$totalUnAnswered</b> megválaszolatlan kérdés van.";
?>
<!-- Ask text box:
NOTE: You can copy and paste the following line to a different page eg index.php if you just want to
display the form and not the actual question and answers. 
if you place askform.php in its own directory, change the location of askform.php, for example
include('path/to/askform.php')
-->
<?php include('askform.php')?>
<!-- End Ask text box-->

<?php
// -----------------------------------------------------------------
//	DISPLAYS QUESTIONS AND ANSWERS X Entries Per Page
//
//	Try to read through my comments (any line with a leading //)
//	To customize the script to your liking
// -----------------------------------------------------------------
// grabs answered questions into an array
$answeredRows = getTotalAnswered();
if (is_array($answeredRows)) {
	// if user set entries to be displayed in descending order, reverse rows in array
	if ($display == 2) {
		$answeredRows = array_reverse($answeredRows);
	}
	// page number
	$pagenum = $_GET['page'];
	// figures out from entries per page, and how many answered entries in database
	// as to how many pages there should be to display all entries
	$answeredRows = perPage($answeredRows, $entryPerPage, $pagenum);
	$numPages = $answeredRows['numpages']; 
	// display 'lapok:' if contains more than one page of entries
	?>
	<table class="qapost" border="0" width="400" align="center">
		<tr><td align="right"><?php printJumpToPage("$phpSelf?page=", $numPages, $pagenum); ?></td></tr>
	</table>
	<?php
	if (is_array($answeredRows['entries'])) {
		foreach ($answeredRows['entries'] as $ans) {
		// grabs data from each row 
		list($id, $q, $a, $ip, $dateAsked, $dateAnswered) = get($ans);?>
		<table class="qapost" border="0" width="400" align="center">
			<tr>
				<td class="td" colspan="2">
				<?php // display Questions?>
				<b>Kérdés:.</b> <b title="IP: <?php echo $ip?>"><?php echo convertLinks($q)?></b></td></tr>
			<tr>
				<td colspan="2">
				<?php // display Answers?>
				<b>Válasz:</b> <?php echo convertLinks(fixBrkForHTML($a))?></td></tr>
			<tr>
				<td align="right">
				<?php // date when asked and answered?>
					<small><b>kérdés:</b> <?php echo dateFormatAdv($dateAsked, $dtFormat)?> <b>válasz:</b> <?php echo dateFormatAdv($dateAnswered, $dtFormat)?></small></td></tr>
				</table><br /><br />
	<?php }
	} 
	// display 'lapok:' if contains more than one page of entries ?>
	<table class="qapost" border="0" width="400" align="center">
		<tr><td align="right"><?php printJumpToPage("$phpSelf?page=", $numPages, $pagenum); ?></td></tr>
	</table>
	<?php
}
?>
<center>
	<a href="http://luved.org" target="_blank"><strong class="betu">Powered by WakScripts</strong></a> <br>
<a href="http://hd.vilaga.hu" target="_blank"><strong class="betu">HUN by Adliz</strong></a>
</center>
