PageRenderTime 48ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/trunk/models/goldvision/goldvision.php

https://bitbucket.org/pooshonk/esw
PHP | 248 lines | 156 code | 35 blank | 57 comment | 5 complexity | 68a98c9b4484020c8f9092da7713f2b3 MD5 | raw file
Possible License(s): LGPL-2.1
  1. <?php
  2. class GoldVisionIntegration {
  3. private $server = "https://mail.equalitysouthwest.org.uk/gold-vision/";
  4. private $goldLink = "Gold-Link/goldlink.asmx";
  5. private $username = "ERH\Samantha Partridge";
  6. private $password = "welcome";
  7. //private $server = "http://junior-pc/Gold-Vision/";
  8. //private $goldLink = "Gold-Link/goldlink.asmx";
  9. //private $username ="WORKGROUP\Richard Thompson";
  10. //private $password = "password";
  11. private $ns = "http://service.gold-vision.com/gold-link";
  12. private $find;
  13. private $add;
  14. private $soap_ns = "http://service.gold-vision.com/gold-link";
  15. public function __construct()
  16. {
  17. $this->find = $this->ns . '/FindItem';
  18. $this->add = $this->ns . '/AddItem';
  19. $this->link = $this->ns . '/AddLink';
  20. $this->update = $this->ns . '/UpdateItem';
  21. }
  22. public function searchAccounts( $text )
  23. {
  24. $params = array();
  25. $params[0] = array( "dbcolumn" => "SUMMARY", "type" => "text", "value" => $text );
  26. $fields = array();
  27. $fields[0] = array("dbcolumn" => "AC_TYPE");
  28. $fields[1] = array("dbcolumn" => "MAIN_SALES_CONTACT");
  29. $fields[2] = array("dbcolumn" => "ACCOUNT_MANAGER");
  30. $fields[3] = array("dbcolumn" => "ACC_ID_SALES");
  31. $fields[4] = array("dbcolumn" => "US_ID_SALES");
  32. return $this->glink_findItem( "Account", $params, $fields, "searchAccountsComplete");
  33. }
  34. public function searchContacts( $email, $orgID )
  35. {
  36. $params = array();
  37. $params[0] = array( "dbcolumn" => "Email1Address", "type" => "text", "value" => $email );
  38. $params[1] = array( "dbcolumn" => "AC_ID", "type" => "text", "value" => $orgID );
  39. $fields = array();
  40. $fields[0] = array("dbcolumn" => "Email1Address");
  41. $fields[1] = array("dbcolumn" => "ACC_ID");
  42. return $this->glink_findItem( "Contact", $params, $fields, "searchAccountsComplete", false );
  43. }
  44. public function createAccount( $summary, $address_1, $address_2, $town, $county, $postcode, $phone_number, $website, $type )
  45. {
  46. $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>';
  47. return $this->glink_addItem("Account", $xml, '');
  48. }
  49. /**
  50. * @desc Clears registered interests for memeber,
  51. * then applies the ones supplied
  52. *
  53. * @param $interests array|string Interest ID(s)
  54. * @param $contact string Contact GUID
  55. */
  56. public function updateInterests( $interests, $contact )
  57. {
  58. $xml = '<SetTagsForItem xmlns="http://service.gold-vision.com/gold-link"><tagList>%s</tagList><id>%s</id></SetTagsForItem>';
  59. $this->glink_execute($this->ns . '/SetTagsForItem', sprintf($xml, '', $contact), null);
  60. if(is_array($interests)){
  61. $interests = implode(',', array_filter($interests));
  62. }
  63. return $this->glink_execute($this->ns . '/SetTagsForItem', sprintf($xml, $interests, $contact), null);
  64. }
  65. public function updateAccount( $id, $summary, $address_1, $address_2, $town, $county, $postcode, $phone_number, $website, $type )
  66. {
  67. $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>';
  68. return $this->glink_updateItem("Account", $xml, $id, 'AllFieldsPresentExceptBlanks');
  69. }
  70. 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 )
  71. {
  72. $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>';
  73. return $this->glink_updateItem("Contact", $xml, $id, 'AllFieldsPresentExceptBlanks' );
  74. }
  75. //2ac86405-64d7-4576-a747-3cd1dcdab21f
  76. public function createContact( $firstName, $lastName, $orgID, $title, $jobTitle, $mobile, $email, $events, $volun, $newsletter, $share )
  77. {
  78. $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>';
  79. return $this->glink_addItem("Contact", $xml, '', false );
  80. }
  81. private function glink_addItem( $objectType, $xmlRecordString, $callBackFunction, $echo=false ) {
  82. // Build find
  83. $s = '';
  84. $s .= '<AddItem xmlns="' . $this->soap_ns .'">';
  85. $s .= '<objectType>' . $objectType . '</objectType>';
  86. $s .= '<xmlData><gvdata xmlns="">' . $xmlRecordString .'</gvdata></xmlData>'; // NOTE THE 'gvdata' and blanking namespace ON THIS LINE
  87. $s .= '</AddItem>';
  88. // Send to Gold-Link
  89. return $this->glink_execute($this->add, $s, '', $echo );
  90. }
  91. private function glink_updateItem( $objectType, $xmlRecordString, $id, $overwrite="AllFieldsPresentExceptBlanks", $echo=false )
  92. {
  93. $s = '';
  94. $s .= '<UpdateItem xmlns="' . $this->soap_ns . '">';
  95. $s .= '<objectType>' . $objectType . '</objectType>';
  96. $s .= '<xmlData><gvdata xmlns="">' . $xmlRecordString .'</gvdata></xmlData>'; // NOTE THE 'gvdata' and blanking namespace ON THIS LINE
  97. $s .= '<id>' . $id . '</id>';
  98. $s .= '<overwrite>' . $overwrite .'</overwrite>';
  99. $s .= '</UpdateItem>';
  100. return $this->glink_execute( $this->update, $s, '', $echo );
  101. }
  102. private function linkOrganisationToIndividual( $org, $ind )
  103. {
  104. $s = '';
  105. $s .= '<AddLink xmlns="' . $this->soap_ns .'">';
  106. $s .= '<idFrom>' . $ind . '</idFrom>';
  107. $s .= '<typeFrom>Contact</typeFrom>';
  108. $s .= '<relationshipFrom>Employee</relationshipFrom>';
  109. $s .= '<idTo>' . $org . '</idTo>';
  110. $s .= '<typeTo>Account</typeTo>';
  111. $s .= '<relationshipTo>Employer</relationshipTo>';
  112. $s .= '</AddLink>';
  113. return $this->glink_execute($this->link, $s, '' );
  114. }
  115. //2ac86405-64d7-4576-a747-3cd1dcdab21f
  116. private function glink_findItem( $objectType, $filterParams, $extraFields, $callBackFunction, $echo=false )
  117. {
  118. // Build find
  119. $s = '';
  120. $s .= '<FindItem xmlns="' . $this->soap_ns . '">';
  121. $s .= '<objectType>' . $objectType . '</objectType>';
  122. $s .= '<XmlFilters><filters xmlns="">';
  123. for ($i = 0; $i < count( $filterParams ); $i++)
  124. {
  125. $s .= '<filter dbcolumn="'. $filterParams[ $i ]["dbcolumn"] . '" type="' . $filterParams[ $i ]["type"] . '" value="' . $filterParams[ $i ]["value"] . '" />';
  126. }
  127. for ( $i = 0; $i < count( $extraFields ); $i++)
  128. {
  129. $s .= '<field dbcolumn="' . $extraFields[ $i ]["dbcolumn"] . '" />';
  130. }
  131. $s .= '</filters></XmlFilters>';
  132. $s .= '</FindItem>';
  133. // Send to Gold-Link
  134. return $this->glink_execute( $this->find, $s, $callBackFunction, $echo);
  135. }
  136. private function glink_execute( $soapAction, $soapXml, $callBackFunctionm, $echo=false )
  137. {
  138. //
  139. $s = "<" . '?xml version="1.0" encoding="utf-8"?>';
  140. $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/">';
  141. $s .= ' <soap:Body>';
  142. // Soap data
  143. $s .= $soapXml;
  144. // End boilerpate
  145. $s .= ' </soap:Body>';
  146. $s .= '</soap:Envelope>';
  147. $url = $this->server . $this->goldLink . "?z=" . time();
  148. $parsed = parse_url($url);
  149. $port = ( isset($parsed['port']) ) ? $parsed['port'] : 80;
  150. $path = ( empty($parsed['path']) ) ? '/' : $parsed['path'];
  151. $path .= ( empty($parsed['query']) ) ? '' : '?'.$parsed['query'];
  152. $ch = curl_init();
  153. curl_setopt( $ch, CURLOPT_URL, $url );
  154. curl_setopt($ch, CURLOPT_POST, 1);
  155. curl_setopt($ch, CURLOPT_POSTFIELDS, $s );
  156. //curl_setopt($ch, CURLOPT_HEADER, true); // Display headers
  157. curl_setopt($ch, CURLOPT_VERBOSE, true); // Display communication with server
  158. curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_NTLM );
  159. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false );
  160. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // Return data instead of display to std out
  161. curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: text/xml;", "SOAPAction: " . $soapAction));
  162. //curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: text/xml; charset=utf-8","SOAPAction: " . $soapAction, "Content-Length: ".strlen($s)));
  163. curl_setopt( $ch, CURLOPT_USERPWD, $this->username . ':' . $this->password);
  164. if( $echo )
  165. {
  166. echo $s;
  167. echo '<br /><br /><br />';
  168. }
  169. //execute post
  170. $result = curl_exec($ch);
  171. if( $echo )
  172. {
  173. echo $result;
  174. //exit();
  175. }
  176. //echo $result;
  177. //exit();
  178. //close connection
  179. curl_close($ch);
  180. return $result;
  181. }
  182. /**public function getAccounts( $xml )
  183. {
  184. $results = array();
  185. // Get root node information from XML
  186. var xml_root = xml.childNodes[xml.childNodes.length - 1];
  187. var xml_list = xml_root.childNodes[0].childNodes[0].childNodes[0].childNodes[0].childNodes[0];
  188. // Clear any existing entries
  189. while(document.getElementById("listresults").childNodes.length > 0)
  190. document.getElementById("listresults").removeChild(document.getElementById("listresults").childNodes[0]);
  191. for (var i = 0; i < xml_list.childNodes.length; i++) {
  192. // Add to screen
  193. var option = document.createElement("option");
  194. option.value = xml_list.childNodes[i].getAttribute("id");
  195. option.text = xml_list.childNodes[i].getAttribute("summary");
  196. option.innerHTML = xml_list.childNodes[i].getAttribute("summary");
  197. document.getElementById("listresults").appendChild(option);
  198. // Store in an array
  199. matchResults[i] = {
  200. "id":xml_list.childNodes[i].getAttribute("id"),
  201. "summary":xml_list.childNodes[i].getAttribute("summary"),
  202. "postcode":xml_list.childNodes[i].getAttribute("postcode"),
  203. "ac_type":xml_list.childNodes[i].getAttribute("ac_type"),
  204. "main_sales_contact":xml_list.childNodes[i].getAttribute("main_sales_contact"),
  205. "acc_id_sales":xml_list.childNodes[i].getAttribute("acc_id_sales"),
  206. "us_id_sales":xml_list.childNodes[i].getAttribute("us_id_sales"),
  207. "account_manager":xml_list.childNodes[i].getAttribute("account_manager")
  208. };
  209. }
  210. }*/
  211. }
  212. ?>