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();
278 $errorcode =
''; $errorlabel =
'';
282 if (!$error && ($id && $ref_ext)) {
284 $errorcode =
'BAD_PARAMETERS'; $errorlabel =
"Parameter id and ref_ext can't be both provided. You must choose one or other but not both.";
291 $result = $contact->fetch($id, 0, $ref_ext);
295 if ($fuser->rights->societe->contact->lire && !$fuser->socid
296 || ($fuser->rights->societe->contact->lire && ($fuser->socid == $contact->socid))
298 $contact_result_fields = array(
299 'id' => $contact->id,
300 'ref_ext' => $contact->ref_ext,
301 'lastname' => $contact->lastname,
302 'firstname' => $contact->firstname,
303 'address' => $contact->address,
304 'zip' => $contact->zip,
305 'town' => $contact->town,
306 'state_id' => $contact->state_id,
307 'state_code' => $contact->state_code,
308 'state' => $contact->state,
309 'country_id' => $contact->country_id,
310 'country_code' => $contact->country_code,
311 'country' => $contact->country,
312 'socid' => $contact->socid,
313 'status' => $contact->statut,
314 'phone_pro' => $contact->phone_pro,
315 'fax' => $contact->fax,
316 'phone_perso' => $contact->phone_perso,
317 'phone_mobile' => $contact->phone_mobile,
318 'code' => $contact->code,
319 'email' => $contact->email,
320 'birthday' => $contact->birthday,
321 'default_lang' => $contact->default_lang,
322 'note' => $contact->note,
323 'ref_facturation' => $contact->ref_facturation,
324 'ref_contrat' => $contact->ref_contrat,
325 'ref_commande' => $contact->ref_commande,
326 'ref_propal' => $contact->ref_propal,
327 'user_id' => $contact->user_id,
328 'user_login' => $contact->user_login,
329 'civility_id' => $contact->civility_id,
330 'poste' => $contact->poste
333 $elementtype =
'socpeople';
338 $extrafields->fetch_name_optionals_label($elementtype,
true);
340 $contact->fetch_optionals();
342 if (isset($extrafields->attributes[$elementtype][
'label']) && is_array($extrafields->attributes[$elementtype][
'label']) && count($extrafields->attributes[$elementtype][
'label'])) {
343 foreach ($extrafields->attributes[$elementtype][
'label'] as $key => $label) {
344 $contact_result_fields = array_merge($contact_result_fields, array(
'options_'.$key => $contact->array_options[
'options_'.$key]));
350 'result'=>array(
'result_code'=>
'OK',
'result_label'=>
''),
351 'contact'=>$contact_result_fields
355 $errorcode =
'PERMISSION_DENIED'; $errorlabel =
'User does not have permission for this request';
359 $errorcode =
'NOT_FOUND'; $errorlabel =
'Object not found for id='.$id.
' nor ref_ext='.$ref_ext;
364 $objectresp = array(
'result'=>array(
'result_code' => $errorcode,
'result_label' => $errorlabel));
380 global $db, $conf, $langs;
384 dol_syslog(
"Function: createContact login=".$authentication[
'login']);
386 if ($authentication[
'entity']) {
387 $conf->entity = $authentication[
'entity'];
391 $objectresp = array();
392 $errorcode =
''; $errorlabel =
'';
396 if (empty($contact[
'lastname'])) {
397 $error++; $errorcode =
'KO'; $errorlabel =
"Name is mandatory.";
403 $newobject->id = $contact[
'id'];
404 $newobject->ref_ext = $contact[
'ref_ext'];
405 $newobject->civility_id = $contact[
'civility_id'];
406 $newobject->lastname = $contact[
'lastname'];
407 $newobject->firstname = $contact[
'firstname'];
408 $newobject->address = $contact[
'address'];
409 $newobject->zip = $contact[
'zip'];
410 $newobject->town = $contact[
'town'];
411 $newobject->state_id = $contact[
'state_id'];
412 $newobject->state_code = $contact[
'state_code'];
413 $newobject->state = $contact[
'state'];
414 $newobject->country_id = $contact[
'country_id'];
415 $newobject->country_code = $contact[
'country_code'];
416 $newobject->country = $contact[
'country'];
417 $newobject->socid = $contact[
'socid'];
418 $newobject->statut = $contact[
'status'];
419 $newobject->phone_pro = $contact[
'phone_pro'];
420 $newobject->fax = $contact[
'fax'];
421 $newobject->phone_perso = $contact[
'phone_perso'];
422 $newobject->phone_mobile = $contact[
'phone_mobile'];
423 $newobject->code = $contact[
'code'];
424 $newobject->email = $contact[
'email'];
425 $newobject->birthday = $contact[
'birthday'];
426 $newobject->default_lang = $contact[
'default_lang'];
427 $newobject->note = $contact[
'note'];
428 $newobject->ref_facturation = $contact[
'ref_facturation'];
429 $newobject->ref_contrat = $contact[
'ref_contrat'];
430 $newobject->ref_commande = $contact[
'ref_commande'];
431 $newobject->ref_propal = $contact[
'ref_propal'];
432 $newobject->user_id = $contact[
'user_id'];
433 $newobject->user_login = $contact[
'user_login'];
434 $newobject->poste = $contact[
'poste'];
436 $elementtype =
'socpeople';
441 $extrafields->fetch_name_optionals_label($elementtype,
true);
442 if (isset($extrafields->attributes[$elementtype][
'label']) && is_array($extrafields->attributes[$elementtype][
'label']) && count($extrafields->attributes[$elementtype][
'label'])) {
443 foreach ($extrafields->attributes[$elementtype][
'label'] as $key => $label) {
444 $key =
'options_'.$key;
445 $newobject->array_options[$key] = $contact[$key];
454 $result = $newobject->create($fuser);
461 $objectresp = array(
'result'=>array(
'result_code'=>
'OK',
'result_label'=>
''),
'id'=>$newobject->id,
'ref'=>$newobject->ref);
466 $errorlabel = $newobject->error;
471 $objectresp = array(
'result'=>array(
'result_code' => $errorcode,
'result_label' => $errorlabel));
486 global $db, $conf, $langs;
488 dol_syslog(
"Function: getContactsForThirdParty login=".$authentication[
'login'].
" idthirdparty=".$idthirdparty);
490 if ($authentication[
'entity']) {
491 $conf->entity = $authentication[
'entity'];
495 $objectresp = array();
496 $errorcode =
''; $errorlabel =
'';
500 if (!$error && empty($idthirdparty)) {
502 $errorcode =
'BAD_PARAMETERS'; $errorlabel =
'Parameter id is not provided';
506 $linesinvoice = array();
508 $sql =
"SELECT c.rowid, c.fk_soc, c.civility as civility_id, c.lastname, c.firstname, c.statut as status,";
509 $sql .=
" c.address, c.zip, c.town,";
510 $sql .=
" c.fk_pays as country_id,";
511 $sql .=
" c.fk_departement as state_id,";
512 $sql .=
" c.birthday,";
513 $sql .=
" c.poste, c.phone, c.phone_perso, c.phone_mobile, c.fax, c.email,";
514 $sql .=
" co.label as country, co.code as country_code,";
515 $sql .=
" d.nom as state, d.code_departement as state_code,";
516 $sql .=
" u.rowid as user_id, u.login as user_login,";
517 $sql .=
" s.nom as socname, s.address as socaddress, s.zip as soccp, s.town as soccity, s.default_lang as socdefault_lang";
518 $sql .=
" FROM ".MAIN_DB_PREFIX.
"socpeople as c";
519 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_country as co ON c.fk_pays = co.rowid";
520 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_departements as d ON c.fk_departement = d.rowid";
521 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"user as u ON c.rowid = u.fk_socpeople";
522 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe as s ON c.fk_soc = s.rowid";
523 $sql .=
" WHERE c.fk_soc = ".((int) $idthirdparty);
525 $resql = $db->query($sql);
527 $num = $db->num_rows($resql);
531 $obj = $db->fetch_object($resql);
534 $contact->fetch($obj->rowid);
537 $linescontact[] = array(
538 'id' => $contact->id,
539 'ref' => $contact->ref,
540 'civility_id' => $contact->civility_id ? $contact->civility_id :
'',
541 'lastname' => $contact->lastname ? $contact->lastname :
'',
542 'firstname' => $contact->firstname ? $contact->firstname :
'',
543 'address' => $contact->address ? $contact->address :
'',
544 'zip' => $contact->zip ? $contact->zip :
'',
545 'town' => $contact->town ? $contact->town :
'',
547 'state_id' => $contact->state_id ? $contact->state_id :
'',
548 'state_code' => $contact->state_code ? $contact->state_code :
'',
549 'state' => $contact->state ? $contact->state :
'',
551 'country_id' => $contact->country_id ? $contact->country_id :
'',
552 'country_code' => $contact->country_code ? $contact->country_code :
'',
553 'country' => $contact->country ? $contact->country :
'',
555 'socid' => $contact->socid ? $contact->socid :
'',
556 'socname' => $contact->socname ? $contact->socname :
'',
557 'poste' => $contact->poste ? $contact->poste :
'',
559 'phone_pro' => $contact->phone_pro ? $contact->phone_pro :
'',
560 'fax' => $contact->fax ? $contact->fax :
'',
561 'phone_perso' => $contact->phone_perso ? $contact->phone_perso :
'',
562 'phone_mobile' => $contact->phone_mobile ? $contact->phone_mobile :
'',
564 'email' => $contact->email ? $contact->email :
'',
565 'priv' => $contact->priv ? $contact->priv :
'',
566 'mail' => $contact->mail ? $contact->mail :
'',
568 'birthday' => $contact->birthday ? $contact->birthday :
'',
569 'default_lang' => $contact->default_lang ? $contact->default_lang :
'',
570 'note' => $contact->note ? $contact->note :
'',
571 'ref_facturation' => $contact->ref_facturation ? $contact->ref_facturation :
'',
572 'ref_contrat' => $contact->ref_contrat ? $contact->ref_contrat :
'',
573 'ref_commande' => $contact->ref_commande ? $contact->ref_commande :
'',
574 'ref_propal' => $contact->ref_propal ? $contact->ref_propal :
'',
575 'user_id' => $contact->user_id ? $contact->user_id :
'',
576 'user_login' => $contact->user_login ? $contact->user_login :
'',
577 'status' => $contact->statut ? $contact->statut :
''
584 'result'=>array(
'result_code'=>
'OK',
'result_label'=>
''),
585 'contacts'=>$linescontact
590 $errorcode = $db->lasterrno(); $errorlabel = $db->lasterror();
595 $objectresp = array(
'result'=>array(
'result_code' => $errorcode,
'result_label' => $errorlabel));
615 dol_syslog(
"Function: updateContact login=".$authentication[
'login']);
617 if ($authentication[
'entity']) {
618 $conf->entity = $authentication[
'entity'];
622 $objectresp = array();
623 $errorcode =
''; $errorlabel =
'';
627 if (empty($contact[
'id']) && empty($contact[
'ref_ext'])) {
628 $error++; $errorcode =
'KO'; $errorlabel =
"Contact id or ref_ext is mandatory.";
631 if (!$error && ($contact[
'id'] && $contact[
'ref_ext'])) {
633 $errorcode =
'BAD_PARAMETERS'; $errorlabel =
"Parameter id and ref_ext can't be all provided. You must choose one of them.";
637 $objectfound =
false;
639 include_once DOL_DOCUMENT_ROOT.
'/core/lib/company.lib.php';
642 $result = $object->fetch($contact[
'id'], 0, $contact[
'ref_ext']);
644 if (!empty($object->id)) {
647 $object->ref_ext = $contact[
'ref_ext'];
649 $object->firstname = $contact[
'firstname'];
650 $object->lastname = $contact[
'lastname'];
652 $object->address = $contact[
'address'];
653 $object->zip = $contact[
'zip'];
654 $object->town = $contact[
'town'];
656 $object->country_id = $contact[
'country_id'];
657 if ($contact[
'country_code']) {
658 $object->country_id =
getCountry($contact[
'country_code'], 3);
660 $object->province_id = $contact[
'province_id'];
663 $object->phone_pro = $contact[
'phone_pro'];
664 $object->phone_perso = $contact[
'phone_perso'];
665 $object->phone_mobile = $contact[
'phone_mobile'];
666 $object->fax = $contact[
'fax'];
667 $object->email = $contact[
'email'];
669 $object->civility_id = $contact[
'civility_id'];
670 $object->poste = $contact[
'poste'];
672 $object->statut = $contact[
'status'];
674 $elementtype =
'socpeople';
679 $extrafields->fetch_name_optionals_label($elementtype,
true);
680 if (isset($extrafields->attributes[$elementtype][
'label']) && is_array($extrafields->attributes[$elementtype][
'label']) && count($extrafields->attributes[$elementtype][
'label'])) {
681 foreach ($extrafields->attributes[$elementtype][
'label'] as $key => $label) {
682 $key =
'options_'.$key;
683 $object->array_options[$key] = $contact[$key];
689 $result = $object->update($contact[
'id'], $fuser);
695 if ((!$error) && ($objectfound)) {
698 'result'=>array(
'result_code'=>
'OK',
'result_label'=>
''),
701 } elseif ($objectfound) {
705 $errorlabel = $object->error;
708 $errorcode =
'NOT_FOUND';
709 $errorlabel =
'Contact id='.$contact[
'id'].
' cannot be found';
714 $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.