contact.php 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. <?php
  2. /* Copyright (C) 2005 Patrick Rouillon <patrick@rouillon.net>
  3. * Copyright (C) 2005-2018 Destailleur Laurent <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
  5. * Copyright (C) 2017 Ferran Marcet <fmarcet@2byte.es>
  6. * Copyright (C) 2023 Christian Foellmann <christian@foellmann.de>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  20. */
  21. /**
  22. * \file htdocs/supplier_proposal/contact.php
  23. * \ingroup supplier_proposal
  24. * \brief Tab to manage contact of a supplier proposal
  25. */
  26. // Load Dolibarr environment
  27. require '../main.inc.php';
  28. require_once DOL_DOCUMENT_ROOT.'/supplier_proposal/class/supplier_proposal.class.php';
  29. require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
  30. require_once DOL_DOCUMENT_ROOT.'/core/lib/supplier_proposal.lib.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. require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php';
  34. require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.dispatch.class.php';
  35. // Load translation files required by the page
  36. $langs->loadLangs(array("propal", "supplier_proposal", "facture", "orders", "sendings", "companies"));
  37. $id = GETPOST('id', 'int');
  38. $ref = GETPOST('ref', 'alpha');
  39. $action = GETPOST('action', 'aZ09');
  40. // Security check
  41. if ($user->socid) {
  42. $socid = $user->socid;
  43. }
  44. $result = restrictedArea($user, 'supplier_proposal', $id, 'supplier_proposal', '');
  45. $object = new SupplierProposal($db);
  46. $permissiontoedit = $user->hasRight('supplier_proposal', 'creer');
  47. $hookmanager->initHooks(array('supplier_proposalcontactcard', 'globalcard'));
  48. /*
  49. * Actions
  50. */
  51. $parameters = array('id'=>$id);
  52. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action);
  53. if ($reshook < 0) {
  54. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  55. }
  56. if (empty($reshook)) {
  57. /*
  58. * Add a new contact
  59. */
  60. if ($action == 'addcontact' && $permissiontoedit) {
  61. $result = $object->fetch($id);
  62. if ($result > 0 && $id > 0) {
  63. $contactid = (GETPOST('userid') ? GETPOST('userid') : GETPOST('contactid'));
  64. $typeid = (GETPOST('typecontact') ? GETPOST('typecontact') : GETPOST('type'));
  65. $result = $object->add_contact($contactid, $typeid, GETPOST("source"));
  66. }
  67. if ($result >= 0) {
  68. header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
  69. exit;
  70. } else {
  71. if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
  72. $langs->load("errors");
  73. setEventMessages($langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType"), null, 'errors');
  74. } else {
  75. setEventMessages($object->error, $object->errors, 'errors');
  76. }
  77. }
  78. } elseif ($action == 'swapstatut' && $permissiontoedit) {
  79. // Toggle the status of a contact
  80. if ($object->fetch($id)) {
  81. $result = $object->swapContactStatus(GETPOST('ligne', 'int'));
  82. } else {
  83. setEventMessages($object->error, $object->errors, 'errors');
  84. }
  85. } elseif ($action == 'deletecontact' && $permissiontoedit) {
  86. // Deleting a contact
  87. $object->fetch($id);
  88. $result = $object->delete_contact(GETPOST("lineid", 'int'));
  89. if ($result >= 0) {
  90. header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
  91. exit;
  92. } else {
  93. setEventMessages($object->error, $object->errors, 'errors');
  94. }
  95. }
  96. }
  97. /*
  98. * View
  99. */
  100. $form = new Form($db);
  101. $formcompany = new FormCompany($db);
  102. $contactstatic = new Contact($db);
  103. $userstatic = new User($db);
  104. /* *************************************************************************** */
  105. /* */
  106. /* Mode vue et edition */
  107. /* */
  108. /* *************************************************************************** */
  109. if ($id > 0 || !empty($ref)) {
  110. $langs->trans("SupplierProposal");
  111. if ($object->fetch($id, $ref) > 0) {
  112. $object->fetch_thirdparty();
  113. $title = $object->ref." - ".$langs->trans('ContactsAddresses');
  114. $help_url = 'EN:Ask_Price_Supplier|FR:Demande_de_prix_fournisseur';
  115. llxHeader('', $title, $help_url);
  116. $head = supplier_proposal_prepare_head($object);
  117. print dol_get_fiche_head($head, 'contact', $langs->trans("CommRequest"), -1, 'supplier_proposal');
  118. // Supplier order card
  119. $linkback = '<a href="'.DOL_URL_ROOT.'/supplier_proposal/list.php'.(!empty($socid) ? '?socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
  120. $morehtmlref = '<div class="refidno">';
  121. // Ref supplier
  122. //$morehtmlref .= $form->editfieldkey("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, 0, 'string', '', 0, 1);
  123. //$morehtmlref .= $form->editfieldval("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, 0, 'string', '', null, null, '', 1);
  124. // Thirdparty
  125. $morehtmlref .= $object->thirdparty->getNomUrl(1);
  126. // Project
  127. if (isModEnabled('project')) {
  128. $langs->load("projects");
  129. $morehtmlref .= '<br>';
  130. if (0) {
  131. $morehtmlref .= img_picto($langs->trans("Project"), 'project', 'class="pictofixedwidth"');
  132. if ($action != 'classify') {
  133. $morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> ';
  134. }
  135. $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, (!getDolGlobalString('PROJECT_CAN_ALWAYS_LINK_TO_ALL_SUPPLIERS') ? $object->socid : -1), $object->fk_project, ($action == 'classify' ? 'projectid' : 'none'), 0, 0, 0, 1, '', 'maxwidth300');
  136. } else {
  137. if (!empty($object->fk_project)) {
  138. $proj = new Project($db);
  139. $proj->fetch($object->fk_project);
  140. $morehtmlref .= $proj->getNomUrl(1);
  141. if ($proj->title) {
  142. $morehtmlref .= '<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).'</span>';
  143. }
  144. }
  145. }
  146. }
  147. $morehtmlref .= '</div>';
  148. dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref, '', 0, '', '', 1);
  149. print dol_get_fiche_end();
  150. // Contacts lines
  151. include DOL_DOCUMENT_ROOT.'/core/tpl/contacts.tpl.php';
  152. } else {
  153. // Contact not found
  154. print "ErrorRecordNotFound";
  155. }
  156. }
  157. // End of page
  158. llxFooter();
  159. $db->close();