<?php



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

/* Connect to database & query */
if(isset($_POST['submit']) && $_POST['name']!= "" && $_POST['agreement'] == "yes"){

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

$insertSQL = "INSERT INTO signaturelist (petition, name, phone, email, comment, region) VALUES ('".$_GET['id']."','".$_POST['name']."', '".$_POST['phone']."', '".$_POST['email']."', '".$_POST['comment']."','".$_POST['region']."')";
$insertresult = mysql_query($insertSQL);

mysql_close();
}
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();

?>


<?php

$f1=mysql_result($result,$i,"id");
$f2=htmlsymbolreplace(mysql_result($result,$i,"title"));
$f3=mysql_result($result,$i,"description");
$f4=htmlsymbolreplace(mysql_result($result,$i,"endtext"));
$f5=mysql_result($result,$i,"setting");
$f6=mysql_result($result,$i,"timestamp");

//determine display mode
if($f5="active")
{
if(isset($_POST['submit']) && $_POST['name']!= ""&& $_POST['agreement'] == "yes"){
echo "<h2>";
echo $f4;
echo "</h2>";
}
?>
<html>
<head>
<title><?echo $f2;?> - Petitions.GoodEasy.info (Free Online Petition)</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<LINK href="style.css" rel="stylesheet" type="text/css">
	<script type="text/javascript" src="/fckeditor/fckeditor.js"></script> 
	<script type="text/javascript"> 
 
window.onload = function()
{
	// Automatically calculates the editor base path based on the _samples directory.
	// This is usefull only for these samples. A real application should use something like this:
	// oFCKeditor.BasePath = '/include/class/fckeditor/' ;	// '/fckeditor/' is the default value.
	var sBasePath = document.location.href.substring(0,document.location.href.lastIndexOf('_samples')) ;
 
	var oFCKeditor = new FCKeditor( 'comment' ) ;
	oFCKeditor.BasePath	= '/fckeditor/' ;
       oFCKeditor.Height=300;
       oFCKeditor.Width=500;
	oFCKeditor.ReplaceTextarea() ;

}
 
	</script> 
</head>
<body>

<!-- AddThis Button BEGIN -->
<div class="addthis_toolbox addthis_default_style ">
<a href="http://www.addthis.com/bookmark.php?v=250&amp;username=xa-4cfe0d5b239f18be" class="addthis_button_compact">Share</a>
<span class="addthis_separator">|</span>
<a class="addthis_button_preferred_1"></a>
<a class="addthis_button_preferred_2"></a>
<a class="addthis_button_preferred_3"></a>
<a class="addthis_button_preferred_4"></a>
</div>
<script type="text/javascript" src="http://s7.addthis.com/js/250/addthis_widget.js#username=xa-4cfe0d5b239f18be"></script>
<!-- AddThis Button END -->
<br />
petition id <?php echo $f1; ?> | created on <?php echo $f6; ?>| <a href="/register.php">create your own petition</a> <br>
URL of this petition: http://petitions.goodeasy.info<?php echo $_SERVER['REQUEST_URI'];?> 
<h1><?php echo $f2; ?></h1>
<hr>
<?php echo $f3; ?><br />
<hr>


<?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();
?>

<table>

<tr>
<td>
number of petition signatures received: <h3><?php echo $signatureNum; ?></h3>
</td>
<td>
<h1>sign the petition</h1>
<form method=post  >
name<input name=name value=" "> <br />
comment<br /><textarea name=comment></textarea> <br />
email<input name=email value=" "> <br />
phone<input name=phone value=" "> <br />
region<input name=region value=" "> <br />
<input type=hidden name=petition value="<?php echo $_GET['id'];?>">

-name is compulsory <br />
-your email and phone number will not be shown to the public <br />
-only the first few letters of your name will be shown to the public <br />
-the organiser of the petition can see your name, email or phone <br />
<input type="checkbox" name="agreement" value="yes" checked> I agree to the <a target="_blank" href="/agreement.php">terms of service</a>
<input type=submit name=submit value="Sign the Petition">
</form>
</td>
</tr>
</table>
<?php
if($signatureNum != 0)
{
?>
<h1>all signatures of the petition</h1>
<table >
<tr>
<th>name</th>

<th>from</th>
<th>signed on</th>
</tr>

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

$sf1=left(htmlsymbolreplace(mysql_result($signatureResult,$si,"name")),4)."...";
$sf2=mysql_result($signatureResult,$si,"comment");
$sf3=mysql_result($signatureResult,$si,"region");
$sf4=mysql_result($signatureResult,$si,"timestamp");



?>

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

<td><?php echo $sf3; ?></td>
<td><?php echo $sf4; ?></td>
</tr>
<tr>
<td colspan=3>comments<br />
<?php echo $sf2; ?>
<hr>
</td>
</tr>
<?php
$si++;
} 
}
?>
<?php

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