From d32bcc22c3f602c1afa825e7c6ee4bbc016f5a37 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 20 Jan 2008 14:29:59 +0000 Subject: [PATCH] La fonction dolibarr_list_dir peut trier par nom --- htdocs/lib/functions.inc.php | 152 ++++++++++++++++++----------------- 1 file changed, 78 insertions(+), 74 deletions(-) diff --git a/htdocs/lib/functions.inc.php b/htdocs/lib/functions.inc.php index eafbc0de0a0..56e8cfdcf75 100644 --- a/htdocs/lib/functions.inc.php +++ b/htdocs/lib/functions.inc.php @@ -2176,87 +2176,91 @@ function create_exdir($dir) \param $recursive Determines whether subdirectories are searched \param $filter Regex for filter \param $exludefilter Regex for exclude filter - \param $sortcriteria Sort criteria ("date","size") + \param $sortcriteria Sort criteria ("name","date","size") \param $sortorder Sort order (SORT_ASC, SORT_DESC) \return array Array of array('name'=>xxx,'date'=>yyy,'size'=>zzz) */ -function dolibarr_dir_list($path, $types="all", $recursive=0, $filter="", $excludefilter="", $sortcriteria="", $sortorder=SORT_ASC) +function dolibarr_dir_list($path, $types="all", $recursive=0, $filter="", $excludefilter="", $sortcriteria="name", $sortorder=SORT_ASC) { - dolibarr_syslog("functions.inc.php::dolibarr_dir_list $path"); - - if (! is_dir($path)) return array(); - - if ($dir = opendir($path)) - { - $file_list = array(); - while (false !== ($file = readdir($dir))) - { - $qualified=1; - - // Check if file is qualified - if (eregi('^\.',$file)) $qualified=0; - if ($excludefilter && eregi($excludefilter,$file)) $qualified=0; - - if ($qualified) - { - // Check whether this is a file or directory and whether we're interested in that type - if ((is_dir($path."/".$file)) && (($types=="directories") || ($types=="all"))) - { - // Add entry into file_list array - if ($sortcriteria == 'date') $filedate=filemtime($path."/".$file); - if ($sortcriteria == 'size') $filesize=filesize($path."/".$file); - - if (! $filter || eregi($filter,$path.'/'.$file)) - { - $file_list[] = array( - "name" => $file, - "fullname" => $path.'/'.$file, - "date" => $filedate, - "size" => $filesize - ); - } - - // if we're in a directory and we want recursive behavior, call this function again - if ($recursive) - { - $file_list = array_merge($file_list, dolibarr_dir_list($path."/".$file."/", $types, $recursive, $filter, $excludefilter, $sortcriteria, $sortorder)); - } - } - else if (($types == "files") || ($types == "all")) - { - // Add file into file_list array - if ($sortcriteria == 'date') $filedate=filemtime($path."/".$file); - if ($sortcriteria == 'size') $filesize=filesize($path."/".$file); - if (! $filter || eregi($filter,$path.'/'.$file)) - { - $file_list[] = array( - "name" => $file, - "fullname" => $path.'/'.$file, - "date" => $filedate, - "size" => $filesize - ); - } - } - } - } - closedir($dir); - - // Obtain a list of columns - $myarray=array(); - foreach ($file_list as $key => $row) + dolibarr_syslog("functions.inc.php::dolibarr_dir_list $path"); + + $loaddate=false; + $loadsize=false; + + if (! is_dir($path)) return array(); + + if ($dir = opendir($path)) { - $myarray[$key] = $row[$sortcriteria]; + $file_list = array(); + while (false !== ($file = readdir($dir))) + { + $qualified=1; + + // Check if file is qualified + if (eregi('^\.',$file)) $qualified=0; + if ($excludefilter && eregi($excludefilter,$file)) $qualified=0; + + if ($qualified) + { + // Check whether this is a file or directory and whether we're interested in that type + 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 (! $filter || eregi($filter,$path.'/'.$file)) + { + $file_list[] = array( + "name" => $file, + "fullname" => $path.'/'.$file, + "date" => $filedate, + "size" => $filesize + ); + } + + // if we're in a directory and we want recursive behavior, call this function again + if ($recursive) + { + $file_list = array_merge($file_list, dolibarr_dir_list($path."/".$file."/", $types, $recursive, $filter, $excludefilter, $sortcriteria, $sortorder)); + } + } + else if (($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 (! $filter || eregi($filter,$path.'/'.$file)) + { + $file_list[] = array( + "name" => $file, + "fullname" => $path.'/'.$file, + "date" => $filedate, + "size" => $filesize + ); + } + } + } + } + closedir($dir); + + // Obtain a list of columns + $myarray=array(); + foreach ($file_list as $key => $row) + { + $myarray[$key] = $row[$sortcriteria]; + } + // Sort the data + array_multisort($myarray, $sortorder, $file_list); + + return $file_list; + } + else + { + return false; } - // Sort the data - array_multisort($myarray, $sortorder, $file_list); - - return $file_list; - } - else - { - return false; - } } + /** \brief Retourne le numéro de la semaine par rapport a une date \param time Date au format 'timestamp'