contact.php 4.3 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 <http://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','alpha');
  35. // Security check
  36. if ($user->societe_id) $socid=$user->societe_id;
  37. $result = restrictedArea($user, 'resource', $id, 'resource');
  38. $object = new DolResource($db);
  39. $result = $object->fetch($id,$ref);
  40. /*
  41. * Add a new contact
  42. */
  43. if ($action == 'addcontact' && $user->rights->resource->write)
  44. {
  45. if ($result > 0 && $id > 0)
  46. {
  47. $contactid = (GETPOST('userid','int') ? GETPOST('userid','int') : GETPOST('contactid','int'));
  48. $result = $object->add_contact($contactid, GETPOST('type','int'), GETPOST('source','alpha'));
  49. }
  50. if ($result >= 0)
  51. {
  52. header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
  53. exit;
  54. }
  55. else
  56. {
  57. if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
  58. $langs->load("errors");
  59. $mesg = $langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType");
  60. } else {
  61. $mesg = $object->error;
  62. }
  63. setEventMessages($mesg, null, 'errors');
  64. }
  65. }
  66. // Toggle the status of a contact
  67. else if ($action == 'swapstatut' && $user->rights->resource->write)
  68. {
  69. $result=$object->swapContactStatus(GETPOST('ligne','int'));
  70. }
  71. // Erase a contact
  72. else if ($action == 'deletecontact' && $user->rights->resource->write)
  73. {
  74. $result = $object->delete_contact(GETPOST('lineid','int'));
  75. if ($result >= 0)
  76. {
  77. header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
  78. exit;
  79. }
  80. else {
  81. dol_print_error($db);
  82. }
  83. }
  84. /*
  85. * View
  86. */
  87. $form = new Form($db);
  88. $formcompany = new FormCompany($db);
  89. $contactstatic=new Contact($db);
  90. $userstatic=new User($db);
  91. llxHeader('',$langs->trans("Resource"));
  92. // Mode vue et edition
  93. if ($id > 0 || ! empty($ref))
  94. {
  95. $soc = new Societe($db);
  96. $soc->fetch($object->socid);
  97. $head = resource_prepare_head($object);
  98. dol_fiche_head($head, 'contact', $langs->trans("ResourceSingular"), -1, 'resource');
  99. $linkback = '<a href="' . DOL_URL_ROOT . '/resource/list.php' . (! empty($socid) ? '?id=' . $socid : '') . '">' . $langs->trans("BackToList") . '</a>';
  100. $morehtmlref='<div class="refidno">';
  101. $morehtmlref.='</div>';
  102. dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
  103. print '<div class="fichecenter">';
  104. print '<div class="underbanner clearboth"></div>';
  105. // Object
  106. print '<table width="100%" class="border">';
  107. // Resource type
  108. print '<tr>';
  109. print '<td class="titlefield">' . $langs->trans("ResourceType") . '</td>';
  110. print '<td>';
  111. print $object->type_label;
  112. print '</td>';
  113. print '</tr>';
  114. print '</table>';
  115. print '</div>';
  116. dol_fiche_end();
  117. print '<br>';
  118. if (! empty($conf->global->RESOURCE_HIDE_ADD_CONTACT_USER)) $hideaddcontactforuser=1;
  119. if (! empty($conf->global->RESOURCE_HIDE_ADD_CONTACT_THIPARTY)) $hideaddcontactforthirdparty=1;
  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();