/trunk/models/goldvision/goldvision.php
PHP | 248 lines | 156 code | 35 blank | 57 comment | 5 complexity | 68a98c9b4484020c8f9092da7713f2b3 MD5 | raw file
Possible License(s): LGPL-2.1
- <?php
- class GoldVisionIntegration {
-
- private $server = "https://mail.equalitysouthwest.org.uk/gold-vision/";
- private $goldLink = "Gold-Link/goldlink.asmx";
- private $username = "ERH\Samantha Partridge";
- private $password = "welcome";
-
- //private $server = "http://junior-pc/Gold-Vision/";
- //private $goldLink = "Gold-Link/goldlink.asmx";
- //private $username ="WORKGROUP\Richard Thompson";
- //private $password = "password";
-
- private $ns = "http://service.gold-vision.com/gold-link";
- private $find;
- private $add;
-
- private $soap_ns = "http://service.gold-vision.com/gold-link";
-
- public function __construct()
- {
- $this->find = $this->ns . '/FindItem';
- $this->add = $this->ns . '/AddItem';
- $this->link = $this->ns . '/AddLink';
- $this->update = $this->ns . '/UpdateItem';
- }
-
-
- public function searchAccounts( $text )
- {
- $params = array();
- $params[0] = array( "dbcolumn" => "SUMMARY", "type" => "text", "value" => $text );
- $fields = array();
- $fields[0] = array("dbcolumn" => "AC_TYPE");
- $fields[1] = array("dbcolumn" => "MAIN_SALES_CONTACT");
- $fields[2] = array("dbcolumn" => "ACCOUNT_MANAGER");
- $fields[3] = array("dbcolumn" => "ACC_ID_SALES");
- $fields[4] = array("dbcolumn" => "US_ID_SALES");
- return $this->glink_findItem( "Account", $params, $fields, "searchAccountsComplete");
- }
-
- public function searchContacts( $email, $orgID )
- {
- $params = array();
- $params[0] = array( "dbcolumn" => "Email1Address", "type" => "text", "value" => $email );
- $params[1] = array( "dbcolumn" => "AC_ID", "type" => "text", "value" => $orgID );
- $fields = array();
- $fields[0] = array("dbcolumn" => "Email1Address");
- $fields[1] = array("dbcolumn" => "ACC_ID");
- return $this->glink_findItem( "Contact", $params, $fields, "searchAccountsComplete", false );
- }
-
- public function createAccount( $summary, $address_1, $address_2, $town, $county, $postcode, $phone_number, $website, $type )
- {
- $xml = '<record><field name="SUMMARY">' . $summary . '</field><field name="ADDRESS_1">' . $address_1 . '</field><field name="ADDRESS_2">' . $address_2 . '</field><field name="TOWN">' . $town . '</field><field name="COUNTY">' . $county . '</field><field name="POSTCODE">' . $postcode . '</field><field name="PHONE_1">' . $phone_number . '</field><field name="WEB_SITE_1">' . $website . '</field><field name="AC_UD1_ID">' . $type . '</field></record>';
- return $this->glink_addItem("Account", $xml, '');
- }
-
- /**
- * @desc Clears registered interests for memeber,
- * then applies the ones supplied
- *
- * @param $interests array|string Interest ID(s)
- * @param $contact string Contact GUID
- */
- public function updateInterests( $interests, $contact )
- {
- $xml = '<SetTagsForItem xmlns="http://service.gold-vision.com/gold-link"><tagList>%s</tagList><id>%s</id></SetTagsForItem>';
-
- $this->glink_execute($this->ns . '/SetTagsForItem', sprintf($xml, '', $contact), null);
-
- if(is_array($interests)){
- $interests = implode(',', array_filter($interests));
- }
-
- return $this->glink_execute($this->ns . '/SetTagsForItem', sprintf($xml, $interests, $contact), null);
- }
-
- public function updateAccount( $id, $summary, $address_1, $address_2, $town, $county, $postcode, $phone_number, $website, $type )
- {
- $xml = '<record><field name="SUMMARY">' . $summary . '</field><field name="ADDRESS_1">' . $address_1 . '</field><field name="ADDRESS_2">' . $address_2 . '</field><field name="TOWN">' . $town . '</field><field name="COUNTY">' . $county . '</field><field name="POSTCODE">' . $postcode . '</field><field name="PHONE_1">' . $phone_number . '</field><field name="WEB_SITE_1">' . $website . '</field><field name="AC_UD1_ID">' . $type . '</field></record>';
- return $this->glink_updateItem("Account", $xml, $id, 'AllFieldsPresentExceptBlanks');
- }
-
- public function updateContact( $id, $firstName, $lastName, $orgID, $title, $jobTitle, $mobile, $email, $events, $volun, $newsletter, $share, $address_1, $address_2, $town, $county, $postcode, $phone_number, $website )
- {
- $xml = '<record><field name="FirstName">' . $firstName . '</field><field name="LastName">' . $lastName . '</field><field name="AC_ID">' . $orgID . '</field><field name="Title">' . $title . '</field><field name="JobTitle">' . $jobTitle . '</field><field name="MobileTelephoneNumber">' . $mobile . '</field><field name="Email1Address">' . $email . '</field><field name="ACC_UD3_ID">' . $events . '</field><field name="ACC_UD1_ID">' . $volun . '</field><field name="ACC_UD20_BIT">' . $newsletter . '</field><field name="ACC_UD21_BIT">' . $share . '</field><field name="BusinessAddressStreet">' . $address_1 . '</field><field name="BusinessAddressStreet2">' . $address_2 . '</field><field name="BusinessAddressCity">' . $town . '</field><field name="BusinessAddressState">' . $county . '</field><field name="BusinessAddressPostalCode">' . $postcode . '</field><field name="BusinessTelephoneNumber">' . $phone_number . '</field><field name="WebPage">' . $website . '</field></record>';
- return $this->glink_updateItem("Contact", $xml, $id, 'AllFieldsPresentExceptBlanks' );
- }
-
- //2ac86405-64d7-4576-a747-3cd1dcdab21f
- public function createContact( $firstName, $lastName, $orgID, $title, $jobTitle, $mobile, $email, $events, $volun, $newsletter, $share )
- {
- $xml = '<record><field name="FirstName">' . $firstName . '</field><field name="LastName">' . $lastName . '</field><field name="AC_ID">' . $orgID . '</field><field name="Title">' . $title . '</field><field name="JobTitle">' . $jobTitle . '</field><field name="MobileTelephoneNumber">' . $mobile . '</field><field name="Email1Address">' . $email . '</field><field name="ACC_UD3_ID">' . $events . '</field><field name="ACC_UD1_ID">' . $volun . '</field><field name="ACC_UD20_BIT">' . $newsletter . '</field><field name="ACC_UD21_BIT">' . $share . '</field></record>';
- return $this->glink_addItem("Contact", $xml, '', false );
- }
-
- private function glink_addItem( $objectType, $xmlRecordString, $callBackFunction, $echo=false ) {
- // Build find
- $s = '';
- $s .= '<AddItem xmlns="' . $this->soap_ns .'">';
- $s .= '<objectType>' . $objectType . '</objectType>';
- $s .= '<xmlData><gvdata xmlns="">' . $xmlRecordString .'</gvdata></xmlData>'; // NOTE THE 'gvdata' and blanking namespace ON THIS LINE
- $s .= '</AddItem>';
- // Send to Gold-Link
- return $this->glink_execute($this->add, $s, '', $echo );
- }
-
- private function glink_updateItem( $objectType, $xmlRecordString, $id, $overwrite="AllFieldsPresentExceptBlanks", $echo=false )
- {
- $s = '';
- $s .= '<UpdateItem xmlns="' . $this->soap_ns . '">';
- $s .= '<objectType>' . $objectType . '</objectType>';
- $s .= '<xmlData><gvdata xmlns="">' . $xmlRecordString .'</gvdata></xmlData>'; // NOTE THE 'gvdata' and blanking namespace ON THIS LINE
- $s .= '<id>' . $id . '</id>';
- $s .= '<overwrite>' . $overwrite .'</overwrite>';
- $s .= '</UpdateItem>';
- return $this->glink_execute( $this->update, $s, '', $echo );
- }
-
- private function linkOrganisationToIndividual( $org, $ind )
- {
- $s = '';
- $s .= '<AddLink xmlns="' . $this->soap_ns .'">';
- $s .= '<idFrom>' . $ind . '</idFrom>';
- $s .= '<typeFrom>Contact</typeFrom>';
- $s .= '<relationshipFrom>Employee</relationshipFrom>';
- $s .= '<idTo>' . $org . '</idTo>';
- $s .= '<typeTo>Account</typeTo>';
- $s .= '<relationshipTo>Employer</relationshipTo>';
- $s .= '</AddLink>';
- return $this->glink_execute($this->link, $s, '' );
- }
-
- //2ac86405-64d7-4576-a747-3cd1dcdab21f
- private function glink_findItem( $objectType, $filterParams, $extraFields, $callBackFunction, $echo=false )
- {
- // Build find
- $s = '';
- $s .= '<FindItem xmlns="' . $this->soap_ns . '">';
- $s .= '<objectType>' . $objectType . '</objectType>';
- $s .= '<XmlFilters><filters xmlns="">';
- for ($i = 0; $i < count( $filterParams ); $i++)
- {
-
- $s .= '<filter dbcolumn="'. $filterParams[ $i ]["dbcolumn"] . '" type="' . $filterParams[ $i ]["type"] . '" value="' . $filterParams[ $i ]["value"] . '" />';
- }
- for ( $i = 0; $i < count( $extraFields ); $i++)
- {
- $s .= '<field dbcolumn="' . $extraFields[ $i ]["dbcolumn"] . '" />';
- }
- $s .= '</filters></XmlFilters>';
- $s .= '</FindItem>';
- // Send to Gold-Link
- return $this->glink_execute( $this->find, $s, $callBackFunction, $echo);
- }
-
- private function glink_execute( $soapAction, $soapXml, $callBackFunctionm, $echo=false )
- {
- //
-
- $s = "<" . '?xml version="1.0" encoding="utf-8"?>';
- $s .= '<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">';
- $s .= ' <soap:Body>';
- // Soap data
- $s .= $soapXml;
-
- // End boilerpate
- $s .= ' </soap:Body>';
- $s .= '</soap:Envelope>';
- $url = $this->server . $this->goldLink . "?z=" . time();
- $parsed = parse_url($url);
-
- $port = ( isset($parsed['port']) ) ? $parsed['port'] : 80;
-
- $path = ( empty($parsed['path']) ) ? '/' : $parsed['path'];
-
- $path .= ( empty($parsed['query']) ) ? '' : '?'.$parsed['query'];
-
- $ch = curl_init();
- curl_setopt( $ch, CURLOPT_URL, $url );
- curl_setopt($ch, CURLOPT_POST, 1);
- curl_setopt($ch, CURLOPT_POSTFIELDS, $s );
- //curl_setopt($ch, CURLOPT_HEADER, true); // Display headers
- curl_setopt($ch, CURLOPT_VERBOSE, true); // Display communication with server
- curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_NTLM );
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false );
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // Return data instead of display to std out
- curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: text/xml;", "SOAPAction: " . $soapAction));
- //curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: text/xml; charset=utf-8","SOAPAction: " . $soapAction, "Content-Length: ".strlen($s)));
- curl_setopt( $ch, CURLOPT_USERPWD, $this->username . ':' . $this->password);
- if( $echo )
- {
- echo $s;
- echo '<br /><br /><br />';
- }
-
-
- //execute post
- $result = curl_exec($ch);
- if( $echo )
- {
- echo $result;
- //exit();
- }
- //echo $result;
- //exit();
- //close connection
- curl_close($ch);
- return $result;
- }
-
- /**public function getAccounts( $xml )
- {
- $results = array();
-
- // Get root node information from XML
- var xml_root = xml.childNodes[xml.childNodes.length - 1];
- var xml_list = xml_root.childNodes[0].childNodes[0].childNodes[0].childNodes[0].childNodes[0];
- // Clear any existing entries
- while(document.getElementById("listresults").childNodes.length > 0)
- document.getElementById("listresults").removeChild(document.getElementById("listresults").childNodes[0]);
- for (var i = 0; i < xml_list.childNodes.length; i++) {
- // Add to screen
- var option = document.createElement("option");
- option.value = xml_list.childNodes[i].getAttribute("id");
- option.text = xml_list.childNodes[i].getAttribute("summary");
- option.innerHTML = xml_list.childNodes[i].getAttribute("summary");
- document.getElementById("listresults").appendChild(option);
- // Store in an array
- matchResults[i] = {
- "id":xml_list.childNodes[i].getAttribute("id"),
- "summary":xml_list.childNodes[i].getAttribute("summary"),
- "postcode":xml_list.childNodes[i].getAttribute("postcode"),
- "ac_type":xml_list.childNodes[i].getAttribute("ac_type"),
- "main_sales_contact":xml_list.childNodes[i].getAttribute("main_sales_contact"),
- "acc_id_sales":xml_list.childNodes[i].getAttribute("acc_id_sales"),
- "us_id_sales":xml_list.childNodes[i].getAttribute("us_id_sales"),
- "account_manager":xml_list.childNodes[i].getAttribute("account_manager")
- };
- }
- }*/
-
-
-
-
- }
- ?>