PageRenderTime 27ms CodeModel.GetById 1ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/contrat/contact.php

https://bitbucket.org/speedealing/speedealing
PHP | 190 lines | 109 code | 38 blank | 43 comment | 24 complexity | e66a7cd1571d07311d3173c59f24bcc1 MD5 | raw file
Possible License(s): LGPL-3.0, LGPL-2.1, GPL-3.0, MIT
  1. <?php
  2. /* Copyright (C) 2005 Patrick Rouillon <patrick@rouillon.net>
  3. * Copyright (C) 2005-2009 Destailleur Laurent <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 <http://www.gnu.org/licenses/>.
  18. */
  19. /**
  20. * \file htdocs/contrat/contact.php
  21. * \ingroup contrat
  22. * \brief Onglet de gestion des contacts des contrats
  23. */
  24. require ("../main.inc.php");
  25. require_once(DOL_DOCUMENT_ROOT."/core/class/html.formfile.class.php");
  26. require_once(DOL_DOCUMENT_ROOT.'/core/lib/contract.lib.php');
  27. require_once(DOL_DOCUMENT_ROOT."/contrat/class/contrat.class.php");
  28. require_once(DOL_DOCUMENT_ROOT."/contact/class/contact.class.php");
  29. require_once(DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php');
  30. $langs->load("contracts");
  31. $langs->load("companies");
  32. $action=GETPOST('action','alpha');
  33. $confirm=GETPOST('confirm','alpha');
  34. $socid = GETPOST('socid','int');
  35. $id = GETPOST('id','int');
  36. $ref=GETPOST('ref','alpha');
  37. // Security check
  38. if ($user->societe_id) $socid=$user->societe_id;
  39. $result=restrictedArea($user,'contrat',$id);
  40. $object = new Contrat($db);
  41. /*
  42. * Ajout d'un nouveau contact
  43. */
  44. if ($action == 'addcontact' && $user->rights->contrat->creer)
  45. {
  46. $result = $object->fetch($id);
  47. if ($result > 0 && $id > 0)
  48. {
  49. $contactid = (GETPOST('userid') ? GETPOST('userid') : GETPOST('contactid'));
  50. $result = $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. $mesg = '<div class="error">'.$langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType").'</div>';
  63. }
  64. else
  65. {
  66. $mesg = '<div class="error">'.$object->error.'</div>';
  67. }
  68. }
  69. }
  70. // bascule du statut d'un contact
  71. if ($action == 'swapstatut' && $user->rights->contrat->creer)
  72. {
  73. if ($object->fetch($id))
  74. {
  75. $result=$object->swapContactStatus(GETPOST('ligne'));
  76. }
  77. else
  78. {
  79. dol_print_error($db,$object->error);
  80. }
  81. }
  82. // Efface un contact
  83. if ($action == 'deletecontact' && $user->rights->contrat->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. }
  93. /*
  94. * View
  95. */
  96. llxHeader('', $langs->trans("ContractCard"), "Contrat");
  97. $form = new Form($db);
  98. $formcompany= new FormCompany($db);
  99. $contactstatic=new Contact($db);
  100. $userstatic=new User($db);
  101. $formfile = new FormFile($db);
  102. dol_htmloutput_mesg($mesg);
  103. /* *************************************************************************** */
  104. /* */
  105. /* Mode vue et edition */
  106. /* */
  107. /* *************************************************************************** */
  108. if ($id > 0 || ! empty($ref))
  109. {
  110. if ($object->fetch($id, $ref) > 0)
  111. {
  112. dol_htmloutput_mesg($mesg);
  113. $object->fetch_thirdparty();
  114. $head = contract_prepare_head($object);
  115. $hselected=1;
  116. dol_fiche_head($head, $hselected, $langs->trans("Contract"), 0, 'contract');
  117. /*
  118. * Contrat
  119. */
  120. print '<table class="border" width="100%">';
  121. $linkback = '<a href="'.DOL_URL_ROOT.'/contrat/liste.php'.(! empty($socid)?'?socid='.$socid:'').'">'.$langs->trans("BackToList").'</a>';
  122. // Reference du contrat
  123. print '<tr><td width="25%">'.$langs->trans("Ref").'</td><td colspan="3">';
  124. print $form->showrefnav($object, 'ref', $linkback, 1, 'ref', 'ref', '');
  125. print "</td></tr>";
  126. // Customer
  127. print "<tr><td>".$langs->trans("Customer")."</td>";
  128. print '<td colspan="3">'.$object->thirdparty->getNomUrl(1).'</td></tr>';
  129. // Ligne info remises tiers
  130. print '<tr><td>'.$langs->trans('Discount').'</td><td>';
  131. if ($object->thirdparty->remise_client) print $langs->trans("CompanyHasRelativeDiscount",$object->thirdparty->remise_client);
  132. else print $langs->trans("CompanyHasNoRelativeDiscount");
  133. $absolute_discount=$object->thirdparty->getAvailableDiscounts();
  134. print '. ';
  135. if ($absolute_discount) print $langs->trans("CompanyHasAbsoluteDiscount",$absolute_discount,$langs->trans("Currency".$conf->currency));
  136. else print $langs->trans("CompanyHasNoAbsoluteDiscount");
  137. print '.';
  138. print '</td></tr>';
  139. print "</table>";
  140. print '</div>';
  141. print '<br>';
  142. // Contacts lines
  143. include DOL_DOCUMENT_ROOT.'/core/tpl/contacts.tpl.php';
  144. }
  145. else
  146. {
  147. print "ErrorRecordNotFound";
  148. }
  149. }
  150. llxFooter();
  151. $db->close();
  152. ?>