/*
$sql_get = '';
if (isset($_GET["search"]) && $_GET["search"] != '')
$sql_get .= " AND (INSTR(`name`, '".pr($_GET["search"])."'))";
$s=mysql_query("SELECT * FROM `i_cva` WHERE `active`=1 ORDER BY `id_sort` ASC");
if (mysql_num_rows($s) > 0)
{
while($r=mysql_fetch_array($s))
{
$ss=mysql_query("SELECT * FROM `i_cva_elements` WHERE `active`=1 AND `id_section`='".$r["id"]."'".$sql_get." ORDER BY `id_sort` ASC");
if (mysql_num_rows($ss) > 0)
{
echo '
';
while($rr=mysql_fetch_array($ss))
{
$link = '';
$name = trim(stripslashes($rr["name"]));
$dirFilePdf = $_SERVER['DOCUMENT_ROOT'].'/pdf/'.$name.'.pdf';
if (is_file($dirFilePdf)) $link = '/pdf/'.$name.'.pdf';
else if ($rr["link_cva"]!='') $link = $rr["link_cva"];
echo '
-
'.$name.'
';
}
echo '
';
}
}
}
*/
$cats = Array(); $files = Array();
$dir = $_SERVER['DOCUMENT_ROOT']."/pdf/";
if ($handle = opendir($dir))
{
while(false !== ($file = readdir($handle)))
{
$format = explode("|", 'pdf|PDF');
if (in_array(getExtension($file), $format))
{
$file_name = str_replace('.pdf', '', $file);
$f_f = explode(' ', $file_name);
if (!in_array($f_f[0], $cats))
$cats[] = $f_f[0];
$files[$f_f[0]][] = $file_name;
}
}
}
foreach($cats as $k=>$v)
{
$name_cat = $v;
$files_ = $files[$name_cat];
if (isset($_GET["search"]) && $_GET["search"] != '')
$files_ = preg_grep('/^'.pr($_GET["search"]).'\s.*/', $files[$name_cat]);
if (sizeof($files_) > 0)
{
echo '
';
foreach($files_ as $kk=>$vv)
{
$link = '';
$name = trim($vv);
$dirFilePdf = $_SERVER['DOCUMENT_ROOT'].'/pdf/'.$name.'.pdf';
if (is_file($dirFilePdf)) $link = '/pdf/'.$name.'.pdf';
echo '
-
'.$name.'
';
}
echo '
';
}
}
?>