contact.php 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. <?php
  2. /* Copyright (C) 2005 Patrick Rouillon <patrick@rouillon.net>
  3. * Copyright (C) 2005-2016 Destailleur Laurent <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
  5. * Copyright (C) 2011-2015 Philippe Grand <philippe.grand@atoo-net.com>
  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 <https://www.gnu.org/licenses/>.
  19. */
  20. /**
  21. * \file htdocs/comm/propal/contact.php
  22. * \ingroup propal
  23. * \brief Tab to manage contacts/adresses of proposal
  24. */
  25. require '../../main.inc.php';
  26. require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
  27. require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
  28. require_once DOL_DOCUMENT_ROOT.'/core/lib/propal.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. require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
  32. // Load translation files required by the page
  33. $langs->loadLangs(array('facture', 'propal', 'orders', 'sendings', 'companies'));
  34. $id = GETPOST('id', 'int');
  35. $ref = GETPOST('ref', 'alpha');
  36. $lineid = GETPOST('lineid', 'int');
  37. $action = GETPOST('action', 'aZ09');
  38. $object = new Propal($db);
  39. // Load object
  40. if ($id > 0 || !empty($ref)) {
  41. $ret = $object->fetch($id, $ref);
  42. if ($ret == 0) {
  43. $langs->load("errors");
  44. setEventMessages($langs->trans('ErrorRecordNotFound'), null, 'errors');
  45. $error++;
  46. } elseif ($ret < 0) {
  47. setEventMessages($object->error, $object->errors, 'errors');
  48. $error++;
  49. }
  50. }
  51. if (!$error) {
  52. $object->fetch_thirdparty();
  53. } else {
  54. header('Location: '.DOL_URL_ROOT.'/comm/propal/list.php');
  55. exit;
  56. }
  57. // Security check
  58. if (!empty($user->socid)) {
  59. $socid = $user->socid;
  60. $object->id = $user->socid;
  61. }
  62. restrictedArea($user, 'propal', $object->id);
  63. /*
  64. * Add a new contact
  65. */
  66. if ($action == 'addcontact' && $user->rights->propale->creer) {
  67. if ($object->id > 0) {
  68. $contactid = (GETPOST('userid', 'int') ? GETPOST('userid', 'int') : GETPOST('contactid', 'int'));
  69. $typeid = (GETPOST('typecontact') ? GETPOST('typecontact') : GETPOST('type'));
  70. $result = $object->add_contact($contactid, $typeid, GETPOST("source", 'aZ09'));
  71. }
  72. if ($result >= 0) {
  73. header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
  74. exit;
  75. } else {
  76. if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
  77. $langs->load("errors");
  78. setEventMessages($langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType"), null, 'errors');
  79. } else {
  80. setEventMessages($object->error, $object->errors, 'errors');
  81. }
  82. }
  83. } elseif ($action == 'swapstatut' && $user->rights->propale->creer) {
  84. // Toggle the status of a contact
  85. if ($object->id > 0) {
  86. $result = $object->swapContactStatus(GETPOST('ligne', 'int'));
  87. }
  88. } elseif ($action == 'deletecontact' && $user->rights->propale->creer) {
  89. // Deletes a contact
  90. $result = $object->delete_contact($lineid);
  91. if ($result >= 0) {
  92. header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
  93. exit;
  94. } else {
  95. dol_print_error($db);
  96. }
  97. }
  98. /*
  99. * View
  100. */
  101. $title = $langs->trans('Proposal')." - ".$langs->trans('ContactsAddresses');
  102. $help_url = "EN:Commercial_Proposals|FR:Proposition_commerciale|ES:Presupuestos";
  103. llxHeader('', $title, $help_url);
  104. $form = new Form($db);
  105. $formcompany = new FormCompany($db);
  106. $formother = new FormOther($db);
  107. if ($object->id > 0) {
  108. $head = propal_prepare_head($object);
  109. print dol_get_fiche_head($head, 'contact', $langs->trans("Proposal"), -1, 'propal');
  110. // Proposal card
  111. $linkback = '<a href="'.DOL_URL_ROOT.'/comm/propal/list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
  112. $morehtmlref = '<div class="refidno">';
  113. // Ref customer
  114. $morehtmlref .= $form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', 0, 1);
  115. $morehtmlref .= $form->editfieldval("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', null, null, '', 1);
  116. // Thirdparty
  117. $morehtmlref .= '<br>'.$langs->trans('ThirdParty').' : '.$object->thirdparty->getNomUrl(1, 'customer');
  118. // Project
  119. if (!empty($conf->project->enabled)) {
  120. $langs->load("projects");
  121. $morehtmlref .= '<br>'.$langs->trans('Project').' ';
  122. if ($user->rights->propal->creer) {
  123. if ($action != 'classify') {
  124. //$morehtmlref.='<a class="editfielda" href="' . $_SERVER['PHP_SELF'] . '?action=classify&token='.newToken().'&id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a>';
  125. $morehtmlref .= ' : ';
  126. }
  127. if ($action == 'classify') {
  128. //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
  129. $morehtmlref .= '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
  130. $morehtmlref .= '<input type="hidden" name="action" value="classin">';
  131. $morehtmlref .= '<input type="hidden" name="token" value="'.newToken().'">';
  132. $morehtmlref .= $formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);
  133. $morehtmlref .= '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
  134. $morehtmlref .= '</form>';
  135. } else {
  136. $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1);
  137. }
  138. } else {
  139. if (!empty($object->fk_project)) {
  140. $proj = new Project($db);
  141. $proj->fetch($object->fk_project);
  142. $morehtmlref .= ' : '.$proj->getNomUrl(1);
  143. if ($proj->title) {
  144. $morehtmlref .= ' - '.$proj->title;
  145. }
  146. } else {
  147. $morehtmlref .= '';
  148. }
  149. }
  150. }
  151. $morehtmlref .= '</div>';
  152. dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref, '', 0, '', '', 1);
  153. print dol_get_fiche_end();
  154. // Contacts lines (modules that overwrite templates must declare this into descriptor)
  155. $dirtpls = array_merge($conf->modules_parts['tpl'], array('/core/tpl'));
  156. foreach ($dirtpls as $reldir) {
  157. $res = @include dol_buildpath($reldir.'/contacts.tpl.php');
  158. if ($res) {
  159. break;
  160. }
  161. }
  162. }
  163. // End of page
  164. llxFooter();
  165. $db->close();