contact.php 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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. *
  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/supplier_proposal/contact.php
  22. * \ingroup supplier_proposal
  23. * \brief Tab to manage contact of a supplier proposal
  24. */
  25. require '../main.inc.php';
  26. require_once DOL_DOCUMENT_ROOT.'/supplier_proposal/class/supplier_proposal.class.php';
  27. require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
  28. require_once DOL_DOCUMENT_ROOT.'/core/lib/supplier_proposal.lib.php';
  29. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
  30. require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
  31. // Load translation files required by the page
  32. $langs->loadLangs(array("propal", "supplier_proposal", "facture", "orders", "sendings", "companies"));
  33. $id = GETPOST('id', 'int');
  34. $ref = GETPOST('ref', 'alpha');
  35. $action = GETPOST('action', 'aZ09');
  36. // Security check
  37. if ($user->socid) {
  38. $socid = $user->socid;
  39. }
  40. $result = restrictedArea($user, 'supplier_proposal', $id, 'supplier_proposal', '');
  41. $object = new SupplierProposal($db);
  42. $permissiontoedit = $user->rights->supplier_proposal->creer;
  43. /*
  44. * Add a new contact
  45. */
  46. if ($action == 'addcontact' && $permissiontoedit) {
  47. $result = $object->fetch($id);
  48. if ($result > 0 && $id > 0) {
  49. $contactid = (GETPOST('userid') ? GETPOST('userid') : GETPOST('contactid'));
  50. $typeid = (GETPOST('typecontact') ? GETPOST('typecontact') : GETPOST('type'));
  51. $result = $object->add_contact($contactid, $typeid, GETPOST("source"));
  52. }
  53. if ($result >= 0) {
  54. header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
  55. exit;
  56. } else {
  57. if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
  58. $langs->load("errors");
  59. setEventMessages($langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType"), null, 'errors');
  60. } else {
  61. setEventMessages($object->error, $object->errors, 'errors');
  62. }
  63. }
  64. } elseif ($action == 'swapstatut' && $permissiontoedit) {
  65. // Toggle the status of a contact
  66. if ($object->fetch($id)) {
  67. $result = $object->swapContactStatus(GETPOST('ligne', 'int'));
  68. } else {
  69. setEventMessages($object->error, $object->errors, 'errors');
  70. }
  71. } elseif ($action == 'deletecontact' && $permissiontoedit) {
  72. // Deleting a contact
  73. $object->fetch($id);
  74. $result = $object->delete_contact(GETPOST("lineid", 'int'));
  75. if ($result >= 0) {
  76. header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
  77. exit;
  78. } else {
  79. setEventMessages($object->error, $object->errors, 'errors');
  80. }
  81. }
  82. /*
  83. * View
  84. */
  85. $title = $langs->trans('CommRequest')." - ".$langs->trans('ContactsAddresses');
  86. $help_url = 'EN:Ask_Price_Supplier|FR:Demande_de_prix_fournisseur';
  87. llxHeader('', $title, $help_url);
  88. $form = new Form($db);
  89. $formcompany = new FormCompany($db);
  90. $contactstatic = new Contact($db);
  91. $userstatic = new User($db);
  92. /* *************************************************************************** */
  93. /* */
  94. /* Mode vue et edition */
  95. /* */
  96. /* *************************************************************************** */
  97. if ($id > 0 || !empty($ref)) {
  98. $langs->trans("SupplierProposal");
  99. if ($object->fetch($id, $ref) > 0) {
  100. $object->fetch_thirdparty();
  101. $head = supplier_proposal_prepare_head($object);
  102. print dol_get_fiche_head($head, 'contact', $langs->trans("CommRequest"), -1, 'supplier_proposal');
  103. // Supplier order card
  104. $linkback = '<a href="'.DOL_URL_ROOT.'/supplier_proposal/list.php'.(!empty($socid) ? '?socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
  105. $morehtmlref = '<div class="refidno">';
  106. // Ref supplier
  107. $morehtmlref .= $form->editfieldkey("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, 0, 'string', '', 0, 1);
  108. $morehtmlref .= $form->editfieldval("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, 0, 'string', '', null, null, '', 1);
  109. // Thirdparty
  110. $morehtmlref .= '<br>'.$langs->trans('ThirdParty').' : '.$object->thirdparty->getNomUrl(1);
  111. // Project
  112. if (!empty($conf->projet->enabled)) {
  113. $langs->load("projects");
  114. $morehtmlref .= '<br>'.$langs->trans('Project').' ';
  115. if ($permissiontoedit) {
  116. if ($action != 'classify') {
  117. //$morehtmlref.='<a class="editfielda" href="' . $_SERVER['PHP_SELF'] . '?action=classify&token='.newToken().'&id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> : ';
  118. $morehtmlref .= ' : ';
  119. }
  120. if ($action == 'classify') {
  121. //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
  122. $morehtmlref .= '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
  123. $morehtmlref .= '<input type="hidden" name="action" value="classin">';
  124. $morehtmlref .= '<input type="hidden" name="token" value="'.newToken().'">';
  125. $morehtmlref .= $formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);
  126. $morehtmlref .= '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
  127. $morehtmlref .= '</form>';
  128. } else {
  129. $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1);
  130. }
  131. } else {
  132. if (!empty($object->fk_project)) {
  133. $proj = new Project($db);
  134. $proj->fetch($object->fk_project);
  135. $morehtmlref .= ' : '.$proj->getNomUrl(1);
  136. if ($proj->title) {
  137. $morehtmlref .= ' - '.$proj->title;
  138. }
  139. } else {
  140. $morehtmlref .= '';
  141. }
  142. }
  143. }
  144. $morehtmlref .= '</div>';
  145. dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref, '', 0, '', '', 1);
  146. print dol_get_fiche_end();
  147. // Contacts lines
  148. include DOL_DOCUMENT_ROOT.'/core/tpl/contacts.tpl.php';
  149. } else {
  150. // Contact not found
  151. print "ErrorRecordNotFound";
  152. }
  153. }
  154. // End of page
  155. llxFooter();
  156. $db->close();