contact.php 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. <?php
  2. /* Copyright (C) 2005 Patrick Rouillon <patrick@rouillon.net>
  3. * Copyright (C) 2005-2009 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/fourn/commande/contact.php
  22. * \ingroup commande
  23. * \brief Onglet de gestion des contacts de commande
  24. */
  25. // Load Dolibarr environment
  26. require '../../main.inc.php';
  27. require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php';
  28. require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
  29. require_once DOL_DOCUMENT_ROOT.'/core/lib/fourn.lib.php';
  30. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
  31. if (isModEnabled('project')) {
  32. require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
  33. }
  34. // Load translation files required by the page
  35. $langs->loadLangs(array("facture", "orders", "sendings", "companies"));
  36. $id = GETPOST('id', 'int');
  37. $ref = GETPOST('ref', 'alpha');
  38. $action = GETPOST('action', 'aZ09');
  39. // Security check
  40. if ($user->socid) {
  41. $socid = $user->socid;
  42. }
  43. $result = restrictedArea($user, 'fournisseur', $id, 'commande_fournisseur', 'commande');
  44. $hookmanager->initHooks(array('ordersuppliercardcontact'));
  45. $object = new CommandeFournisseur($db);
  46. $usercancreate = ($user->rights->fournisseur->commande->creer || $user->rights->supplier_order->creer);
  47. $permissiontoadd = $usercancreate; // Used by the include of actions_addupdatedelete.inc.php
  48. /*
  49. * Actions
  50. */
  51. if ($action == 'addcontact' && ($user->rights->fournisseur->commande->creer || $user->rights->supplier_order->creer)) {
  52. $result = $object->fetch($id);
  53. if ($result > 0 && $id > 0) {
  54. $contactid = (GETPOST('userid') ? GETPOST('userid') : GETPOST('contactid'));
  55. $typeid = (GETPOST('typecontact') ? GETPOST('typecontact') : GETPOST('type'));
  56. $result = $object->add_contact($contactid, $typeid, GETPOST("source", 'aZ09'));
  57. }
  58. if ($result >= 0) {
  59. header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
  60. exit;
  61. } else {
  62. if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
  63. $langs->load("errors");
  64. setEventMessages($langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType"), null, 'errors');
  65. } else {
  66. setEventMessages($object->error, $object->errors, 'errors');
  67. }
  68. }
  69. } elseif ($action == 'swapstatut' && ($user->rights->fournisseur->commande->creer || $user->rights->supplier_order->creer)) {
  70. // Toggle the status of a contact
  71. if ($object->fetch($id)) {
  72. $result = $object->swapContactStatus(GETPOST('ligne', 'int'));
  73. } else {
  74. setEventMessages($object->error, $object->errors, 'errors');
  75. }
  76. } elseif ($action == 'deletecontact' && ($user->rights->fournisseur->commande->creer || $user->rights->supplier_order->creer)) {
  77. // Deleting a contact
  78. $object->fetch($id);
  79. $result = $object->delete_contact(GETPOST("lineid", 'int'));
  80. if ($result >= 0) {
  81. header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
  82. exit;
  83. } else {
  84. setEventMessages($object->error, $object->errors, 'errors');
  85. }
  86. }
  87. /*
  88. * View
  89. */
  90. $form = new Form($db);
  91. $formcompany = new FormCompany($db);
  92. $contactstatic = new Contact($db);
  93. $userstatic = new User($db);
  94. /* *************************************************************************** */
  95. /* */
  96. /* Mode vue et edition */
  97. /* */
  98. /* *************************************************************************** */
  99. if ($id > 0 || !empty($ref)) {
  100. $langs->trans("OrderCard");
  101. if ($object->fetch($id, $ref) > 0) {
  102. $object->fetch_thirdparty();
  103. $title = $object->ref." - ".$langs->trans('ContactsAddresses');
  104. $help_url = 'EN:Module_Suppliers_Orders|FR:CommandeFournisseur|ES:Módulo_Pedidos_a_proveedores';
  105. llxHeader('', $title, $help_url);
  106. $head = ordersupplier_prepare_head($object);
  107. print dol_get_fiche_head($head, 'contact', $langs->trans("SupplierOrder"), -1, 'order');
  108. // Supplier order card
  109. $linkback = '<a href="'.DOL_URL_ROOT.'/fourn/commande/list.php'.(!empty($socid) ? '?socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
  110. $morehtmlref = '<div class="refidno">';
  111. // Ref supplier
  112. $morehtmlref .= $form->editfieldkey("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, 0, 'string', '', 0, 1);
  113. $morehtmlref .= $form->editfieldval("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, 0, 'string', '', null, null, '', 1);
  114. // Thirdparty
  115. $morehtmlref .= '<br>'.$object->thirdparty->getNomUrl(1);
  116. // Project
  117. if (isModEnabled('project')) {
  118. $langs->load("projects");
  119. $morehtmlref .= '<br>';
  120. if (0) {
  121. $morehtmlref .= img_picto($langs->trans("Project"), 'project', 'class="pictofixedwidth"');
  122. if ($action != 'classify' && $caneditproject) {
  123. $morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> ';
  124. }
  125. $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, (empty($conf->global->PROJECT_CAN_ALWAYS_LINK_TO_ALL_SUPPLIERS) ? $object->socid : -1), $object->fk_project, ($action == 'classify' ? 'projectid' : 'none'), 0, 0, 0, 1, '', 'maxwidth300');
  126. } else {
  127. if (!empty($object->fk_project)) {
  128. $proj = new Project($db);
  129. $proj->fetch($object->fk_project);
  130. $morehtmlref .= $proj->getNomUrl(1);
  131. if ($proj->title) {
  132. $morehtmlref .= '<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).'</span>';
  133. }
  134. }
  135. }
  136. }
  137. $morehtmlref .= '</div>';
  138. dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref, '', 0, '', '', 1);
  139. print dol_get_fiche_end();
  140. // Contacts lines
  141. include DOL_DOCUMENT_ROOT.'/core/tpl/contacts.tpl.php';
  142. } else {
  143. // Contact not found
  144. print "ErrorRecordNotFound";
  145. }
  146. }
  147. // End of page
  148. llxFooter();
  149. $db->close();