| ";
+ //print "XX".$file['name']; //$file['name'] must be utf8
print '';
- print img_mime($file['name']).' ';
- print htmlentities(dol_trunc($file['name'],$maxlength,'middle'));
+ print img_mime($file['name'],$file['name'].' ('.dol_print_size($file['size'],0,0).')').' ';
+ print dol_trunc($file['name'],$maxlength,'middle');
print '';
print " | \n";
- print ''.dol_print_size($file['size']).' | ';
+ print ''.dol_print_size($file['size'],1,1).' | ';
print ''.dol_print_date($file['date'],"dayhour").' | ';
print '';
//print ' ';
diff --git a/htdocs/langs/en_US/main.lang b/htdocs/langs/en_US/main.lang
index aefd418c652..34836c9112a 100644
--- a/htdocs/langs/en_US/main.lang
+++ b/htdocs/langs/en_US/main.lang
@@ -231,6 +231,13 @@ MonthOfDay=Month of the day
HourShort=H
Rate=Rate
Bytes=Bytes
+KiloBytes=Kilobytes
+MegaBytes=Megabytes
+GigaBytes=Gigabytes
+b=b.
+Kb=Kb
+Mb=Mb
+Gb=Gb
Cut=Cut
Copy=Copy
Paste=Paste
diff --git a/htdocs/langs/fr_FR/main.lang b/htdocs/langs/fr_FR/main.lang
index cbcd05638b5..f3be801a66e 100644
--- a/htdocs/langs/fr_FR/main.lang
+++ b/htdocs/langs/fr_FR/main.lang
@@ -230,6 +230,13 @@ MonthOfDay=Mois du jour
HourShort=H
Rate=Taux
Bytes=Octets
+KiloBytes=Kilooctets
+MegaBytes=Megaoctets
+GigaBytes=Gigaoctets
+b=o.
+Kb=Ko
+Mb=Mo
+Gb=Go
Cut=Couper
Copy=Copier
Paste=Coller
diff --git a/htdocs/langs/fr_FR/other.lang b/htdocs/langs/fr_FR/other.lang
index 229bcf005e0..9e89208a27e 100644
--- a/htdocs/langs/fr_FR/other.lang
+++ b/htdocs/langs/fr_FR/other.lang
@@ -31,7 +31,7 @@ Notify_NOTIFY_VAL_FAC=Validation facture
Notify_NOTIFY_APP_ORDER_SUPPLIER=Approbation commande fournisseur
Notify_NOTIFY_REF_ORDER_SUPPLIER=Refus commande fournisseur
NbOfAttachedFiles=Nombre de fichiers/documents liés
-TotalSizeOfAttachedFiles=Taille total des fichiers/documents liés
+TotalSizeOfAttachedFiles=Taille total fichiers/documents liés
MaxSize=Taille maximum
AttachANewFile=Ajouter un nouveau fichier/document
LinkedObject=Objet lié
diff --git a/htdocs/lib/files.lib.php b/htdocs/lib/files.lib.php
index a2baf32a1b6..443e87d323f 100644
--- a/htdocs/lib/files.lib.php
+++ b/htdocs/lib/files.lib.php
@@ -1,5 +1,5 @@
+/* Copyright (C) 2008-2009 Laurent Destailleur
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -24,7 +24,7 @@
*/
/**
- * \brief Scan a directory and return a list of files/directories
+ * \brief Scan a directory and return a list of files/directories. Content for string is UTF8.
* \param $path Starting path from which to search
* \param $types Can be "directories", "files", or "all"
* \param $recursive Determines whether subdirectories are searched
@@ -43,7 +43,7 @@ function dol_dir_list($path, $types="all", $recursive=0, $filter="", $excludefil
$loadsize=$mode?true:false;
// Clean parameters
- $path=eregi_replace('[\\/]+$','',$path);
+ $path=eregi_replace('[\\/]+$','',utf8_check($path)?utf8_decode($path):$path);
if (! is_dir($path)) return array();
@@ -52,6 +52,9 @@ function dol_dir_list($path, $types="all", $recursive=0, $filter="", $excludefil
$file_list = array();
while (false !== ($file = readdir($dir)))
{
+ // readdir return value in ISO and we want UTF8 in memory
+ if (! utf8_check($file)) $file=utf8_encode($file);
+
$qualified=1;
// Check if file is qualified
@@ -64,8 +67,8 @@ function dol_dir_list($path, $types="all", $recursive=0, $filter="", $excludefil
if (is_dir($path."/".$file) && (($types=="directories") || ($types=="all")))
{
// Add entry into file_list array
- if ($loaddate || $sortcriteria == 'date') $filedate=filemtime($path."/".$file);
- if ($loadsize || $sortcriteria == 'size') $filesize=filesize($path."/".$file);
+ if ($loaddate || $sortcriteria == 'date') $filedate=filemtime(utf8_check($path."/".$file)?utf8_decode($path."/".$file):$path."/".$file);
+ if ($loadsize || $sortcriteria == 'size') $filesize=filesize(utf8_check($path."/".$file)?utf8_decode($path."/".$file):$path."/".$file);
if (! $filter || eregi($filter,$path.'/'.$file))
{
@@ -87,8 +90,8 @@ function dol_dir_list($path, $types="all", $recursive=0, $filter="", $excludefil
else if (! is_dir($path."/".$file) && (($types == "files") || ($types == "all")))
{
// Add file into file_list array
- if ($loaddate || $sortcriteria == 'date') $filedate=filemtime($path."/".$file);
- if ($loadsize || $sortcriteria == 'size') $filesize=filesize($path."/".$file);
+ if ($loaddate || $sortcriteria == 'date') $filedate=filemtime(utf8_check($path."/".$file)?utf8_decode($path."/".$file):$path."/".$file);
+ if ($loadsize || $sortcriteria == 'size') $filesize=filesize(utf8_check($path."/".$file)?utf8_decode($path."/".$file):$path."/".$file);
if (! $filter || eregi($filter,$path.'/'.$file))
{
$file_list[] = array(
@@ -193,19 +196,18 @@ function dol_mimetype($file)
*/
function dol_dir_is_emtpy($folder)
{
- if (is_dir($folder))
+ $newfolder=utf8_check($folder)?utf8_decode($folder):$folder; // The opendir need ISO strings
+ if (is_dir($newfolder))
{
- $handle = opendir($folder);
- while( (gettype( $name = readdir($handle)) != "boolean")){
+ $handle = opendir($newfolder);
+ while ((gettype( $name = readdir($handle)) != "boolean"))
+ {
$name_array[] = $name;
}
- foreach($name_array as $temp)
- $folder_content .= $temp;
+ foreach($name_array as $temp) $folder_content .= $temp;
- if($folder_content == "...")
- return true;
- else
- return false;
+ if ($folder_content == "...") return true;
+ else return false;
closedir($handle);
}
@@ -221,16 +223,18 @@ function dol_dir_is_emtpy($folder)
function dol_count_nb_of_line($file)
{
$nb=0;
+
+ $newfile=utf8_check($file)?utf8_decode($file):$file; // The fopen need ISO strings
//print 'x'.$file;
- $fp=fopen($file,'r');
+ $fp=fopen($newfile,'r');
if ($fp)
{
- while (!feof($fp))
- {
- $line=fgets($fp);
- $nb++;
- }
- fclose($fp);
+ while (!feof($fp))
+ {
+ $line=fgets($fp);
+ $nb++;
+ }
+ fclose($fp);
}
else
{
diff --git a/htdocs/lib/functions.lib.php b/htdocs/lib/functions.lib.php
index 7d42fa1c942..858b518715e 100644
--- a/htdocs/lib/functions.lib.php
+++ b/htdocs/lib/functions.lib.php
@@ -698,13 +698,33 @@ function dol_date($fmt, $timestamp, $gm=0)
/**
* \brief Return string with formated size
* \param size Size to print
+ * \param shortvalue Tell if we want long value to use another unit (Ex: 1.5Kb instead of 1500b)
+ * \param shortunit Use short value of size unit
* \return string Link
*/
-function dol_print_size($size)
+function dol_print_size($size,$shortvalue=0,$shortunit=0)
{
global $langs;
+ $level=1024;
- return $size.' '.$langs->trans("Bytes");
+ // Set value text
+ if (empty($shortvalue) || $size < ($level*10))
+ {
+ $ret=$size;
+ $textunitshort=$langs->trans("b");
+ $textunitlong=$langs->trans("Bytes");
+ }
+ else
+ {
+ $ret=round($size/$level,0);
+ $textunitshort=$langs->trans("Kb");
+ $textunitlong=$langs->trans("KiloBytes");
+ }
+ // Use long or short text unit
+ if (empty($shortunit)) { $ret.=' '.$textunitlong; }
+ else { $ret.=' '.$textunitshort; }
+
+ return $ret;
}
/**
@@ -2111,11 +2131,12 @@ function print_fleche_navigation($page,$file,$options='',$nextpage,$betweenarrow
function dol_delete_file($file)
{
$ok=true;
- foreach (glob($file) as $filename)
+ $newfile=utf8_check($file)?utf8_decode($file):$file; // glob function accepts only ISO string
+ foreach (glob($newfile) as $filename)
{
$ok=unlink($filename);
- if ($ok) dol_syslog("Removed file $filename",LOG_DEBUG);
- else dol_syslog("Failed to remove file $filename",LOG_ERR);
+ if ($ok) dol_syslog("Removed file ".$filename,LOG_DEBUG);
+ else dol_syslog("Failed to remove file ".$filename,LOG_ERR);
}
return $ok;
}
@@ -2128,7 +2149,8 @@ function dol_delete_file($file)
*/
function dol_delete_dir($dir)
{
- return rmdir($dir);
+ $newdir=utf8_check($dir)?utf8_decode($dir):$dir;
+ return rmdir($newdir);
}
/**
@@ -2140,7 +2162,8 @@ function dol_delete_dir($dir)
function dol_delete_dir_recursive($dir,$count=0)
{
//dol_syslog("functions.lib:dol_delete_dir_recursive ".$dir,LOG_DEBUG);
- if ($handle = opendir("$dir"))
+ $newdir=utf8_check($dir)?utf8_decode($dir):$dir;
+ if ($handle = opendir("$newdir"))
{
while (false !== ($item = readdir($handle)))
{
|