diff --git a/htdocs/core/actions_linkedfiles.inc.php b/htdocs/core/actions_linkedfiles.inc.php index 8977938eb4a..6f2d4a2128f 100644 --- a/htdocs/core/actions_linkedfiles.inc.php +++ b/htdocs/core/actions_linkedfiles.inc.php @@ -140,4 +140,33 @@ elseif ($action == 'confirm_updateline' && GETPOST('save') && GETPOST('link', 'a //error fetching } } - +elseif ($action == 'renamefile' && GETPOST('renamefilesave')) +{ + if ($object->id) + { + // For documents pages, upload_dir contains already path to file from module dir, so we clean path into urlfile. + //var_dump($upload_dir);exit; + if (! empty($upload_dir)) + { + $filenamefrom=dol_sanitizeFileName(GETPOST('renamefilefrom')); + $filenameto=dol_sanitizeFileName(GETPOST('renamefileto')); + if ($filenamefrom && $filenameto) + { + $srcpath = $upload_dir.'/'.$filenamefrom; + $destpath = $upload_dir.'/'.$filenameto; + + $result = dol_move($srcpath, $destpath); + if ($result) + { + $object->addThumbs($destpath); + + // TODO Add revert function of addThumbs + //$object->delThumbs($srcpath); + + setEventMessages($langs->trans("FileRenamed"), null); + } + else setEventMessages($langs->trans("ErrorFailToRenameFile", $filenamefrom, $filenameto), null, 'errors'); + } + } + } +} diff --git a/htdocs/core/class/html.formfile.class.php b/htdocs/core/class/html.formfile.class.php index 06eb8c0c5d2..67c8f015740 100644 --- a/htdocs/core/class/html.formfile.class.php +++ b/htdocs/core/class/html.formfile.class.php @@ -782,16 +782,17 @@ class FormFile * @param string $param Parameters on sort links (param must start with &, example &aaa=bbb&ccc=ddd) * @param int $forcedownload Force to open dialog box "Save As" when clicking on file * @param string $relativepath Relative path of docs (autodefined if not provided) - * @param int $permtodelete Permission to delete + * @param int $permonobject Permission on object (so permission to delete or crop document) * @param int $useinecm Change output for use in ecm module * @param string $textifempty Text to show if filearray is empty ('NoFileFound' if not defined) * @param int $maxlength Maximum length of file name shown * @param string $title Title before list * @param string $url Full url to use for click links ('' = autodetect) * @param int $showrelpart 0=Show only filename (default), 1=Show first level 1 dir + * @param int $permtoeditline Permission to edit document line (-1 is deprecated) * @return int <0 if KO, nb of files shown if OK */ - function list_of_documents($filearray,$object,$modulepart,$param='',$forcedownload=0,$relativepath='',$permtodelete=1,$useinecm=0,$textifempty='',$maxlength=0,$title='',$url='', $showrelpart=0) + function list_of_documents($filearray,$object,$modulepart,$param='',$forcedownload=0,$relativepath='',$permonobject=1,$useinecm=0,$textifempty='',$maxlength=0,$title='',$url='', $showrelpart=0, $permtoeditline=-1) { global $user, $conf, $langs, $hookmanager; global $bc; @@ -805,7 +806,7 @@ class FormFile 'param' => $param, 'forcedownload' => $forcedownload, 'relativepath' => $relativepath, - 'permtodelete' => $permtodelete, + 'permtodelete' => $permonobject, 'useinecm' => $useinecm, 'textifempty' => $textifempty, 'maxlength' => $maxlength, @@ -822,10 +823,33 @@ class FormFile { $param = (isset($object->id)?'&id='.$object->id:'').$param; + if ($permtoeditline < 0) // Old behaviour for backward compatibility. New feature should call method with value 0 or 1 + { + $permtoeditline=0; + if (in_array($modulepart, array('product','produit','service'))) + { + if ($user->rights->produit->creer && $object->type == Product::TYPE_PRODUCT) $permtoeditline=1; + if ($user->rights->service->creer && $object->type == Product::TYPE_SERVICE) $permtoeditline=1; + } + } + if (empty($conf->global->MAIN_UPLOAD_DOC)) + { + $permtoeditline=0; + $permonobject=0; + } + // Show list of existing files if (empty($useinecm)) print load_fiche_titre($title?$title:$langs->trans("AttachedFiles")); if (empty($url)) $url=$_SERVER["PHP_SELF"]; + print ''."\n"; + if (GETPOST('action') == 'editfile' && $permtoeditline) + { + print '
'; + } + return $nboffiles; } } diff --git a/htdocs/core/tpl/document_actions_post_headers.tpl.php b/htdocs/core/tpl/document_actions_post_headers.tpl.php index 35d1299fd8f..83d38793072 100644 --- a/htdocs/core/tpl/document_actions_post_headers.tpl.php +++ b/htdocs/core/tpl/document_actions_post_headers.tpl.php @@ -20,7 +20,7 @@ $langs->load("link"); if (empty($relativepathwithnofile)) $relativepathwithnofile=''; - +if (empty($permtoedit)) $permtoedit=-1; /* * Confirm form to delete @@ -80,7 +80,14 @@ $formfile->list_of_documents( $param, 0, $relativepathwithnofile, // relative path with no file. For example "moduledir/0/1" - $permission + $permission, + 0, + '', + 0, + '', + '', + 0, + $permtoedit ); print "