contact.php 8.0 KB

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