ticket.lib.php 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. <?php
  2. /* Copyright (C) 2013-2018 Jean-François FERRY <hello@librethic.io>
  3. * Copyright (C) 2016 Christophe Battarel <christophe@altairis.fr>
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /**
  19. * \file core/lib/ticket.lib.php
  20. * \ingroup ticket
  21. * \brief This file is a library for Ticket module
  22. */
  23. /**
  24. * Build tabs for admin page
  25. *
  26. * @return array
  27. */
  28. function ticketAdminPrepareHead()
  29. {
  30. global $langs, $conf;
  31. $langs->load("ticket");
  32. $h = 0;
  33. $head = array();
  34. $head[$h][0] = DOL_URL_ROOT.'/admin/ticket.php';
  35. $head[$h][1] = $langs->trans("TicketSettings");
  36. $head[$h][2] = 'settings';
  37. $h++;
  38. $head[$h][0] = DOL_URL_ROOT.'/admin/ticket_extrafields.php';
  39. $head[$h][1] = $langs->trans("ExtraFieldsTicket");
  40. $head[$h][2] = 'attributes';
  41. $h++;
  42. // Show more tabs from modules
  43. // Entries must be declared in modules descriptor with line
  44. //$this->tabs = array(
  45. // 'entity:+tabname:Title:@ticket:/ticket/mypage.php?id=__ID__'
  46. //); // to add new tab
  47. //$this->tabs = array(
  48. // 'entity:-tabname:Title:@ticket:/ticket/mypage.php?id=__ID__'
  49. //); // to remove a tab
  50. complete_head_from_modules($conf, $langs, $object, $head, $h, 'ticketadmin');
  51. return $head;
  52. }
  53. /**
  54. * Build tabs for a Ticket object
  55. *
  56. * @param Ticket $object Object Ticket
  57. * @return array Array of tabs
  58. */
  59. function ticket_prepare_head($object)
  60. {
  61. global $db, $langs, $conf, $user;
  62. $h = 0;
  63. $head = array();
  64. $head[$h][0] = DOL_URL_ROOT.'/ticket/card.php?action=view&track_id=' . $object->track_id;
  65. $head[$h][1] = $langs->trans("Card");
  66. $head[$h][2] = 'tabTicket';
  67. $h++;
  68. if (empty($conf->global->MAIN_DISABLE_CONTACTS_TAB) && empty($user->socid))
  69. {
  70. $nbContact = count($object->liste_contact(-1,'internal')) + count($object->liste_contact(-1,'external'));
  71. $head[$h][0] = DOL_URL_ROOT.'/ticket/contact.php?track_id='.$object->track_id;
  72. $head[$h][1] = $langs->trans('ContactsAddresses');
  73. if ($nbContact > 0) $head[$h][1].= ' <span class="badge">'.$nbContact.'</span>';
  74. $head[$h][2] = 'contact';
  75. $h++;
  76. }
  77. complete_head_from_modules($conf, $langs, $object, $head, $h, 'ticket');
  78. // Attached files
  79. include_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php';
  80. $upload_dir = $conf->ticket->dir_output . "/" . $object->track_id;
  81. $nbFiles = count(dol_dir_list($upload_dir, 'files'));
  82. $head[$h][0] = dol_buildpath('/ticket/document.php', 1) . '?track_id=' . $object->track_id;
  83. $head[$h][1] = $langs->trans("Documents");
  84. if ($nbFiles > 0) {
  85. $head[$h][1] .= ' <span class="badge">' . $nbFiles . '</span>';
  86. }
  87. $head[$h][2] = 'tabTicketDocument';
  88. $h++;
  89. // History
  90. $head[$h][0] = DOL_URL_ROOT.'/ticket/history.php?track_id=' . $object->track_id;
  91. $head[$h][1] = $langs->trans('Events');
  92. if (! empty($conf->agenda->enabled) && (!empty($user->rights->agenda->myactions->read) || !empty($user->rights->agenda->allactions->read) ))
  93. {
  94. $head[$h][1].= '/';
  95. $head[$h][1].= $langs->trans("Agenda");
  96. }
  97. $head[$h][2] = 'tabTicketLogs';
  98. $h++;
  99. complete_head_from_modules($conf, $langs, $object, $head, $h, 'ticket','remove');
  100. return $head;
  101. }
  102. /**
  103. * Generate a random id
  104. *
  105. * @param string $car Char to generate key
  106. * @return void
  107. */
  108. function generate_random_id($car=16)
  109. {
  110. $string = "";
  111. $chaine = "abcdefghijklmnopqrstuvwxyz123456789";
  112. srand((double) microtime() * 1000000);
  113. for ($i = 0; $i < $car; $i++) {
  114. $string .= $chaine[rand() % strlen($chaine)];
  115. }
  116. return $string;
  117. }
  118. /**
  119. * Show header for public pages
  120. *
  121. * @param string $title Title
  122. * @param string $head Head array
  123. * @param int $disablejs More content into html header
  124. * @param int $disablehead More content into html header
  125. * @param array $arrayofjs Array of complementary js files
  126. * @param array $arrayofcss Array of complementary css files
  127. * @return void
  128. */
  129. function llxHeaderTicket($title, $head = "", $disablejs = 0, $disablehead = 0, $arrayofjs = '', $arrayofcss = '')
  130. {
  131. global $user, $conf, $langs, $mysoc;
  132. top_htmlhead($head, $title, $disablejs, $disablehead, $arrayofjs, $arrayofcss); // Show html headers
  133. print '<body id="mainbody" class="publicnewticketform" style="margin-top: 10px;">';
  134. if (! empty($conf->global->TICKET_SHOW_COMPANY_LOGO)) {
  135. // Print logo
  136. $urllogo = DOL_URL_ROOT . '/theme/login_logo.png';
  137. if (!empty($mysoc->logo_small) && is_readable($conf->mycompany->dir_output . '/logos/thumbs/' . $mysoc->logo_small)) {
  138. $urllogo = DOL_URL_ROOT . '/viewimage.php?modulepart=mycompany&amp;entity='.$conf->entity.'&amp;file=' . urlencode('logos/thumbs/'.$mysoc->logo_small);
  139. } elseif (!empty($mysoc->logo) && is_readable($conf->mycompany->dir_output . '/logos/' . $mysoc->logo)) {
  140. $urllogo = DOL_URL_ROOT . '/viewimage.php?modulepart=mycompany&amp;entity='.$conf->entity.'&amp;file=' . urlencode('logos/'.$mysoc->logo);
  141. $width = 128;
  142. } elseif (is_readable(DOL_DOCUMENT_ROOT . '/theme/dolibarr_logo.png')) {
  143. $urllogo = DOL_URL_ROOT . '/theme/dolibarr_logo.png';
  144. }
  145. print '<center>';
  146. print '<a href="' . ($conf->global->TICKET_URL_PUBLIC_INTERFACE ? $conf->global->TICKET_URL_PUBLIC_INTERFACE : dol_buildpath('/public/ticket/index.php', 1)) . '"><img alt="Logo" id="logosubscribe" title="" src="' . $urllogo . '" style="max-width: 440px" /></a><br>';
  147. print '<strong>' . ($conf->global->TICKET_PUBLIC_INTERFACE_TOPIC ? $conf->global->TICKET_PUBLIC_INTERFACE_TOPIC : $langs->trans("TicketSystem")) . '</strong>';
  148. print '</center><br>';
  149. }
  150. print '<div style="margin-left: 50px; margin-right: 50px;">';
  151. }