<%doc>$Id: phone.mhtml,v 1.52 2004/02/08 20:50:20 anoncvs Exp $</%doc>
<%args>
$data
@people
$user
$err => ''
$state
$volunteerState => ''
$format => 'html'
</%args>

<%perl>
my $formAction = "/eblocks/index.mhtml";
</%perl>

%if (!$people[0]) {
 Sorry, I couldn't find any voters in that city and state. Most likely they've all been assigned.
%} else {
%my $inCallTime = 1;
%if (!$data->inStateCallTime($state)) {
%$inCallTime = 0;
%my $tryAt = $data->getOffsetPhoneHour($state, undef, 'start');
 <h1>Please try again later</h1>
 Sorry, but right now it's too early or too late to call people in <%$data->getStateData($state)->{name}%>.
 Please try again later at <% $tryAt %>:00 AM Eastern time. In the meantime, why not <a href="/eblock/index.mhtml?mode=mail">write some letters?</a> <p>Your block is still available in case you've already made these calls and just want to mark them complete.
<hr>
%}

<%perl>
my $firstState = $people[0]->mstate();
</%perl>

<h1>Your Phone eBlock</h1>

<%perl>
my $timedOut = 0;
if ($people[0]->userExceededTimeout($user, 'call')) {
 $timedOut = 1;
 if ($err) {
  $err .= '<br />';
 }
}
</%perl>

%if($timedOut) {
%my $timeout = $data->getConfVar('eblocks_call_timeout') || 60;
%my $limit = $data->getConfVar('eblocks_call_timeout_limit') || 10;

 <font color="red">Please note: your account is limited to completing <%$limit%> phone calls every <%$timeout%> minutes.<p>If you need to be able to mark voters complete more quickly, please send mail to <a href="mailto:accounts@forclark.com">accounts@forclark.com</a></font>.
%}

%if ($err) {
 <p><b>Error:</b> <font color="red"><%$err%></font></p>
%}

<p><b>Sending letters:</b> If you want to send letters instead of
making phone calls, <a href="/eblock/index.mhtml?mode=mail">click
here</a>.

%if ($state eq 'NH') {
<p><b>Quick instructions:</b> Click a voter's phone number to bring up
a new window containing a phone script for that voter. Call the voter
and talk to them, using the script as a guide.

<p>Once the phone call is complete, click the "Finish call"
button. The phone script window will close and the voter will be
removed from your block. Once you complete your block, you'll get
another one to work on.</p>

%} else {
<p><b>Quick instructions:</b> Click a voter's phone number to bring up
a new window containing a phone script for that voter. Call the voter
and go through the script, typing in any information they provide into
the fields on the script.

<p>Once the phone call is complete, fill out the section "After the
Call" and click the "Finish call" button. The phone script window will
close and the voter will be removed from your block. Once you complete
your block, you'll get another one to work on.</p>
%}
<p><a href="/eblocks/resources/phone/">Phone calling tips</a> | <a
href="/eblocks/resources/phone/issues.mhtml">Quick issues
guide</a></p>

<hr>
%#Display in CSV format, if that's what they requested.
%if ($user->hasPermission('eblocks_unlimited') && $format eq 'csv') {
<pre>
SALUTATION,FIRST,MIDDLE,LAST,JR,PHONE,CITY,STATE,GENDER,PARTY,VOTERID
%foreach my $p (@people) {
<% $p->prefix() %>,<% $p->firstName() %>,<% $p->middleName() %>,<% $p->lastName() %>,<% $p->suffix() %>,<% $p->phoneNumber() %>,<% $p->city() %>,<% $p->mstate() %>,<% $p->genderName() %>,<% $p->partyName() %>,<%$p->statevoterkey()%>
%}
</pre>
%if ($data->userCanCompleteInBulk($user, 'call')) {
 <form name="call-all" action="<%$formAction%>" method="post">
 <input type="hidden" name="action" value="setall">
%$m->comp('mantainState.mhtml', mode => 'call', format => $format, state => $state, volunteerState => $volunteerState);
 <input type="submit" name="setall" value="Mark this block as Complete">
</form>
%}
%} else {
<table width="100%">
<tr><th></th>
<!-- <th>DEBUG: VoterKey</th> -->
<th>Voter name</th><th>Phone number</th><th>City/State</th><th>Gender</th><th>Party</th><th>eBlock #<th></th></tr>
% foreach my $p (@people) {
<form name="phone-<% $p->voterkey() %>" action="<%$formAction%>" method="post">
%$m->comp('mantainState.mhtml', mode => 'call', format => $format, state => $state, volunteerState => $volunteerState);
<input type="hidden" name="action" value="set">
<tr>
 <td valign="top"><% $counter %>. <!--Score <% $p->phone_score() %>--></td>
 <!-- <td valign="top"><% $p->voterkey() %></td> -->
 <td valign="top"><% $p->prefix() %> <% $p->firstName() %> <% $p->middleName() %> <% $p->lastName() %> <% $p->suffix() %></td>
 <td valign="top">
%my $url = "/eblocks/resources/call_script.mhtml?voterkey=" . $p->voterkey() . '&nav=0&' . $data->queryString('call', $state, $volunteerState, $format);
%if (!$timedOut) {
<a href="<%$url%>" onclick="window.open('<%$url%>','_call_log','width=550,height=490,scrollbars=yes,toolbar=no,left=80,top=50,resizable=yes'); return false;">
%}
%if (($inCallTime && $data->inStateCallTime($state, $p->phone())) || $user->hasPermission("eblocks_admin"))  {
 <% $p->phoneNumber() %>
%if (!$timedOut) {
</a>
%}
%} else {
[Outside of call time]
%}
 <td valign="top"><% $p->city() %>, <% $p->mstate() %></td>
 <td valign="top"><% $p->genderName() %></td>
 <td valign="top"><% $p->partyName() %></td>
 <td valign="top"><% $p->statevoterkey() %></td>
%if ($format eq 'html') {
%$url .= "#after";
 <td valign="top">
%if (!$timedOut) {
<a href="<%$url%>" onclick="window.open('<%$url%>','_call_log','width=550,height=590,scrollbars=yes,toolbar=no,left=80,top=80,resizable=yes'); return false;">Complete this call</a>
%}
</td>
%}
</tr>
</tr>
</form>
% $counter++;
% }
% if ($data->userCanCompleteInBulk($user, 'call') && $counter > 2) {
 <tr><td colspan="7"></td><td><form name="call-all" action="<%$formAction%>" method="post">
 <input type="hidden" name="action" value="setall">
% $m->comp('mantainState.mhtml', mode => 'call', format => $format, state => $state, volunteerState => $volunteerState);
 <input type="submit" name="setall" value="Mark all <%$counter-1%> as Complete"></form></td></>

%}
</table>

<p>This block is reserved for you until <%$data->expiryTime($user,
'call')%>. If you don't mark these voters complete by then, they'll
be returned to the pool and you'll get another block.
%}
%}
%if ($user->hasPermission('eblocks_unlimited')) {
  <p><font size="-1">
%if ($format eq 'html') {
<a href="/eblocks/index.mhtml?<%$data->queryString('call', $state, $volunteerState, 'csv')%>">Show your eBlock in comma-separated value form</a> (for input into Excel)
%} else {
<a href="/eblocks/index.mhtml?<%$data->queryString('call', $state, $volunteerState, 'html')%>">Show your eBlock as HTML</a>
%}
%}
<%init>
our $counter = 1;
</%init>
