<?

  include_once '../../config.inc.php';
  if (!include '../autorization.php')
  {
    echo 'Access denied!';
    exit ();
  }

  if (!($result_proper = mysql_query ('select * from properties')))
  {
    exit ('<b>Error:</b>' . mysql_error ());
    ;
  }

  $proper = mysql_fetch_array ($result_proper);
  include '../lang/' . $proper['admin_language'];
  echo '
<HTML><BODY BGCOLOR="white"><LINK HREF="../style.css" REL="stylesheet" TYPE="text/css"><TABLE WIDTH="600" BORDER=0 CELLSPACING=0 CELLPADDING=1><TR><TD style="background-color:#505090;"><TABLE WIDTH="100%" BORDER=0 CELLSPACING=0 CELLPADDING=5 BGCOLOR="#EFEFF8">
<TR><TD VALIGN=top BGCOLOR="#BFBFDF" STYLE="border-bottom: 1px solid #505090;"><FONT COLOR="navy"><B>';
  echo $admin_Create_New_Poll;
  echo '</B></FONT></TD></TR><TR><TD VALIGN=top>


';
  if (0 < $_POST['a_num'])
  {
    if (!($result = mysql_query ('' . 'SELECT * FROM poll WHERE question=\'' . $_POST['question'] . '\'')))
    {
      exit ('Invalid query3');
      ;
    }

    $row = mysql_fetch_array ($result);
    if ($row)
    {
      echo '<S';
      echo 'CRIPT LANGUAGE="JavaScript" TYPE="text/javascript">alert("Poll \\"';
      echo $_POST['question'];
      echo '\\" already exist!")</SCRIPT>';
    }
    else
    {
      echo '<FORM ACTION="add.php" METHOD=post>
		<textarea cols="60" rows="3" name="question">';
      echo $_POST['question'];
      echo '</textarea><br><br>
	
	';
      for ($i = 0; $i < $_POST['a_num']; ++$i)
      {
        echo $admin_answer;
        echo ' # ';
        echo $i + 1;
        echo ': <INPUT TYPE=text NAME="answer';
        echo $i;
        echo '"><BR>';
      }

      echo '<BR>
	<INPUT TYPE=hidden NAME="num" VALUE="';
      echo $_POST['a_num'];
      echo '">
	<INPUT TYPE=submit NAME="next1" VALUE="';
      echo $admin_Create_New_Poll;
      echo '">
	</FORM>
';
    }
  }
  else
  {
    if ($_POST['next1'])
    {
      echo '<BR><B>';
      echo $_POST['question'] = stripslashes ($_POST['question']);
      echo '</B><BR><BR>';
      for ($i = 0; $i < $_POST['num']; ++$i)
      {
        $answ = $answ . $_POST['answer' . $i] . '
';
        $res = $res . '0
';
        echo $i + 1 . '. ' . $_POST['answer' . $i] . '<BR>';
      }

      $_POST['question'] = trim ($_POST['question']);
      $answ = trim ($answ);
      if (!(mysql_query ('' . 'INSERT INTO poll VALUES(\'\',\'' . $_POST['question'] . '\',\'' . $answ . '\')')))
      {
        exit ('Invalid query3');
        ;
      }

      if (!($result = mysql_query ('' . 'SELECT * FROM poll WHERE question=\'' . $_POST['question'] . '\'')))
      {
        exit ('Invalid query3');
        ;
      }

      $row = mysql_fetch_array ($result);
      if (!(mysql_query ('' . 'INSERT INTO poll_result VALUES(\'' . $row['id'] . '\',\'' . $res . '\')')))
      {
        exit ('Invalid query3');
        ;
      }

      echo '<BR><FONT COLOR="#000080">';
      echo $admin_poll_success;
      echo '</FONT><BR>';
    }
    else
    {
      echo '<FORM ACTION="add.php" METHOD=post>
';
      echo $admin_question;
      echo ': <textarea cols="60" rows="3" name="question"></textarea><BR>
';
      echo $admin_answer;
      echo ': <INPUT TYPE=text NAME="a_num" SIZE=8><BR><BR>
<INPUT TYPE=submit NAME="next" VALUE="Next ->">
</FORM>
';
    }
  }

  echo '

</TD></TR></TABLE></TD></TR></TABLE></BODY></HTML>';
?>
