contact.php 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. <?php
  2. /* Copyright (C) 2005 Patrick Rouillon <patrick@rouillon.net>
  3. * Copyright (C) 2005-2018 Destailleur Laurent <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
  5. * Copyright (C) 2017 Ferran Marcet <fmarcet@2byte.es>
  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/supplier_proposal/contact.php
  22. * \ingroup supplier_proposal
  23. * \brief Tab to manage contact of a supplier proposal
  24. */
  25. require '../main.inc.php';
  26. require_once DOL_DOCUMENT_ROOT.'/supplier_proposal/class/supplier_proposal.class.php';
  27. require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
  28. require_once DOL_DOCUMENT_ROOT.'/core/lib/supplier_proposal.lib.php';
  29. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
  30. require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
  31. // Load translation files required by the page
  32. $langs->loadLangs(array("propal","facture","orders","sendings","companies"));
  33. $id = GETPOST('id', 'int');
  34. $ref = GETPOST('ref', 'alpha');
  35. $action = GETPOST('action', 'alpha');
  36. // Security check
  37. if ($user->societe_id) $socid=$user->societe_id;
  38. $result = restrictedArea($user, 'supplier_proposal', $id, 'supplier_proposal', '');
  39. $object = new SupplierProposal($db);
  40. $permissiontoedit = $user->rights->supplier_proposal->creer;
  41. /*
  42. * Add a new contact
  43. */
  44. if ($action == 'addcontact' && $permissiontoedit)
  45. {
  46. $result = $object->fetch($id);
  47. if ($result > 0 && $id > 0)
  48. {
  49. $contactid = (GETPOST('userid') ? GETPOST('userid') : GETPOST('contactid'));
  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. // Toggle the status of a contact
  71. else if ($action == 'swapstatut' && $permissiontoedit)
  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. // Deleting a contact
  83. else if ($action == 'deletecontact' && $permissiontoedit)
  84. {
  85. $object->fetch($id);
  86. $result = $object->delete_contact(GETPOST("lineid",'int'));
  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. * View
  98. */
  99. $help_url='';
  100. llxHeader('',$langs->trans("SupplierProposals"),$help_url);
  101. $form = new Form($db);
  102. $formcompany = new FormCompany($db);
  103. $contactstatic=new Contact($db);
  104. $userstatic=new User($db);
  105. /* *************************************************************************** */
  106. /* */
  107. /* Mode vue et edition */
  108. /* */
  109. /* *************************************************************************** */
  110. if ($id > 0 || ! empty($ref))
  111. {
  112. $langs->trans("SupplierProposal");
  113. if ($object->fetch($id, $ref) > 0)
  114. {
  115. $object->fetch_thirdparty();
  116. $head = supplier_proposal_prepare_head($object);
  117. dol_fiche_head($head, 'contact', $langs->trans("CommRequest"), -1, 'supplier_proposal');
  118. // Supplier order card
  119. $linkback = '<a href="'.DOL_URL_ROOT.'/supplier_proposal/list.php'.(! empty($socid)?'?socid='.$socid:'').'">'.$langs->trans("BackToList").'</a>';
  120. $morehtmlref='<div class="refidno">';
  121. // Ref supplier
  122. $morehtmlref.=$form->editfieldkey("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, 0, 'string', '', 0, 1);
  123. $morehtmlref.=$form->editfieldval("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, 0, 'string', '', null, null, '', 1);
  124. // Thirdparty
  125. $morehtmlref.='<br>'.$langs->trans('ThirdParty') . ' : ' . $object->thirdparty->getNomUrl(1);
  126. // Project
  127. if (! empty($conf->projet->enabled))
  128. {
  129. $langs->load("projects");
  130. $morehtmlref.='<br>'.$langs->trans('Project') . ' ';
  131. if ($permissiontoedit)
  132. {
  133. if ($action != 'classify')
  134. //$morehtmlref.='<a href="' . $_SERVER['PHP_SELF'] . '?action=classify&amp;id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> : ';
  135. $morehtmlref.=' : ';
  136. if ($action == 'classify') {
  137. //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
  138. $morehtmlref.='<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
  139. $morehtmlref.='<input type="hidden" name="action" value="classin">';
  140. $morehtmlref.='<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  141. $morehtmlref.=$formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);
  142. $morehtmlref.='<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
  143. $morehtmlref.='</form>';
  144. } else {
  145. $morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1);
  146. }
  147. } else {
  148. if (! empty($object->fk_project)) {
  149. $proj = new Project($db);
  150. $proj->fetch($object->fk_project);
  151. $morehtmlref.='<a href="'.DOL_URL_ROOT.'/projet/card.php?id=' . $object->fk_project . '" title="' . $langs->trans('ShowProject') . '">';
  152. $morehtmlref.=$proj->ref;
  153. $morehtmlref.='</a>';
  154. } else {
  155. $morehtmlref.='';
  156. }
  157. }
  158. }
  159. $morehtmlref.='</div>';
  160. dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref, '', 0, '', '', 1);
  161. dol_fiche_end();
  162. // Contacts lines
  163. include DOL_DOCUMENT_ROOT.'/core/tpl/contacts.tpl.php';
  164. }
  165. else
  166. {
  167. // Contact not found
  168. print "ErrorRecordNotFound";
  169. }
  170. }
  171. // End of page
  172. llxFooter();
  173. $db->close();