contact.php 7.4 KB

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