dolibarr 21.0.0-beta
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
28//if (! defined('NOREQUIREUSER')) define('NOREQUIREUSER','1'); // Not disabled cause need to load personalized language
29//if (! defined('NOREQUIREDB')) define('NOREQUIREDB','1'); // Not disabled cause need to load personalized language
30//if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC','1');
31//if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN','1'); // Not disabled cause need to do translations
32/*
33if (!defined('NOCSRFCHECK')) {
34 define('NOCSRFCHECK', 1);
35}
36if (!defined('NOTOKENRENEWAL')) {
37 define('NOTOKENRENEWAL', 1);
38}
39*/
40//if (! defined('NOLOGIN')) define('NOLOGIN',1); // Not disabled cause need to load personalized language
41/*
42if (!defined('NOREQUIREMENU')) {
43 define('NOREQUIREMENU', 1);
44}
45*/
46//if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML',1);
47
48require_once '../main.inc.php';
49require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
58if (GETPOST('lang', 'aZ09')) {
59 $langs->setDefaultLang(GETPOST('lang', 'aZ09')); // If language was forced on URL by the main.inc.php
60}
61
62$langs->loadLangs(array("main", "other"));
63
64$action = GETPOST('action', 'aZ09');
65$modulepart = GETPOST('modulepart', 'aZ09');
66
67
68/*
69 * Actions
70 */
71
72if (getDolGlobalString('MAIN_USE_TOP_MENU_IMPORT_FILE') && !is_numeric(getDolGlobalString('MAIN_USE_TOP_MENU_IMPORT_FILE'))) {
73 $urlforuploadpage = getDolGlobalString('MAIN_USE_TOP_MENU_IMPORT_FILE');
74
75 header("Location: ".$urlforuploadpage);
76 exit(1);
77}
78
79if ($action == 'uploadfile') { // Test on permission not required here. Done later
80 $arrayobject = getElementProperties($modulepart);
81
82 $module = $arrayobject['module'];
83 $element = $arrayobject['element'];
84 $dir_output = $arrayobject['dir_output'];
85 $dir_temp = $arrayobject['dir_temp'];
86
87 $permlevel1 = $element;
88 if ($module == 'fournisseur') {
89 $permlevel1 = 'facture';
90 }
91
92 $permissiontoadd = $user->hasRight($module, $permlevel1, 'read');
93 $upload_dir = $dir_temp.'/import';
94 $forceFullTextIndexation = '1';
95
96 // Set $object so entry file will be linked to object.
97 // TODO
98
99 include DOL_DOCUMENT_ROOT.'/core/actions_linkedfiles.inc.php';
100}
101
102
103/*
104 * View
105 */
106
107$form = new Form($db);
108
109// Important: Following code is to avoid page request by browser and PHP CPU at each Dolibarr page access.
110if (empty($dolibarr_nocache) && GETPOSTINT('cache')) {
111 header('Cache-Control: max-age='.GETPOSTINT('cache').', public');
112 // For a .php, we must set an Expires to avoid to have it forced to an expired value by the web server
113 header('Expires: '.gmdate('D, d M Y H:i:s', dol_now('gmt') + GETPOSTINT('cache')).' GMT');
114 // HTTP/1.0
115 header('Pragma: token=public');
116} else {
117 // HTTP/1.0
118 header('Cache-Control: no-cache');
119}
120
121$title = $langs->trans("UploadFile");
122$help_url = '';
123
124// URL http://mydolibarr/core/search_page?dol_use_jmobile=1 can be used for tests
125$head = '<!-- Upload file -->'."\n"; // This is used by DoliDroid to know page is a search page
126$arrayofjs = array();
127$arrayofcss = array();
128
129llxHeader('', $title, $help_url, '', 0, 0, $arrayofjs, $arrayofcss, '', 'mod-upload page-card');
130//top_htmlhead($head, $title, 0, 0, $arrayofjs, $arrayofcss);
131
132print load_fiche_titre('', '', '', 0, '', '', '<h2>'.$title.'</h2>');
133
134
135// Instantiate hooks of thirdparty module
136$hookmanager->initHooks(array('uploadform'));
137
138// Define $uploadform
139$uploadform = '';
140
141
142$uploadform = '<div class="display-flex">';
143
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 .= $form->select_company(GETPOSTINT('socid'), 'socid', 'statut=0', $langs->transnoentitiesnoconv("Supplier"));
152
153 $uploadform .= '<br><br>
154 <small>('.$langs->trans("OrClickToSelectAFile").')</small>
155 </div>
156 </div>';
157}
158
159if (isModEnabled('salaries')) {
160 $langs->load("salaries");
161 $uploadform .= '
162 <div id="userpayroll" class="flex-item flex-item-uploadfile">'.img_picto('', 'salary', 'class="fa-2x"').'<br>
163 <div>'.$langs->trans("UserPaySlip").'<br>
164 <small>('.$langs->trans("OrClickToSelectAFile").')</small>
165 </div>
166 </div>';
167}
168
169$uploadform .= '</div>';
170
171
172// Execute hook printSearchForm
173$parameters = array('uploadform' => $uploadform);
174$reshook = $hookmanager->executeHooks('printUploadForm', $parameters); // Note that $action and $object may have been modified by some hooks
175if (empty($reshook)) {
176 $uploadform .= $hookmanager->resPrint;
177} else {
178 $uploadform = $hookmanager->resPrint;
179}
180
181$uploadform .= '<br>';
182
183
184// Show all forms
185print "\n";
186print "<!-- Begin UploadForm -->\n";
187print '<form id="uploadform" enctype="multipart/form-data" method="POST" action="'.$_SERVER["PHP_SELF"].'">';
188print '<input type="hidden" name="token" value="'.newToken().'">';
189print '<input type="hidden" name="action" value="uploadfile">';
190print '<input type="hidden" name="sendit" value="1">';
191print '<input type="hidden" name="modulepart" id="modulepart" value="">';
192
193print '<div class="center"><div class="center" style="padding: 30px;">';
194print '<style>.menu_titre { padding-top: 7px; }</style>';
195print '<div id="blockupload" class="center">'."\n";
196//print '<input name="filenamePDF" id="filenamePDF" type="hideobject">';
197print $uploadform;
198
199
200$accept = '.pdf, image';
201$disablemulti = 1;
202$perm = 1;
203$capture = 1;
204
205$maxfilesizearray = getMaxFileSizeArray();
206$max = $maxfilesizearray['max'];
207$maxmin = $maxfilesizearray['maxmin'];
208$maxphptoshow = $maxfilesizearray['maxphptoshow'];
209$maxphptoshowparam = $maxfilesizearray['maxphptoshowparam'];
210$out = '';
211if ($maxmin > 0) {
212 $out .= '<input type="hidden" name="MAX_FILE_SIZE" value="'.($maxmin * 1024).'">'; // MAX_FILE_SIZE must precede the field type=file
213}
214$out .= '<input class="hideobject" type="file" id="fileInput"';
215// @phpstan-ignore-next-line
216$out .= ((getDolGlobalString('MAIN_DISABLE_MULTIPLE_FILEUPLOAD') || $disablemulti) ? ' name="userfile"' : ' name="userfile[]" multiple');
217// @phpstan-ignore-next-line
218$out .= (!getDolGlobalString('MAIN_UPLOAD_DOC') || empty($perm) ? ' disabled' : '');
219// @phpstan-ignore-next-line
220$out .= (!empty($accept) ? ' accept="'.$accept.'"' : ' accept=""');
221// @phpstan-ignore-next-line
222$out .= (!empty($capture) ? ' capture="capture"' : '');
223$out .= '>';
224
225print $out;
226
227
228print "<script>
229$(document).ready(function() {
230 jQuery('#supplierinvoice').on('click', function(event) {
231 console.log('Click on link to open input file');
232 console.log(event);
233 $('#modulepart').val('invoice_supplier');
234 $('#fileInput').click();
235 });
236
237 jQuery('#userpayroll').on('click', function(event) {
238 console.log('Click on link to open input file');
239 console.log(event);
240 $('#modulepart').val('salary');
241 $('#fileInput').click();
242 });
243
244 jQuery('#search_socid').on('click', function(event) {
245 event.stopPropagation();
246 console.log('Avoid to open the input select');
247 });
248
249 jQuery('#fileInput').on('change', function() {
250 console.log('A file was selected, we submit the form');
251 $('#uploadform').submit();
252 });
253});
254</script>";
255
256print '</div>'."\n";
257print '</div></div>';
258
259print '</form>';
260print "\n<!-- End UploadForm -->\n";
261
262
263
264// End of page
265llxFooter();
266$db->close();
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:71
Class to manage generation of HTML components Only common components must be here.
llxFooter()
Footer empty.
Definition document.php:107
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)
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.
getMaxFileSizeArray()
Return the max allowed for file upload.