contact.php 9.0 KB

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