contact.php 7.1 KB

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