document.php 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  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. // Load Dolibarr environment
  27. require '../main.inc.php';
  28. require_once DOL_DOCUMENT_ROOT.'/core/lib/ticket.lib.php';
  29. require_once DOL_DOCUMENT_ROOT.'/ticket/class/ticket.class.php';
  30. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  31. require_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
  32. require_once DOL_DOCUMENT_ROOT."/core/lib/company.lib.php";
  33. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  34. if (isModEnabled('project')) {
  35. include_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
  36. include_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
  37. include_once DOL_DOCUMENT_ROOT.'/core/lib/project.lib.php';
  38. }
  39. // Load translation files required by the page
  40. $langs->loadLangs(array("companies", "other", "ticket", "mails"));
  41. $id = GETPOST('id', 'int');
  42. $socid = GETPOST('socid', 'int');
  43. $ref = GETPOST('ref', 'alpha');
  44. $track_id = GETPOST('track_id', 'alpha');
  45. $action = GETPOST('action', 'alpha');
  46. $confirm = GETPOST('confirm', 'alpha');
  47. // Store current page url
  48. $url_page_current = DOL_URL_ROOT.'/ticket/document.php';
  49. // Get parameters
  50. $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
  51. $sortfield = GETPOST('sortfield', 'aZ09comma');
  52. $sortorder = GETPOST('sortorder', 'aZ09comma');
  53. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  54. if (empty($page) || $page == -1) {
  55. $page = 0;
  56. } // If $page is not defined, or '' or -1
  57. $offset = $limit * $page;
  58. $pageprev = $page - 1;
  59. $pagenext = $page + 1;
  60. if (!$sortorder) {
  61. $sortorder = "ASC";
  62. }
  63. if (!$sortfield) {
  64. $sortfield = "position_name";
  65. }
  66. $object = new Ticket($db);
  67. $result = $object->fetch($id, $ref, $track_id);
  68. if ($result < 0) {
  69. setEventMessages($object->error, $object->errors, 'errors');
  70. } else {
  71. $upload_dir = $conf->ticket->dir_output."/".dol_sanitizeFileName($object->ref);
  72. }
  73. // Security check - Protection if external user
  74. $result = restrictedArea($user, 'ticket', $object->id);
  75. // restrict access for externals users
  76. if ($user->socid > 0 && ($object->fk_soc != $user->socid)) {
  77. accessforbidden();
  78. }
  79. // or for unauthorized internals users
  80. if (!$user->socid && getDolGlobalString('TICKET_LIMIT_VIEW_ASSIGNED_ONLY') && $object->fk_user_assign != $user->id && !$user->hasRight('ticket', 'manage')) {
  81. accessforbidden();
  82. }
  83. $permissiontoadd = $user->rights->ticket->write; // Used by the include of actions_addupdatedelete.inc.php and actions_linkedfiles
  84. /*
  85. * Actions
  86. */
  87. include DOL_DOCUMENT_ROOT.'/core/actions_linkedfiles.inc.php';
  88. // Set parent company
  89. if ($action == 'set_thirdparty' && $user->hasRight('ticket', 'write')) {
  90. if ($object->fetch(GETPOST('id', 'int'), '', GETPOST('track_id', 'alpha')) >= 0) {
  91. $result = $object->setCustomer(GETPOST('editcustomer', 'int'));
  92. $url = $_SERVER["PHP_SELF"].'?track_id='.GETPOST('track_id', 'alpha');
  93. header("Location: ".$url);
  94. exit();
  95. }
  96. }
  97. /*
  98. * View
  99. */
  100. $form = new Form($db);
  101. $help_url = '';
  102. llxHeader('', $langs->trans("TicketDocumentsLinked").' - '.$langs->trans("Files"), $help_url);
  103. if ($object->id) {
  104. /*
  105. * Show tabs
  106. */
  107. if ($socid > 0) {
  108. $object->fetch_thirdparty();
  109. $head = societe_prepare_head($object->thirdparty);
  110. print dol_get_fiche_head($head, 'ticket', $langs->trans("ThirdParty"), 0, 'company');
  111. dol_banner_tab($object->thirdparty, 'socid', '', ($user->socid ? 0 : 1), 'rowid', 'nom');
  112. print dol_get_fiche_end();
  113. }
  114. if (!$user->socid && getDolGlobalString('TICKET_LIMIT_VIEW_ASSIGNED_ONLY')) {
  115. $object->next_prev_filter = "te.fk_user_assign = ".((int) $user->id);
  116. } elseif ($user->socid > 0) {
  117. $object->next_prev_filter = "te.fk_soc = ".((int) $user->socid);
  118. }
  119. $head = ticket_prepare_head($object);
  120. print dol_get_fiche_head($head, 'tabTicketDocument', $langs->trans("Ticket"), 0, 'ticket');
  121. $morehtmlref = '<div class="refidno">';
  122. $morehtmlref .= $object->subject;
  123. // Author
  124. if ($object->fk_user_create > 0) {
  125. $morehtmlref .= '<br>'.$langs->trans("CreatedBy").' : ';
  126. $fuser = new User($db);
  127. $fuser->fetch($object->fk_user_create);
  128. $morehtmlref .= $fuser->getNomUrl(-1);
  129. } elseif (!empty($object->email_msgid)) {
  130. $morehtmlref .= '<br>'.$langs->trans("CreatedBy").' : ';
  131. $morehtmlref .= img_picto('', 'email', 'class="paddingrightonly"');
  132. $morehtmlref .= dol_escape_htmltag($object->origin_email).' <small class="hideonsmartphone opacitymedium">('.$form->textwithpicto($langs->trans("CreatedByEmailCollector"), $langs->trans("EmailMsgID").': '.$object->email_msgid).')</small>';
  133. } elseif (!empty($object->origin_email)) {
  134. $morehtmlref .= '<br>'.$langs->trans("CreatedBy").' : ';
  135. $morehtmlref .= img_picto('', 'email', 'class="paddingrightonly"');
  136. $morehtmlref .= dol_escape_htmltag($object->origin_email).' <small class="hideonsmartphone opacitymedium">('.$langs->trans("CreatedByPublicPortal").')</small>';
  137. }
  138. // Thirdparty
  139. if (isModEnabled("societe")) {
  140. $morehtmlref .= '<br>';
  141. $morehtmlref .= img_picto($langs->trans("ThirdParty"), 'company', 'class="pictofixedwidth"');
  142. if ($action != 'editcustomer' && $permissiontoadd) {
  143. $morehtmlref .= '<a class="editfielda" href="'.$url_page_current.'?action=editcustomer&token='.newToken().'&track_id='.$object->track_id.'">'.img_edit($langs->transnoentitiesnoconv('SetThirdParty'), 0).'</a> ';
  144. }
  145. $morehtmlref .= $form->form_thirdparty($url_page_current.'?track_id='.$object->track_id, $object->socid, $action == 'editcustomer' ? 'editcustomer' : 'none', '', 1, 0, 0, array(), 1);
  146. }
  147. // Project
  148. if (isModEnabled('project')) {
  149. $langs->load("projects");
  150. if (0) {
  151. $morehtmlref .= '<br>';
  152. $morehtmlref .= img_picto($langs->trans("Project"), 'project', 'class="pictofixedwidth"');
  153. if ($action != 'classify') {
  154. $morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> ';
  155. }
  156. $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, ($action == 'classify' ? 'projectid' : 'none'), 0, 0, 0, 1, '', 'maxwidth300');
  157. } else {
  158. if (!empty($object->fk_project)) {
  159. $morehtmlref .= '<br>';
  160. $proj = new Project($db);
  161. $proj->fetch($object->fk_project);
  162. $morehtmlref .= $proj->getNomUrl(1);
  163. if ($proj->title) {
  164. $morehtmlref .= '<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).'</span>';
  165. }
  166. }
  167. }
  168. }
  169. $morehtmlref .= '</div>';
  170. $linkback = '<a href="'.dol_buildpath('/ticket/list.php', 1).'"><strong>'.$langs->trans("BackToList").'</strong></a> ';
  171. dol_banner_tab($object, 'ref', $linkback, ($user->socid ? 0 : 1), 'ref', 'ref', $morehtmlref, '', 0, '', '', 1);
  172. print dol_get_fiche_end();
  173. // Build file list
  174. $filearray = dol_dir_list($upload_dir, "files", 0, '', '\.meta$', $sortfield, (strtolower($sortorder) == 'desc' ? SORT_DESC : SORT_ASC), 1);
  175. $totalsize = 0;
  176. foreach ($filearray as $key => $file) {
  177. $totalsize += $file['size'];
  178. }
  179. //$object->ref = $object->track_id; // For compatibility we use track ID for directory
  180. $modulepart = 'ticket';
  181. $permissiontoadd = $user->rights->ticket->write;
  182. $permtoedit = $user->rights->ticket->write;
  183. $param = '&id='.$object->id;
  184. include DOL_DOCUMENT_ROOT.'/core/tpl/document_actions_post_headers.tpl.php';
  185. } else {
  186. accessforbidden('', 0, 1);
  187. }
  188. // End of page
  189. llxFooter();
  190. $db->close();