149if (isset($extrafields->attributes[$elementtype][
'label']) && is_array($extrafields->attributes[$elementtype][
'label']) && count($extrafields->attributes[$elementtype][
'label'])) {
268 global $db, $conf, $langs;
270 dol_syslog(
"Function: getContact login=".$authentication[
'login'].
" id=".$id.
" ref_ext=".$ref_ext);
272 if ($authentication[
'entity']) {
273 $conf->entity = $authentication[
'entity'];
277 $objectresp = array();
283 if (!$error && ($id && $ref_ext)) {
285 $errorcode =
'BAD_PARAMETERS';
286 $errorlabel =
"Parameter id and ref_ext can't be both provided. You must choose one or other but not both.";
293 $result = $contact->fetch($id, 0, $ref_ext);
297 if ($fuser->hasRight(
'societe',
'contact',
'lire') && !$fuser->socid
298 || ($fuser->hasRight(
'societe',
'contact',
'lire') && ($fuser->socid == $contact->socid))
300 $contact_result_fields = array(
301 'id' => $contact->id,
302 'ref_ext' => $contact->ref_ext,
303 'lastname' => $contact->lastname,
304 'firstname' => $contact->firstname,
305 'address' => $contact->address,
306 'zip' => $contact->zip,
307 'town' => $contact->town,
308 'state_id' => $contact->state_id,
309 'state_code' => $contact->state_code,
310 'state' => $contact->state,
311 'country_id' => $contact->country_id,
312 'country_code' => $contact->country_code,
313 'country' => $contact->country,
314 'socid' => $contact->socid,
315 'status' => $contact->statut,
316 'phone_pro' => $contact->phone_pro,
317 'fax' => $contact->fax,
318 'phone_perso' => $contact->phone_perso,
319 'phone_mobile' => $contact->phone_mobile,
320 'code' => $contact->code,
321 'email' => $contact->email,
322 'birthday' => $contact->birthday,
323 'default_lang' => $contact->default_lang,
324 'note' => $contact->note,
325 'ref_facturation' => $contact->ref_facturation,
326 'ref_contrat' => $contact->ref_contrat,
327 'ref_commande' => $contact->ref_commande,
328 'ref_propal' => $contact->ref_propal,
329 'user_id' => $contact->user_id,
330 'user_login' => $contact->user_login,
331 'civility_id' => $contact->civility_id,
332 'poste' => $contact->poste
335 $elementtype =
'socpeople';
340 $extrafields->fetch_name_optionals_label($elementtype,
true);
342 $contact->fetch_optionals();
344 if (isset($extrafields->attributes[$elementtype][
'label']) && is_array($extrafields->attributes[$elementtype][
'label']) && count($extrafields->attributes[$elementtype][
'label'])) {
345 foreach ($extrafields->attributes[$elementtype][
'label'] as $key => $label) {
346 $contact_result_fields = array_merge($contact_result_fields, array(
'options_'.$key => $contact->array_options[
'options_'.$key]));
352 'result'=>array(
'result_code'=>
'OK',
'result_label'=>
''),
353 'contact'=>$contact_result_fields
357 $errorcode =
'PERMISSION_DENIED';
358 $errorlabel =
'User does not have permission for this request';
362 $errorcode =
'NOT_FOUND';
363 $errorlabel =
'Object not found for id='.$id.
' nor ref_ext='.$ref_ext;
368 $objectresp = array(
'result'=>array(
'result_code' => $errorcode,
'result_label' => $errorlabel));
384 global $db, $conf, $langs;
388 dol_syslog(
"Function: createContact login=".$authentication[
'login']);
390 if ($authentication[
'entity']) {
391 $conf->entity = $authentication[
'entity'];
395 $objectresp = array();
401 if (empty($contact[
'lastname'])) {
404 $errorlabel =
"Name is mandatory.";
410 $newobject->id = $contact[
'id'];
411 $newobject->ref_ext = $contact[
'ref_ext'];
412 $newobject->civility_id = $contact[
'civility_id'];
413 $newobject->lastname = $contact[
'lastname'];
414 $newobject->firstname = $contact[
'firstname'];
415 $newobject->address = $contact[
'address'];
416 $newobject->zip = $contact[
'zip'];
417 $newobject->town = $contact[
'town'];
418 $newobject->state_id = $contact[
'state_id'];
419 $newobject->state_code = $contact[
'state_code'];
420 $newobject->state = $contact[
'state'];
421 $newobject->country_id = $contact[
'country_id'];
422 $newobject->country_code = $contact[
'country_code'];
423 $newobject->country = $contact[
'country'];
424 $newobject->socid = $contact[
'socid'];
425 $newobject->statut = $contact[
'status'];
426 $newobject->phone_pro = $contact[
'phone_pro'];
427 $newobject->fax = $contact[
'fax'];
428 $newobject->phone_perso = $contact[
'phone_perso'];
429 $newobject->phone_mobile = $contact[
'phone_mobile'];
430 $newobject->code = $contact[
'code'];
431 $newobject->email = $contact[
'email'];
432 $newobject->birthday = $contact[
'birthday'];
433 $newobject->default_lang = $contact[
'default_lang'];
434 $newobject->note = $contact[
'note'];
435 $newobject->ref_facturation = $contact[
'ref_facturation'];
436 $newobject->ref_contrat = $contact[
'ref_contrat'];
437 $newobject->ref_commande = $contact[
'ref_commande'];
438 $newobject->ref_propal = $contact[
'ref_propal'];
439 $newobject->user_id = $contact[
'user_id'];
440 $newobject->user_login = $contact[
'user_login'];
441 $newobject->poste = $contact[
'poste'];
443 $elementtype =
'socpeople';
448 $extrafields->fetch_name_optionals_label($elementtype,
true);
449 if (isset($extrafields->attributes[$elementtype][
'label']) && is_array($extrafields->attributes[$elementtype][
'label']) && count($extrafields->attributes[$elementtype][
'label'])) {
450 foreach ($extrafields->attributes[$elementtype][
'label'] as $key => $label) {
451 $key =
'options_'.$key;
452 $newobject->array_options[$key] = $contact[$key];
461 $result = $newobject->create($fuser);
468 $objectresp = array(
'result'=>array(
'result_code'=>
'OK',
'result_label'=>
''),
'id'=>$newobject->id,
'ref'=>$newobject->ref);
473 $errorlabel = $newobject->error;
478 $objectresp = array(
'result'=>array(
'result_code' => $errorcode,
'result_label' => $errorlabel));
493 global $db, $conf, $langs;
495 dol_syslog(
"Function: getContactsForThirdParty login=".$authentication[
'login'].
" idthirdparty=".$idthirdparty);
497 if ($authentication[
'entity']) {
498 $conf->entity = $authentication[
'entity'];
502 $objectresp = array();
508 if (!$error && empty($idthirdparty)) {
510 $errorcode =
'BAD_PARAMETERS';
511 $errorlabel =
'Parameter id is not provided';
515 $linesinvoice = array();
517 $sql =
"SELECT c.rowid, c.fk_soc, c.civility as civility_id, c.lastname, c.firstname, c.statut as status,";
518 $sql .=
" c.address, c.zip, c.town,";
519 $sql .=
" c.fk_pays as country_id,";
520 $sql .=
" c.fk_departement as state_id,";
521 $sql .=
" c.birthday,";
522 $sql .=
" c.poste, c.phone, c.phone_perso, c.phone_mobile, c.fax, c.email,";
523 $sql .=
" co.label as country, co.code as country_code,";
524 $sql .=
" d.nom as state, d.code_departement as state_code,";
525 $sql .=
" u.rowid as user_id, u.login as user_login,";
526 $sql .=
" s.nom as socname, s.address as socaddress, s.zip as soccp, s.town as soccity, s.default_lang as socdefault_lang";
527 $sql .=
" FROM ".MAIN_DB_PREFIX.
"socpeople as c";
528 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_country as co ON c.fk_pays = co.rowid";
529 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_departements as d ON c.fk_departement = d.rowid";
530 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"user as u ON c.rowid = u.fk_socpeople";
531 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe as s ON c.fk_soc = s.rowid";
532 $sql .=
" WHERE c.fk_soc = ".((int) $idthirdparty);
534 $resql = $db->query($sql);
536 $num = $db->num_rows($resql);
540 $obj = $db->fetch_object($resql);
543 $contact->fetch($obj->rowid);
546 $linescontact[] = array(
547 'id' => $contact->id,
548 'ref' => $contact->ref,
549 'civility_id' => $contact->civility_id ? $contact->civility_id :
'',
550 'lastname' => $contact->lastname ? $contact->lastname :
'',
551 'firstname' => $contact->firstname ? $contact->firstname :
'',
552 'address' => $contact->address ? $contact->address :
'',
553 'zip' => $contact->zip ? $contact->zip :
'',
554 'town' => $contact->town ? $contact->town :
'',
556 'state_id' => $contact->state_id ? $contact->state_id :
'',
557 'state_code' => $contact->state_code ? $contact->state_code :
'',
558 'state' => $contact->state ? $contact->state :
'',
560 'country_id' => $contact->country_id ? $contact->country_id :
'',
561 'country_code' => $contact->country_code ? $contact->country_code :
'',
562 'country' => $contact->country ? $contact->country :
'',
564 'socid' => $contact->socid ? $contact->socid :
'',
565 'socname' => $contact->socname ? $contact->socname :
'',
566 'poste' => $contact->poste ? $contact->poste :
'',
568 'phone_pro' => $contact->phone_pro ? $contact->phone_pro :
'',
569 'fax' => $contact->fax ? $contact->fax :
'',
570 'phone_perso' => $contact->phone_perso ? $contact->phone_perso :
'',
571 'phone_mobile' => $contact->phone_mobile ? $contact->phone_mobile :
'',
573 'email' => $contact->email ? $contact->email :
'',
574 'priv' => $contact->priv ? $contact->priv :
'',
575 'mail' => $contact->mail ? $contact->mail :
'',
577 'birthday' => $contact->birthday ? $contact->birthday :
'',
578 'default_lang' => $contact->default_lang ? $contact->default_lang :
'',
579 'note' => $contact->note ? $contact->note :
'',
580 'ref_facturation' => $contact->ref_facturation ? $contact->ref_facturation :
'',
581 'ref_contrat' => $contact->ref_contrat ? $contact->ref_contrat :
'',
582 'ref_commande' => $contact->ref_commande ? $contact->ref_commande :
'',
583 'ref_propal' => $contact->ref_propal ? $contact->ref_propal :
'',
584 'user_id' => $contact->user_id ? $contact->user_id :
'',
585 'user_login' => $contact->user_login ? $contact->user_login :
'',
586 'status' => $contact->statut ? $contact->statut :
''
593 'result'=>array(
'result_code'=>
'OK',
'result_label'=>
''),
594 'contacts'=>$linescontact
599 $errorcode = $db->lasterrno();
600 $errorlabel = $db->lasterror();
605 $objectresp = array(
'result'=>array(
'result_code' => $errorcode,
'result_label' => $errorlabel));
625 dol_syslog(
"Function: updateContact login=".$authentication[
'login']);
627 if ($authentication[
'entity']) {
628 $conf->entity = $authentication[
'entity'];
632 $objectresp = array();
638 if (empty($contact[
'id']) && empty($contact[
'ref_ext'])) {
641 $errorlabel =
"Contact id or ref_ext is mandatory.";
644 if (!$error && ($contact[
'id'] && $contact[
'ref_ext'])) {
646 $errorcode =
'BAD_PARAMETERS';
647 $errorlabel =
"Parameter id and ref_ext can't be all provided. You must choose one of them.";
651 $objectfound =
false;
653 include_once DOL_DOCUMENT_ROOT.
'/core/lib/company.lib.php';
656 $result = $object->fetch($contact[
'id'], 0, $contact[
'ref_ext']);
658 if (!empty($object->id)) {
661 $object->ref_ext = $contact[
'ref_ext'];
663 $object->firstname = $contact[
'firstname'];
664 $object->lastname = $contact[
'lastname'];
666 $object->address = $contact[
'address'];
667 $object->zip = $contact[
'zip'];
668 $object->town = $contact[
'town'];
670 $object->country_id = $contact[
'country_id'];
671 if ($contact[
'country_code']) {
672 $object->country_id =
getCountry($contact[
'country_code'], 3);
674 $object->province_id = $contact[
'province_id'];
677 $object->phone_pro = $contact[
'phone_pro'];
678 $object->phone_perso = $contact[
'phone_perso'];
679 $object->phone_mobile = $contact[
'phone_mobile'];
680 $object->fax = $contact[
'fax'];
681 $object->email = $contact[
'email'];
683 $object->civility_id = $contact[
'civility_id'];
684 $object->poste = $contact[
'poste'];
686 $object->statut = $contact[
'status'];
688 $elementtype =
'socpeople';
693 $extrafields->fetch_name_optionals_label($elementtype,
true);
694 if (isset($extrafields->attributes[$elementtype][
'label']) && is_array($extrafields->attributes[$elementtype][
'label']) && count($extrafields->attributes[$elementtype][
'label'])) {
695 foreach ($extrafields->attributes[$elementtype][
'label'] as $key => $label) {
696 $key =
'options_'.$key;
697 $object->array_options[$key] = $contact[$key];
703 $result = $object->update($contact[
'id'], $fuser);
709 if ((!$error) && ($objectfound)) {
712 'result'=>array(
'result_code'=>
'OK',
'result_label'=>
''),
715 } elseif ($objectfound) {
719 $errorlabel = $object->error;
722 $errorcode =
'NOT_FOUND';
723 $errorlabel =
'Contact id='.$contact[
'id'].
' cannot be found';
728 $objectresp = array(
'result'=>array(
'result_code' => $errorcode,
'result_label' => $errorlabel));
getCountry($searchkey, $withcode='', $dbtouse=0, $outputlangs='', $entconv=1, $searchlabel='')
Return country label, code or id from an id, code or label.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
check_authentication($authentication, &$error, &$errorcode, &$errorlabel)
Check authentication array and set error, errorcode, errorlabel.