From 1605e72adba33275a288346588289361c283c154 Mon Sep 17 00:00:00 2001 From: fhenry Date: Tue, 15 Jan 2013 21:43:11 +0100 Subject: [PATCH] Add update actioncomm webservice method Fix bug on update thridparty webservice method --- htdocs/webservices/server_actioncomm.php | 117 ++++++++++++++++++++++- htdocs/webservices/server_thirdparty.php | 11 +-- 2 files changed, 117 insertions(+), 11 deletions(-) diff --git a/htdocs/webservices/server_actioncomm.php b/htdocs/webservices/server_actioncomm.php index 7014c8d331f..c43aeedddd9 100644 --- a/htdocs/webservices/server_actioncomm.php +++ b/htdocs/webservices/server_actioncomm.php @@ -220,6 +220,20 @@ $server->register( 'WS to create a actioncomm' ); +// Register WSDL +$server->register( + 'updateActionComm', + // Entry values + array('authentication'=>'tns:authentication','actioncomm'=>'tns:actioncomm'), + // Exit values + array('result'=>'tns:result'), + $ns, + $ns.'#updateActionComm', + $styledoc, + $styleuse, + 'WS to update a actioncomm' +); + @@ -473,7 +487,104 @@ function createActionComm($authentication,$actioncomm) return $objectresp; } -// Return the results. -$server->service($HTTP_RAW_POST_DATA); +/** + * Create ActionComm + * + * @param array $authentication Array of authentication information + * @param ActionComm $actioncomm $actioncomm + * @return array Array result + */ +function updateActionComm($authentication,$actioncomm) +{ + global $db,$conf,$langs; -?> + $now=dol_now(); + + dol_syslog("Function: updateActionComm 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($actioncomm['id'])) { + $error++; $errorcode='KO'; $errorlabel="Actioncomm id is mandatory."; + } + + if (! $error) + { + $objectfound=false; + + $object=new ActionComm($db); + $result=$object->fetch($actioncomm['id']); + + if (!empty($object->id)) { + + $objectfound=true; + + $object->datep=$actioncomm['datep']; + $object->datef=$actioncomm['datef']; + $object->type_code=$actioncomm['type_code']; + $object->societe->id=$actioncomm['socid']; + $object->fk_project=$actioncomm['projectid']; + $object->note=$actioncomm['note']; + $object->contact->id=$actioncomm['contactid']; + $object->usertodo->id=$actioncomm['usertodo']; + $object->userdone->id=$actioncomm['userdone']; + $object->label=$actioncomm['label']; + $object->percentage=$actioncomm['percentage']; + $object->priority=$actioncomm['priority']; + $object->fulldayevent=$actioncomm['fulldayevent']; + $object->location=$actioncomm['location']; + $object->fk_element=$actioncomm['fk_element']; + $object->elementtype=$actioncomm['elementtype']; + + //Retreive all extrafield for actioncomm + // fetch optionals attributes and labels + $extrafields=new ExtraFields($db); + $extralabels=$extrafields->fetch_name_optionals_label('actioncomm'); + foreach($extrafields->attribute_label as $key=>$label) + { + $key='options_'.$key; + $newobject->array_options[$key]=$actioncomm[$key]; + } + + $db->begin(); + + $result=$object->update($fuser); + if ($result <= 0) { + $error++; + } + } + + if ((! $error) && ($objectfound)) + { + $db->commit(); + $objectresp=array('result'=>array('result_code'=>'OK', 'result_label'=>'')); + } + elseif ($objectfound) + { + $db->rollback(); + $error++; + $errorcode='KO'; + $errorlabel=$object->error; + } else { + $error++; + $errorcode='NOT_FOUND'; + $errorlabel='Actioncomm id='.$actioncomm['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); \ No newline at end of file diff --git a/htdocs/webservices/server_thirdparty.php b/htdocs/webservices/server_thirdparty.php index 40c5bdefd6e..1e3ee7cedca 100755 --- a/htdocs/webservices/server_thirdparty.php +++ b/htdocs/webservices/server_thirdparty.php @@ -506,7 +506,6 @@ function updateThirdParty($authentication,$thirdparty) $error++; $errorcode='KO'; $errorlabel="Thirdparty id is mandatory."; } - if (! $error) { $objectfound=false; @@ -514,9 +513,9 @@ function updateThirdParty($authentication,$thirdparty) include_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php'; $object=new Societe($db); - $result=$object->fetch($id); + $result=$object->fetch($thirdparty['id']); - if (!empty($thirdparty['id'])) { + if (!empty($object->id)) { $objectfound=true; @@ -680,9 +679,5 @@ function getListOfThirdParties($authentication,$filterthirdparty) return $objectresp; } - - // Return the results. -$server->service($HTTP_RAW_POST_DATA); - -?> +$server->service($HTTP_RAW_POST_DATA); \ No newline at end of file