<commit_before><?php
/*
 * survey.php:
 * Client code for the demographic surveys - call from sites which show the survey.
 * 
 * Copyright (c) 2008 UK Citizens Online Democracy. All rights reserved.
 * Email: <EMAIL>; WWW: http://www.mysociety.org/
 *
 * $Id: survey.php,v 1.1 2008-06-03 19:05:32 francis Exp $
 * 
 */

function survey_sign_email_address($email) {
    // Encode the email address to make the user code, so that anyone just with access to the survey database
    // can't work out what the email is. We don't have a salt, as we want to be able to test uniqueness.
    $user_code = sha1($email . "-" . OPTION_SURVEY_SECRET); 
    // And sign it to authorise it
    $auth_signature = auth_sign_with_shared_secret($user_code, OPTION_SURVEY_SECRET); 

    return array($user_code, $auth_signature);
}

function survey_check_if_already_done($user_code, $auth_signature) {
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
    curl_setopt($ch, CURLOPT_USERAGENT, 'PHP survey client, version $Id: survey.php,v 1.1 2008-06-03 19:05:32 francis Exp $');
    curl_setopt($ch, CURLOPT_URL, OPTION_SURVEY_URL);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, "querydone=1&user_code=" . urlencode($user_code) . "&auth_signature=" . urlencode($auth_signature));

    $r = curl_exec($ch);
    if ($r === FALSE)
        err(curl_error($ch) . " curling " . OPTION_SURVEY_URL);
    $errcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    if ($errcode != 200)
        err("Error $errcode curling " . OPTION_SURVEY_URL);

    curl_close($ch);
    
    return $r ? true : false;
}


<commit_msg>Fix error reporting from survey call. Enable survey.<commit_after><?php
/*
 * survey.php:
 * Client code for the demographic surveys - call from sites which show the survey.
 * 
 * Copyright (c) 2008 UK Citizens Online Democracy. All rights reserved.
 * Email: <EMAIL>; WWW: http://www.mysociety.org/
 *
 * $Id: survey.php,v 1.2 2008-06-06 20:15:56 francis Exp $
 * 
 */

function survey_sign_email_address($email) {
    // Encode the email address to make the user code, so that anyone just with access to the survey database
    // can't work out what the email is. We don't have a salt, as we want to be able to test uniqueness.
    $user_code = sha1($email . "-" . OPTION_SURVEY_SECRET); 
    // And sign it to authorise it
    $auth_signature = auth_sign_with_shared_secret($user_code, OPTION_SURVEY_SECRET); 

    return array($user_code, $auth_signature);
}

function survey_check_if_already_done($user_code, $auth_signature) {
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
    curl_setopt($ch, CURLOPT_USERAGENT, 'PHP survey client, version $Id: survey.php,v 1.2 2008-06-06 20:15:56 francis Exp $');
    curl_setopt($ch, CURLOPT_URL, OPTION_SURVEY_URL);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, "querydone=1&user_code=" . urlencode($user_code) . "&auth_signature=" . urlencode($auth_signature));

    $r = curl_exec($ch);
    if ($r === FALSE)
        err(curl_error($ch) . " curling " . OPTION_SURVEY_URL);
    $errcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    if ($errcode != 200)
        err("Error $errcode curling " . OPTION_SURVEY_URL);

    curl_close($ch);
    
    $r = trim($r);
    if ($r == "1")
        return true;
    elseif ($r == "0")
        return false;
    else
        err("Error returned from survey service: " . $r);
}



{'fraction_non_alphanumeric': 0.1272929405225125, 'fraction_numerical': 0.02556976097832129, 'mean_word_length': 3.7417654808959155, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3037902', 'n_tokens_mistral': 1364, 'n_tokens_neox': 1241, 'n_words': 326}