#!/usr/bin/perl

#use DBI;
use CGI qw/:standard :html3/;
#use Digest::MD5;

$|=1;

my $debug =1;

my $cgiquery = CGI::new();

my $boardtitle = 'NationBuilder User Interfarce Correctionator';
my $tags = "";

# has the user set the electorate code?
if ( $electorate = $cgiquery->param("electorate")) {

# make sure code is 3 chars
$electorate~=/\c\c\c/;
$cgiquery->delete('electorate');
print $cgiquery->redirect('');
}

# has the user selected "copy to clipboard"?

if ($clip = $cgiquery->param("clip"){

#build text string

$tags .= "score-".$pvg."-GE2026," if $pvg>0;
$tags .= "score-".$cvg."-".$electorate."-GE2026," if $cvg>0;

$tags .= "followup-".$electorate."-GE2026," if $followup;
$tags .= "will-volunteer-GE2026," if $volunteer;
$tags .= "will-billboardhost-GE2026," if $billboardhost;
$tags .= "will-doorknock-GE2026," if $doorknock;
$tags .= "will-phonebank-GE2026," if $phonebank;
$tags .= "will-bake-GE2026," if $bake;



print qq|$tags</br>| if $debug;

#copy to client's clipboard using javascript

print qq|
<script type="text/javascript">navigator.clipboard.writeText($tags);alert("Tags copied to clipboard");</script>

|;

# clear parameters that need clearing

}

my $stylesheet="base.css";
my $dtd2="-//W3C//DTD XHTML 1.0 Strict//EN";
my $dtd1="-//W3C//DTD HTML 4.01 Transitional//EN";
$cgiquery->default_dtd("$dtd2");
print $cgiquery->start_html( -title  => "$boardtitle",
 -style=>{'src'=>"$stylesheet"},
 -dtd    => 1);

print qq|<div id="header"><span class="headerTitle">$boardtitle</span></div>
|;

}

# show the set electorate form

print qq|<form id="electorate" name="electorate" action="index.cgi" method="POST">
<table><tr><td>Electorate Code:</td><td>
<text name="electorate" rows="15" cols="70" wrap="virtual"></text></td></tr>
<tr><td>
<input name="submit" type="submit" value="Set Code"></td></tr></table></form>
|;

# clear all CGI parameters
#$cgiquery->delete_all();

# show the main input form

print qq|<form id="input" name="input" action="index.cgi" method="POST">
<table><tr>
<td>Will they party vote Green?:</br>
<input type="radio" id="1" name="pvg" value="1">
<input type="radio" id="2" name="pvg" value="2">
<input type="radio" id="3" name="pvg" value="3">
<input type="radio" id="4" name="pvg" value="4">
<input type="radio" id="5" name="pvg" value="5">
</td>
</tr><tr>
<td>Will they candidate vote Green?:</br>
<input type="radio" id="1" name="cvg" value="1">
<input type="radio" id="2" name="cvg" value="2">
<input type="radio" id="3" name="cvg" value="3">
<input type="radio" id="4" name="cvg" value="4">
<input type="radio" id="5" name="cvg" value="5">
</td>
</tr><tr>
<td>Is follow-up needed?:</br>

<input type="checkbox" id="followup" name="Follow-up required" value="followup"></br>
</br>
<input type="checkbox" id="volunteer" name="Will volunteer" value="volunteer"></br>
<input type="checkbox" id="billboardhost" name="Will billboard host" value=""billboardhost></br>
<input type="checkbox" id="doorknock" name="Will doorknock" value="doorknock"></br>
<input type="checkbox" id="phonebank" name="Will phonebank" value="phonebank"></br>
<input type="checkbox" id="bake" name="Will bake" value="bake"></br>



<textarea name="contrib" rows="15" cols="70" wrap="virtual"></textarea></td></tr>
<tr><td>
<input name="submit" type="submit" value="Copy to Clipboard"></td></tr></table></form>
|;

#print qq|$user->{id} $user->{handle}|;
print qq|</body></html>|;
exit;

