contact.php 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  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@capnetworks.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 <http://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. require '../main.inc.php';
  25. require_once DOL_DOCUMENT_ROOT.'/expedition/class/expedition.class.php';
  26. require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
  27. require_once DOL_DOCUMENT_ROOT.'/core/lib/sendings.lib.php';
  28. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
  29. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
  30. $langs->load("orders");
  31. $langs->load("sendings");
  32. $langs->load("companies");
  33. $id=GETPOST('id','int');
  34. $ref=GETPOST('ref','alpha');
  35. $action=GETPOST('action','alpha');
  36. // Security check
  37. if ($user->societe_id) $socid=$user->societe_id;
  38. $result = restrictedArea($user, 'expedition', $id,'');
  39. $object = new Expedition($db);
  40. if ($id > 0 || ! empty($ref))
  41. {
  42. $object->fetch($id, $ref);
  43. $object->fetch_thirdparty();
  44. if (!empty($object->origin))
  45. {
  46. $typeobject = $object->origin;
  47. $origin = $object->origin;
  48. $object->fetch_origin();
  49. }
  50. // Linked documents
  51. if ($typeobject == 'commande' && $object->$typeobject->id && ! empty($conf->commande->enabled))
  52. {
  53. $objectsrc=new Commande($db);
  54. $objectsrc->fetch($object->$typeobject->id);
  55. }
  56. if ($typeobject == 'propal' && $object->$typeobject->id && ! empty($conf->propal->enabled))
  57. {
  58. $objectsrc=new Propal($db);
  59. $objectsrc->fetch($object->$typeobject->id);
  60. }
  61. }
  62. /*
  63. * Actions
  64. */
  65. if ($action == 'addcontact' && $user->rights->expedition->creer)
  66. {
  67. if ($result > 0 && $id > 0)
  68. {
  69. $result = $objectsrc->add_contact($_POST["contactid"], $_POST["type"], $_POST["source"]);
  70. }
  71. if ($result >= 0)
  72. {
  73. header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
  74. exit;
  75. }
  76. else
  77. {
  78. if ($objectsrc->error == 'DB_ERROR_RECORD_ALREADY_EXISTS')
  79. {
  80. $langs->load("errors");
  81. $mesg = '<div class="error">'.$langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType").'</div>';
  82. }
  83. else
  84. {
  85. $mesg = '<div class="error">'.$objectsrc->error.'</div>';
  86. }
  87. }
  88. }
  89. // bascule du statut d'un contact
  90. else if ($action == 'swapstatut' && $user->rights->expedition->creer)
  91. {
  92. $result=$objectsrc->swapContactStatus(GETPOST('ligne'));
  93. }
  94. // Efface un contact
  95. else if ($action == 'deletecontact' && $user->rights->expedition->creer)
  96. {
  97. $result = $objectsrc->delete_contact(GETPOST("lineid"));
  98. if ($result >= 0)
  99. {
  100. header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
  101. exit;
  102. }
  103. else {
  104. dol_print_error($db);
  105. }
  106. }
  107. else if ($action == 'setaddress' && $user->rights->expedition->creer)
  108. {
  109. $object->fetch($id);
  110. $result=$object->setDeliveryAddress($_POST['fk_address']);
  111. if ($result < 0) dol_print_error($db,$object->error);
  112. }
  113. /*
  114. * View
  115. */
  116. llxHeader('',$langs->trans('Order'),'EN:Customers_Orders|FR:expeditions_Clients|ES:Pedidos de clientes');
  117. $form = new Form($db);
  118. $formcompany = new FormCompany($db);
  119. $formother = new FormOther($db);
  120. $contactstatic=new Contact($db);
  121. $userstatic=new User($db);
  122. /* *************************************************************************** */
  123. /* */
  124. /* Mode vue et edition */
  125. /* */
  126. /* *************************************************************************** */
  127. dol_htmloutput_mesg($mesg);
  128. if ($id > 0 || ! empty($ref))
  129. {
  130. $langs->trans("OrderCard");
  131. $head = shipping_prepare_head($object);
  132. dol_fiche_head($head, 'contact', $langs->trans("Shipment"), 0, 'sending');
  133. /*
  134. * Facture synthese pour rappel
  135. */
  136. print '<table class="border" width="100%">';
  137. $linkback = '<a href="'.DOL_URL_ROOT.'/expedition/liste.php">'.$langs->trans("BackToList").'</a>';
  138. // Ref
  139. print '<tr><td width="18%">'.$langs->trans("Ref").'</td><td colspan="3">';
  140. print $form->showrefnav($object, 'ref', $linkback, 1, 'ref', 'ref');
  141. print "</td></tr>";
  142. // Customer
  143. print '<tr><td width="20%">'.$langs->trans("Customer").'</td>';
  144. print '<td colspan="3">'.$object->thirdparty->getNomUrl(1).'</td>';
  145. print "</tr>";
  146. // Linked documents
  147. if ($typeobject == 'commande' && $object->$typeobject->id && ! empty($conf->commande->enabled))
  148. {
  149. print '<tr><td>';
  150. $objectsrc=new Commande($db);
  151. $objectsrc->fetch($object->$typeobject->id);
  152. print $langs->trans("RefOrder").'</td>';
  153. print '<td colspan="3">';
  154. print $objectsrc->getNomUrl(1,'commande');
  155. print "</td>\n";
  156. print '</tr>';
  157. }
  158. if ($typeobject == 'propal' && $object->$typeobject->id && ! empty($conf->propal->enabled))
  159. {
  160. print '<tr><td>';
  161. $objectsrc=new Propal($db);
  162. $objectsrc->fetch($object->$typeobject->id);
  163. print $langs->trans("RefProposal").'</td>';
  164. print '<td colspan="3">';
  165. print $objectsrc->getNomUrl(1,'expedition');
  166. print "</td>\n";
  167. print '</tr>';
  168. }
  169. // Ref expedition client
  170. print '<tr><td>';
  171. print '<table class="nobordernopadding" width="100%"><tr><td class="nowrap">';
  172. print $langs->trans('RefCustomer').'</td><td align="left">';
  173. print '</td>';
  174. print '</tr></table>';
  175. print '</td><td colspan="3">';
  176. print $objectsrc->ref_client;
  177. print '</td>';
  178. print '</tr>';
  179. // Delivery address
  180. if (! empty($conf->global->SOCIETE_ADDRESSES_MANAGEMENT))
  181. {
  182. print '<tr><td>';
  183. print '<table class="nobordernopadding" width="100%"><tr><td>';
  184. print $langs->trans('DeliveryAddress');
  185. print '</td>';
  186. if ($action != 'editdelivery_address' && $object->brouillon) print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editdelivery_address&amp;socid='.$object->socid.'&amp;id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetDeliveryAddress'),1).'</a></td>';
  187. print '</tr></table>';
  188. print '</td><td colspan="3">';
  189. if ($action == 'editdelivery_address')
  190. {
  191. $formother->form_address($_SERVER['PHP_SELF'].'?id='.$object->id,$object->fk_delivery_address,$object->socid,'fk_address','shipping',$object->id);
  192. }
  193. else
  194. {
  195. $formother->form_address($_SERVER['PHP_SELF'].'?id='.$object->id,$object->fk_delivery_address,$object->socid,'none','shipping',$object->id);
  196. }
  197. print '</td></tr>';
  198. }
  199. print "</table>";
  200. dol_fiche_end();
  201. // Lignes de contacts
  202. echo '<br>';
  203. // Contacts lines (modules that overwrite templates must declare this into descriptor)
  204. $dirtpls=array_merge($conf->modules_parts['tpl'],array('/core/tpl'));
  205. foreach($dirtpls as $reldir)
  206. {
  207. $res=@include dol_buildpath($reldir.'/contacts.tpl.php');
  208. if ($res) break;
  209. }
  210. }
  211. llxFooter();
  212. $db->close();