PageRenderTime 32ms CodeModel.GetById 6ms RepoModel.GetById 1ms app.codeStats 0ms

/htdocs/fourn/commande/contact.php

http://github.com/Dolibarr/dolibarr
PHP | 187 lines | 111 code | 29 blank | 47 comment | 39 complexity | 53f0f78f52478e3d75abf82712460f12 MD5 | raw file
Possible License(s): GPL-2.0, AGPL-3.0, LGPL-2.0, CC-BY-SA-4.0, BSD-3-Clause, MPL-2.0-no-copyleft-exception, LGPL-3.0, GPL-3.0, LGPL-2.1, MIT
  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. require '../../main.inc.php';
  26. require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php';
  27. require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
  28. require_once DOL_DOCUMENT_ROOT.'/core/lib/fourn.lib.php';
  29. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
  30. if (!empty($conf->projet->enabled)) {
  31. require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
  32. }
  33. // Load translation files required by the page
  34. $langs->loadLangs(array("facture", "orders", "sendings", "companies"));
  35. $id = GETPOST('id', 'int');
  36. $ref = GETPOST('ref', 'alpha');
  37. $action = GETPOST('action', 'aZ09');
  38. // Security check
  39. if ($user->socid) {
  40. $socid = $user->socid;
  41. }
  42. $result = restrictedArea($user, 'fournisseur', $id, 'commande_fournisseur', 'commande');
  43. $hookmanager->initHooks(array('ordersuppliercardcontact'));
  44. $object = new CommandeFournisseur($db);
  45. /*
  46. * Add a new contact
  47. */
  48. if ($action == 'addcontact' && ($user->rights->fournisseur->commande->creer || $user->rights->supplier_order->creer)) {
  49. $result = $object->fetch($id);
  50. if ($result > 0 && $id > 0) {
  51. $contactid = (GETPOST('userid') ? GETPOST('userid') : GETPOST('contactid'));
  52. $typeid = (GETPOST('typecontact') ? GETPOST('typecontact') : GETPOST('type'));
  53. $result = $object->add_contact($contactid, $typeid, GETPOST("source", 'aZ09'));
  54. }
  55. if ($result >= 0) {
  56. header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
  57. exit;
  58. } else {
  59. if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
  60. $langs->load("errors");
  61. setEventMessages($langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType"), null, 'errors');
  62. } else {
  63. setEventMessages($object->error, $object->errors, 'errors');
  64. }
  65. }
  66. } elseif ($action == 'swapstatut' && ($user->rights->fournisseur->commande->creer || $user->rights->supplier_order->creer)) {
  67. // Toggle the status of a contact
  68. if ($object->fetch($id)) {
  69. $result = $object->swapContactStatus(GETPOST('ligne', 'int'));
  70. } else {
  71. setEventMessages($object->error, $object->errors, 'errors');
  72. }
  73. } elseif ($action == 'deletecontact' && ($user->rights->fournisseur->commande->creer || $user->rights->supplier_order->creer)) {
  74. // Deleting a contact
  75. $object->fetch($id);
  76. $result = $object->delete_contact(GETPOST("lineid", 'int'));
  77. if ($result >= 0) {
  78. header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
  79. exit;
  80. } else {
  81. setEventMessages($object->error, $object->errors, 'errors');
  82. }
  83. }
  84. /*
  85. * View
  86. */
  87. $title = $langs->trans('SupplierOrder')." - ".$langs->trans('ContactsAddresses');
  88. $help_url = 'EN:Module_Suppliers_Orders|FR:CommandeFournisseur|ES:Módulo_Pedidos_a_proveedores';
  89. llxHeader('', $title, $help_url);
  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. $head = ordersupplier_prepare_head($object);
  104. print dol_get_fiche_head($head, 'contact', $langs->trans("SupplierOrder"), -1, 'order');
  105. // Supplier order card
  106. $linkback = '<a href="'.DOL_URL_ROOT.'/fourn/commande/list.php'.(!empty($socid) ? '?socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
  107. $morehtmlref = '<div class="refidno">';
  108. // Ref supplier
  109. $morehtmlref .= $form->editfieldkey("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, 0, 'string', '', 0, 1);
  110. $morehtmlref .= $form->editfieldval("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, 0, 'string', '', null, null, '', 1);
  111. // Thirdparty
  112. $morehtmlref .= '<br>'.$langs->trans('ThirdParty').' : '.$object->thirdparty->getNomUrl(1);
  113. // Project
  114. if (!empty($conf->projet->enabled)) {
  115. $langs->load("projects");
  116. $morehtmlref .= '<br>'.$langs->trans('Project').' ';
  117. if ($user->rights->fournisseur->commande->creer || $user->rights->supplier_order->creer) {
  118. if ($action != 'classify') {
  119. //$morehtmlref.='<a class="editfielda" href="' . $_SERVER['PHP_SELF'] . '?action=classify&token='.newToken().'&id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> : ';
  120. $morehtmlref .= ' : ';
  121. }
  122. if ($action == 'classify') {
  123. //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
  124. $morehtmlref .= '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
  125. $morehtmlref .= '<input type="hidden" name="action" value="classin">';
  126. $morehtmlref .= '<input type="hidden" name="token" value="'.newToken().'">';
  127. $morehtmlref .= $formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);
  128. $morehtmlref .= '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
  129. $morehtmlref .= '</form>';
  130. } else {
  131. $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1);
  132. }
  133. } else {
  134. if (!empty($object->fk_project)) {
  135. $proj = new Project($db);
  136. $proj->fetch($object->fk_project);
  137. $morehtmlref .= ' : '.$proj->getNomUrl(1);
  138. if ($proj->title) {
  139. $morehtmlref .= ' - '.$proj->title;
  140. }
  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. // Contacts lines
  150. include DOL_DOCUMENT_ROOT.'/core/tpl/contacts.tpl.php';
  151. } else {
  152. // Contact not found
  153. print "ErrorRecordNotFound";
  154. }
  155. }
  156. // End of page
  157. llxFooter();
  158. $db->close();