contact.php 8.9 KB

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