diff --git a/htdocs/core/ajax/fileupload.php b/htdocs/core/ajax/fileupload.php index 4e05c7d8cb6..aba272d69a5 100644 --- a/htdocs/core/ajax/fileupload.php +++ b/htdocs/core/ajax/fileupload.php @@ -19,24 +19,28 @@ /** * \file htdocs/core/ajax/fileupload.php * \brief File to return Ajax response on file upload - * - * Option MAIN_USE_JQUERY_FILEUPLOAD must be enabled to have this feature working. Use is NOT secured ! */ -if (!defined('NOTOKENRENEWAL')) { - define('NOTOKENRENEWAL', '1'); -} if (!defined('NOREQUIREMENU')) { define('NOREQUIREMENU', '1'); // If there is no menu to show } if (!defined('NOREQUIREHTML')) { define('NOREQUIREHTML', '1'); // If we don't need to load the html.form.class.php } - +if (!defined('NOREQUIREAJAX')) { + define('NOREQUIREAJAX', '1'); +} +if (!defined('NOREQUIRESOC')) { + define('NOREQUIRESOC', '1'); +} +/*if (!defined('NOREQUIRETRAN')) { + define('NOREQUIRETRAN', '1'); +}*/ // Load Dolibarr environment require '../../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/fileupload.class.php'; +require_once DOL_DOCUMENT_ROOT.'/core/class/genericobject.class.php'; error_reporting(E_ALL | E_STRICT); @@ -44,16 +48,56 @@ error_reporting(E_ALL | E_STRICT); //print_r($_GET); //print 'upload_dir='.GETPOST('upload_dir'); -$fk_element = GETPOST('fk_element', 'int'); -$element = GETPOST('element', 'alpha'); +$id = GETPOST('fk_element', 'int'); +$elementupload = GETPOST('element', 'alpha'); +$element = $elementupload; -$upload_handler = new FileUpload(null, $fk_element, $element); - -// Feature not enabled. Warning feature not used and not secured so disabled. -if (!getDolGlobalInt('MAIN_USE_JQUERY_FILEUPLOAD')) { - return; +if ($element == "invoice_supplier") { + $element = "fournisseur"; } +$object = new GenericObject($db); +$tmparray = explode('@', $element); + +if (empty($tmparray[1])) { + $subelement = ''; + + $object->module = $element; + $object->element = $element; + $object->table_element = $element; + + // Special case for compatibility + if ($object->table_element == 'websitepage') { + $object->table_element = 'website_page'; + } +} else { + $element = $tmparray[0]; + $subelement = $tmparray[1]; + + $object->module = $element; + $object->element = $subelement; + $object->table_element = $object->module.'_'.$object->element; +} +$object->id = $id; + +// Security check +if (!empty($user->socid)) { + $socid = $user->socid; +} + +$module = $object->module; +$element = $object->element; +$usesublevelpermission = ($module != $element ? $element : ''); +if ($usesublevelpermission && !isset($user->rights->$module->$element)) { // There is no permission on object defined, we will check permission on module directly + $usesublevelpermission = ''; +} +$result = restrictedArea($user, $object->module, $object, $object->table_element, $usesublevelpermission, 'fk_soc', 'rowid', 0, 1); +if (!$result) { + header('HTTP/1.0 403 Forbidden'); + exit; +} +$upload_handler = new FileUpload(null, $id, $elementupload); + /* * View diff --git a/htdocs/core/class/fileupload.class.php b/htdocs/core/class/fileupload.class.php index 4a4394a7049..4dcfb55f781 100644 --- a/htdocs/core/class/fileupload.class.php +++ b/htdocs/core/class/fileupload.class.php @@ -19,8 +19,6 @@ /** * \file htdocs/core/class/fileupload.class.php * \brief File to return Ajax response on file upload - * - * Option MAIN_USE_JQUERY_FILEUPLOAD must be enabled to have feature working. Use is NOT secured ! */ require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; @@ -49,11 +47,6 @@ class FileUpload global $object; global $hookmanager; - // Feature not enabled. Warning feature not used and not secured so disabled. - if (!getDolGlobalInt('MAIN_USE_JQUERY_FILEUPLOAD')) { - return; - } - $hookmanager->initHooks(array('fileupload')); $this->fk_element = $fk_element; @@ -266,9 +259,6 @@ class FileUpload */ protected function getFileObject($file_name) { - if (!getDolGlobalInt('MAIN_USE_JQUERY_FILEUPLOAD')) { - return null; - } $file_path = $this->options['upload_dir'].$file_name; if (is_file($file_path) && $file_name[0] !== '.') { @@ -310,10 +300,6 @@ class FileUpload { global $maxwidthmini, $maxheightmini; - if (!getDolGlobalInt('MAIN_USE_JQUERY_FILEUPLOAD')) { - return false; - } - $file_path = $this->options['upload_dir'].$file_name; $new_file_path = $options['upload_dir'].$file_name; @@ -345,10 +331,6 @@ class FileUpload */ protected function validate($uploaded_file, $file, $error, $index) { - if (!getDolGlobalInt('MAIN_USE_JQUERY_FILEUPLOAD')) { - return false; - } - if ($error) { $file->error = $error; return false; @@ -464,10 +446,6 @@ class FileUpload */ protected function handleFileUpload($uploaded_file, $name, $size, $type, $error, $index) { - if (!getDolGlobalInt('MAIN_USE_JQUERY_FILEUPLOAD')) { - return null; - } - $file = new stdClass(); $file->name = $this->trimFileName($name, $type, $index); $file->mime = dol_mimetype($file->name, '', 2); @@ -514,10 +492,6 @@ class FileUpload */ public function get() { - if (!getDolGlobalInt('MAIN_USE_JQUERY_FILEUPLOAD')) { - return; - } - $file_name = isset($_REQUEST['file']) ? basename(stripslashes($_REQUEST['file'])) : null; if ($file_name) { @@ -536,10 +510,6 @@ class FileUpload */ public function post() { - if (!getDolGlobalInt('MAIN_USE_JQUERY_FILEUPLOAD')) { - return; - } - if (isset($_REQUEST['_method']) && $_REQUEST['_method'] === 'DELETE') { return $this->delete(); } @@ -595,10 +565,6 @@ class FileUpload */ public function delete() { - if (!getDolGlobalInt('MAIN_USE_JQUERY_FILEUPLOAD')) { - return null; - } - $file_name = isset($_REQUEST['file']) ? basename(stripslashes($_REQUEST['file'])) : null; $file_path = $this->options['upload_dir'].$file_name; diff --git a/htdocs/core/lib/files.lib.php b/htdocs/core/lib/files.lib.php index 5d98e081e9c..3141ddfaa73 100644 --- a/htdocs/core/lib/files.lib.php +++ b/htdocs/core/lib/files.lib.php @@ -3386,3 +3386,86 @@ function getFilesUpdated(&$file_list, SimpleXMLElement $dir, $path = '', $pathre return $file_list; } + +/** + * Function to manage the drag and drop file. + * We use global variable $object + * + * @param string $htmlname The id of the component where we need to drag and drop + * @return string Js script to display + */ +function dragAndDropFileUpload($htmlname) +{ + global $object, $langs; + $out = ""; + $out .= ''; + $out .= "\n\n"; + $out .= "\n"; + return $out; +} diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index b3f1bd7773f..6a02df0c1c6 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -1890,9 +1890,10 @@ function dol_fiche_head($links = array(), $active = '0', $title = '', $notab = 0 * @param string $morecss More CSS on the link * @param int $limittoshow Limit number of tabs to show. Use 0 to use automatic default value. * @param string $moretabssuffix A suffix to use when you have several dol_get_fiche_head() in same page + * @param int $dragdropfile 0 (default) or 1. 1 enable a drop zone for file to be upload, 0 disable it * @return string */ -function dol_get_fiche_head($links = array(), $active = '', $title = '', $notab = 0, $picto = '', $pictoisfullpath = 0, $morehtmlright = '', $morecss = '', $limittoshow = 0, $moretabssuffix = '') +function dol_get_fiche_head($links = array(), $active = '', $title = '', $notab = 0, $picto = '', $pictoisfullpath = 0, $morehtmlright = '', $morecss = '', $limittoshow = 0, $moretabssuffix = '', $dragdropfile = 0) { global $conf, $langs, $hookmanager; @@ -2058,9 +2059,11 @@ function dol_get_fiche_head($links = array(), $active = '', $title = '', $notab } if (!$notab || $notab == -1 || $notab == -2 || $notab == -3) { - $out .= "\n".'
'."\n"; + $out .= "\n".'
'."\n"; + } + if (!empty($dragdropfile)) { + $out .= dragAndDropFileUpload("dragDropAreaTabBar"); } - $parameters = array('tabname' => $active, 'out' => $out); $reshook = $hookmanager->executeHooks('printTabsHead', $parameters); // This hook usage is called just before output the head of tabs. Take also a look at "completeTabsHead" if ($reshook > 0) { diff --git a/htdocs/fourn/facture/card.php b/htdocs/fourn/facture/card.php index 5408b8f980a..054ae69e3ad 100644 --- a/htdocs/fourn/facture/card.php +++ b/htdocs/fourn/facture/card.php @@ -2800,7 +2800,7 @@ if ($action == 'create') { $head = facturefourn_prepare_head($object); $titre = $langs->trans('SupplierInvoice'); - print dol_get_fiche_head($head, 'card', $titre, -1, 'supplier_invoice'); + print dol_get_fiche_head($head, 'card', $titre, -1, 'supplier_invoice', 0, '', '', 0, '', 1); $formconfirm = ''; diff --git a/htdocs/langs/en_US/errors.lang b/htdocs/langs/en_US/errors.lang index 6e60f238911..6c07dc05e98 100644 --- a/htdocs/langs/en_US/errors.lang +++ b/htdocs/langs/en_US/errors.lang @@ -310,6 +310,8 @@ ErrorFieldExist=The value for %s already exist ErrorEqualModule=Module invalid in %s ErrorFieldValue=Value for %s is incorrect ErrorCoherenceMenu=%s is required when %s is 'left' +ErrorUploadFileDragDrop=There was an error while the file(s) upload +ErrorUploadFileDragDropPermissionDenied=There was an error while the file(s) upload : Permission denied # Warnings WarningParamUploadMaxFileSizeHigherThanPostMaxSize=Your PHP parameter upload_max_filesize (%s) is higher than PHP parameter post_max_size (%s). This is not a consistent setup. diff --git a/htdocs/langs/en_US/main.lang b/htdocs/langs/en_US/main.lang index d8f5d988d08..09627d5a3b0 100644 --- a/htdocs/langs/en_US/main.lang +++ b/htdocs/langs/en_US/main.lang @@ -1229,3 +1229,5 @@ LastPasswordChangeDate=Last password change date PublicVirtualCardUrl=Virtual business card page URL PublicVirtualCard=Virtual business card TreeView=Tree view +DropFileToAddItToObject=Drop a file to add it to this object +UploadFileDragDropSuccess=The file(s) have been uploaded successfully diff --git a/htdocs/main.inc.php b/htdocs/main.inc.php index 8f539c507b4..30fde1ef185 100644 --- a/htdocs/main.inc.php +++ b/htdocs/main.inc.php @@ -1388,7 +1388,14 @@ if (!defined('NOREQUIREMENU')) { $menumanager->loadMenu(); } - +if (!empty(GETPOST('seteventmessages', 'alpha'))) { + $message = GETPOST('seteventmessages', 'alpha'); + $messages = explode(',', $message); + foreach ($messages as $key => $msg) { + $tmp = explode(':', $msg); + setEventMessages($tmp[0], null, !empty($tmp[1]) ? $tmp[1] : 'mesgs'); + } +} // Functions diff --git a/htdocs/modulebuilder/template/myobject_card.php b/htdocs/modulebuilder/template/myobject_card.php index c6cf1b43c26..4234089971b 100644 --- a/htdocs/modulebuilder/template/myobject_card.php +++ b/htdocs/modulebuilder/template/myobject_card.php @@ -333,7 +333,7 @@ if (($id || $ref) && $action == 'edit') { if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'create'))) { $head = myobjectPrepareHead($object); - print dol_get_fiche_head($head, 'card', $langs->trans("MyObject"), -1, $object->picto); + print dol_get_fiche_head($head, 'card', $langs->trans("MyObject"), -1, $object->picto, 0, '', '', 0, '', 1); $formconfirm = ''; diff --git a/htdocs/theme/eldy/global.inc.php b/htdocs/theme/eldy/global.inc.php index cab0cb247ca..74b4257f7e6 100644 --- a/htdocs/theme/eldy/global.inc.php +++ b/htdocs/theme/eldy/global.inc.php @@ -7591,6 +7591,28 @@ div.clipboardCPValue.hidewithsize { /* filter: blur(4px); */ } +/* ============================================================================== */ +/* For drag and drop feature */ +/* ============================================================================== */ + +.cssDragDropArea{ + position: relative; +} +.highlightDragDropArea{ + border: 2px #000 dashed !important; + background-color: #bbbbbb !important; +} +.highlightDragDropArea * :not(.dragDropAreaMessage *){ + opacity:0.7; + filter: blur(3px) grayscale(100%); +} +.dragDropAreaMessage { + position: absolute; + left:50%; + top:50%; + transform: translate(-50%, -50%); + text-align:center; +} /* ============================================================================== */ /* CSS style used for small screen */ diff --git a/htdocs/theme/md/style.css.php b/htdocs/theme/md/style.css.php index 29e460a7c4f..943fad9e127 100644 --- a/htdocs/theme/md/style.css.php +++ b/htdocs/theme/md/style.css.php @@ -7508,6 +7508,28 @@ div.clipboardCPValue.hidewithsize { zoom: 0.20; } +/* ============================================================================== */ +/* For drag and drop feature */ +/* ============================================================================== */ + +.cssDragDropArea{ + position: relative; +} +.highlightDragDropArea{ + border: 2px #000 dashed !important; + background-color: #bbbbbb !important; +} +.highlightDragDropArea * :not(.dragDropAreaMessage *){ + opacity:0.7; + filter: blur(3px) grayscale(100%); +} +.dragDropAreaMessage { + position: absolute; + left:50%; + top:50%; + transform: translate(-50%, -50%); + text-align:center; +} /* ============================================================================== */ /* CSS style used for small screen */