diff --git a/htdocs/fourn/commande/card.php b/htdocs/fourn/commande/card.php index 263a96bdca4ed..4ae8fb1775407 100644 --- a/htdocs/fourn/commande/card.php +++ b/htdocs/fourn/commande/card.php @@ -1049,8 +1049,8 @@ if ($action == 'webservice' && GETPOST('mode', 'alpha') == "send" && ! GETPOST('cancel')) { - $ws_host = GETPOST('ws_host','alpha'); - $ws_key = GETPOST('ws_key','alpha'); + $ws_url = $object->thirdparty->webservices_url; + $ws_key = $object->thirdparty->webservices_key; $ws_user = GETPOST('ws_user','alpha'); $ws_password = GETPOST('ws_password','alpha'); $ws_entity = GETPOST('ws_entity','int'); @@ -1069,18 +1069,20 @@ //Is sync supplier web services module activated? and everything filled? if (empty($conf->syncsupplierwebservices->enabled)) { setEventMessage($langs->trans("WarningModuleNotActive",$langs->transnoentities("Module2650Name"))); - } else if ($mode != "init" && (empty($ws_host) || empty($ws_key) || empty($ws_user) || empty($ws_password) || empty($ws_thirdparty))) { + } else if (empty($ws_url) || empty($ws_key)) { + setEventMessage($langs->trans("ErrorWebServicesFieldsRequired"), 'errors'); + } else if (empty($ws_user) || empty($ws_password) || empty($ws_thirdparty)) { setEventMessage($langs->trans("ErrorFieldsRequired"), 'errors'); } else { //Create SOAP client and connect it to order - $soapclient_order = new nusoap_client($ws_host."/webservices/server_order.php"); + $soapclient_order = new nusoap_client($ws_url."/webservices/server_order.php"); $soapclient_order->soap_defencoding='UTF-8'; $soapclient_order->decodeUTF8(false); //Create SOAP client and connect it to product/service - $soapclient_product = new nusoap_client($ws_host."/webservices/server_productorservice.php"); + $soapclient_product = new nusoap_client($ws_url."/webservices/server_productorservice.php"); $soapclient_product->soap_defencoding='UTF-8'; $soapclient_product->decodeUTF8(false); @@ -1123,7 +1125,11 @@ $ws_parameters = array('authentication'=>$ws_authentication, 'order' => $order); $result_order = $soapclient_order->call("createOrder", $ws_parameters, $ws_ns, ''); - if ($result_order["result"]["result_code"] != "OK") + if (empty($result_order["result"]["result_code"])) //No result, check error str + { + setEventMessage($langs->trans("SOAPError")." '".$soapclient_order->error_str."'", 'errors'); + } + else if ($result_order["result"]["result_code"] != "OK") //Something went wrong { setEventMessage($langs->trans("SOAPError")." '".$result_order["result"]["result_code"]."' - '".$result_order["result"]["result_label"]."'", 'errors'); } @@ -1970,8 +1976,8 @@ elseif ($action == 'webservice' && GETPOST('mode', 'alpha') != "send" && ! GETPOST('cancel')) { $mode = GETPOST('mode', 'alpha'); - $ws_host = GETPOST('ws_host','alpha'); - $ws_key = GETPOST('ws_key','alpha'); + $ws_url = $object->thirdparty->webservices_url; + $ws_key = $object->thirdparty->webservices_key; $ws_user = GETPOST('ws_user','alpha'); $ws_password = GETPOST('ws_password','alpha'); @@ -1988,7 +1994,11 @@ print_titre($langs->trans('CreateRemoteOrder')); //Is everything filled? - if ($mode != "init" && (empty($ws_host) || empty($ws_key) || empty($ws_user) || empty($ws_password))) { + if (empty($ws_url) || empty($ws_key)) { + setEventMessage($langs->trans("ErrorWebServicesFieldsRequired"), 'errors'); + $mode = "init"; + $error_occurred = true; //Don't allow to set the user/pass if thirdparty fields are not filled + } else if ($mode != "init" && (empty($ws_user) || empty($ws_password))) { setEventMessage($langs->trans("ErrorFieldsRequired"), 'errors'); $mode = "init"; } @@ -2001,26 +2011,29 @@ print ''; print ''; print ''; - $textinput_size = "50"; - - //Remote Host URL - print ''.$langs->trans("Host").''; - - //Remote Webservices key - print ''.$langs->trans("KeyForWebServicesAccess").''; - - //Remote User - print ''.$langs->trans("User").''; - //Remote Password - print ''.$langs->trans("Password").''; - - //Submit and cancel buttons - print ''; - print ''; - print '     '; - print ''; - print ''; + if ($error_occurred) + { + print "
".$langs->trans("ErrorOccurredReviseAndRetry")."
"; + print ''; + } + else + { + $textinput_size = "50"; + // Webservice url + print ''.$langs->trans("WebServiceURL").''.dol_print_url($ws_url).''; + //Remote User + print ''.$langs->trans("User").''; + //Remote Password + print ''.$langs->trans("Password").''; + //Submit button + print ''; + print ''; + print '     '; + //Cancel button + print ''; + print ''; + } //End table/form print ''; @@ -2032,14 +2045,8 @@ $ws_thirdparty = ''; $error_occurred = false; - //Check if has transport, without any the soap client will give error - if (strpos($ws_host, "http") === false) - { - $ws_host = "http://".$ws_host; - } - //Create SOAP client and connect it to user - $soapclient_user = new nusoap_client($ws_host."/webservices/server_user.php"); + $soapclient_user = new nusoap_client($ws_url."/webservices/server_user.php"); $soapclient_user->soap_defencoding='UTF-8'; $soapclient_user->decodeUTF8(false); @@ -2062,7 +2069,7 @@ else { //Create SOAP client and connect it to product/service - $soapclient_product = new nusoap_client($ws_host."/webservices/server_productorservice.php"); + $soapclient_product = new nusoap_client($ws_url."/webservices/server_productorservice.php"); $soapclient_product->soap_defencoding='UTF-8'; $soapclient_product->decodeUTF8(false); @@ -2086,7 +2093,11 @@ // Check the result code $status_code = $result_product["result"]["result_code"]; - if ($status_code != "OK") + if (empty($status_code)) //No result, check error str + { + setEventMessage($langs->trans("SOAPError")." '".$soapclient_order->error_str."'", 'errors'); + } + else if ($status_code != "OK") //Something went wrong { if ($status_code == "NOT_FOUND") { @@ -2135,6 +2146,11 @@ setEventMessage($langs->trans("RemoteUserNotPermission"), 'errors'); $error_occurred = true; } + elseif ($user_status_code == "BAD_CREDENTIALS") + { + setEventMessage($langs->trans("RemoteUserBadCredentials"), 'errors'); + $error_occurred = true; + } else { setEventMessage($langs->trans("ResponseNonOK")." '".$user_status_code."'", 'errors'); @@ -2146,15 +2162,13 @@ print ''; print ''; print ''; - print ''; - print ''; print ''; print ''; print ''; print ''; if ($error_occurred) { - print "
".$langs->trans("ErrorOccurredReviseAndRetry")."
"; //TODO: Translate + print "
".$langs->trans("ErrorOccurredReviseAndRetry")."
"; } else { diff --git a/htdocs/install/mysql/migration/3.6.0-3.7.0.sql b/htdocs/install/mysql/migration/3.6.0-3.7.0.sql index c2e10543b7ae1..552563db677f3 100644 --- a/htdocs/install/mysql/migration/3.6.0-3.7.0.sql +++ b/htdocs/install/mysql/migration/3.6.0-3.7.0.sql @@ -1110,3 +1110,6 @@ DELETE FROM llx_menu WHERE module = 'boutique'; -- Add option always editable on extrafield ALTER TABLE llx_extrafields ADD alwayseditable INTEGER DEFAULT 0 AFTER pos; +-- add supplier webservice fields +ALTER TABLE llx_societe ADD webservices_url varchar(255) DEFAULT NULL; +ALTER TABLE llx_societe ADD webservices_key varchar(128) DEFAULT NULL; diff --git a/htdocs/install/mysql/tables/llx_societe.sql b/htdocs/install/mysql/tables/llx_societe.sql index bfe69b0d5f857..b9327ba521c65 100644 --- a/htdocs/install/mysql/tables/llx_societe.sql +++ b/htdocs/install/mysql/tables/llx_societe.sql @@ -92,4 +92,6 @@ create table llx_societe logo varchar(255), canvas varchar(32), -- type of canvas if used (null by default) import_key varchar(14) -- import key + webservices_url varchar(255), -- supplier webservice url + webservices_key varchar(128), -- supplier webservice key )ENGINE=innodb; diff --git a/htdocs/societe/class/societe.class.php b/htdocs/societe/class/societe.class.php index 6d80189c7beae..79d24a8d917df 100644 --- a/htdocs/societe/class/societe.class.php +++ b/htdocs/societe/class/societe.class.php @@ -334,6 +334,18 @@ class Societe extends CommonObject */ var $import_key; + /** + * Supplier WebServices URL + * @var string + */ + var $webservices_url; + + /** + * Supplier WebServices Key + * @var string + */ + var $webservices_key; + var $logo; var $logo_small; var $logo_mini; @@ -715,6 +727,10 @@ function update($id, $user='', $call_trigger=1, $allowmodcodeclient=0, $allowmod $supplier=true; } + //Web services + $this->webservices_url = $this->webservices_url?clean_url($this->webservices_url,0):''; + $this->webservices_key = trim($this->webservices_key); + $this->db->begin(); // Check name is required and codes are ok or unique. @@ -795,6 +811,9 @@ function update($id, $user='', $call_trigger=1, $allowmodcodeclient=0, $allowmod $sql .= ",default_lang = ".(! empty($this->default_lang)?"'".$this->default_lang."'":"null"); $sql .= ",logo = ".(! empty($this->logo)?"'".$this->logo."'":"null"); + $sql .= ",webservices_url = ".(! empty($this->webservices_url)?"'".$this->db->escape($this->webservices_url)."'":"null"); + $sql .= ",webservices_key = ".(! empty($this->webservices_key)?"'".$this->db->escape($this->webservices_key)."'":"null"); + if ($customer) { $sql .= ", code_client = ".(! empty($this->code_client)?"'".$this->db->escape($this->code_client)."'":"null"); @@ -951,6 +970,7 @@ function fetch($rowid, $ref='', $ref_ext='', $ref_int='', $idprof1='',$idprof2=' $sql .= ', s.fk_typent as typent_id'; $sql .= ', s.fk_effectif as effectif_id'; $sql .= ', s.fk_forme_juridique as forme_juridique_code'; + $sql .= ', s.webservices_url, s.webservices_key'; $sql .= ', s.code_client, s.code_fournisseur, s.code_compta, s.code_compta_fournisseur, s.parent, s.barcode'; $sql .= ', s.fk_departement, s.fk_pays as country_id, s.fk_stcomm, s.remise_client, s.mode_reglement, s.cond_reglement, s.tva_assuj'; $sql .= ', s.mode_reglement_supplier, s.cond_reglement_supplier, s.localtax1_assuj, s.localtax1_value, s.localtax2_assuj, s.localtax2_value, s.fk_prospectlevel, s.default_lang, s.logo'; @@ -1086,6 +1106,9 @@ function fetch($rowid, $ref='', $ref_ext='', $ref_int='', $idprof1='',$idprof2=' $this->default_lang = $obj->default_lang; $this->logo = $obj->logo; + $this->webservices_url = $obj->webservices_url; + $this->webservices_key = $obj->webservices_key; + $this->outstanding_limit = $obj->outstanding_limit; // multiprix diff --git a/htdocs/societe/soc.php b/htdocs/societe/soc.php index a0b9bda1c8e0e..8117de5f09b78 100644 --- a/htdocs/societe/soc.php +++ b/htdocs/societe/soc.php @@ -119,7 +119,7 @@ $res=$object->setValueFrom('localtax2_value', $value); } - // Add new third party + // Add new or update third party if ((! GETPOST('getcustomercode') && ! GETPOST('getsuppliercode')) && ($action == 'add' || $action == 'update') && $user->rights->societe->creer) { @@ -189,6 +189,10 @@ $object->commercial_id = GETPOST('commercial_id', 'int'); $object->default_lang = GETPOST('default_lang'); + // Webservices url/key + $object->webservices_url = GETPOST('webservices_url', 'custom', 0, FILTER_SANITIZE_URL); + $object->webservices_key = GETPOST('webservices_key', 'san_alpha'); + // Fill array 'array_options' with data from add form $ret = $extrafields->setOptionalsFromPost($extralabels,$object); @@ -217,6 +221,18 @@ $error++; $errors[] = $langs->trans("ErrorSupplierModuleNotEnabled"); $action = ($action=='add'?'create':'edit'); } + if (! empty($object->webservices_url)) { + //Check if has transport, without any the soap client will give error + if (strpos($object->webservices_url, "http") === false) + { + $object->webservices_url = "http://".$object->webservices_url; + } + if (! isValidUrl($object->webservices_url)) { + $langs->load("errors"); + $error++; $errors[] = $langs->trans("ErrorBadUrl",$object->webservices_url); + $action = ($action=='add'?'create':'edit'); + } + } // We set country_id, country_code and country for the selected country $object->country_id=GETPOST('country_id')!=''?GETPOST('country_id'):$mysoc->country_id; @@ -1179,6 +1195,10 @@ $object->tva_intra = GETPOST('tva_intra', 'alpha'); $object->status = GETPOST('status', 'int'); + // Webservices url/key + $object->webservices_url = GETPOST('webservices_url', 'custom', 0, FILTER_SANITIZE_URL); + $object->webservices_key = GETPOST('webservices_key', 'san_alpha'); + //Local Taxes $object->localtax1_assuj = GETPOST('localtax1assuj_value'); $object->localtax2_assuj = GETPOST('localtax2assuj_value'); @@ -1558,6 +1578,14 @@ print $object->showOptionals($extrafields,'edit'); } + // Webservices url/key + if (!empty($conf->syncsupplierwebservices->enabled)) { + print ''; + print ''; + print ''; + print ''; + } + // Logo print ''; print ''; @@ -2014,6 +2042,12 @@ print "\n"; } + // Webservices url/key + if (!empty($conf->syncsupplierwebservices->enabled)) { + print ''.$langs->trans("WebServiceURL").''.dol_print_url($object->webservices_url).''; + print ''.$langs->trans('WebServiceKey').''.$object->webservices_key.''; + } + print ''; dol_fiche_end();