NEW Can renamed attached files on products and expense reports

This commit is contained in:
Laurent Destailleur 2016-09-07 01:54:16 +02:00
parent 5aaa3028a2
commit 5fdca121aa
6 changed files with 142 additions and 57 deletions

View File

@ -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');
}
}
}
}

View File

@ -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 '<!-- html.formfile::list_of_documents -->'."\n";
if (GETPOST('action') == 'editfile' && $permtoeditline)
{
print '<form action="'.$_SERVER["PHP_SELF"].'?'.$param.'" method="POST">';
print '<input type="hidden" name="action" value="renamefile">';
print '<input type="hidden" name="id" value="'.$object->id.'">';
print '<input type="hidden" name="modulepart" value="'.$modulepart.'">';
}
print '<table width="100%" class="'.($useinecm?'nobordernopadding':'liste').'">';
print '<tr class="liste_titre">';
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 '<tr '.$bc[$var].'>';
print '<td class="tdoverflow">';
@ -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 '</a>';
if (GETPOST('action') == 'editfile' && $file['name'] == basename(GETPOST('urlfile')))
{
print '</a>';
print '<input type="hidden" name="renamefilefrom" value="'.dol_escape_htmltag($file['name']).'">';
print '<input type="text" name="renamefileto" class="quatrevingtpercent" value="'.dol_escape_htmltag($file['name']).'">';
$editline=1;
}
else
{
print $file['name'];
print '</a>';
}
print $this->showPreview($file,$modulepart,$filepath);
if (! $editline) print $this->showPreview($file,$modulepart,$filepath);
print "</td>\n";
print '<td align="right" width="80px">'.dol_print_size($file['size'],1,1).'</td>';
@ -907,55 +944,61 @@ class FormFile
else print '&nbsp;';
print '</td>';
}
// Delete or view link
// ($param must start with &)
print '<td class="valignmiddle right" width="50px">';
if ($useinecm) print '<a href="'.DOL_URL_ROOT.'/ecm/docfile.php?urlfile='.urlencode($file['name']).$param.'" class="editfilelink" rel="'.urlencode($file['name']).'">'.img_view().'</a> &nbsp; ';
if (! $editline)
{
// Delete or view link
// ($param must start with &)
print '<td class="valignmiddle right">';
if ($useinecm)
{
print '<a href="'.DOL_URL_ROOT.'/ecm/docfile.php?urlfile='.urlencode($file['name']).$param.'" class="editfilelink" rel="'.urlencode($file['name']).'">'.img_view('default', 0, 'class="paddingrightonly"').'</a>';
}
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 '<a href="'.DOL_URL_ROOT.'/core/photos_resize.php?modulepart='.urlencode($newmodulepart).'&id='.$object->id.'&file='.urlencode($relativepath.$fileinfo['filename'].'.'.strtolower($fileinfo['extension'])).'" title="'.dol_escape_htmltag($langs->trans("Resize")).'">'.img_picto($langs->trans("Resize"),DOL_URL_ROOT.'/theme/common/transform-crop-and-resize','class="paddingrightonly"',1).'</a>';
}
}
if ($permtoeditline)
{
print '<a href="'.(($useinecm && $useajax)?'#':$url.'?action=editfile&urlfile='.urlencode($filepath).$param).'" class="editfilelink" rel="'.$filepath.'">'.img_edit('default',0,'class="paddingrightonly"').'</a>';
}
}
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 '<a href="'.(($useinecm && $useajax)?'#':$url.'?action=delete&urlfile='.urlencode($filepath).$param).'" class="deletefilelink" rel="'.$filepath.'">'.img_delete().'</a>';
}
print "</td>";
}
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 '<a href="'.DOL_URL_ROOT.'/core/photos_resize.php?modulepart='.urlencode($newmodulepart).'&id='.$object->id.'&file='.urlencode($relativepath.$fileinfo['filename'].'.'.strtolower($fileinfo['extension'])).'" title="'.dol_escape_htmltag($langs->trans("Resize")).'">'.img_picto($langs->trans("Resize"),DOL_URL_ROOT.'/theme/common/transform-crop-and-resize','',1).'</a> &nbsp; ';
}
}
print '<td class="right">';
print '<input type="submit" class="button" name="renamefilesave" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
print '<input type="submit" class="button" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
print '</td>';
}
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 '<a href="'.(($useinecm && $useajax)?'#':$url.'?action=delete&urlfile='.urlencode($filepath).$param).'" class="deletefilelink" rel="'.$filepath.'">'.img_delete().'</a>';
}
else print '&nbsp;';
print "</td>";
print "</tr>\n";
}
}
@ -967,7 +1010,11 @@ class FormFile
print '</td></tr>';
}
print "</table>";
if (GETPOST('action') == 'editfile' && $permtoeditline)
{
print '</form>';
}
return $nboffiles;
}
}

View File

@ -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 "<br>";

View File

@ -2160,7 +2160,7 @@ print '<div style="width:50%">';
* 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);

View File

@ -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';

View File

@ -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