contact.php 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  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) 2023 Christian Foellmann <christian@foellmann.de>
  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/expedition/contact.php
  22. * \ingroup expedition
  23. * \brief Onglet de gestion des contacts de expedition
  24. */
  25. // Load Dolibarr environment
  26. require '../main.inc.php';
  27. require_once DOL_DOCUMENT_ROOT.'/expedition/class/expedition.class.php';
  28. require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
  29. require_once DOL_DOCUMENT_ROOT.'/core/lib/sendings.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. if (isModEnabled('project')) {
  33. require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
  34. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
  35. }
  36. // Load translation files required by the page
  37. $langs->loadLangs(array('orders', 'sendings', 'companies'));
  38. $id = GETPOST('id', 'int');
  39. $ref = GETPOST('ref', 'alpha');
  40. $action = GETPOST('action', 'aZ09');
  41. $object = new Expedition($db);
  42. if ($id > 0 || !empty($ref)) {
  43. $object->fetch($id, $ref);
  44. $object->fetch_thirdparty();
  45. if (!empty($object->origin)) {
  46. $typeobject = $object->origin;
  47. $origin = $object->origin;
  48. $object->fetch_origin();
  49. }
  50. // Linked documents
  51. if ($typeobject == 'commande' && $object->$typeobject->id && isModEnabled('commande')) {
  52. $objectsrc = new Commande($db);
  53. $objectsrc->fetch($object->$typeobject->id);
  54. }
  55. if ($typeobject == 'propal' && $object->$typeobject->id && isModEnabled("propal")) {
  56. $objectsrc = new Propal($db);
  57. $objectsrc->fetch($object->$typeobject->id);
  58. }
  59. }
  60. // Security check
  61. if ($user->socid) {
  62. $socid = $user->socid;
  63. }
  64. $result = restrictedArea($user, 'expedition', $object->id, '');
  65. $hookmanager->initHooks(array('shipmentcontactcard', 'globalcard'));
  66. /*
  67. * Actions
  68. */
  69. $parameters = array('id'=>$id);
  70. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action);
  71. if ($reshook < 0) {
  72. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  73. }
  74. if (empty($reshook)) {
  75. if ($action == 'addcontact' && $user->hasRight('expedition', 'creer')) {
  76. if ($result > 0 && $id > 0) {
  77. $contactid = (GETPOST('userid', 'int') ? GETPOST('userid', 'int') : GETPOST('contactid', 'int'));
  78. $typeid = (GETPOST('typecontact') ? GETPOST('typecontact') : GETPOST('type'));
  79. $result = $objectsrc->add_contact($contactid, $typeid, GETPOST("source", 'aZ09'));
  80. }
  81. if ($result >= 0) {
  82. header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
  83. exit;
  84. } else {
  85. if ($objectsrc->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
  86. $langs->load("errors");
  87. $mesg = $langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType");
  88. } else {
  89. $mesg = $objectsrc->error;
  90. $mesgs = $objectsrc->errors;
  91. }
  92. setEventMessages($mesg, $mesgs, 'errors');
  93. }
  94. } elseif ($action == 'swapstatut' && $user->hasRight('expedition', 'creer')) {
  95. // bascule du statut d'un contact
  96. $result = $objectsrc->swapContactStatus(GETPOST('ligne', 'int'));
  97. } elseif ($action == 'deletecontact' && $user->hasRight('expedition', 'creer')) {
  98. // Efface un contact
  99. $result = $objectsrc->delete_contact(GETPOST("lineid", 'int'));
  100. if ($result >= 0) {
  101. header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
  102. exit;
  103. } else {
  104. dol_print_error($db);
  105. }
  106. }
  107. }
  108. /*
  109. * View
  110. */
  111. $help_url = 'EN:Module_Shipments|FR:Module_Expéditions|ES:M&oacute;dulo_Expediciones|DE:Modul_Lieferungen';
  112. llxHeader('', $langs->trans('Order'), $help_url);
  113. $form = new Form($db);
  114. $formcompany = new FormCompany($db);
  115. $formother = new FormOther($db);
  116. $contactstatic = new Contact($db);
  117. $userstatic = new User($db);
  118. /* *************************************************************************** */
  119. /* */
  120. /* Mode vue et edition */
  121. /* */
  122. /* *************************************************************************** */
  123. if ($id > 0 || !empty($ref)) {
  124. $langs->trans("OrderCard");
  125. $head = shipping_prepare_head($object);
  126. print dol_get_fiche_head($head, 'contact', $langs->trans("Shipment"), -1, $object->picto);
  127. // Shipment card
  128. $linkback = '<a href="'.DOL_URL_ROOT.'/expedition/list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
  129. $morehtmlref = '<div class="refidno">';
  130. // Ref customer shipment
  131. $morehtmlref .= $form->editfieldkey("RefCustomer", '', $object->ref_customer, $object, $user->hasRight('expedition', 'creer'), 'string', '', 0, 1);
  132. $morehtmlref .= $form->editfieldval("RefCustomer", '', $object->ref_customer, $object, $user->hasRight('expedition', 'creer'), 'string', '', null, null, '', 1);
  133. // Thirdparty
  134. $morehtmlref .= '<br>'.$object->thirdparty->getNomUrl(1);
  135. // Project
  136. if (isModEnabled('project')) {
  137. $langs->load("projects");
  138. $morehtmlref .= '<br>';
  139. if (0) { // Do not change on shipment
  140. $morehtmlref .= img_picto($langs->trans("Project"), 'project', 'class="pictofixedwidth"');
  141. if ($action != 'classify') {
  142. $morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> ';
  143. }
  144. $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $objectsrc->socid, $objectsrc->fk_project, ($action == 'classify' ? 'projectid' : 'none'), 0, 0, 0, 1, '', 'maxwidth300');
  145. } else {
  146. if (!empty($objectsrc) && !empty($objectsrc->fk_project)) {
  147. $proj = new Project($db);
  148. $proj->fetch($objectsrc->fk_project);
  149. $morehtmlref .= $proj->getNomUrl(1);
  150. if ($proj->title) {
  151. $morehtmlref .= '<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).'</span>';
  152. }
  153. }
  154. }
  155. }
  156. $morehtmlref .= '</div>';
  157. dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
  158. print '<div class="fichecenter">';
  159. //print '<div class="fichehalfleft">';
  160. print '<div class="underbanner clearboth"></div>';
  161. print '<table class="border centpercent tableforfield">';
  162. // Linked documents
  163. if ($typeobject == 'commande' && $object->$typeobject->id && isModEnabled('commande')) {
  164. print '<tr><td class="titlefield">';
  165. $objectsrc = new Commande($db);
  166. $objectsrc->fetch($object->$typeobject->id);
  167. print $langs->trans("RefOrder").'</td>';
  168. print '<td colspan="3">';
  169. print $objectsrc->getNomUrl(1, 'commande');
  170. print "</td>\n";
  171. print '</tr>';
  172. }
  173. if ($typeobject == 'propal' && $object->$typeobject->id && isModEnabled("propal")) {
  174. print '<tr><td class="titlefield">';
  175. $objectsrc = new Propal($db);
  176. $objectsrc->fetch($object->$typeobject->id);
  177. print $langs->trans("RefProposal").'</td>';
  178. print '<td colspan="3">';
  179. print $objectsrc->getNomUrl(1, 'expedition');
  180. print "</td>\n";
  181. print '</tr>';
  182. }
  183. print "</table>";
  184. //print '</div>';
  185. //print '<div class="fichehalfright">';
  186. //print '<div class="underbanner clearboth"></div>';
  187. //print '</div>';
  188. print '</div>';
  189. print '<div class="clearboth"></div>';
  190. print dol_get_fiche_end();
  191. // Lines of contacts
  192. echo '<br>';
  193. // Contacts lines (modules that overwrite templates must declare this into descriptor)
  194. $dirtpls = array_merge($conf->modules_parts['tpl'], array('/core/tpl'));
  195. $preselectedtypeofcontact = dol_getIdFromCode($db, 'SHIPPING', 'c_type_contact', 'code', 'rowid');
  196. foreach ($dirtpls as $reldir) {
  197. $res = @include dol_buildpath($reldir.'/contacts.tpl.php');
  198. if ($res) {
  199. break;
  200. }
  201. }
  202. }
  203. // End of page
  204. llxFooter();
  205. $db->close();