contact.php 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  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 <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. if (! empty($conf->projet->enabled)) {
  31. require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
  32. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
  33. }
  34. // Load translation files required by the page
  35. $langs->loadLangs(array('orders', 'sendings', 'companies'));
  36. $id=GETPOST('id','int');
  37. $ref=GETPOST('ref','alpha');
  38. $action=GETPOST('action','alpha');
  39. // Security check
  40. if ($user->societe_id) $socid=$user->societe_id;
  41. $result = restrictedArea($user, 'expedition', $id,'');
  42. $object = new Expedition($db);
  43. if ($id > 0 || ! empty($ref))
  44. {
  45. $object->fetch($id, $ref);
  46. $object->fetch_thirdparty();
  47. if (!empty($object->origin))
  48. {
  49. $typeobject = $object->origin;
  50. $origin = $object->origin;
  51. $object->fetch_origin();
  52. }
  53. // Linked documents
  54. if ($typeobject == 'commande' && $object->$typeobject->id && ! empty($conf->commande->enabled))
  55. {
  56. $objectsrc=new Commande($db);
  57. $objectsrc->fetch($object->$typeobject->id);
  58. }
  59. if ($typeobject == 'propal' && $object->$typeobject->id && ! empty($conf->propal->enabled))
  60. {
  61. $objectsrc=new Propal($db);
  62. $objectsrc->fetch($object->$typeobject->id);
  63. }
  64. }
  65. /*
  66. * Actions
  67. */
  68. if ($action == 'addcontact' && $user->rights->expedition->creer)
  69. {
  70. if ($result > 0 && $id > 0)
  71. {
  72. $result = $objectsrc->add_contact(GETPOST('userid') ? GETPOST('userid') : GETPOST('contactid'), $_POST["type"], $_POST["source"]);
  73. }
  74. if ($result >= 0)
  75. {
  76. header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
  77. exit;
  78. }
  79. else
  80. {
  81. if ($objectsrc->error == 'DB_ERROR_RECORD_ALREADY_EXISTS')
  82. {
  83. $langs->load("errors");
  84. $mesg = $langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType");
  85. } else {
  86. $mesg = $objectsrc->error;
  87. $mesgs = $objectsrc->errors;
  88. }
  89. setEventMessages($mesg, $mesgs, 'errors');
  90. }
  91. }
  92. // bascule du statut d'un contact
  93. else if ($action == 'swapstatut' && $user->rights->expedition->creer)
  94. {
  95. $result=$objectsrc->swapContactStatus(GETPOST('ligne'));
  96. }
  97. // Efface un contact
  98. else if ($action == 'deletecontact' && $user->rights->expedition->creer)
  99. {
  100. $result = $objectsrc->delete_contact(GETPOST("lineid"));
  101. if ($result >= 0)
  102. {
  103. header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
  104. exit;
  105. }
  106. else {
  107. dol_print_error($db);
  108. }
  109. }
  110. /*
  111. else if ($action == 'setaddress' && $user->rights->expedition->creer)
  112. {
  113. $object->fetch($id);
  114. $result=$object->setDeliveryAddress($_POST['fk_address']);
  115. if ($result < 0) dol_print_error($db,$object->error);
  116. }*/
  117. /*
  118. * View
  119. */
  120. llxHeader('',$langs->trans('Order'),'EN:Customers_Orders|FR:expeditions_Clients|ES:Pedidos de clientes');
  121. $form = new Form($db);
  122. $formcompany = new FormCompany($db);
  123. $formother = new FormOther($db);
  124. $contactstatic=new Contact($db);
  125. $userstatic=new User($db);
  126. /* *************************************************************************** */
  127. /* */
  128. /* Mode vue et edition */
  129. /* */
  130. /* *************************************************************************** */
  131. if ($id > 0 || ! empty($ref))
  132. {
  133. $langs->trans("OrderCard");
  134. $head = shipping_prepare_head($object);
  135. dol_fiche_head($head, 'contact', $langs->trans("Shipment"), -1, 'sending');
  136. // Shipment card
  137. $linkback = '<a href="'.DOL_URL_ROOT.'/expedition/list.php?restore_lastsearch_values=1' . (! empty($socid) ? '&socid=' . $socid : '') . '">'.$langs->trans("BackToList").'</a>';
  138. $morehtmlref='<div class="refidno">';
  139. // Ref customer shipment
  140. $morehtmlref.=$form->editfieldkey("RefCustomer", '', $object->ref_customer, $object, $user->rights->expedition->creer, 'string', '', 0, 1);
  141. $morehtmlref.=$form->editfieldval("RefCustomer", '', $object->ref_customer, $object, $user->rights->expedition->creer, 'string', '', null, null, '', 1);
  142. // Thirdparty
  143. $morehtmlref.='<br>'.$langs->trans('ThirdParty') . ' : ' . $object->thirdparty->getNomUrl(1);
  144. // Project
  145. if (! empty($conf->projet->enabled)) {
  146. $langs->load("projects");
  147. $morehtmlref .= '<br>' . $langs->trans('Project') . ' ';
  148. if (0) { // Do not change on shipment
  149. if ($action != 'classify') {
  150. $morehtmlref .= '<a href="' . $_SERVER['PHP_SELF'] . '?action=classify&amp;id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> : ';
  151. }
  152. if ($action == 'classify') {
  153. // $morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
  154. $morehtmlref .= '<form method="post" action="' . $_SERVER['PHP_SELF'] . '?id=' . $object->id . '">';
  155. $morehtmlref .= '<input type="hidden" name="action" value="classin">';
  156. $morehtmlref .= '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">';
  157. $morehtmlref .= $formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);
  158. $morehtmlref .= '<input type="submit" class="button" value="' . $langs->trans("Modify") . '">';
  159. $morehtmlref .= '</form>';
  160. } else {
  161. $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1);
  162. }
  163. } else {
  164. // We don't have project on shipment, so we will use the project or source object instead
  165. // TODO Add project on shipment
  166. $morehtmlref .= ' : ';
  167. if (! empty($objectsrc->fk_project)) {
  168. $proj = new Project($db);
  169. $proj->fetch($objectsrc->fk_project);
  170. $morehtmlref .= '<a href="' . DOL_URL_ROOT . '/projet/card.php?id=' . $objectsrc->fk_project . '" title="' . $langs->trans('ShowProject') . '">';
  171. $morehtmlref .= $proj->ref;
  172. $morehtmlref .= '</a>';
  173. } else {
  174. $morehtmlref .= '';
  175. }
  176. }
  177. }
  178. $morehtmlref.='</div>';
  179. dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
  180. print '<div class="fichecenter">';
  181. //print '<div class="fichehalfleft">';
  182. print '<div class="underbanner clearboth"></div>';
  183. print '<table class="border centpercent">';
  184. // Linked documents
  185. if ($typeobject == 'commande' && $object->$typeobject->id && ! empty($conf->commande->enabled))
  186. {
  187. print '<tr><td class="titlefield">';
  188. $objectsrc=new Commande($db);
  189. $objectsrc->fetch($object->$typeobject->id);
  190. print $langs->trans("RefOrder").'</td>';
  191. print '<td colspan="3">';
  192. print $objectsrc->getNomUrl(1,'commande');
  193. print "</td>\n";
  194. print '</tr>';
  195. }
  196. if ($typeobject == 'propal' && $object->$typeobject->id && ! empty($conf->propal->enabled))
  197. {
  198. print '<tr><td class="titlefield">';
  199. $objectsrc=new Propal($db);
  200. $objectsrc->fetch($object->$typeobject->id);
  201. print $langs->trans("RefProposal").'</td>';
  202. print '<td colspan="3">';
  203. print $objectsrc->getNomUrl(1,'expedition');
  204. print "</td>\n";
  205. print '</tr>';
  206. }
  207. print "</table>";
  208. //print '</div>';
  209. //print '<div class="fichehalfright">';
  210. //print '<div class="ficheaddleft">';
  211. //print '<div class="underbanner clearboth"></div>';
  212. //print '</div>';
  213. //print '</div>';
  214. print '</div>';
  215. print '<div class="clearboth"></div>';
  216. dol_fiche_end();
  217. // Lignes de contacts
  218. echo '<br>';
  219. // Contacts lines (modules that overwrite templates must declare this into descriptor)
  220. $dirtpls=array_merge($conf->modules_parts['tpl'],array('/core/tpl'));
  221. foreach($dirtpls as $reldir)
  222. {
  223. $res=@include dol_buildpath($reldir.'/contacts.tpl.php');
  224. if ($res) break;
  225. }
  226. }
  227. // End of page
  228. llxFooter();
  229. $db->close();