From 4c55f278ac90695c8dab5d94625313cc4c0cb6c8 Mon Sep 17 00:00:00 2001 From: Chad Davis Date: Fri, 21 Jun 2024 14:09:51 -0500 Subject: [PATCH 01/12] Update message container formatting Add shadow to container and bold text. Close #9, Close #12 --- index.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.php b/index.php index 614fa59..57c0375 100644 --- a/index.php +++ b/index.php @@ -170,7 +170,7 @@ function delete_backup_folder($folder) { gap: 10px; margin-bottom: 20px; } - .button-container button { + .button-container button, .message { box-shadow: 0 8px 8px 1px rgba(0, 0, 0, .2); font-weight: bold; } From 2536d2799124203000e413c5408da5386d36060e Mon Sep 17 00:00:00 2001 From: Chad Davis Date: Fri, 21 Jun 2024 14:36:45 -0500 Subject: [PATCH 02/12] Fix table alternating row background colors Close #1 --- index.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/index.php b/index.php index 57c0375..eacd7d6 100644 --- a/index.php +++ b/index.php @@ -209,10 +209,10 @@ function delete_backup_folder($folder) { color: #fff; } table tr:nth-child(even) { - background-color: #f0f0f0; + background-color: snow; } table tr:nth-child(odd) { - background-color: #e9ecef; + background-color: lightgray; } table th:nth-child(1), table th:nth-child(2), table td:nth-child(1), table td:nth-child(2) { @@ -262,7 +262,7 @@ function delete_backup_folder($folder) { Delete $folder): ?> - + From 196d660f1b5126d64aa2e7abd993b879089e7d7d Mon Sep 17 00:00:00 2001 From: Chad Davis Date: Mon, 24 Jun 2024 18:16:09 -0500 Subject: [PATCH 03/12] Added version number and check for updates - Added current version number to the bottom corner of the page. - Added feature to auto-compare the current version to the latest release and display message if different Close #5 --- index.php | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 50 insertions(+), 4 deletions(-) diff --git a/index.php b/index.php index eacd7d6..6147ac7 100644 --- a/index.php +++ b/index.php @@ -65,10 +65,49 @@ function delete_backup_folder($folder) { return rmdir($folder); } -$message = ''; -$messageColor = "#dc3545"; -$current_dir = getcwd(); // Get current directory -$folders = get_sibling_folders($current_dir); // Get sibling folder names excluding current directory +// Function to get the latest release tag_name from GitHub +function getLatestReleaseTag($url) { + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL, $url); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($ch, CURLOPT_USERAGENT, 'dynamiccookies/Simple-Backup-Utility'); + $response = curl_exec($ch); + curl_close($ch); + + $releases = json_decode($response, true); + return isset($releases[0]['tag_name']) ? $releases[0]['tag_name'] : ''; +} + +// Function to compare versions +function compareVersions($currentVersion, $latestVersion) { + // Remove 'v' prefix for comparison + $currentVersionClean = ltrim($currentVersion, 'v'); + $latestVersionClean = ltrim($latestVersion, 'v'); + + // Compare versions and switch on the result + switch (version_compare($currentVersionClean, $latestVersionClean)) { + case -1: + return "New version $latestVersion available!"; + case 0: + return $currentVersion; + case 1: + return "BETA RELEASE $currentVersion INSTALLED"; + default: + return 'Error: Unable to determine version status.'; + } +} + +// Define the current version constant +define('CURRENT_VERSION', 'v0.1.3'); + +// Define variables +$apiUrl = 'https://api.github.com/repos/dynamiccookies/Simple-Backup-Utility/releases'; +$current_dir = getcwd(); // Get current directory +$folders = get_sibling_folders($current_dir); // Get sibling folder names excluding current directory +$latestVersion = getLatestReleaseTag($apiUrl); +$message = ''; +$messageColor = "#dc3545"; +$versionMessage = compareVersions(CURRENT_VERSION, $latestVersion); if ($_SERVER['REQUEST_METHOD'] === 'POST') { if (isset($_POST['delete'])) { @@ -235,6 +274,12 @@ function delete_backup_folder($folder) { .trash-icon:hover { color: #c82333; } + .version-info { + position: fixed; + bottom: 0; + right: 0; + margin: 20px; + } @@ -276,5 +321,6 @@ function delete_backup_folder($folder) { +

From d6adf3d42315f15e5a972f9edc8ee16aaa0cd3c8 Mon Sep 17 00:00:00 2001 From: Chad Davis Date: Fri, 28 Jun 2024 09:04:16 -0500 Subject: [PATCH 04/12] Update version message text and formatting - Updated the version message BETA text and removed the unnecessary default text since the compareversions() function will only ever return -1, 0, or 1. - Removed unnecessary paragraph HTML tags - Updated the message CSS to decrease the margin, decrease the text size, and color and bold the version number when linked to the repo --- index.php | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/index.php b/index.php index 6147ac7..6120ec4 100644 --- a/index.php +++ b/index.php @@ -91,14 +91,12 @@ function compareVersions($currentVersion, $latestVersion) { case 0: return $currentVersion; case 1: - return "BETA RELEASE $currentVersion INSTALLED"; - default: - return 'Error: Unable to determine version status.'; + return "BETA-$currentVersion INSTALLED"; } } // Define the current version constant -define('CURRENT_VERSION', 'v0.1.3'); +define('CURRENT_VERSION', 'v0.1.4'); // Define variables $apiUrl = 'https://api.github.com/repos/dynamiccookies/Simple-Backup-Utility/releases'; @@ -278,8 +276,13 @@ function compareVersions($currentVersion, $latestVersion) { position: fixed; bottom: 0; right: 0; - margin: 20px; + margin: 10px; + font-size: small; } + .version-info a { + color: yellow; + font-weight: bold; + } @@ -321,6 +324,6 @@ function compareVersions($currentVersion, $latestVersion) { -

+
From 067d3e53eab35003180a68affa4e4332e899f5bd Mon Sep 17 00:00:00 2001 From: Chad Davis Date: Fri, 28 Jun 2024 14:31:24 -0500 Subject: [PATCH 05/12] Add confirmation when deleting a backup #7 Added a JavaScript function to prompt with confirmation when deleting a backup --- index.php | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/index.php b/index.php index 6120ec4..c2a361c 100644 --- a/index.php +++ b/index.php @@ -96,7 +96,7 @@ function compareVersions($currentVersion, $latestVersion) { } // Define the current version constant -define('CURRENT_VERSION', 'v0.1.4'); +define('CURRENT_VERSION', 'v0.1.5'); // Define variables $apiUrl = 'https://api.github.com/repos/dynamiccookies/Simple-Backup-Utility/releases'; @@ -262,6 +262,9 @@ function compareVersions($currentVersion, $latestVersion) { border-top: 1px solid #fff; margin: 20px 0; } + .inline-form { + display: inline; + } .trash-icon { cursor: pointer; background: none; @@ -284,6 +287,13 @@ function compareVersions($currentVersion, $latestVersion) { font-weight: bold; } +
@@ -314,8 +324,9 @@ function compareVersions($currentVersion, $latestVersion) { -
-
From acfd5ce185c5c57c8d74a8813f64297cf78cc3ea Mon Sep 17 00:00:00 2001 From: Chad Davis Date: Fri, 28 Jun 2024 16:52:37 -0500 Subject: [PATCH 06/12] Update commenting #18 - Moved PHP variable declarations to the top of the script - Rearranged the PHP functions to be in alphabetical order - Added extensive commenting --- index.php | 219 ++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 148 insertions(+), 71 deletions(-) diff --git a/index.php b/index.php index c2a361c..20b9b83 100644 --- a/index.php +++ b/index.php @@ -1,6 +1,43 @@ $latestVersion available!"; + case 0: + return $currentVersion; + case 1: + return "BETA-$currentVersion INSTALLED"; } - return $sibling_folders; } +/** + * Recursively deletes a folder and its contents. + * + * @param string $folder The path of the folder to delete. + * @return bool True if the folder was deleted, false otherwise. + */ +function delete_backup_folder($folder) { + if (!is_dir($folder)) { + return false; + } + $files = array_diff(scandir($folder), array('.', '..')); + foreach ($files as $file) { + $path = "$folder/$file"; + is_dir($path) ? delete_backup_folder($path) : unlink($path); + } + return rmdir($folder); +} + +/** + * Retrieves the list of backup folders in the current directory. + * + * @param string $dir The current directory path. + * @return array The list of backup folders with their creation date and timestamp. + */ function get_backup_folders($dir) { $folders = array_filter(glob($dir . '/*'), 'is_dir'); $backup_folders = []; @@ -53,20 +124,13 @@ function get_backup_folders($dir) { return $backup_folders; } -function delete_backup_folder($folder) { - if (!is_dir($folder)) { - return false; - } - $files = array_diff(scandir($folder), array('.', '..')); - foreach ($files as $file) { - $path = "$folder/$file"; - is_dir($path) ? delete_backup_folder($path) : unlink($path); - } - return rmdir($folder); -} - -// Function to get the latest release tag_name from GitHub -function getLatestReleaseTag($url) { +/** + * Gets the latest release tag from a GitHub repository. + * + * @param string $url The GitHub API URL to fetch the releases. + * @return string The latest release tag name. + */ +function get_latest_release_tag($url) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); @@ -78,65 +142,79 @@ function getLatestReleaseTag($url) { return isset($releases[0]['tag_name']) ? $releases[0]['tag_name'] : ''; } -// Function to compare versions -function compareVersions($currentVersion, $latestVersion) { - // Remove 'v' prefix for comparison - $currentVersionClean = ltrim($currentVersion, 'v'); - $latestVersionClean = ltrim($latestVersion, 'v'); - - // Compare versions and switch on the result - switch (version_compare($currentVersionClean, $latestVersionClean)) { - case -1: - return "New version $latestVersion available!"; - case 0: - return $currentVersion; - case 1: - return "BETA-$currentVersion INSTALLED"; +/** + * Retrieves the names of sibling directories excluding the current directory. + * + * @param string $dir The current directory path. + * @return array The list of sibling directory names. + */ +function get_sibling_folders($dir) { + $parent_dir = dirname($dir); + $folders = array_filter(glob($parent_dir . '/*'), 'is_dir'); + $sibling_folders = []; + foreach ($folders as $folder) { + $folder_name = basename($folder); + if ($folder_name !== basename($dir)) { + $sibling_folders[] = $folder_name; + } } + return $sibling_folders; } -// Define the current version constant -define('CURRENT_VERSION', 'v0.1.5'); - -// Define variables -$apiUrl = 'https://api.github.com/repos/dynamiccookies/Simple-Backup-Utility/releases'; -$current_dir = getcwd(); // Get current directory -$folders = get_sibling_folders($current_dir); // Get sibling folder names excluding current directory -$latestVersion = getLatestReleaseTag($apiUrl); -$message = ''; -$messageColor = "#dc3545"; -$versionMessage = compareVersions(CURRENT_VERSION, $latestVersion); - +// **************************************************************************************** +// * Handle POST requests for folder deletion and backup creation +// **************************************************************************************** if ($_SERVER['REQUEST_METHOD'] === 'POST') { + // Check if a delete action is requested if (isset($_POST['delete'])) { + // Construct the path to the folder to delete $folder_to_delete = $current_dir . '/' . $_POST['delete']; + + // Attempt to delete the folder if (delete_backup_folder($folder_to_delete)) { + // Set success message if deletion is successful $message = "The folder '{$_POST['delete']}' has been deleted."; - $messageColor = "#28a745"; + $messageColor = "#28a745"; // Green color for success message } else { + // Set error message if deletion fails $message = "Failed to delete the folder '{$_POST['delete']}'."; } + // Process backup creation if 'delete' action is not requested } else { + + // Sanitize and prepare the backup folder name $input_name = preg_replace('/\s+/', '-', trim($_POST['folder_name'])); // Replace spaces with dashes + // Check if a valid backup folder is selected if (isset($_POST['backup']) && in_array($_POST['backup'], $folders)) { + // Define the source path for backup $source = "../{$_POST['backup']}"; } else { + // Set error message for invalid backup folder selection $message = 'Invalid backup folder selected.'; } + // Proceed if no error message is set if (empty($message)) { + // Define the destination folder name and path $folder_name = $_POST['backup'] . '_' . $input_name; $destination = "../" . basename($current_dir) . "/" . $folder_name; + // Check if the destination folder already exists if (is_dir($destination)) { + // Set error message if the destination folder already exists $message = "The folder '$folder_name' already exists. Backup cannot be completed."; } else { + // Perform the backup operation $file_count = backup_folder($source, $destination); + + // Check if files are successfully backed up if ($file_count > 0) { + // Set success message if backup operation is successful $message = "The folder '$folder_name' has been created with $file_count files."; - $messageColor = "#28a745"; + $messageColor = "#28a745"; // Green color for success message } else { + // Set error message if backup operation fails $message = "Failed to create the folder '$folder_name'."; } } @@ -144,21 +222,6 @@ function compareVersions($currentVersion, $latestVersion) { } } -$backup_folders = get_backup_folders($current_dir); - -// Array of colors -$colors = [ - "blue", "blueviolet", "brown", "cadetblue", "chocolate", "crimson", "darkblue", - "darkcyan", "darkgray", "darkgreen", "darkmagenta", "darkolivegreen", "darkorchid", - "darkred", "darkslateblue", "darkslategray", "darkviolet", "deeppink", "dimgray", - "firebrick", "forestgreen", "gray", "green", "indianred", "magenta", "maroon", - "mediumblue", "mediumvioletred", "midnightblue", "navy", "orangered", "palevioletred", - "peru", "purple", "rebeccapurple", "red", "seagreen", "sienna", "slategray", "steelblue", - "teal", "tomato" -]; - -// Randomly select a color -$random_color = $colors[array_rand($colors)]; ?> @@ -288,6 +351,7 @@ function compareVersions($currentVersion, $latestVersion) { } From 0635ca870a25a2ca55e3f1d85df00aa5761d172d Mon Sep 17 00:00:00 2001 From: Chad Davis Date: Sat, 6 Jul 2024 00:55:44 -0500 Subject: [PATCH 11/12] Update to v0.2.0 --- index.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.php b/index.php index 6c343bf..8ed379f 100644 --- a/index.php +++ b/index.php @@ -4,7 +4,7 @@ // * Define constant for the current version // **************************************************************************************** date_default_timezone_set('America/Chicago'); -define('CURRENT_VERSION', 'v0.1.6'); +define('CURRENT_VERSION', 'v0.2.0'); // **************************************************************************************** // * Define variables for API URL, directories, and other data From d3f2fbd2a69034c08a2104202c2f710a5a7ee30d Mon Sep 17 00:00:00 2001 From: Chad Davis Date: Sat, 6 Jul 2024 12:43:38 -0500 Subject: [PATCH 12/12] Fixed #22 Existing Backups table not updating - Found the issue was created when the line that sets the `$backup_folders` variable was moved to before the backup folder is created/deleted. - Fixed by moving it to just before where it's used. - Incremented version to v0.2.1 Close #22 --- index.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/index.php b/index.php index 8ed379f..e1b3f27 100644 --- a/index.php +++ b/index.php @@ -4,7 +4,7 @@ // * Define constant for the current version // **************************************************************************************** date_default_timezone_set('America/Chicago'); -define('CURRENT_VERSION', 'v0.2.0'); +define('CURRENT_VERSION', 'v0.2.1'); // **************************************************************************************** // * Define variables for API URL, directories, and other data @@ -16,7 +16,6 @@ $message = ''; $messageColor = "#dc3545"; $versionMessage = compare_versions(CURRENT_VERSION, $latestVersion); -$backup_folders = get_backup_folders($current_dir); $colors = [ "blue", "blueviolet", "brown", "cadetblue", "chocolate", "crimson", "darkblue", "darkcyan", "darkgray", "darkgreen", "darkmagenta", "darkolivegreen", "darkorchid", @@ -422,7 +421,9 @@ function triggerUpdate() { Created Date (CST) Delete - $folder): ?> + $folder): ?>