contact.php 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. <?php
  2. /* Copyright (C) 2011-2016 Jean-François Ferry <hello@librethic.io>
  3. * Copyright (C) 2011 Regis Houssin <regis.houssin@inodbox.com>
  4. * Copyright (C) 2016 Christophe Battarel <christophe@altairis.fr>
  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, write to the Free Software
  18. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  19. */
  20. /**
  21. * \file htdocs/ticket/contact.php
  22. * \ingroup ticket
  23. * \brief Contacts of tickets
  24. */
  25. require '../main.inc.php';
  26. require_once DOL_DOCUMENT_ROOT . '/ticket/class/ticket.class.php';
  27. require_once DOL_DOCUMENT_ROOT . '/core/lib/ticket.lib.php';
  28. require_once DOL_DOCUMENT_ROOT . '/societe/class/societe.class.php';
  29. require_once DOL_DOCUMENT_ROOT . "/core/lib/company.lib.php";
  30. require_once DOL_DOCUMENT_ROOT . '/contact/class/contact.class.php';
  31. require_once DOL_DOCUMENT_ROOT . '/core/class/html.formcompany.class.php';
  32. // Load translation files required by the page
  33. $langs->loadLangs(array('companies', 'ticket'));
  34. // Get parameters
  35. $socid = GETPOST("socid", 'int');
  36. $action = GETPOST("action", 'alpha');
  37. $track_id = GETPOST("track_id", 'alpha');
  38. $id = GETPOST("id", 'int');
  39. $ref = GETPOST('ref', 'alpha');
  40. $type = GETPOST('type', 'alpha');
  41. $source = GETPOST('source', 'alpha');
  42. $ligne = GETPOST('ligne', 'int');
  43. $lineid = GETPOST('lineid', 'int');
  44. // Protection if external user
  45. if ($user->societe_id > 0) {
  46. $socid = $user->societe_id;
  47. accessforbidden();
  48. }
  49. // Store current page url
  50. $url_page_current = dol_buildpath('/ticket/contact.php', 1);
  51. $object = new Ticket($db);
  52. /*
  53. * Ajout d'un nouveau contact
  54. */
  55. if ($action == 'addcontact' && $user->rights->ticket->write) {
  56. $result = $object->fetch($id, '', $track_id);
  57. if ($result > 0 && ($id > 0 || (!empty($track_id)))) {
  58. $contactid = (GETPOST('userid', 'int') ? GETPOST('userid', 'int') : GETPOST('contactid', 'int'));
  59. $result = $object->add_contact($contactid, $type, $source);
  60. }
  61. if ($result >= 0) {
  62. Header("Location: " . $url_page_current . "?id=" . $object->id);
  63. exit;
  64. } else {
  65. if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
  66. $langs->load("errors");
  67. setEventMessages($langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType"), null, 'errors');
  68. } else {
  69. setEventMessages($object->error, $object->errors, 'errors');
  70. }
  71. }
  72. }
  73. // bascule du statut d'un contact
  74. if ($action == 'swapstatut' && $user->rights->ticket->write) {
  75. if ($object->fetch($id, '', $track_id)) {
  76. $result = $object->swapContactStatus($ligne);
  77. } else {
  78. dol_print_error($db, $object->error);
  79. }
  80. }
  81. // Efface un contact
  82. if ($action == 'deletecontact' && $user->rights->ticket->write) {
  83. if ($object->fetch($id, '', $track_id)) {
  84. $result = $object->delete_contact($lineid);
  85. if ($result >= 0) {
  86. Header("Location: " . $url_page_current . "?id=" . $object->id);
  87. exit;
  88. }
  89. }
  90. }
  91. /*
  92. * View
  93. */
  94. $help_url = 'FR:DocumentationModuleTicket';
  95. llxHeader('', $langs->trans("TicketContacts"), $help_url);
  96. $form = new Form($db);
  97. $formcompany = new FormCompany($db);
  98. $contactstatic = new Contact($db);
  99. $userstatic = new User($db);
  100. /* *************************************************************************** */
  101. /* */
  102. /* Mode vue et edition */
  103. /* */
  104. /* *************************************************************************** */
  105. if ($id > 0 || !empty($track_id) || !empty($ref)) {
  106. if ($object->fetch($id, $ref, $track_id) > 0)
  107. {
  108. if ($socid > 0) {
  109. $object->fetch_thirdparty();
  110. $head = societe_prepare_head($object->thirdparty);
  111. dol_fiche_head($head, 'ticket', $langs->trans("ThirdParty"), 0, 'company');
  112. dol_banner_tab($object->thirdparty, 'socid', '', ($user->societe_id ? 0 : 1), 'rowid', 'nom');
  113. dol_fiche_end();
  114. }
  115. if (!$user->societe_id && $conf->global->TICKET_LIMIT_VIEW_ASSIGNED_ONLY) {
  116. $object->next_prev_filter = "te.fk_user_assign = '" . $user->id . "'";
  117. } elseif ($user->societe_id > 0) {
  118. $object->next_prev_filter = "te.fk_soc = '" . $user->societe_id . "'";
  119. }
  120. $head = ticket_prepare_head($object);
  121. dol_fiche_head($head, 'contact', $langs->trans("Ticket"), -1, 'ticket');
  122. $morehtmlref ='<div class="refidno">';
  123. $morehtmlref.= $object->subject;
  124. // Author
  125. if ($object->fk_user_create > 0) {
  126. $morehtmlref .= '<br>' . $langs->trans("CreatedBy") . ' ';
  127. $langs->load("users");
  128. $fuser = new User($db);
  129. $fuser->fetch($object->fk_user_create);
  130. $morehtmlref .= $fuser->getNomUrl(0);
  131. }
  132. if (!empty($object->origin_email)) {
  133. $morehtmlref .= '<br>' . $langs->trans("CreatedBy") . ' ';
  134. $morehtmlref .= $object->origin_email . ' <small>(' . $langs->trans("TicketEmailOriginIssuer") . ')</small>';
  135. }
  136. $morehtmlref.='</div>';
  137. $linkback = '<a href="' . dol_buildpath('/ticket/list.php', 1) . '"><strong>' . $langs->trans("BackToList") . '</strong></a> ';
  138. dol_banner_tab($object, 'ref', $linkback, ($user->societe_id ? 0 : 1), 'ref', 'ref', $morehtmlref);
  139. dol_fiche_end();
  140. //print '<br>';
  141. $permission = $user->rights->ticket->write;
  142. // Contacts lines (modules that overwrite templates must declare this into descriptor)
  143. $dirtpls=array_merge($conf->modules_parts['tpl'], array('/core/tpl'));
  144. foreach ($dirtpls as $reldir) {
  145. $res=@include dol_buildpath($reldir.'/contacts.tpl.php');
  146. if ($res) {
  147. break;
  148. }
  149. }
  150. } else {
  151. print "ErrorRecordNotFound";
  152. }
  153. }
  154. // End of page
  155. llxFooter();
  156. $db->close();