contact.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. <?php
  2. /* Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
  3. * Copyright (C) 2007-2009 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2012 Juanjo Menent <jmenent@2byte.es>
  5. * Copyright (C) 2016 Gilles Poirier <glgpoirier@gmail.com>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  19. */
  20. /**
  21. * \file htdocs/resource/contact.php
  22. * \ingroup resource
  23. * \brief Onglet de gestion des contacts des resources
  24. */
  25. require '../main.inc.php';
  26. require_once DOL_DOCUMENT_ROOT.'/resource/class/dolresource.class.php';
  27. require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
  28. require_once DOL_DOCUMENT_ROOT.'/core/lib/resource.lib.php';
  29. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
  30. // Load translation files required by the page
  31. $langs->loadLangs(array('resource', 'sendings', 'companies'));
  32. $id = GETPOST('id', 'int');
  33. $ref = GETPOST('ref', 'alpha');
  34. $action = GETPOST('action', 'aZ09');
  35. $object = new DolResource($db);
  36. // Load object
  37. include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once.
  38. // Security check
  39. if ($user->socid) {
  40. $socid = $user->socid;
  41. }
  42. $result = restrictedArea($user, 'resource', $object->id, 'resource');
  43. // Security check
  44. if (!$user->rights->resource->read) {
  45. accessforbidden();
  46. }
  47. /*
  48. * Add a new contact
  49. */
  50. if ($action == 'addcontact' && $user->rights->resource->write) {
  51. if ($result > 0 && $id > 0) {
  52. $contactid = (GETPOST('userid', 'int') ? GETPOST('userid', 'int') : GETPOST('contactid', 'int'));
  53. $typeid = (GETPOST('typecontact') ? GETPOST('typecontact') : GETPOST('type'));
  54. $result = $object->add_contact($contactid, $typeid, GETPOST("source", 'aZ09'));
  55. }
  56. if ($result >= 0) {
  57. header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
  58. exit;
  59. } else {
  60. if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
  61. $langs->load("errors");
  62. $mesg = $langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType");
  63. } else {
  64. $mesg = $object->error;
  65. }
  66. setEventMessages($mesg, null, 'errors');
  67. }
  68. } elseif ($action == 'swapstatut' && $user->rights->resource->write) {
  69. // Toggle the status of a contact
  70. $result = $object->swapContactStatus(GETPOST('ligne', 'int'));
  71. } elseif ($action == 'deletecontact' && $user->rights->resource->write) {
  72. // Erase a contact
  73. $result = $object->delete_contact(GETPOST('lineid', 'int'));
  74. if ($result >= 0) {
  75. header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
  76. exit;
  77. } else {
  78. dol_print_error($db);
  79. }
  80. }
  81. /*
  82. * View
  83. */
  84. $form = new Form($db);
  85. $formcompany = new FormCompany($db);
  86. $contactstatic = new Contact($db);
  87. $userstatic = new User($db);
  88. llxHeader('', $langs->trans("Resource"));
  89. // Mode vue et edition
  90. if ($id > 0 || !empty($ref)) {
  91. $soc = new Societe($db);
  92. $soc->fetch($object->socid);
  93. $head = resource_prepare_head($object);
  94. print dol_get_fiche_head($head, 'contact', $langs->trans("ResourceSingular"), -1, 'resource');
  95. $linkback = '<a href="'.DOL_URL_ROOT.'/resource/list.php'.(!empty($socid) ? '?id='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
  96. $morehtmlref = '<div class="refidno">';
  97. $morehtmlref .= '</div>';
  98. dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
  99. print '<div class="fichecenter">';
  100. print '<div class="underbanner clearboth"></div>';
  101. // Object
  102. print '<table class="border tableforfield centpercent">';
  103. // Resource type
  104. print '<tr>';
  105. print '<td class="titlefield">'.$langs->trans("ResourceType").'</td>';
  106. print '<td>';
  107. print $object->type_label;
  108. print '</td>';
  109. print '</tr>';
  110. print '</table>';
  111. print '</div>';
  112. print dol_get_fiche_end();
  113. print '<br>';
  114. if (!empty($conf->global->RESOURCE_HIDE_ADD_CONTACT_USER)) {
  115. $hideaddcontactforuser = 1;
  116. }
  117. if (!empty($conf->global->RESOURCE_HIDE_ADD_CONTACT_THIPARTY)) {
  118. $hideaddcontactforthirdparty = 1;
  119. }
  120. $permission = 1;
  121. // Contacts lines
  122. include DOL_DOCUMENT_ROOT.'/core/tpl/contacts.tpl.php';
  123. }
  124. // End of page
  125. llxFooter();
  126. $db->close();