mirror of
https://github.com/Dolibarr/dolibarr.git
synced 2025-02-20 13:46:52 +01:00
New webservice method to update contact
This commit is contained in:
parent
3780d0fde6
commit
cb0404a750
|
|
@ -211,7 +211,19 @@ $server->register(
|
|||
'WS to get all contacts of a third party'
|
||||
);
|
||||
|
||||
|
||||
// Register WSDL
|
||||
$server->register(
|
||||
'updateContact',
|
||||
// Entry values
|
||||
array('authentication'=>'tns:authentication','contact'=>'tns:contact'),
|
||||
// Exit values
|
||||
array('result'=>'tns:result','id'=>'xsd:string'),
|
||||
$ns,
|
||||
$ns.'#updateContact',
|
||||
$styledoc,
|
||||
$styleuse,
|
||||
'WS to update a contact'
|
||||
);
|
||||
|
||||
|
||||
/**
|
||||
|
|
@ -581,6 +593,112 @@ function getContactsForThirdParty($authentication,$idthirdparty)
|
|||
return $objectresp;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Update a contact
|
||||
*
|
||||
* @param array $authentication Array of authentication information
|
||||
* @param Contact $contact Contact
|
||||
* @return array Array result
|
||||
*/
|
||||
function updateContact($authentication,$contact)
|
||||
{
|
||||
global $db,$conf,$langs;
|
||||
|
||||
$now=dol_now();
|
||||
|
||||
dol_syslog("Function: updateContact login=".$authentication['login']);
|
||||
|
||||
if ($authentication['entity']) $conf->entity=$authentication['entity'];
|
||||
|
||||
// Init and check authentication
|
||||
$objectresp=array();
|
||||
$errorcode='';$errorlabel='';
|
||||
$error=0;
|
||||
$fuser=check_authentication($authentication,$error,$errorcode,$errorlabel);
|
||||
// Check parameters
|
||||
if (empty($contact['id'])) {
|
||||
$error++; $errorcode='KO'; $errorlabel="Contact id is mandatory.";
|
||||
}
|
||||
|
||||
if (! $error)
|
||||
{
|
||||
$objectfound=false;
|
||||
|
||||
include_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
|
||||
|
||||
$object=new Contact($db);
|
||||
$result=$object->fetch($contact['id']);
|
||||
|
||||
if (!empty($object->id)) {
|
||||
|
||||
$objectfound=true;
|
||||
|
||||
|
||||
$object->firstname=$contact['firstname'];
|
||||
$object->lastname=$contact['lastname'];
|
||||
|
||||
$object->address=$contact['address'];
|
||||
$object->zip=$contact['zip'];
|
||||
$object->town=$contact['town'];
|
||||
|
||||
$object->country_id=$contact['country_id'];
|
||||
if ($contact['country_code']) $object->country_id=getCountry($contact['country_code'],3);
|
||||
$object->province_id=$contact['province_id'];
|
||||
|
||||
|
||||
$object->phone_perso=$contact['phone_perso'];
|
||||
$object->phone_mobile=$contact['phone_mobile'];
|
||||
$object->fax=$contact['fax'];
|
||||
$object->email=$contact['email'];
|
||||
|
||||
|
||||
//Retreive all extrafield for contact
|
||||
// fetch optionals attributes and labels
|
||||
$extrafields=new ExtraFields($db);
|
||||
$extralabels=$extrafields->fetch_name_optionals_label('contact',true);
|
||||
foreach($extrafields->attribute_label as $key=>$label)
|
||||
{
|
||||
$key='options_'.$key;
|
||||
$object->array_options[$key]=$contact[$key];
|
||||
}
|
||||
|
||||
$db->begin();
|
||||
|
||||
$result=$object->update($contact['id'],$fuser);
|
||||
if ($result <= 0) {
|
||||
$error++;
|
||||
}
|
||||
}
|
||||
|
||||
if ((! $error) && ($objectfound))
|
||||
{
|
||||
$db->commit();
|
||||
$objectresp=array(
|
||||
'result'=>array('result_code'=>'OK', 'result_label'=>''),
|
||||
'id'=>$object->id
|
||||
);
|
||||
}
|
||||
elseif ($objectfound)
|
||||
{
|
||||
$db->rollback();
|
||||
$error++;
|
||||
$errorcode='KO';
|
||||
$errorlabel=$object->error;
|
||||
} else {
|
||||
$error++;
|
||||
$errorcode='NOT_FOUND';
|
||||
$errorlabel='Contact id='.$contact['id'].' cannot be found';
|
||||
}
|
||||
}
|
||||
|
||||
if ($error)
|
||||
{
|
||||
$objectresp = array('result'=>array('result_code' => $errorcode, 'result_label' => $errorlabel));
|
||||
}
|
||||
|
||||
return $objectresp;
|
||||
}
|
||||
// Return the results.
|
||||
$server->service($HTTP_RAW_POST_DATA);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user