LOGIC:
OpenForm("offline_storage");
echo "<table width=\"100%\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\"><tr><td width=\"185\" style=\"padding-right: 10px;\" valign=\"top\">";
OpenTable("Folders");
echo "<table width=\"100%\" style=\"border: 1px solid black; border-collapse: collapse; background-color: white;\"><tr><td>";
echo "<div><a style=\"font-family: courier;\" href=\"".$ADMIN_URL."offline_storage.php\">";
if (!isset($_GET['folder'])) echo "<strong>";
echo "offline storage";
if (!isset($_GET['folder'])) echo "</strong>";
echo "</a></div>";
$total_size = 0;
$current_size = 0;
RecurseFolder();
echo "</td></tr></table>";
CloseTable();
echo "</td><td valign=\"top\">";
if (HasErrors() || HasNotices()) {
WriteErrors();
WriteNotices();
}
OpenTable("Files");
$navigator = "";
$folder = "";
$navigator .= "<a href=\"".$ADMIN_URL."offline_storage.php\"><strong>offline storage</strong></a>";
$get_folder = str_replace(";", "/", $_GET['folder']);
if (isset($_GET['folder'])) {
$parts = explode(";", $_GET['folder']);
$fld = "";
$parent = "";
$part_ct = count($parts);
for ($i = 0; $i < $part_ct; $i++) {
if ($i == $part_ct - 1) {
$parent = substr($fld, 0, strlen($fld) - 1);
}
$fld .= $parts[$i].";";
$navigator .= " / <a href=\"".$ADMIN_URL."offline_storage.php?folder=".substr($fld, 0, strlen($fld) - 1)."\"><strong>".$parts[$i]."</strong></a>";
}
$folder = $OFFLINE_STORAGE_ROOT.$get_folder;
} else {
$folder = $OFFLINE_STORAGE_ROOT;
}
if ($get_folder == SanitizePath($get_folder) && file_exists($folder) && is_dir($folder)) {
$dir = opendir($folder);
echo $navigator."<br> ";
$ct = 0;
$foldersize = 0;
while ($file = readdir($dir)) {
if ($ct == 0) {
echo "<table width=\"100%\" style=\"background-color: white; color: #333344; border: 1px solid black; border-collapse: collapse\">";
}
$fullpath = $folder."/".$file;
if (1 != 2) {
$usr_info = posix_getpwuid(fileowner($fullpath));
$grp_info = posix_getgrgid(filegroup($fullpath));
$filesize = filesize($fullpath);
$permissions = GetPermissions($fullpath);
$filedate = date("M d H:i", filemtime($fullpath));
$is_file = is_file($fullpath);
$is_dir = is_dir($fullpath);
$deleted = FALSE;
$style = "";
$disk_free = disk_free_space($fullpath);
// Fix the filenames so that they are valid HTTP Post variable NAMES (not values).
// i.e., filenames can have spaces, but $_POST['file name.ext'] is invalid. PHP would interpret
// the posted variable as 'file_name_ext'. We'll just replace the bad characters with something
// else just for the purposes of comparison.
$fixfile = str_replace(".", "_DOT_", $file);
$fixfile = str_replace(" ", "_SPC_", $fixfile);
echo "<tr>";
if ($is_file) {
if (isset($_POST["delete_$fixfile"]) && !empty($_POST["delete_$fixfile"]) && $_POST["delete_$fixfile"] == "1") {
echo " <td align=\"center\" width=\"25\">-</td>";
if (unlink($fullpath)) {
$style = " text-decoration: line-through; color: #aaaaaa;";
$deleted = TRUE;
} else {
$style = " font-weight: bold; color: red;";
}
} else {
echo " <td align=\"center\" width=\"25\"><input type=\"checkbox\" name=\"delete_$fixfile\" value=\"1\" /></td>";
}
} else if ($is_dir) {
if ($file != "." && $file != "..") {
if (isset($_POST["delete_$fixfile"]) && !empty($_POST["delete_$fixfile"]) && $_POST["delete_$fixfile"] == "1") {
echo " <td align=\"center\" width=\"25\">-</td>";
if (KillFolder($fullpath)) {
$style = " text-decoration: line-through; color: #aaaaaa;";
$deleted = TRUE;
} else {
$style = " font-weight: bold; color: red;";
}
} else {
echo " <td align=\"center\" width=\"25\"><input type=\"checkbox\" name=\"delete_$fixfile\" value=\"1\" /></td>";
}
} else {
echo " <td align=\"center\" width=\"25\">-</td>";
}
}
echo " <td width=\"100\" style=\"font-family: courier;".$style."\">".$permissions."</td>";
echo " <td width=\"75\" style=\"font-family: courier;".$style."\">".$usr_info['name']."</td>";
echo " <td width=\"75\" style=\"font-family: courier;".$style."\">".$usr_info['name']."</td>";
echo " <td width=\"50\" style=\"font-family: courier;".$style."\" align=\"right\">".number_format($filesize, 0)."</td>";
echo " <td width=\"125\" style=\"font-family: courier;".$style."\" align=\"center\">".$filedate."</td>";
if ($is_file) {
echo " <td style=\"font-family: courier;".$style."\">";
if (!$deleted) echo "<a style=\"font-family: courier;\" href=\"".$BASE_URL."download.php?offline=".urlencode($file).(isset($_GET['folder']) ? "&folder=".$_GET['folder'] : "")."\">";
echo $file;
if (!$deleted) echo "</a>";
echo "</td>";
if (!$deleted) $foldersize += $filesize;
} else if ($is_dir) {
if ($file == ".") {
echo " <td style=\"font-family: courier;\"><a href=\"".$ADMIN_URL."offline_storage.php".((isset($_GET['folder']) && !empty($_GET['folder'])) ? "?folder=".$_GET['folder'] : "")."\" style=\"font-family: courier; color: #5555EE;\">.</a></td>";
} else if ($file == "..") {
echo " <td style=\"font-family: courier;\"><a href=\"".$ADMIN_URL."offline_storage.php".(!empty($parent) ? "?folder=".$parent : "")."\" style=\"font-family: courier; color: #5555EE;\">..</a></td>";
} else {
$prepend = "";
if (isset($_GET['folder']) && !empty($_GET['folder'])) {
$prepend = $_GET['folder'].";";
}
echo " <td style=\"font-family: courier;\"><a href=\"".$ADMIN_URL."offline_storage.php?folder=".$prepend.$file."\" style=\"font-family: courier; color: #5555EE;\">$file</a></td>";
}
}
echo "</tr>";
$ct++;
}
}
if ($ct == 0) {
echo "<div>No files.</div>";
} else {
echo "<tr><td> </td><td style=\"padding: 3px 3px 3px 3px; font-family: courier;\" colspan=\"6\">";
echo " ";
echo "</td></tr>";
echo "<tr><td> </td><td style=\"padding: 3px 3px 3px 3px; font-family: courier;\" colspan=\"6\">";
echo "Files Size ".str_replace(" ", " ", Pad(number_format($foldersize, 0), 15, " ", "begin"))." bytes ".str_replace(" ", " ", Pad(number_format(($foldersize / 1048576), 2), 10, " ", "begin"))." MB";
echo "</td></tr>";
echo "<tr><td> </td><td style=\"padding: 3px 3px 3px 3px; font-family: courier;\" colspan=\"6\">";
echo "Folder Size ".str_replace(" ", " ", Pad(number_format($current_size, 0), 15, " ", "begin"))." bytes ".str_replace(" ", " ", Pad(number_format(($current_size / 1048576), 2), 10, " ", "begin"))." MB";
echo "</td></tr>";
echo "<tr><td> </td><td style=\"padding: 3px 3px 3px 3px; font-family: courier;\" colspan=\"6\">";
echo "Total Size ".str_replace(" ", " ", Pad(number_format($total_size, 0), 15, " ", "begin"))." bytes ".str_replace(" ", " ", Pad(number_format(($total_size / 1048576), 2), 10, " ", "begin"))." MB";
echo "</td></tr>";
echo "<tr><td> </td><td style=\"padding: 3px 3px 3px 3px; font-family: courier;\" colspan=\"6\">";
echo "Disk Free ".str_replace(" ", " ", Pad(number_format($disk_free, 0), 15, " ", "begin"))." bytes ".str_replace(" ", " ", Pad(number_format(($disk_free / 1048576), 2), 10, " ", "begin"))." MB";
echo "</td></tr>";
echo "<tr><td> </td><td style=\"padding: 3px 3px 3px 3px; font-family: courier;\" colspan=\"6\">";
echo " ";
echo "</td></tr>";
echo "<tr><td> </td><td style=\"padding: 3px 3px 3px 3px;\" colspan=\"6\"><input type=\"submit\" name=\"action\" value=\"Delete Selected Files\"></td></tr>";
echo "</table>";
}
} else {
echo "Invalid Path : ".$folder;
}
CloseTable();
echo "</td></tr></table>\r\n";
CloseForm();
require_once($ROOT_DIRECTORY."_footer.php");