- Where there are 2 documents, they are named ###-Product Name-A.pdf and ###-Product Name-B.pdf
- Where there is only 1 document, it is named ###-Product Name-anything else.pdf or ###-Product Name.pdf
and no subdirectories under /uploads/products/.
Code: Select all
global $gCms;
$dir = "uploads/products/";
echo "<table>\n";
echo "<thead>\n";
echo "<tr>";
echo "<th>Product Number</th>";
echo "<th>Product Name</th>";
echo "<th>Document One</th>";
echo "<th>Document Two</th>";
echo "</tr>\n";
echo "</thead>\n";
echo "<tbody>\n";
if ($handle = opendir($dir)) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
$fileList[] = $file;
}
}
sort ($fileList);
reset ($fileList);
while (list ($key, $val) = each ($fileList)) {
$products1 = explode(".", $val);
$products2 = explode("-", $products1[0]);
if ($products2[2]=="A") {
echo "<tr><td>$products2[0]</td>";
echo "<td>$products2[1]</td>";
if ($params['linked']=='true') {
echo "<td><a href='$dir$val' target='_blank'>$val</a></td>";
} else {
echo "<td>$val</td>";
}
} elseif ($products2[2]=="B") {
if ($params['linked']=='true') {
echo "<td><a href='$dir$val' target='_blank'>$val</a></td></tr>\n";
} else {
echo "<td>$val</td></tr>\n";
}
} else {
echo "<tr><td>$products2[0]</td>";
echo "<td>$products2[1]</td>";
if ($params['linked']=='true') {
echo "<td><a href='$dir$val' target='_blank'>$val</a></td></tr>\n";
} else {
echo "<td>$val</td></tr>\n";
}
}
}
closedir($handle);
}
echo "</tbody>\n";
echo "</table>\n";
if ($params['linked']=='false') {
echo "<p>You must be logged in to download these documents.</p>";
}
Nullig