mirror of
https://github.com/Dolibarr/dolibarr.git
synced 2026-01-04 16:12:39 +01:00
WIP generic upload files
This commit is contained in:
@@ -67,15 +67,13 @@ if ($action == 'builddoc' && ($permissiontoadd || !empty($usercangeneretedoc)))
|
||||
}
|
||||
|
||||
// Special case to force bank account
|
||||
//if (property_exists($object, 'fk_bank'))
|
||||
//{
|
||||
if (GETPOSTINT('fk_bank')) {
|
||||
// this field may come from an external module
|
||||
$object->fk_bank = GETPOSTINT('fk_bank');
|
||||
$object->fk_bank = GETPOSTINT('fk_bank'); // For compatibility
|
||||
$object->fk_account = GETPOSTINT('fk_bank');
|
||||
} elseif (!empty($object->fk_account)) {
|
||||
$object->fk_bank = $object->fk_account;
|
||||
$object->fk_bank = $object->fk_account; // For compatibility
|
||||
}
|
||||
//}
|
||||
|
||||
$outputlangs = $langs;
|
||||
$newlang = '';
|
||||
|
||||
@@ -60,6 +60,8 @@ if ((GETPOST('sendit', 'alpha')
|
||||
// Submit file/link
|
||||
if (GETPOST('sendit', 'alpha') && getDolGlobalString('MAIN_UPLOAD_DOC') && !empty($permissiontoadd)) {
|
||||
if (!empty($_FILES) && is_array($_FILES['userfile'])) {
|
||||
include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
|
||||
|
||||
if (is_array($_FILES['userfile']['tmp_name'])) {
|
||||
$userfiles = $_FILES['userfile']['tmp_name'];
|
||||
} else {
|
||||
|
||||
@@ -12908,7 +12908,7 @@ function getElementProperties($elementType)
|
||||
|
||||
//$element_type='facture';
|
||||
|
||||
$classfile = $classname = $classpath = $subdir = $dir_output = $parent_element = '';
|
||||
$classfile = $classname = $classpath = $subdir = $dir_output = $dir_temp = $parent_element = '';
|
||||
|
||||
// Parse element/subelement
|
||||
$module = $elementType;
|
||||
@@ -13267,15 +13267,25 @@ function getElementProperties($elementType)
|
||||
} elseif (!empty($conf->$module->dir_output)) {
|
||||
$dir_output = $conf->$module->dir_output;
|
||||
}
|
||||
if (!empty($conf->$module->multidir_temp[$conf->entity])) {
|
||||
$dir_temp = $conf->$module->multidir_temp[$conf->entity];
|
||||
} elseif (!empty($conf->$module->temp[$conf->entity])) {
|
||||
$dir_temp = $conf->$module->temp[$conf->entity];
|
||||
} elseif (!empty($conf->$module->dir_temp)) {
|
||||
$dir_temp = $conf->$module->dir_temp;
|
||||
}
|
||||
}
|
||||
|
||||
// Overwrite value for special cases
|
||||
if ($element == 'order_supplier') {
|
||||
$dir_output = $conf->fournisseur->commande->dir_output;
|
||||
$dir_temp = $conf->fournisseur->commande->dir_temp;
|
||||
} elseif ($element == 'invoice_supplier') {
|
||||
$dir_output = $conf->fournisseur->facture->dir_output;
|
||||
$dir_temp = $conf->fournisseur->facture->dir_temp;
|
||||
}
|
||||
$dir_output .= $subdir;
|
||||
$dir_temp .= $subdir;
|
||||
|
||||
$elementProperties = array(
|
||||
'module' => $module,
|
||||
@@ -13286,6 +13296,7 @@ function getElementProperties($elementType)
|
||||
'classfile' => $classfile,
|
||||
'classname' => $classname,
|
||||
'dir_output' => $dir_output,
|
||||
'dir_temp' => $dir_temp,
|
||||
'parent_element' => $parent_element,
|
||||
);
|
||||
|
||||
|
||||
@@ -61,7 +61,8 @@ if (GETPOST('lang', 'aZ09')) {
|
||||
|
||||
$langs->loadLangs(array("main", "other"));
|
||||
|
||||
//$action = GETPOST('action', 'aZ09');
|
||||
$action = GETPOST('action', 'aZ09');
|
||||
$modulepart = GETPOST('modulepart', 'aZ09');
|
||||
|
||||
|
||||
/*
|
||||
@@ -75,6 +76,25 @@ if (!is_numeric(getDolGlobalString('MAIN_USE_TOP_MENU_IMPORT_FILE'))) {
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if ($action == 'uploadfile') { // Test on permission not required here. Done later
|
||||
$arrayobject = getElementProperties($modulepart);
|
||||
|
||||
$module = $arrayobject['module'];
|
||||
$element = $arrayobject['element'];
|
||||
$dir_output = $arrayobject['dir_output'];
|
||||
$dir_temp = $arrayobject['dir_temp'];
|
||||
|
||||
$permlevel1 = $element;
|
||||
if ($module == 'fournisseur') {
|
||||
$permlevel1 = 'facture';
|
||||
}
|
||||
|
||||
$permissiontoadd = $user->hasRight($module, $permlevel1, 'read');
|
||||
$upload_dir = $dir_temp.'/import';
|
||||
var_dump($upload_dir);
|
||||
include DOL_DOCUMENT_ROOT.'/core/actions_linkedfiles.inc.php';
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* View
|
||||
@@ -117,26 +137,30 @@ $uploadform = '';
|
||||
|
||||
$uploadform = '<div class="display-flex">';
|
||||
|
||||
$langs->load("bills");
|
||||
$uploadform .= '
|
||||
<div id="supplierinvoice" class="flex-item flex-item-uploadfile">'.img_picto('', 'bill', 'class="fa-2x"').'<br>
|
||||
<div>'.$langs->trans("SupplierInvoice").'<br><br>';
|
||||
if (isModEnabled('supplier_invoice')) {
|
||||
$langs->load("bills");
|
||||
$uploadform .= '
|
||||
<div id="supplierinvoice" class="flex-item flex-item-uploadfile">'.img_picto('', 'bill', 'class="fa-2x"').'<br>
|
||||
<div>'.$langs->trans("SupplierInvoice").'<br><br>';
|
||||
|
||||
$uploadform .= img_picto('', 'company', 'class="pictofixedwidth"');
|
||||
$uploadform .= $form->select_company(GETPOSTINT('socid'), 'socid', 'statut=0', $langs->transnoentitiesnoconv("Supplier"));
|
||||
$uploadform .= img_picto('', 'company', 'class="pictofixedwidth"');
|
||||
$uploadform .= $form->select_company(GETPOSTINT('socid'), 'socid', 'statut=0', $langs->transnoentitiesnoconv("Supplier"));
|
||||
|
||||
$uploadform .= '<br><br>
|
||||
<small>('.$langs->trans("OrClickToSelectAFile").')</small>
|
||||
</div>
|
||||
</div>';
|
||||
$uploadform .= '<br><br>
|
||||
<small>('.$langs->trans("OrClickToSelectAFile").')</small>
|
||||
</div>
|
||||
</div>';
|
||||
}
|
||||
|
||||
$langs->load("salaries");
|
||||
$uploadform .= '
|
||||
<div id="userpayroll" class="flex-item flex-item-uploadfile">'.img_picto('', 'salary', 'class="fa-2x"').'<br>
|
||||
<div>'.$langs->trans("UserPaySlip").'<br>
|
||||
<small>('.$langs->trans("OrClickToSelectAFile").')</small>
|
||||
</div>
|
||||
</div>';
|
||||
if (isModEnabled('salaries')) {
|
||||
$langs->load("salaries");
|
||||
$uploadform .= '
|
||||
<div id="userpayroll" class="flex-item flex-item-uploadfile">'.img_picto('', 'salary', 'class="fa-2x"').'<br>
|
||||
<div>'.$langs->trans("UserPaySlip").'<br>
|
||||
<small>('.$langs->trans("OrClickToSelectAFile").')</small>
|
||||
</div>
|
||||
</div>';
|
||||
}
|
||||
|
||||
$uploadform .= '</div>';
|
||||
|
||||
@@ -159,6 +183,8 @@ print "<!-- Begin UploadForm -->\n";
|
||||
print '<form id="uploadform" enctype="multipart/form-data" method="POST" action="'.$_SERVER["PHP_SELF"].'">';
|
||||
print '<input type="hidden" name="token" value="'.newToken().'">';
|
||||
print '<input type="hidden" name="action" value="uploadfile">';
|
||||
print '<input type="hidden" name="sendit" value="1">';
|
||||
print '<input type="hidden" name="modulepart" id="modulepart" value="">';
|
||||
|
||||
print '<div class="center"><div class="center" style="padding: 30px;">';
|
||||
print '<style>.menu_titre { padding-top: 7px; }</style>';
|
||||
@@ -166,13 +192,43 @@ print '<div id="blockupload" class="center">'."\n";
|
||||
//print '<input name="filenamePDF" id="filenamePDF" type="hideobject">';
|
||||
print $uploadform;
|
||||
|
||||
print '<input type="file" id="fileInput" class="hideobject" accept=".pdf, image/*">';
|
||||
|
||||
$accept = '.pdf, image';
|
||||
$disablemulti = 1;
|
||||
$perm = 1;
|
||||
$capture = 1;
|
||||
|
||||
$maxfilesizearray = getMaxFileSizeArray();
|
||||
$max = $maxfilesizearray['max'];
|
||||
$maxmin = $maxfilesizearray['maxmin'];
|
||||
$maxphptoshow = $maxfilesizearray['maxphptoshow'];
|
||||
$maxphptoshowparam = $maxfilesizearray['maxphptoshowparam'];
|
||||
if ($maxmin > 0) {
|
||||
$out .= '<input type="hidden" name="MAX_FILE_SIZE" value="'.($maxmin * 1024).'">'; // MAX_FILE_SIZE must precede the field type=file
|
||||
}
|
||||
$out .= '<input class="hideobject" type="file" id="fileInput"';
|
||||
$out .= ((getDolGlobalString('MAIN_DISABLE_MULTIPLE_FILEUPLOAD') || $disablemulti) ? ' name="userfile"' : ' name="userfile[]" multiple');
|
||||
$out .= (!getDolGlobalString('MAIN_UPLOAD_DOC') || empty($perm) ? ' disabled' : '');
|
||||
$out .= (!empty($accept) ? ' accept="'.$accept.'"' : ' accept=""');
|
||||
$out .= (!empty($capture) ? ' capture="capture"' : '');
|
||||
$out .= '>';
|
||||
|
||||
print $out;
|
||||
|
||||
|
||||
print "<script>
|
||||
$(document).ready(function() {
|
||||
jQuery('#supplierinvoice').on('click', function(event) {
|
||||
console.log('Click on link to open input file');
|
||||
console.log(event);
|
||||
$('#modulepart').val('invoice_supplier');
|
||||
$('#fileInput').click();
|
||||
});
|
||||
|
||||
jQuery('#userpayroll').on('click', function(event) {
|
||||
console.log('Click on link to open input file');
|
||||
console.log(event);
|
||||
$('#modulepart').val('salary');
|
||||
$('#fileInput').click();
|
||||
});
|
||||
|
||||
|
||||
@@ -920,7 +920,8 @@ class User extends CommonObject
|
||||
// In $user->rights, we have 'accounting', 'produit', 'facture', ...
|
||||
//var_dump($this->rights->$rightsPath);
|
||||
//var_dump($conf->modules);
|
||||
//var_dump($module.' '.isModEnabled($module).' '.$rightsPath.' '.$permlevel1.' '.$permlevel2);
|
||||
//if ($module == 'fournisseur') { var_dump($module.' '.isModEnabled($module).' '.$rightsPath.' '.$permlevel1.' '.$permlevel2); }
|
||||
|
||||
if (!isModEnabled($module)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user