contact.php 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  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 <https://www.gnu.org/licenses/>.
  18. */
  19. /**
  20. * \file htdocs/reception/contact.php
  21. * \ingroup reception
  22. * \brief Onglet de gestion des contacts de reception
  23. */
  24. require '../main.inc.php';
  25. require_once DOL_DOCUMENT_ROOT.'/reception/class/reception.class.php';
  26. require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php';
  27. require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
  28. require_once DOL_DOCUMENT_ROOT.'/core/lib/reception.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 (!empty($conf->projet->enabled)) {
  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. $langs->loadLangs(array("orders", "receptions", "companies"));
  36. $id = GETPOST('id', 'int');
  37. $ref = GETPOST('ref', 'alpha');
  38. $action = GETPOST('action', 'aZ09');
  39. $object = new Reception($db);
  40. if ($id > 0 || !empty($ref)) {
  41. $object->fetch($id, $ref);
  42. $object->fetch_thirdparty();
  43. if (!empty($object->origin)) {
  44. $origin = $object->origin;
  45. $object->fetch_origin();
  46. $typeobject = $object->origin;
  47. }
  48. // Linked documents
  49. if ($origin == 'order_supplier' && $object->$typeobject->id && (!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) || !empty($conf->supplier_order->enabled))) {
  50. $objectsrc = new CommandeFournisseur($db);
  51. $objectsrc->fetch($object->$typeobject->id);
  52. }
  53. }
  54. // Security check
  55. if ($user->socid > 0) {
  56. $socid = $user->socid;
  57. }
  58. if ($origin == 'reception') {
  59. $result = restrictedArea($user, $origin, $object->id);
  60. } else {
  61. if ($origin == 'supplierorder' || $origin == 'order_supplier') {
  62. $result = restrictedArea($user, 'fournisseur', $origin_id, 'commande_fournisseur', 'commande');
  63. } elseif (empty($user->rights->{$origin}->lire) && empty($user->rights->{$origin}->read)) {
  64. accessforbidden();
  65. }
  66. }
  67. /*
  68. * Actions
  69. */
  70. if ($action == 'addcontact' && $user->rights->reception->creer) {
  71. if ($result > 0 && $id > 0) {
  72. $contactid = (GETPOST('userid', 'int') ? GETPOST('userid', 'int') : GETPOST('contactid', 'int'));
  73. $typeid = (GETPOST('typecontact') ? GETPOST('typecontact') : GETPOST('type'));
  74. $result = $objectsrc->add_contact($contactid, $typeid, GETPOST("source", 'aZ09'));
  75. }
  76. if ($result >= 0) {
  77. header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
  78. exit;
  79. } else {
  80. if ($objectsrc->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
  81. $langs->load("errors");
  82. $mesg = $langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType");
  83. } else {
  84. $mesg = $objectsrc->error;
  85. $mesgs = $objectsrc->errors;
  86. }
  87. setEventMessages($mesg, $mesgs, 'errors');
  88. }
  89. } elseif ($action == 'swapstatut' && $user->rights->reception->creer) {
  90. // bascule du statut d'un contact
  91. $result = $objectsrc->swapContactStatus(GETPOST('ligne', 'int'));
  92. } elseif ($action == 'deletecontact' && $user->rights->reception->creer) {
  93. // Efface un contact
  94. $result = $objectsrc->delete_contact(GETPOST("lineid", 'int'));
  95. if ($result >= 0) {
  96. header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
  97. exit;
  98. } else {
  99. dol_print_error($db);
  100. }
  101. }
  102. /*
  103. * View
  104. */
  105. llxHeader('', $langs->trans('Reception'), 'EN:Customers_Orders|FR:receptions_Clients|ES:Pedidos de clientes');
  106. $form = new Form($db);
  107. $formcompany = new FormCompany($db);
  108. $formother = new FormOther($db);
  109. $contactstatic = new Contact($db);
  110. $userstatic = new User($db);
  111. // View mode
  112. if ($id > 0 || !empty($ref)) {
  113. $langs->trans("OrderCard");
  114. $head = reception_prepare_head($object);
  115. print dol_get_fiche_head($head, 'contact', $langs->trans("Reception"), -1, 'dollyrevert');
  116. // Reception card
  117. $linkback = '<a href="'.DOL_URL_ROOT.'/reception/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
  118. $morehtmlref = '<div class="refidno">';
  119. // Ref customer reception
  120. $morehtmlref .= $form->editfieldkey("RefSupplier", '', $object->ref_supplier, $object, $user->rights->reception->creer, 'string', '', 0, 1);
  121. $morehtmlref .= $form->editfieldval("RefSupplier", '', $object->ref_supplier, $object, $user->rights->reception->creer, 'string', '', null, null, '', 1);
  122. // Thirdparty
  123. $morehtmlref .= '<br>'.$langs->trans('ThirdParty').' : '.$object->thirdparty->getNomUrl(1);
  124. // Project
  125. if (!empty($conf->projet->enabled)) {
  126. $langs->load("projects");
  127. $morehtmlref .= '<br>'.$langs->trans('Project').' ';
  128. if (0) { // Do not change on reception
  129. if ($action != 'classify') {
  130. $morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&amp;id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> : ';
  131. }
  132. if ($action == 'classify') {
  133. // $morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
  134. $morehtmlref .= '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
  135. $morehtmlref .= '<input type="hidden" name="action" value="classin">';
  136. $morehtmlref .= '<input type="hidden" name="token" value="'.newToken().'">';
  137. $morehtmlref .= $formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);
  138. $morehtmlref .= '<input type="submit" class="button" value="'.$langs->trans("Modify").'">';
  139. $morehtmlref .= '</form>';
  140. } else {
  141. $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1);
  142. }
  143. } else {
  144. // We don't have project on reception, so we will use the project or source object instead
  145. // TODO Add project on reception
  146. $morehtmlref .= ' : ';
  147. if (!empty($objectsrc->fk_project)) {
  148. $proj = new Project($db);
  149. $proj->fetch($objectsrc->fk_project);
  150. $morehtmlref .= '<a href="'.DOL_URL_ROOT.'/projet/card.php?id='.$objectsrc->fk_project.'" title="'.$langs->trans('ShowProject').'">';
  151. $morehtmlref .= $proj->ref;
  152. $morehtmlref .= '</a>';
  153. } else {
  154. $morehtmlref .= '';
  155. }
  156. }
  157. }
  158. $morehtmlref .= '</div>';
  159. dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
  160. print '<div class="fichecenter">';
  161. //print '<div class="fichehalfleft">';
  162. print '<div class="underbanner clearboth"></div>';
  163. print '<table class="border centpercent">';
  164. // Linked documents
  165. if ($origin == 'order_supplier' && $object->$typeobject->id && (!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) || !empty($conf->supplier_order->enabled))) {
  166. print '<tr><td class="titlefield">';
  167. $objectsrc = new CommandeFournisseur($db);
  168. $objectsrc->fetch($object->$typeobject->id);
  169. print $langs->trans("RefOrder").'</td>';
  170. print '<td colspan="3">';
  171. print $objectsrc->getNomUrl(1, 'commande');
  172. print "</td>\n";
  173. print '</tr>';
  174. }
  175. if ($typeobject == 'propal' && $object->$typeobject->id && !empty($conf->propal->enabled)) {
  176. print '<tr><td class="titlefield">';
  177. $objectsrc = new Propal($db);
  178. $objectsrc->fetch($object->$typeobject->id);
  179. print $langs->trans("RefProposal").'</td>';
  180. print '<td colspan="3">';
  181. print $objectsrc->getNomUrl(1, 'reception');
  182. print "</td>\n";
  183. print '</tr>';
  184. }
  185. print "</table>";
  186. //print '</div>';
  187. //print '<div class="fichehalfright">';
  188. //print '<div class="ficheaddleft">';
  189. //print '<div class="underbanner clearboth"></div>';
  190. //print '</div>';
  191. //print '</div>';
  192. print '</div>';
  193. print '<div class="clearboth"></div>';
  194. print dol_get_fiche_end();
  195. // Lines of contacts
  196. echo '<br>';
  197. // Contacts lines (modules that overwrite templates must declare this into descriptor)
  198. $dirtpls = array_merge($conf->modules_parts['tpl'], array('/core/tpl'));
  199. foreach ($dirtpls as $reldir) {
  200. $res = @include dol_buildpath($reldir.'/contacts.tpl.php');
  201. if ($res) {
  202. break;
  203. }
  204. }
  205. }
  206. llxFooter();
  207. $db->close();