Example #1
0
function _connect_action_process_opt_in($pid, $cid, $token)
{
    if (!is_numeric($pid) || !is_numeric($cid)) {
        drupal_goto('node');
    }
    $parent = node_load($pid);
    $child = node_load($cid);
    if ($parent && $child && connect_get_parent($child) == $pid) {
        $test = connect_value('double_optin_token', $parent, $child, 'child');
        if ($test == $token) {
            connect_value('double_optin_token', $parent, $child, 'child', 'yes');
            node_save($child);
            drupal_set_message(connect_node_options($parent->nid, 'double_optin_message'));
        }
    }
    drupal_goto("node/{$pid}");
}
Example #2
0
function connect_lookup_mp($op = 'lookup', &$parent, &$child)
{
    switch ($op) {
        case 'cache':
            return array('EDID2MP' => 'Federal riding to MP', 'pc2riding_federal_federal_ca' => 'Postal code to Federal riding');
            break;
        case 'requires':
            $return['variables'] = array('makethechange_key' => array('#type' => 'textfield', '#title' => 'Makethechange web service key', '#default_value' => connect_node_options($parent->nid, 'makethechange_key'), '#required' => TRUE), 'mp_lookup_cache' => array('#type' => 'radios', '#title' => 'Cache the lookup data?', '#options' => array('no' => 'No', 'yes' => 'Yes'), '#default_value' => connect_node_options($parent->nid, 'mp_lookup_cache'), '#required' => TRUE));
            $return['child'] = array('postal_code' => 'Postal code', 'lookup_mp_data_edid' => 'Riding');
            return $return;
        case 'validate':
            $code = connect_value('postal_code', $parent, $child, 'child');
            if (!connect_is_postalcode($code)) {
                form_set_error('', 'Please enter a valid postal code.');
            }
            break;
        case 'lookup':
            $return = array();
            $use_cache = connect_node_options($parent->nid, 'mp_lookup_cache') == 'yes';
            $mtc_key = connect_node_options($parent->nid, 'makethechange_key');
            $postalcode = connect_value('postal_code', $parent, $child, 'child');
            $edid = _connect_get_riding($mtc_key, $postalcode, 'federal', 'federal', $use_cache);
            if ($edid) {
                // save the riding in the child node
                connect_value('lookup_mp_data_edid', $parent, $child, 'child', $edid[0]['id']);
                /* Danger! in rare cases there may be > 1 matches: this
                 * just grabs the first one; if this is a problem,
                 * use the CCK MPautocomplete version to allow users to select a riding
                 * or write a two-stage version of the participation form
                 */
                $mp = _connect_get_MP_by_EDID($mtc_key, $edid[0]['id'], $use_cache);
                if (!empty($mp)) {
                    $return['name'] = $mp->mp_name;
                    $return['email'] = $mp->Email;
                    $return['fax'] = $mp->HillFax;
                } else {
                    watchdog('connect', "connect_lookup_mp: MP not found for {$edid['0']}[id]");
                }
            } else {
                watchdog('connect', "connect_lookup_mp: EDID not found for {$postalcode}");
            }
            return $return;
            break;
    }
}