contact.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  18. */
  19. /**
  20. * \file htdocs/fichinter/contact.php
  21. * \ingroup fichinter
  22. * \brief Onglet de gestion des contacts de fiche d'intervention
  23. */
  24. // Load Dolibarr environment
  25. require '../main.inc.php';
  26. require_once DOL_DOCUMENT_ROOT.'/fichinter/class/fichinter.class.php';
  27. require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
  28. require_once DOL_DOCUMENT_ROOT.'/core/lib/fichinter.lib.php';
  29. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
  30. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
  31. require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
  32. // Load translation files required by the page
  33. $langs->loadLangs(array('interventions', 'sendings', 'companies'));
  34. $id = GETPOST('id', 'int');
  35. $ref = GETPOST('ref', 'alpha');
  36. $action = GETPOST('action', 'aZ09');
  37. // Security check
  38. if ($user->socid) {
  39. $socid = $user->socid;
  40. }
  41. $result = restrictedArea($user, 'ficheinter', $id, 'fichinter');
  42. $object = new Fichinter($db);
  43. $result = $object->fetch($id, $ref);
  44. if (!$result) {
  45. print 'Record not found';
  46. exit;
  47. }
  48. $usercancreate = $user->hasRight('ficheinter', 'creer');
  49. /*
  50. * Adding a new contact
  51. */
  52. if ($action == 'addcontact' && $user->hasRight('ficheinter', 'creer')) {
  53. if ($result > 0 && $id > 0) {
  54. $contactid = (GETPOST('userid', 'int') ? GETPOST('userid', 'int') : GETPOST('contactid', 'int'));
  55. $typeid = (GETPOST('typecontact') ? GETPOST('typecontact') : GETPOST('type'));
  56. $result = $object->add_contact($contactid, $typeid, GETPOST("source", 'aZ09'));
  57. }
  58. if ($result >= 0) {
  59. header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
  60. exit;
  61. } else {
  62. if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
  63. $langs->load("errors");
  64. $mesg = $langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType");
  65. } else {
  66. $mesg = $object->error;
  67. }
  68. setEventMessages($mesg, null, 'errors');
  69. }
  70. } elseif ($action == 'swapstatut' && $user->hasRight('ficheinter', 'creer')) {
  71. // Toggle the status of a contact
  72. $result = $object->swapContactStatus(GETPOST('ligne', 'int'));
  73. } elseif ($action == 'deletecontact' && $user->hasRight('ficheinter', 'creer')) {
  74. // Deletes a contact
  75. $result = $object->delete_contact(GETPOST('lineid', 'int'));
  76. if ($result >= 0) {
  77. header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
  78. exit;
  79. } else {
  80. dol_print_error($db);
  81. }
  82. }
  83. /*
  84. * View
  85. */
  86. $form = new Form($db);
  87. $formcompany = new FormCompany($db);
  88. $contactstatic = new Contact($db);
  89. $userstatic = new User($db);
  90. $formproject = new FormProjets($db);
  91. llxHeader('', $langs->trans("Intervention"));
  92. // Mode vue et edition
  93. if ($id > 0 || !empty($ref)) {
  94. $object->fetch_thirdparty();
  95. $head = fichinter_prepare_head($object);
  96. print dol_get_fiche_head($head, 'contact', $langs->trans("InterventionCard"), -1, 'intervention');
  97. // Intervention card
  98. $linkback = '<a href="'.DOL_URL_ROOT.'/fichinter/list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
  99. $morehtmlref = '<div class="refidno">';
  100. // Ref customer
  101. //$morehtmlref.=$form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, $user->rights->ficheinter->creer, 'string', '', 0, 1);
  102. //$morehtmlref.=$form->editfieldval("RefCustomer", 'ref_client', $object->ref_client, $object, $user->rights->ficheinter->creer, 'string', '', null, null, '', 1);
  103. $morehtmlref.=$form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', 0, 1);
  104. $morehtmlref.=$form->editfieldval("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', null, null, '', 1);
  105. // Thirdparty
  106. $morehtmlref .= '<br>'.$object->thirdparty->getNomUrl(1, 'customer');
  107. // Project
  108. if (isModEnabled('project')) {
  109. $langs->load("projects");
  110. $morehtmlref .= '<br>';
  111. if ($usercancreate && 0) {
  112. $morehtmlref .= img_picto($langs->trans("Project"), 'project', 'class="pictofixedwidth"');
  113. if ($action != 'classify') {
  114. $morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> ';
  115. }
  116. $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, ($action == 'classify' ? 'projectid' : 'none'), 0, 0, 0, 1, '', 'maxwidth300');
  117. } else {
  118. if (!empty($object->fk_project)) {
  119. $proj = new Project($db);
  120. $proj->fetch($object->fk_project);
  121. $morehtmlref .= $proj->getNomUrl(1);
  122. if ($proj->title) {
  123. $morehtmlref .= '<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).'</span>';
  124. }
  125. }
  126. }
  127. }
  128. $morehtmlref .= '</div>';
  129. dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref, '', 0, '', '', 1);
  130. print dol_get_fiche_end();
  131. print '<br>';
  132. if (!empty($conf->global->FICHINTER_HIDE_ADD_CONTACT_USER)) {
  133. $hideaddcontactforuser = 1;
  134. }
  135. if (!empty($conf->global->FICHINTER_HIDE_ADD_CONTACT_THIPARTY)) {
  136. $hideaddcontactforthirdparty = 1;
  137. }
  138. // Contacts lines (modules that overwrite templates must declare this into descriptor)
  139. $dirtpls = array_merge($conf->modules_parts['tpl'], array('/core/tpl'));
  140. foreach ($dirtpls as $reldir) {
  141. $res = @include dol_buildpath($reldir.'/contacts.tpl.php');
  142. if ($res) {
  143. break;
  144. }
  145. }
  146. }
  147. llxFooter();
  148. $db->close();