diff --git a/htdocs/core/lib/files.lib.php b/htdocs/core/lib/files.lib.php index 290ce015543..b3ce04157d0 100644 --- a/htdocs/core/lib/files.lib.php +++ b/htdocs/core/lib/files.lib.php @@ -1217,11 +1217,12 @@ function dol_uncompress($inputfile,$outputdir) * @param string $dir Directory to scan * @param string $regexfilter Regexfilter * @param string $excludefilter Array of Regex for exclude filter (example: array('\.meta$','^\.')) - * @return strnig Full path to most recent file + * @param int $nohook Disable all hooks + * @return string Full path to most recent file */ -function dol_most_recent_file($dir,$regexfilter='',$excludefilter=array('\.meta$','^\.')) +function dol_most_recent_file($dir,$regexfilter='',$excludefilter=array('\.meta$','^\.'),$nohook=false) { - $tmparray=dol_dir_list($dir,'files',0,$regexfilter,$excludefilter,'date',SORT_DESC); + $tmparray=dol_dir_list($dir,'files',0,$regexfilter,$excludefilter,'date',SORT_DESC,'',$nohook); return $tmparray[0]; } ?> diff --git a/htdocs/webservices/server_contact.php b/htdocs/webservices/server_contact.php index dfb235354c3..4434777be74 100644 --- a/htdocs/webservices/server_contact.php +++ b/htdocs/webservices/server_contact.php @@ -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' +); /** @@ -247,12 +259,16 @@ function getContact($authentication,$id,$ref='',$ref_ext='') { $fuser->getrights(); - if ($fuser->rights->societe->contact->lire ) + $contact=new Contact($db); + $result=$contact->fetch($id,$ref,$ref_ext); + if ($result > 0) { - $contact=new Contact($db); - $result=$contact->fetch($id,$ref,$ref_ext); - if ($result > 0) - { + // Only internal user who have contact read permission + // Or for external user who have contact read permission, with restrict on societe_id + if ( + $fuser->rights->societe->contact->lire && !$fuser->societe_id + || ( $fuser->rights->societe->contact->lire && ($fuser->societe_id == $contact->socid)) + ){ $contact_result_fields =array( 'id' => $contact->id, 'lastname' => $contact->lastname, @@ -305,18 +321,18 @@ function getContact($authentication,$id,$ref='',$ref_ext='') 'result'=>array('result_code'=>'OK', 'result_label'=>''), 'contact'=>$contact_result_fields ); - } - else - { - $error++; - $errorcode='NOT_FOUND'; $errorlabel='Object not found for id='.$id.' nor ref='.$ref.' nor ref_ext='.$ref_ext; - } - } - else - { - $error++; - $errorcode='PERMISSION_DENIED'; $errorlabel='User does not have permission for this request'; - } + } + else + { + $error++; + $errorcode='PERMISSION_DENIED'; $errorlabel='User does not have permission for this request'; + } + } + else + { + $error++; + $errorcode='NOT_FOUND'; $errorlabel='Object not found for id='.$id.' nor ref='.$ref.' nor ref_ext='.$ref_ext; + } } if ($error) @@ -581,6 +597,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); diff --git a/htdocs/webservices/server_user.php b/htdocs/webservices/server_user.php index 226f061ba68..c74ea28af51 100644 --- a/htdocs/webservices/server_user.php +++ b/htdocs/webservices/server_user.php @@ -151,6 +151,7 @@ $server->wsdl->addComplexType( ), 'tns:group' ); + $thirdpartywithuser_fields = array( // For thirdparty and contact 'name' => array('name'=>'name','type'=>'xsd:string'), @@ -211,6 +212,20 @@ $server->wsdl->addComplexType( $thirdpartywithuser_fields ); +// Define WSDL user short object +$server->wsdl->addComplexType( + 'shortuser', + 'complexType', + 'struct', + 'all', + '', + array( + 'login' => array('name'=>'login','type'=>'xsd:string'), + 'password' => array('name'=>'password','type'=>'xsd:string'), + 'entity' => array('name'=>'entity','type'=>'xsd:string'), + ) +); + // 5 styles: RPC/encoded, RPC/literal, Document/encoded (not WS-I compliant), Document/literal, Document/literal wrapped @@ -261,6 +276,19 @@ $server->register( 'WS to create an external user with thirdparty and contact' ); +$server->register( + 'SetUserPassword', + // Entry values + array('authentication'=>'tns:authentication','shortuser'=>'tns:shortuser'), + // Exit values + array('result'=>'tns:result','id'=>'xsd:string'), + $ns, + $ns.'#SetUserPassword', + $styledoc, + $styleuse, + 'WS to change password of an user' +); + @@ -554,10 +582,9 @@ function CreateUserFromThirdparty($authentication,$thirdpartywithuser) foreach($extrafields->attribute_label as $key=>$label) { $key='contact_options_'.$key; + $key=substr($key,8); // Remove 'contact_' prefix $contact->array_options[$key]=$thirdpartywithuser[$key]; } - - $contact_id = $contact->create($fuser); @@ -630,6 +657,86 @@ function CreateUserFromThirdparty($authentication,$thirdpartywithuser) return $objectresp; } + +/** + * Set password of an user + * + * @param array $authentication Array of authentication information + * @param array $shortuser Array of login/password info + * @return mixed + */ +function SetUserPassword($authentication,$shortuser) { + + global $db,$conf,$langs; + + dol_syslog("Function: SetUserPassword login=".$authentication['login']." id=".$id." ref=".$ref." ref_ext=".$ref_ext); + + if ($authentication['entity']) $conf->entity=$authentication['entity']; + + $objectresp=array(); + $errorcode='';$errorlabel=''; + $error=0; + + $fuser=check_authentication($authentication,$error,$errorcode,$errorlabel); + + if ($fuser->societe_id) $socid=$fuser->societe_id; + + if (! $error && ! $shortuser) + { + $error++; + $errorcode='BAD_PARAMETERS'; $errorlabel="Parameter shortuser must be provided."; + } + + if (! $error) + { + $fuser->getrights(); + + if ($fuser->rights->user->user->password || $fuser->rights->user->self->password) + { + $userstat=new User($db); + $res = $userstat->fetch('',$shortuser['login']); + if($res) + { + $res = $userstat->setPassword($userstat,$shortuser['password']); + if($res) + { + $objectresp = array( + 'result'=>array('result_code' => 'OK', 'result_label' => ''), + 'groups'=>$arraygroups + ); + } + else + { + $error++; + $errorcode='NOT_MODIFIED'; $errorlabel='Error when changing password'; + } + } + else + { + $error++; + $errorcode='NOT_FOUND'; $errorlabel='User not found'; + } + + } + else + { + $error++; + $errorcode='PERMISSION_DENIED'; $errorlabel='User does not have permission for this request'; + } + } + + + if ($error) + { + $objectresp = array( + 'result'=>array('result_code' => $errorcode, 'result_label' => $errorlabel) + ); + } + + return $objectresp; +} + + // Return the results. $server->service($HTTP_RAW_POST_DATA);