document.php 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  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. $fuser = new User($db);
  110. $fuser->fetch($object->fk_user_create);
  111. $morehtmlref .= $fuser->getNomUrl(-1);
  112. } elseif (!empty($object->email_msgid)) {
  113. $morehtmlref .= '<br>'.$langs->trans("CreatedBy").' : ';
  114. $morehtmlref .= img_picto('', 'email', 'class="paddingrightonly"');
  115. $morehtmlref .= dol_escape_htmltag($object->origin_email).' <small class="hideonsmartphone opacitymedium">('.$form->textwithpicto($langs->trans("CreatedByEmailCollector"), $langs->trans("EmailMsgID").': '.$object->email_msgid).')</small>';
  116. } elseif (!empty($object->origin_email)) {
  117. $morehtmlref .= '<br>'.$langs->trans("CreatedBy").' : ';
  118. $morehtmlref .= img_picto('', 'email', 'class="paddingrightonly"');
  119. $morehtmlref .= dol_escape_htmltag($object->origin_email).' <small class="hideonsmartphone opacitymedium">('.$langs->trans("CreatedByPublicPortal").')</small>';
  120. }
  121. // Thirdparty
  122. if (isModEnabled('societe')) {
  123. $morehtmlref .= '<br>'.$langs->trans('ThirdParty');
  124. /*if ($action != 'editcustomer' && $object->fk_statut < 8 && !$user->socid && $user->rights->ticket->write) {
  125. $morehtmlref.='<a class="editfielda" href="' . $url_page_current . '?action=editcustomer&token='.newToken().'&track_id=' . $object->track_id . '">' . img_edit($langs->transnoentitiesnoconv('Edit'), 1) . '</a>';
  126. }*/
  127. $morehtmlref .= ' : ';
  128. if ($action == 'editcustomer') {
  129. $morehtmlref .= $form->form_thirdparty($url_page_current.'?track_id='.$object->track_id, $object->socid, 'editcustomer', '', 1, 0, 0, array(), 1);
  130. } else {
  131. $morehtmlref .= $form->form_thirdparty($url_page_current.'?track_id='.$object->track_id, $object->socid, 'none', '', 1, 0, 0, array(), 1);
  132. }
  133. }
  134. // Project
  135. if (isModEnabled('project')) {
  136. $langs->load("projects");
  137. $morehtmlref .= '<br>'.$langs->trans('Project').' ';
  138. if ($user->rights->ticket->write) {
  139. if ($action != 'classify') {
  140. //$morehtmlref.='<a class="editfielda" href="' . $_SERVER['PHP_SELF'] . '?action=classify&token='.newToken().'&id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a>';
  141. $morehtmlref .= ' : ';
  142. }
  143. if ($action == 'classify') {
  144. //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
  145. $morehtmlref .= '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
  146. $morehtmlref .= '<input type="hidden" name="action" value="classin">';
  147. $morehtmlref .= '<input type="hidden" name="token" value="'.newToken().'">';
  148. $morehtmlref .= $formproject->select_projects($object->socid, $object->fk_project, 'projectid', 0, 0, 1, 0, 1, 0, 0, '', 1);
  149. $morehtmlref .= '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
  150. $morehtmlref .= '</form>';
  151. } else {
  152. $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1);
  153. }
  154. } else {
  155. if (!empty($object->fk_project)) {
  156. $proj = new Project($db);
  157. $proj->fetch($object->fk_project);
  158. $morehtmlref .= $proj->getNomUrl(1);
  159. } else {
  160. $morehtmlref .= '';
  161. }
  162. }
  163. }
  164. $morehtmlref .= '</div>';
  165. $linkback = '<a href="'.dol_buildpath('/ticket/list.php', 1).'"><strong>'.$langs->trans("BackToList").'</strong></a> ';
  166. dol_banner_tab($object, 'ref', $linkback, ($user->socid ? 0 : 1), 'ref', 'ref', $morehtmlref, '', 0, '', '', 1);
  167. print dol_get_fiche_end();
  168. // Build file list
  169. $filearray = dol_dir_list($upload_dir, "files", 0, '', '\.meta$', $sortfield, (strtolower($sortorder) == 'desc' ? SORT_DESC : SORT_ASC), 1);
  170. $totalsize = 0;
  171. foreach ($filearray as $key => $file) {
  172. $totalsize += $file['size'];
  173. }
  174. //$object->ref = $object->track_id; // For compatibility we use track ID for directory
  175. $modulepart = 'ticket';
  176. $permissiontoadd = $user->rights->ticket->write;
  177. $permtoedit = $user->rights->ticket->write;
  178. $param = '&id='.$object->id;
  179. include DOL_DOCUMENT_ROOT.'/core/tpl/document_actions_post_headers.tpl.php';
  180. } else {
  181. accessforbidden('', 0, 1);
  182. }
  183. // End of page
  184. llxFooter();
  185. $db->close();