dolibarr 22.0.5
upload_page.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2005-2017 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
4 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
5 *
6 * This file is a modified version of datepicker.php from phpBSM to fix some
7 * bugs, to add new features and to dramatically increase speed.
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 3 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <https://www.gnu.org/licenses/>.
21 */
22
28require_once '../main.inc.php';
29require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
30require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
31
40if (GETPOST('lang', 'aZ09')) {
41 $langs->setDefaultLang(GETPOST('lang', 'aZ09')); // If language was forced on URL by the main.inc.php
42}
43
44$langs->loadLangs(array("main", "other"));
45
46$action = GETPOST('action', 'aZ09');
47$modulepart = GETPOST('modulepart', 'aZ09');
48
49$upload_dir = $conf->admin->dir_temp.'/import';
50
51// Delete the temporary files that are used when uploading files
52dol_delete_file($upload_dir.'/upload_page-by'.$user->id.'-*');
53
54
55/*
56 * Actions
57 */
58
59if (getDolGlobalString('MAIN_USE_TOP_MENU_IMPORT_FILE') && !is_numeric(getDolGlobalString('MAIN_USE_TOP_MENU_IMPORT_FILE'))) {
60 $urlforuploadpage = getDolGlobalString('MAIN_USE_TOP_MENU_IMPORT_FILE');
61
62 header("Location: ".$urlforuploadpage);
63 exit(1);
64}
65
66if ($action == 'uploadfile') { // Test on permission not required here. Done later
67 $arrayobject = getElementProperties($modulepart);
68
69 $module = $arrayobject['module'];
70 $element = $arrayobject['element'];
71 $dir_output = $arrayobject['dir_output'];
72 $dir_temp = $arrayobject['dir_temp'];
73
74 $permlevel1 = 'read';
75 $permlevel2 = '';
76 $fileprefix = 'unknown';
77 if (in_array($modulepart, array('fournisseur', 'invoice_supplier'))) {
78 $permlevel1 = 'facture';
79 $permlevel2 = 'read';
80 $fileprefix = 'upload_page-by'.$user->id.'-'.$modulepart.'-'.(GETPOSTINT('socid') > 0 ? GETPOSTINT('socid') : 0).'-'.(GETPOSTINT('search_prodid') > 0 ? GETPOSTINT('search_prodid') : 0);
81 } elseif ($modulepart == 'expensereport') {
82 $fileprefix = 'upload_page-by'.$user->id.'-'.$modulepart.'-'.(GETPOSTINT('userexpensereportid') > 0 ? GETPOSTINT('userexpensereportid') : 0);
83 } elseif ($modulepart == 'salaries') {
84 $fileprefix = 'upload_page-by'.$user->id.'-'.$modulepart.'-'.(GETPOSTINT('usersalaryid') > 0 ? GETPOSTINT('usersalaryid') : 0);
85 }
86
87 if ($permlevel2) {
88 $permissiontoadd = $user->hasRight($module, $permlevel1, $permlevel2);
89 } else {
90 $permissiontoadd = $user->hasRight($module, $permlevel1);
91 }
92 $forceFullTextIndexation = '1';
93
94 $_FILES['userfile']['name'] = $fileprefix.'-'.$_FILES['userfile']['name'];
95
96 include DOL_DOCUMENT_ROOT.'/core/actions_linkedfiles.inc.php';
97
98 // Then ...
99}
100
101
102/*
103 * View
104 */
105
106$form = new Form($db);
107
108// Important: Following code is to avoid page request by browser and PHP CPU at each Dolibarr page access.
109if (empty($dolibarr_nocache) && GETPOSTINT('cache')) {
110 header('Cache-Control: max-age='.GETPOSTINT('cache').', public');
111 // For a .php, we must set an Expires to avoid to have it forced to an expired value by the web server
112 header('Expires: '.gmdate('D, d M Y H:i:s', dol_now('gmt') + GETPOSTINT('cache')).' GMT');
113 // HTTP/1.0
114 header('Pragma: token=public');
115} else {
116 // HTTP/1.0
117 header('Cache-Control: no-cache');
118}
119
120$title = $langs->trans("UploadFile");
121$help_url = '';
122
123// URL http://mydolibarr/core/search_page?dol_use_jmobile=1 can be used for tests
124$head = '<!-- Upload file -->'."\n"; // This is used by DoliDroid to know page is a search page
125$arrayofjs = array();
126$arrayofcss = array();
127
128llxHeader('', $title, $help_url, '', 0, 0, $arrayofjs, $arrayofcss, '', 'mod-upload page-card');
129//top_htmlhead($head, $title, 0, 0, $arrayofjs, $arrayofcss);
130
131print load_fiche_titre('', '', '', 0, '', '', '<h2>'.$title.'</h2>');
132
133
134// Instantiate hooks of thirdparty module
135$hookmanager->initHooks(array('uploadform'));
136
137// Define $uploadform
138$uploadform = '';
139
140
141$uploadform = '<div class="display-flex">';
142
143// Form to upload a supplier invoice
144if (isModEnabled('supplier_invoice')) {
145 $langs->load("bills");
146 $uploadform .= '
147 <div id="supplierinvoice" class="flex-item flex-item-uploadfile">'.img_picto('', 'bill', 'class="fa-2x"').'<br>
148 <div>'.$langs->trans("SupplierInvoice").'<br><br>';
149
150 $uploadform .= img_picto('', 'company', 'class="pictofixedwidth"');
151 //$uploadform .= '<span class="disableautoopen">';
152 $uploadform .= $form->select_company(GETPOSTINT('socid'), 'socid', '(statut:=:0)', $langs->transnoentitiesnoconv("Supplier"), 0, 0, array(), 0, 'maxwidth200 disableautoopen');
153 //$uploadform .= '</span>';
154
155 $uploadform .= '<br>';
156
157 $uploadform .= img_picto('', 'product', 'class="pictofixedwidth"');
158 $prodid = GETPOSTINT('prodid');
159 $prodtext = $langs->trans("RefOrLabel");
160
161 //$uploadform .= '<span class="disableautoopen">';
162 //$uploadform .= $form->select_produits_fournisseurs(0, $prodid, 'prodid', '', 0, 0, 1, 2, $prodtext, 0, array(), GETPOSTINT('socid'), '1', 0, 'maxwidth200 disableautoopen', 0, '', null, 1);
163 $uploadform .= $form->select_produits_fournisseurs(0, $prodid, 'prodid', '', '', array(), 1, 1, 'maxwidth200 disableautoopen', $prodtext, 1);
164 //$uploadform .= '</span>';
165
166 $uploadform .= '<br>';
167
168 $uploadform .= '<br>
169 <small>('.$langs->trans("OrClickToSelectAFile").')</small>
170 </div>
171 </div>';
172}
173
174// Form to upload an expense report
175if (isModEnabled('expensereport')) {
176 $langs->load("expensereport");
177 $uploadform .= '
178 <div id="userexpensereport" class="flex-item flex-item-uploadfile">'.img_picto('', 'expensereport', 'class="fa-2x"').'<br>
179 <div>'.$langs->trans("ExpenseReport").'<br><br>';
180
181 $uploadform .= img_picto('', 'user', 'class="pictofixedwidth"');
182 //$uploadform .= '<span class="disableautoopen">';
183 $uploadform .= $form->select_dolusers(GETPOSTINT('userexpensereportid') > 0 ? GETPOSTINT('userexpensereportid') : $user->id, 'userexpensereportid', $langs->transnoentitiesnoconv("User"), null, 0, 'hierarchyme', '', '', 0, 0, '', 0, '', 'maxwidth200 disableautoopen', 1);
184 //$uploadform .= '</span>';
185
186 $uploadform .= '<br>';
187
188 $uploadform .= '<br>
189 <small>('.$langs->trans("OrClickToSelectAFile").')</small>
190 </div>
191 </div>';
192}
193
194
195// Form to upload a salary document
196if (isModEnabled('salaries')) {
197 $langs->load("salaries");
198 $uploadform .= '
199 <div id="userpayroll" class="flex-item flex-item-uploadfile">'.img_picto('', 'salary', 'class="fa-2x"').'<br>
200 <div>'.$langs->trans("UserPaySlip").'<br><br>';
201
202
203 $uploadform .= img_picto('', 'user', 'class="pictofixedwidth"');
204 //$uploadform .= '<span class="disableautoopen">';
205 $uploadform .= $form->select_dolusers(GETPOSTINT('usersalaryid') > 0 ? GETPOSTINT('usersalaryid') : $user->id, 'usersalaryid', $langs->transnoentitiesnoconv("Employee"), null, 0, 'hierarchyme', '', '', 0, 0, '', 0, '', 'maxwidth200 disableautoopen', 1);
206 //$uploadform .= '</span>';
207
208 $uploadform .= '<br>';
209
210 $uploadform .= '<br>
211 <small>('.$langs->trans("OrClickToSelectAFile").')</small>
212 </div>
213 </div>';
214}
215
216
217
218$uploadform .= '</div>';
219
220
221// Execute hook printSearchForm
222$parameters = array('uploadform' => $uploadform);
223$reshook = $hookmanager->executeHooks('printUploadForm', $parameters); // Note that $action and $object may have been modified by some hooks
224if (empty($reshook)) {
225 $uploadform .= $hookmanager->resPrint;
226} else {
227 $uploadform = $hookmanager->resPrint;
228}
229
230$uploadform .= '<br>';
231
232
233// Show all forms
234print "\n";
235print "<!-- Begin UploadForm -->\n";
236print '<form id="uploadform" enctype="multipart/form-data" method="POST" action="'.$_SERVER["PHP_SELF"].'">';
237print '<input type="hidden" name="token" value="'.newToken().'">';
238print '<input type="hidden" name="action" value="uploadfile">';
239print '<input type="hidden" name="sendit" value="1">';
240print '<input type="hidden" name="modulepart" id="modulepart" value="">';
241
242print '<div class="center"><div class="center" style="padding: 30px;">';
243print '<style>.menu_titre { padding-top: 7px; }</style>';
244print '<div id="blockupload" class="center">'."\n";
245//print '<input name="filenamePDF" id="filenamePDF" type="hideobject">';
246print $uploadform;
247
248
249$accept = '.pdf, image';
250$disablemulti = 1;
251$perm = 1;
252$capture = 1;
253
254$maxfilesizearray = getMaxFileSizeArray();
255$max = $maxfilesizearray['max'];
256$maxmin = $maxfilesizearray['maxmin'];
257$maxphptoshow = $maxfilesizearray['maxphptoshow'];
258$maxphptoshowparam = $maxfilesizearray['maxphptoshowparam'];
259$out = '';
260if ($maxmin > 0) {
261 $out .= '<input type="hidden" name="MAX_FILE_SIZE" value="'.($maxmin * 1024).'">'; // MAX_FILE_SIZE must precede the field type=file
262}
263$out .= '<input class="hideobject" type="file" id="fileInput"';
264// @phpstan-ignore-next-line
265$out .= ((getDolGlobalString('MAIN_DISABLE_MULTIPLE_FILEUPLOAD') || $disablemulti) ? ' name="userfile"' : ' name="userfile[]" multiple');
266// @phpstan-ignore-next-line
267$out .= (!getDolGlobalString('MAIN_UPLOAD_DOC') || empty($perm) ? ' disabled' : '');
268// @phpstan-ignore-next-line
269$out .= (!empty($accept) ? ' accept="'.$accept.'"' : ' accept=""');
270// @phpstan-ignore-next-line
271$out .= (!empty($capture) ? ' capture="capture"' : '');
272$out .= '>';
273
274print $out;
275
276
277print "<script>
278$(document).ready(function() {
279 jQuery('#supplierinvoice:not(.disableautoopen)').on('click', function(event) {
280 console.log('Click on link supplierinvoice to open input file');
281 console.log(event);
282 if (!event.target.closest('.disableautoopen')) {
283 $('#modulepart').val('invoice_supplier');
284 $('#fileInput').click();
285 }
286 });
287
288 jQuery('#userexpensereport:not(.disableautoopen)').on('click', function(event) {
289 console.log('Click on link userexpensereport to open input file');
290 console.log(event);
291 if (!event.target.closest('.disableautoopen')) {
292 $('#modulepart').val('expensereport');
293 $('#fileInput').click();
294 }
295 });
296
297 jQuery('#userpayroll:not(.disableautoopen)').on('click', function(event) {
298 console.log('Click on link userpayroll to open input file');
299 console.log(event);
300 if (!event.target.closest('.disableautoopen')) {
301 $('#modulepart').val('salaries');
302 $('#fileInput').click();
303 }
304 });
305
306 jQuery('#fileInput').on('change', function(event) {
307 console.log(event);
308 console.log('A file was selected, we submit the form');
309 $('#uploadform').submit();
310 });
311});
312</script>";
313
314print '</div>'."\n";
315print '</div></div>';
316
317print '</form>';
318print "\n<!-- End UploadForm -->\n";
319
320
321
322// End of page
323llxFooter();
324$db->close();
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:73
Class to manage generation of HTML components Only common components must be here.
dol_delete_file($file, $disableglob=0, $nophperrors=0, $nohook=0, $object=null, $allowdotdot=false, $indexdatabase=1, $nolog=0)
Remove a file or several files with a mask.
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_now($mode='auto')
Return date for now.
getElementProperties($elementType)
Get an array with properties of an element.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
getMaxFileSizeArray()
Return the max allowed for file upload.