<?php
include('header.php');
echo $h;

$action = $_GET['action'];
if(!isset($action)) $action = "add";

IF ($action=="add"){
$sql = "SELECT * FROM opitions where id=1";
$result = mysql_query ($sql) or die ("Query failed");
$p_cats = mysql_fetch_array($result);
?>
<form name="vbform" method="post" action="poll_cp.php?action=default">
<table class='xtable' width="100%" id="AutoNumber1">
     <tr>
      <td width="100%" class='xtt' align="center"><?php echo $LANGAUGE_CP[379]; ?></td>
    </tr>
    <tr>
      <td width="100%" class='xtd' align="center">
<select size='1' name="idpool">
<?php
$sql = "SELECT id,question FROM pool";
$result = mysql_query ($sql) or die ("Query failed");
while ($p_s=mysql_fetch_array($result))
{
if($p_s['id'] == $p_cats['idpool'])
{
echo "<OPTION value='$p_s[id]' selected='selected'>$p_s[question]</OPTION>";
}else echo "<OPTION value='$p_s[id]'>$p_s[question]</OPTION>";
}
?>
</select> <input type="submit" value=" <?php echo $LANGAUGE_CP[33]; ?> " name="cmdAdd" />
</td></tr>
</table>
</form>
<form method="post" action="poll_cp.php?action=insert">
  <table class='xtable' width="100%" id="AutoN44umber1">
  <tr>
      <td width="100%" colspan="2" class='xtx' align="center"><?php echo $LANGAUGE_CP[380]; ?></td>
    </tr>
    <tr>
      <td width="20%" class='xtr'><?php echo $LANGAUGE_CP[381]; ?></td>
      <td width="80%" class='xtd'><input size="60" name="yourname" /></td>
    </tr>
    <tr>
      <td width="20%" class='xtr'><?php echo $LANGAUGE_CP[382]; ?></td>
      <td width="80%" class='xtd'><input size="60" name="question" /></td>
    </tr>
    <tr>
      <td width="20%" class='xtr'><?php echo $LANGAUGE_CP[383]; ?></td>
      <td width="80%" class='xtd'><input size="60" name="answer1" /></td>
    </tr>
    <tr>
      <td width="20%" class='xtr'><?php echo $LANGAUGE_CP[384]; ?></td>
      <td width="80%" class='xtd'><input size="60" name="answer2" /></td>
    </tr>
    <tr>
      <td width="20%" class='xtr'><?php echo $LANGAUGE_CP[385]; ?></td>
      <td width="80%" class='xtd'><input size="60" name="answer3" /></td>
    </tr>
    <tr>
      <td width="20%" class='xtr'><?php echo $LANGAUGE_CP[386]; ?></td>
      <td width="80%" class='xtd'><input size="60" name="answer4" /></td>
    </tr>
    <tr>
      <td width="20%" class='xtr'><?php echo $LANGAUGE_CP[387]; ?></td>
      <td width="80%" class='xtd'><input size="60" name="answer5" /></td>
    </tr>
    <tr>
      <td width="20%" class='xtr'><?php echo $LANGAUGE_CP[388]; ?></td>
      <td width="80%" class='xtd'><input size="60" name="answer6" /></td>
    </tr>
     <tr>
      <td width="100%" colspan="2" align="center" class='xtr'>
      <input type="submit" value=" <?php echo $LANGAUGE_CP[18]; ?> " name="cmdAdd" /></td>
    </tr>
  </table>
</form>
<?php

$queryx = mysql_query("SELECT * FROM pool order by id desc");
$xx = mysql_num_rows($queryx);
if($xx == 0){
echo "";
}else{

echo "<table class='xtable' width='100%' id='Auto4Number15'>
  <tr>
<td width='100%' colspan='3' class='xtt' align='center'>".$LANGAUGE_CP[97]."</td>
</tr>
  <tr>
      <td width='86%' align='center' class='xtr'>".$LANGAUGE_CP[389]."</td>
      <td width='7%' align='center' class='xtr'>".$LANGAUGE_CP[26]."</td>
      <td width='7%' align='center' class='xtr'>".$LANGAUGE_CP[27]."</td>
    </tr>";
while($s = mysql_fetch_array($queryx))
{
$d = date("j/n/Y",$s['date']);

$s['question'] = stripslashes($s['question']);
$s['question'] = htmlspecialchars($s['question']);

$s['answer1'] = stripslashes($s['answer1']);
$s['answer1'] = htmlspecialchars($s['answer1']);

$s['answer2'] = stripslashes($s['answer2']);
$s['answer2'] = htmlspecialchars($s['answer2']);

$s['answer3'] = stripslashes($s['answer3']);
$s['answer3'] = htmlspecialchars($s['answer3']);

$s['answer4'] = stripslashes($s['answer4']);
$s['answer4'] = htmlspecialchars($s['answer4']);

$s['answer5'] = stripslashes($s['answer5']);
$s['answer5'] = htmlspecialchars($s['answer5']);

$s['answer6'] = stripslashes($s['answer6']);
$s['answer6'] = htmlspecialchars($s['answer6']);

$all_votes = "<table class='xtablex' width='100%' id='AutoNumber15'>
    <tr>
      <td width='100%' colspan='6' align='center' class='xtr'>".$s['question']."</td>
    </tr>
    <tr>
      <td width='16%' align='center' class='xtd'>".$s['answer1']."</td>
      <td width='17%' align='center' class='xtd'>".$s['answer2']."</td>
      <td width='17%' align='center' class='xtd'>".$s['answer3']."</td>
      <td width='17%' align='center' class='xtd'>".$s['answer4']."</td>
      <td width='17%' align='center' class='xtd'>".$s['answer5']."</td>
      <td width='17%' align='center' class='xtd'>".$s['answer6']."</td>
    </tr>
    <tr>
      <td width='16%' align='center' class='xtd'>$s[vote1]</td>
      <td width='17%' align='center' class='xtd'>$s[vote2]</td>
      <td width='17%' align='center' class='xtd'>$s[vote3]</td>
      <td width='17%' align='center' class='xtd'>$s[vote4]</td>
      <td width='17%' align='center' class='xtd'>$s[vote5]</td>
      <td width='17%' align='center' class='xtd'>$s[vote6]</td>
    </tr>
   <tr>
    <td width='100%' colspan='6' class='xtr' align='center'>".$LANGAUGE_CP[57]." $d</td>
  </tr>
  </table>";

echo "<tr>
      <td width='86%' class='xtd'>$all_votes</td>
      <td width='7%' align='center' class='xtd'><a href='poll_cp.php?action=edit&id=$s[id]'><img border='0' src='images/edit.gif' alt='".$s['question']."' /></a></td>
      <td width='7%' align='center' class='xtd'><a href='poll_cp.php?action=delete&id=$s[id]'><img border='0' src='images/delete.gif' alt='".$s['question']."' /></a></td>
    </tr>";
}
echo "</table>";
}

}ELSEIF ($action=="default"){
$idpool = $_POST['idpool'];
$query1 =  mysql_query("UPDATE opitions SET idpool='$idpool' where id='1'");
echo $LANGAUGE_CP[34];
echo "<META HTTP-EQUIV='Refresh' CONTENT='1;URL=poll_cp.php' />";

}ELSEIF ($action=="insert"){

$d = time();

$yourname = addslashes($_POST['yourname']);
$question = addslashes($_POST['question']);
$answer1  = addslashes($_POST['answer1']);
$answer2  = addslashes($_POST['answer2']);
$answer3  = addslashes($_POST['answer3']);
$answer4  = addslashes($_POST['answer4']);
$answer5  = addslashes($_POST['answer5']);
$answer6  = addslashes($_POST['answer6']);


if ($yourname==""){
echo $LANGAUGE_CP[390];
}elseif ($question == ""){
echo $LANGAUGE_CP[391];
}elseif ($answer1 == "" && $answer2 == "" && $answer3 == "" && $answer4 == "" && $answer5 == "" && $answer6 == ""){
echo $LANGAUGE_CP[392];
}else{
$query="INSERT INTO pool (yourname,question,answer1,answer2,answer3,answer4,answer5,answer6,date) VALUES ('$yourname','$question','$answer1','$answer2','$answer3','$answer4','$answer5','$answer6','$d')";
$result = mysql_query ($query) or die ("error");
print $LANGAUGE_CP[21];
echo "<META HTTP-EQUIV='refresh' CONTENT='1; URL=poll_cp.php?action=add' />";
}


}ELSEIF ($action=="edit"){
$id = intval($_GET['id']);
$query = mysql_query("SELECT * FROM pool where id=$id");
$p_cats = mysql_fetch_array($query);

$question = "$p_cats[question]";
$question = htmlspecialchars($question);
$question = stripslashes($question);

$yourname = "$p_cats[yourname]";
$yourname = htmlspecialchars($yourname);
$yourname = stripslashes($yourname);

$answer1 = "$p_cats[answer1]";
$answer1 = htmlspecialchars($answer1);
$answer1 = stripslashes($answer1);

$answer2 = "$p_cats[answer2]";
$answer2 = htmlspecialchars($answer2);
$answer2 = stripslashes($answer2);

$answer3 = "$p_cats[answer3]";
$answer3 = htmlspecialchars($answer3);
$answer3 = stripslashes($answer3);

$answer4 = "$p_cats[answer4]";
$answer4 = htmlspecialchars($answer4);
$answer4 = stripslashes($answer4);

$answer5 = "$p_cats[answer5]";
$answer5 = htmlspecialchars($answer5);
$answer5 = stripslashes($answer5);

$answer6 = "$p_cats[answer6]";
$answer6 = htmlspecialchars($answer6);
$answer6 = stripslashes($answer6);


echo "<form method='POST' action='poll_cp.php?action=editok'>
<input type='hidden' name='id' value='$p_cats[id]' />

<table class='xtable' width='100%' id='AutoNumber15'>

<tr>
<td width='100%' colspan='2' class='xtx' align='center'>".$LANGAUGE_CP[32]."</td>
</tr>

<tr>
<td width='30%' class='xtr'>".$LANGAUGE_CP[381]."</td>
<td width='70%' class='xtd'><input name='yourname' size='60' value='$yourname' /></td>
</tr>

<tr>
<td width='30%' class='xtr'>".$LANGAUGE_CP[382]."</td>
<td width='70%' class='xtd'><input name='question' size='60' value='$question' /></td>
</tr>

<tr>
<td width='30%' class='xtr'>".$LANGAUGE_CP[383]."</td>
<td width='70%' class='xtd'><input name='answer1' size='60' value='$answer1' /></td>
</tr>

<tr>
<td width='30%' class='xtr'>".$LANGAUGE_CP[384]."</td>
<td width='70%' class='xtd'><input name='answer2' size='60' value='$answer2' /></td>
</tr>

<tr>
<td width='30%' class='xtr'>".$LANGAUGE_CP[385]."</td>
<td width='70%' class='xtd'><input name='answer3' size='60' value='$answer3' /></td>
</tr>

<tr>
<td width='30%' class='xtr'>".$LANGAUGE_CP[386]."</td>
<td width='70%' class='xtd'><input name='answer4' size='60' value='$answer4' /></td>
</tr>

<tr>
<td width='30%' class='xtr'>".$LANGAUGE_CP[387]."</td>
<td width='70%' class='xtd'><input name='answer5' size='60' value='$answer5' /></td>
</tr>

<tr>
<td width='30%' class='xtr'>".$LANGAUGE_CP[389]."</td>
<td width='70%' class='xtd'><input name='answer6' size='60' value='$answer6' /></td>
</tr>

<tr>
<td width='100%' colspan='2' align='center' class='xtr'><input type='submit' value=' ".$LANGAUGE_CP[33]." ' name='B1' /></td>
</tr>

</table>
</form>";

}ELSEIF ($action=="editok"){

$id        = $_POST['id'];
$yourname  = addslashes($_POST['yourname']);
$question  = addslashes($_POST['question']);
$answer1   = addslashes($_POST['answer1']);
$answer2   = addslashes($_POST['answer2']);
$answer3   = addslashes($_POST['answer3']);
$answer4   = addslashes($_POST['answer4']);
$answer5   = addslashes($_POST['answer5']);
$answer6   = addslashes($_POST['answer6']);


if ($yourname==""){
echo $LANGAUGE_CP[390];
}elseif ($question == ""){
echo $LANGAUGE_CP[391];
}elseif ($answer1 == "" && $answer2 == "" && $answer3 == "" && $answer4 == "" && $answer5 == "" && $answer6 == ""){
echo $LANGAUGE_CP[392];
}else{
$query =  mysql_query("UPDATE pool SET yourname='$yourname', question='$question', answer1='$answer1', answer2='$answer2', answer3='$answer3', answer4='$answer4', answer5='$answer5', answer6='$answer6' where id='$id'");
echo $LANGAUGE_CP[34];
echo "<META HTTP-EQUIV='Refresh' CONTENT='1;URL=poll_cp.php?action=add' />";
}

}ELSEIF ($action=="delete"){
$id = intval($_GET['id']);
$query1 =  mysql_query("DELETE FROM pool WHERE id = $id");
echo $LANGAUGE_CP[35];
echo "<META HTTP-EQUIV='Refresh' CONTENT='1;URL=poll_cp.php?action=add' />";
}
echo $f;
?>