28require_once
'../main.inc.php';
36require_once DOL_DOCUMENT_ROOT.
'/core/class/html.form.class.php';
37require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
38require_once DOL_DOCUMENT_ROOT.
'/ai/class/ai.class.php';
42 $langs->setDefaultLang(
GETPOST(
'lang',
'aZ09'));
45$langs->loadLangs(array(
"main",
"other"));
47$action =
GETPOST(
'action',
'aZ09');
48$modulepart =
GETPOST(
'modulepart',
'aZ09');
51$upload_dir =
$conf->user->dir_temp.
'/import';
56$originalfilename = $file;
57$uid = $thiid = $pid = $erid = $salid = 0;
59if (preg_match(
'/-uid([\d+])/', $file, $reg)) {
61 $originalfilename = preg_replace(
'/-uid\d+/',
'', $originalfilename);
63if (preg_match(
'/-thiid([\d+])/', $file, $reg)) {
65 $originalfilename = preg_replace(
'/-thiid\d+/',
'', $originalfilename);
67if (preg_match(
'/-pid([\d+])/', $file, $reg)) {
69 $originalfilename = preg_replace(
'/-pid\d+/',
'', $originalfilename);
71if (preg_match(
'/-erid([\d+])/', $file, $reg)) {
73 $originalfilename = preg_replace(
'/-erid\d+/',
'', $originalfilename);
75if (preg_match(
'/-salid([\d+])/', $file, $reg)) {
77 $originalfilename = preg_replace(
'/-salid\d+/',
'', $originalfilename);
79$originalfilename = preg_replace(
'/^upload_page-[a-z_]+-/',
'', $originalfilename);
93 header(
"Location: ".$urlforuploadpage);
97if ($action ==
'uploadfile') {
99 print
'Error, modulepart param is empty';
104 $arrayobject = getElementProperties($modulepart);
106 $module = $arrayobject[
'module'];
107 $element = $arrayobject[
'element'];
108 $dir_output = $arrayobject[
'dir_output'];
109 $dir_temp = $arrayobject[
'dir_temp'];
111 $permlevel1 =
'read';
113 $fileprefix =
'unknown';
114 if (in_array($modulepart, array(
'fournisseur',
'invoice_supplier'))) {
115 $permlevel1 =
'facture';
116 $permlevel2 =
'read';
118 } elseif ($modulepart ==
'expensereport') {
119 $fileprefix =
'upload_page-'.$modulepart.
'-uid'.$user->id.
'-erid'.(
GETPOSTINT(
'userexpensereportid') > 0 ?
GETPOSTINT(
'userexpensereportid') : 0).
'-pid'.(
GETPOSTINT(
'search_prodid') > 0 ?
GETPOSTINT(
'search_prodid') : 0);
120 } elseif ($modulepart ==
'salaries') {
121 $fileprefix =
'upload_page-'.$modulepart.
'-uid'.$user->id.
'-salid'.(
GETPOSTINT(
'usersalaryid') > 0 ?
GETPOSTINT(
'usersalaryid') : 0);
125 $permissiontoadd = $user->hasRight($module, $permlevel1, $permlevel2);
127 $permissiontoadd = $user->hasRight($module, $permlevel1);
129 $forceFullTextIndexation =
'0';
132 if (!empty($_FILES[
'userfile'][
'name'])) {
133 $fullnewname = $fileprefix.
'-'.$_FILES[
'userfile'][
'name'];
134 $_FILES[
'userfile'][
'name'] = $fullnewname;
139 include DOL_DOCUMENT_ROOT.
'/core/actions_linkedfiles.inc.php';
144 header(
"Location: ".DOL_URL_ROOT.
'/core/ajax/ajaxuploadpage.php?file='.urlencode($fullnewname));
174$title = $langs->trans(
"UploadFile");
178$arrayofcss = array();
180llxHeader(
'', $title, $help_url,
'', 0, 0, $arrayofjs, $arrayofcss,
'',
'mod-upload page-card');
186$hookmanager->initHooks(array(
'uploadform'));
192$uploadform =
'<div class="display-flex">';
196 $langs->load(
"bills");
198 <div id="supplierinvoice" class="flex-item flex-item-uploadfile">'.img_picto(
'',
'bill',
'class="fa-2x"').
'<br>
199 <div>'.$langs->trans(
"SupplierInvoice").
'<br><br>';
201 $uploadform .=
img_picto(
'',
'company',
'class="pictofixedwidth"');
202 $uploadform .= $form->select_company(
GETPOSTINT(
'socid'),
'socid',
'(statut:=:0)', $langs->transnoentitiesnoconv(
"Supplier"), 0, 0, array(), 0,
'maxwidth200 disableautoopen');
204 $uploadform .=
'<br>';
207 $prodtext = $langs->trans(
"RefOrLabel");
210 $uploadform .=
img_picto(
'',
'product',
'class="pictofixedwidth"');
211 $uploadform .= $form->select_produits_fournisseurs(0, $prodid,
'prodid',
'',
'', array(), 1, 1,
'maxwidth200 disableautoopen', $prodtext, 1);
213 $uploadform .=
'<br>';
216 <small class="opacitymedium">'.$langs->trans(
"OrClickToSelectAFile").
'...</small>
223 $langs->load(
"expensereport");
225 <div id="userexpensereport" class="flex-item flex-item-uploadfile">'.img_picto(
'',
'expensereport',
'class="fa-2x"').
'<br>
226 <div>'.$langs->trans(
"ExpenseReport").
'<br><br>';
228 $uploadform .=
img_picto(
'',
'user',
'class="pictofixedwidth"');
230 $uploadform .= $form->select_dolusers(
GETPOSTINT(
'userexpensereportid') > 0 ?
GETPOSTINT(
'userexpensereportid') : $user->id,
'userexpensereportid', $langs->transnoentitiesnoconv(
"User"), null, 0,
'hierarchyme',
'',
'', 0, 0,
'', 0,
'',
'maxwidth200 disableautoopen', 1);
233 $uploadform .=
'<br>';
236 <small class="opacitymedium">'.$langs->trans(
"OrClickToSelectAFile").
'...</small>
244 $langs->load(
"salaries");
246 <div id="userpayroll" class="flex-item flex-item-uploadfile">'.img_picto(
'',
'salary',
'class="fa-2x"').
'<br>
247 <div>'.$langs->trans(
"UserPaySlip").
'<br><br>';
250 $uploadform .=
img_picto(
'',
'user',
'class="pictofixedwidth"');
252 $uploadform .= $form->select_dolusers(
GETPOSTINT(
'usersalaryid') > 0 ?
GETPOSTINT(
'usersalaryid') : $user->id,
'usersalaryid', $langs->transnoentitiesnoconv(
"Employee"), null, 0,
'hierarchyme',
'',
'', 0, 0,
'', 0,
'',
'maxwidth200 disableautoopen', 1);
255 $uploadform .=
'<br>';
258 <small class="opacitymedium">'.$langs->trans(
"OrClickToSelectAFile").
'...</small>
265$uploadform .=
'</div>';
269$parameters = array(
'uploadform' => $uploadform);
270$reshook = $hookmanager->executeHooks(
'printUploadForm', $parameters);
271if (empty($reshook)) {
272 $uploadform .= $hookmanager->resPrint;
274 $uploadform = $hookmanager->resPrint;
277$uploadform .=
'<br>';
280if ($action ==
'uploadfile') {
281 print $langs->trans(
"ImportInProcess", $originalfilename).
'<br>';
284 print $langs->trans(
"AIProcessingPleaseWait", $ai->getApiService()).
'...';
287 print
'<div class="progress" title="80%">
288 <div class="progress-bar" role="progressbar" style="width: 0%" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100"></div>
293 print
"\n<!-- End Form -->\n";
297 print
"<!-- Begin UploadForm -->\n";
298 print
'<form id="uploadform" enctype="multipart/form-data" method="POST" action="'.dolBuildUrl($_SERVER[
"PHP_SELF"]).
'">';
299 print
'<input type="hidden" name="token" value="'.newToken().
'">';
300 print
'<input type="hidden" name="action" value="uploadfile">';
301 print
'<input type="hidden" name="sendit" value="1">';
302 print
'<input type="hidden" name="modulepart" id="modulepart" value="">';
303 print
'<input type="hidden" name="overwritefile" value="1">';
305 print
'<div class="center"><div class="center" style="padding: 10px;">';
306 print
'<style>.menu_titre { padding-top: 7px; }</style>';
307 print
'<div id="blockupload" class="center">'.
"\n";
312 $accept =
'.pdf,image/*';
318 $max = $maxfilesizearray[
'max'];
319 $maxmin = $maxfilesizearray[
'maxmin'];
320 $maxphptoshow = $maxfilesizearray[
'maxphptoshow'];
321 $maxphptoshowparam = $maxfilesizearray[
'maxphptoshowparam'];
324 $out .=
'<input type="hidden" name="MAX_FILE_SIZE" value="'.($maxmin * 1024).
'">';
326 $out .=
'<input class="hideobject" type="file" id="fileInput" value=""';
328 $out .= ((
getDolGlobalString(
'MAIN_DISABLE_MULTIPLE_FILEUPLOAD') || $disablemulti) ?
' name="userfile"' :
' name="userfile[]" multiple');
332 $out .= (!empty($accept) ?
' accept="'.$accept.
'"' :
' accept=""');
334 $out .= (!empty($capture) ?
' capture="capture"' :
'');
341 $(document).ready(function() {
342 jQuery('#supplierinvoice:not(.disableautoopen)').on('click', function(event) {
343 console.log('Click on link supplierinvoice to open input file');
345 if (!event.target.closest('.disableautoopen')) {
346 $('#modulepart').val('invoice_supplier');
347 $('#fileInput').click();
351 jQuery('#userexpensereport:not(.disableautoopen)').on('click', function(event) {
352 console.log('Click on link userexpensereport to open input file');
354 if (!event.target.closest('.disableautoopen')) {
355 $('#modulepart').val('expensereport');
356 $('#fileInput').click();
360 jQuery('#userpayroll:not(.disableautoopen)').on('click', function(event) {
361 console.log('Click on link userpayroll to open input file');
363 if (!event.target.closest('.disableautoopen')) {
364 $('#modulepart').val('salaries');
365 $('#fileInput').click();
369 jQuery('#fileInput').on('change', function(event) {
371 console.log('A file was selected, we submit the form');
372 $('#uploadform').submit();
378 print
'</div></div>';
381 print
"\n<!-- End UploadForm -->\n";
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
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.
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.
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.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
getMaxFileSizeArray()
Return the max allowed for file upload.