3 require
"NSconfig.php";
12 foreach ($array as $key => $value)
14 if ( $value ===
false || ( !is_null($value) && $value !=
"" && !
arrayValuesAreEmpty($value)))
25 if ( is_array($array) && ! empty($array) )
27 for ( $iterator = count($array) - 1; $iterator; $iterator-- )
29 if ( ! array_key_exists($iterator, $array) ) {
return true; }
31 return ! array_key_exists(0, $array);
39 $classname = get_class($object);
41 $typesmap = $classname::$paramtypesmap;
43 if (!isset ($typesmap)) {
48 if ($fieldArray == null)
54 foreach ($fieldArray as $fldName => $fldValue)
56 if (((is_null($fldValue) || $fldValue ==
"") && $fldValue !==
false) ||
arrayValuesAreEmpty($fldValue))
62 if (!isset($typesmap[$fldName])) {
64 trigger_error(
"SetFields error: parameter \"" .$fldName .
"\" is not a valid parameter for an object of class \"" . $classname .
"\", it will be omitted", E_USER_WARNING);
68 if ($fldValue ===
'false')
71 $object->$fldName = FALSE;
73 elseif (is_object($fldValue))
75 $object->$fldName = $fldValue;
80 if (substr($typesmap[$fldName],-2) ==
"[]") {
81 trigger_error(
"Trying to assign an object into an array parameter \"" .$fldName .
"\" of class \"" . $classname .
"\", it will be omitted", E_USER_WARNING);
84 $obj =
new $typesmap[$fldName]();
86 $object->$fldName = $obj;
91 if (substr($typesmap[$fldName],-2) !=
"[]") {
93 trigger_error(
"Trying to assign an array value into parameter \"" .$fldName .
"\" of class \"" . $classname .
"\", it will be omitted", E_USER_WARNING);
98 $basetype = substr($typesmap[$fldName],0,-2);
101 foreach ($fldValue as $item)
103 if (is_object($item))
108 elseif ($typesmap[$fldName] ==
"string")
117 $obj =
new $basetype();
123 $object->$fldName = $val;
127 $object->$fldName = $fldValue;
134 $m = explode(
' ',microtime());
135 return (
int)round($m[0]*10000,4);
140 $xml_root = str_replace(
'xsi:type',
'xsitype', $xml_root);
141 $record_element =
new SimpleXMLElement($xml_root);
143 foreach ($record_element->getDocNamespaces() as $name => $ns)
147 $xml_root = str_replace($name .
':',
'', $xml_root);
151 $record_element =
new SimpleXMLElement($xml_root);
153 foreach($record_element->children() as $field)
155 $field_element =
new SimpleXMLElement($field->asXML());
157 foreach ($field_element->getDocNamespaces() as $name2 => $ns2)
161 $xml_root = str_replace($name2 .
':',
'', $xml_root);
170 private $nsversion =
"2015_1r1";
174 private $soapHeaders = array();
175 private $userequest =
true;
181 global $nshost, $nsendpoint;
182 global $nsaccount, $nsemail, $nsrole, $nspassword;
186 if (!isset($nshost)) {
187 throw new Exception(
'Webservice host must be specified');
189 if (!isset($nsendpoint)) {
190 throw new Exception(
'Webservice endpoint must be specified');
192 $wsdl = $nshost .
"/wsdl/v" . $nsendpoint .
"_0/netsuite.wsdl";
195 if (!extension_loaded(
'soap')) {
197 $soap_warning =
'The SOAP PHP extension is not loaded. Please modify the extension settings in php.ini accordingly.';
198 trigger_error($soap_warning, E_USER_WARNING);
201 if (!extension_loaded(
'openssl') && substr($wsdl, 0, 5) ==
"https") {
203 $soap_warning =
'The Open SSL PHP extension is not loaded and you are trying to use HTTPS protocol. Please modify the extension settings in php.ini accordingly.';
204 trigger_error($soap_warning, E_USER_WARNING);
207 if ( $this->generated_from_endpoint != $nsendpoint ) {
209 $endpoint_warning =
'The NetSuiteService classes were generated from the '.$this->generated_from_endpoint .
' endpoint but you are running against ' . $nsendpoint;
210 trigger_error($endpoint_warning, E_USER_WARNING);
214 $options[
'trace'] = 1;
215 $options[
'connection_timeout'] = 5;
216 $options[
'cache_wsdl'] = WSDL_CACHE_BOTH;
217 $httpheaders =
"PHP-SOAP/" . phpversion() .
" + NetSuite PHP Toolkit " . $this->nsversion;
219 $options[
'location'] = $nshost .
"/services/NetSuitePort_" . $nsendpoint;
220 $options[
'keep_alive'] =
false;
221 $options[
'features'] = SOAP_SINGLE_ELEMENT_ARRAYS;
223 $context = array(
'http' =>
225 'header' =>
'Authorization: dnwdjewdnwe'
230 if (isset($debuginfo)) {
231 $httpheaders .=
"\r\nDebug: true";
232 $httpheaders .=
"\r\nUser: " . $debuginfo[
"email"];
233 $httpheaders .=
"\r\nPassword: " . $debuginfo[
"password"];
234 $httpheaders .=
"\r\nIssue: " . $debuginfo[
"issue"];
237 $options[
'user_agent'] = $httpheaders;
238 $this->
setPassport($nsaccount, $nsemail, $nsrole, $nspassword);
240 $this->client =
new SoapClient($wsdl, $options);
243 public function setPassport($nsaccount, $nsemail, $nsrole, $nspassword) {
245 $this->passport->account = $nsaccount;
246 $this->passport->email = $nsemail;
247 $this->passport->password = $nspassword;
249 $this->passport->role->internalId = $nsrole;
253 $this->userequest = $option;
256 public function setPreferences ($warningAsError =
false, $disableMandatoryCustomFieldValidation =
false, $disableSystemNotesForCustomFields =
false, $ignoreReadOnlyFields =
false)
259 $sp->warningAsError = $warningAsError;
260 $sp->disableMandatoryCustomFieldValidation = $disableMandatoryCustomFieldValidation;
261 $sp->disableSystemNotesForCustomFields = $disableSystemNotesForCustomFields;
262 $sp->ignoreReadOnlyFields = $ignoreReadOnlyFields;
274 $sp->bodyFieldsOnly = $bodyFieldsOnly;
275 $sp->pageSize = $pageSize;
276 $sp->returnSearchColumns = $returnSearchColumns;
278 $this->
addHeader(
"searchPreferences", $sp);
286 $this->soapHeaders[$header_name] =
new SoapHeader(
"ns", $header_name, $header);
289 unset($this->soapHeaders[$header_name]);
293 if ($this->userequest) {
295 $this->
addHeader(
"passport", $this->passport);
297 $this->client->__setCookie(
"JSESSIONID");
302 $response = $this->client->__soapCall($operation, array($parameter), NULL, $this->soapHeaders);
304 if ( file_exists(dirname(__FILE__) .
'/nslog') ) {
307 $req = dirname(__FILE__) .
'/nslog' .
"/" . date(
"Ymd.His") .
"." .
milliseconds() .
"-" . $operation .
"-request.xml";
308 $Handle = fopen($req,
'w');
309 $Data = $this->client->__getLastRequest();
313 $xml = simplexml_load_string($Data,
'SimpleXMLElement', LIBXML_NOCDATA);
315 $passwordFields = $xml->xpath(
"//password | //password2 | //currentPassword | //newPassword | //newPassword2 | //ccNumber | //ccSecurityCode | //socialSecurityNumber");
317 foreach ($passwordFields as &$pwdField) {
318 (string)$pwdField[0] =
"[Content Removed for Security Reasons]";
321 $stringCustomFields = $xml->xpath(
"//customField[@xsitype='StringCustomFieldRef']");
323 foreach ($stringCustomFields as $field) {
324 (string)$field->value =
"[Content Removed for Security Reasons]";
327 $xml_string = str_replace(
'xsitype',
'xsi:type', $xml->asXML());
329 fwrite($Handle, $xml_string);
333 $resp = dirname(__FILE__) .
'/nslog' .
"/" . date(
"Ymd.His") .
"." .
milliseconds() .
"-" . $operation .
"-response.xml";
334 $Handle = fopen($resp,
'w');
335 $Data = $this->client->__getLastResponse();
336 fwrite($Handle, $Data);
setPreferences($warningAsError=false, $disableMandatoryCustomFieldValidation=false, $disableSystemNotesForCustomFields=false, $ignoreReadOnlyFields=false)
cleanUpNamespaces($xml_root)
arrayValuesAreEmpty($array)
clearHeader($header_name)
makeSoapCall($operation, $parameter)
array_is_associative($array)
setPassport($nsaccount, $nsemail, $nsrole, $nspassword)
useRequestLevelCredentials($option)
__construct($wsdl=null, $options=array())
addHeader($header_name, $header)
setFields($object, array $fieldArray=null)
setSearchPreferences($bodyFieldsOnly=true, $pageSize=50, $returnSearchColumns=true)