ticket.lib.php 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. <?php
  2. /* Copyright (C) 2013-2018 Jean-François FERRY <hello@librethic.io>
  3. * Copyright (C) 2016 Christophe Battarel <christophe@altairis.fr>
  4. * Copyright (C) 2019-2022 Frédéric France <frederic.france@netlogic.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, see <https://www.gnu.org/licenses/>.
  18. */
  19. /**
  20. * \file core/lib/ticket.lib.php
  21. * \ingroup ticket
  22. * \brief This file is a library for Ticket module
  23. */
  24. /**
  25. * Build tabs for admin page
  26. *
  27. * @return array
  28. */
  29. function ticketAdminPrepareHead()
  30. {
  31. global $langs, $conf, $db;
  32. $extrafields = new ExtraFields($db);
  33. $extrafields->fetch_name_optionals_label('ticket');
  34. $langs->load("ticket");
  35. $h = 0;
  36. $head = array();
  37. $head[$h][0] = DOL_URL_ROOT.'/admin/ticket.php';
  38. $head[$h][1] = $langs->trans("TicketSettings");
  39. $head[$h][2] = 'settings';
  40. $h++;
  41. $head[$h][0] = DOL_URL_ROOT.'/admin/ticket_extrafields.php';
  42. $head[$h][1] = $langs->trans("ExtraFieldsTicket");
  43. $nbExtrafields = $extrafields->attributes['ticket']['count'];
  44. if ($nbExtrafields > 0) {
  45. $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbExtrafields.'</span>';
  46. }
  47. $head[$h][2] = 'attributes';
  48. $h++;
  49. $head[$h][0] = DOL_URL_ROOT.'/admin/ticket_public.php';
  50. $head[$h][1] = $langs->trans("PublicInterface");
  51. $head[$h][2] = 'public';
  52. $h++;
  53. // Show more tabs from modules
  54. // Entries must be declared in modules descriptor with line
  55. //$this->tabs = array(
  56. // 'entity:+tabname:Title:@ticket:/ticket/mypage.php?id=__ID__'
  57. //); // to add new tab
  58. //$this->tabs = array(
  59. // 'entity:-tabname:Title:@ticket:/ticket/mypage.php?id=__ID__'
  60. //); // to remove a tab
  61. complete_head_from_modules($conf, $langs, null, $head, $h, 'ticketadmin');
  62. complete_head_from_modules($conf, $langs, null, $head, $h, 'ticketadmin', 'remove');
  63. return $head;
  64. }
  65. /**
  66. * Build tabs for a Ticket object
  67. *
  68. * @param Ticket $object Object Ticket
  69. * @return array Array of tabs
  70. */
  71. function ticket_prepare_head($object)
  72. {
  73. global $db, $langs, $conf, $user;
  74. $h = 0;
  75. $head = array();
  76. $head[$h][0] = DOL_URL_ROOT.'/ticket/card.php?track_id='.$object->track_id;
  77. $head[$h][1] = $langs->trans("Ticket");
  78. $head[$h][2] = 'tabTicket';
  79. $h++;
  80. if (!getDolGlobalInt('MAIN_DISABLE_CONTACTS_TAB') && empty($user->socid) && isModEnabled("societe")) {
  81. $nbContact = count($object->liste_contact(-1, 'internal')) + count($object->liste_contact(-1, 'external'));
  82. $head[$h][0] = DOL_URL_ROOT.'/ticket/contact.php?track_id='.$object->track_id;
  83. $head[$h][1] = $langs->trans('ContactsAddresses');
  84. if ($nbContact > 0) {
  85. $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbContact.'</span>';
  86. }
  87. $head[$h][2] = 'contact';
  88. $h++;
  89. }
  90. complete_head_from_modules($conf, $langs, $object, $head, $h, 'ticket', 'add', 'core');
  91. // Attached files
  92. include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  93. $upload_dir = $conf->ticket->dir_output."/".$object->ref;
  94. $nbFiles = count(dol_dir_list($upload_dir, 'files'));
  95. $head[$h][0] = DOL_URL_ROOT.'/ticket/document.php?id='.$object->id;
  96. $head[$h][1] = $langs->trans("Documents");
  97. if ($nbFiles > 0) {
  98. $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbFiles.'</span>';
  99. }
  100. $head[$h][2] = 'tabTicketDocument';
  101. $h++;
  102. // History
  103. $ticketViewType = "messaging";
  104. if (empty($_SESSION['ticket-view-type'])) {
  105. $_SESSION['ticket-view-type'] = $ticketViewType;
  106. } else {
  107. $ticketViewType = $_SESSION['ticket-view-type'];
  108. }
  109. if ($ticketViewType == "messaging") {
  110. $head[$h][0] = DOL_URL_ROOT.'/ticket/messaging.php?track_id='.$object->track_id;
  111. } else {
  112. // $ticketViewType == "list"
  113. $head[$h][0] = DOL_URL_ROOT.'/ticket/agenda.php?track_id='.$object->track_id;
  114. }
  115. $head[$h][1] = $langs->trans('Events');
  116. if (isModEnabled('agenda') && ($user->hasRight('agenda', 'myactions', 'read') || $user->hasRight('agenda', 'allactions', 'read'))) {
  117. $head[$h][1] .= '/';
  118. $head[$h][1] .= $langs->trans("Agenda");
  119. }
  120. $head[$h][2] = 'tabTicketLogs';
  121. $h++;
  122. complete_head_from_modules($conf, $langs, $object, $head, $h, 'ticket', 'add', 'external');
  123. complete_head_from_modules($conf, $langs, $object, $head, $h, 'ticket', 'remove');
  124. return $head;
  125. }
  126. /**
  127. * Return string with full Url. The file qualified is the one defined by relative path in $object->last_main_doc
  128. *
  129. * @param Object $object Object
  130. * @return string Url string
  131. */
  132. function showDirectPublicLink($object)
  133. {
  134. global $conf, $langs;
  135. require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
  136. $email = CMailFile::getValidAddress($object->origin_email, 2);
  137. $url = '';
  138. if ($email) {
  139. $url = dol_buildpath('/public/ticket/view.php', 3).'?track_id='.$object->track_id.'&email='.$email;
  140. }
  141. $out = '';
  142. if (!getDolGlobalInt('TICKET_ENABLE_PUBLIC_INTERFACE')) {
  143. $langs->load('errors');
  144. $out .= '<span class="opacitymedium">'.$langs->trans("ErrorPublicInterfaceNotEnabled").'</span>';
  145. } else {
  146. $out .= img_picto('', 'object_globe.png').' <span class="opacitymedium">'.$langs->trans("TicketPublicAccess").'</span><br>';
  147. if ($url) {
  148. $out .= '<div class="urllink">';
  149. $out .= '<input type="text" id="directpubliclink" class="quatrevingtpercentminusx" value="'.$url.'">';
  150. $out .= '<a href="'.$url.'" target="_blank" rel="noopener noreferrer">'.img_picto('', 'object_globe.png', 'class="paddingleft"').'</a>';
  151. $out .= '</div>';
  152. $out .= ajax_autoselect("directpubliclink", 0);
  153. } else {
  154. $out .= '<span class="opacitymedium">'.$langs->trans("TicketNotCreatedFromPublicInterface").'</span>';
  155. }
  156. }
  157. return $out;
  158. }
  159. /**
  160. * Generate a random id
  161. *
  162. * @param int $car Length of string to generate key
  163. * @return string
  164. */
  165. function generate_random_id($car = 16)
  166. {
  167. $string = "";
  168. $chaine = "abcdefghijklmnopqrstuvwxyz123456789";
  169. mt_srand((double) microtime() * 1000000);
  170. for ($i = 0; $i < $car; $i++) {
  171. $string .= $chaine[mt_rand() % strlen($chaine)];
  172. }
  173. return $string;
  174. }
  175. /**
  176. * Show http header, open body tag and show HTML header banner for public pages for tickets
  177. *
  178. * @param string $title Title
  179. * @param string $head Head array
  180. * @param int $disablejs More content into html header
  181. * @param int $disablehead More content into html header
  182. * @param array $arrayofjs Array of complementary js files
  183. * @param array $arrayofcss Array of complementary css files
  184. * @return void
  185. */
  186. function llxHeaderTicket($title, $head = "", $disablejs = 0, $disablehead = 0, $arrayofjs = '', $arrayofcss = '')
  187. {
  188. global $user, $conf, $langs, $mysoc;
  189. $urllogo = "";
  190. top_htmlhead($head, $title, $disablejs, $disablehead, $arrayofjs, $arrayofcss, 0, 1); // Show html headers
  191. print '<body id="mainbody" class="publicnewticketform">';
  192. print '<div class="publicnewticketform2 flexcontainer centpercent" style="min-height: 100%;">';
  193. print '<header class="center centpercent">';
  194. // Define urllogo
  195. if (getDolGlobalInt('TICKET_SHOW_COMPANY_LOGO') || getDolGlobalString('TICKET_PUBLIC_INTERFACE_TOPIC')) {
  196. // Print logo
  197. if (getDolGlobalInt('TICKET_SHOW_COMPANY_LOGO')) {
  198. $urllogo = DOL_URL_ROOT.'/theme/common/login_logo.png';
  199. if (!empty($mysoc->logo_small) && is_readable($conf->mycompany->dir_output.'/logos/thumbs/'.$mysoc->logo_small)) {
  200. $urllogo = DOL_URL_ROOT.'/viewimage.php?modulepart=mycompany&amp;entity='.$conf->entity.'&amp;file='.urlencode('logos/thumbs/'.$mysoc->logo_small);
  201. } elseif (!empty($mysoc->logo) && is_readable($conf->mycompany->dir_output.'/logos/'.$mysoc->logo)) {
  202. $urllogo = DOL_URL_ROOT.'/viewimage.php?modulepart=mycompany&amp;entity='.$conf->entity.'&amp;file='.urlencode('logos/'.$mysoc->logo);
  203. } elseif (is_readable(DOL_DOCUMENT_ROOT.'/theme/dolibarr_logo.svg')) {
  204. $urllogo = DOL_URL_ROOT.'/theme/dolibarr_logo.svg';
  205. }
  206. }
  207. }
  208. // Output html code for logo
  209. if ($urllogo || getDolGlobalString('TICKET_PUBLIC_INTERFACE_TOPIC')) {
  210. print '<div class="backgreypublicpayment">';
  211. print '<div class="logopublicpayment">';
  212. if ($urllogo) {
  213. print '<a href="'.(getDolGlobalString('TICKET_URL_PUBLIC_INTERFACE') ? getDolGlobalString('TICKET_URL_PUBLIC_INTERFACE') : dol_buildpath('/public/ticket/index.php?entity='.$conf->entity, 1)).'">';
  214. print '<img id="dolpaymentlogo" src="'.$urllogo.'"';
  215. print '>';
  216. print '</a>';
  217. }
  218. if (getDolGlobalString('TICKET_PUBLIC_INTERFACE_TOPIC')) {
  219. print '<div class="clearboth"></div><strong>'.(getDolGlobalString('TICKET_PUBLIC_INTERFACE_TOPIC') ? getDolGlobalString('TICKET_PUBLIC_INTERFACE_TOPIC') : $langs->trans("TicketSystem")).'</strong>';
  220. }
  221. print '</div>';
  222. if (!getDolGlobalInt('MAIN_HIDE_POWERED_BY')) {
  223. print '<div class="poweredbypublicpayment opacitymedium right hideonsmartphone"><a class="poweredbyhref" href="https://www.dolibarr.org?utm_medium=website&utm_source=poweredby" target="dolibarr" rel="noopener">'.$langs->trans("PoweredBy").'<br><img src="'.DOL_URL_ROOT.'/theme/dolibarr_logo.svg" width="80px"></a></div>';
  224. }
  225. print '</div>';
  226. }
  227. if (getDolGlobalInt('TICKET_IMAGE_PUBLIC_INTERFACE')) {
  228. print '<div class="backimagepublicticket">';
  229. print '<img id="idTICKET_IMAGE_PUBLIC_INTERFACE" src="'.getDolGlobalString('TICKET_IMAGE_PUBLIC_INTERFACE').'">';
  230. print '</div>';
  231. }
  232. print '</header>';
  233. //print '<div class="ticketlargemargin">';
  234. }