Browse code

Import from the old rivettracker git repository at sourceforge (amisaph/amisapphire branch)

Clarissa Walker (ami-sapphire) authored on 2014/01/24 14:02:23
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,126 @@
1
+<?php
2
+require ("config.php");
3
+require_once ("funcsv2.php");
4
+//Check session
5
+session_start();
6
+
7
+if (!$_SESSION['admin_logged_in'])
8
+{
9
+	//check fails
10
+	header("Location: authenticate.php?status=session");
11
+	exit();
12
+}
13
+?>
14
+
15
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
16
+
17
+<html>
18
+<head>
19
+	<title>Edit Torrent in Database</title>
20
+	<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
21
+	<link rel="stylesheet" href="./css/style.css" type="text/css" />
22
+</head>
23
+<body>
24
+<h1>Edit Torrent in Database</h1>
25
+<h2>This page allows you to edit torrents that are already in the database.  If you need to change other things about
26
+the torrent please <a href="deleter.php">delete it</a> and add it again.</h2>
27
+	
28
+<?php
29
+
30
+//connect to database
31
+if ($GLOBALS["persist"])
32
+	$db = mysql_pconnect($dbhost, $dbuser, $dbpass) or die(errorMessage() . "Tracker error: can't connect to database - " . mysql_error() . "</p>");
33
+else
34
+	$db = mysql_connect($dbhost, $dbuser, $dbpass) or die(errorMessage() . "Tracker error: can't connect to database - " . mysql_error() . "</p>");
35
+mysql_select_db($database) or die(errorMessage() . "Error selecting database.</p>");
36
+
37
+//get filename from URL string
38
+if (isset($_GET['filename'])) {
39
+	$filename = htmlentities($_GET['filename']);
40
+}
41
+
42
+//if not edit database or filename set, display all torrents as links
43
+if (!isset($_POST["editdatabase"]) && !isset($filename))
44
+{
45
+	?>
46
+	<p><strong>Click on a file to edit it:</strong></p>
47
+	<table border="0">
48
+	<?php
49
+	if ($GLOBALS["customtitle"] == "true")
50
+	$query = "SELECT title, filename FROM ".$prefix."namemap ORDER BY title ASC";	
51
+	else $query = "SELECT filename FROM ".$prefix."namemap ORDER BY filename ASC";
52
+	$rows = mysql_query($query) or die(errorMessage() . "Can't do SQL query - " . mysql_error() . "</p>");
53
+	
54
+	while ($data = mysql_fetch_row($rows))
55
+	{
56
+		if ($GLOBALS["customtitle"] == "true")
57
+		echo "<tr><td><a href=\"" . htmlentities($_SERVER['PHP_SELF']) . "?filename=" . rawurlencode($data[1]) . "\">" . $data[0] . "</a></td></tr>\n";
58
+		else echo "<tr><td><a href=\"" . htmlentities($_SERVER['PHP_SELF']) . "?filename=" . rawurlencode($data[0]) . "\">" . $data[0] . "</a></td></tr>\n";
59
+	}
60
+	?>
61
+	</table>
62
+	<?php
63
+}
64
+
65
+if (isset($filename) && !isset($_POST["editdatabase"]))
66
+{
67
+	$query = "SELECT info_hash,title,filename,url,pubDate FROM ".$prefix."namemap WHERE filename = '" . mysql_real_escape_string($filename) . "'";
68
+	$rows = mysql_query($query) or die(errorMessage() . "Can't do SQL query - " . mysql_error() . "</p>");
69
+	
70
+	$data = mysql_fetch_row($rows); //should be only one entry...
71
+	?>
72
+	<form action="<?php echo htmlentities($_SERVER['PHP_SELF']);?>" method="POST">
73
+	<input type="hidden" name="editdatabase" value="1">
74
+	<input type="hidden" name="<?php echo $data[0];?>" value="<?php echo $data[0];?>">
75
+	<input type="hidden" name="<?php echo $data[0] . "_old_filename";?>" value="<?php echo $data[2];?>">
76
+	<table border="0">
77
+	<tr><td><b>Info Hash: </b></td><td><?php echo $data[0];?></td></tr>
78
+	<tr><td><b>Title:</b></td><td><input type="text" name="<?php echo $data[0] . "_title";?>" size="60" value="<?php echo $data[1];?>"></td></tr>
79
+	<tr><td><b>Filename:</b></td><td><input type="text" name="<?php echo $data[0] . "_filename";?>" size="60" value="<?php echo $data[2];?>"></td></tr>
80
+	<tr><td><b>URL:</b></td><td><input type="text" name="<?php echo $data[0] . "_url";?>" size="60" value="<?php echo $data[3];?>"></td></tr>
81
+	<tr><td><b>Publication Date:</b></td><td><input type="text" name="<?php echo $data[0] . "_pubDate";?>" size="60" value="<?php echo $data[4];?>"></td></tr>
82
+	<tr><td><hr></td><td><hr></td></tr>		
83
+	
84
+	</table>
85
+	<br>
86
+	<input type="submit" value="Edit Entry">
87
+	</form>
88
+	
89
+	<?php
90
+}
91
+
92
+//write data to database
93
+if (isset($_POST["editdatabase"]))
94
+{
95
+	$temp_counter = (count($_POST)-1)/5;
96
+	array_shift($_POST);
97
+	
98
+	for ($i = 0; $i < $temp_counter; $i++)
99
+	{
100
+		$temp_hash = htmlspecialchars(array_shift($_POST));
101
+		$old_filename = htmlspecialchars(array_shift($_POST));
102
+		$temp_title = htmlspecialchars(array_shift($_POST));
103
+		$temp_filename = array_shift($_POST);
104
+		$temp_filename = Ltrim($temp_filename);
105
+		$temp_filename = htmlspecialchars(rtrim($temp_filename));
106
+		$temp_url = htmlspecialchars(array_shift($_POST));
107
+		$temp_pubDate = htmlspecialchars(array_shift($_POST));
108
+		$query = "UPDATE ".$prefix."namemap SET title=\"$temp_title\", filename=\"$temp_filename\", url=\"$temp_url\", pubDate=\"$temp_pubDate\" WHERE info_hash=\"$temp_hash\"";
109
+		mysql_query($query) or die(errorMessage() . "Can't do SQL query - " . mysql_error() . "</p>");
110
+		//if filename changes, rename .torrent
111
+		if ($old_filename != $temp_filename)
112
+			rename("torrents/" . $old_filename . ".torrent", "torrents/" . $temp_filename . ".torrent");
113
+	}
114
+	
115
+	//run RSS generator
116
+	require_once("rss_generator.php");
117
+	
118
+	echo "<br><p class=\"success\">The database was edited successfully!</p>\n";
119
+}
120
+
121
+?>
122
+<br>
123
+<br>
124
+<a href="admin.php"><img src="images/admin.png" border="0" class="icon" alt="Admin Page" title="Admin Page" /></a><a href="admin.php">Return to Admin Page</a>
125
+</body>
126
+</html>