Fix: Data in memory must always be encoded in utf8. PHP files functions need ISO, so we convert data just before and after using them.

This commit is contained in:
Laurent Destailleur
2009-10-04 15:52:16 +00:00
parent 84bc3f5b31
commit e192abc755
11 changed files with 83 additions and 41 deletions

View File

@@ -907,7 +907,7 @@ $companystatic=new Societe($db);
$now=gmmktime();
$id = $_GET['propalid'];
$id = $_GET['propalid']?$_GET['propalid']:$_GET['id'];
$ref= $_GET['ref'];
if ($id > 0 || ! empty($ref))
{
@@ -920,7 +920,7 @@ if ($id > 0 || ! empty($ref))
$product_static=new Product($db);
$propal = new Propal($db);
$propal->fetch($_GET['propalid'],$_GET['ref']);
$propal->fetch($id,$ref);
$societe = new Societe($db);
$societe->fetch($propal->socid);

View File

@@ -116,7 +116,7 @@ llxHeader();
$html = new Form($db);
$id = $_GET['propalid'];
$id = $_GET['propalid']?$_GET['propalid']:$_GET['id'];
$ref= $_GET['ref'];
if ($id > 0 || ! empty($ref))
{

View File

@@ -117,7 +117,7 @@ llxHeader();
$html = new Form($db);
$id = $_GET['facid'];
$id = $_GET['facid']?$_GET['facid']:$_GET['id'];
$ref= $_GET['ref'];
if ($id > 0 || ! empty($ref))
{

View File

@@ -256,7 +256,7 @@ if (empty($action) || $action == 'file_manager' || eregi('refresh',$action) || $
print '<tr class="liste_titre">';
print '<td class="liste_titre" align="left">'.$langs->trans("ECMSections").'</td>';
print '<td class="liste_titre" colspan="5" align="right">';
print '<a href="'.$_SERVER["PHP_SELF"].'?action=refreshmanual'.($section?'&amp;section='.$section:'').'">'.img_picto($langs->trans("Refresh"),'refresh').'</a>&nbsp;';
print '<a href="'.$_SERVER["PHP_SELF"].'?action=refreshmanual'.($section?'&amp;section='.$section:'').'">'.img_picto($langs->trans("Refresh"),'refresh').'</a>';
print '</td>';
print '</tr>';

View File

@@ -100,7 +100,7 @@ if ($_GET["facid"])
print '<table class="border" width="100%">';
// Ref
print '<tr><td width="30%" nowrap="nowrap">'.$langs->trans("Ref").'</td><td colspan="3">';
print '<tr><td width="20%" nowrap="nowrap">'.$langs->trans("Ref").'</td><td colspan="3">';
print $html->showrefnav($fac,'facid','',1,'rowid','ref',$morehtmlref);
print '</td>';
print "</tr>\n";

View File

@@ -431,7 +431,7 @@ class FormFile
if (empty($useinecm)) print_titre($langs->trans("AttachedFiles"));
else { $bc[true]=''; $bc[false]=''; };
$url=$_SERVER["PHP_SELF"];
print '<table width="100%" class="noborder">';
print '<table width="100%" class="nobordernopadding">';
print '<tr class="liste_titre">';
print_liste_field_titre($langs->trans("Documents2"),$_SERVER["PHP_SELF"],"name","",$param,'align="left"',$sortfield,$sortorder);
print_liste_field_titre($langs->trans("Size"),$_SERVER["PHP_SELF"],"size","",$param,'align="right"',$sortfield,$sortorder);
@@ -457,14 +457,15 @@ class FormFile
$var=!$var;
print "<tr $bc[$var]><td>";
//print "XX".$file['name']; //$file['name'] must be utf8
print '<a href="'.DOL_URL_ROOT.'/document.php?modulepart='.$modulepart;
if ($forcedownload) print '&type=application/binary';
print '&file='.urlencode($relativepath.$file['name']).'">';
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 '</a>';
print "</td>\n";
print '<td align="right">'.dol_print_size($file['size']).'</td>';
print '<td align="right">'.dol_print_size($file['size'],1,1).'</td>';
print '<td align="center">'.dol_print_date($file['date'],"dayhour").'</td>';
print '<td align="right">';
//print '&nbsp;';

View File

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

View File

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

View File

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

View File

@@ -1,5 +1,5 @@
<?php
/* Copyright (C) 2008 Laurent Destailleur <eldy@users.sourceforge.net>
/* Copyright (C) 2008-2009 Laurent Destailleur <eldy@users.sourceforge.net>
*
* 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($newfolder);
while ((gettype( $name = readdir($handle)) != "boolean"))
{
$handle = opendir($folder);
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,8 +223,10 @@ 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))

View File

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