document.php 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  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 <https://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. $socid = GETPOST('socid', 'int');
  37. $ref = GETPOST('ref', 'alpha');
  38. $track_id = GETPOST('track_id', 'alpha');
  39. $action = GETPOST('action', 'alpha');
  40. $confirm = GETPOST('confirm', 'alpha');
  41. // Get parameters
  42. $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
  43. $sortfield = GETPOST('sortfield', 'aZ09comma');
  44. $sortorder = GETPOST('sortorder', 'aZ09comma');
  45. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  46. if (empty($page) || $page == -1) {
  47. $page = 0;
  48. } // If $page is not defined, or '' or -1
  49. $offset = $limit * $page;
  50. $pageprev = $page - 1;
  51. $pagenext = $page + 1;
  52. if (!$sortorder) {
  53. $sortorder = "ASC";
  54. }
  55. if (!$sortfield) {
  56. $sortfield = "position_name";
  57. }
  58. $object = new Ticket($db);
  59. $result = $object->fetch($id, $ref, $track_id);
  60. if ($result < 0) {
  61. setEventMessages($object->error, $object->errors, 'errors');
  62. } else {
  63. $upload_dir = $conf->ticket->dir_output."/".dol_sanitizeFileName($object->ref);
  64. }
  65. $permissiontoadd = $user->rights->ticket->write; // Used by the include of actions_addupdatedelete.inc.php and actions_linkedfiles
  66. // Security check - Protection if external user
  67. $result = restrictedArea($user, 'ticket', $object->id);
  68. // restrict access for externals users
  69. if ($user->socid > 0 && ($object->fk_soc != $user->socid)) {
  70. accessforbidden();
  71. }
  72. // or for unauthorized internals users
  73. if (!$user->socid && !empty($conf->global->TICKET_LIMIT_VIEW_ASSIGNED_ONLY) && $object->fk_user_assign != $user->id && empty($user->rights->ticket->manage)) {
  74. accessforbidden();
  75. }
  76. /*
  77. * Actions
  78. */
  79. include DOL_DOCUMENT_ROOT.'/core/actions_linkedfiles.inc.php';
  80. /*
  81. * View
  82. */
  83. $form = new Form($db);
  84. $help_url = '';
  85. llxHeader('', $langs->trans("TicketDocumentsLinked").' - '.$langs->trans("Files"), $help_url);
  86. if ($object->id) {
  87. /*
  88. * Show tabs
  89. */
  90. if ($socid > 0) {
  91. $object->fetch_thirdparty();
  92. $head = societe_prepare_head($object->thirdparty);
  93. print dol_get_fiche_head($head, 'ticket', $langs->trans("ThirdParty"), 0, 'company');
  94. dol_banner_tab($object->thirdparty, 'socid', '', ($user->socid ? 0 : 1), 'rowid', 'nom');
  95. print dol_get_fiche_end();
  96. }
  97. if (!$user->socid && !empty($conf->global->TICKET_LIMIT_VIEW_ASSIGNED_ONLY)) {
  98. $object->next_prev_filter = "te.fk_user_assign = '".$user->id."'";
  99. } elseif ($user->socid > 0) {
  100. $object->next_prev_filter = "te.fk_soc = '".$user->socid."'";
  101. }
  102. $head = ticket_prepare_head($object);
  103. print dol_get_fiche_head($head, 'tabTicketDocument', $langs->trans("Ticket"), 0, 'ticket');
  104. $morehtmlref = '<div class="refidno">';
  105. $morehtmlref .= $object->subject;
  106. // Author
  107. if ($object->fk_user_create > 0) {
  108. $morehtmlref .= '<br>'.$langs->trans("CreatedBy").' : ';
  109. $langs->load("users");
  110. $fuser = new User($db);
  111. $fuser->fetch($object->fk_user_create);
  112. $morehtmlref .= $fuser->getNomUrl(-1);
  113. }
  114. if (!empty($object->origin_email)) {
  115. $morehtmlref .= '<br>'.$langs->trans("CreatedBy").' : ';
  116. $morehtmlref .= $object->origin_email.' <small>('.$langs->trans("TicketEmailOriginIssuer").')</small>';
  117. }
  118. // Thirdparty
  119. if (!empty($conf->societe->enabled)) {
  120. $morehtmlref .= '<br>'.$langs->trans('ThirdParty');
  121. /*if ($action != 'editcustomer' && $object->fk_statut < 8 && !$user->socid && $user->rights->ticket->write) {
  122. $morehtmlref.='<a class="editfielda" href="' . $url_page_current . '?action=editcustomer&token='.newToken().'&track_id=' . $object->track_id . '">' . img_edit($langs->transnoentitiesnoconv('Edit'), 1) . '</a>';
  123. }*/
  124. $morehtmlref .= ' : ';
  125. if ($action == 'editcustomer') {
  126. $morehtmlref .= $form->form_thirdparty($url_page_current.'?track_id='.$object->track_id, $object->socid, 'editcustomer', '', 1, 0, 0, array(), 1);
  127. } else {
  128. $morehtmlref .= $form->form_thirdparty($url_page_current.'?track_id='.$object->track_id, $object->socid, 'none', '', 1, 0, 0, array(), 1);
  129. }
  130. }
  131. // Project
  132. if (!empty($conf->projet->enabled)) {
  133. $langs->load("projects");
  134. $morehtmlref .= '<br>'.$langs->trans('Project').' ';
  135. if ($user->rights->ticket->write) {
  136. if ($action != 'classify') {
  137. //$morehtmlref.='<a class="editfielda" href="' . $_SERVER['PHP_SELF'] . '?action=classify&token='.newToken().'&id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a>';
  138. $morehtmlref .= ' : ';
  139. }
  140. if ($action == 'classify') {
  141. //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
  142. $morehtmlref .= '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
  143. $morehtmlref .= '<input type="hidden" name="action" value="classin">';
  144. $morehtmlref .= '<input type="hidden" name="token" value="'.newToken().'">';
  145. $morehtmlref .= $formproject->select_projects($object->socid, $object->fk_project, 'projectid', 0, 0, 1, 0, 1, 0, 0, '', 1);
  146. $morehtmlref .= '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
  147. $morehtmlref .= '</form>';
  148. } else {
  149. $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1);
  150. }
  151. } else {
  152. if (!empty($object->fk_project)) {
  153. $proj = new Project($db);
  154. $proj->fetch($object->fk_project);
  155. $morehtmlref .= $proj->getNomUrl(1);
  156. } else {
  157. $morehtmlref .= '';
  158. }
  159. }
  160. }
  161. $morehtmlref .= '</div>';
  162. $linkback = '<a href="'.dol_buildpath('/ticket/list.php', 1).'"><strong>'.$langs->trans("BackToList").'</strong></a> ';
  163. dol_banner_tab($object, 'ref', $linkback, ($user->socid ? 0 : 1), 'ref', 'ref', $morehtmlref, '', 0, '', '', 1);
  164. print dol_get_fiche_end();
  165. // Build file list
  166. $filearray = dol_dir_list($upload_dir, "files", 0, '', '\.meta$', $sortfield, (strtolower($sortorder) == 'desc' ? SORT_DESC : SORT_ASC), 1);
  167. $totalsize = 0;
  168. foreach ($filearray as $key => $file) {
  169. $totalsize += $file['size'];
  170. }
  171. //$object->ref = $object->track_id; // For compatibility we use track ID for directory
  172. $modulepart = 'ticket';
  173. $permissiontoadd = $user->rights->ticket->write;
  174. $permtoedit = $user->rights->ticket->write;
  175. $param = '&id='.$object->id;
  176. include DOL_DOCUMENT_ROOT.'/core/tpl/document_actions_post_headers.tpl.php';
  177. } else {
  178. accessforbidden('', 0, 1);
  179. }
  180. // End of page
  181. llxFooter();
  182. $db->close();