Ejemplo n.º 1
0
    //Check if the postcode is editable
    $fyr_postcode_editable = is_postcode_editable($fyr_representative['type']);

    //Check that the representative represents this postcode
    verify_rep_postcode($fyr_postcode, $fyr_representative);

    // Get the electoral body information
    $eb_type = $va_inside[$fyr_voting_area['type']];
    if (array_key_exists($eb_type, $verify_voting_area_map)) {
        $eb_id = $verify_voting_area_map[$eb_type];
    } else {
        $eb_id = $fyr_voting_area['parent_area_id'];
    }
    
    $eb_area_info = mapit_get_voting_area_info($eb_id);
    mapit_check_error($eb_area_info);

    // Data bad due to election etc?
    $parent_status = dadem_get_area_status($eb_id);
    dadem_check_error($parent_status);
    $status = dadem_get_area_status($fyr_representative['voting_area']);
    dadem_check_error($status);
    if ($parent_status != 'none' || $status != 'none'){
        $election_error = cobrand_election_error_message($cobrand);
        if (!$election_error) {
             $election_error = 'Sorry, an election is forthcoming or has recently happened here.';
        }
        template_show_error($election_error);
    }

    //Check the contact method exists
Ejemplo n.º 2
0
        $fyr_all_url = htmlspecialchars(url_new('who', false,
                        'pc', $fyr_postcode,
                        'fyr_extref', fyr_external_referrer(),
                        'cocode', $cocode));
    }
}

// If in a county, but not a county electoral division, display explanation
// (which is lack of data from Ordnance Survey)
$fyr_county_note = false;
if (array_key_exists('CTY', $voting_areas) && !array_key_exists('CED', $voting_areas)) {
    $fyr_county_note = true; 
}

$voting_areas_info = mapit_get_voting_areas_info(array_values($voting_areas));
mapit_check_error($voting_areas_info);
debug_timestamp();

$area_representatives = dadem_get_representatives(array_values($voting_areas));
$error = dadem_get_error($area_representatives);
dadem_check_error($area_representatives);
debug_timestamp();

$all_representatives = array();
foreach (array_values($area_representatives) as $rr) {
    $all_representatives = array_merge($all_representatives, $rr);
}
$representatives_info = dadem_get_representatives_info($all_representatives);
dadem_check_error($representatives_info);
debug_timestamp();
Ejemplo n.º 3
0
    debug("FRONTEND", "Valid reps", $stash['valid_reps']);
    // Set a msgid for each rep in the list
    assign_message_ids();
} else {
    // Message intended for individual representative
    $fyr_representative = get_rep($fyr_values['who']);
    $fyr_voting_area = get_area($fyr_representative['voting_area']);
    if (is_postcode_editable($fyr_representative['type'])) {
        $eb_area = mapit_call('area', $fyr_voting_area['parent_area']);
    } else {
        // Check that the representative represents this postcode
        if (!$fyr_values['pc']) {
            mismatch_error();
        }
        $postcode_areas = mapit_call('postcode', $fyr_values['pc']);
        mapit_check_error($postcode_areas);
        $area_ids = array_keys($postcode_areas['areas']);
        if (!in_array($fyr_representative['voting_area'], $area_ids)) {
            mismatch_error();
        }
        $eb_type = $va_inside[$fyr_voting_area['type']];
        foreach ($postcode_areas['areas'] as $id => $arr) {
            if ($arr['type'] == $eb_type) {
                $eb_area = $arr;
                break;
            }
        }
    }
    // Data bad due to election etc?
    check_area_status($eb_area, $fyr_voting_area);
    //Check the contact method exists
Ejemplo n.º 4
0
require_once "../commonlib/phplib/mapit.php";
require_once "../commonlib/phplib/dadem.php";
require_once "../commonlib/phplib/votingarea.php";
require_once "../commonlib/phplib/utility.php";
// Get all fyr_values
$fyr_values = get_all_variables();
debug("FRONTEND", "All variables:", $fyr_values);
if (!array_key_exists('id', $fyr_values) || $fyr_values['id'] == '' || !ctype_digit($fyr_values['id'])) {
    template_show_error('Please <a href="/">start from the beginning</a>.');
    exit;
}
$fyr_vatype = $fyr_values['id'];
$va_info = mapit_call('area', $fyr_vatype);
mapit_check_error($va_info);
$parent_info = mapit_call('area', $va_info['parent_area']);
mapit_check_error($parent_info);
debug_timestamp();
$area_reps = dadem_get_representatives(array($fyr_vatype));
dadem_check_error($area_reps);
debug_timestamp();
$area_reps = $area_reps[$fyr_vatype];
$area_reps = array_values($area_reps);
$reps_info = dadem_get_representatives_info($area_reps);
dadem_check_error($reps_info);
debug_timestamp();
$template_page = 'corrections-index';
if (isset($fyr_values['name']) && isset($fyr_values['party'])) {
    # Changes have been submitted
    $fyr_names = $fyr_values['name'];
    $fyr_parties = $fyr_values['party'];
    $fyr_new = isset($fyr_values['new']) ? $fyr_values['new'] : array();
Ejemplo n.º 5
0
    function print_messages($messages, $msgid = null) {
?>

<table border="1" width="100%">
    <tr>
        <th>Created</th>
        <th>Message ID /<br>Group ID</th>
        <th>Last state change</th>
        <th>State /<br>Last action</th>
        <th>Sender</th>
        <th>Recipient</th>
        <th>Client IP / <br> Referrer / Cobrand</th>
        <th>Length (chars)</th>
        <th>Questionnaire</th>
        <th>Tick</th>
    </tr>
    <form action="<?=htmlspecialchars(url_new("", false, 'view', get_http_var('view'), 'simto', get_http_var('simto'), 'page', get_http_var('page'))) ?>" method="post">
<?
            $c = 1;
            foreach ($messages as $message) {
                print '<tr' . ($c==1 ? ' class="v"' : '') . '>';
                print "<td>" . strftime('%Y-%m-%d %H:%M:%S', $message['created']) . "</td>";
                print '<td><a href="'
                        . $this->self_link . "&id=".urlencode($message['id'])
                        . '">'
                        .  $message['id'] . '</a>' 
                        . "<br>${message['group_id']}"
                        . '</td>';
                print "<td>" . strftime('%Y-%m-%d %H:%M:%S', $message['laststatechange']) . "</td>";
                print "<td>";
                print add_tooltip($message['state'], $this->state_help_notes($message['state']));
                /* Only show frozen flag if the message is in a state this can
                 * affect. */
                if ($message['frozen']) 
                {
                    if ($message['state'] == 'new' or $message['state'] == 'pending' or $message['state'] == 'ready')
                        print "<br><b>frozen</b>";
                    else
                        print "<br>frozen";
                }

                if ($message['numactions'] > 0) {
                    if ($message['state'] == 'pending')  {
                        print "<br>" .  ($message['numactions'] - 1) . " ".
                        make_plural(($message['numactions'] - 1), 'reminder');
                    } elseif ($message['state'] == 'sent' || $message['state'] == 'failed_closed')  {
                        print "<br>". $message['numactions'] . " " .
                        make_plural($message['numactions'], 'day');
                    } elseif ($message['state'] == 'ready')  {
                        print "<br>". $message['numactions'] . " " .
                        make_plural($message['numactions'], 'failure');
                    } else {
                        print "<br>". $message['numactions'] . " " .
                        make_plural($message['numactions'], 'attempt');
                    }
                }

                if ($message['lastaction'] > 0 && $message['state'] != 'failed_closed')
                    print "<br>" .  strftime('%Y-%m-%d %H:%M:%S', $message['lastaction']);

                print "</td>";
                print "<td>"
                        . htmlspecialchars($message['sender_name']) . "<br>"
                        . str_replace($message['sender_postcode'], 
                        '<a href="'.OPTION_BASE_URL.'/who?pc='.urlencode($message['sender_postcode']).'">'.$message['sender_postcode'].'</a>',
                            htmlspecialchars($message['sender_addr'])
                                ) . "<br>"
                        . htmlspecialchars($message['sender_email'])
                        . "</td>";

                $display_name = $message['recipient_name'];
                if (!isset($display_name) || $display_name == "") {
                    $display_name = "scrubbed, id " .
                    $message['recipient_id'] . ", " .
                    $message['recipient_type'];
                }
                print '<td><a href="'
                        . htmlspecialchars(url_new('', false, 'page', 'reps', 'rep_id', $message['recipient_id'], 'pc', $message['sender_postcode']))                   . '">' . htmlspecialchars($display_name) . "</a>"
                        . " (<a href=\"" . htmlspecialchars(url_new('', false, 'page', 'fyrqueue', 'rep_id', $message['recipient_id']))                   . '">msgs</a>)' 
                        ."<br>";
                if ($message['recipient_via']) {
                    $repinfo = dadem_get_representative_info($message['recipient_id']);
                    if (!dadem_get_error($repinfo)) {
                        $vainfo = mapit_get_voting_area_info($repinfo['voting_area']);
                        $parentinfo = mapit_get_voting_area_info($vainfo['parent_area_id']);
                        mapit_check_error($parentinfo);
                        print '<a href="' .
                           htmlspecialchars(url_new('', false, 'page', 'reps', 'ds_va_id', $vainfo['parent_area_id'], 'pc', $message['sender_postcode']))  . '">' . 
                            htmlspecialchars("via " . $parentinfo['name']) . "</a>:<br>";
                    } else {
                        print 'recipient_via contact, but rep id not found ';
                    }
                }
                if ($message['recipient_email'])
                    print htmlspecialchars($message['recipient_email']) . "<br>";
                if ($message['recipient_fax'])
                    print htmlspecialchars($message['recipient_fax']) . "<br>";
                print "</td>";

                print "<td><a href=\"ipaddrinfo.cgi?ipaddr=${message['sender_ipaddr']}\">${message['sender_ipaddr']}</a>".
                    "<br>" . trim_url($message['sender_referrer']) . 
                    "<br>" . $message['cobrand'] . " " . $message['cocode'] .
                    "</td>";
                print "<td>${message['message_length']}</td>";

                $outof0 = ($message['questionnaire_0_no'] + $message['questionnaire_0_yes']);
                $outof1 = ($message['questionnaire_1_no'] + $message['questionnaire_1_yes']);
                print '<td>';
                if ($outof0) {
                    print 'responded:';
                    print $message['questionnaire_0_yes'] .'/'. $outof0;
                }
                if ($outof0 && $outof1)
                    print '<br>';
                if ($outof1) {
                    print ' firsttime:';
                    print $message['questionnaire_1_yes'] .'/'. $outof1;
                }
                if ($message['no_questionnaire']) {
                        print "<br>no quest";
                }
                if (!$outof0 && !$outof1) {
                    print '&nbsp;';
                }
                print '</td>';

                /* Javascript code changes shading of table row for checked
                 * messages to make them look "selected". */
                print '<td><input type="checkbox" name="check_'
                        . $message['id']
                        . '" onclick="this.parentNode.parentNode.className = this.checked ? \'h\' : \''
                            . ($c == 1 ? 'v' : '')
                            . '\'" >';
                print '</td>';

                print "</tr>";
                # this.checked this .className=

                if (array_key_exists('diff', $message)) {
                    /* Each element of the array consists either of an array of
                     * two strings, which are the strings unique to the "from"
                     * and "to" strings; or a string, representing a common
                     * part; or null, indicating an elided part. */
                    print '<tr'.($c==1?' class="v"':'').'><td colspan = "9">';
                    print "<b>Differences: </b> ";
                    if (isset($msgid) and $message['id'] == $msgid) {
                        print 'This is the message being compared against. <span class="difffrom">Text that appears only in this message, </span><span class="diffto">or only in the other message.</span>';
                    } else {
                        foreach ($message['diff'] as $elem) {
                            if (!isset($elem)) {
                                print '<span class="diffsnipped">[ ... snipped ... ]</span>';
                            } else if (is_array($elem)) {
                                print '<span class="difffrom">'
                                        . htmlspecialchars($elem[0])
                                        . '</span><span class="diffto">'
                                        . htmlspecialchars($elem[1])
                                        . '</span>';
                            } else {
                                print htmlspecialchars($elem);
                            }
                        }
                    }
                    print "</td></tr>";
                }

                $c = 1 - $c;
            }
            if (count($messages) > 1) {
?><tr><td colspan=9><b>Ticked items:</b>
        <input name="token" value="<? print get_token(); ?>" type="hidden" />
        <input size="20" name="notebody" type="text" /> 
        <input name="note" value="Note" type="submit" />
        &nbsp; <b>Action:</b>
        <input name="freeze" value="Freeze" type="submit" />
        <input name="thaw" value="Thaw" type="submit" />
        <input name="error" value="Error with email" type="submit" />
        <input name="failed" value="Fail silently" type="submit" />
</td><tr>
<?
    }
?>
</form>
</table>
<?
    }
Ejemplo n.º 6
0
function crosssell_check_twfy($email, $postcode)
{
    global $crosssell_check_twfy_checked;
    if (!is_null($crosssell_check_twfy_checked)) {
        return $crosssell_check_twfy_checked;
    }
    if (!defined('OPTION_AUTH_SHARED_SECRET') || !$postcode) {
        return false;
    }
    // Look up who the MP is
    global $crosssell_voting_areas;
    if (!$crosssell_voting_areas) {
        $crosssell_voting_areas = mapit_get_voting_areas($postcode);
    }
    mapit_check_error($crosssell_voting_areas);
    if (!array_key_exists('WMC', $crosssell_voting_areas)) {
        $crosssell_check_twfy_checked = false;
        return false;
    }
    $reps = dadem_get_representatives($crosssell_voting_areas['WMC']);
    dadem_check_error($reps);
    if (count($reps) != 1) {
        $crosssell_check_twfy_checked = false;
        return false;
    }
    $rep_info = dadem_get_representative_info($reps[0]);
    dadem_check_error($rep_info);
    if (!array_key_exists('parlparse_person_id', $rep_info)) {
        $crosssell_check_twfy_checked = false;
        return false;
    }
    $person_id = str_replace('uk.org.publicwhip/person/', '', $rep_info['parlparse_person_id']);
    if (!$person_id) {
        $crosssell_check_twfy_checked = false;
        return false;
    }
    $auth_signature = auth_sign_with_shared_secret($email, OPTION_AUTH_SHARED_SECRET);
    // See if already signed up
    $already_signed = crosssell_fetch_page('www.theyworkforyou.com', '/alert/authed.php?pid=' . $person_id . '&email=' . urlencode($email) . '&sign=' . urlencode($auth_signature));
    if ($already_signed != 'not signed') {
        $crosssell_check_twfy_checked = false;
        return false;
    }
    $crosssell_check_twfy_checked = array($person_id, $auth_signature);
    return $crosssell_check_twfy_checked;
}
Ejemplo n.º 7
0
 function display($self_link)
 {
     // Input data
     $rep_id = get_http_var('rep_id');
     $va_id = get_http_var('va_id');
     $ds_va_id = get_http_var('ds_va_id');
     $bad_contacts = get_http_var('bad_contacts');
     $user_corrections = get_http_var('user_corrections');
     // Make new rep in this voting area
     $new_in_va_id = get_http_var('new_in_va_id');
     if (!$rep_id && $ds_va_id) {
         // Democratic services
         $ds_vainfo = dadem_get_representatives($ds_va_id);
         dadem_check_error($ds_vainfo);
         if (isset($ds_vainfo[0])) {
             $rep_id = $ds_vainfo[0];
         } else {
             $new_in_va_id = $ds_va_id;
         }
     }
     // Postcode
     $pc = get_http_var('pc');
     // Search
     $search = null;
     if (get_http_var('gos')) {
         if (validate_postcode(get_http_var('search'))) {
             $pc = get_http_var('search');
             $rep_id = null;
         } else {
             $search = get_http_var('search');
             $rep_id = null;
         }
     }
     if (get_http_var('cancel') != "") {
         $rep_id = null;
     }
     if (get_http_var('done') != "") {
         if (get_http_var('token') != $this->get_token()) {
             print "<p><i>Token not found</i></p>";
         } else {
             $newdata['name'] = get_http_var('name');
             $newdata['party'] = get_http_var('party');
             $newdata['method'] = get_http_var('method');
             $newdata['email'] = get_http_var('email');
             $newdata['fax'] = get_http_var('fax');
             if (!$rep_id) {
                 // Making a new representative, put in type and id
                 $newdata['area_id'] = $new_in_va_id;
                 $vainfo = mapit_call('area', $new_in_va_id);
                 mapit_check_error($vainfo);
                 $newdata['area_type'] = $vainfo['type'];
             }
             $result = dadem_admin_edit_representative($rep_id, $newdata, http_auth_user(), get_http_var('note'));
             dadem_check_error($result);
             $rep_id = $result;
             $new_in_va_id = null;
             print "<p><i>Successfully updated representative " . htmlspecialchars($rep_id) . "</i></p>";
             if (get_http_var('nextbad')) {
                 $rep_id = get_http_var('nextbad');
                 $url = $self_link . "&nextbad=" . urlencode($this->get_next_bad_contact($rep_id)) . "&just_done_bad=1&rep_id=" . urlencode($rep_id);
                 header("Location: {$url}");
                 exit;
             } else {
                 $rep_id = null;
             }
         }
     }
     if (get_http_var('just_done_bad')) {
         print "<p><i>Moved on to next bad contact</i></p>";
     }
     if (get_http_var('delete') != "") {
         if (get_http_var('token') != $this->get_token()) {
             print "<p><i>Token not found</i></p>";
         } else {
             $result = dadem_admin_edit_representative($rep_id, null, http_auth_user(), get_http_var('note'));
             dadem_check_error($result);
             print "<p><i>Successfully deleted representative " . htmlspecialchars($rep_id) . "</i></p>";
             $rep_id = null;
         }
     }
     if (get_http_var('ucclose') != "") {
         $result = dadem_admin_done_user_correction(get_http_var('ucid'));
         dadem_check_error($result);
         print "<p><i>Successfully closed correction " . htmlspecialchars(get_http_var('ucid')) . "</i></p>";
     }
     if (get_http_var('vaupdate') != "") {
         $result = dadem_admin_set_area_status(get_http_var('va_id'), get_http_var('new_status'));
         dadem_check_error($result);
         print "<p><i>Successfully updated voting area status " . htmlspecialchars(get_http_var('va_id')) . " to " . htmlspecialchars(get_http_var('new_status')) . "</i></p>";
     }
     // Postcode and search box
     $form = new HTML_QuickForm('adminRepsSearchForm', 'get', $self_link);
     $form->addElement('header', '', 'Search');
     $buttons[] =& HTML_QuickForm::createElement('text', 'search', null, array('size' => 20, 'maxlength' => 255));
     $buttons[] =& HTML_QuickForm::createElement('submit', 'gos', 'postcode or query');
     $form->addElement('hidden', 'page', $this->id);
     $form->addGroup($buttons, 'stuff', null, '&nbsp', false);
     admin_render_form($form);
     // Conditional parts:
     if ($rep_id or $new_in_va_id) {
         $form = new HTML_QuickForm('adminRepsEditForm', 'post', $self_link);
         $form->addElement('hidden', 'page', $this->id);
         $form->addElement('hidden', 'token', $this->get_token());
         // Edit representative
         $sameperson = null;
         if ($rep_id) {
             $repinfo = dadem_get_representative_info($rep_id);
             dadem_check_error($repinfo);
             if ($repinfo['parlparse_person_id']) {
                 $sameperson = dadem_get_same_person($repinfo['parlparse_person_id']);
                 dadem_check_error($sameperson);
             }
         }
         $va_id = $rep_id ? $repinfo['voting_area'] : $new_in_va_id;
         $vainfo = mapit_call('area', $va_id);
         mapit_check_error($vainfo);
         if ($vainfo['parent_area']) {
             $parentinfo = mapit_call('area', $vainfo['parent_area']);
             mapit_check_error($parentinfo);
         } else {
             $parentinfo = null;
         }
         $rephistory = $rep_id ? dadem_get_representative_history($rep_id) : array();
         dadem_check_error($rephistory);
         // Reverse postcode lookup
         if (!$pc) {
             $pc = mapit_call('area/example_postcode', $va_id);
             if (!mapit_get_error($pc)) {
                 $form->addElement('static', 'note1', null, "Example postcode for testing: " . "<a href='" . OPTION_BASE_URL . '/who?pc=' . urlencode($pc) . "'>" . htmlentities($pc) . "</a> (<a href='?search=" . urlencode($pc) . "&amp;gos=postcode+or+query&amp;page=reps'>all reps here</a>)");
             } else {
                 $pc = '';
             }
         }
         if ($rep_id) {
             $form->setDefaults(array('name' => $repinfo['name'], 'party' => $repinfo['party'], 'method' => $repinfo['method'], 'email' => $repinfo['email'], 'fax' => $repinfo['fax']));
         }
         // Councillor types are not edited here, but in match.cgi interface
         global $va_council_child_types, $va_type_name, $va_rep_name;
         $editable_here = true;
         if (OPTION_ADMIN_SERVICES_CGI && in_array($vainfo['type'], $va_council_child_types)) {
             $editable_here = false;
         }
         $readonly = $editable_here ? null : "readonly";
         if ($rep_id) {
             $form->addElement('header', '', 'Edit Representative');
             if ($repinfo['deleted']) {
                 $form->addElement('static', 'notedeleted', null, "<strong style=\"color: red\">Deleted representative</strong>, click 'Done' to undelete");
             }
         } else {
             $form->addElement('header', '', 'New Representative');
         }
         if ($rep_id and $editable_here) {
             $form->addElement('static', 'note1', null, "\n                Edit only the values which you need to.  If a representative\n                has changed delete them and make a new one.  Do not just edit\n                their values, as this would ruin our reponsiveness stats.");
         }
         if ($rep_id && $sameperson) {
             $html = '';
             foreach ($sameperson as $samerep) {
                 if ($samerep == $rep_id) {
                     continue;
                 }
                 $html .= "<a href=\"{$self_link}&pc=" . urlencode(get_http_var('pc')) . "&rep_id=" . $samerep . "\">" . $samerep . "</a> \n";
             }
             if ($html) {
                 $html = '(Note that these other representatives are the same person: ' . trim($html) . ')';
                 $form->addElement('static', 'sameperson', null, $html);
             }
         }
         $rep_name = isset($va_rep_name[$vainfo['type']]) ? $va_rep_name[$vainfo['type']] : '';
         $form->addElement('static', 'office', 'Office:', htmlspecialchars($rep_name) . " for " . htmlspecialchars($vainfo['name']) . " " . htmlspecialchars($va_type_name[$vainfo['type']]) . ($parentinfo ? " in " . htmlspecialchars($parentinfo['name']) . " " . htmlspecialchars($va_type_name[$parentinfo['type']]) : ""));
         $form->addElement('text', 'name', "Full name:", array('size' => 60, $readonly => 1));
         $form->addElement('text', 'party', "Party:", array('size' => 60, $readonly => 1));
         $form->addElement('static', 'note2', null, "Make sure you update contact method when you change email or fax numbers.");
         $form->addElement('select', 'method', "Contact method:", array('fax' => 'Fax only', 'email' => 'Email only', 'shame' => "Shame! Doesn't want contacting", 'via' => 'Contact via electoral body (e.g. Democratic Services)', 'unknown' => "We don't know contact details"));
         $form->addElement('text', 'email', "Email:", array('size' => 60, $readonly => 1));
         $form->addElement('text', 'fax', "Fax:", array('size' => 60, $readonly => 1));
         $form->addElement('textarea', 'note', "Notes for log:", array('rows' => 3, 'cols' => 60, $readonly => 1));
         $form->addElement('hidden', 'pc', $pc);
         if (get_http_var('nextbad')) {
             $form->addElement('hidden', 'nextbad', get_http_var('nextbad'));
         }
         if ($rep_id) {
             $form->addElement('hidden', 'rep_id', $rep_id);
         } else {
             $form->addElement('hidden', 'new_in_va_id', $new_in_va_id);
         }
         if ($editable_here) {
             $finalgroup[] =& HTML_QuickForm::createElement('submit', 'done', 'Done');
             $finalgroup[] =& HTML_QuickForm::createElement('submit', 'cancel', 'Cancel');
             if ($rep_id) {
                 $finalgroup[] =& HTML_QuickForm::createElement('static', 'newlink', null, "<a href=\"{$self_link}&pc=" . urlencode(get_http_var('pc')) . "&new_in_va_id=" . $va_id . "\">" . "Make new " . htmlspecialchars($vainfo['name']) . " rep" . "</a> \n");
                 if ($repinfo['deleted']) {
                     $finalgroup[] =& HTML_QuickForm::createElement('static', 'staticspacer', null, '&nbsp; Deleted rep, no longer in office, just click done to undelete');
                 } else {
                     $finalgroup[] =& HTML_QuickForm::createElement('static', 'staticspacer', null, '&nbsp; No longer in office? --->');
                     $finalgroup[] =& HTML_QuickForm::createElement('submit', 'delete', 'Delete');
                 }
             }
             $form->addGroup($finalgroup, "finalgroup", "", ' ', false);
         } else {
             $form->addElement('static', 'note3', null, '<a href="' . OPTION_ADMIN_SERVICES_CGI . 'match.cgi?page=councilinfo;area_id=' . $vainfo['parent_area'] . '">To edit Councillors please use the match.cgi interface</a>' . '<br><a href="' . $self_link . '&ds_va_id=' . $vainfo['parent_area'] . '">... or edit Democratic Services for this council</a>');
             $finalgroup[] =& HTML_QuickForm::createElement('submit', 'done', 'Done');
             $finalgroup[] =& HTML_QuickForm::createElement('submit', 'cancel', 'Cancel');
             $form->addGroup($finalgroup, "finalgroup", "", ' ', false);
         }
         if ($rep_id) {
             $search_links = "Search for: ";
             $search_links .= "<a href=\"{$self_link}&page=fyrqueue&rep_id=" . $rep_id . "\">WriteToThem messages</a> | ";
             foreach (array("tel " . $repinfo['name'], "fax " . $repinfo['name'], "tel " . $repinfo['name'] . " " . $rep_name, "fax " . $repinfo['name'] . " " . $rep_name) as $searchq) {
                 $search_links .= "<a href=\"http://search.yahoo.com/search?p=" . htmlspecialchars($searchq) . "\"> " . htmlspecialchars($searchq) . "</a> | ";
             }
             $form->addElement('static', 'newlink', null, $search_links);
             if ($repinfo['parlparse_person_id']) {
                 $form->addElement('static', 'person', 'parlparse person_id:', $repinfo['parlparse_person_id']);
             }
         }
         $form->addElement('header', '', 'Historical Changes');
         $html = "<table border=1>";
         $html .= "<th>Order</th><th>Date</th><th>Editor</th><th>Note</th>\n                <th>Name</th> <th>Party</th> <th>Method</th> <th>Email</th>\n                <th>Fax</th><th>Active</th>";
         $previous_row = null;
         foreach ($rephistory as $row) {
             $html .= "<tr>";
             foreach (array('order_id', 'whenedited', 'editor', 'note', 'name', 'party', 'method', 'email', 'fax', 'deleted') as $field) {
                 if ($row['deleted'] && ($field == 'email' || $field == 'fax' || $field == 'method')) {
                     $display_value = 'deleted';
                     $html .= "<td>-</td>\n";
                     continue;
                 }
                 $value = $row[$field];
                 if ($field == 'note') {
                     $display_value = make_ids_links($value);
                 } elseif ($field == 'whenedited') {
                     $display_value = strftime('%Y-%m-%d %H:%M:%S', $value);
                 } elseif ($field == 'deleted') {
                     $display_value = $value ? 'deleted' : 'yes';
                 } else {
                     $display_value = $value;
                 }
                 if ($field != "order_id" && $field != "whenedited" && $field != "editor" && $field != "note" && $previous_row && $previous_row[$field] != $value) {
                     $display_value = "<strong>{$display_value}</strong>";
                 }
                 # Try and spot stupidity
                 if (preg_match('#parl(i|a)ment#', $display_value)) {
                     $display_value = "<span style='color:#00ff00'>{$display_value}</span>";
                 }
                 $html .= "<td>" . $display_value . "</td>\n";
             }
             $html .= "</tr>";
             $previous_row = $row;
         }
         $html .= "</table>";
         $form->addElement('static', 'bytype', null, $html);
         admin_render_form($form);
     } elseif ($va_id) {
         // One voting area
         $form = new HTML_QuickForm('adminVotingArea', 'get', $self_link);
         $area_info = mapit_call('area', $va_id);
         mapit_check_error($area_info);
         $reps = dadem_get_representatives($va_id);
         dadem_check_error($reps);
         $reps = array_values($reps);
         $html = $this->render_area($self_link, $va_id, $area_info, $pc);
         $html .= $this->render_reps($self_link, $reps);
         $form->addElement('static', 'bytype', null, $html);
         $form->addElement('hidden', 'page', $this->id);
         $form->addElement('hidden', 'token', $this->get_token());
         $form->addElement('hidden', 'va_id', $va_id);
         $select = $form->addElement('select', 'new_status', null, array('none' => 'No special status', 'pending_election' => 'Pending election, rep data not valid', 'recent_election' => 'Recent election, our rep data not yet updated', 'boundary_changes' => 'Recent election, had boundary changes'), array());
         $status = dadem_get_area_status($va_id);
         dadem_check_error($status);
         $select->setSelected($status);
         $form->addElement('submit', 'vaupdate', 'Update');
         admin_render_form($form);
     } elseif ($search) {
         $form = new HTML_QuickForm('adminRepsSearchResults', 'get', $self_link);
         $html = '';
         $areas = mapit_call('areas', $search);
         mapit_check_error($areas);
         global $va_inside;
         foreach (array_keys($areas) as $va_id) {
             $area_info = mapit_call('area', $va_id);
             mapit_check_error($area_info);
             $reps = dadem_get_representatives($va_id);
             dadem_check_error($reps);
             $reps = array_values($reps);
             $html .= $this->render_area($self_link, $va_id, $area_info, $pc, isset($va_inside[$area_info['type']]));
             $html .= $this->render_reps($self_link, $reps);
         }
         // Search reps
         $reps = dadem_search_representatives($search);
         dadem_check_error($reps);
         $html .= '<hr>' . $this->render_reps($self_link, $reps);
         $form->addElement('static', 'bytype', null, $html);
         admin_render_form($form);
     } elseif ($pc) {
         $form = new HTML_QuickForm('adminRepsSearchResults', 'get', $self_link);
         // Postcode search
         $voting_areas = mapit_call('postcode', $pc);
         mapit_check_error($voting_areas);
         $areas_info = $voting_areas['areas'];
         $html = "";
         // Display in order council, ward, council, ward...
         global $va_display_order, $va_inside;
         $our_order = array();
         foreach ($va_display_order as $row) {
             if (!is_array($row)) {
                 $row = array($row);
             }
             if (!in_array($va_inside[$row[0]], $our_order)) {
                 $our_order[] = $va_inside[$row[0]];
             }
             foreach ($row as $va_type) {
                 $our_order[] = $va_type;
             }
         }
         // Render everything in the order
         foreach ($our_order as $va_type) {
             foreach ($areas_info as $area => $area_info) {
                 if ($va_type != $area_info['type']) {
                     continue;
                 }
                 $va_id = $area;
                 // One voting area
                 $reps = dadem_get_representatives($va_id);
                 dadem_check_error($reps);
                 $reps = array_values($reps);
                 $html .= $this->render_area($self_link, $va_id, $area_info, $pc, isset($va_inside[$va_type]));
                 $html .= $this->render_reps($self_link, $reps);
             }
         }
         $form->addElement('static', 'bytype', null, $html);
         admin_render_form($form);
     } elseif ($bad_contacts) {
         // Bad contacts
         $form = new HTML_QuickForm('adminRepsBad', 'post', $self_link);
         $badcontacts = dadem_get_bad_contacts();
         dadem_check_error($badcontacts);
         $form->addElement('header', '', 'Bad Contacts ' . count($badcontacts));
         $html = $this->render_reps($self_link, $badcontacts, true);
         $form->addElement('static', 'badcontacts', null, $html);
         admin_render_form($form);
     } elseif ($user_corrections) {
         // User submitted corrections
         $form = new HTML_QuickForm('adminRepsCorrectionsHeader', 'post', $self_link);
         $corrections = dadem_get_user_corrections();
         dadem_check_error($corrections);
         $form->addElement('header', '', 'User Submitted Corrections ' . count($corrections));
         $form->addElement('hidden', 'token', $this->get_token());
         admin_render_form($form);
         // Get all the data for areas and their parents in as few call as possible
         $vaids = array();
         foreach ($corrections as $correction) {
             array_push($vaids, $correction['voting_area_id']);
         }
         $info1 = mapit_call('areas', $vaids);
         mapit_check_error($info1);
         $vaids = array();
         foreach ($info1 as $key => $value) {
             array_push($vaids, $value['parent_area']);
         }
         $info2 = mapit_call('areas', $vaids);
         foreach ($corrections as $correction) {
             $form = new HTML_QuickForm('adminRepsCorrections', 'post', $self_link);
             $html = "";
             $rep = $correction['representative_id'];
             $html .= "<p>";
             $html .= strftime('%Y-%m-%d %H:%M:%S', $correction['whenentered']) . " ";
             if ($correction['user_email']) {
                 $html .= " by " . htmlspecialchars($correction['user_email']);
             }
             $html .= "<br>";
             if ($correction['voting_area_id']) {
                 $wardinfo = $info1[$correction['voting_area_id']];
                 $vaid = $wardinfo['parent_area'];
                 $vainfo = $info2[$vaid];
                 // TODO: Make this councilinfo, and give a valid r= return URL
                 $html .= '<a href="' . OPTION_ADMIN_SERVICES_CGI . 'match.cgi?page=councilinfo;area_id=' . $vaid . '&r=' . '">' . htmlspecialchars($vainfo['name']) . "</a>, ";
                 $html .= htmlspecialchars($wardinfo['name']);
                 $html .= "<br>";
             }
             $html .= $correction['alteration'] . " ";
             if ($rep) {
                 $repinfo = dadem_get_representative_info($rep);
                 dadem_check_error($repinfo);
                 $html .= "<a href=\"{$self_link}&pc=" . urlencode(get_http_var('pc')) . "&rep_id=" . $rep . "\">" . htmlspecialchars($repinfo['name']) . " (" . htmlspecialchars($repinfo['party']) . ")</a> \n";
                 if ($correction['alteration'] != "delete") {
                     $html .= " to ";
                 }
             }
             if ($correction['alteration'] != "delete") {
                 $html .= htmlspecialchars($correction['name']) . " (" . htmlspecialchars($correction['party']) . ")";
             }
             if ($correction['user_notes']) {
                 $html .= "<br>Notes: " . htmlspecialchars($correction['user_notes']);
             }
             $usercorr = array();
             $usercorr[] =& HTML_QuickForm::createElement('static', 'usercorrections', null, $html);
             // You can't do this with element type "hidden" as it only allows one value in a
             // page for variable named ucid.  So once again I go to raw HTML.  Remind me not
             // to use HTML_QuickForm again...
             $usercorr[] =& HTML_QuickForm::createElement('html', '<input name="ucid" type="hidden" value="' . $correction['user_correction_id'] . '" />');
             $usercorr[] =& HTML_QuickForm::createElement('submit', 'ucclose', 'hide (done)');
             $form->addGroup($usercorr, 'stuff', null, '&nbsp', false);
             admin_render_form($form);
         }
     } else {
         print '<p><a href="?page=reps&bad_contacts=1">Bad contacts</a> (please fix these!)';
         // General info
         if (OPTION_ADMIN_SERVICES_CGI) {
             print '<br><a href="?page=reps&user_corrections=1">User corrections</a> (just for your interest, as sent automatically to GovEval)';
         }
     }
 }
Ejemplo n.º 8
0
require_once '../commonlib/phplib/mapit.php';
require_once '../commonlib/phplib/dadem.php';
$dates = array('2013-05-10' => array(2228, 2217, 2242, 2218, 2229, 2225), '2013-05-17' => array(2234, 2233, 2232, 2241), '2013-05-21' => array(2561), '2013-05-22' => array(2236, 2245, 2222, 2227, 2237, 2223, 2244, 2220, 2226, 2231, 2240, 2248, 2235, 2224, 2243, 2221, 2250, 2230, 2636, 2249, 2246, 2239, 65719), '2013-05-23' => array(2251, 2637, 2238));
foreach ($dates as $date => $ids) {
    foreach ($ids as $id) {
        $date_done[$id] = $date;
    }
}
$statuses = dadem_get_area_statuses();
foreach ($statuses as $status_arr) {
    $area_id = $status_arr[0];
    $status = $status_arr[1];
    $lookup[$area_id] = $status;
}
$areas_info = mapit_call('areas', array_keys($lookup));
mapit_check_error($areas_info);
function by_name($a, $b)
{
    global $areas_info, $date_done;
    if (isset($date_done[$a]) && isset($date_done[$b])) {
        if ($date_done[$a] < $date_done[$b]) {
            return 1;
        }
        if ($date_done[$a] > $date_done[$b]) {
            return -1;
        }
    } elseif (isset($date_done[$a])) {
        return -1;
    } elseif (isset($date_done[$b])) {
        return 1;
    }