Przeglądaj źródła

Add support for season removal (so long as the season folder is empty)

Zachary Kotlarek 13 lat temu
rodzic
commit
55a4dc6fd6
3 zmienionych plików z 47 dodań i 5 usunięć
  1. 4 2
      web/includes/display.php
  2. 19 1
      web/includes/season.php
  3. 24 2
      web/index.php

+ 4 - 2
web/includes/display.php

@@ -72,14 +72,16 @@ function printSeries($series) {
 			if ($monitored !== false && $monitored !== true) {
 				echo htmlspecialchars($monitored);
 			}
-			echo '"/><br/>';
+			echo '"/>';
+			echo '<input type="submit" name="season_del_' . $season_html . '" value="Delete">';
+			echo '<br/>';
 		}
 		echo '</p>';
 
 		# Add a season
 		$next_season = max(array_keys($seasons)) + 1;
 		echo '<p>Add season: ';
-		echo '<input type="text" size="2" name="season_new" value="' . htmlspecialchars($next_season) . '"/>';
+		echo '<input type="text" size="2" name="season_add" value="' . htmlspecialchars($next_season) . '"/>';
 		echo '<input type="submit" name="AddSeason" value="Add Season">';
 		echo '</p>';
 

+ 19 - 1
web/includes/season.php

@@ -118,7 +118,7 @@ function saveSeasons($series, $data, $series_last, $seasons_last) {
 	}
 }
 
-# Add a folder for the provided series and season
+# Add the specified season folder
 function addSeason($series, $season) {
 
 	# Ensure the series exists
@@ -136,4 +136,22 @@ function addSeason($series, $season) {
 	mkdir($season_path);
 }
 
+# Remove the specified season folder, if possible (i.e. if empty)
+function delSeason($series, $season) {
+
+	# Ensure the series exists
+	if (!seriesExists($series)) {
+		die('Invalid series: ' . htmlspecialchars($series) . "\n");
+	}
+
+	# Ensure the season exists
+	$season_path = seriesPath($series) . '/Season ' . intval($season);
+	if (!file_exists($season_path)) {
+		die('Invalid season: ' . htmlspecialchars($season) . "\n");
+	}
+
+	# Remove the directory (or fail silently)
+	@rmdir($season_path);
+}
+
 ?>

+ 24 - 2
web/index.php

@@ -37,13 +37,35 @@ if ($series !== false && isset($_POST['AddSeason'])) {
 	if (preg_match('/^(?:172\.19\.[17]\.|2602:3f:e50d:76|74\.93\.97\.65)/', $_SERVER['REMOTE_ADDR'])) {
 
 		# Add a season folder
-		$new_season = intval($_POST['season_new']);
-		addSeason($series, $new_season);
+		$season = intval($_POST['season_add']);
+		addSeason($series, $season);
 	} else {
 		echo '<h4 style="color: red;">Cannot save: User not authenticated</h4>';
 	}
 }
 
+# Did the user delete a season?
+if ($series !== false) {
+	$season = false;
+	foreach (array_keys($_POST) as $key) {
+		if (preg_match('/season_del_(\d+)/', $key, $matches)) {
+			$season = intval($matches[1]);
+			last;
+		}
+	}
+	if ($season !== false) {
+
+		# Require auth (or for the time being, specific IP addresses)
+		if (preg_match('/^(?:172\.19\.[17]\.|2602:3f:e50d:76|74\.93\.97\.65)/', $_SERVER['REMOTE_ADDR'])) {
+
+			# Remove a season folder (if empty)
+			delSeason($series, $season);
+		} else {
+			echo '<h4 style="color: red;">Cannot save: User not authenticated</h4>';
+		}
+	}
+}
+
 #=========================================================================================
 
 # Generic XHTML 1.1 header