mirror of
https://github.com/Dolibarr/dolibarr.git
synced 2025-12-11 12:01:23 +01:00
La fonction dolibarr_list_dir peut trier par nom
This commit is contained in:
@@ -2176,87 +2176,91 @@ function create_exdir($dir)
|
|||||||
\param $recursive Determines whether subdirectories are searched
|
\param $recursive Determines whether subdirectories are searched
|
||||||
\param $filter Regex for filter
|
\param $filter Regex for filter
|
||||||
\param $exludefilter Regex for exclude 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)
|
\param $sortorder Sort order (SORT_ASC, SORT_DESC)
|
||||||
\return array Array of array('name'=>xxx,'date'=>yyy,'size'=>zzz)
|
\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");
|
dolibarr_syslog("functions.inc.php::dolibarr_dir_list $path");
|
||||||
|
|
||||||
if (! is_dir($path)) return array();
|
$loaddate=false;
|
||||||
|
$loadsize=false;
|
||||||
if ($dir = opendir($path))
|
|
||||||
{
|
if (! is_dir($path)) return array();
|
||||||
$file_list = array();
|
|
||||||
while (false !== ($file = readdir($dir)))
|
if ($dir = opendir($path))
|
||||||
{
|
|
||||||
$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)
|
|
||||||
{
|
{
|
||||||
$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<75>ro de la semaine par rapport a une date
|
\brief Retourne le num<75>ro de la semaine par rapport a une date
|
||||||
\param time Date au format 'timestamp'
|
\param time Date au format 'timestamp'
|
||||||
|
|||||||
Reference in New Issue
Block a user