contact.php 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. <?php
  2. /* Copyright (C) 2005 Patrick Rouillon <patrick@rouillon.net>
  3. * Copyright (C) 2005-2016 Destailleur Laurent <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
  5. * Copyright (C) 2011-2022 Philippe Grand <philippe.grand@atoo-net.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/comm/propal/contact.php
  22. * \ingroup propal
  23. * \brief Tab to manage contacts/adresses of proposal
  24. */
  25. // Load Dolibarr environment
  26. require '../../main.inc.php';
  27. require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
  28. require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
  29. require_once DOL_DOCUMENT_ROOT.'/core/lib/propal.lib.php';
  30. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
  31. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
  32. require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
  33. // Load translation files required by the page
  34. $langs->loadLangs(array('facture', 'propal', 'orders', 'sendings', 'companies'));
  35. $id = GETPOST('id', 'int');
  36. $ref = GETPOST('ref', 'alpha');
  37. $lineid = GETPOST('lineid', 'int');
  38. $action = GETPOST('action', 'aZ09');
  39. $object = new Propal($db);
  40. // Load object
  41. if ($id > 0 || !empty($ref)) {
  42. $ret = $object->fetch($id, $ref);
  43. if ($ret == 0) {
  44. $langs->load("errors");
  45. setEventMessages($langs->trans('ErrorRecordNotFound'), null, 'errors');
  46. $error++;
  47. } elseif ($ret < 0) {
  48. setEventMessages($object->error, $object->errors, 'errors');
  49. $error++;
  50. }
  51. }
  52. if (!$error) {
  53. $object->fetch_thirdparty();
  54. } else {
  55. header('Location: '.DOL_URL_ROOT.'/comm/propal/list.php');
  56. exit;
  57. }
  58. // Security check
  59. $socid = '';
  60. if (!empty($user->socid)) {
  61. $socid = $user->socid;
  62. }
  63. restrictedArea($user, 'propal', $object->id);
  64. $usercancreate = $user->hasRight("propal", "creer");
  65. /*
  66. * Add a new contact
  67. */
  68. if ($action == 'addcontact' && $user->rights->propal->creer) {
  69. if ($object->id > 0) {
  70. $contactid = (GETPOST('userid', 'int') ? GETPOST('userid', 'int') : GETPOST('contactid', 'int'));
  71. $typeid = (GETPOST('typecontact') ? GETPOST('typecontact') : GETPOST('type'));
  72. $result = $object->add_contact($contactid, $typeid, GETPOST("source", 'aZ09'));
  73. }
  74. if ($result >= 0) {
  75. header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
  76. exit;
  77. } else {
  78. if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
  79. $langs->load("errors");
  80. setEventMessages($langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType"), null, 'errors');
  81. } else {
  82. setEventMessages($object->error, $object->errors, 'errors');
  83. }
  84. }
  85. } elseif ($action == 'swapstatut' && $user->rights->propal->creer) {
  86. // Toggle the status of a contact
  87. if ($object->id > 0) {
  88. $result = $object->swapContactStatus(GETPOST('ligne', 'int'));
  89. }
  90. } elseif ($action == 'deletecontact' && $user->rights->propal->creer) {
  91. // Deletes a contact
  92. $result = $object->delete_contact($lineid);
  93. if ($result >= 0) {
  94. header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
  95. exit;
  96. } else {
  97. dol_print_error($db);
  98. }
  99. }
  100. /*
  101. * View
  102. */
  103. $title = $object->ref." - ".$langs->trans('ContactsAddresses');
  104. $help_url = "EN:Commercial_Proposals|FR:Proposition_commerciale|ES:Presupuestos";
  105. llxHeader('', $title, $help_url);
  106. $form = new Form($db);
  107. $formcompany = new FormCompany($db);
  108. $formother = new FormOther($db);
  109. if ($object->id > 0) {
  110. $head = propal_prepare_head($object);
  111. print dol_get_fiche_head($head, 'contact', $langs->trans("Proposal"), -1, 'propal');
  112. // Proposal card
  113. $linkback = '<a href="'.DOL_URL_ROOT.'/comm/propal/list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
  114. $morehtmlref = '<div class="refidno">';
  115. // Ref customer
  116. $morehtmlref .= $form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', 0, 1);
  117. $morehtmlref .= $form->editfieldval("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', null, null, '', 1);
  118. // Thirdparty
  119. $morehtmlref .= '<br>'.$object->thirdparty->getNomUrl(1, 'customer');
  120. // Project
  121. if (isModEnabled('project')) {
  122. $langs->load("projects");
  123. $morehtmlref .= '<br>';
  124. if (0) {
  125. $morehtmlref .= img_picto($langs->trans("Project"), 'project', 'class="pictofixedwidth"');
  126. if ($action != 'classify') {
  127. $morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> ';
  128. }
  129. $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, ($action == 'classify' ? 'projectid' : 'none'), 0, 0, 0, 1, '', 'maxwidth300');
  130. } else {
  131. if (!empty($object->fk_project)) {
  132. $proj = new Project($db);
  133. $proj->fetch($object->fk_project);
  134. $morehtmlref .= $proj->getNomUrl(1);
  135. if ($proj->title) {
  136. $morehtmlref .= '<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).'</span>';
  137. }
  138. }
  139. }
  140. }
  141. $morehtmlref .= '</div>';
  142. dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref, '', 0, '', '', 1);
  143. print dol_get_fiche_end();
  144. // Contacts lines (modules that overwrite templates must declare this into descriptor)
  145. $dirtpls = array_merge($conf->modules_parts['tpl'], array('/core/tpl'));
  146. foreach ($dirtpls as $reldir) {
  147. $res = @include dol_buildpath($reldir.'/contacts.tpl.php');
  148. if ($res) {
  149. break;
  150. }
  151. }
  152. }
  153. // End of page
  154. llxFooter();
  155. $db->close();