contact.php 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  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-2015 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. require '../main.inc.php';
  27. require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
  28. require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
  29. require_once DOL_DOCUMENT_ROOT.'/core/lib/order.lib.php';
  30. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
  31. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
  32. require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
  33. // Load translation files required by the page
  34. $langs->loadLangs(array('orders', 'sendings', 'companies', 'bills'));
  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, 'commande', $id, '');
  43. $object = new Commande($db);
  44. /*
  45. * Ajout d'un nouveau contact
  46. */
  47. if ($action == 'addcontact' && $user->rights->commande->creer) {
  48. $result = $object->fetch($id);
  49. if ($result > 0 && $id > 0) {
  50. $contactid = (GETPOST('userid', 'int') ? GETPOST('userid', 'int') : GETPOST('contactid', 'int'));
  51. $typeid = (GETPOST('typecontact') ? GETPOST('typecontact') : GETPOST('type'));
  52. $result = $object->add_contact($contactid, $typeid, GETPOST("source", 'aZ09'));
  53. }
  54. if ($result >= 0) {
  55. header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
  56. exit;
  57. } else {
  58. if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
  59. $langs->load("errors");
  60. setEventMessages($langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType"), null, 'errors');
  61. } else {
  62. setEventMessages($object->error, $object->errors, 'errors');
  63. }
  64. }
  65. } elseif ($action == 'swapstatut' && $user->rights->commande->creer) {
  66. // bascule du statut d'un contact
  67. if ($object->fetch($id)) {
  68. $result = $object->swapContactStatus(GETPOST('ligne', 'int'));
  69. } else {
  70. dol_print_error($db);
  71. }
  72. } elseif ($action == 'deletecontact' && $user->rights->commande->creer) {
  73. // Efface un contact
  74. $object->fetch($id);
  75. $result = $object->delete_contact(GETPOST("lineid", 'int'));
  76. if ($result >= 0) {
  77. header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
  78. exit;
  79. } else {
  80. setEventMessages($object->error, $object->errors, 'errors');
  81. }
  82. }
  83. /*
  84. elseif ($action == 'setaddress' && $user->rights->commande->creer)
  85. {
  86. $object->fetch($id);
  87. $result=$object->setDeliveryAddress($_POST['fk_address']);
  88. if ($result < 0) dol_print_error($db,$object->error);
  89. }*/
  90. /*
  91. * View
  92. */
  93. $title = $langs->trans('Order')." - ".$langs->trans('ContactsAddresses');
  94. $help_url = 'EN:Customers_Orders|FR:Commandes_Clients|ES:Pedidos de clientes|DE:Modul_Kundenaufträge';
  95. llxHeader('', $title, $help_url);
  96. $form = new Form($db);
  97. $formcompany = new FormCompany($db);
  98. $formother = new FormOther($db);
  99. $contactstatic = new Contact($db);
  100. $userstatic = new User($db);
  101. /* *************************************************************************** */
  102. /* */
  103. /* Mode vue et edition */
  104. /* */
  105. /* *************************************************************************** */
  106. if ($id > 0 || !empty($ref)) {
  107. if ($object->fetch($id, $ref) > 0) {
  108. $object->fetch_thirdparty();
  109. $head = commande_prepare_head($object);
  110. print dol_get_fiche_head($head, 'contact', $langs->trans("CustomerOrder"), -1, 'order');
  111. // Order card
  112. $linkback = '<a href="'.DOL_URL_ROOT.'/commande/list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
  113. $morehtmlref = '<div class="refidno">';
  114. // Ref customer
  115. $morehtmlref .= $form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', 0, 1);
  116. $morehtmlref .= $form->editfieldval("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', null, null, '', 1);
  117. // Thirdparty
  118. $morehtmlref .= '<br>'.$langs->trans('ThirdParty').' : '.$object->thirdparty->getNomUrl(1);
  119. // Project
  120. if (!empty($conf->projet->enabled)) {
  121. $langs->load("projects");
  122. $morehtmlref .= '<br>'.$langs->trans('Project').' ';
  123. if ($user->rights->commande->creer) {
  124. if ($action != 'classify') {
  125. //$morehtmlref.='<a class="editfielda" href="' . $_SERVER['PHP_SELF'] . '?action=classify&amp;id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> : ';
  126. $morehtmlref .= ' : ';
  127. }
  128. if ($action == 'classify') {
  129. //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
  130. $morehtmlref .= '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
  131. $morehtmlref .= '<input type="hidden" name="action" value="classin">';
  132. $morehtmlref .= '<input type="hidden" name="token" value="'.newToken().'">';
  133. $morehtmlref .= $formproject->select_projects($object->thirdparty->id, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);
  134. $morehtmlref .= '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
  135. $morehtmlref .= '</form>';
  136. } else {
  137. $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->thirdparty->id, $object->fk_project, 'none', 0, 0, 0, 1);
  138. }
  139. } else {
  140. if (!empty($object->fk_project)) {
  141. $proj = new Project($db);
  142. $proj->fetch($object->fk_project);
  143. $morehtmlref .= '<a href="'.DOL_URL_ROOT.'/projet/card.php?id='.$object->fk_project.'" title="'.$langs->trans('ShowProject').'">';
  144. $morehtmlref .= $proj->ref;
  145. $morehtmlref .= '</a>';
  146. } else {
  147. $morehtmlref .= '';
  148. }
  149. }
  150. }
  151. $morehtmlref .= '</div>';
  152. dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref, '', 0, '', '', 1);
  153. print dol_get_fiche_end();
  154. print '<br>';
  155. // Contacts lines (modules that overwrite templates must declare this into descriptor)
  156. $dirtpls = array_merge($conf->modules_parts['tpl'], array('/core/tpl'));
  157. foreach ($dirtpls as $reldir) {
  158. $res = @include dol_buildpath($reldir.'/contacts.tpl.php');
  159. if ($res) {
  160. break;
  161. }
  162. }
  163. } else {
  164. // Contact not found
  165. print "ErrorRecordNotFound";
  166. }
  167. }
  168. // End of page
  169. llxFooter();
  170. $db->close();