NEW upload a file by drag and drop on social contribution and salary

This commit is contained in:
Laurent Destailleur
2023-05-04 17:28:42 +02:00
parent 095052b3cc
commit f61f425231
8 changed files with 211 additions and 182 deletions

View File

@@ -492,8 +492,9 @@ if ($id > 0) {
} }
if ($action == 'edit') { if ($action == 'edit') {
print "<form name=\"charge\" action=\"".$_SERVER["PHP_SELF"]."?id=$object->id&amp;action=update\" method=\"post\">"; print '<form name="charge" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" method="POST">';
print '<input type="hidden" name="token" value="'.newToken().'">'; print '<input type="hidden" name="token" value="'.newToken().'">';
print '<input type="hidden" name="action" value="update">';
} }
// Call Hook formConfirm // Call Hook formConfirm
$parameters = array('formConfirm' => $formconfirm, 'lineid' => $lineid); $parameters = array('formConfirm' => $formconfirm, 'lineid' => $lineid);

View File

@@ -39,12 +39,6 @@ require '../../main.inc.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/fileupload.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/fileupload.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/genericobject.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/genericobject.class.php';
error_reporting(E_ALL | E_STRICT);
//print_r($_POST);
//print_r($_GET);
//print 'upload_dir='.GETPOST('upload_dir');
$id = GETPOST('fk_element', 'int'); $id = GETPOST('fk_element', 'int');
$element = GETPOST('element', 'alpha'); // 'myobject' (myobject=mymodule) or 'myobject@mymodule' or 'myobject_mysubobject' (myobject=mymodule) $element = GETPOST('element', 'alpha'); // 'myobject' (myobject=mymodule) or 'myobject@mymodule' or 'myobject_mysubobject' (myobject=mymodule)
$elementupload = $element; $elementupload = $element;
@@ -59,7 +53,7 @@ if ($usesublevelpermission && !isset($user->rights->$module->$element)) { // The
$usesublevelpermission = ''; $usesublevelpermission = '';
} }
//print $object->id.' - '.$object->module.' - '.$object->element.' - '.$object->table_element.' - '.$usesublevelpermission."\n"; //print 'fileupload.php: '.$object->id.' - '.$object->module.' - '.$object->element.' - '.$object->table_element.' - '.$usesublevelpermission."\n";
// Security check // Security check
if (!empty($user->socid)) { if (!empty($user->socid)) {
@@ -71,7 +65,7 @@ if (!empty($user->socid)) {
$result = restrictedArea($user, $object->module, $object, $object->table_element, $usesublevelpermission, 'fk_soc', 'rowid', 0, 1); // Call with mode return $result = restrictedArea($user, $object->module, $object, $object->table_element, $usesublevelpermission, 'fk_soc', 'rowid', 0, 1); // Call with mode return
if (!$result) { if (!$result) {
httponly_accessforbidden('Not allowed by restrictArea'); httponly_accessforbidden('Not allowed by restrictArea (module='.$object->module.' table_element='.$object->table_element.')');
} }
@@ -81,6 +75,7 @@ if (!$result) {
$upload_handler = new FileUpload(null, $id, $elementupload); $upload_handler = new FileUpload(null, $id, $elementupload);
top_httphead(); top_httphead();
header('Pragma: no-cache'); header('Pragma: no-cache');
@@ -103,6 +98,7 @@ switch ($_SERVER['REQUEST_METHOD']) {
$upload_handler->delete(); $upload_handler->delete();
} else { } else {
$upload_handler->post(); $upload_handler->post();
// Note: even if this return an error on 1 file in post(), we will return http code 200 because error must be managed by the caller (some files may be ok and some in error)
} }
break; break;
case 'DELETE': case 'DELETE':

View File

@@ -30,99 +30,58 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
*/ */
class FileUpload class FileUpload
{ {
protected $options; public $options;
protected $fk_element; protected $fk_element;
protected $element; protected $element;
/** /**
* Constructor * Constructor.
* This set ->$options
* *
* @param array $options Options array * @param array $options Options array
* @param int $fk_element fk_element * @param int $fk_element ID of element
* @param string $element element * @param string $element Code of element
*/ */
public function __construct($options = null, $fk_element = null, $element = null) public function __construct($options = null, $fk_element = null, $element = null)
{ {
global $db, $conf; global $db, $conf;
global $object;
global $hookmanager; global $hookmanager;
$hookmanager->initHooks(array('fileupload')); $hookmanager->initHooks(array('fileupload'));
$element_prop = getElementProperties($element);
//var_dump($element_prop);
$this->fk_element = $fk_element; $this->fk_element = $fk_element;
$this->element = $element; $this->element = $element;
$pathname = $filename = $element; $pathname = str_replace('/class', '', $element_prop['classpath']);
$regs = array(); $filename = $element_prop['classfile'];
if (preg_match('/^([^_]+)_([^_]+)/i', $element, $regs)) { $dir_output = $element_prop['dir_output'];
$pathname = $regs[1];
$filename = $regs[2]; //print 'fileupload.class.php: element='.$element.' pathname='.$pathname.' filename='.$filename.' dir_output='.$dir_output;
if (empty($dir_output)) {
setEventMessage('The element '.$element.' is not supported for uploading file. dir_output is unknow.', 'errors');
throw new Exception('The element '.$element.' is not supported for uploading file. dir_output is unknow.');
} }
$parentForeignKey = ''; // If pathname and filename are null then we can still upload files if we have specified upload_dir on $options
// For compatibility
if ($element == 'propal') {
$pathname = 'comm/propal';
$dir_output = $conf->$element->dir_output;
} elseif ($element == 'facture') {
$pathname = 'compta/facture';
$dir_output = $conf->$element->dir_output;
} elseif ($element == 'project') {
$element = $pathname = 'projet';
$dir_output = $conf->$element->dir_output;
} elseif ($element == 'project_task') {
$pathname = 'projet';
$filename = 'task';
$dir_output = $conf->project->dir_output;
$parentForeignKey = 'fk_project';
$parentClass = 'Project';
$parentElement = 'projet';
$parentObject = 'project';
} elseif ($element == 'fichinter') {
$element = 'ficheinter';
$dir_output = $conf->$element->dir_output;
} elseif ($element == 'order_supplier') {
$pathname = 'fourn';
$filename = 'fournisseur.commande';
$dir_output = $conf->fournisseur->commande->dir_output;
} elseif ($element == 'invoice_supplier') {
$pathname = 'fourn';
$filename = 'fournisseur.facture';
$dir_output = $conf->fournisseur->facture->dir_output;
} elseif ($element == 'product') {
$dir_output = $conf->product->multidir_output[$conf->entity];
} elseif ($element == 'productbatch') {
$dir_output = $conf->productbatch->multidir_output[$conf->entity];
} elseif ($element == 'action') {
$pathname = 'comm/action';
$filename = 'actioncomm';
$dir_output = $conf->agenda->dir_output;
} elseif ($element == 'chargesociales') {
$pathname = 'compta/sociales';
$filename = 'chargesociales';
$dir_output = $conf->tax->dir_output;
} else {
$dir_output = $conf->$element->dir_output;
}
// If pathname and filename are null then we can still upload files
// IF we have specified upload_dir on $this->options
if ($pathname !== null && $filename !== null) { if ($pathname !== null && $filename !== null) {
dol_include_once('/'.$pathname.'/class/'.$filename.'.class.php'); // Get object from its id and type
$object = fetchObjectByElement($fk_element, $element);
$classname = ucfirst($filename); $object_ref = dol_sanitizeFileName($object->ref);
if ($element == 'order_supplier') { // Special cases to forge $object_ref used to forge $upload_dir
$classname = 'CommandeFournisseur'; if ($element == 'invoice_supplier') {
} elseif ($element == 'invoice_supplier') { $object_ref = get_exdir($object->id, 2, 0, 0, $object, 'invoice_supplier').$object_ref;
$classname = 'FactureFournisseur'; } elseif ($element == 'project_task') {
} $parentForeignKey = 'fk_project';
$parentClass = 'Project';
$parentElement = 'projet';
$parentObject = 'project';
$object = new $classname($db);
$object->fetch($fk_element);
if (!empty($parentForeignKey)) {
dol_include_once('/'.$parentElement.'/class/'.$parentObject.'.class.php'); dol_include_once('/'.$parentElement.'/class/'.$parentObject.'.class.php');
$parent = new $parentClass($db); $parent = new $parentClass($db);
$parent->fetch($object->$parentForeignKey); $parent->fetch($object->$parentForeignKey);
@@ -130,60 +89,53 @@ class FileUpload
$parent->fetch_thirdparty(); $parent->fetch_thirdparty();
} }
$object->$parentObject = clone $parent; $object->$parentObject = clone $parent;
} else {
$object->fetch_thirdparty();
}
$object_ref = dol_sanitizeFileName($object->ref); $object_ref = dol_sanitizeFileName($object->project->ref).'/'.$object_ref;
if ($element == 'invoice_supplier') {
$object_ref = get_exdir($object->id, 2, 0, 0, $object, 'invoice_supplier').$object_ref;
} elseif ($element == 'project_task') {
$object_ref = $object->project->ref.'/'.$object_ref;
} }
} }
$this->options = array( $this->options = array(
'script_url' => $_SERVER['PHP_SELF'], 'script_url' => $_SERVER['PHP_SELF'],
'upload_dir' => $dir_output.'/'.$object_ref.'/', 'upload_dir' => $dir_output.'/'.$object_ref.'/',
'upload_url' => DOL_URL_ROOT.'/document.php?modulepart='.$element.'&attachment=1&file=/'.$object_ref.'/', 'upload_url' => DOL_URL_ROOT.'/document.php?modulepart='.$element.'&attachment=1&file=/'.$object_ref.'/',
'param_name' => 'files', 'param_name' => 'files',
// Set the following option to 'POST', if your server does not support // Set the following option to 'POST', if your server does not support
// DELETE requests. This is a parameter sent to the client: // DELETE requests. This is a parameter sent to the client:
'delete_type' => 'DELETE', 'delete_type' => 'DELETE',
// The php.ini settings upload_max_filesize and post_max_size // The php.ini settings upload_max_filesize and post_max_size
// take precedence over the following max_file_size setting: // take precedence over the following max_file_size setting:
'max_file_size' => null, 'max_file_size' => null,
'min_file_size' => 1, 'min_file_size' => 1,
'accept_file_types' => '/.+$/i', 'accept_file_types' => '/.+$/i',
// The maximum number of files for the upload directory: // The maximum number of files for the upload directory:
'max_number_of_files' => null, 'max_number_of_files' => null,
// Image resolution restrictions: // Image resolution restrictions:
'max_width' => null, 'max_width' => null,
'max_height' => null, 'max_height' => null,
'min_width' => 1, 'min_width' => 1,
'min_height' => 1, 'min_height' => 1,
// Set the following option to false to enable resumable uploads: // Set the following option to false to enable resumable uploads:
'discard_aborted_uploads' => true, 'discard_aborted_uploads' => true,
'image_versions' => array( 'image_versions' => array(
// Uncomment the following version to restrict the size of // Uncomment the following version to restrict the size of
// uploaded images. You can also add additional versions with // uploaded images. You can also add additional versions with
// their own upload directories: // their own upload directories:
/* /*
'large' => array( 'large' => array(
'upload_dir' => dirname($_SERVER['SCRIPT_FILENAME']).'/files/', 'upload_dir' => dirname($_SERVER['SCRIPT_FILENAME']).'/files/',
'upload_url' => $this->getFullUrl().'/files/', 'upload_url' => $this->getFullUrl().'/files/',
'max_width' => 1920, 'max_width' => 1920,
'max_height' => 1200, 'max_height' => 1200,
'jpeg_quality' => 95 'jpeg_quality' => 95
), ),
*/ */
'thumbnail' => array( 'thumbnail' => array(
'upload_dir' => $dir_output.'/'.$object_ref.'/thumbs/', 'upload_dir' => $dir_output.'/'.$object_ref.'/thumbs/',
'upload_url' => DOL_URL_ROOT.'/document.php?modulepart='.$element.'&attachment=1&file=/'.$object_ref.'/thumbs/', 'upload_url' => DOL_URL_ROOT.'/document.php?modulepart='.urlencode($element).'&attachment=1&file=/'.$object_ref.'/thumbs/',
'max_width' => 80, 'max_width' => 80,
'max_height' => 80 'max_height' => 80
)
) )
)
); );
global $action; global $action;
@@ -451,37 +403,49 @@ class FileUpload
$file->mime = dol_mimetype($file->name, '', 2); $file->mime = dol_mimetype($file->name, '', 2);
$file->size = intval($size); $file->size = intval($size);
$file->type = $type; $file->type = $type;
if ($this->validate($uploaded_file, $file, $error, $index) && dol_mkdir($this->options['upload_dir']) >= 0) {
$file_path = $this->options['upload_dir'].$file->name; $validate = $this->validate($uploaded_file, $file, $error, $index);
$append_file = !$this->options['discard_aborted_uploads'] && is_file($file_path) && $file->size > filesize($file_path);
clearstatcache(); if ($validate) {
if ($uploaded_file && is_uploaded_file($uploaded_file)) { if (dol_mkdir($this->options['upload_dir']) >= 0) {
// multipart/formdata uploads (POST method uploads) $file_path = $this->options['upload_dir'].$file->name;
if ($append_file) { $append_file = !$this->options['discard_aborted_uploads'] && is_file($file_path) && $file->size > filesize($file_path);
file_put_contents($file_path, fopen($uploaded_file, 'r'), FILE_APPEND);
} else { clearstatcache();
dol_move_uploaded_file($uploaded_file, $file_path, 1, 0, 0, 0, 'userfile');
} if ($uploaded_file && is_uploaded_file($uploaded_file)) {
} else { // multipart/formdata uploads (POST method uploads)
// Non-multipart uploads (PUT method support) if ($append_file) {
file_put_contents($file_path, fopen('php://input', 'r'), $append_file ? FILE_APPEND : 0); file_put_contents($file_path, fopen($uploaded_file, 'r'), FILE_APPEND);
} } else {
$file_size = filesize($file_path); $result = dol_move_uploaded_file($uploaded_file, $file_path, 1, 0, 0, 0, 'userfile');
if ($file_size === $file->size) {
$file->url = $this->options['upload_url'].rawurlencode($file->name);
foreach ($this->options['image_versions'] as $version => $options) {
if ($this->createScaledImage($file->name, $options)) {
$tmp = explode('.', $file->name);
$file->{$version.'_url'} = $options['upload_url'].rawurlencode($tmp[0].'_mini.'.$tmp[1]);
} }
} else {
// Non-multipart uploads (PUT method support)
file_put_contents($file_path, fopen('php://input', 'r'), $append_file ? FILE_APPEND : 0);
} }
} elseif ($this->options['discard_aborted_uploads']) { $file_size = filesize($file_path);
unlink($file_path); if ($file_size === $file->size) {
$file->error = 'abort'; $file->url = $this->options['upload_url'].rawurlencode($file->name);
foreach ($this->options['image_versions'] as $version => $options) {
if ($this->createScaledImage($file->name, $options)) {
$tmp = explode('.', $file->name);
$file->{$version.'_url'} = $options['upload_url'].rawurlencode($tmp[0].'_mini.'.$tmp[1]);
}
}
} elseif ($this->options['discard_aborted_uploads']) {
unlink($file_path);
$file->error = 'abort';
}
$file->size = $file_size;
$this->setFileDeleteUrl($file);
} else {
$file->error = 'failedtocreatedestdir';
} }
$file->size = $file_size; } else {
$this->setFileDeleteUrl($file); // should not happen
} }
return $file; return $file;
} }
@@ -506,13 +470,17 @@ class FileUpload
/** /**
* Output data * Output data
* *
* @return string|void * @return int 0 if OK, nb of error if errors
*/ */
public function post() public function post()
{ {
$error = 0;
if (isset($_REQUEST['_method']) && $_REQUEST['_method'] === 'DELETE') { if (isset($_REQUEST['_method']) && $_REQUEST['_method'] === 'DELETE') {
return $this->delete(); return $this->delete();
} }
//var_dump($_FILES);
$upload = isset($_FILES[$this->options['param_name']]) ? $upload = isset($_FILES[$this->options['param_name']]) ?
$_FILES[$this->options['param_name']] : null; $_FILES[$this->options['param_name']] : null;
$info = array(); $info = array();
@@ -520,7 +488,7 @@ class FileUpload
// param_name is an array identifier like "files[]", // param_name is an array identifier like "files[]",
// $_FILES is a multi-dimensional array: // $_FILES is a multi-dimensional array:
foreach ($upload['tmp_name'] as $index => $value) { foreach ($upload['tmp_name'] as $index => $value) {
$info[] = $this->handleFileUpload( $tmpres = $this->handleFileUpload(
$upload['tmp_name'][$index], $upload['tmp_name'][$index],
isset($_SERVER['HTTP_X_FILE_NAME']) ? $_SERVER['HTTP_X_FILE_NAME'] : $upload['name'][$index], isset($_SERVER['HTTP_X_FILE_NAME']) ? $_SERVER['HTTP_X_FILE_NAME'] : $upload['name'][$index],
isset($_SERVER['HTTP_X_FILE_SIZE']) ? $_SERVER['HTTP_X_FILE_SIZE'] : $upload['size'][$index], isset($_SERVER['HTTP_X_FILE_SIZE']) ? $_SERVER['HTTP_X_FILE_SIZE'] : $upload['size'][$index],
@@ -528,11 +496,15 @@ class FileUpload
$upload['error'][$index], $upload['error'][$index],
$index $index
); );
if (!empty($tmpres->error)) {
$error++;
}
$info[] = $tmpres;
} }
} elseif ($upload || isset($_SERVER['HTTP_X_FILE_NAME'])) { } elseif ($upload || isset($_SERVER['HTTP_X_FILE_NAME'])) {
// param_name is a single object identifier like "file", // param_name is a single object identifier like "file",
// $_FILES is a one-dimensional array: // $_FILES is a one-dimensional array:
$info[] = $this->handleFileUpload( $tmpres = $this->handleFileUpload(
isset($upload['tmp_name']) ? $upload['tmp_name'] : null, isset($upload['tmp_name']) ? $upload['tmp_name'] : null,
isset($_SERVER['HTTP_X_FILE_NAME']) ? $_SERVER['HTTP_X_FILE_NAME'] : (isset($upload['name']) ? $upload['name'] : null), isset($_SERVER['HTTP_X_FILE_NAME']) ? $_SERVER['HTTP_X_FILE_NAME'] : (isset($upload['name']) ? $upload['name'] : null),
isset($_SERVER['HTTP_X_FILE_SIZE']) ? $_SERVER['HTTP_X_FILE_SIZE'] : (isset($upload['size']) ? $upload['size'] : null), isset($_SERVER['HTTP_X_FILE_SIZE']) ? $_SERVER['HTTP_X_FILE_SIZE'] : (isset($upload['size']) ? $upload['size'] : null),
@@ -540,28 +512,37 @@ class FileUpload
isset($upload['error']) ? $upload['error'] : null, isset($upload['error']) ? $upload['error'] : null,
0 0
); );
if (!empty($tmpres->error)) {
$error++;
}
$info[] = $tmpres;
} }
header('Vary: Accept'); header('Vary: Accept');
$json = json_encode($info); $json = json_encode($info);
$redirect = isset($_REQUEST['redirect']) ?
stripslashes($_REQUEST['redirect']) : null; /* disabled. Param redirect seems not used
$redirect = isset($_REQUEST['redirect']) ? stripslashes($_REQUEST['redirect']) : null;
if ($redirect) { if ($redirect) {
header('Location: '.sprintf($redirect, rawurlencode($json))); header('Location: '.sprintf($redirect, rawurlencode($json)));
return; return;
} }
if (isset($_SERVER['HTTP_ACCEPT']) && */
(strpos($_SERVER['HTTP_ACCEPT'], 'application/json') !== false)) {
if (isset($_SERVER['HTTP_ACCEPT']) && (strpos($_SERVER['HTTP_ACCEPT'], 'application/json') !== false)) {
header('Content-type: application/json'); header('Content-type: application/json');
} else { } else {
header('Content-type: text/plain'); header('Content-type: text/plain');
} }
echo $json; echo $json;
return $error;
} }
/** /**
* Delete uploaded file * Delete uploaded file
* *
* @return string|null * @return int
*/ */
public function delete() public function delete()
{ {
@@ -581,6 +562,6 @@ class FileUpload
header('Content-type: application/json'); header('Content-type: application/json');
echo json_encode($success); echo json_encode($success);
return null; return 0;
} }
} }

View File

@@ -3469,7 +3469,23 @@ function dragAndDropFileUpload($htmlname)
data: fd, data: fd,
success:function() { success:function() {
console.log("Uploaded.", arguments); console.log("Uploaded.", arguments);
window.location.href = "'.$_SERVER["PHP_SELF"].'?id='.dol_escape_js($object->id).'&seteventmessages=UploadFileDragDropSuccess:mesgs"; /* arguments[0] is the json string of files */
/* arguments[1] is the value for variable "success", can be 0 or 1 */
let listoffiles = JSON.parse(arguments[0]);
console.log(listoffiles);
let nboferror = 0;
for (let i = 0; i < listoffiles.length; i++) {
console.log(listoffiles[i].error);
if (listoffiles[i].error) {
nboferror++;
}
}
console.log(nboferror);
if (nboferror > 0) {
window.location.href = "'.$_SERVER["PHP_SELF"].'?id='.dol_escape_js($object->id).'&seteventmessages=ErrorOnAtLeastOneFileUpload:warnings";
} else {
window.location.href = "'.$_SERVER["PHP_SELF"].'?id='.dol_escape_js($object->id).'&seteventmessages=UploadFileDragDropSuccess:mesgs";
}
}, },
error:function() { error:function() {
console.log("Error Uploading.", arguments) console.log("Error Uploading.", arguments)

View File

@@ -11256,17 +11256,19 @@ function dolGetButtonTitle($label, $helpText = '', $iconClass = 'fa fa-file', $u
* Get an array with properties of an element. * Get an array with properties of an element.
* *
* @param string $element_type Element type (Value of $object->element). Example: * @param string $element_type Element type (Value of $object->element). Example:
* 'action', 'facture', 'project_task', * 'action', 'facture', 'project', 'project_task' or
* 'myobject@mymodule' or * 'myobject@mymodule' or
* 'myobject_mysubobject' (where mymodule = myobject, like 'project_task') * 'myobject_mysubobject' (where mymodule = myobject, like 'project_task')
* @return array (module, classpath, element, subelement, classfile, classname) * @return array array('module'=>, 'classpath'=>, 'element'=>, 'subelement'=>, 'classfile'=>, 'classname'=>, 'dir_output'=>)
* @see fetchObjectByElement() * @see fetchObjectByElement()
*/ */
function getElementProperties($element_type) function getElementProperties($element_type)
{ {
global $conf;
$regs = array(); $regs = array();
$classfile = $classname = $classpath = ''; $classfile = $classname = $classpath = $dir_output = '';
// Parse element/subelement // Parse element/subelement
$module = $element_type; $module = $element_type;
@@ -11401,14 +11403,14 @@ function getElementProperties($element_type)
$classpath = 'fourn/class'; $classpath = 'fourn/class';
$module = 'fournisseur'; $module = 'fournisseur';
$classfile = 'fournisseur.commande'; $classfile = 'fournisseur.commande';
$element = 'commande'; $element = 'order_supplier';
$subelement = ''; $subelement = '';
$classname = 'CommandeFournisseur'; $classname = 'CommandeFournisseur';
} elseif ($element_type == 'invoice_supplier') { } elseif ($element_type == 'invoice_supplier') {
$classpath = 'fourn/class'; $classpath = 'fourn/class';
$module = 'fournisseur'; $module = 'fournisseur';
$classfile = 'fournisseur.facture'; $classfile = 'fournisseur.facture';
$element = 'facture'; $element = 'invoice_supplier';
$subelement = ''; $subelement = '';
$classname = 'FactureFournisseur'; $classname = 'FactureFournisseur';
} elseif ($element_type == "service") { } elseif ($element_type == "service") {
@@ -11434,6 +11436,9 @@ function getElementProperties($element_type)
$classpath = 'core/class'; $classpath = 'core/class';
$module = 'accounting'; $module = 'accounting';
$subelement = 'fiscalyear'; $subelement = 'fiscalyear';
} elseif ($element_type == 'chargesociales') {
$classpath = 'compta/sociales/class';
$module = 'tax';
} }
if (empty($classfile)) { if (empty($classfile)) {
@@ -11446,13 +11451,32 @@ function getElementProperties($element_type)
$classpath = $module.'/class'; $classpath = $module.'/class';
} }
// Set dir_output
if ($module && isset($conf->$module)) { // The generic case
if (!empty($conf->$module->multidir_output[$conf->entity])) {
$dir_output = $conf->$module->multidir_output[$conf->entity];
} elseif (!empty($conf->$module->output[$conf->entity])) {
$dir_output = $conf->$module->output[$conf->entity];
} elseif (!empty($conf->$module->dir_output)) {
$dir_output = $conf->$module->dir_output;
}
}
// Overwrite value for special cases
if ($element == 'order_supplier') {
$dir_output = $conf->fournisseur->commande->dir_output;
} elseif ($element == 'invoice_supplier') {
$dir_output = $conf->fournisseur->facture->dir_output;
}
$element_properties = array( $element_properties = array(
'module' => $module, 'module' => $module,
'classpath' => $classpath,
'element' => $element, 'element' => $element,
'subelement' => $subelement, 'subelement' => $subelement,
'classpath' => $classpath,
'classfile' => $classfile, 'classfile' => $classfile,
'classname' => $classname 'classname' => $classname,
'dir_output' => $dir_output
); );
return $element_properties; return $element_properties;
} }

View File

@@ -401,6 +401,9 @@ function restrictedArea(User $user, $features, $object = 0, $tableandshare = '',
if ($features == 'productbatch') { if ($features == 'productbatch') {
$features = 'produit'; $features = 'produit';
} }
if ($features == 'tax') {
$feature2 = 'charges';
}
if ($features == 'fournisseur') { // When vendor invoice and purchase order are into module 'fournisseur' if ($features == 'fournisseur') { // When vendor invoice and purchase order are into module 'fournisseur'
$features = 'fournisseur'; $features = 'fournisseur';
if (is_object($object) && $object->element == 'invoice_supplier') { if (is_object($object) && $object->element == 'invoice_supplier') {

View File

@@ -87,7 +87,7 @@ class modTax extends DolibarrModules
$r++; $r++;
$this->rights[$r][0] = 91; $this->rights[$r][0] = 91;
$this->rights[$r][1] = 'Lire les charges'; $this->rights[$r][1] = 'Read social contibutions';
$this->rights[$r][2] = 'r'; $this->rights[$r][2] = 'r';
$this->rights[$r][3] = 0; $this->rights[$r][3] = 0;
$this->rights[$r][4] = 'charges'; $this->rights[$r][4] = 'charges';
@@ -95,7 +95,7 @@ class modTax extends DolibarrModules
$r++; $r++;
$this->rights[$r][0] = 92; $this->rights[$r][0] = 92;
$this->rights[$r][1] = 'Creer/modifier les charges'; $this->rights[$r][1] = 'Create/modify social contributions';
$this->rights[$r][2] = 'w'; $this->rights[$r][2] = 'w';
$this->rights[$r][3] = 0; $this->rights[$r][3] = 0;
$this->rights[$r][4] = 'charges'; $this->rights[$r][4] = 'charges';
@@ -103,7 +103,7 @@ class modTax extends DolibarrModules
$r++; $r++;
$this->rights[$r][0] = 93; $this->rights[$r][0] = 93;
$this->rights[$r][1] = 'Supprimer les charges'; $this->rights[$r][1] = 'Delete social contributions';
$this->rights[$r][2] = 'd'; $this->rights[$r][2] = 'd';
$this->rights[$r][3] = 0; $this->rights[$r][3] = 0;
$this->rights[$r][4] = 'charges'; $this->rights[$r][4] = 'charges';
@@ -111,7 +111,7 @@ class modTax extends DolibarrModules
$r++; $r++;
$this->rights[$r][0] = 94; $this->rights[$r][0] = 94;
$this->rights[$r][1] = 'Exporter les charges'; $this->rights[$r][1] = 'Export social contributions';
$this->rights[$r][2] = 'r'; $this->rights[$r][2] = 'r';
$this->rights[$r][3] = 0; $this->rights[$r][3] = 0;
$this->rights[$r][4] = 'charges'; $this->rights[$r][4] = 'charges';

View File

@@ -31,6 +31,7 @@
// Load Dolibarr environment // Load Dolibarr environment
require '../main.inc.php'; require '../main.inc.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
require_once DOL_DOCUMENT_ROOT.'/salaries/class/salary.class.php'; require_once DOL_DOCUMENT_ROOT.'/salaries/class/salary.class.php';
require_once DOL_DOCUMENT_ROOT.'/salaries/class/paymentsalary.class.php'; require_once DOL_DOCUMENT_ROOT.'/salaries/class/paymentsalary.class.php';
require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'; require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
@@ -111,6 +112,8 @@ $permissiontoread = $user->rights->salaries->read;
$permissiontoadd = $user->rights->salaries->write; // Used by the include of actions_addupdatedelete.inc.php and actions_lineupdown.inc.php $permissiontoadd = $user->rights->salaries->write; // Used by the include of actions_addupdatedelete.inc.php and actions_lineupdown.inc.php
$permissiontodelete = $user->rights->salaries->delete || ($permissiontoadd && isset($object->status) && $object->status == $object::STATUS_DRAFT); $permissiontodelete = $user->rights->salaries->delete || ($permissiontoadd && isset($object->status) && $object->status == $object::STATUS_DRAFT);
$upload_dir = $conf->salaries->multidir_output[$conf->entity];
/* /*
* Actions * Actions
@@ -150,12 +153,17 @@ if (empty($reshook)) {
} }
$action = ''; $action = '';
} }
// Actions to send emails
$triggersendname = 'COMPANY_SENTBYMAIL'; // Actions to send emails
$paramname = 'id'; $triggersendname = 'COMPANY_SENTBYMAIL';
$mode = 'emailfromthirdparty'; $paramname = 'id';
$trackid = 'thi'.$object->id; $mode = 'emailfromthirdparty';
include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php'; $trackid = 'sal'.$object->id;
include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php';
//var_dump($upload_dir);var_dump($permissiontoadd);var_dump($action);exit;
// Actions to build doc
include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php';
} }
// Link to a project // Link to a project
@@ -758,7 +766,7 @@ if ($id > 0) {
print $formconfirm; print $formconfirm;
print dol_get_fiche_head($head, 'card', $langs->trans("SalaryPayment"), -1, 'salary'); print dol_get_fiche_head($head, 'card', $langs->trans("SalaryPayment"), -1, 'salary', 0, '', '', 0, '', 1);
$linkback = '<a href="'.DOL_URL_ROOT.'/salaries/list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>'; $linkback = '<a href="'.DOL_URL_ROOT.'/salaries/list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';