contact.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. <?php
  2. /* Copyright (C) 2001-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2003 Brian Fraval <brian@fraval.org>
  4. * Copyright (C) 2004-2015 Laurent Destailleur <eldy@users.sourceforge.net>
  5. * Copyright (C) 2005 Eric Seigne <eric.seigne@ryxeo.com>
  6. * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
  7. * Copyright (C) 2008 Patrick Raguin <patrick.raguin@auguria.net>
  8. * Copyright (C) 2010-2016 Juanjo Menent <jmenent@2byte.es>
  9. * Copyright (C) 2011-2013 Alexandre Spangaro <aspangaro@open-dsi.fr>
  10. * Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
  11. * Copyright (C) 2015 Marcos García <marcosgdf@gmail.com>
  12. * Copyright (C) 2015 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
  13. *
  14. * This program is free software; you can redistribute it and/or modify
  15. * it under the terms of the GNU General Public License as published by
  16. * the Free Software Foundation; either version 3 of the License, or
  17. * (at your option) any later version.
  18. *
  19. * This program is distributed in the hope that it will be useful,
  20. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. * GNU General Public License for more details.
  23. *
  24. * You should have received a copy of the GNU General Public License
  25. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  26. */
  27. /**
  28. * \file htdocs/societe/contact.php
  29. * \ingroup societe
  30. * \brief Page of contacts of thirdparties
  31. */
  32. // Load Dolibarr environment
  33. require '../main.inc.php';
  34. require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
  35. require_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
  36. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  37. require_once DOL_DOCUMENT_ROOT.'/core/lib/functions.lib.php';
  38. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
  39. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
  40. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  41. require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
  42. require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
  43. require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
  44. if (isModEnabled('adherent')) {
  45. require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
  46. }
  47. // Load translation files required by the page
  48. $langs->loadLangs(array("companies", "commercial", "bills", "banks", "users"));
  49. if (isModEnabled('categorie')) {
  50. $langs->load("categories");
  51. }
  52. if (isModEnabled('incoterm')) {
  53. $langs->load("incoterm");
  54. }
  55. if (isModEnabled('notification')) {
  56. $langs->load("mails");
  57. }
  58. $mesg = ''; $error = 0; $errors = array();
  59. // Get parameters
  60. $action = (GETPOST('action', 'aZ09') ? GETPOST('action', 'aZ09') : 'view');
  61. $cancel = GETPOST('cancel', 'alpha');
  62. $backtopage = GETPOST('backtopage', 'alpha');
  63. $confirm = GETPOST('confirm');
  64. $socid = GETPOST('socid', 'int') ? GETPOST('socid', 'int') : GETPOST('id', 'int');
  65. if ($user->socid) {
  66. $socid = $user->socid;
  67. }
  68. if (empty($socid) && $action == 'view') {
  69. $action = 'create';
  70. }
  71. // Initialize objects
  72. $object = new Societe($db);
  73. $extrafields = new ExtraFields($db);
  74. // fetch optionals attributes and labels
  75. $extrafields->fetch_name_optionals_label($object->table_element);
  76. // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
  77. $hookmanager->initHooks(array('thirdpartycontact', 'globalcard'));
  78. if ($object->fetch($socid) <= 0 && $action == 'view') {
  79. $langs->load("errors");
  80. print($langs->trans('ErrorRecordNotFound'));
  81. exit;
  82. }
  83. // Get object canvas (By default, this is not defined, so standard usage of dolibarr)
  84. $canvas = $object->canvas ? $object->canvas : GETPOST("canvas");
  85. $objcanvas = null;
  86. if (!empty($canvas)) {
  87. require_once DOL_DOCUMENT_ROOT.'/core/class/canvas.class.php';
  88. $objcanvas = new Canvas($db, $action);
  89. $objcanvas->getCanvas('thirdparty', 'card', $canvas);
  90. }
  91. // Security check
  92. $result = restrictedArea($user, 'societe', $socid, '&societe', '', 'fk_soc', 'rowid', 0);
  93. if (!$user->hasRight('societe', 'contact', 'lire')) {
  94. accessforbidden();
  95. }
  96. /*
  97. * Actions
  98. */
  99. $parameters = array('id'=>$socid, 'objcanvas'=>$objcanvas);
  100. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  101. if ($reshook < 0) {
  102. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  103. }
  104. if (empty($reshook)) {
  105. if ($cancel) {
  106. $action = '';
  107. if (!empty($backtopage)) {
  108. header("Location: ".$backtopage);
  109. exit;
  110. }
  111. }
  112. // Selection of new fields
  113. include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
  114. }
  115. /*
  116. * View
  117. */
  118. $form = new Form($db);
  119. $formfile = new FormFile($db);
  120. $formadmin = new FormAdmin($db);
  121. $formcompany = new FormCompany($db);
  122. if ($socid > 0 && empty($object->id)) {
  123. $result = $object->fetch($socid);
  124. if ($result <= 0) {
  125. dol_print_error('', $object->error);
  126. }
  127. }
  128. $title = $langs->trans("ThirdParty");
  129. if (getDolGlobalString('MAIN_HTML_TITLE') && preg_match('/thirdpartynameonly/', $conf->global->MAIN_HTML_TITLE) && $object->name) {
  130. $title = $object->name." - ".$langs->trans('ContactsAddresses');
  131. }
  132. $help_url = 'EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas';
  133. llxHeader('', $title, $help_url);
  134. $countrynotdefined = $langs->trans("ErrorSetACountryFirst").' ('.$langs->trans("SeeAbove").')';
  135. if (!empty($object->id)) {
  136. $res = $object->fetch_optionals();
  137. }
  138. //if ($res < 0) { dol_print_error($db); exit; }
  139. $head = societe_prepare_head($object);
  140. print dol_get_fiche_head($head, 'contact', $langs->trans("ThirdParty"), 0, 'company');
  141. $linkback = '<a href="'.DOL_URL_ROOT.'/societe/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
  142. dol_banner_tab($object, 'socid', $linkback, ($user->socid ? 0 : 1), 'rowid', 'nom', '', '', 0, '', '', 'arearefnobottom');
  143. print dol_get_fiche_end();
  144. print '<br>';
  145. if ($action != 'presend') {
  146. // Contacts list
  147. if (!getDolGlobalString('SOCIETE_DISABLE_CONTACTS')) {
  148. $result = show_contacts($conf, $langs, $db, $object, $_SERVER["PHP_SELF"].'?socid='.$object->id, 1);
  149. }
  150. }
  151. // End of page
  152. llxFooter();
  153. $db->close();