function create_from_supporter($dia_supporter_key)
 {
     $dia = new DemocracyInAction_API(DIA_API_NODE, DIA_API_USERNAME, DIA_API_PASSWORD);
     $dia->authenticate();
     $supporter = $dia->get('supporter', $dia_supporter_key);
     if (empty($supporter)) {
         WinMember::dia_supporter_not_found();
     }
     $member = WinMember::find_by_email($supporter['Email']);
     if (!$member) {
         $member = new WinMember($supporter['uid']);
     }
     $member->dia =& $dia;
     if (empty($supporter['uid'])) {
         trigger_error('no supporter UID');
         $member->data->mergeData(array(WIN_USERNAME => $supporter['Email'], WIN_DIA_SUPPORTER_KEY => $supporter['supporter_KEY'], 'Email' => $supporter['Email'], 'First_Name' => $supporter['First_Name'], 'Last_Name' => $supporter['Last_Name'], 'Street' => $supporter['Street'], 'City' => $supporter['City'], 'State' => $supporter['State'], 'Zip' => $supporter['Zip'], 'modin' => 20));
         $member->data->save();
         trigger_error(var_export($member->data->id, true));
         trigger_error(var_export($member->data->getData('Email'), true));
         $member->dia->save('supporter', array('Email' => $member->data->getData('Email'), 'email_trigger_KEYS' => '0,' . WIN_SET_PASSWORD_EMAIL_KEY, 'USERNAME' => $member->data->getData('Email')));
         $message = 'You must set your password before you can log in.  <a href="http://www.winonline.org/forgot_password.php?login_type=content">Click here to set your password now </a>';
         AMP_flashMessage($message, $error = 'true');
     }
     return $member;
 }
function dia_connection( $dia_config ) {
    static $dia;
    if( $dia ) return $dia;

    $dia = new DemocracyInAction_API( $dia_config['node'], $dia_config['login'], $dia_config['password'] );

    $dia->authenticate( );

    $dia_groups = $dia->get( 'groups', array( 'limit' => 1) );
    if( !$dia_groups ) { 
        print "auth failed";
        exit;
    }
    return $dia;
}
<?php

// DemocracyInAction API: EXAMPLE USAGE
//
// THE FOLLOWING ACTIONS ARE SUPPORTED: get, save, delete, report
//
// more details about the external API can be found at http://dev.salsacommons.org/o/8001/p/salsa/commons/dev/docs/api/
//
require dirname(__FILE__) . '/api.php';
// LOGIN INFO: Make sure you are using the correct node
$node = 'salsa.democracyinaction.org';
$user = '******';
$password = '******';
// CREATE THE API
$api = new DemocracyInAction_API($node, $user, $password);
// GET A SINGLE SUPPORTER RECORD WITH ID 1234567 AS AN ARRAY OF DATA
$data = $api->get('supporter', 1234567);
// ALL OF THIS WORKS WITH ANY DIA TABLE
$data = $api->get('donation', 1234567);
// GETTING AN ARRAY OF MULTIPLE SUPPORTERS
// YOU CAN PASS IN MULTIPLE CONDITIONS AS AN ARRAY, ALL OTHER OPTIONS TAKE A SINGLE VALUE OR A COMMA SEPERATED LIST
$options = array('condition' => array('State=CA', 'Last_Name=McTest'), 'orderBy' => 'Last_Name,First_Name', 'limit' => 5, 'include' => 'First_Name,Last_Name,State');
$supporters = $api->get('supporter', $options);
print "DATA RECIEVED FROM DIA: \n";
print var_dump($supporters);
// SAVING DATA: MAKE AN ARRAY OF FIELDS WITH DIA FIELD NAMES
// THE NEW SUPPORTER KEY IS RETURNED IF SUCCESSFUL
$record = array('First_Name' => 'Testy', 'Last_Name' => 'McTest', 'Email' => '*****@*****.**', 'State' => 'CA');
$supporter_key = $api->save('supporter', $record);
// UPDATING RECORDS: SAME AS SAVING, BUT INCLUDE A KEY
$update = array('key' => $supporter_key, 'First_Name' => 'Testofolus', 'State' => 'OR');
<?php

#to do
# conditional show personal petition
# url encode everything emails and add share url to the end
# thermometer
# cc add to paste buffer
# update  share counts on the server
require_once 'dia/api.php';
require_once 'settings.php';
$DIA = new DemocracyInAction_API($node, $user, $password);
#get action key from slug
#$campign_slug = ''   ran.org/act/slug/ $_SERVER['REQUEST_URI']
if ($_REQUEST['a']) {
    $action_KEY = $_REQUEST['a'];
} else {
    $action_KEY = '5917';
}
#get supporter key from url
$supporter_KEY = $_GET['$u'];
if ($_REQUEST['u']) {
    $supporter_KEY = $_REQUEST['u'];
} else {
    #$supporter_KEY  ='42703842';
}
#get supporter action key from url
if ($_REQUEST['p']) {
    $supporter_action_KEY = $_REQUEST['p'];
} elseif ($_REQUEST['u']) {
    #$supporter_action_KEY ='8979243';
    # look up in supporter_action where supporter_KEY = $U and personal_petition =1
<?php

require_once '../lib/democracyinaction/api.php';
global $DIA;
define('SALSA_NODE', 'salsa.democracyinaction.org');
define('SALSA_USER', '*****@*****.**');
define('SALSA_PASS', 'furmp32');
$DIA = new DemocracyInAction_API(SALSA_NODE, SALSA_USER, SALSA_PASS);
function caclulate_score($supporter_KEY, $max, $avg, $last)
{
    global $DIA;
    $d['gift_string__largest__low'] = $max * 1;
    $d['gift_string__largest__medium'] = $max * 1.5;
    $d['gift_string__largest__high'] = $max * 2;
    $d['gift_string__avg__low'] = $avg * 1;
    $d['gift_string__avg__medium'] = $avg * 1.5;
    $d['gift_string__avg__high'] = $avg * 2;
    $d['gift_string__last__low'] = $last * 1;
    $d['gift_string__last__medium'] = $last * 1.5;
    $d['gift_string__last__high'] = $last * 2;
    $d['key'] = $supporter_KEY;
    #$DIA->save('supporter',$data)
    echo '<pre>';
    print_r($d);
    echo '</pre>';
}
function get_last_donation($supporter_KEY)
{
    global $db;
    $sql = 'select amount, Transaction_Date from donations where supporter_KEY = ' . $supporter_KEY . ' and  recurring_donation_KEY = 0 order by Transaction_Date desc limit 1';
    if ($r['amount'] = 0) {
<?php

# TO DOS
# required fields and form validation
# personal page share features
# letter content line breaks
# thermometer
# updating of action count
# tweet and fb counts populating in sane manner
# encode share codes in twitter bitly url
# paste button copying to buffer
require_once 'dia/api.php';
require_once 'settings.php';
$DIA = new DemocracyInAction_API($node, $user, $password);
#get the action info
#to do, populate the action key by the url slug
if ($_REQUEST['a']) {
    $action_KEY = $_REQUEST['a'];
} else {
    ##GET THE ACTION KEY FROM THE URL SLUG
    $action_KEY = '5917';
}
#$options = array('condition' => array('campaign_slug='.$campaign_slug));
$options = array('condition' => array('action_KEY=' . $action_KEY));
$action = $DIA->get('action', $options);
$a = $action[0];
#get the action content
$options = array('condition' => array('action_KEY=' . $a['action_KEY']));
$con = $DIA->get('action_content', $options);
$options = array('condition' => array('action_content_KEY=' . $con[0]['action_content_KEY']));
$detail = $DIA->get('action_content_detail', $options);
if ($winpay->check_donation_status($donation_key)) {
    $member = WinMember::create_from_supporter($dia_supporter_key);
    $member->create_or_renew($donation_key);
    $member->mark_as_paid_in_dia($dia_supporter_key);
    $member->set_membership_status('active');
    $member->add_to_group($dia_supporter_key, WIN_CURRENT_MEMBERS);
    $member->sync_to_dia();
    if ($winpay->donation_amount >= $sustainer_amount) {
        $member->set_membership_status('sustainer');
        $member->add_to_group($dia_supporter_key, WIN_SUSTAINERS);
    }
    if ($combo || $winpay->donation_amount == '75' || $winpay->donation_amount == '80') {
        trigger_error('combo payment');
        if ($winpay->donation_amount == '75' || $winpay->donation_amount == '80') {
            trigger_error(var_export($member->dia, true));
            $dia = new DemocracyInAction_API(DIA_API_NODE, DIA_API_USERNAME, DIA_API_PASSWORD);
            $dia->authenticate();
            $member->dia =& $dia;
            $member->dia->save('supporter', array('Email' => $member->data->getData('Email'), 'email_trigger_KEYS' => '0,12374', 'USERNAME' => $member->data->getData('Email')));
        }
        //$member->add_to_group($dia_supporter_key, WIN_COMBO_GROUP );
        $member->data->mergeData(array('region' => true));
    }
    ampredirect(WIN_LOGIN_URL);
} else {
    AmpUtility::bail('Sorry, your payment is no longer valid.  Please contact WIN to resolve this issue.');
}
class WinPaymentVerifier
{
    var $membership_cost = 15;
    function WinPaymentVerifier()
<?php

require_once 'dia/api.php';
require_once 'settings.php';
$DIA = new DemocracyInAction_API($node, $user, $password);
$d = $_REQUEST;
$s_a = array('key' => $d['key'], 'personal_petition' => '1', 'personal_message' => $d['personal_message'], 'signature_goal' => $d['signature_goal'], 'email_message' => $d['email_message'], 'facebook_message' => $d['facebook_message'], 'twitter_message' => $d['twitter_message']);
$DIA->save('supporter_action', $s_a);
if ($d['email_trigger_KEYS'] && $d['Email']) {
    $s['email_trigger_KEYS'] = $d['email_trigger_KEYS'];
    $s['Email'] = $d['Email'];
}
if ($d['image']) {
    $s['image'] = $d['image'];
}
$s['key'] = $d['linkKey'];
$DIA->save('supporter', $s);
header('Location: ' . $d['redirect']);
<?php

require_once 'start.php';
// initialize DIA library
require_once APP_ROOT . '/lib/democracyinaction-php/api.php';
$dia_config = $app_config['democracy_in_action'];
$dia = new DemocracyInAction_API($dia_config['node'], $dia_config['login'], $dia_config['password']);
$dia->authenticate();
$dia_groups = $dia->get(Group::dia_object);
if (!$dia_groups) {
    print "auth failed";
    exit;
}
foreach ($dia_groups as $dia_group) {
    $group = GroupPeer::find_or_create_by_dia_key($dia_group);
    $group->save();
}
$groups = GroupPeer::doSelect(new Criteria());
$groups_to_geocode = GroupPeer::geocodable();
foreach ($groups_to_geocode as $group) {
    $group->geocode();
    $group->save();
}