Location: PHPKode > projects > PHP Simple FAQ > phpsimplefaq1.1beta/phpsimplefaq/includes/faq_answers.inc.php
<? 

// PHP Simple FAQ Answer page v1.0

if (($add == "answer") && ($message != "")) 
	
	{
		if ($php_simplefaq_name) 
		
			{
				$answer_user = "$php_simplefaq_name";
			} else {
				$answer_user = "$posted_email";
			}
			 
		if (!$answer_user)
			
			{
				$answer_user = "$anon_user";
			}
				
		$check_answer = "SELECT answer
						 FROM $database_name.$answer_table
						 WHERE answer = '$message' AND q_id = '$q_id'";
		$check_result = mysql_query($check_answer,$connection);
		$check_num1 = mysql_numrows($check_result);
		
		if ($check_num1 == 0) 
		
			{
				$new_question = "INSERT INTO $database_name.$answer_table 
								 (answer, answer_date, q_id, answer_user)
								 VALUES 
								 ('$message', '$date', '$q_id', '$answer_user')";
				mysql_query($new_question,$connection);
				$newest_answer = "$message";
				
			}
	}

$get_cat = "SELECT *
			FROM $database_name.$category_table
			WHERE cat_id='$category'";
$cat_result = mysql_query($get_cat,$connection);
$myrow1 = mysql_fetch_array($cat_result);
$this_category = $myrow1["category"];
$cat_id = $myrow1["cat_id"];
$faq_id = $myrow1["faq_id"];
$get_faq = "SELECT *
			FROM $database_name.$faq_table
			WHERE faq_id='$faq_id'";
$faq_result = mysql_query($get_faq,$connection);
$myrow2 = mysql_fetch_array($faq_result);
$faq_title = $myrow2["faq_title"];

?>
<table border="0" width="100%" cellspacing="2" cellpadding="2">
	<tr valign=top align=left>
		<td><? echo "<font face=\"$font_face\" size=\"$font_size\" class=\"$font_class\">" ?>
		<center><b><? echo "<a class=\"psf\" href=\"index.php\">$main_title</a> > <a class=\"psf\" href=\"index.php?action=qa&faq=$faq_id\">$faq_title</a> > <a class=\"psf\" href=\"index.php?action=qa&category=$cat_id\">$this_category</a>"; ?></b><br>
		<? if (($add == "answer") && ($message == "")) { echo "<font color=\"red\">$blank_answer_lang</font>"; } ?>
		<? if ($check_num1 != 0) { echo "<font color=\"red\">$duplicate_answer_lang</font>"; } ?></center></font></td>
	</tr>
</table>
<table border="0" width="90%" cellspacing="2" cellpadding="2">
	<tr>
	   <td align=right><? echo "<font class=\"G10\"><a class=\"psf\" href=\"index.php?action=qa&faq=$faq_id\">$view_faq_lang</a></font></td>"; ?>
	</tr>
</table>
	
	<?
	
	if (!$add)
		{
			$been_seen_sql = "UPDATE $database_name.$question_table
							  SET been_seen = been_seen + 1
							  WHERE question_id='$q_id'";
			mysql_query($been_seen_sql, $connection);
		}
	
	$get_question = "SELECT *
					 FROM $database_name.$question_table
					 WHERE question_id='$q_id'";
	$quest_result = mysql_query($get_question,$connection);
	$myrow7 = mysql_fetch_array($quest_result);
	$question = $myrow7["question"];				 
	$posted_by = $myrow7["posted_by"];
	$been_seen = $myrow7["been_seen"];
	$posted_date = $myrow7["posted_date"];
	if ($been_seen == 1)
		
		{	
			$viewed = "$viewed_lang $been_seen $time_lang";
		} else {
			$viewed = "$viewed_lang $been_seen $times_lang";
		}
		 
	?>
	<center>
	<table width="90%" cellpadding="4" cellspacing="2" bgcolor="#333366">
		<tr>
			<td align="LEFT" valign="TOP" bgcolor="#3366CC"><b><? echo "<font face=\"$font_face\" size=\"$font_size\" class=\"$font_class\" color=\"#FFFFFF\">$question<BR></B><I>$asked_by_lang $posted_by $on_lang $posted_date</I>"; ?></font></TD>
			<td align="LEFT" valign="TOP" bgcolor="#3366CC" width="170" nowrap><? echo "<font face=\"$font_face\" size=\"$font_size\" class=\"$font_class\" color=\"#FFFFFF\"><b>$answer_from_lang</b><br>"; ?></font></td>
		</tr>	
		
		<? 
				
				$get_a = "SELECT * 
						  FROM $database_name.$answer_table 
						  WHERE q_id='$q_id'";
				$result = mysql_query($get_a, $connection);
				while ($myrow3 = mysql_fetch_array($result)) 
				
					{
						$answer = $myrow3["answer"];
						$q_id = $myrow3["q_id"];
						$rating = $myrow3["rating"];
						$answer_user = $myrow3["answer_user"];
					
		?>
		
	<tr>
		<td align="LEFT" valign="TOP" bgcolor="#DDDDDD"><? echo "<font face=\"$font_face\" size=\"$font_size\" class=\"$font_class\">$answer"; ?></font></td>
		<td align="LEFT" valign="TOP" bgcolor="#DDDDDD" width="170"><? echo "<font face=\"$font_face\" size=\"$font_size\" class=\"$font_class\">$answer_user"; ?></font></td>
	</tr>

				 <? } ?>

</table>
<table border="0" width="90%" cellspacing="2" cellpadding="2">
	<tr>
	   <td align=left><? echo "<font class=\"G10\">$viewed</font></td>"; ?>
	   <td align=right><? echo "<font class=\"G10\"><a class=\"psf\" href=\"index.php?action=qa&faq=$faq_id\">$view_faq_lang</a></font></td>"; ?>
	</tr>
</table>
<br>
<br><br>
<center>
<FORM NAME="form1" METHOD="post" ACTION="index.php?action=answers&category=<? echo "$category&q_id=$q_id&add=answer\">"; ?>
<table width="90%" cellpadding="4" cellspacing="2" bgcolor="#FFFFFF">	
	<tr>
		<td valign="TOP" align="LEFT" bgcolor="#FFFFFF">
		<? echo "<font face=\"$font_face\" size=\"$font_size\" class=\"$font_class\"><b>$add_answer2_lang:</b></font></td>
	</tr>" ?>
	
	<tr>
		<td valign="TOP" align="LEFT" bgcolor="#FFFFFF"><textarea rows="6" name="message" cols="65"></textarea></td>
	</tr>
	<? 
	
	if (!$php_simplefaq_name) 
	
		{ 
	
	?>
		<tr>
			<td valign="TOP" align="LEFT" bgcolor="#FFFFFF"><INPUT TYPE="text" NAME="posted_email" CLASS="add_style">
			<? echo "<font face=\"$font_face\" size=\"$font_size\" class=\"$font_class\">&nbsp;$name_nick_lang</td>"; ?>
		</tr>
	<? 
	
		} 
	
	?>
	<tr>
		<td valign="TOP" align="LEFT" bgcolor="#FFFFFF"><input type="submit" name="Submit" value="<? echo "$submit_button_lang"; ?>"></td>
	</tr>
</table>
</form>
</center>

<? 				
	if (($admin_email == "Yes") && ($add == "answer") && ($message != ""))
	
		{
			// Email the admin for new answer
			$email_sql = "SELECT user_email
						  FROM $database_name.$user_table
						  WHERE user_admin = 'Yes'";
			$email_result = mysql_query($email_sql,$connection);				
			
			$get_question1 = "SELECT question
							  FROM $database_name.$question_table
							  WHERE question_id='$q_id'";
			$quest_result1 = mysql_query($get_question1,$connection);
			$myrow = mysql_fetch_array($quest_result1);
			$the_question = $myrow["question"];
			while ($my_email = mysql_fetch_array($email_result))
			
				{
					$email = $my_email["user_email"];
					$message = "<a href=\"$absolute_url/index.php?action=answers&category=$cat_id&q_id=$q_id\">$question_title_lang</a>: " . stripslashes($the_question) . "<br>\n";
					$message .= "$answer_lang: " . stripslashes($newest_answer) . "<br>\n";
					$message .= "<i>$posted_by_lang $answer_user</i><br><br>\n";
					$message .= "<a href=\"$absolute_url\">$main_title</a><br>\n";
					$message .= "<font size=\"2\" color=\"#666666\"><a href=\"http://sourceforge.net/projects/phpsimplefaq/\">PHP Simple FAQ</a> $phpsf_version</font><br>\n";
					$subject = "$email_answer_lang\n";
					$mailheaders = "From: $main_title <$email>\n";
					$mailheaders .= "Reply-To: $email\n";
					$mailheaders .= "Content-type: text/html; charset=iso-8859-1\r\n";
					Mail($email, $subject, $message, $mailheaders);
				}
		}
					
?>
Return current item: PHP Simple FAQ