/**
  * Establishes a connection to the salesforce server
  *
  * @param array $config configuration to be used for creating connection
  * @return bool true on success
  */
 protected function _connect(array $config)
 {
     $this->config = $config;
     if (empty($this->config['my_wsdl'])) {
         throw new \ErrorException("A WSDL needs to be provided");
     } else {
         $wsdl = CONFIG . DS . $this->config['my_wsdl'];
     }
     $mySforceConnection = new \SforceEnterpriseClient();
     $mySoapClient = $mySforceConnection->createConnection($wsdl);
     $sflogin = (array) Cache::read('salesforce_login', 'salesforce');
     if (!empty($sflogin['sessionId'])) {
         $mySforceConnection->setSessionHeader($sflogin['sessionId']);
         $mySforceConnection->setEndPoint($sflogin['serverUrl']);
     } else {
         try {
             $mylogin = $mySforceConnection->login($this->config['username'], $this->config['password']);
             $sflogin = array('sessionId' => $mylogin->sessionId, 'serverUrl' => $mylogin->serverUrl);
             Cache::write('salesforce_login', $sflogin, 'salesforce');
         } catch (Exception $e) {
             $this->log("Error logging into salesforce - Salesforce down?");
             $this->log("Username: "******"Password: " . $this->config['password']);
         }
     }
     $this->client = $mySforceConnection;
     $this->connected = true;
     return $this->connected;
 }
Пример #2
0
 static function createSfdcLead()
 {
     include "./config.php";
     $mySforceConnection = new SforceEnterpriseClient();
     $mySforceConnection->createConnection($SfdcWsdl);
     $mySforceConnection->login($SfdcUsername, $SfdcPassword . $SfdcSecurityToken);
     $records = array();
     $records[0] = new stdclass();
     // $records[0]->Company = $_SESSION['userEmail'];
     $records[0]->Company = $_SESSION['userEmail'];
     $records[0]->Email = $_SESSION['userEmail'];
     $records[0]->FirstName = $_SESSION['userFname'];
     $records[0]->LastName = $_SESSION['userLname'];
     $records[0]->Phone = $_SESSION['userPhone'];
     $records[0]->Street = $_SESSION['userAddress1'];
     $records[0]->City = $_SESSION['userCity'];
     $records[0]->Country = $_SESSION['userCountry'];
     $records[0]->State = $_SESSION['userState'];
     $records[0]->PostalCode = $_SESSION['userPostalCode'];
     $records[0]->Description = 'This lead arrived from the website and abandoned the shopping cart flow prior to completing the transaction';
     $records[0]->Status = 'Open';
     $records[0]->LeadSource = 'Web';
     $response = $mySforceConnection->create($records, 'Lead');
     return $response[0];
 }
 /**
  * Initialize method
  *
  * @param  array $config The configuration for the Table.
  * @return void
  */
 public function initialize(array $config)
 {
     parent::initialize($config);
     $this->table(false);
     $this->displayField('Id');
     $this->primaryKey('Id');
     if (!empty($config['connection']->config()['my_wsdl'])) {
         $wsdl = CONFIG . DS . $config['connection']->config()['my_wsdl'];
     } else {
         throw new \Exception("You need to provide a WSDL");
     }
     $mySforceConnection = new \SforceEnterpriseClient();
     $mySoapClient = $mySforceConnection->createConnection($wsdl);
     $sflogin = (array) Cache::read('salesforce_login', 'salesforce');
     if (!empty($sflogin['sessionId'])) {
         $mySforceConnection->setSessionHeader($sflogin['sessionId']);
         $mySforceConnection->setEndPoint($sflogin['serverUrl']);
     } else {
         try {
             $mylogin = $mySforceConnection->login($config['connection']->config()['username'], $config['connection']->config()['password']);
             $sflogin = array('sessionId' => $mylogin->sessionId, 'serverUrl' => $mylogin->serverUrl);
             Cache::write('salesforce_login', $sflogin, 'salesforce');
         } catch (Exception $e) {
             $this->log("Error logging into salesforce from Table - Salesforce down?");
         }
     }
     if (!($sObject = Cache::read($this->name . '_sObject', 'salesforce'))) {
         $sObject = $mySforceConnection->describeSObject($this->name);
         Cache::write($this->name . '_sObject', $sObject, 'salesforce');
     }
     foreach ($sObject->fields as $field) {
         if (substr($field->soapType, 0, 3) != "ens") {
             //we dont want type of ens
             if (substr($field->soapType, 4) == "int") {
                 $type_name = "integer";
             } elseif (substr($field->soapType, 4) == "boolean") {
                 $type_name = "boolean";
             } elseif (substr($field->soapType, 4) == "dateTime" || substr($field->soapType, 4) == "date") {
                 $type_name = "datetime";
             } else {
                 $type_name = "string";
             }
             if ($field->updateable) {
                 $this->updatable_fields[$field->name] = ['type' => $type_name, 'length' => $field->length, 'null' => $field->nillable];
                 $this->selectable_fields[$field->name] = ['type' => $type_name, 'length' => $field->length, 'null' => $field->nillable];
             } else {
                 $this->selectable_fields[$field->name] = ['type' => $type_name, 'length' => $field->length, 'null' => $field->nillable];
             }
         }
     }
     //Cache select fields right away as most likely need them immediately
     Cache::write($this->name . '_selectable_schema', $this->selectable_fields, 'salesforce');
     if (!$this->schema(Cache::read($this->name . '_updatable_schema', 'salesforce'))) {
         $this->schema($this->updatable_fields);
         Cache::write($this->name . '_updatable_schema', $this->updatable_fields, 'salesforce');
     }
 }
function SFDCConnection()
{
    ini_set("soap.wsdl_cache_enabled", "0");
    $USERNAME = "******";
    $PASSWORD = "******";
    $TOKEN = "qhO7UhNTUrYp8XU5eF1SRomDp";
    require_once ABSPATH . '/soapclient/SforceEnterpriseClient.php';
    require_once ABSPATH . '/soapclient/SforceHeaderOptions.php';
    $wsdl = ABSPATH . '/soapclient/eSNenterprise.wsdl.xml';
    $SforceConnection = new SforceEnterpriseClient();
    $SoapClient = $SforceConnection->createConnection($wsdl);
    $login = $SforceConnection->login($USERNAME, $PASSWORD . $TOKEN);
    return $SforceConnection;
}
Пример #5
0
 public function __construct()
 {
     /**
      * Salesforce Enterprise WSDL
      */
     $cred = new SalesforceLogin();
     require_once $_SERVER['DOCUMENT_ROOT'] . '/soapclient/SforceEnterpriseClient.php';
     $enterprise_wsdl = "soapclient/enterprise.wsdl.xml";
     $mySforceConnection = new SforceEnterpriseClient();
     $myConnection = $mySforceConnection->createConnection($enterprise_wsdl);
     $myLogin = $mySforceConnection->login($cred->SFcredentials['usr'], $cred->SFcredentials['pwd'] . $cred->SFcredentials['key']);
     $fields = $mySforceConnection->describeSObject('Lead')->fields;
     $this->sf_fields = $fields;
 }
Пример #6
0
                 }
             }
         }
     }
 }
 /**
  *  Hardcoded Keys
  */
 $usr = '';
 $pss = '';
 $key = '';
 require_once 'soapclient/SforceEnterpriseClient.php';
 $enterprise_wsdl = "soapclient/enterprise.wsdl.xml";
 try {
     $ENT = new SforceEnterpriseClient();
     $ENT_client = $ENT->createConnection($enterprise_wsdl);
     $ENT_login = $ENT->login($usr, $pss . $key);
     $fields = $ENT->describeSObject('Lead')->fields;
     $new_lead[0] = new stdClass();
     foreach ($lead as $key => $value) {
         $new_lead[0]->{$key} = $value;
     }
     // We have some required fields
     $new_lead[0]->Company = 'N/A';
     if (!isset($new_lead[0]->LastName)) {
         if (isset($new_lead[0]->FirstName)) {
             $new_lead[0]->LastName = $new_lead[0]->FirstName;
         } else {
             $new_lead[0]->LastName = 'N/A';
         }
     }
Пример #7
0
     // if/else service status
     debugServiceSeparator($service_id, false);
 }
 // MAILCHIMP
 /**************************************************************************************
  * SALESFORCE API
  **************************************************************************************/
 if (!empty($cfg['salesforce']['username']) && !empty($cfg['salesforce']['password']) && !empty($cfg['salesforce']['accesstoken']) && !empty($cfg['salesforce']['lists'])) {
     $service_id = 'salesforce';
     debugServiceSeparator($service_id, true);
     $service_requirements_status = $cfgenwpapi_obj->checkServiceRequirements($service_id);
     if ($service_requirements_status['status']) {
         include '../api/salesforce/SforceEnterpriseClient.php';
         $mySforceConnection = new SforceEnterpriseClient();
         try {
             $mySforceConnection->createConnection('../api/salesforce/enterprise.wsdl.xml');
             $mySforceConnection->login($cfg[$service_id]['username'], $cfg[$service_id]['password'] . $cfg[$service_id]['accesstoken']);
             foreach ($cfg[$service_id]['lists'] as $list_v) {
                 $list_id = $list_v['list_id'];
                 $merge_vars = array();
                 // FIELDS
                 $records = array();
                 $records[0] = new stdclass();
                 if (isset($list_v['fields']) && $list_v['fields']) {
                     foreach ($list_v['fields'] as $field_v) {
                         $records[0]->{$field_v['list_field_id']} = getElementValue($field_v['element_id']);
                     }
                     try {
                         $sf_addcontact = true;
                         if ($list_v['preventduplicates'] || $list_v['updateexistingcontact'] && !empty($list_v['filterduplicates'])) {
                             $sf_contact_exists_where = '';
Пример #8
0
    <![endif]-->
</head>
<body>
<div class="container">
	<?php 
require_once 'soapclient/SforcePartnerClient.php';
require_once 'soapclient/SforceEnterpriseClient.php';
//define("USERNAME", "*****@*****.**");
//define("PASSWORD", "Apollo007");
//define("SECURITY_TOKEN", "WoyB0DRSHLOesYQG23PMY7xv");
define("USERNAME", "*****@*****.**");
define("PASSWORD", "Turtleorange1!");
define("SECURITY_TOKEN", "f80rEWCCDzHunVCiiWNDayCKM");
try {
    $mySforceConnection = new SforceEnterpriseClient();
    $mySoapClient = $mySforceConnection->createConnection('soapclient/enterprise.wsdl.xml');
    //echo "Connection<pre>"; print_r($mySforceConnection); echo "</pre>";
    // Connection
    $mylogin = $mySforceConnection->login(USERNAME, PASSWORD . SECURITY_TOKEN);
    //echo "Login<pre>"; print_r($mylogin); echo "</pre>";
    // Select Statment
    $Customer = array();
    $Customer[0] = new stdclass();
    $Customer[0]->Customer_Name__c = 'Tusal';
    $Customer[0]->Customer_Email__c = '*****@*****.**';
    /**** Master-Deatil Relation Inserts ****/
    /*echo "<pre>";
    		$query = "SELECT ID , Customer_Name__c FROM CustomerMaster__c WHERE Customer_Name__c='".$Customer[0]->Customer_Name__c."'";
    		$response = $mySforceConnection->query($query);
    		echo "SELECT STATEMENT <br>";
    		
Пример #9
0
        <title>REST/OAuth Example</title>
    </head>
    <body>
        <tt>
<?php 
require_once 'PHPToolkit/soapclient/SforcePartnerClient.php';
require_once 'PHPToolkit/soapclient/SforceEnterpriseClient.php';
define("USERNAME", "***");
define("PASSWORD", "***");
define("SECURITY_TOKEN", "***");
ini_set("soap.wsdl_cache_enabled", "0");
try {
    echo "<table border=\"1\"><tr><td>";
    echo "First with the enterprise client<br/><br/>\n";
    $mySforceConnection = new SforceEnterpriseClient();
    $mySforceConnection->createConnection("PHPToolkit/soapclient/enterprise.wsdl.xml");
    // Simple example of session management - first call will do
    // login, refresh will use session ID and location cached in
    // PHP session
    if (isset($_SESSION['enterpriseSessionId'])) {
        $location = $_SESSION['enterpriseLocation'];
        $sessionId = $_SESSION['enterpriseSessionId'];
        $mySforceConnection->setEndpoint($location);
        $mySforceConnection->setSessionHeader($sessionId);
        echo "Used session ID for enterprise<br/><br/>\n";
    } else {
        $mySforceConnection->login(USERNAME, PASSWORD . SECURITY_TOKEN);
        $_SESSION['enterpriseLocation'] = $mySforceConnection->getLocation();
        $_SESSION['enterpriseSessionId'] = $mySforceConnection->getSessionId();
        echo "Logged in with enterprise<br/><br/>\n";
    }
Пример #10
0
÷<?php 
define("USERNAME", "*****@*****.**");
define("PASSWORD", "*******");
define("SECURITY_TOKEN", "AloffpMAl876xrkc4lhuC1x3");
require_once 'soapclient/SforceEnterpriseClient.php';
require_once 'parsecsv.lib.php';
$mySforceConnection = new SforceEnterpriseClient();
$mySforceConnection->createConnection("Enterprise.wsdl.xml");
$mySforceConnection->login(USERNAME, PASSWORD . SECURITY_TOKEN);
$sObjectIdMap = array();
main(false, $mySforceConnection, $sObjectIdMap);
updateAllObjects($mySforceConnection);
function main($processChildren, $mySforceConnection, &$sObjectIdMap)
{
    $files = scandir('data/');
    foreach ($files as $file) {
        $fieldArray = array();
        echo 'Processing file : ' . $file . "\n";
        $validObj = true;
        try {
            $objName = basename($file, '.csv');
            $describedObj = $mySforceConnection->describeSObject($objName);
        } catch (Exception $e) {
            $validObj = false;
        }
        if ($validObj) {
            $isDetail = false;
            $isRequired = false;
            //loop through fields of object and determine if field should be set in object.
            foreach ($describedObj->fields as $field) {
                //if field is updateable and not a lookup then use field
Пример #11
0
function printSfiCalendar($userName, $pass, $ownerId, $baseUrl, $showDetail)
{
    function calguid($str)
    {
        $charid = strtoupper(md5($str));
        $hyphen = chr(45);
        // "-"
        $uuid = "" . substr($charid, 0, 8) . $hyphen . substr($charid, 8, 4) . $hyphen . substr($charid, 12, 4) . $hyphen . substr($charid, 16, 4) . $hyphen . substr($charid, 20, 12);
        return $uuid;
    }
    function get_timezone_offset($remote_tz, $origin_tz = null)
    {
        if ($origin_tz === null) {
            if (!is_string($origin_tz = date_default_timezone_get())) {
                return false;
                // A UTC timestamp was returned -- bail out!
            }
        }
        $origin_dtz = new DateTimeZone($origin_tz);
        $remote_dtz = new DateTimeZone($remote_tz);
        $origin_dt = new DateTime("now", $origin_dtz);
        $remote_dt = new DateTime("now", $remote_dtz);
        $offset = $origin_dtz->getOffset($origin_dt) - $remote_dtz->getOffset($remote_dt);
        return $offset;
    }
    function escapeText($s)
    {
        $v = str_replace("\r\n", "\n", $s);
        $v = str_replace("\r", "\n", $s);
        $v = str_replace("\t", " ", $v);
        $v = str_replace("\v", " ", $v);
        $v = str_replace("\\", "\\\\", $v);
        $v = str_replace("\n", "\\n", $v);
        $v = str_replace(";", "\\;", $v);
        $v = str_replace(",", "\\,", $v);
        return $v;
    }
    try {
        $calGuid = calguid($userName . $ownerId);
        $mySforceConnection = new SforceEnterpriseClient();
        $mySoapClient = $mySforceConnection->createConnection(SOAP_CLIENT_BASEDIR . '/enterprise.wsdl.xml');
        $mylogin = $mySforceConnection->login($userName, $pass);
        $nowDate = new DateTime();
        $startDate = clone $nowDate;
        $startDate = $startDate->sub(new DateInterval('P366D'));
        $endDate = clone $nowDate;
        $endDate = $endDate->add(new DateInterval('P400D'));
        $query = 'SELECT Id, Name, TimeZoneSidKey from User where Id = \'' . $ownerId . '\'';
        $users = $mySforceConnection->query($query);
        if (count($users->records) == 0) {
            header('HTTP/1.1 403 Forbidden');
            echo 'no data';
            exit;
        }
        $query = '
SELECT
   Id
 , Subject
 , ActivityDateTime
 , StartDateTime
 , EndDateTime
 , Location ' . ($showDetail ? ' , Description ' : '') . '
 , IsAllDayEvent
 , OwnerId
from Event
where
      OwnerId = \'' . $ownerId . '\'
  and StartDateTime >= ' . gmdate('Y-m-d\\TH:i:s\\Z', $startDate->getTimestamp()) . '
  and StartDateTime <  ' . gmdate('Y-m-d\\TH:i:s\\Z', $endDate->getTimestamp()) . '
order by StartDateTime limit 10000';
        $response = $mySforceConnection->query($query);
        header("Cache-Control: no-cache");
        header('Content-type: text/plain; charset=utf-8');
        //header('Content-Disposition: attachment; filename="' . $calGuid . '.ics"');
        $tzoffset = get_timezone_offset('UTC', $users->records[0]->TimeZoneSidKey);
        $tzoffset = (int) ($tzoffset / 3600) * 100 + (int) ($tzoffset / 60) % 60;
        echo "BEGIN:VCALENDAR\r\n", "PRODID:My Cal\r\n", "VERSION:2.0\r\n", "METHOD:PUBLISH\r\n", "CALSCALE:GREGORIAN\r\n", "BEGIN:VTIMEZONE\r\n", "TZID:", $users->records[0]->TimeZoneSidKey, "\r\n", "BEGIN:STANDARD\r\n", "DTSTART:19700101T000000Z\r\n", "TZOFFSETFROM:", sprintf('%1$+05d', $tzoffset), "\r\n", "TZOFFSETTO:", sprintf('%1$+05d', $tzoffset), "\r\n", "END:STANDARD\r\n", "END:VTIMEZONE\r\n", "X-WR-CALNAME:", escapeText($users->records[0]->Name), "'s calendar\r\n", "X-WR-CALDESC:", escapeText($users->records[0]->Name), "'s calendar\r\n", "X-WR-RELCALID:", $calGuid, "\r\n", "X-WR-TIMEZONE:Asia/Tokyo\r\n";
        foreach ($response->records as $record) {
            $dateFmt = 'Ymd\\THis\\Z';
            $timeAdd = 0;
            if ($record->IsAllDayEvent) {
                $dateFmt = 'Ymd';
                $timeAdd = 3600 * 24;
            }
            echo "BEGIN:VEVENT\r\n", "UID:mycal/", $calGuid, "/", $record->Id, "\r\n", !$record->IsAllDayEvent ? "DTSTAMP:" . gmdate('Ymd\\THis\\Z', strtotime($record->StartDateTime)) . "\r\n" : '', "DTSTART:", gmdate($dateFmt, strtotime($record->StartDateTime)), "\r\n", "DTEND:", gmdate($dateFmt, strtotime($record->EndDateTime) + $timeAdd), "\r\n", "SUMMARY:", escapeText($record->Subject), "\r\n", "DESCRIPTION:", $baseUrl, "/", $record->Id, $showDetail && isset($record->Description) ? '\\n\\n' . escapeText($record->Description) : '', "\r\n", "LOCATION:", isset($record->Location) ? escapeText($record->Location) : '', "\r\n", "END:VEVENT\r\n";
        }
        echo "END:VCALENDAR\r\n";
    } catch (Exception $e) {
        echo $e;
        exit;
    }
}
Пример #12
0
<?php

require './codes.php';
// contains the DB credentials and connection
require_once './Force.com-Toolkit-for-PHP/soapclient/SforceEnterpriseClient.php';
$mySforceConnection = new SforceEnterpriseClient();
$wsdl = './test.enterprise.wsdl.xml';
//$wsdl = './enterprise.wsdl.xml';
$mySforceConnection->createConnection($wsdl);
$mySforceConnection->login(USERNAME, PASSWORD . SECURITY_TOKEN);
$C = new Codes();
$codes = $C->generateMany($number_of_codes);
$prep = $C->prepareCodesForInsert($codes);
//	echo 'Prefix : ' .$C->prefix .'<br />';
//	echo '<pre>';
//	print_r($codes);
//	echo '</pre>';
/************************** INSERT DATA INTO SF **************************/
$records = array();
$i = 0;
foreach ($prep as $code) {
    $records[$i] = new stdclass();
    $records[$i]->Contract_Deal_Attribute__c = $cda;
    $records[$i]->Voucher_Code__c = $code;
    $i++;
}
$response = $mySforceConnection->create($records, 'External_Voucher_Code__c');
print_r(json_encode($response));
Пример #13
0
function SF_Account_Upsert226($entry, $form)
{
    global $wpdb;
    ini_set("soap.wsdl_cache_enabled", "0");
    $USERNAME = "******";
    //- variable that contains your Salesforce.com username (must be in the form of an email)
    $PASSWORD = "******";
    //- variable that contains your Salesforce.com password
    $TOKEN = "qhO7UhNTUrYp8XU5eF1SRomDp";
    //- variable that contains your Salesforce.com password
    require_once ABSPATH . '/soapclient/SforceEnterpriseClient.php';
    require_once ABSPATH . '/soapclient/SforceHeaderOptions.php';
    // Salesforce Login information
    $wsdl = ABSPATH . '/soapclient/eSNenterprise.wsdl.xml';
    $mySforceConnectionu = new SforceEnterpriseClient();
    $mySoapClient = $mySforceConnectionu->createConnection($wsdl);
    $mylogin = $mySforceConnectionu->login($USERNAME, $PASSWORD . $TOKEN);
    $loginname = $entry[30];
    $thenewuser = get_user_by('login', $loginname);
    if ($thenewuser) {
        $user_id = $thenewuser->ID;
    } else {
        sleep(1);
        $thenewuser = get_user_by('login', $loginname);
        $user_id = $thenewuser->ID;
    }
    $newperson = array();
    $newperson['WP_Unique_ID__c'] = $user_id;
    $newperson['WP_ID__c'] = $user_id;
    $newperson['Source__c'] = $_SERVER["SERVER_NAME"];
    $newperson['Site_Registered_On__c'] = $_SERVER["SERVER_NAME"];
    $wp_subreq_id = '21' . $entry[4];
    //21 = digital ecn [4] is email
    if (!empty($entry[4])) {
        $newperson['PersonEmail'] = $entry[4];
        $newSubReq['Email__c'] = $entry[4];
        $newperson['Email_as_ExternalID__c'] = $entry[4];
    }
    if (!empty($entry[1])) {
        $newperson['FirstName'] = $entry[1];
        $newSubReq['First_Name__c'] = $entry[1];
    }
    if (!empty($entry[2])) {
        $newperson['LastName'] = $entry[2];
        $newSubReq['Last_Name__c'] = $entry[2];
    }
    if (!empty($entry[61])) {
        $newperson['Unique_Title__c'] = $entry[61];
        $newSubReq['Unique_Title__c'] = $entry[61];
    }
    if (!empty($entry[5])) {
        $newperson['PersonTitle'] = $entry[5];
        $newSubReq['Title__c'] = $entry[5];
    }
    $OptedOutflag = 0;
    if (!empty($entry['57.1'])) {
        $newperson['eSN_This_Week__c'] = $entry['57.1'];
        if ($entry['57.1'] == 'Subscribed') {
            $OptedOutflag = 1;
        }
    } else {
        $newperson['eSN_This_Week__c'] = "Not Subscribed";
    }
    if (!empty($entry['57.2'])) {
        $newperson['eSN_Today__c'] = $entry['57.2'];
        if ($entry['57.2'] == 'Subscribed') {
            $OptedOutflag = 1;
        }
    } else {
        $newperson['eSN_Today__c'] = "Not Subscribed";
    }
    if (!empty($entry['57.3'])) {
        $newperson['eSN_IT_School_Leadership__c'] = $entry['57.3'];
        if ($entry['57.3'] == 'Subscribed') {
            $OptedOutflag = 1;
        }
    } else {
        $newperson['eSN_IT_School_Leadership__c'] = "Not Subscribed";
    }
    if (!empty($entry['57.4'])) {
        /* Check on this field */
        $newperson['MyeCN_EdTech_Leadership__c'] = $entry['57.4'];
        if ($entry['57.4'] == 'Subscribed') {
            $OptedOutflag = 1;
        }
    } else {
        $newperson['MyeCN_EdTech_Leadership__c'] = "Not Subscribed";
    }
    if (!empty($entry['57.5'])) {
        $newperson['eCN_Today__c'] = $entry['57.5'];
        if ($entry['57.5'] == 'Subscribed') {
            $OptedOutflag = 1;
        }
    } else {
        $newperson['eCN_Today__c'] = "Not Subscribed";
    }
    if (!empty($entry['57.6'])) {
        $newperson['eCN_This_Week__c'] = $entry['57.6'];
        if ($entry['57.6'] == 'Subscribed') {
            $OptedOutflag = 1;
        }
    } else {
        $newperson['eCN_This_Week__c'] = "Not Subscribed";
    }
    if (!empty($entry['57.7'])) {
        $newperson['eCN_IT_School_Leadership__c'] = $entry['57.7'];
        if ($entry['57.7'] == 'Subscribed') {
            $OptedOutflag = 1;
        }
    } else {
        $newperson['eCN_IT_School_Leadership__c'] = "Not Subscribed";
    }
    if (!empty($entry['57.8'])) {
        $newperson['eClassroom_News__c'] = $entry['57.8'];
        if ($entry['57.8'] == 'Subscribed') {
            $OptedOutflag = 1;
        }
    } else {
        $newperson['eClassroom_News__c'] = "Not Subscribed";
    }
    $newperson['eSN_Offers__c'] = "Not Subscribed";
    $newperson['Partner_Offers__c'] = "Not Subscribed";
    $newperson['eCN_Offers__c'] = "Not Subscribed";
    $newperson['eCN_Partners__c'] = "Not Subscribed";
    //special update unsub flag if they subscribe to anything...  else do not change it.
    if ($OptedOutflag == 1) {
        $newperson['PersonHasOptedOutOfEmail'] = false;
    }
    $upsertResponse = $mySforceConnectionu->upsert('Email_as_ExternalID__c', array($newperson), 'Account');
    if ($upsertResponse->success == 1) {
        //Saved for later use
        mail('*****@*****.**', '226 SF Subscription request success', 'line 138');
    } else {
        $upsertResponse = $mySforceConnectionu->upsert('Email_as_ExternalID__c', array($newperson), 'Account');
        mail('*****@*****.**', '226 SF Subscription request failed', 'line 142');
    }
    $formsuccess = validateint($_GET['success']);
}
 /**
  * Use WSDL for basic fields first of all
  * passes the salesforce credentals for login
  * @return boolean True on success, false on failure
  */
 public function connect()
 {
     //Vendor loading seems to be picky using App::import
     require_once App::Path('Vendor')[0] . 'salesforce/soapclient/SforceEnterpriseClient.php';
     if (empty($this->config['my_wsdl'])) {
         $wsdl = App::Path('Vendor')[0] . 'salesforce/soapclient/' . $this->config['standard_wsdl'];
     } else {
         $wsdl = APP . "Config" . DS . $this->config['my_wsdl'];
     }
     $mySforceConnection = new SforceEnterpriseClient();
     //Dont forget to Change your API version in here!
     $mySoapClient = $mySforceConnection->createConnection($wsdl);
     $sflogin = (array) Cache::read('salesforce_login', 'short');
     if (!empty($sflogin['sessionId'])) {
         $mySforceConnection->setSessionHeader($sflogin['sessionId']);
         $mySforceConnection->setEndPoint($sflogin['serverUrl']);
     } else {
         $mylogin = $mySforceConnection->login($this->config['username'], $this->config['password']);
         $sflogin = array('sessionId' => $mylogin->sessionId, 'serverUrl' => $mylogin->serverUrl);
         Cache::write('salesforce_login', $sflogin, 'short');
     }
     $this->client = $mySforceConnection;
     $this->connected = true;
     return $this->connected;
 }
Пример #15
0
function SF_Account_Upsert166($entry, $form)
{
    //upload information to salesforce from the final form.
    global $wpdb;
    ini_set("soap.wsdl_cache_enabled", "0");
    $USERNAME = "******";
    //- variable that contains your Salesforce.com username (must be in the form of an email)
    $PASSWORD = "******";
    //- variable that contains your Salesforce.com password
    $TOKEN = "qhO7UhNTUrYp8XU5eF1SRomDp";
    //- variable that contains your Salesforce.com password
    require_once ABSPATH . '/soapclient/SforceEnterpriseClient.php';
    require_once ABSPATH . '/soapclient/SforceHeaderOptions.php';
    // Salesforce Login information
    $wsdl = ABSPATH . '/soapclient/eSNenterprise.wsdl.xml';
    $mySforceConnectionu = new SforceEnterpriseClient();
    $mySoapClient = $mySforceConnectionu->createConnection($wsdl);
    $mylogin = $mySforceConnectionu->login($USERNAME, $PASSWORD . $TOKEN);
    $loginname = $entry[30];
    $thenewuser = get_user_by('login', $loginname);
    if ($thenewuser) {
        $user_id = $thenewuser->ID;
    } else {
        sleep(1);
        $thenewuser = get_user_by('login', $loginname);
        $user_id = $thenewuser->ID;
    }
    $newperson = array();
    $newperson['WP_Unique_ID__c'] = $user_id;
    $newperson['WP_ID__c'] = $user_id;
    $newperson['Source__c'] = $_SERVER["SERVER_NAME"];
    $newperson['Site_Registered_On__c'] = $_SERVER["SERVER_NAME"];
    $wp_subreq_id = '21' . $entry[4];
    //21 = digital ecn [4] is email
    $newSubReq = array();
    // array for subscription
    $newSubReq['Source__c'] = "Web";
    //$newSubReq['WP_ID__c'] = $user_id;
    $newSubReq['WP_ID__c'] = substr($wp_subreq_id, 0, 20);
    //need to limit length to 20 characters
    $newSubReq["Sub_Status__c"] = 'Pending';
    $newSubReq['Personal_Question__c'] = $entry[59];
    $newSubReq['Promo_Code__c'] = "Registration";
    $newSubReq['Renewal_Link__c'] = substr(${$entry}[18], 0, 254);
    $newSubReq['Request_Date__c'] = date("Y-m-d");
    $newSubReq['Request_URL__c'] = $_SERVER["SERVER_NAME"];
    $newSubReq["Name"] = 'eCampus News Digital Subscription';
    if (!empty($entry[30])) {
        $newperson['WP_Login__c'] = strtolower($entry[30]);
    }
    if (!empty($entry[4])) {
        $newperson['PersonEmail'] = $entry[4];
        $newSubReq['Email__c'] = $entry[4];
        $newperson['Email_as_ExternalID__c'] = $entry[4];
        //12-20-2011
    }
    if (!empty($entry[1])) {
        $newperson['FirstName'] = $entry[1];
        $newSubReq['First_Name__c'] = $entry[1];
    }
    if (!empty($entry[2])) {
        $newperson['LastName'] = $entry[2];
        $newSubReq['Last_Name__c'] = $entry[2];
    }
    if (!empty($entry[61])) {
        $newperson['Unique_Title__c'] = $entry[61];
        $newSubReq['Unique_Title__c'] = $entry[61];
    }
    if (!empty($entry[3])) {
        $newperson['Organization__c'] = $entry[3];
        $newSubReq['Organization__c'] = $entry[3];
    }
    if (!empty($entry[5])) {
        $newperson['PersonTitle'] = $entry[5];
        $newSubReq['Title__c'] = $entry[5];
    }
    if (!empty($entry[6])) {
        $newperson['Company_Type__c'] = $entry[6];
        $newSubReq['Organization_Type__c'] = $entry[6];
    }
    if (!empty($entry[7])) {
        $newperson['PersonMailingStreet'] = $entry[7];
        $newSubReq['Address1__c'] = $entry[7];
    }
    if (!empty($entry[8])) {
        $newperson['Mailing_Address_2__c'] = $entry[8];
        $newSubReq['Address2__c'] = $entry[8];
    }
    if (!empty($entry[9])) {
        $newperson['PersonMailingCity'] = $entry[9];
        $newSubReq['city__c'] = $entry[9];
    }
    if (!empty($entry[10])) {
        $newperson['PersonMailingState'] = $entry[10];
        $newSubReq['State__c'] = $entry[10];
    }
    if (!empty($entry[12])) {
        $newperson['PersonMailingPostalCode'] = $entry[12];
        $newSubReq['Zip__c'] = $entry[12];
    }
    if (!empty($entry[13])) {
        $newperson['PersonMailingCountry'] = $entry[13];
        $newSubReq['Country__c'] = $entry[13];
    }
    if (!empty($entry[22])) {
        $newperson['Phone'] = $entry[22];
        $newSubReq['Phone__c'] = $entry[22];
    }
    if (!empty($entry[31])) {
        $newperson['Fax'] = $entry[31];
        $newSubReq['Fax__c'] = $entry[31];
    }
    if (!empty($entry[32])) {
        $newperson['Grade_Level__c'] = $entry[32];
    } else {
        $newperson['Grade_Level__c'] = "";
    }
    if (!empty($entry[33])) {
        $newperson['Subject_Taught__c'] = $entry[33];
    } else {
        $newperson['Subject_Taught__c'] = "";
    }
    if (!empty($entry[14])) {
        $newSubReq['Personal_Answer__c'] = $entry[14];
    }
    $OptedOutflag = 0;
    if (!empty($entry['57.1'])) {
        $newperson['ecn_today__c'] = $entry['57.1'];
        if ($entry['57.1'] == 'Subscribed') {
            $OptedOutflag = 1;
        }
    } else {
        $newperson['ecn_today__c'] = "Not Subscribed";
    }
    if (!empty($entry['57.2'])) {
        $newperson['eCN_This_Week__c'] = $entry['57.2'];
        if ($entry['57.2'] == 'Subscribed') {
            $OptedOutflag = 1;
        }
    } else {
        $newperson['eCN_This_Week__c'] = "Not Subscribed";
    }
    //	<span style="cursor:Pointer;" title="Weekly on Wednesday"> eCampus IT Leadership<img src="/wp-content/themes/advanced-newspaper/images/info14.gif" /></span>|Subscribed
    if (!empty($entry['57.3'])) {
        $newperson['eCN_IT_School_Leadership__c'] = $entry['57.3'];
        if ($entry['57.3'] == 'Subscribed') {
            $OptedOutflag = 1;
        }
    } else {
        $newperson['eCN_IT_School_Leadership__c'] = "Not Subscribed";
    }
    if (!empty($entry['57.4'])) {
        $newperson['eCN_Offers__c'] = $entry['57.4'];
        if ($entry['57.4'] == 'Subscribed') {
            $OptedOutflag = 1;
        }
    } else {
        $newperson['eCN_Offers__c'] = "Not Subscribed";
    }
    if (!empty($entry['57.5'])) {
        $newperson['eCN_Partners__c'] = $entry['57.5'];
        if ($entry['57.5'] == 'Subscribed') {
            $OptedOutflag = 1;
        }
    } else {
        $newperson['eCN_Partners__c'] = "Not Subscribed";
    }
    $newperson['eSN_Today__c'] = "Not Subscribed";
    $newperson['eSN_Tools_For_Schools__c'] = "Not Subscribed";
    $newperson['Ed_Resource_Alert__c'] = "Not Subscribed";
    $newperson['eClassroom_News__c'] = "Not Subscribed";
    $newperson['eSN_This_Week__c'] = "Not Subscribed";
    $newperson['eSN_Offers__c'] = "Not Subscribed";
    $newperson['Partner_Offers__c'] = "Not Subscribed";
    //special update unsub flag if they subscribe to anything...  else do not change it.
    if ($OptedOutflag == 1) {
        $newperson['PersonHasOptedOutOfEmail'] = false;
    }
    $upsertResponse = $mySforceConnectionu->upsert('Email_as_ExternalID__c', array($newperson), 'Account');
    //When
    if ($upsertResponse->success == 1) {
        update_user_meta($user_id, "sfid", $upsertResponse->id);
        update_user_meta($user_id, "PersonContactId", $upsertResponse->id);
        $newSubReq['Person_Account__c'] = $upsertResponse->id;
        //now that we have a new user account put in the my eschool news data if it is set
        $esm_change = '6|1|';
        $seperator = ',';
        if (isset($_POST[input_54_1]) and $_POST[input_54_1] == 213) {
            $esm_change .= '213,';
        }
        if (isset($_POST[input_54_2]) and $_POST[input_54_2] == 27) {
            $esm_change .= '27,';
        }
        if (isset($_POST[input_54_3]) and $_POST[input_54_3] == 4) {
            $esm_change .= '4,';
        }
        if (isset($_POST[input_54_4]) and $_POST[input_54_4] == 5351) {
            $esm_change .= '5351,';
        }
        if (isset($_POST[input_54_5]) and $_POST[input_54_5] == 2303) {
            $esm_change .= '2303,';
        }
        if (isset($_POST[input_54_6]) and $_POST[input_54_6] == 43) {
            $esm_change .= '43,';
        }
        if (isset($_POST[input_54_7]) and $_POST[input_54_7] == 215) {
            $esm_change .= '215,';
        }
        if (isset($_POST[input_54_8]) and $_POST[input_54_8] == 4217) {
            $esm_change .= '4217,';
        }
        if (isset($_POST[input_54_9]) and $_POST[input_54_9] == 28) {
            $esm_change .= '28,';
        }
        if (isset($_POST[input_54_11]) and $_POST[input_54_11] == 9) {
            $esm_change .= '9,';
        }
        if (isset($_POST[input_54_12]) and $_POST[input_54_12] == 26) {
            $esm_change .= '26,';
        }
        if (isset($_POST[input_54_13]) and $_POST[input_54_13] == 872) {
            $esm_change .= '872,';
        }
        if (isset($_POST[input_54_14]) and $_POST[input_54_14] == 3) {
            $esm_change .= '3,';
        }
        if (isset($_POST[input_54_15]) and $_POST[input_54_15] == 11) {
            $esm_change .= '11,';
        }
        $esm_change = trim($esm_change, $seperator);
        $key = '_myesm_esn';
        $single = true;
        update_user_meta($user_id, $key, $esm_change);
        //we did it so keep little data on the server...
    } else {
        //try again in one second...
        sleep(1);
        $upsertResponse = $mySforceConnectionu->upsert('Email_as_ExternalID__c', array($newperson), 'Account');
        if ($upsertResponse->success == 1) {
            update_user_meta($user_id, "sfid", $upsertResponse->id);
            update_user_meta($user_id, "PersonContactId", $upsertResponse->id);
            $newSubReq['Person_Account__c'] = $upsertResponse->id;
            //now that we have a new user account put in the my eschool news data if it is set
            $esm_change = '6|1|';
            $seperator = ',';
            if (isset($_POST[input_54_1]) and $_POST[input_54_1] == 213) {
                $esm_change .= '213,';
            }
            if (isset($_POST[input_54_2]) and $_POST[input_54_2] == 27) {
                $esm_change .= '27,';
            }
            if (isset($_POST[input_54_3]) and $_POST[input_54_3] == 4) {
                $esm_change .= '4,';
            }
            if (isset($_POST[input_54_4]) and $_POST[input_54_4] == 5351) {
                $esm_change .= '5351,';
            }
            if (isset($_POST[input_54_5]) and $_POST[input_54_5] == 2303) {
                $esm_change .= '2303,';
            }
            if (isset($_POST[input_54_6]) and $_POST[input_54_6] == 43) {
                $esm_change .= '43,';
            }
            if (isset($_POST[input_54_7]) and $_POST[input_54_7] == 215) {
                $esm_change .= '215,';
            }
            if (isset($_POST[input_54_8]) and $_POST[input_54_8] == 4217) {
                $esm_change .= '4217,';
            }
            if (isset($_POST[input_54_9]) and $_POST[input_54_9] == 28) {
                $esm_change .= '28,';
            }
            if (isset($_POST[input_54_11]) and $_POST[input_54_11] == 9) {
                $esm_change .= '9,';
            }
            if (isset($_POST[input_54_12]) and $_POST[input_54_12] == 26) {
                $esm_change .= '26,';
            }
            if (isset($_POST[input_54_13]) and $_POST[input_54_13] == 872) {
                $esm_change .= '872,';
            }
            if (isset($_POST[input_54_14]) and $_POST[input_54_14] == 3) {
                $esm_change .= '3,';
            }
            if (isset($_POST[input_54_15]) and $_POST[input_54_15] == 11) {
                $esm_change .= '11,';
            }
            $esm_change = trim($esm_change, $seperator);
            $key = '_myesm_esn';
            $single = true;
            update_user_meta($user_id, $key, $esm_change);
        } else {
            //mail('*****@*****.**','SF User UPloaded FAILED 2nd try',print_r($sfaccountresponse));
        }
    }
    if (!empty($entry[48])) {
        //check if they want the pub, if so upload it, in a custom object so we cannot just add it if it is eSchool News.
        if ($entry[48] == 'Yes') {
            // add subscription
            $upsertResponse2 = $mySforceConnectionu->upsert('WP_ID__c', array($newSubReq), 'Subscription_Request__c');
            if ($upsertResponse2->success == 1) {
            } else {
                //try again
                sleep(1);
                $upsertResponse2 = $mySforceConnectionu->upsert('WP_ID__c', array($newSubReq), 'Subscription_Request__c');
            }
        }
    }
    $user_login = $entry[30];
    //use the input if of the username
    $user_pass = $entry[47];
    //use the input if of the password
    //pass the above to the wp_signon function
    $user = wp_signon(array('user_login' => $user_login, 'user_password' => $user_pass, 'remember' => true));
    //check if we need to give a message.
    if (!empty($entry[48]) and $entry[48] == 'No') {
        if ($upsertResponse->success == 1) {
            if ($_GET['redirect_to']) {
                $redirectto = $_GET['redirect_to'];
                $reditchk = strpos($redirectto, "eschoolnews");
                if ($reditchk > 1) {
                    //we are ok no need to do anything...
                } else {
                    $redirectto = 'http://www.eschoolnews.com/';
                }
                wp_safe_redirect($redirectto);
                sleep(2);
                exit;
                break;
            }
        }
    } else {
        if (!empty($entry[48])) {
            if ($upsertResponse2->success == 1) {
                if ($_GET['redirect_to']) {
                    $redirectto = $_GET['redirect_to'];
                    $reditchk = strpos($redirectto, "eschoolnews");
                    if ($reditchk > 1) {
                        //we are ok no need to do anything...
                    } else {
                        $redirectto = 'http://www.eschoolnews.com/';
                    }
                    wp_safe_redirect($redirectto);
                    sleep(2);
                    exit;
                    break;
                }
            }
        }
    }
    $formsuccess = validateint($_GET['success']);
}
Пример #16
0
function SF_Account_Upsert($entry, $form)
{
    global $wpdb;
    $user_email = $entry[4];
    ini_set("soap.wsdl_cache_enabled", "0");
    $USERNAME = "******";
    //- variable that contains your Salesforce.com username (must be in the form of an email)
    $PASSWORD = "******";
    //- variable that contains your Salesforce.com password
    $TOKEN = "qhO7UhNTUrYp8XU5eF1SRomDp";
    //- variable that contains your Salesforce.com password
    require_once ABSPATH . '/soapclient/SforceEnterpriseClient.php';
    require_once ABSPATH . '/soapclient/SforceHeaderOptions.php';
    // Salesforce Login information
    $wsdl = ABSPATH . '/soapclient/eSNenterprise.wsdl.xml';
    $mySforceConnectionu = new SforceEnterpriseClient();
    $mySoapClient = $mySforceConnectionu->createConnection($wsdl);
    $mylogin = $mySforceConnectionu->login($USERNAME, $PASSWORD . $TOKEN);
    //determine site we are on - ecampus, eclassroom, or enews
    $sitesource = $entry[26];
    $entrysubtype = $entry[21];
    if ($entrysubtype == 'Print') {
        $pubsubtype = "Print";
        $pubforid = 1;
    } else {
        $pubsubtype = "Digital";
        $pubforid = 2;
    }
    if ($sitesource !== "") {
        $school = strpos($sitesource, "eschoolnews");
        $campus = strpos($sitesource, "ecampusnews");
        $classroom = strpos($sitesource, "eclassroomnews");
    } else {
        $school = strpos($_SERVER["SERVER_NAME"], "eschoolnews");
        $campus = strpos($_SERVER["SERVER_NAME"], "ecampusnews");
        $classroom = strpos($_SERVER["SERVER_NAME"], "eclassroomnews");
    }
    if ($school !== false) {
        $name = 'eSchoolNews ' . $pubsubtype . ' Subscription';
        $linksource = "eschoolnews";
        $pubforid = $pubforid . '1';
    } elseif ($campus !== false) {
        $name = 'eCampusNews ' . $pubsubtype . ' Subscription';
        $linksource = "ecampusnews";
        $pubforid = $pubforid . '2';
    } elseif ($classroom !== false) {
        $newSubReq["Name"] = 'eClassroomNews ' . $pubsubtype . ' Subscription';
        $linksource = "eclassroomnews";
        $pubforid = $pubforid . '3';
    } else {
        $name = 'Unknown';
        $linksource = "Unk";
        $pubforid = $pubforid . '4';
    }
    //query sfdc to see if user exists based on email address
    $sfaccountdataquery = "Select Id, WP_Unique_ID__c from Account where Email_as_ExternalID__c ='" . $user_email . "' and IsPersonAccount=true";
    $sfaccountresponse = $mySforceConnectionu->query($sfaccountdataquery);
    $wp_id = "";
    //create array for account to get upserted
    $newperson = array();
    if (count($sfaccountresponse->records) > 0) {
        $wp_id = $sfaccountresponse->records[0]->WP_Unique_ID__c;
    } else {
        //see if user is in WP and get id
        $wp_id = $wpdb->get_var($wpdb->prepare("SELECT ID FROM {$WPDB->USERS} WHERE USER_EMAIL='" . $user_email . "'"));
        $newperson['Source__c'] = $_SERVER["SERVER_NAME"];
        //only want to populate source when first creating person account
    }
    if (is_null($wp_id)) {
        $wp_id = $user_email;
    }
    $newperson['WP_Unique_ID__c'] = $wp_id;
    //query sfdc subscription request object to see if there is an existing pending subscription request
    $sfsubreqdataquery = "Select Id, wp_id__c, sub_status__c, Title__c, name from Subscription_Request__c where Email__c = '" . $user_email . "' and Sub_Status__c = 'Pending' and name = '" . $name . "'";
    $sfsubreqresponse = $mySforceConnectionu->query($sfsubreqdataquery);
    if (count($sfsubreqresponse->records) > 0) {
        $wp_subreq_id = $pubforid . $sfsubreqresponse->records[0]->WP_ID__c;
    } else {
        //there is no sub request record, need to create an external id
        //echo 'No Pending'.PHP_EOL;
        $sfcountquery = "Select id from Subscription_Request__c where Email__c = '" . $user_email . "'";
        $sfcountresponse = $mySforceConnectionu->query($sfcountquery);
        //echo 'count '.$sfcountresponse->size;
        $reccount = $sfcountresponse->size + 1;
        $wp_subreq_id = $pubforid . $user_email;
        //$wp_subreq_id = $pubforid . $reccount.$user_email;
    }
    //create new array for subscription request to be upserted
    $newSubReq = array();
    $newSubReq['Source__c'] = "Web";
    $newSubReq['WP_ID__c'] = substr($wp_subreq_id, 0, 20);
    //need to limit length to 20 characters
    //echo $newSubReq['WP_ID__c'].PHP_EOL.PHP_EOL;
    $newSubReq["Sub_Status__c"] = 'Pending';
    $newSubReq['Personal_Question__c'] = "What was your high school mascot?";
    $newSubReq['Request_URL__c'] = $_SERVER["SERVER_NAME"];
    $newSubReq["Name"] = $name;
    $newSubReq['Request_Date__c'] = date("Y-m-d");
    $sfFEIDquery = "Select feid__c, wp_id__c from Subscription_Request__c where Email__c = '" . $user_email . "' and Sub_Status__c = 'Processed' and name = '" . $name . "'";
    $sfFEIDresponse = $mySforceConnectionu->query($sfFEIDquery);
    if (count($sfFEIDresponse->records) > 0) {
        //echo 'Processed Found'.PHP_EOL;
        //echo 'wp id = '.$sfFEIDresponse->records[0]->WP_ID__C.PHP_EOL;
        $newSubReq['FEID__c'] = $sfFEIDresponse->records[0]->FEID__c;
    }
    if (!empty($entry[4])) {
        //if (strpos($entry[4], 'esmnoemailsupplied') !== false) {
        $newperson['PersonEmail'] = $entry[4];
        $newSubReq['Email__c'] = $entry[4];
        $newperson['Email_as_ExternalID__c'] = $entry[4];
        //12-20-2011
        //}
    }
    if (!empty($entry[1])) {
        $newperson['FirstName'] = $entry[1];
        $newSubReq['First_Name__c'] = $entry[1];
    }
    if (!empty($entry[2])) {
        $newperson['LastName'] = $entry[2];
        $newSubReq['Last_Name__c'] = $entry[2];
    }
    if (!empty($entry[3])) {
        $newperson['Organization__c'] = $entry[3];
        $newSubReq['Organization__c'] = $entry[3];
    }
    if (!empty($entry[5])) {
        $newperson['PersonTitle'] = $entry[5];
        $newSubReq['Title__c'] = $entry[5];
    }
    if (!empty($entry[6])) {
        $newperson['Company_Type__c'] = $entry[6];
        $newSubReq['Organization_Type__c'] = $entry[6];
    }
    if (!empty($entry[7])) {
        $newperson['PersonMailingStreet'] = $entry[7];
        $newSubReq['Address1__c'] = $entry[7];
    }
    if (!empty($entry[8])) {
        $newperson['Mailing_Address_2__c'] = $entry[8];
        $newSubReq['Address2__c'] = $entry[8];
    }
    if (!empty($entry[9])) {
        $newperson['PersonMailingCity'] = $entry[9];
        $newSubReq['city__c'] = $entry[9];
    }
    if (!empty($entry[10])) {
        $newperson['PersonMailingState'] = $entry[10];
        $newSubReq['State__c'] = $entry[10];
    }
    if (!empty($entry[12])) {
        $newperson['PersonMailingPostalCode'] = $entry[12];
        $newSubReq['Zip__c'] = $entry[12];
    }
    if (!empty($entry[13])) {
        $newperson['PersonMailingCountry'] = $entry[13];
        $newSubReq['Country__c'] = $entry[13];
    }
    if (!empty($entry[22])) {
        $newperson['Phone'] = $entry[22];
        $newSubReq['Phone__c'] = $entry[22];
    }
    if (!empty($entry[23])) {
        $newperson['Grade_Level__c'] = $entry[23];
    }
    if (!empty($entry[24])) {
        $newperson['Subject_Taught__c'] = $entry[24];
    }
    if (!empty($entry[25])) {
        $newperson['Industry__c'] = $entry[25];
    }
    if (!empty($entry[14])) {
        $newSubReq['Personal_Answer__c'] = $entry[14];
    }
    if (!empty($entry[29])) {
        $newSubReq['Promo_Code__c'] = $entry[29];
    }
    $upsertResponse = $mySforceConnectionu->upsert('Email_as_ExternalID__c', array($newperson), 'Account');
    //echo '<pre> 189<br>';
    //echo print_r($upsertResponse);
    //echo '</pre>';
    if ($upsertResponse->success == 1) {
        update_user_meta($user_id, "sfid", $upsertResponse->id);
        $sfaccountdataquery = "Select Id, PersonContactId from Account where PersonEmail ='" . $entry[4] . "'";
        $sfaccountresponse = $mySforceConnectionu->query($sfaccountdataquery);
        $sfAccountid = $sfaccountresponse->records[0]->Id;
        //	echo '<pre> 195<br>';
        //echo print_r($sfaccountresponse);
        //mail('*****@*****.**','SF Subscription upserted account', print_r($sfaccountresponse).print_r($sfAccountid));
        //echo '</pre>';
        //since upserted account successfully, now upsert sub request
        //get the person account id just created to use in the subscription request record
        $newSubReq['Person_Account__c'] = $sfAccountid;
        //need to set renewal link
        $isrenewal = strpos($entry[source_url], 'sfid');
        if ($isrenewal !== false) {
            $renewalurl = substr($entry[source_url], 0, $isrenewal) . 'sfid=' . $sfAccountid . '&source=' . $linksource;
        } else {
            if (strpos($entry[source_url], '?' !== false)) {
                $renewalurl = $entry[source_url] . '&sfid=' . $sfAccountid . '&source=' . $linksource;
            } else {
                $renewalurl = $entry[source_url] . '?sfid=' . $sfAccountid . '&source=' . $linksource;
            }
        }
        $newSubReq['Renewal_Link__c'] = substr($renewalurl, 0, 254);
        $upsertResponse2 = $mySforceConnectionu->upsert('WP_ID__c', array($newSubReq), 'Subscription_Request__c');
        //echo '<pre> 220<br>' . $Subscription_Request__c;
        //print_r($newSubReq);
        //print_r($sfaccountresponse);
        //echo '</pre>';
        if ($upsertResponse2->success == 1) {
            print_r($sfaccountresponse);
            //mail('*****@*****.**','SF Subscription request upload success','we are ok');
        } else {
            //mail('*****@*****.**','SF Subscription Request UPload FAILED', print_r($newSubReq).print_r($upsertResponse2));
        }
    } else {
        //mail('*****@*****.**','SF Subscription form UPload FAILED',print_r($sfaccountresponse));
        //mail('*****@*****.**','an SF Subscription account upload FAILED ','Email address that failed is '.$user_email);
        //echo '<pre> 236<br>';
        //print_r($newSubReq);
        //print_r($sfaccountresponse);
        //echo '</pre>';
    }
}
Пример #17
0
    echo "key : " . $key;
    echo "\t";
    echo "value : " . $val;
    echo "\n";
}
foreach ($_GET as $key => $val) {
    echo "key : " . $key;
    echo "\t";
    echo "value : " . $val;
    echo "\n";
}
require_once 'lib/soapclient/SforceEnterpriseClient.php';
//$mySforceConnection->createConnection("lib/soapclient/enterprise8.wsdl.xml");
//$mySforceConnection->login("*****@*****.**", "saasten2011");
try {
    $mySforceConnection = new SforceEnterpriseClient();
    $mySforceConnection->createConnection("lib/soapclient/enterprise1.wsdl.xml");
    $mySforceConnection->setSessionHeader($_GET['session'] . "");
    $mySforceConnection->setEndpoint($_GET['url']);
    $UserInfo = $mySforceConnection->getUserInfo();
    var_dump($UserInfo->userName);
    if (!empty($UserInfo->userName)) {
        $query = "SELECT Id, FirstName, LastName FROM Contact";
        $response = $mySforceConnection->query($query);
        echo "<pre>";
        var_dump($response);
        echo "</pre>";
    }
} catch (Exception $e) {
    echo 'Caught exception: ', $e->getMessage(), "\n";
}
Пример #18
0
<?php

session_start();
include 'Services/Twilio.php';
include "config.php";
require_once 'Services/soapclient/SforceEnterpriseClient.php';
$message = "{{name}} Try our new hot and ready pizza!";
$client = new Services_Twilio($accountsid, $authtoken);
$mySforceConnection = new SforceEnterpriseClient();
$mySforceConnection->createConnection("Services/soapclient/enterprise.wsdl.xml");
$mySforceConnection->login(SF_USERNAME, SF_PASSWORD . SF_SECURITY_TOKEN);
$query = "SELECT Id, FirstName, LastName, Phone from Contact";
$response = $mySforceConnection->query($query);
echo "Results of query '{$query}'<br/><br/>\n";
foreach ($response->records as $record) {
    echo "Sending message to " . $record->FirstName . " " . $record->LastName . " at " . $record->Phone . "<br/>\n";
    $msg = str_replace("{{name}}", $record->FirstName, $message);
    $sid = send_sms($record->Phone, $msg);
}
exit;
function send_sms($number, $message)
{
    global $client, $fromNumber;
    $sms = $client->account->sms_messages->create($fromNumber, $number, $message);
    return $sms->sid;
}
Пример #19
0
function export_to_saleforce(
  $to_address,
  $account_holder_name = null,
  $account_sort_code = null,
  $account_number = null
) {

  require_once "salesforce-api/soapclient/SforceEnterpriseClient.php";

  try {
    // get a salesforce connection object instance
    $my_sforce_connection = new SforceEnterpriseClient();

    if (SALESFORCE_SANDBOX === true) {
      $from_address = get_custom("worldpay_confirmation_email_from_sandbox");
      $salesforce_password = get_custom("salesforce_password_sandbox");
      $salesforce_security_token = get_custom("salesforce_security_token_sandbox");
      $salesforce_username = get_custom("salesforce_username_sandbox");
      $my_sforce_connection->createConnection(dirname(__FILE__) . "/enterprise_staging.wsdl.xml");
    } else {
      $from_address = get_custom("worldpay_confirmation_email_from");
      $salesforce_password = get_custom("salesforce_password");
      $salesforce_security_token = get_custom("salesforce_security_token");
      $salesforce_username = get_custom("salesforce_username");
      $my_sforce_connection->createConnection(dirname(__FILE__) . "/enterprise_main.wsdl.xml");
    }
    // fill in the definition of the SF system we are connecting
    // Woodenspoon will need to supply an up to date enterprise WSDL
    $ini = ini_set("soap.wsdl_cache_enabled", "0");

    // from userAuth.php or somewhere else
    $my_sforce_connection->login(
      $salesforce_username,
      $salesforce_password . $salesforce_security_token
    );

    $s_contact_obj = new stdclass();
    $s_member_obj = new stdclass();
    $s_direct_deb_obj = new stdclass();

    /*Contact Entry*/
    $s_contact_obj->Email = $_SESSION["email"]; //Monthly
    $s_contact_obj->FirstName = $_SESSION["firstName"];
    $s_contact_obj->LastName = $_SESSION["lastName"];
    $s_contact_obj->MobilePhone = $_SESSION["phone"];
    $s_contact_obj->Salutation = $_SESSION["title"];
    // $s_contact_obj->HomePhone = $_SESSION["home-phone"];

    // if ($_SESSION["date_of_birth"] != "--") { $s_contact_obj->Birthdate = $_SESSION["date_of_birth"]; }
    $s_contact_obj->MailingCity = $_SESSION["town"];
    $s_contact_obj->MailingCountry = $_SESSION["country"];
    $s_contact_obj->MailingPostalCode = $_SESSION["postcode"];
    $s_contact_obj->MailingStreet = $_SESSION["addressLine1"] . " " . $_SESSION["addressLine2"];
    $s_contact_obj->Description = $_SESSION["comments"];
    if ($_SESSION["dataProtection"]) {
      $s_contact_obj->Data_Protection_Received__c = 1;
    }
    $s_contact_obj->Date_Relationship_Begun__c = date("Y-m-d");

    // $s_contact_obj->Primary_Address_Type__c = $_SESSION["address_type"];
    if ($_SESSION["giftAid"] == "true") {
      $s_contact_obj->Said_Yes_to_Gift_Aid__c = 1; //Monthly
    } else {
      $s_contact_obj->Not_eligible_for_Gift_Aid__c = 1; //Monthly
    }
    // create the SF record. This process returns the unique SF id of the record
    // there is NO checking for duplicates here. This is performed in SF.
    $createResponse2 = $my_sforce_connection->create(array($s_contact_obj), "Contact");

    /*Membership Entry*/
    // this field links the just created contact (the id) to the about to be created membership entry
    $s_member_obj->Members_Name__c = $createResponse2[0]->id;

    $s_member_obj->Date_Membership_From__c = date("Y-m-d"); //"2014-08-14";
    // $s_member_obj->Stirred_Into_Action_By__c = $_SESSION["hear_about_us"];

    if ($_SESSION["donationRepetition"] == "oneoff") {
      $s_member_obj->Membership_Status__c = "Non Member";
    } else {
      $s_member_obj->Membership_Status__c = "Member";
    }
    $createResponse1 = $my_sforce_connection->create(array($s_member_obj), "Membership__c");

    /*
    the next two bits of code NEED logic to be placed around them
    I do not know how you are going to decide if this is a direct debit
    or non direct debit money.

    You will need to put an IF ELSE around the next two blocks of code

    Remember these field format values MUST be validated earlier at input
    by the customer

     */
    $s_direct_deb_obj->Payment_Method__c = $_SESSION["paymentMethod"];
    if ($_SESSION["paymentMethod"] == "Direct Debit") {
      /* BLOCK 1 Direct Debit Entry*/
      $s_direct_deb_obj->Bank_Account_Name__c = $account_holder_name;
      $s_direct_deb_obj->Sort_Code__c = $account_sort_code;
      $s_direct_deb_obj->Account_Number__c = $account_number;
      $s_direct_deb_obj->First_Collection_Amount__c = $_SESSION["donationAmountOther"];
      $s_direct_deb_obj->Payment_Type__c = "Membership Payment"; //Monthly
    } else {
      /* BLOCK2 Non-Direct Debit Entry*/
      $s_direct_deb_obj->RecordTypeId = "01240000000DjRYAA0";
      $s_direct_deb_obj->Gift_Amount__c = $_SESSION["donationAmountOther"];
    }

    //Monthly

    if ($_SESSION["donationRepetition"] == "oneoff") {
      $s_direct_deb_obj->Payment_Status__c = "One-off Payment";
      $s_direct_deb_obj->Collection_Frequency__c = "One-off Payment";
      $s_direct_deb_obj->Annual_Reminder__c = date("F");
    } else {
      $s_direct_deb_obj->Payment_Status__c = "Ongoing Collection";
      $s_direct_deb_obj->Payment_Type__c = "Membership Payment";
      if ($_SESSION["donationRepetition"] == "year") {
        $s_direct_deb_obj->Collection_Frequency__c = "Annually";
      }
      if ($_SESSION["donationRepetition"] == "month") {
        $s_direct_deb_obj->Collection_Frequency__c = "Monthly";
      }
    }
    /* end of block 2 */

    /* for both types of collection this bit of code actually creates the record in SF */

    // create the direct debit record in SF - not truely a DD always
    $s_direct_deb_obj->Contact__c = $createResponse2[0]->id;
    $s_direct_deb_obj->Membership__c = $createResponse1[0]->id;
    $createResponse = $my_sforce_connection->create(array($s_direct_deb_obj), "Direct_Debit__c");

    $to = $_SESSION["email"];
    $subject = get_custom("thank_you_email_subject");
    $message = str_replace("%name%", $_SESSION["firstName"], get_custom("thank_you_email_body"));

    $headers[] = "Content-Type: text/plain; charset=UTF-8";
    $headers[] = "From: Woodenspoon <" . $from_address . ">";

    wp_mail($to, $subject, $message, $headers);

    if ($createResponse[0]->success != 1 || $createResponse2[0]->success != 1 || $createResponse1[0]->success != 1) {
      salesforce_error_mail($to_address, $account_holder_name, $account_sort_code, $account_number, $createResponse, $createResponse2, $createResponse1);
    }

  } catch (Exception $e) {
    salesforce_error_mail($to_address, $account_holder_name, $account_sort_code, $account_number, bull, null, null);
  }
  session_destroy();
}
Пример #20
0
function myplugin_registration_save($user_id)
{
    $user_info = get_userdata($user_id);
    $email = "{$user_info->user_email}";
    #$test=implode(" ",$user_info);
    $role = $user_info->roles[0];
    $test = get_user_meta($user_id, 'role');
    $test = implode(" ", $test);
    $server_base = $_SERVER['DOCUMENT_ROOT'];
    define("SOAP_CLIENT_BASEDIR", "{$server_base}/wp-content/Force.com-Toolkit-for-PHP-master/soapclient");
    require_once SOAP_CLIENT_BASEDIR . '/SforceEnterpriseClient.php';
    require_once "{$server_base}/wp-content/Force.com-Toolkit-for-PHP-master/samples/userAuth.php";
    ini_set("soap.wsdl_cache_enabled", "0");
    $mySforceConnection = new SforceEnterpriseClient();
    $mySoapClient = $mySforceConnection->createConnection(SOAP_CLIENT_BASEDIR . '/enterprise.wsdl.xml');
    $mylogin = $mySforceConnection->login($USERNAME, $PASSWORD);
    $found = 0;
    if ($role == 'Client' || $role == 'Expert') {
        $query = "SELECT Id,C_ID__c,AccountId,Account_Name__c,Email,Phone,LastName,FirstName,IsDeleted,MailingCity,MailingState,MailingCountry,MailingPostalCode from Contact WHERE Email='{$email}' AND IsDeleted=False  LIMIT 1";
        $response = $mySforceConnection->query($query);
        foreach ($response->records as $record) {
            $found = 1;
            update_user_meta($user_id, 'first_name', $record->FirstName);
            update_user_meta($user_id, 'last_name', $record->LastName);
            update_user_meta($user_id, 'account_name', $record->Account_Name__c);
            update_user_meta($user_id, 'id_sf_account', $record->AccountId);
            update_user_meta($user_id, 'id_sf_contact', $record->Id);
            update_user_meta($user_id, 'cid', $record->C_ID__c);
            wp_update_user(array('ID' => $user_id, 'role' => 'Client'));
            $sObject1 = new stdClass();
            $sObject1->Id = $record->Id;
            $sObject1->WP_Login_ID__c = $user_id;
            $response = $mySforceConnection->update(array($sObject1), 'Contact');
        }
        if ($found == 0) {
            $query = "SELECT Id,Firstname__c,Lastname__c,Ms_Mr_Dr_Nurse__c,E_ID__c from Expert__c WHERE Email__c='{$email}' LIMIT 1";
            $response = $mySforceConnection->query($query);
            foreach ($response->records as $record) {
                $found = 1;
                update_user_meta($user_id, 'id_sf_expert', $record->Id);
                update_user_meta($user_id, 'eid', $record->E_ID__c);
                update_user_meta($user_id, 'first_name', $record->Firstname__c);
                update_user_meta($user_id, 'last_name', $record->Lastname__c);
                update_user_meta($user_id, 'title', $record->Ms_Mr_Dr_Nurse__c);
                update_user_meta($user_id, 'role_check', "Expert");
                $update = wp_update_user(array('ID' => $user_id, 'role' => "Expert"));
                $sObject1 = new stdClass();
                $sObject1->Id = $record->Id;
                $sObject1->WP_Login_ID__c = $user_id;
                $response = $mySforceConnection->update(array($sObject1), 'Expert__c');
            }
        }
    }
}
Пример #21
0
$LCMT_First = $_GET['UFIRST'];
$LCMT_Last = $_GET['ULAST'];
$OID = $_GET['OID'];
$na = $_POST['na'];
$name = $_GET['case'];
$aid = $_GET['aid'];
$msg = $_POST['msg'];
$WP = $_GET['WP'];
$case_manage_img = "<img class='case-manager-img text-center' src=\"https://res.cloudinary.com/theexpertinstitute-com/image/upload/c_thumb,g_face:center,h_60,w_60/v40/users/{$UID}.jpg\">";
if ($na == 'send') {
    define("SOAP_CLIENT_BASEDIR", "./wp-content/Force.com-Toolkit-for-PHP-master/soapclient");
    require_once SOAP_CLIENT_BASEDIR . '/SforceEnterpriseClient.php';
    require_once './wp-content/Force.com-Toolkit-for-PHP-master/samples/userAuth.php';
    ini_set("soap.wsdl_cache_enabled", "0");
    $mySforceConnection = new SforceEnterpriseClient();
    $mySoapClient = $mySforceConnection->createConnection(SOAP_CLIENT_BASEDIR . '/enterprise.wsdl.xml');
    $mylogin = $mySforceConnection->login($USERNAME, $PASSWORD);
    $sObject = new stdclass();
    $sObject->Contact__c = $IDU;
    $sObject->Message__c = $msg;
    $sObject->Opportunity__c = $IDO;
    $createResponse = $mySforceConnection->create(array($sObject), 'Opportunity_Messages__c');
    $id = $createResponse[0];
    $id_msg = $id->id;
    echo "<META http-equiv=\"refresh\" content=\"0;URL=https://theexpertinstitute.secure.force.com/Client/ClientCaseDetail?IDO={$IDO}&IDU={$IDU}&WP={$WP}#chatter\">";
    ?>
  </head> 
<?php 
} else {
    ?>
  
Пример #22
0
function salesforce_save_choice()
{
    global $avail_id;
    $IDU = $_POST['idu'];
    $IDU_Type = $_POST['idu_type'];
    $chosen_start = $_POST['chosen_start'];
    $chosen_end = $_POST['chosen_end'];
    $chosen_offset = $_POST['chosen_offset'];
    $avail_id = $_POST['avail_id'];
    $utc_offset = $_POST['utc_offset'];
    $userPhonenumber = $_POST['userPhonenumber'];
    $userNotes = $_POST['userNotes'];
    $id_opp = $_POST['id_opp'];
    $nonce = $_POST['nonce'];
    if (check_ajax_referer('save-choice', $nonce, false)) {
        echo $nonce;
        die('Security Check:');
    } else {
        //nonce check passed
        if ($avail_id == '') {
            echo 'no id';
            return;
        }
        $server_base = $_SERVER['DOCUMENT_ROOT'];
        define("SOAP_CLIENT_BASEDIR", "{$server_base}/wp-content/Force.com-Toolkit-for-PHP-master/soapclient");
        require_once SOAP_CLIENT_BASEDIR . '/SforceEnterpriseClient.php';
        require_once "{$server_base}/wp-content/Force.com-Toolkit-for-PHP-master/samples/userAuth.php";
        ini_set("soap.wsdl_cache_enabled", "0");
        $mySforceConnection = new SforceEnterpriseClient();
        $mySoapClient = $mySforceConnection->createConnection(SOAP_CLIENT_BASEDIR . '/enterprise.wsdl.xml');
        $mylogin = $mySforceConnection->login($USERNAME, $PASSWORD);
        // $ID=$_GET['ID'];
        $query = "SELECT Id,Json_Times__c From Conference_Call__c  WHERE  Id='{$avail_id}'";
        $response = $mySforceConnection->query($query);
        foreach ($response->records as $record) {
            $json_times = $record->Json_Times__c;
        }
        $date_start = explode('T', $chosen_start);
        $date_start = $date_start[0];
        $date_start = $date_start . "T";
        $temp = explode($date_start, $json_times);
        $temp = $temp[1];
        $offset_hour = intval(substr($temp, 9, 2)) * 60 / -1;
        $sObject1 = new stdClass();
        $sObject1->Time_start__c = $chosen_start;
        $sObject1->Time_end__c = $chosen_end;
        if ($IDU_Type == 'Expert') {
            $sObject1->Timezone_Expert__c = $chosen_offset;
            $sObject1->Expert_Phone_Call__c = $userPhonenumber;
            $sObject1->Expert_Call_Note__c = $userNotes;
            $sObject1->Timezone_Contact__c = $offset_hour;
        }
        if ($IDU_Type == 'Attorney') {
            $sObject1->Timezone_Expert__c = $offset_hour;
            $sObject1->Timezone_Contact__c = $chosen_offset;
            $sObject1->Contact_Phone_Call__c = $userPhonenumber;
            $sObject1->Client_Call_Info__c = $userNotes;
        }
        $sObject1->Status__c = 'Confirmed';
        $sObject1->Id = $avail_id;
        $response = $mySforceConnection->update(array($sObject1), 'Conference_Call__c');
        $sObject11 = new stdClass();
        $sObject11->StageName = 'CC Scheduled';
        $sObject11->Id = $id_opp;
        $response = $mySforceConnection->update(array($sObject11), 'Opportunity');
        if ($IDU_Type == 'Expert') {
            $query = "SELECT Id, Expert__c,E_ID__c, Contact__c,Opportunity__c,Time_start_Contact__c,Start_Contact_Text__c From Conference_Call__c  WHERE   Id='{$avail_id}' ";
            $response = $mySforceConnection->query($query);
            foreach ($response->records as $record) {
                $utc_offset_client = $record->Timezone_Contact__c;
                $Time_client_start = $record->Time_start_Contact__c;
                $eid = $record->E_ID__c;
                $attorneyID = $record->Contact__c;
                $client_start = $record->Start_Contact_Text__c;
                $url = site_url();
                $cc_link = "{$url}/scheduler/?ID={$record->Opportunity__c}&IDCC={$avail_id}&IDU={$attorneyID}";
                $msg = "Conference Call Scheduled w/ Expert {$eid} for {$client_start}";
                $sObject3 = new stdclass();
                $sObject3->Expert__c = $record->Expert__c;
                $sObject3->Message__c = $msg;
                $sObject3->Opportunity__c = $record->Opportunity__c;
                $createResponse = $mySforceConnection->create(array($sObject3), 'Opportunity_Messages__c');
                $id = $createResponse[0];
            }
        }
        die;
    }
}