%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /var/www/projetos/rrsos.com.br/
Upload File :
Create Path :
Current File : /var/www/projetos/rrsos.com.br/enviar_cadastro.php

<?php
include_once('libs/activecampaign/ActiveCampaign.class.php');
include_once('inc/config.php');

/*
if( !preg_match('/rrsos/i', $_SERVER['HTTP_REFERER']) ){
	header('Location: '.$url_rrsos);
}
 */
 
 
 
// By default, this sample code is designed to get the result from your ActiveCampaign installation and print out the result
$url = 'https://rrsos.api-us1.com';
 
 
$params = array(
 
    // the API Key can be found on the "Your Settings" page under the "API" tab.
    // replace this with your API Key
    'api_key'      => '383b6c1deb5d943ffbb242ac373bb14e0b356b05983d9039d4a9aec1b6d5218acca9add5',
 
    // this is the action that modifies subscriber info based on the ID you provide
    'api_action'   => 'subscriber_edit',
 
    // define the type of output you wish to get back
    // possible values:
    // - 'xml'  :      you have to write your own XML parser
    // - 'json' :      data is returned in JSON format and can be decoded with
    //                 json_decode() function (included in PHP since 5.2.0)
    // - 'serialize' : data is returned in a serialized format and can be decoded with
    //                 a native unserialize() function
    'api_output'   => 'serialize',
 
  // by default, it overwrites all subscriber data. set to 0 to only update supplied post parameters
  'overwrite'    =>  0,
);
 
// here we define the data we are posting in order to perform an update
$post = array(
    'id'                       => 4, // example subscriber ID to modify
    //'username'               => $params['api_user'], // username cannot be changed!
    'email'                    => 'dmaciel@ongrace.com',
    'first_name'               => 'FirstName',
    'last_name'                => 'LastName',
 
    // any custom fields
    //'field[345,DATAID]'      => 'field value', // where 345 is the field ID, and DATAID is the ID of the subscriber's data row
    //'field[%PERS_1%,0]'      => 'field value', // using the personalization tag instead
 
    // assign to lists:
    'p["1"]'                   => 1, // example list ID
    'status["1"]'              => 0, // 1: active, 2: unsubscribed
    'p["3"]'                   => 3, // example list ID
    'status["3"]'              => 0, // 1: active, 2: unsubscribed
    //'first_name_list[123]'   => 'FirstName', // overwrite global first name with list-specific first name
    //'last_name_list[123]'    => 'LastName', // overwrite global last name with list-specific last name
    //'noresponders[123]'      => 1, // uncomment to set "do not send any future responders"
    // use the folowing only if status=1
    //'instantresponders[123]' => 1, // set to 0 to if you don't want to sent instant autoresponders
    //'lastmessage[123]'       => 1, // uncomment to set "send the last broadcast campaign"
    // use the folowing only if status=2
    //'sendoptout[123]'        => 1, // uncomment to send opt-out confirmation email
    //'unsubreason[1]'         => 'Reason for unsubscribing',
 
    //'p[345]'                 => 345, // some additional lists?
    //'status[345]'            => 1, // some additional lists?
);
 
// This section takes the input fields and converts them to the proper format
$query = "";
foreach( $params as $key => $value ) $query .= $key . '=' . urlencode($value) . '&';
$query = rtrim($query, '& ');
 
// This section takes the input data and converts it to the proper format
$data = "";
foreach( $post as $key => $value ) $data .= $key . '=' . urlencode($value) . '&';
$data = rtrim($data, '& ');
 
// clean up the url
$url = rtrim($url, '/ ');
 
// This sample code uses the CURL library for php to establish a connection,
// submit your request, and show (print out) the response.
if ( !function_exists('curl_init') ) die('CURL not supported. (introduced in PHP 4.0.2)');
 
// If JSON is used, check if json_decode is present (PHP 5.2.0+)
if ( $params['api_output'] == 'json' && !function_exists('json_decode') ) {
    die('JSON not supported. (introduced in PHP 5.2.0)');
}
 
// define a final API request - GET
$api = $url . '/admin/api.php?' . $query;
 
$request = curl_init($api); // initiate curl object
curl_setopt($request, CURLOPT_HEADER, 0); // set to 0 to eliminate header info from response
curl_setopt($request, CURLOPT_RETURNTRANSFER, 1); // Returns response data instead of TRUE(1)
curl_setopt($request, CURLOPT_POSTFIELDS, $data); // use HTTP POST to send form data
curl_setopt($request, CURLOPT_SSL_VERIFYPEER, FALSE); // uncomment if you get no gateway response and are using HTTPS
curl_setopt($request, CURLOPT_FOLLOWLOCATION, true);
 
$response = (string)curl_exec($request); // execute curl fetch and store results in $response
 
// additional options may be required depending upon your server configuration
// you can find documentation on curl options at http://www.php.net/curl_setopt
curl_close($request); // close curl object
 
if ( !$response ) {
    die('Nothing was returned. Do you have a connection to Email Marketing server?');
}
 
// This line takes the response and breaks it into an array using:
// JSON decoder
//$result = json_decode($response);
// unserializer
$result = unserialize($response);
// XML parser...
// ...
 
// Result info that is always returned
echo 'Result: ' . ( $result['result_code'] ? 'SUCCESS' : 'FAILED' ) . '<br />';
echo 'Message: ' . $result['result_message'] . '<br />';
 
// The entire result printed out
echo 'The entire result printed out:<br />';
echo '<pre>';
print_r($result);
echo '</pre>';
 
// Raw response printed out
echo 'Raw response printed out:<br />';
echo '<pre>';
print_r($response);
echo '</pre>';
 
// API URL that returned the result
echo 'API URL that returned the result:<br />';
echo $api;
 
echo '<br /><br />POST params:<br />';
echo '<pre>';
print_r($post);
echo '</pre>';

exit;

//print_r($_SERVER); exit;

if( empty($_POST['fullname']) || empty($_POST['email']) ||
    empty($_POST['field'][5]) || empty($_POST['field'][4]) ||
    empty($_POST['field'][1]) || empty($_POST['nascimento']) ){

    if( !headers_sent() ) {
        header('Location: '.$url_rrsos.'index.php');
    }
}

$arr_fullname = explode(' ', $_POST['fullname']);

if( $_POST['email'] == $_POST['field'][5] ){

    $fields = array();
    $url = 'http://rrsos.activehosted.com/proc.php';
    $ac = new ActiveCampaign(ACTIVECAMPAIGN_URL, ACTIVECAMPAIGN_API_KEY);

    if (!(int)$ac->credentials_test()) {
        print_r("Invalid credentials (URL and API Key).");
        exit();
    }

    foreach( $_POST as $k => $v ){
        if( is_array($v) ){
            foreach( $v as $k1 => $v1 ){
                $fields[$k.'['.$k1.']'] = $v1;
            }
        } else {
            $fields[$k] = $v;
        }
    }

    $resposta = $ac->api('subscriber/view?email='.$_POST['email']);

    if( $resposta->success ){
        $unconfirmed = true;
        $res_upd = $ac->api('subscriber/edit?overwrite=0', array(
            'id' => 4,
            'email' => 'dmaciel@ongrace.com',
            'first_name' => 'antonio',
            'p["1"]' => 1,
            'p["3"]' => 3,
            'status["1"]' => 0, // alterando o status para 'unconfirmed'
            'status["3"]' => 0, // alterando o status para 'unconfirmed'
        ));
        var_dump($resposta);exit;

        foreach($resposta->fields as $k => $v){
            if( preg_match('/(pa(i|í)s|nascimento)/i', $v->title) ){
                if( empty($v->val) ){
                    $unconfirmed = true;
                }
            }
        }

        if( $unconfirmed ){
            // resposta da atualização dos dados do usuario
            $res_upd = $ac->api('subscriber/edit?overwrite=0', array(
                'id' => $resposta->subscriberid,
                'email' => $resposta->email,
                'first_name' => $arr_fullname[0],
                'last_name' => implode(' ', array_slice($arr_fullname, 1)),
                'field[%PERS_1%,0]' => $_POST['field'][1],
                'field[%PERS_2%,0]' => $_POST['field'][2],
                'field[%PERS_3%,0]' => $_POST['field'][3],
                'field[%PERS_4%,0]' => $_POST['field'][4],
                'p['.$resposta->listid.']' => $resposta->listid,
                'status['.$resposta->listid.']' => 0, // alterando o status para 'unconfirmed'
            ));

            if($res_upd->success){
                //header('Location: '.$url_rrsos.'index.php?msg='.urlencode("Cadastro efetuado com sucesso!"));
                header('Location: '.$url_rrsos.'show_message.php?msg='.urlencode("Cadastro efetuado com sucesso!"));
                exit;
            }
        }

        /*
        $fields['f'] = 1007;
        $fields['s'] = '';
        $fields['c'] = 0;
        $fields['m'] = 0;
        $fields['act'] = 'update_request';

         */
        $msg = 'Email já cadastrado.';
    }else{
        $msg = 'Confira seu email. Uma mensagem de ativação foi enviada.';
    }

} else {

    if( !headers_sent() ) {
        //header('Location: '.$url_rrsos.urlencode('index.php?msg=Confira se os emails estão iguais.'));
        header('Location: '.$url_rrsos.urlencode('show_message.php?msg=Confira se os emails estão iguais.'));
    }
}

if( !sendPost($url, $fields) ){
    $msg = 'Não foi possível fazer o cadastro, tente novamente mais tarde.';
}

if( !headers_sent() ) {
    //header('Location: '.$url_rrsos.'index.php?msg='.urlencode($msg));
    header('Location: '.$url_rrsos.'show_message.php?msg='.urlencode($msg));
}

function sendPost($url, $fields){
    $fields_string = '';

    foreach( $fields as $key => $val ){ $fields_string .= $key.'='.$val.'&'; }
    $fields_string = rtrim( $fields_string, '&');

    //print_r($fields_string);
    $ch = curl_init();

    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_POST, count($fields));
    curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);

    $result = curl_exec($ch);

    curl_close($ch);

    return $result;
}

Zerion Mini Shell 1.0