Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Ticket message file #31120

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions htdocs/langs/en_US/ticket.lang
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ TicketTimeToRead=Time elapsed before read
TicketTimeElapsedBeforeSince=Time elapsed before / since
TicketContacts=Contacts ticket
TicketDocumentsLinked=Documents linked to ticket
TicketDocumentsLinkedToMessages=Documents linked to ticket message
ConfirmReOpenTicket=Confirm reopen this ticket ?
TicketMessageMailIntroAutoNewPublicMessage=A new message was posted on the ticket with the subject %s:
TicketAssignedToYou=Ticket assigned
Expand Down
68 changes: 54 additions & 14 deletions htdocs/ticket/document.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
require_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
require_once DOL_DOCUMENT_ROOT."/core/lib/company.lib.php";
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php';
if (isModEnabled('project')) {
include_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
include_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
Expand Down Expand Up @@ -74,8 +75,16 @@
$object = new Ticket($db);
$result = $object->fetch($id, $ref, $track_id);

if ($result < 0) {
$res = 0;
$objectMsg = new ActionComm($db);
if (GETPOSTISSET("urlfile") && dirname(GETPOST('urlfile', 'alpha', 0, null, null, 1)) != $object->ref) {
$res = $objectMsg->fetch(0, dirname(GETPOST('urlfile', 'alpha', 0, null, null, 1)));
}

if ($result < 0 || $res < 0) {
setEventMessages($object->error, $object->errors, 'errors');
} elseif ($res > 0) {
$upload_dir = $conf->agenda->dir_output.'/'.dol_sanitizeFileName($objectMsg->ref);
} else {
$upload_dir = $conf->ticket->dir_output."/".dol_sanitizeFileName($object->ref);
}
Expand Down Expand Up @@ -209,14 +218,31 @@

print dol_get_fiche_end();

if (!empty($object->ref) && $object->ref != basename($upload_dir)) {
$upload_dir = $conf->ticket->dir_output."/".dol_sanitizeFileName($object->ref);
}
// Build file list
$filearray = dol_dir_list($upload_dir, "files", 0, '', '\.meta$', $sortfield, (strtolower($sortorder) == 'desc' ? SORT_DESC : SORT_ASC), 1);

$totalsize = 0;
foreach ($filearray as $key => $file) {
$totalsize += $file['size'];
}

//$object->ref = $object->track_id; // For compatibility we use track ID for directory
$modulepart = 'ticket';
$permissiontoadd = $user->rights->ticket->write;
$permtoedit = $user->rights->ticket->write;
$param = '&id='.$object->id;

include DOL_DOCUMENT_ROOT.'/core/tpl/document_actions_post_headers.tpl.php';

// same as above for every messages
$sql = 'SELECT id FROM '.MAIN_DB_PREFIX.'actioncomm';
$sql .= " WHERE fk_element = ".(int) $object->id." AND elementtype = 'ticket'";
$resql = $db->query($sql);
if ($resql) {
$file_msg_array = array();
$filearray = array();
$numrows = $db->num_rows($resql);
for ($i=0; $i < $numrows; $i++) {
$upload_msg_dir = $conf->agenda->dir_output.'/'.$db->fetch_row($resql)[0];
Expand All @@ -226,29 +252,43 @@
foreach ($file_msg as $key => $file) {
$file_msg[$key]['modulepart'] = 'actions';
$file_msg[$key]['relativepath'] = $file['level1name'].'/'; // directory without file name
$file_msg[$key]['permtoedit'] = 0;
$file_msg[$key]['permonobject'] = 0;
$file_msg[$key]['permtoedit'] = $permtoedit;
$file_msg[$key]['permonobject'] = $permtoedit;
}
$file_msg_array = array_merge($file_msg, $file_msg_array);
$filearray = array_merge($file_msg, $filearray);
}
}
if (count($file_msg_array)) {
$filearray = array_merge($filearray, $file_msg_array);
}
}

$totalsize = 0;
foreach ($filearray as $key => $file) {
$totalsize += $file['size'];
}

//$object->ref = $object->track_id; // For compatibility we use track ID for directory
$modulepart = 'ticket';
$permissiontoadd = $user->hasRight('ticket', 'write');
$permtoedit = $user->hasRight('ticket', 'write');
$param = '&id='.$object->id;

include DOL_DOCUMENT_ROOT.'/core/tpl/document_actions_post_headers.tpl.php';
$formfile = new FormFile($db);

// List of document
$formfile->list_of_documents(
$filearray,
null,
'actions',
$param,
0,
'', // relative path with no file. For example "0/1"
$user->rights->ticket->write,
0,
'',
0,
$langs->trans("TicketDocumentsLinkedToMessages"),
'',
0,
$user->rights->ticket->write,
$upload_dir,
$sortfield,
$sortorder,
1
);
} else {
accessforbidden('', 0, 1);
}
Expand Down