stocktransfer_contact.php 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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/comm/propal/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. // Load translation files required by the page
  29. $langs->loadLangs(array('facture', 'orders', 'sendings', 'companies', 'stocks'));
  30. $id = GETPOST('id', 'int');
  31. $ref = GETPOST('ref', 'alpha');
  32. $lineid = GETPOST('lineid', 'int');
  33. $action = GETPOST('action', 'alpha');
  34. // Security check
  35. if ($user->socid) $socid = $user->socid;
  36. $result = restrictedArea($user, 'stocktransfer', $id, '', 'stocktransfer');
  37. $object = new StockTransfer($db);
  38. // Load object
  39. if ($id > 0 || !empty($ref)) {
  40. $ret = $object->fetch($id, $ref);
  41. if ($ret == 0) {
  42. $langs->load("errors");
  43. setEventMessages($langs->trans('ErrorRecordNotFound'), null, 'errors');
  44. $error++;
  45. } elseif ($ret < 0) {
  46. setEventMessages($object->error, $object->errors, 'errors');
  47. $error++;
  48. }
  49. }
  50. if (!$error) {
  51. $object->fetch_thirdparty();
  52. } else {
  53. header('Location: '.dol_buildpath('/stocktransfer/stocktransfer_list.php', 1));
  54. exit;
  55. }
  56. /*
  57. * Add a new contact
  58. */
  59. if ($action == 'addcontact' && $user->rights->stocktransfer->stocktransfer->write) {
  60. if ($object->id > 0) {
  61. $contactid = (GETPOST('userid', 'int') ? GETPOST('userid', 'int') : GETPOST('contactid', 'int'));
  62. $result = $object->add_contact($contactid, !empty($_POST["typecontact"]) ? $_POST["typecontact"] : $_POST["type"], $_POST["source"]);
  63. }
  64. if ($result >= 0) {
  65. header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
  66. exit;
  67. } else {
  68. if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
  69. $langs->load("errors");
  70. setEventMessages($langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType"), null, 'errors');
  71. } else {
  72. setEventMessages($object->error, $object->errors, 'errors');
  73. }
  74. }
  75. } elseif ($action == 'swapstatut' && $user->rights->stocktransfer->stocktransfer->write) { // Toggle the status of a contact
  76. if ($object->id > 0) {
  77. $result = $object->swapContactStatus(GETPOST('ligne'));
  78. }
  79. } elseif ($action == 'deletecontact' && $user->rights->stocktransfer->stocktransfer->write) { // Deletes a contact
  80. $result = $object->delete_contact($lineid);
  81. if ($result >= 0) {
  82. header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
  83. exit;
  84. } else {
  85. dol_print_error($db);
  86. }
  87. }
  88. /*
  89. elseif ($action == 'setaddress' && $user->rights->stocktransfer->stocktransfer->write)
  90. {
  91. $result=$object->setDeliveryAddress($_POST['fk_address']);
  92. if ($result < 0) dol_print_error($db,$object->error);
  93. }*/
  94. /*
  95. * View
  96. */
  97. llxHeader('', $langs->trans('ModuleStockTransferName'), 'EN:Commercial_Proposals|FR:Proposition_commerciale|ES:Presupuestos');
  98. $form = new Form($db);
  99. $formcompany = new FormCompany($db);
  100. $formother = new FormOther($db);
  101. if ($object->id > 0) {
  102. $head = stocktransferPrepareHead($object);
  103. print dol_get_fiche_head($head, 'contact', $langs->trans("StockTransfer"), -1, 'stock');
  104. // Proposal card
  105. $linkback = '<a href="'.DOL_URL_ROOT.'/comm/propal/list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
  106. $morehtmlref = '<div class="refidno">';
  107. // Ref customer
  108. $morehtmlref .= $form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', 0, 1);
  109. $morehtmlref .= $form->editfieldval("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', null, null, '', 1);
  110. // Thirdparty
  111. if (!empty($object->thirdparty)) {
  112. $morehtmlref .= '<br>' . $langs->trans('ThirdParty') . ' : ' . $object->thirdparty->getNomUrl(1, 'customer');
  113. }
  114. // Project
  115. if (!empty($conf->project->enabled)) {
  116. $langs->load("projects");
  117. $morehtmlref .= '<br>'.$langs->trans('Project').' ';
  118. if ($user->rights->stocktransfer->stocktransfer->write) {
  119. if ($action != 'classify') {
  120. //$morehtmlref.='<a class="editfielda" href="' . $_SERVER['PHP_SELF'] . '?action=classify&amp;id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a>';
  121. $morehtmlref .= ' : ';
  122. }
  123. if ($action == 'classify') {
  124. //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
  125. $morehtmlref .= '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
  126. $morehtmlref .= '<input type="hidden" name="action" value="classin">';
  127. $morehtmlref .= '<input type="hidden" name="token" value="'.newToken().'">';
  128. $morehtmlref .= $formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);
  129. $morehtmlref .= '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
  130. $morehtmlref .= '</form>';
  131. } else {
  132. $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1, '', 'maxwidth300');
  133. }
  134. } else {
  135. if (!empty($object->fk_project)) {
  136. $proj = new Project($db);
  137. $proj->fetch($object->fk_project);
  138. $morehtmlref .= '<a href="'.DOL_URL_ROOT.'/projet/card.php?id='.$object->fk_project.'" title="'.$langs->trans('ShowProject').'">';
  139. $morehtmlref .= $proj->ref;
  140. $morehtmlref .= '</a>';
  141. } else {
  142. $morehtmlref .= '';
  143. }
  144. }
  145. }
  146. $morehtmlref .= '</div>';
  147. dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref, '', 0, '', '', 1);
  148. print dol_get_fiche_end();
  149. $user->rights->stocktransfer->write = $user->rights->stocktransfer->stocktransfer->write;
  150. // Contacts lines (modules that overwrite templates must declare this into descriptor)
  151. $dirtpls = array_merge($conf->modules_parts['tpl'], array('/core/tpl'));
  152. foreach ($dirtpls as $reldir) {
  153. $res = @include dol_buildpath($reldir.'/contacts.tpl.php');
  154. if ($res) break;
  155. }
  156. }
  157. // End of page
  158. llxFooter();
  159. $db->close();