<?php

/* Login Protect file */
include('loginprotect.php');

/* Config file */
include('config.php');

if($connectDatabase == TRUE){$action=TRUE;include('connect.php');}

$query="SELECT * FROM petitionlist WHERE  id = '".$_GET['id']."'" ;
$result=mysql_query($query);
$num=mysql_num_rows($result);
mysql_close();

$f1=mysql_result($result,$i,"owner");
$f2=mysql_result($result,$i,"title");

//determine rights
if($f1 !=$_SESSION['userName'])
{

  header("Location: login.php");exit();

}
include('header.php');
?>


<h1><?php echo $f2; ?></h1>



<?php

if($connectDatabase == TRUE){$action=TRUE;include('connect.php');}

$signatureQuery="SELECT * FROM signaturelist WHERE  petition = '".$_GET['id']."'" ;
$signatureResult=mysql_query($signatureQuery);
$signatureNum=mysql_num_rows($signatureResult);

mysql_close();
?>
<h1>number of petition signatures received:<?php echo $signatureNum; ?></h1>

<?php
if($signatureNum != 0)
{
?>
<h1>all signatures of the petition</h1>
<table >
<tr>
<th>name</th>

<th>from</th>
<th>signed on</th>
<th>email</th>
<th>phone</th>
<th>comment</th>
</tr>

<?php
$si=0;
while ($si < $signatureNum) {

$sf1=mysql_result($signatureResult,$si,"name");
$sf2=mysql_result($signatureResult,$si,"comment");
$sf3=mysql_result($signatureResult,$si,"region");
$sf4=mysql_result($signatureResult,$si,"timestamp");
$sf5=mysql_result($signatureResult,$si,"email");
$sf6=mysql_result($signatureResult,$si,"phone");

?>

<tr>
<td><?php echo $sf1; ?></td>

<td><?php echo $sf3; ?></td>
<td><?php echo $sf4; ?></td>
<td><?php echo $sf5; ?></td>
<td><?php echo $sf6; ?></td>
<td><?php echo $sf2; ?></td>
<?php
$si++;
} 
}
?>
<?php

/* Disconnect from database */
if($connectDatabase == TRUE){$action=FALSE;include('connect.php');}
?>
<?php
include('footer.php');
?>
