WIP file attachment on expense report lines

This commit is contained in:
Laurent Destailleur 2019-03-24 13:27:26 +01:00
parent 5ff76e2c13
commit fad6efd86c
4 changed files with 24 additions and 23 deletions

View File

@ -1828,19 +1828,18 @@ function deleteFilesIntoDatabaseIndex($dir, $file, $mode = 'uploaded')
function dol_convert_file($fileinput, $ext = 'png', $fileoutput = '')
{
global $langs;
if (class_exists('Imagick'))
{
$image=new Imagick();
$image=new Imagick();
try {
$ret = $image->readImage($fileinput);
$ret = $image->readImage($fileinput);
} catch(Exception $e) {
dol_syslog("Failed to read image using Imagick. Try to install package 'apt-get install ghostscript'.", LOG_WARNING);
dol_syslog("Failed to read image using Imagick (Try to install package 'apt-get install ghostscript'): ".$e->getMessage(), LOG_WARNING);
return 0;
}
if ($ret)
{
$ret = $image->setImageFormat($ext);
$ret = $image->setImageFormat($ext);
if ($ret)
{
if (empty($fileoutput)) $fileoutput=$fileinput.".".$ext;

View File

@ -1390,7 +1390,7 @@ function dol_banner_tab($object, $paramid, $morehtml = '', $shownav = 1, $fieldi
$fileimagebis = $file.'_preview-0.png'; // If PDF has more than one page
$relativepathimage = $relativepath.'_preview.png';
// Si fichier PDF existe
// If PDF file exists
if (file_exists($file))
{
$encfile = urlencode($file);
@ -1399,7 +1399,7 @@ function dol_banner_tab($object, $paramid, $morehtml = '', $shownav = 1, $fieldi
&& (! file_exists($fileimagebis) || (filemtime($fileimagebis) < filemtime($file)))
)
{
if (empty($conf->global->MAIN_DISABLE_PDF_THUMBS)) // If you experienc trouble with pdf thumb generation and imagick, you can disable here.
if (empty($conf->global->MAIN_DISABLE_PDF_THUMBS)) // If you experience trouble with pdf thumb generation and imagick, you can disable here.
{
include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
$ret = dol_convert_file($file, 'png', $fileimage);
@ -1428,7 +1428,7 @@ function dol_banner_tab($object, $paramid, $morehtml = '', $shownav = 1, $fieldi
}
elseif (! $phototoshow)
{
$phototoshow = $form->showphoto($modulepart, $object, 0, 0, 0, 'photoref', 'small', 1, 0, $maxvisiblephotos);
$phototoshow.= $form->showphoto($modulepart, $object, 0, 0, 0, 'photoref', 'small', 1, 0, $maxvisiblephotos);
}
if ($phototoshow)
@ -1441,7 +1441,7 @@ function dol_banner_tab($object, $paramid, $morehtml = '', $shownav = 1, $fieldi
if (! $phototoshow) // Show No photo link (picto of pbject)
{
$morehtmlleft.='<div class="floatleft inline-block valignmiddle divphotoref">';
$morehtmlleft.='<div class="floatleft inline-block valignmiddle divphotoref">';
if ($object->element == 'action')
{
$width=80;
@ -7336,13 +7336,6 @@ function printCommonFooter($zone = 'private')
if (! empty($user->rights->debugbar->read) && is_object($debugbar))
{
$debugbar['time']->stopMeasure('pageaftermaster');
/*foreach($conf->logbuffer as $logline)
{
//print $logline."<br>\n";
//$debugbar['log']->addMessage($logline, 'ERR', false);
}*/
print '<!-- Output debugbar data -->'."\n";
print $debugbar->getRenderer()->render();
}

View File

@ -203,6 +203,7 @@ class DolLogsCollector extends MessagesCollector
$class = new ReflectionClass(new LogLevel());
$levels = $class->getConstants();
$levels['ERR'] = 'error';
$levels['WARN'] = 'warning';
return $levels;
}

View File

@ -2282,10 +2282,12 @@ else
print '$(document).ready(function() {
$( ".auploadnewfilenow" ).click(function() {
jQuery(".truploadnewfilenow").toggle();
jQuery(".trattachnewfilenow").hide();
return false;
});
$( ".aattachtodoc" ).click(function() {
jQuery(".trattachnewfilenow").toggle();
jQuery(".truploadnewfilenow").hide();
return false;
});';
if (is_array(GETPOST('attachfile', 'array')) && count(GETPOST('attachfile', 'array')))
@ -2299,14 +2301,12 @@ else
print '</td></tr>';
// Add line to upload new file
print '<tr class="oddeven truploadnewfilenow"'.(empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)?' style="display: none"':'').'>';
print '<tr class="oddeven nohover truploadnewfilenow"'.(empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)?' style="display: none"':'').'>';
print '<td colspan="'.$colspan.'">';
$modulepart = 'expensereport';
$permission = $user->rights->expensereport->creer;
$formfile=new FormFile($db);
// We define var to enable the feature to add prefix of uploaded files
$savingdocmask='';
if (empty($conf->global->MAIN_DISABLE_SUGGEST_REF_AS_PREFIX))
@ -2351,7 +2351,7 @@ else
$nbLinks=Link::count($db, $object->element, $object->id);
if ($nbFiles >= 0)
{
print '<tr class="oddeven trattachnewfilenow"'.(! GETPOSTISSET('sendit') && empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)?' style="display: none"':'').'>';
print '<tr class="oddeven nohover trattachnewfilenow"'.(! GETPOSTISSET('sendit') && empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)?' style="display: none"':'').'>';
print '<td colspan="'.$colspan.'">';
//print '<span class="opacitymedium">'.$langs->trans("AttachTheNewLineToTheDocument").'</span><br>';
$modulepart='expensereport';$maxheightmini=48;
@ -2372,10 +2372,18 @@ else
} else {
print '<a href="'.$urlforhref['url'].'" class="'.$urlforhref['css'].'" target="'.$urlforhref['target'].'" mime="'.$urlforhref['mime'].'">';
}
print '<img class="photo" height="'.$maxheightmini.'" src="'.DOL_URL_ROOT.'/viewimage.php?modulepart='.$modulepart.'&entity='.(!empty($object->entity)?$object->entity:$conf->entity).'&file='.urlencode($relativepath.$minifile).'" title="">';
print '<div class="photoref">';
print '<img class="photoexpensereport photorefcenter" height="'.$maxheightmini.'" src="'.DOL_URL_ROOT.'/viewimage.php?modulepart='.$modulepart.'&entity='.(!empty($object->entity)?$object->entity:$conf->entity).'&file='.urlencode($relativepath.$minifile).'" title="">';
print '</div>';
print '</a>';
}
else print '&nbsp;';
else
{
print '<a href=""><div class="photoref">';
//print '<img class="photoexpensereport photorefcenter" height="16" src="'.DOL_URL_ROOT.'/theme/eldy/img/object_trip.png" title="">';
print img_mime($relativepath.$minifile);
print '</div></a>';
}
print '<br>';
$checked='';
//var_dump(GETPOST($file['relativename'])); var_dump($file['relativename']); var_dump($_FILES['userfile']['name']);
@ -2391,7 +2399,7 @@ else
break;
}
}
print '<input type="checkbox"'.$checked.' name="attachfile[]" value="'.$file['relativename'].'"> '.$file['relativename'];
print '<div class="margintoponly"><input type="checkbox"'.$checked.' name="attachfile[]" value="'.$file['relativename'].'"> '.$file['relativename'].'</div>';
print '</div>';
}
print '</td></tr>';