stocktransfer_contact.php 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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-2015 Philippe Grand <philippe.grand@atoo-net.com>
  6. * Copyright (C) 2021 Gauthier VERDOL <gauthier.verdol@atm-consulting.fr>
  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/product/stock/stocktransfer/stocktransfer_contact.php
  23. * \ingroup propal
  24. * \brief Tab to manage contacts/adresses of proposal
  25. */
  26. // Load Dolibarr environment
  27. require '../../../main.inc.php';
  28. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
  29. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.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. require_once DOL_DOCUMENT_ROOT.'/product/stock/stocktransfer/class/stocktransfer.class.php';
  33. require_once DOL_DOCUMENT_ROOT.'/product/stock/stocktransfer/lib/stocktransfer_stocktransfer.lib.php';
  34. // Load translation files required by the page
  35. $langs->loadLangs(array('facture', 'orders', 'sendings', 'companies', 'stocks'));
  36. $id = GETPOST('id', 'int');
  37. $ref = GETPOST('ref', 'alpha');
  38. $lineid = GETPOST('lineid', 'int');
  39. $action = GETPOST('action', 'alpha');
  40. $object = new StockTransfer($db);
  41. // Load object
  42. if ($id > 0 || !empty($ref)) {
  43. $ret = $object->fetch($id, $ref);
  44. if ($ret == 0) {
  45. $langs->load("errors");
  46. setEventMessages($langs->trans('ErrorRecordNotFound'), null, 'errors');
  47. $error++;
  48. } elseif ($ret < 0) {
  49. setEventMessages($object->error, $object->errors, 'errors');
  50. $error++;
  51. }
  52. }
  53. if (!$error) {
  54. $object->fetch_thirdparty();
  55. } else {
  56. header('Location: '.dol_buildpath('/stocktransfer/stocktransfer_list.php', 1));
  57. exit;
  58. }
  59. // Security check
  60. if ($user->socid) {
  61. $socid = $user->socid;
  62. }
  63. $result = restrictedArea($user, 'stocktransfer', $id, '', 'stocktransfer');
  64. /*
  65. * Add a new contact
  66. */
  67. if ($action == 'addcontact' && $user->hasRight('stocktransfer', 'stocktransfer', 'write')) {
  68. if ($object->id > 0) {
  69. $contactid = (GETPOST('userid', 'int') ? GETPOST('userid', 'int') : GETPOST('contactid', 'int'));
  70. $result = $object->add_contact($contactid, !empty($_POST["typecontact"]) ? $_POST["typecontact"] : $_POST["type"], $_POST["source"]);
  71. }
  72. if ($result >= 0) {
  73. header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
  74. exit;
  75. } else {
  76. if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
  77. $langs->load("errors");
  78. setEventMessages($langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType"), null, 'errors');
  79. } else {
  80. setEventMessages($object->error, $object->errors, 'errors');
  81. }
  82. }
  83. } elseif ($action == 'swapstatut' && $user->hasRight('stocktransfer', 'stocktransfer', 'write')) { // Toggle the status of a contact
  84. if ($object->id > 0) {
  85. $result = $object->swapContactStatus(GETPOST('ligne'));
  86. }
  87. } elseif ($action == 'deletecontact' && $user->hasRight('stocktransfer', 'stocktransfer', 'write')) { // Deletes a contact
  88. $result = $object->delete_contact($lineid);
  89. if ($result >= 0) {
  90. header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
  91. exit;
  92. } else {
  93. dol_print_error($db);
  94. }
  95. }
  96. /*
  97. elseif ($action == 'setaddress' && $user->rights->stocktransfer->stocktransfer->write)
  98. {
  99. $result=$object->setDeliveryAddress($_POST['fk_address']);
  100. if ($result < 0) dol_print_error($db,$object->error);
  101. }*/
  102. /*
  103. * View
  104. */
  105. llxHeader('', $langs->trans('ModuleStockTransferName'), 'EN:Commercial_Proposals|FR:Proposition_commerciale|ES:Presupuestos');
  106. $form = new Form($db);
  107. $formcompany = new FormCompany($db);
  108. $formother = new FormOther($db);
  109. if ($object->id > 0) {
  110. $head = stocktransferPrepareHead($object);
  111. print dol_get_fiche_head($head, 'contact', $langs->trans("StockTransfer"), -1, 'stock');
  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. // Thirdparty
  116. $morehtmlref .= empty($object->thirdparty) ? '' : $object->thirdparty->getNomUrl(1, 'customer');
  117. if (!getDolGlobalInt('MAIN_DISABLE_OTHER_LINK') && $object->thirdparty->id > 0) {
  118. $morehtmlref .= ' (<a href="'.DOL_URL_ROOT.'/commande/list.php?socid='.$object->thirdparty->id.'&search_societe='.urlencode($object->thirdparty->name).'">'.$langs->trans("OtherOrders").'</a>)';
  119. }
  120. // Project
  121. if (isModEnabled('project')) {
  122. $langs->load("projects");
  123. if (!empty($object->fk_project)) {
  124. $morehtmlref .= '<br>';
  125. $proj = new Project($db);
  126. $proj->fetch($object->fk_project);
  127. $morehtmlref .= $proj->getNomUrl(1);
  128. if ($proj->title) {
  129. $morehtmlref .= '<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).'</span>';
  130. }
  131. }
  132. }
  133. $morehtmlref .= '</div>';
  134. dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref, '', 0, '', '', 1);
  135. print dol_get_fiche_end();
  136. $user->rights->stocktransfer->write = $user->rights->stocktransfer->stocktransfer->write;
  137. // Contacts lines (modules that overwrite templates must declare this into descriptor)
  138. $dirtpls = array_merge($conf->modules_parts['tpl'], array('/core/tpl'));
  139. foreach ($dirtpls as $reldir) {
  140. $res = @include dol_buildpath($reldir.'/contacts.tpl.php');
  141. if ($res) {
  142. break;
  143. }
  144. }
  145. }
  146. // End of page
  147. llxFooter();
  148. $db->close();