Skip to content

Commit

Permalink
Added ws url/key to thirdparty SQL table, class and info page
Browse files Browse the repository at this point in the history
  • Loading branch information
IonAgorria committed Oct 31, 2014
1 parent 557cbaf commit 82aa845
Show file tree
Hide file tree
Showing 5 changed files with 117 additions and 41 deletions.
94 changes: 54 additions & 40 deletions htdocs/fourn/commande/card.php
Expand Up @@ -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');
Expand All @@ -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);

Expand Down Expand Up @@ -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');
}
Expand Down Expand Up @@ -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');

Expand All @@ -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";
}
Expand All @@ -2001,26 +2011,29 @@
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="action" value="webservice">';
print '<input type="hidden" name="mode" value="check">';
$textinput_size = "50";

//Remote Host URL
print '<tr><td>'.$langs->trans("Host").'</td><td><input size="'.$textinput_size.'" type="text" name="ws_host"></td></tr>';

//Remote Webservices key
print '<tr><td>'.$langs->trans("KeyForWebServicesAccess").'</td><td><input size="'.$textinput_size.'" type="text" name="ws_key"></td></tr>';

//Remote User
print '<tr><td>'.$langs->trans("User").'</td><td><input size="'.$textinput_size.'" type="text" name="ws_user"></td></tr>';

//Remote Password
print '<tr><td>'.$langs->trans("Password").'</td><td><input size="'.$textinput_size.'" type="text" name="ws_password"></td></tr>';

//Submit and cancel buttons
print '<tr><td align="center" colspan="2">';
print '<input class="button" type="submit" id="ws_submit" name="ws_submit" value="'.$langs->trans("CreateRemoteOrder").'">';
print ' &nbsp; &nbsp; ';
print '<input class="button" type="submit" id="cancel" name="cancel" value="'.$langs->trans("Cancel").'">';
print '</td></tr>';
if ($error_occurred)
{
print "<br>".$langs->trans("ErrorOccurredReviseAndRetry")."<br>";
print '<input class="button" type="submit" id="cancel" name="cancel" value="'.$langs->trans("Cancel").'">';
}
else
{
$textinput_size = "50";
// Webservice url
print '<tr><td>'.$langs->trans("WebServiceURL").'</td><td colspan="3">'.dol_print_url($ws_url).'</td></tr>';
//Remote User
print '<tr><td>'.$langs->trans("User").'</td><td><input size="'.$textinput_size.'" type="text" name="ws_user"></td></tr>';
//Remote Password
print '<tr><td>'.$langs->trans("Password").'</td><td><input size="'.$textinput_size.'" type="text" name="ws_password"></td></tr>';
//Submit button
print '<tr><td align="center" colspan="2">';
print '<input class="button" type="submit" id="ws_submit" name="ws_submit" value="'.$langs->trans("CreateRemoteOrder").'">';
print ' &nbsp; &nbsp; ';
//Cancel button
print '<input class="button" type="submit" id="cancel" name="cancel" value="'.$langs->trans("Cancel").'">';
print '</td></tr>';
}

//End table/form
print '</form>';
Expand All @@ -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);

Expand All @@ -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);

Expand All @@ -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")
{
Expand Down Expand Up @@ -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');
Expand All @@ -2146,15 +2162,13 @@
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="action" value="webservice">';
print '<input type="hidden" name="mode" value="send">';
print '<input type="hidden" name="ws_host" value="'.$ws_host.'">';
print '<input type="hidden" name="ws_key" value="'.$ws_key.'">';
print '<input type="hidden" name="ws_user" value="'.$ws_user.'">';
print '<input type="hidden" name="ws_password" value="'.$ws_password.'">';
print '<input type="hidden" name="ws_entity" value="'.$ws_entity.'">';
print '<input type="hidden" name="ws_thirdparty" value="'.$ws_thirdparty.'">';
if ($error_occurred)
{
print "<br>".$langs->trans("ErrorOccurredReviseAndRetry")."<br>"; //TODO: Translate
print "<br>".$langs->trans("ErrorOccurredReviseAndRetry")."<br>";
}
else
{
Expand Down
3 changes: 3 additions & 0 deletions htdocs/install/mysql/migration/3.6.0-3.7.0.sql
Expand Up @@ -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;
2 changes: 2 additions & 0 deletions htdocs/install/mysql/tables/llx_societe.sql
Expand Up @@ -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;
23 changes: 23 additions & 0 deletions htdocs/societe/class/societe.class.php
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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';
Expand Down Expand Up @@ -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
Expand Down
36 changes: 35 additions & 1 deletion htdocs/societe/soc.php
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -1558,6 +1578,14 @@
print $object->showOptionals($extrafields,'edit');
}

// Webservices url/key
if (!empty($conf->syncsupplierwebservices->enabled)) {
print '<tr><td><label for="webservices_url">'.$langs->trans('WebServiceURL').'</label></td>';
print '<td><input type="text" name="webservices_url" id="webservices_url" size="32" value="'.$object->webservices_url.'"></td>';
print '<td><label for="webservices_key">'.$langs->trans('WebServiceKey').'</label></td>';
print '<td><input type="text" name="webservices_key" id="webservices_key" size="32" value="'.$object->webservices_key.'"></td></tr>';
}

// Logo
print '<tr class="hideonsmartphone">';
print '<td><label for="photoinput">'.$langs->trans("Logo").'</label></td>';
Expand Down Expand Up @@ -2014,6 +2042,12 @@
print "</tr>\n";
}

// Webservices url/key
if (!empty($conf->syncsupplierwebservices->enabled)) {
print '<tr><td>'.$langs->trans("WebServiceURL").'</td><td>'.dol_print_url($object->webservices_url).'</td>';
print '<td class="nowrap">'.$langs->trans('WebServiceKey').'</td><td>'.$object->webservices_key.'</td></tr>';
}

print '</table>';

dol_fiche_end();
Expand Down

0 comments on commit 82aa845

Please sign in to comment.