fix: Warning : Invalid argument supplied for foreach()

This commit is contained in:
Grand Philippe 2012-09-18 18:00:05 +02:00
parent d25e8fc584
commit 2bcbd7dc2a

View File

@ -450,46 +450,49 @@ class FormFile
} }
// Loop on each file found // Loop on each file found
foreach($file_list as $file) if (is_array($file_list))
{ {
$var=!$var; foreach($file_list as $file)
{
$var=!$var;
// Define relative path for download link (depends on module) // Define relative path for download link (depends on module)
$relativepath=$file["name"]; // Cas general $relativepath=$file["name"]; // Cas general
if ($filename) $relativepath=$filename."/".$file["name"]; // Cas propal, facture... if ($filename) $relativepath=$filename."/".$file["name"]; // Cas propal, facture...
// Autre cas // Autre cas
if ($modulepart == 'donation') { $relativepath = get_exdir($filename,2).$file["name"]; } if ($modulepart == 'donation') { $relativepath = get_exdir($filename,2).$file["name"]; }
if ($modulepart == 'export') { $relativepath = $file["name"]; } if ($modulepart == 'export') { $relativepath = $file["name"]; }
$out.= "<tr ".$bc[$var].">"; $out.= "<tr ".$bc[$var].">";
// Show file name with link to download // Show file name with link to download
$out.= '<td nowrap="nowrap">'; $out.= '<td nowrap="nowrap">';
$out.= '<a href="'.DOL_URL_ROOT . '/document.php?modulepart='.$modulepart.'&amp;file='.urlencode($relativepath).'"'; $out.= '<a href="'.DOL_URL_ROOT . '/document.php?modulepart='.$modulepart.'&amp;file='.urlencode($relativepath).'"';
$mime=dol_mimetype($relativepath,'',0); $mime=dol_mimetype($relativepath,'',0);
if (preg_match('/text/',$mime)) $out.= ' target="_blank"'; if (preg_match('/text/',$mime)) $out.= ' target="_blank"';
$out.= '>'; $out.= '>';
$out.= img_mime($file["name"],$langs->trans("File").': '.$file["name"]).' '.dol_trunc($file["name"],$maxfilenamelength); $out.= img_mime($file["name"],$langs->trans("File").': '.$file["name"]).' '.dol_trunc($file["name"],$maxfilenamelength);
$out.= '</a>'."\n"; $out.= '</a>'."\n";
$out.= '</td>'; $out.= '</td>';
// Show file size // Show file size
$size=(! empty($file['size'])?$file['size']:dol_filesize($filedir."/".$file["name"])); $size=(! empty($file['size'])?$file['size']:dol_filesize($filedir."/".$file["name"]));
$out.= '<td align="right" nowrap="nowrap">'.dol_print_size($size).'</td>'; $out.= '<td align="right" nowrap="nowrap">'.dol_print_size($size).'</td>';
// Show file date // Show file date
$date=(! empty($file['date'])?$file['date']:dol_filemtime($filedir."/".$file["name"])); $date=(! empty($file['date'])?$file['date']:dol_filemtime($filedir."/".$file["name"]));
$out.= '<td align="right" nowrap="nowrap">'.dol_print_date($date, 'dayhour').'</td>'; $out.= '<td align="right" nowrap="nowrap">'.dol_print_date($date, 'dayhour').'</td>';
if ($delallowed) if ($delallowed)
{ {
$out.= '<td align="right">'; $out.= '<td align="right">';
$out.= '<a href="'.$urlsource.(strpos($urlsource,'?')?'&':'?').'action=remove_file&file='.urlencode($relativepath); $out.= '<a href="'.$urlsource.(strpos($urlsource,'?')?'&':'?').'action=remove_file&file='.urlencode($relativepath);
$out.= ($param?'&'.$param:''); $out.= ($param?'&'.$param:'');
//$out.= '&modulepart='.$modulepart; // TODO obsolete ? //$out.= '&modulepart='.$modulepart; // TODO obsolete ?
//$out.= '&urlsource='.urlencode($urlsource); // TODO obsolete ? //$out.= '&urlsource='.urlencode($urlsource); // TODO obsolete ?
$out.= '">'.img_delete().'</a></td>'; $out.= '">'.img_delete().'</a></td>';
} }
}
$out.= '</tr>'; $out.= '</tr>';