Location: PHPKode > projects > H-tracker > indexedit.php
<?
//
//  H-Tracker v0.2
//    http://h-tracker.org
//    Based on TorrentTrader (http://www.torrenttrader.org)
//
//

require_once("backend/functions.php");
include("codecs.php");
dbconn();
loggedinonly();
if (get_user_class() < 7)
	show_error_msg("Error","Access Denied");
$action = $_GET["action"];
if ($action == 'edit') {
	$id = (int) $_GET["id"];
	if (!is_valid_id($id))
		show_error_msg("Error","Invalid ID");
	$res = mysql_query("SELECT * FROM indexreleases WHERE id = ".sqlesc($id)) or sqlerr(__FILE__,__LINE__);
	if (mysql_num_rows($res) != 1)
		show_error_msg("Error","Invalid ID");
	$release = mysql_fetch_array($res);
	if ($_SERVER['REQUEST_METHOD'] == 'POST') {
		$var_list = "name:poster:genre:director:actors:descr:quality:video_codec:video_size:video_kbps:audio_lang:audio_trans:audio_codec:audio_kbps:time:torrentid:cat";
		$int_list = "quality:video_codec:video_kbps:audio_lang:audio_trans:audio_codec:audio_kbps:torrentid:cat";

		foreach (explode(":", $var_list) as $x)
			if (empty($_POST[$x]))
				show_error_msg("Error", "You have not filled in all fields!");
			else
				$GLOBALS[$x] = $_POST[$x];

		foreach (explode(":", $int_list) as $x)
			if (!is_valid_id($GLOBALS[$x]))
				show_error_msg("Error", "You have entered not number into a following field: $x");
		//$video_kbps = $_POST["video_kbps"];
		$time = $_POST["time"];
		$imdb = $_POST["imdb"];
		//$added = sqlesc(get_date_time());
		
		$updateset = array();

		/*$updateset[] = "name = ".sqlesc($name);
		$updateset[] = "poster = ".sqlesc($poster);
		$updateset[] = "genre = ".sqlesc($genre);
		$updateset[] = "actors = ".sqlesc($actors);
		$updateset[] = "quality = ".sqlesc($quality);
		$updateset[] = "video_codec = ".sqlesc($video_codec);
		$updateset[] = "video_size = ".sqlesc($video_size);
		$updateset[] = "video_kbps = ".sqlesc($video_kbps);
		$updateset[] = "audio_lang = ".sqlesc($audio_lang);
		$updateset[] = "audio_trans = ".sqlesc($audio_trans);
		$updateset[] = "audio_codec = ".sqlesc($audio_codec);
		$updateset[] = "audio_kbps = ".sqlesc($audio_kbps);
		$updateset[] = "time = ".sqlesc($time);
		$updateset[] = "torrentid = ".sqlesc($torrentid);
		$updateset[] = "cat = ".sqlesc($cat);*/

		foreach (explode(":", $var_list) as $x)
			$updateset[] = "$x = ".sqlesc($GLOBALS[$x]);
		if (!empty($imdb))
			$updateset[] = "imdb = ".sqlesc($imdb);
		mysql_query("UPDATE indexreleases SET " . implode(", ", $updateset) . " WHERE id = $id") or sqlerr(__FILE__, __LINE__);
		//sql_query("UPDATE indexreleases SET (".implode(", ", explode(":", $var_list)).($imdb ? ", imdb" : "").") VALUES (".implode(", ", array_map("sqlesc", array())).($imdb ? ", ".sqlesc($imdb) : "").") WHERE id=$id") or sqlerr(__FILE__,__LINE__);
		$returnto = htmlentities($_POST['returnto']);
		if ($returnto != "")
			header("Location: $returnto");
		else
			show_succes_msg("Successfully", "Release edited.");
	} else {
		$returnto = $_GET['returnto'];
		stdhead("Edit release");

$cats = mysql_query("SELECT id, name, parent_cat FROM categories ORDER BY parent_cat ASC, sort_index ASC");
$categories = "<select name=\"cat\"><option selected>Choose category</option>";
while ($cat = mysql_fetch_array($cats)) {
    $cat_id = $cat["id"];
      $parent_cat = $cat["parent"];
    $cat_name = $cat["name"];
    $categories .= "<option value=\"$cat_id\">" . htmlspecialchars($cat["parent_cat"]) . ":$cat_name</option>";

}
$categories .= "</select>";
$quality = "<select name=\"quality\"><option value=\"0\">Choose quality</option>";
foreach ($release_quality as $id => $name)
	$quality .= "<option value=\"$id\"".($release["quality"] == $id ? " selected" : "").">$name</option>";
$quality .= "</select>";
$video = "<select name=\"video_codec\"><option value=\"0\">Choose codec</option>";
foreach ($video_codec as $id => $name)
	$video .= "<option value=\"$id\"".($release["video_codec"] == $id ? " selected" : "").">$name</option>";
$video .= "</select>".
"<input type=\"text\" name=\"video_size\" size=\"10\" value=\"$release[video_size]\">".
"<input type=\"text\" name=\"video_kbps\" size=\"10\" value=\"$release[video_kbps]\"> kb/s";
$audio = "<select name=\"audio_lang\"><option value=\"0\">Choose language</option>";
foreach ($audio_lang as $id => $name)
	$audio .= "<option value=\"$id\"".($release["audio_lang"] == $id ? " selected" : "").">$name</option>";
$audio .= "</select>".
"<select name=\"audio_trans\"><option value=\"0\">Choose translation</option>";
foreach ($audio_trans as $id => $name)
	$audio .= "<option value=\"$id\"".($release["audio_trans"] == $id ? " selected" : "").">$name</option>";
$audio .= "</select>".
"<select name=\"audio_codec\"><option value=\"0\">Choose codec</option>";
foreach ($audio_codec as $id => $name)
	$audio .= "<option value=\"$id\"".($release["audio_codec"] == $id ? " selected" : "").">$name</option>";
$audio .= "</select>".
"<input type=\"text\" name=\"audio_kbps\" size=\"20\" value=\"$release[audio_kbps]\"> kb/s";

$id = (int) $_GET["id"];
begin_frame("Edit Release");
?>

<form action="?action=edit&id=<?=$id;?>" method="post">
<table border="0" cellspacing="0" cellpadding="5" width="95%" align="center">
<?
tr("Release name", "<input type=\"text\" name=\"name\" size=\"60\" value=\"$release[name]\" /><br />Example: Death of the President(2006) DVDRip\n", 1);
tr("Poster", "<input type=\"text\" name=\"poster\" size=\"60\" value=\"$release[poster]\" /><br />Upload picture on <a href=\"http://www.imageshack.us\">ImageShack</a>", 1);
tr("Genre", "<input type=\"text\" name=\"genre\" size=\"60\" value=\"$release[genre]\" />\n", 1);
tr("Director", "<input type=\"text\" name=\"director\" size=\"60\" value=\"$release[director]\" />\n", 1);
tr("Actors", "<input type=\"text\" name=\"actors\" size=\"60\" value=\"$release[actors]\" />\n", 1);
tr("Description", "<textarea name=\"descr\" rows=\"10\" cols=\"50\">$release[descr]</textarea>", 1);
tr("Quality", $quality, 1);
tr("Video", $video, 1);
tr("Audio", $audio, 1);
tr("Duration", "<input type=\"text\" name=\"time\" size=\"30\" value=\"$release[time]\" /><br />Exemple: 01:54:00\n", 1);
tr("Torrent number", "<input type=\"text\" name=\"torrentid\" size=\"60\" value=\"$release[torrentid]\" /><br />Exemple: $DEFAULTBASEURL/details.php?id=<b>6764</b><br />Allocated bold - and the number is the torrent\n", 1);
tr("URL IMDB", "<input type=\"text\" name=\"imdb\" size=\"60\" value=\"$release[imdb]\" /><br />Exemple: http://www.imdb.com/title/tt0408306/\n", 1);
tr("Category", $categories, 1);
?>
<tr><td align="center" colspan="2"><input type="submit" value="Change" /></td></tr>
</table>
<? if ($_GET["returnto"])
	print "<input type=\"hidden\" name=\"returnto\" value=\"".htmlentities($_GET["returnto"])."\" />";
?>
</form>

<?
end_frame();
		stdfoot();
	}
}

?>
Return current item: H-tracker