<?

require_once ("include/bittorrent.php");

if (! mkglobal ( "id" ))
	die ();

$id = ( int ) $id;
if (! $id)
	die ();

dbconn ();

global $CURUSER, $CURGROUP;

$res = mysql_query ( "SELECT * FROM torrents WHERE id = $id" );
$row = mysql_fetch_array ( $res );
if (! $row)
	die ();

stdhead ( "Редактирование раздачи \"" . $row ["name"] . "\"" );
begin_frame ( "Редактируем " . $row ["name"] . "", "100", true );

if ($CURUSER ["id"] == $row ["owner"])
	validcan ( false, 'can_edittor|can_editltor' );
else
	validcan ( false, 'can_editltor' );
print ( "<form method=post action=takeedit.php enctype=multipart/form-data>\n" );
print ( "<input type=\"hidden\" name=\"id\" value=\"$id\">\n" );
if (isset ( $_GET ["returnto"] ))
	print ( "<input type=\"hidden\" name=\"returnto\" value=\"" . htmlspecialchars_uni ( $_GET ["returnto"] ) . "\" />\n" );
print ( "<table border=\"1\" cellspacing=\"0\" cellpadding=\"10\">\n" );
tr ( "Название", "<input type=\"text\" name=\"name\" value=\"" . $row ["name"] . "\" size=\"80\" />", 1 );
/// MOD PEREZALIVKA TORRENTA ///
tr ( "Торрент", "<input type=file name=tfile size=60>", 1 );
/// MOD PEREZALIVKA TORRENTA ///
tr ( "Жанр", "<input type=\"text\" name=\"genre\" value=\"" . htmlspecialchars_uni ( $row ["genre"] ) . "\" size=\"80\" />", 1 );
/// MOD TRAILER ///
if ($CURGROUP ['can_uploadtr'])
	echo "<tr><td class=\"heading\" valign=\"top\" align=\"right\"> Трейлер: </td><td valign=\"top\" align=left> <input type=checkbox name=trailer value=yes" . ($row ["trailer"] == "yes" ? " checked" : "") . "> Сделать трейлером</td></tr>\n";
	/// MOD TRAILER ///
if (! $img_on_server) {
	tr ( "Постер", "<input type=\"text\" name=\"poster\" value=\"" . htmlspecialchars_uni ( $row ["poster"] ) . "\" size=\"80\" />", 1 );
} else {
	tr ( "Постер", "<input type=radio name=posteraction value='keep' checked>Оставить&nbsp&nbsp" . "<input type=radio name=posteraction value='delete'>Удалить&nbsp&nbsp" . "<input type=radio name=posteraction value='update'>Обновить<br /><b><input type=file name=image0 size=70>", 1 );
}
tr ( "NFO", "<input type=radio name=nfoaction value='keep' checked>Оставить&nbsp;&nbsp;<input type=radio name=nfoaction value='update'>Заменить<br><input type=file name=nfo size=70>", 1 );
if ((strpos ( $row ["ori_descr"], "<" ) === false) || (strpos ( $row ["ori_descr"], "&lt;" ) !== false))
	$c = "";
else
	$c = " checked";
tr ( "Описание", "<textarea name=\"descr\" rows=\"15\" cols=\"80\">" . htmlspecialchars_uni ( $row ["ori_descr"] ) . "</textarea><br>(HTML не разрешён. Нажмите <a href=tags.php>сюда</a> для получения информации о доступных тэгах.)", 1 );
if (! $img_on_server)
	tr ( "Скриншоты", "<textarea name=\"screenshot\" rows=\"5\" cols=\"80\">" . htmlspecialchars_uni ( $row ["screenshot1"] ) . "</textarea>", 1 );
else {
	tr ( "Скриншоты", "<input type=radio name=scr1action value='keep' checked>Оставить&nbsp&nbsp" . "<input type=radio name=scr1action value='delete'>Удалить&nbsp&nbsp" . "<input type=radio name=scr1action value='update'>Обновить<br /><b>Скриншот 1:</b>&nbsp&nbsp<input type=file name=image1 size=55> <br /><br />
    <input type=radio name=scr2action value='keep' checked>Оставить&nbsp&nbsp" . "<input type=radio name=scr2action value='delete'>Удалить&nbsp&nbsp" . "<input type=radio name=scr2action value='update'>Обновить<br /><b>Скриншот 2:</b>&nbsp&nbsp<input type=file name=image2 size=55> <br /><br />
    <input type=radio name=scr3action value='keep' checked>Оставить&nbsp&nbsp" . "<input type=radio name=scr3action value='delete'>Удалить&nbsp&nbsp" . "<input type=radio name=scr3action value='update'>Обновить<br /><b>Скриншот 3:</b>&nbsp&nbsp<input type=file name=image3 size=55> <br /><br />
    <input type=radio name=scr4action value='keep' checked>Оставить&nbsp&nbsp" . "<input type=radio name=scr4action value='delete'>Удалить&nbsp&nbsp" . "<input type=radio name=scr4action value='update'>Обновить<br /><b>Скриншот 4:</b>&nbsp&nbsp<input type=file name=image4 size=55>", 1 );
}
tr ( "Дополнительно", "<textarea name=\"dops\" rows=\"5\" cols=\"80\">" . htmlspecialchars_uni ( $row ["dops"] ) . "</textarea>", 1 );
tr ( "Релиз", "<input type=\"text\" name=\"reliz\" value=\"" . htmlspecialchars_uni ( $row ["reliz"] ) . "\" size=\"80\" />", 1 );
$s = "<select name=\"type\">\n";

$cats = genrelist ();
foreach ( $cats as $subrow ) {
	$s .= "<option value=\"" . $subrow ["id"] . "\"";
	if ($subrow ["id"] == $row ["category"])
		$s .= " selected=\"selected\"";
	$s .= ">" . htmlspecialchars_uni ( $subrow ["name"] ) . "</option>\n";
}

$s .= "</select>\n";
tr ( "Тип", $s, 1 );
/// MOD INCAT ///
?>
<td class="heading"><b>Подкатегория </b></td>
<td><select name="incat">
	<option value="0">Основная категория</option>
<?
$incats = ingenrelist ();
$catdropdown = "";
foreach ( $incats as $incat ) {
	if ($incat ["incat_cat"] == $row ["category"]) {
		$catdropdown .= "<option value=\"" . $incat ["id"] . "\"";
		if ($incat ["id"] == $row ["incat"])
			$catdropdown .= " selected=\"selected\"";
		$catdropdown .= ">" . htmlspecialchars_uni ( $incat ["name"] ) . "</option>\n";
	}
}
?>
<?=

$catdropdown?>
</select></td>
<?
/// MOD INCAT ///
if ($CURGROUP ['can_editltor'])
	tr ( "Видимый", "<input type=\"checkbox\" name=\"visible\"" . (($row ["visible"] == "yes") ? " checked=\"checked\"" : "") . " value=\"1\" /> Видимый на главной странице<br /><br /><table border=0 cellspacing=0 cellpadding=0 width=420><tr><td class=embedded>Внимание! Этот торрент автоматически станет видимым как только вы начнёте раздачу, и автоматически станет не видимым (мёртвым) если не будет ни одно раздающего. Используйте этот переключатель для ускорения процесса. Так же обратите внимание что не видимые (мёртвые) торренты могут остаться видимыми для поиска, но не всегда.</td></tr></table>", 1 );

if ($CURGROUP ['can_makefree']) {
	$prc .= "Download не учитывать на <select name=\"free\">";
	for($i = 0; $i <= 10; ++ $i) {
		$selected = ($row ['free'] == $i * 10) ? " selected=\"selected\"" : "";
		$prc .= "<option value=" . $i . "0" . $selected . ">" . $i . "0</option>";
	}
	$prc .= "</select> %";
	tr ( "BONUS", $prc, 1 );
}

if ($CURGROUP ['can_makesticky'])
	tr ( "Важный", "<input type=\"checkbox\" name=\"sticky\"" . (($row ["sticky"] == "yes") ? " checked=\"checked\"" : "") . " value=\"yes\" /> Всегда сверху", 1 );
if ($CURGROUP ['can_makehide'])
	tr ( "Скрытый", "<input type=\"checkbox\" name=\"hide\"" . (($row ["hide"] == "yes") ? " checked=\"checked\"" : "") . " value=\"yes\" /> Скрыть этот торрент", 1 );

print ( "<tr><td colspan=\"2\" align=\"center\"><input type=\"submit\" value='Редактировать!' style='height: 25px; width: 125px'> <input type=reset value='Отменить изменения' style='height: 25px; width: 125px'></td></tr>\n" );
print ( "</table>\n" );
print ( "</form>\n" );
print ( "<p>\n" );
print ( "<form method=\"post\" action=\"delete.php\">\n" );
print ( "<table border=\"1\" cellspacing=\"0\" cellpadding=\"5\">\n" );
print ( "<tr><td class=embedded style='background-color: #F5F4EA;padding-bottom: 5px' colspan=\"2\"><b>Удалить торрент.</b> По причине:</td></tr>" );
print ( "<td><input name=\"reasontype\" type=\"radio\" value=\"1\">&nbsp;Мёртвый </td><td> 0 раздающих, 0 качающих = 0 пиров всего</td></tr>\n" );
print ( "<tr><td><input name=\"reasontype\" type=\"radio\" value=\"2\">&nbsp;Дубликат</td><td><input type=\"text\" size=\"40\" name=\"reason[]\"></td></tr>\n" );
print ( "<tr><td><input name=\"reasontype\" type=\"radio\" value=\"3\">&nbsp;Блокированый</td><td><input type=\"text\" size=\"40\" name=\"reason[]\"></td></tr>\n" );
print ( "<tr><td><input name=\"reasontype\" type=\"radio\" value=\"4\">&nbsp;Нарушитель</td><td><input type=\"text\" size=\"40\" name=\"reason[]\">(обяз.)</td></tr>" );
print ( "<tr><td><input name=\"reasontype\" type=\"radio\" value=\"5\" checked>&nbsp;Другая:</td><td><input type=\"text\" size=\"40\" name=\"reason[]\">(обяз.)</td></tr>\n" );
print ( "<input type=\"hidden\" name=\"id\" value=\"$id\">\n" );
if (isset ( $_GET ["returnto"] ))
	print ( "<input type=\"hidden\" name=\"returnto\" value=\"" . htmlspecialchars_uni ( $_GET ["returnto"] ) . "\" />\n" );
print ( "<td colspan=\"2\" align=\"center\"><input type=submit value='Удалить!' style='height: 25px'></td></tr>\n" );
print ( "</table>" );
print ( "</form>\n" );
print ( "</p>\n" );
end_frame ();
stdfoot ();

?>