﻿<?php
if(!isset($_POST['action']))
{
echo "<div class=\"form\">\n";
echo "<form method=\"post\" action=\"admin.php?nocache=$nocache&amp;ver=html&amp;".SID."&amp;pass=$pass&amp;mod=addquestion\">\n";
echo "Question<br/>\n";
echo "<input type=\"text\" name=\"question\" maxlength=\"50\"/><br/>\n";
echo "Translitirovat<input type=\"checkbox\" name=\"tq\" value=\"true\"/><br/>\n";
echo "Answer:<br/>\n";
echo "<input type=\"text\" name=\"answer\" maxlength=\"50\"/><br/>\n";
echo "Translitirovat: <input type=\"checkbox\" name=\"ta\" value=\"true\"/><br/>\n";
echo "<input type=\"hidden\" name=\"action\" value=\"add\"/>";
echo "<input type=\"submit\" value=\"Add\"/></form></div><br/>\n";
}
else
{
$question = htmlspecialchars(mysql_escape_string(trim($_POST['question'])));
$question = str_replace('$', '$$', $question);
$answer = htmlspecialchars(mysql_escape_string(trim($_POST['answer'])));
$answer = str_replace('$', '$$', $answer);
$tq = $_POST['tq'];
$ta = $_POST['ta'];

if($tq == "true")
{
$question = str_replace($lat, $rus, $question);
}

if($ta == "true")
{
$answer = str_replace($lat, $rus, $answer);
}

if(empty($question))
{
echo "You did not enter the question<br/>\n";
break;
}

if(empty($answer))
{
echo "You did not enter the Answer<br/>\n";
break;
}

$q = mysql_query("SELECT `id` FROM `chat_questions` WHERE `question` = '".$question."' AND `answer` = '".$answer."';");

if(mysql_num_rows($q) != 0)
{
echo "Such a question already in the database.<br/>\n";
break;
}

$translit = strtolower(str_replace($rus, $lat, $answer));

mysql_query("INSERT INTO `chat_questions` VALUES(0, '".$question."', '".$answer."', '".$translit."');");

$q = mysql_query("SELECT COUNT(*) FROM `chat_questions`;");
$questions = mysql_result($q, 0);

echo "The question has been added!<br/>\n";
echo "In the base $questions questions.<br/>\n";
}
?>