document.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. <?php
  2. /* Copyright (C) 2002-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2010 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
  5. * Copyright (C) 2010 Juanjo Menent <jmenent@2byte.es>
  6. * Copyright (C) 2013-2016 Jean-François Ferry <hello@librethic.io>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. */
  21. /**
  22. * \file htdocs/ticket/document.php
  23. * \ingroup ticket
  24. * \brief files linked to a ticket
  25. */
  26. require '../main.inc.php';
  27. require_once DOL_DOCUMENT_ROOT . '/core/lib/ticket.lib.php';
  28. require_once DOL_DOCUMENT_ROOT . '/ticket/class/ticket.class.php';
  29. require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php';
  30. require_once DOL_DOCUMENT_ROOT . '/core/lib/images.lib.php';
  31. require_once DOL_DOCUMENT_ROOT . "/core/lib/company.lib.php";
  32. require_once DOL_DOCUMENT_ROOT . '/core/class/html.formfile.class.php';
  33. // Load translation files required by the page
  34. $langs->loadLangs(array("companies","other","ticket","mails"));
  35. $id = GETPOST('id', 'int');
  36. $ref = GETPOST('ref', 'alpha');
  37. $track_id = GETPOST('track_id', 'alpha');
  38. $action = GETPOST('action','alpha');
  39. $confirm = GETPOST('confirm','alpha');
  40. // Security check
  41. if (!$user->rights->ticket->read) {
  42. accessforbidden();
  43. }
  44. // Get parameters
  45. $sortfield = GETPOST("sortfield", 'alpha');
  46. $sortorder = GETPOST("sortorder", 'alpha');
  47. $page = GETPOST("page", 'int');
  48. if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
  49. $offset = $conf->liste_limit * $page;
  50. $pageprev = $page - 1;
  51. $pagenext = $page + 1;
  52. if (! $sortorder) $sortorder="ASC";
  53. if (! $sortfield) $sortfield="position_name";
  54. $object = new Ticket($db);
  55. $result = $object->fetch($id, $ref, $track_id);
  56. // to match document rules and compatibility
  57. $old_ref = $object->ref;
  58. $object->ref = $object->track_id;
  59. if ($result < 0) {
  60. setEventMessages($object->error, $object->errors, 'errors');
  61. } else {
  62. $upload_dir = $conf->ticket->dir_output . "/" . dol_sanitizeFileName($object->track_id);
  63. }
  64. /*
  65. * Actions
  66. */
  67. include_once DOL_DOCUMENT_ROOT . '/core/actions_linkedfiles.inc.php';
  68. $object->ref = $old_ref;
  69. /*
  70. * View
  71. */
  72. $form = new Form($db);
  73. $help_url = '';
  74. llxHeader('', $langs->trans("TicketDocumentsLinked") . ' - ' . $langs->trans("Files"), $help_url);
  75. if ($object->id)
  76. {
  77. /*
  78. * Show tabs
  79. */
  80. if ($socid > 0) {
  81. $object->fetch_thirdparty();
  82. $head = societe_prepare_head($object->thirdparty);
  83. dol_fiche_head($head, 'ticket', $langs->trans("ThirdParty"), 0, 'company');
  84. dol_banner_tab($object->thirdparty, 'socid', '', ($user->societe_id ? 0 : 1), 'rowid', 'nom');
  85. dol_fiche_end();
  86. }
  87. if (!$user->societe_id && $conf->global->TICKET_LIMIT_VIEW_ASSIGNED_ONLY) {
  88. $object->next_prev_filter = "te.fk_user_assign = '" . $user->id . "'";
  89. } elseif ($user->societe_id > 0) {
  90. $object->next_prev_filter = "te.fk_soc = '" . $user->societe_id . "'";
  91. }
  92. $head = ticket_prepare_head($object);
  93. dol_fiche_head($head, 'tabTicketDocument', $langs->trans("Ticket"), 0, 'ticket');
  94. $morehtmlref ='<div class="refidno">';
  95. $morehtmlref.= $object->subject;
  96. // Author
  97. if ($object->fk_user_create > 0) {
  98. $morehtmlref .= '<br>' . $langs->trans("CreatedBy") . ' ';
  99. $langs->load("users");
  100. $fuser = new User($db);
  101. $fuser->fetch($object->fk_user_create);
  102. $morehtmlref .= $fuser->getNomUrl(0);
  103. }
  104. if (!empty($object->origin_email)) {
  105. $morehtmlref .= '<br>' . $langs->trans("CreatedBy") . ' ';
  106. $morehtmlref .= $object->origin_email . ' <small>(' . $langs->trans("TicketEmailOriginIssuer") . ')</small>';
  107. }
  108. $morehtmlref.='</div>';
  109. $linkback = '<a href="' . dol_buildpath('/ticket/list.php', 1) . '"><strong>' . $langs->trans("BackToList") . '</strong></a> ';
  110. dol_banner_tab($object, 'ref', $linkback, ($user->societe_id ? 0 : 1), 'ref', 'ref', $morehtmlref);
  111. dol_fiche_end();
  112. // Build file list
  113. $filearray = dol_dir_list($upload_dir, "files", 0, '', '\.meta$', $sortfield, (strtolower($sortorder) == 'desc' ? SORT_DESC : SORT_ASC), 1);
  114. $totalsize = 0;
  115. foreach ($filearray as $key => $file) {
  116. $totalsize += $file['size'];
  117. }
  118. $object->ref = $object->track_id; // For compatibility we use track ID for directory
  119. $modulepart = 'ticket';
  120. $permission = $user->rights->ticket->write;
  121. $permtoedit = $user->rights->ticket->write;
  122. $param = '&id=' . $object->id;
  123. include_once DOL_DOCUMENT_ROOT . '/core/tpl/document_actions_post_headers.tpl.php';
  124. }
  125. else
  126. {
  127. accessforbidden('', 0, 0);
  128. }
  129. // End of page
  130. llxFooter();
  131. $db->close();