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 '
'; + print ''; + print ''; + print ''; + } print ''; print ''; print_liste_field_titre($langs->trans("Documents2"),$url,"name","",$param,'align="left"',$sortfield,$sortorder); @@ -860,6 +884,9 @@ class FormFile $relativepath=preg_replace('/^.*\/produit\//','',$file['path']).'/'; } $var=!$var; + + $editline=0; + print ''; print '\n"; print ''; @@ -907,55 +944,61 @@ class FormFile else print ' '; print ''; } - // Delete or view link - // ($param must start with &) - print '"; + } else { - if (image_format_supported($file['name']) > 0) - { - $permtoedit=0; - $newmodulepart=$modulepart; - if ($modulepart == 'product' || $modulepart == 'produit' || $modulepart == 'service') - { - if ($user->rights->produit->creer && $object->type == Product::TYPE_PRODUCT) $permtoedit=1; - if ($user->rights->service->creer && $object->type == Product::TYPE_SERVICE) $permtoedit=1; - $newmodulepart='produit|service'; - } - /* TODO Not yet working - if ($modulepart == 'holiday') - { - if ($user->rights->holiday->write_all) $permtoedit=1; - } - */ - - if (empty($conf->global->MAIN_UPLOAD_DOC)) $permtoedit=0; - - if ($permtoedit) - { - // Link to resize - print ''.img_picto($langs->trans("Resize"),DOL_URL_ROOT.'/theme/common/transform-crop-and-resize','',1).'   '; - } - } + print ''; } - if ($permtodelete) - { - /* - if ($file['level1name'] <> $object->id) - $filepath=$file['level1name'].'/'.$file['name']; - else - $filepath=$file['name']; - */ - $useajax=1; - if (! empty($conf->dol_use_jmobile)) $useajax=0; - if (empty($conf->use_javascript_ajax)) $useajax=0; - if (! empty($conf->global->MAIN_ECM_DISABLE_JS)) $useajax=0; - - print ''.img_delete().''; - } - else print ' '; - print ""; print "\n"; } } @@ -967,7 +1010,11 @@ class FormFile print ''; } print "
'; @@ -880,10 +907,20 @@ class FormFile print img_mime($file['name'],$file['name'].' ('.dol_print_size($file['size'],0,0).')').' '; if ($showrelpart == 1) print $relativepath; //print dol_trunc($file['name'],$maxlength,'middle'); - print $file['name']; - print ''; + if (GETPOST('action') == 'editfile' && $file['name'] == basename(GETPOST('urlfile'))) + { + print ''; + print ''; + print ''; + $editline=1; + } + else + { + print $file['name']; + print ''; + } - print $this->showPreview($file,$modulepart,$filepath); + if (! $editline) print $this->showPreview($file,$modulepart,$filepath); print "'.dol_print_size($file['size'],1,1).''; - if ($useinecm) print ''.img_view().'   '; + if (! $editline) + { + // Delete or view link + // ($param must start with &) + print ''; + if ($useinecm) + { + print ''.img_view('default', 0, 'class="paddingrightonly"').''; + } + else + { + $newmodulepart=$modulepart; + if (in_array($modulepart, array('product','produit','service'))) $newmodulepart='produit|service'; + + $disablecrop=0; + if ($modulepart == 'expensereport') $disablecrop=1; // TODO Remove this in future + + if (image_format_supported($file['name']) > 0 && ! $disablecrop) + { + if ($permtoeditline) + { + // Link to resize + print ''.img_picto($langs->trans("Resize"),DOL_URL_ROOT.'/theme/common/transform-crop-and-resize','class="paddingrightonly"',1).''; + } + } + + if ($permtoeditline) + { + print ''.img_edit('default',0,'class="paddingrightonly"').''; + } + } + if ($permonobject) + { + /* + if ($file['level1name'] <> $object->id) + $filepath=$file['level1name'].'/'.$file['name']; + else + $filepath=$file['name']; + */ + $useajax=1; + if (! empty($conf->dol_use_jmobile)) $useajax=0; + if (empty($conf->use_javascript_ajax)) $useajax=0; + if (! empty($conf->global->MAIN_ECM_DISABLE_JS)) $useajax=0; + + print ''.img_delete().''; + } + print "'; + print ''; + print ''; + print '
"; - + 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 "
"; diff --git a/htdocs/expensereport/card.php b/htdocs/expensereport/card.php index f0c21ebd3d8..74522e0337c 100644 --- a/htdocs/expensereport/card.php +++ b/htdocs/expensereport/card.php @@ -2160,7 +2160,7 @@ print '
'; * Generate documents */ -if($user->rights->expensereport->export && $object->fk_statut>0 && $action != 'edit') +if($user->rights->expensereport->export && $action != 'edit') { $filename = dol_sanitizeFileName($object->ref); $filedir = $conf->expensereport->dir_output . "/" . dol_sanitizeFileName($object->ref); diff --git a/htdocs/expensereport/document.php b/htdocs/expensereport/document.php index 00e8cfe583d..9ff90982c3e 100644 --- a/htdocs/expensereport/document.php +++ b/htdocs/expensereport/document.php @@ -123,6 +123,7 @@ if ($object->id) $modulepart = 'expensereport'; $permission = $user->rights->expensereport->creer; + $permtoedit = $user->rights->expensereport->creer; $param = '&id=' . $object->id; include_once DOL_DOCUMENT_ROOT . '/core/tpl/document_actions_post_headers.tpl.php'; diff --git a/htdocs/langs/en_US/main.lang b/htdocs/langs/en_US/main.lang index 8acf2b8621b..4fd073ee57f 100644 --- a/htdocs/langs/en_US/main.lang +++ b/htdocs/langs/en_US/main.lang @@ -67,6 +67,7 @@ SelectDate=Select a date SeeAlso=See also %s SeeHere=See here BackgroundColorByDefault=Default background color +FileRenamed=The file was successfully renamed FileUploaded=The file was successfully uploaded FileWasNotUploaded=A file is selected for attachment but was not yet uploaded. Click on "Attach file" for this. NbOfEntries=Nb of entries