contact.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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.dolibarr@gmail.com>
  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 <http://www.gnu.org/licenses/>.
  26. */
  27. /**
  28. * \file htdocs/societe/contact.php
  29. * \ingroup societe
  30. * \brief Page of contacts of thirdparties
  31. */
  32. require '../main.inc.php';
  33. require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
  34. require_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
  35. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  36. require_once DOL_DOCUMENT_ROOT.'/core/lib/functions.lib.php';
  37. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
  38. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
  39. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  40. require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
  41. require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
  42. require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
  43. if (! empty($conf->adherent->enabled)) require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
  44. $langs->loadLangs(array("companies","commercial","bills","banks","users"));
  45. if (! empty($conf->categorie->enabled)) $langs->load("categories");
  46. if (! empty($conf->incoterm->enabled)) $langs->load("incoterm");
  47. if (! empty($conf->notification->enabled)) $langs->load("mails");
  48. $mesg=''; $error=0; $errors=array();
  49. $action = (GETPOST('action','aZ09') ? GETPOST('action','aZ09') : 'view');
  50. $cancel = GETPOST('cancel','alpha');
  51. $backtopage = GETPOST('backtopage','alpha');
  52. $confirm = GETPOST('confirm');
  53. $socid = GETPOST('socid','int')?GETPOST('socid','int'):GETPOST('id','int');
  54. if ($user->societe_id) $socid=$user->societe_id;
  55. if (empty($socid) && $action == 'view') $action='create';
  56. $object = new Societe($db);
  57. $extrafields = new ExtraFields($db);
  58. // fetch optionals attributes and labels
  59. $extralabels=$extrafields->fetch_name_optionals_label($object->table_element);
  60. // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
  61. $hookmanager->initHooks(array('thirdpartycontact','globalcard'));
  62. if ($action == 'view' && $object->fetch($socid)<=0)
  63. {
  64. $langs->load("errors");
  65. print($langs->trans('ErrorRecordNotFound'));
  66. exit;
  67. }
  68. // Get object canvas (By default, this is not defined, so standard usage of dolibarr)
  69. $object->getCanvas($socid);
  70. $canvas = $object->canvas?$object->canvas:GETPOST("canvas");
  71. $objcanvas=null;
  72. if (! empty($canvas))
  73. {
  74. require_once DOL_DOCUMENT_ROOT.'/core/class/canvas.class.php';
  75. $objcanvas = new Canvas($db, $action);
  76. $objcanvas->getCanvas('thirdparty', 'card', $canvas);
  77. }
  78. // Security check
  79. $result = restrictedArea($user, 'societe', $socid, '&societe', '', 'fk_soc', 'rowid', $objcanvas);
  80. /*
  81. * Actions
  82. */
  83. $parameters=array('id'=>$socid, 'objcanvas'=>$objcanvas);
  84. $reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
  85. if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  86. if (empty($reshook))
  87. {
  88. if ($cancel)
  89. {
  90. $action='';
  91. if (! empty($backtopage))
  92. {
  93. header("Location: ".$backtopage);
  94. exit;
  95. }
  96. }
  97. // Selection of new fields
  98. include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
  99. }
  100. /*
  101. * View
  102. */
  103. $form = new Form($db);
  104. $formfile = new FormFile($db);
  105. $formadmin = new FormAdmin($db);
  106. $formcompany = new FormCompany($db);
  107. if ($socid > 0 && empty($object->id))
  108. {
  109. $result=$object->fetch($socid);
  110. if ($result <= 0) dol_print_error('',$object->error);
  111. }
  112. $title=$langs->trans("ThirdParty");
  113. if (! empty($conf->global->MAIN_HTML_TITLE) && preg_match('/thirdpartynameonly/',$conf->global->MAIN_HTML_TITLE) && $object->name) $title=$object->name." - ".$langs->trans('Card');
  114. $help_url='EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas';
  115. llxHeader('',$title,$help_url);
  116. $countrynotdefined=$langs->trans("ErrorSetACountryFirst").' ('.$langs->trans("SeeAbove").')';
  117. if (!empty($object->id)) $res=$object->fetch_optionals($object->id,$extralabels);
  118. //if ($res < 0) { dol_print_error($db); exit; }
  119. $head = societe_prepare_head($object);
  120. dol_fiche_head($head, 'contact', $langs->trans("ThirdParty"), 0, 'company');
  121. $linkback = '<a href="'.DOL_URL_ROOT.'/societe/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
  122. dol_banner_tab($object, 'socid', $linkback, ($user->societe_id?0:1), 'rowid', 'nom', '', '', 0, '', '', 'arearefnobottom');
  123. dol_fiche_end();
  124. print '<br>';
  125. if ($action != 'presend')
  126. {
  127. // Contacts list
  128. if (empty($conf->global->SOCIETE_DISABLE_CONTACTS))
  129. {
  130. $result=show_contacts($conf,$langs,$db,$object,$_SERVER["PHP_SELF"].'?socid='.$object->id);
  131. }
  132. // Addresses list
  133. if (! empty($conf->global->SOCIETE_ADDRESSES_MANAGEMENT))
  134. {
  135. $result=show_addresses($conf,$langs,$db,$object,$_SERVER["PHP_SELF"].'?socid='.$object->id);
  136. }
  137. }
  138. // End of page
  139. llxFooter();
  140. $db->close();