/
expensereport_linktofile.tpl.php
158 lines (141 loc) · 7.27 KB
/
expensereport_linktofile.tpl.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
<?php
/* Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
*/
// Add line to select existing file
if (!getDolGlobalString('EXPENSEREPORT_DISABLE_ATTACHMENT_ON_LINES')) {
print '<!-- expensereport_linktofile.tpl.php -->'."\n";
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php';
$upload_dir = $conf->expensereport->dir_output."/".dol_sanitizeFileName($object->ref);
$arrayoffiles = dol_dir_list($upload_dir, 'files', 0, '', '(\.meta|_preview.*\.png|'.preg_quote(dol_sanitizeFileName($object->ref.'.pdf'), '/').')$');
$nbFiles = count($arrayoffiles);
$nbLinks = Link::count($db, $object->element, $object->id);
if ($nbFiles > 0) {
print '<tr class="trattachnewfilenow'.(empty($tredited) ? ' oddeven nohover' : ' '.$tredited).'"'.(!GETPOSTISSET('sendit') && !getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER') ? ' style="display: none"' : '').'>';
// Num line
if ($action == 'editline') {
print '<td></td>';
}
// Select image section
print '<td colspan="'.($action == 'editline' ? $colspan - 1 : $colspan).'">';
//print '<span class="opacitymedium">'.$langs->trans("AttachTheNewLineToTheDocument").'</span><br>';
$modulepart = 'expensereport';
$maxheightmini = 48;
$relativepath = (!empty($object->ref) ? dol_sanitizeFileName($object->ref) : '').'/';
$filei = 0;
// Loop on each attached file
foreach ($arrayoffiles as $file) {
$urlforhref = array();
$filei++;
print '<div class="inline-block margintoponly marginleftonly marginrightonly center valigntop">';
$fileinfo = pathinfo($file['fullname']);
if (image_format_supported($file['name']) > 0) {
$minifile = getImageFileNameForSize($file['name'], '_mini'); // For new thumbs using same ext (in lower case however) than original
//print $file['path'].'/'.$minifile.'<br>';
$urlforhref = getAdvancedPreviewUrl($modulepart, $relativepath.$fileinfo['filename'].'.'.strtolower($fileinfo['extension']), 1, '&entity='.(empty($object->entity) ? $conf->entity : $object->entity));
if (empty($urlforhref)) {
$urlforhref = DOL_URL_ROOT.'/viewimage.php?modulepart='.$modulepart.'&entity='.(empty($object->entity) ? $conf->entity : $object->entity).'&file='.urlencode($file['relativename'].'.'.strtolower($fileinfo['extension']));
print '<a href="'.$urlforhref.'" class="aphoto" target="_blank" rel="noopener noreferrer">';
} else {
print '<a href="'.$urlforhref['url'].'" class="'.$urlforhref['css'].'" target="'.$urlforhref['target'].'" mime="'.$urlforhref['mime'].'">';
}
print '<div class="photoref backgroundblank">';
print '<img class="photoexpensereport photorefcenter" height="'.$maxheightmini.'" src="'.DOL_URL_ROOT.'/viewimage.php?modulepart='.$modulepart.'&entity='.(empty($object->entity) ? $conf->entity : $object->entity).'&file='.urlencode($relativepath.$minifile).'" title="">';
print '</div>';
print '</a>';
} else {
$error = 0;
$thumbshown = '';
if (preg_match('/\.pdf$/i', $file['name'])) {
$urlforhref = getAdvancedPreviewUrl($modulepart, $relativepath.$fileinfo['filename'].'.'.strtolower($fileinfo['extension']), 1, '&entity='.(empty($object->entity) ? $conf->entity : $object->entity));
$filepdf = $conf->expensereport->dir_output.'/'.$relativepath.$file['name'];
$fileimage = $conf->expensereport->dir_output.'/'.$relativepath.$file['name'].'_preview.png';
$relativepathimage = $relativepath.$file['name'].'_preview.png';
$pdfexists = file_exists($filepdf);
if ($pdfexists) {
// Conversion du PDF en image png si fichier png non existent
if (!file_exists($fileimage) || (filemtime($fileimage) < filemtime($filepdf))) {
if (!getDolGlobalString('MAIN_DISABLE_PDF_THUMBS')) { // If you experience trouble with pdf thumb generation and imagick, you can disable here.
include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
$ret = dol_convert_file($filepdf, 'png', $fileimage, '0'); // Convert first page of PDF into a file _preview.png
if ($ret < 0) {
$error++;
}
}
}
}
if ($pdfexists && !$error) {
$heightforphotref = 70;
if (!empty($conf->dol_optimize_smallscreen)) {
$heightforphotref = 60;
}
// If the preview file is found
if (file_exists($fileimage)) {
$thumbshown = '<img height="'.$heightforphotref.'" class="photo photowithmargin photowithborder" src="'.DOL_URL_ROOT.'/viewimage.php?modulepart=apercu'.urlencode($modulepart).'&file='.urlencode($relativepathimage).'">';
}
}
}
if (empty($urlforhref) || empty($thumbshown)) {
print '<span href="" class="aphoto" target="_blank" rel="noopener noreferrer">';
} else {
print '<a href="'.$urlforhref['url'].'" class="'.$urlforhref['css'].'" target="'.$urlforhref['target'].'" mime="'.$urlforhref['mime'].'">';
}
print '<div class="photoref backgroundblank">';
print $thumbshown ? $thumbshown : img_mime($minifile);
print '</div>';
if (empty($urlforhref) || empty($thumbshown)) {
print '</span>';
} else {
print '</a>';
}
}
print '<br>';
$checked = '';
//var_dump(GETPOST($file['relativename']));
//var_dump($file['relativename']);
//var_dump($_FILES['userfile']['name']);
// If a file was just uploaded, we check to preselect it
if (is_array($_FILES['userfile']) && is_array($_FILES['userfile']['name'])) {
foreach ($_FILES['userfile']['name'] as $tmpfile) {
if ($file['relativename'] == (GETPOST('savingdocmask', 'alpha') ? dol_sanitizeFileName($object->ref.'-') : '').$tmpfile) {
$checked = ' checked';
break;
} elseif ($file['relativename'] && in_array($file['relativename'], GETPOST('attachfile', 'array'))) {
$checked = ' checked';
break;
}
}
}
// If we edit a line already linked, then $filenamelinked is defined to the filename (without path) of linked file
if (!empty($filenamelinked) && $filenamelinked == $file['relativename']) {
$checked = ' checked';
}
print '<div class="margintoponly minwidth150 maxwidth150 divoverflow"><input type="checkbox"'.$checked.' id="radio'.$filei.'" name="attachfile[]" class="checkboxattachfile valignmiddle" value="'.$file['relativename'].'">';
print '<label class="wordbreak checkboxattachfilelabel paddingrightonly valignmiddle" for="radio'.$filei.'" title="'.dol_escape_htmltag($file['relativename']).'">'.$file['relativename'].'</label>';
print '</div>';
print '</div>';
}
print '<script>';
print '$(document).ready(function() {';
print "$('.checkboxattachfile').on('change', function() { $('.checkboxattachfile').not(this).prop('checked', false); });";
print '});';
print '</script>';
print '</td></tr>';
} else {
if (empty($tredited)) {
$css = 'oddeven nohover trattachnewfilenow';
$newcolspan = $colspan;
} else {
$css = 'trattachnewfilenow tredited';
$newcolspan = $colspan - 1;
}
print '<tr class="'.$css.'"'.(!GETPOSTISSET('sendit') && !getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER') ? ' style="display: none"' : '').'>';
if (!empty($tredited)) {
print '<td></td>';
}
print '<td colspan="'.($newcolspan).'">';
print '<span class="opacitymedium">'.$langs->trans("NoFilesUploadedYet").'</span>';
print '</td></tr>';
}
}