contact.php 4.5 KB

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