contact.php 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. <?php
  2. /* Copyright (C) 2005 Patrick Rouillon <patrick@rouillon.net>
  3. * Copyright (C) 2005-2011 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
  5. * Copyright (C) 2011-2022 Philippe Grand <philippe.grand@atoo-net.com>
  6. * Copyright (C) 2021 Frédéric France <frederic.france@netlogic.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/commande/contact.php
  23. * \ingroup commande
  24. * \brief Onglet de gestion des contacts de commande
  25. */
  26. // Load Dolibarr environment
  27. require '../main.inc.php';
  28. require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
  29. require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
  30. require_once DOL_DOCUMENT_ROOT.'/core/lib/order.lib.php';
  31. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
  32. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
  33. require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
  34. // Load translation files required by the page
  35. $langs->loadLangs(array('orders', 'sendings', 'companies', 'bills'));
  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. // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
  44. $hookmanager->initHooks(array('ordercontact', 'globalcard'));
  45. $result = restrictedArea($user, 'commande', $id, '');
  46. $hookmanager->initHooks(array('ordercontactcard', 'globalcard'));
  47. $usercancreate = $user->hasRight("commande", "creer");
  48. $object = new Commande($db);
  49. /*
  50. * Actions
  51. */
  52. $parameters = array('id'=>$id);
  53. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action);
  54. if ($reshook < 0) {
  55. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  56. }
  57. if (empty($reshook)) {
  58. // Add new contact
  59. if ($action == 'addcontact' && $user->hasRight('commande', 'creer')) {
  60. $result = $object->fetch($id);
  61. if ($result > 0 && $id > 0) {
  62. $contactid = (GETPOST('userid', 'int') ? GETPOST('userid', 'int') : GETPOST('contactid', 'int'));
  63. $typeid = (GETPOST('typecontact') ? GETPOST('typecontact') : GETPOST('type'));
  64. $result = $object->add_contact($contactid, $typeid, GETPOST("source", 'aZ09'));
  65. }
  66. if ($result >= 0) {
  67. header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
  68. exit;
  69. } else {
  70. if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
  71. $langs->load("errors");
  72. setEventMessages($langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType"), null, 'errors');
  73. } else {
  74. setEventMessages($object->error, $object->errors, 'errors');
  75. }
  76. }
  77. } elseif ($action == 'swapstatut' && $user->hasRight('commande', 'creer')) {
  78. // Toggle the status of a contact
  79. if ($object->fetch($id)) {
  80. $result = $object->swapContactStatus(GETPOST('ligne', 'int'));
  81. } else {
  82. dol_print_error($db);
  83. }
  84. } elseif ($action == 'deletecontact' && $user->hasRight('commande', 'creer')) {
  85. // Delete contact
  86. $object->fetch($id);
  87. $result = $object->delete_contact(GETPOST("lineid", 'int'));
  88. if ($result >= 0) {
  89. header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
  90. exit;
  91. } else {
  92. setEventMessages($object->error, $object->errors, 'errors');
  93. }
  94. }
  95. }
  96. /*
  97. * View
  98. */
  99. $form = new Form($db);
  100. $formcompany = new FormCompany($db);
  101. $formother = new FormOther($db);
  102. $contactstatic = new Contact($db);
  103. $userstatic = new User($db);
  104. /* *************************************************************************** */
  105. /* */
  106. /* Mode vue et edition */
  107. /* */
  108. /* *************************************************************************** */
  109. if ($id > 0 || !empty($ref)) {
  110. if ($object->fetch($id, $ref) > 0) {
  111. $object->fetch_thirdparty();
  112. $title = $object->ref." - ".$langs->trans('ContactsAddresses');
  113. $help_url = 'EN:Customers_Orders|FR:Commandes_Clients|ES:Pedidos de clientes|DE:Modul_Kundenaufträge';
  114. llxHeader('', $title, $help_url);
  115. $head = commande_prepare_head($object);
  116. print dol_get_fiche_head($head, 'contact', $langs->trans("CustomerOrder"), -1, 'order');
  117. // Order card
  118. $linkback = '<a href="'.DOL_URL_ROOT.'/commande/list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
  119. $morehtmlref = '<div class="refidno">';
  120. // Ref customer
  121. $morehtmlref .= $form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', 0, 1);
  122. $morehtmlref .= $form->editfieldval("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', null, null, '', 1);
  123. // Thirdparty
  124. $morehtmlref .= '<br>'.$object->thirdparty->getNomUrl(1);
  125. // Project
  126. if (isModEnabled('project')) {
  127. $langs->load("projects");
  128. $morehtmlref .= '<br>';
  129. if (0) {
  130. $morehtmlref .= img_picto($langs->trans("Project"), 'project', 'class="pictofixedwidth"');
  131. if ($action != 'classify') {
  132. $morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> ';
  133. }
  134. $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, ($action == 'classify' ? 'projectid' : 'none'), 0, 0, 0, 1, '', 'maxwidth300');
  135. } else {
  136. if (!empty($object->fk_project)) {
  137. $proj = new Project($db);
  138. $proj->fetch($object->fk_project);
  139. $morehtmlref .= $proj->getNomUrl(1);
  140. if ($proj->title) {
  141. $morehtmlref .= '<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).'</span>';
  142. }
  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. print '<br>';
  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) {
  155. break;
  156. }
  157. }
  158. } else {
  159. // Contact not found
  160. print "ErrorRecordNotFound";
  161. }
  162. }
  163. // End of page
  164. llxFooter();
  165. $db->close();