<?php
if (!defined('ADMIN_FILE') || !is_admin_modul($aid, "Media2")) die("Illegal File Access");

require_once("config/config_media2.php");

function Media2Navi() {
	global $admin_file;
	GraphicAdmin();
	OpenTable();
    echo "<center><font class=\"title\">Медиа каталог2</font><br><br>"
	."[ <a href=\"".$admin_file.".php?op=media2\">"._HOME."</a>"
	." | <a href=\"".$admin_file.".php?op=add_media2\">"._ADD."</a>"
	." | <a href=\"".$admin_file.".php?op=cat_media2\">"._CATEGORIES."</a>"
	." | <a href=\"".$admin_file.".php?op=new_media2\">"._ADDNEWFILES."</a>"
	." | <a href=\"".$admin_file.".php?op=brocen_media2\">"._ADDBROCFILES."</a>"
	." | <a href=\"".$admin_file.".php?op=media2conf\">"._PREFERENCES."</a> ]</center>";
	CloseTable();
}

function media2getparent($parentid,$title) {
	global $prefix, $db;
    $result = $db->sql_query("SELECT cid, title, parentid FROM ".$prefix."_media2_categories WHERE cid='$parentid'");
    list($cid, $ptitle, $pparentid) = $db->sql_fetchrow($result);
    if ($ptitle != "") $title = "".$ptitle."/".$title."";
    if ($pparentid != 0) $title = media2getparent($pparentid,$title);
    return $title;
}

function media2() {
    global $prefix, $db, $admin_file, $pagenum;
    include("header.php");
	Media2Navi();
	$storynum = 25;
	$pagenum = (!intval($pagenum)) ? 1 : intval($pagenum);
	$offset = ($pagenum-1) * $storynum;
	$offset = intval($offset);
	$result = $db->sql_query("SELECT f.lid, f.cid, f.title, f.date, f.ip_sender, c.cid, c.title FROM ".$prefix."_media2 AS f LEFT JOIN ".$prefix."_media2_categories AS c ON (f.cid=c.cid) WHERE status!='0' ORDER BY f.lid DESC LIMIT $offset, $storynum");
	if ($db->sql_numrows($result) > 0) {
		OpenTable();
		echo "<center><font class=\"option\">"._FILESADMIN."</font></center><br />"
		."<script language=\"JavaScript\" type=\"text/javascript\" src=\"javascripts/SortTable.js\"></script><table width=\"100%\" border=\"0\" cellpadding=\"3\" cellspacing=\"1\" class=\"sort\" id=\"sort_id\"><tr><th>"._ID."</th><th>"._TITLE."</th><th>"._CATEGORY."</th>"
		."<th>"._DATE."</th><th>"._IP."</th><th>"._FUNCTIONS."</th></tr>";
		while (list($lid, $cid, $title, $date, $ip_sender, $ccid, $ctitle) = $db->sql_fetchrow($result)) {
			$ip_sender = ($ip_sender) ? $ip_sender : ""._NO."";
			echo "<tr class=\"bgcolor1\"><td align=\"center\">".$lid."</td>"
			."<td>".$title."</td>"
			."<td>".$ctitle."</td>"
			."<td align=\"center\">".$date."</td>"
			."<td align=\"center\">".$ip_sender."</td>"
			."<td align=\"center\"><a href=\"".$admin_file.".php?op=edit_media2&lid=$lid\" title=\""._EDIT."\"><img src=\"images/edit.gif\" border=\"0\" alt=\""._EDIT."\"></a> <a href=\"".$admin_file.".php?op=delit_media2&lid=$lid\" title=\""._DELETE."\"><img src=images/delete.gif border=\"0\" alt=\""._DELETE."\"></a></td></tr>";
	    }
		echo "</table>";
		CloseTable();
		list($numstories) = $db->sql_fetchrow($db->sql_query("SELECT Count(lid) FROM ".$prefix."_media2 WHERE status!='0'"));
		$numpages = ceil($numstories / $storynum);
		num_page($module_name, $numstories, $numpages, $storynum, "op=media2&");
	}

}

function add_media2() {
    global $prefix, $db, $admin_file, $stop, $nlinks, $langtm, $formatm, $qualitym, $admin;
    include("header.php");
	Media2Navi();
	if ($stop) warning($stop, "", "", 1);
	OpenTable();
	echo "<center><font class=\"option\"><b>"._ADDFILE."</b></font></center><br>"
	."<script language=\"JavaScript\" type=\"text/javascript\" src=\"javascripts/SwitchMenu.js\"></script>"
	."<form name=\"post\" enctype=\"multipart/form-data\" action=\"".$admin_file.".php\" method=\"post\">"
	."<table border=\"0\" cellpadding=\"3\" cellspacing=\"0\" align=\"center\">"
	."<tr><td>Разместил:</td><td><input type=\"text\" name=\"author\" value=\"".$admin[1]."\" maxlength=\"100\" size=\"65\" style=\"width:400px\"></td></tr>"
	."<tr><td>Название:</td><td><input type=\"text\" name=\"title\" maxlength=\"100\" size=\"65\" style=\"width:400px\"></td></tr>"

	."<tr><td>"._CATEGORY.":</td><td>"
	."<select name=\"cid\" style=\"width:400px\"><option value=\"0\">"._HOMEFILES."</option>";
	$result = $db->sql_query("SELECT cid, title, parentid FROM ".$prefix."_media2_categories ORDER BY parentid,title");
	while (list($cid2, $title, $parentid2) = $db->sql_fetchrow($result)) {
		if ($parentid2 != 0) $title = media2getparent($parentid2,$title);
		echo "<option value=\"$cid2\">$title</option>";
	}
	echo "</select></td></tr>"
	."<tr><td>"._SUBTITLE.":</td><td><textarea id=\"area\" name=\"description\" cols=\"65\" rows=\"10\" style=\"width:400px\" OnKeyPress=\"TransliteFeld(this, event)\" OnSelect=\"FieldName(this, this.name)\" OnClick=\"FieldName(this, this.name)\" OnKeyUp=\"FieldName(this, this.name)\"></textarea>".get_code("area")."</td></tr>"
	."<tr><td>Год выпуска:</td><td>"
	."<select name=\"year\" style=\"width:400px\">"
	."<option value=\"\">Нет информации</option>";
	$date = getdate();
	$year = $date[year] - 100;
	while ($year <= $date[year]) {
		echo "<option value=\"$year\">$year</option>";
		$year++;
	}
	echo "</select></td></tr>"
	."<tr><td>Разработчик</td><td><input type=\"text\" name=\"director\" maxlength=\"300\" size=\"65\" style=\"width:400px\"></td></tr>"
	."<tr><td>системки минимаьные</td><td><input type=\"text\" name=\"f_roles\" maxlength=\"4000\" size=\"65\" style=\"width:400px\"></td></tr>"
	."<tr><td>рекомендуемые системки
</td><td><input type=\"text\" name=\"time\" maxlength=\"4000\" size=\"65\" style=\"width:400px\"></td></tr>"
	."<tr><td>Язык:</td><td>"
	."<select name=\"langt\" style=\"width:400px\">"
	."<option value=\"\">Нет информации</option>";
	$langt = explode(",", $langtm);
	foreach ($langt as $key => $val) {
		echo "<option value=\"$val\">$val</option>";
	}
	echo "</select></td></tr>"	

	. "<tr><td>Загрузить изображение с компьютера:</td><td><input name=\"userfile\" type=\"file\" size=\"65\" style=\"width:400px\"></td></tr>"

	."<tr><td>Общий размер:</td><td><input type=\"text\" name=\"size\" maxlength=\"50\" size=\"65\" style=\"width:400px\"></td></tr>"
	."<tr><td colspan=\"2\" align=\"center\">";
		$i = 0;
	while ($i < $nlinks) {
		$a = $i + 1;
		$display = ($i !== 0 && $links[$i] == "") ? "style=\"display:none;\"" : "";
		echo "<div id=\"dis".$i."\" ".$display.">"
		."<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" align=\"center\"><tr><td width=\"100%\">"._URL." - $a:</td><td><input type=\"text\" name=\"links[]\" value=\"".$links[$i]."\" size=\"60\" style=\"width:382px\"></td><td>&nbsp;<img src=\"images/editor/plus.gif\" id=\"cont\" border=\"0\" alt=\""._ADD."\" title=\""._ADD."\" id=\"menu".$a."\" OnClick=\"SwitchMenu('dis".$a."')\" style=\"cursor:pointer;\"></td></tr></table><table border=\"0\" cellpadding=\"2\" cellspacing=\"0\"><tr><td></td></tr></table>"
		."</div>";
		$i++;
	}
	echo "<input type=\"hidden\" name=\"op\" value=\"media2_save\">"
	."<input type=\"submit\" value=\""._ADD."\"></td></tr></form></table>";
	CloseTable();

}

function cat_media2() {
    global $prefix, $db, $admin_file;
    include("header.php");
	Media2Navi();
	//m@rt upgrate start
	OpenTable();
	echo "<center><font class=\"option\"><b>"._ADDCATEGORY."</b></font></center><br>"
	."<form name=\"post\" action=\"".$admin_file.".php\" method=\"post\">"
	."<script language=\"JavaScript\" type=\"text/javascript\" src=\"javascripts/ShowImage.js\"></script>"
	."<table border=\"0\" cellpadding=\"3\" cellspacing=\"0\" align=\"center\">"
	."<tr><td>"._TITLE.":</td><td><input type=\"text\" name=\"title\" size=\"65\" style=\"width: 400px\"></td></tr>"
	."<tr><td>"._DESCRIPTION.":</td><td><textarea name=\"description\" cols=\"65\" rows=\"5\" style=\"width: 400px\"></textarea></td></tr>"
	."<tr><td>"._IMG.":</td><td><select name=\"imgcat\" onChange=\"ShowImage('post', 'imgcat', '1')\" style=\"width:400px\">"
	."<option value=\"modules/Media2/imgcat/No.gif\">"._NO."</option>";
	$dir = opendir("modules/Media2/imgcat");
	while ($entry = readdir($dir)) {
		if (preg_match("/(\.gif|\.png|\.jpg|\.jpeg)$/is", $entry) && $entry != "." && $entry != ".." && $entry != "No.gif") {
			$entryname = str_replace("_", " ", preg_replace("/^(.*)\..*$/", "\\1", $entry));
			echo "<option value=\"modules/Media2/imgcat/".$entry."\">$entryname</option>";
		}
	}
	closedir($dir);
	echo "</select></td></tr>"
	."<tr><td>"._PREVIEW.":</td><td><img src=\"modules/Media2/imgcat/No.gif\" name=\"pictures\" alt=\""._IMG."\"></td></tr>" 
	."<tr><td colspan=\"2\" align=\"center\"><input type=\"hidden\" name=\"op\" value=\"add_media2_category\">"
	."<input type=\"submit\" value=\""._ADD."\"></td></tr></form></table>";
    CloseTable();
	$result = $db->sql_query("SELECT cid, title, parentid FROM ".$prefix."_media2_categories ORDER BY parentid,title");
    if ($numrows = $db->sql_numrows($result) > 0) {
		OpenTable();
		echo "<center><font class=\"option\"><b>"._ADDSUBCATEGORY."</b></font></center><br>"
		."<form name=\"post2\" action=\"".$admin_file.".php\" method=\"post\">"
        ."<table border=\"0\" cellpadding=\"3\" cellspacing=\"0\" align=\"center\">"
		."<tr><td>"._TITLE.":</td><td><input type=\"text\" name=\"title\" maxlength=\"100\" size=\"65\" style=\"width:400px\"></td></tr>"
		."<tr><td>"._SUBTITLE.":</td><td><textarea name=\"description\" cols=\"65\" rows=\"5\" style=\"width:400px\"></textarea></td></tr>"
		."<tr><td>"._INCAT.":</td><td>"
        ."<select name=\"cid\" style=\"width:400px\">";
		while (list($cid2, $title, $parentid2) = $db->sql_fetchrow($result)) {
			if ($parentid2 != 0) $title = filegetparent($parentid2,$title);
			echo "<option value=\"$cid2\">$title</option>";
		}
		echo "</select></td></tr>"
		."<tr><td>"._IMG.":</td><td><select name=\"imgsubcat\" onChange=\"ShowImage('post2', 'imgsubcat', '2')\" style=\"width:400px\">"
		."<option value=\"modules/media2/imgcat/No.gif\">"._NO."</option>";
		$dir = opendir("modules/media2/imgcat");
		while ($entry = readdir($dir)) {
			if (preg_match("/(\.gif|\.png|\.jpg|\.jpeg)$/is", $entry) && $entry != "." && $entry != ".." && $entry != "No.gif") {
				$entryname = str_replace("_", " ", preg_replace("/^(.*)\..*$/", "\\1", $entry));
				echo "<option value=\"modules/media2/imgcat/".$entry."\">$entryname</option>";
			}
		}
		closedir($dir);
		echo "</select></td></tr>"
		."<tr><td>"._PREVIEW.":</td><td><img src=\"modules/media2/imgcat/No.gif\" name=\"pictures2\" alt=\""._IMG."\"></td></tr>"
		."<tr><td colspan=\"2\" align=\"center\"><input type=\"hidden\" name=\"op\" value=\"add_media2_sub_cat\">"
		."<input type=\"submit\" value=\""._ADD."\"></td></tr></form></table>";
		CloseTable();
		//m@rt upgrate stop
	}
	$result = $db->sql_query("SELECT cid, title, parentid FROM ".$prefix."_media2_categories ORDER BY parentid,title");
	if ($numrows = $db->sql_numrows($result) > 0) {
		OpenTable();
		echo "<center><font class=\"option\"><b>"._EDITFCAT."</b></font></center><br>"
		."<form action=\"".$admin_file.".php\" method=\"post\">"
		."<center>"._CATEGORY.": <select name=\"cid\" style=\"width:400px\">";
		while (list($cid2, $title, $parentid2) = $db->sql_fetchrow($result)) {
			if ($parentid2!=0) $title = media2getparent($parentid2,$title);
			echo "<option value=\"$cid2\">$title</option>";
		}
		echo "</select> <input type=\"hidden\" name=\"op\" value=\"edit_media2_category\"><input type=\"submit\" value=\""._EDIT."\"></form></center>";
		CloseTable();
	}
	$numfiles = $db->sql_numrows($db->sql_query("SELECT * FROM ".$prefix."_media2"));
	if ($numfiles > 0) {
		$result = $db->sql_query("SELECT cid, title, parentid FROM ".$prefix."_media2_categories ORDER BY parentid,title");
		if ($numrows = $db->sql_numrows($result) > 0) {
			OpenTable();
			echo "<center><font class=\"option\"><b>"._MOVEFCAT."</b></font></center><br>"
			."<form action=\"".$admin_file.".php\" method=\"post\">"
			."<table border=\"0\" cellpadding=\"3\" cellspacing=\"0\" align=\"center\">"
			."<tr><td>"._FROMCATEGORY.":</td><td><select name=\"fromcid\" style=\"width:400px\"><option value=\"0\">"._HOMEFILES."</option>";
			while (list($cid2, $title, $parentid2) = $db->sql_fetchrow($result)) {
				if ($parentid2 != 0) $title = media2getparent($parentid2,$title);
				echo "<option value=\"$cid2\">$title</option>";
			}
			echo "</select></td></tr>";
			echo "<tr><td>"._INCATEGORY.":</td><td><select name=\"incid\" style=\"width:400px\"><option value=\"0\">"._HOMEFILES."</option>";
			$result2 = $db->sql_query("SELECT cid, title, parentid FROM ".$prefix."_media2_categories ORDER BY parentid,title");
			while (list($i_cid2, $i_title, $i_parentid2) = $db->sql_fetchrow($result2)) {
				if ($i_parentid2 != 0) $i_title = media2getparent($i_parentid2,$i_title);
				echo "<option value=\"$i_cid2\">$i_title</option>";
			}
			echo "</select></td></tr>"
			."<tr><td colspan=\"2\" align=\"center\"><input type=\"hidden\" name=\"op\" value=\"move_media2_cat\"><input type=\"submit\" value=\""._MOVEFCATS."\"></td></tr></form></table>";
			CloseTable();
		}
	}

}

	//m@rt upgrate start
function add_media2_category($title, $description, $imgcat) {
    global $prefix, $db, $admin_file;
    $imgcat = str_replace("modules/media2/imgcat/", "", $imgcat);
	$imgcat = (!$imgcat || $imgcat == "No.gif") ? "" : $imgcat;
    $db->sql_query("INSERT INTO ".$prefix."_media2_categories (cid, title, cdescription, cimg) VALUES (NULL, '$title', '$description', '$imgcat')");
    Header("Location: ".$admin_file.".php?op=cat_media2");
}
	//m@rt upgrate stop

function add_media2_sub_cat($cid, $title, $description, $imgsubcat) {
    global $prefix, $db, $admin_file;
	$imgsubcat = str_replace("modules/media2/imgcat/", "", $imgsubcat);
	$imgsubcat = (!$imgsubcat || $imgsubcat == "No.gif") ? "" : $imgsubcat;
    $db->sql_query("INSERT INTO ".$prefix."_media2_categories (cid, title, cdescription, cimg, parentid) VALUES (NULL, '$title', '$description', '$imgsubcat', '$cid')");
    Header("Location: ".$admin_file.".php?op=cat_media2");
}

function edit_media2_category($cid) {
    global $prefix, $db, $admin_file;
    include("header.php");
    media2Navi();
    //m@rt upgrate start
    OpenTable();
    $result = $db->sql_query("SELECT title, cdescription, cimg, parentid FROM ".$prefix."_media2_categories WHERE cid='$cid'");
    list($title, $description, $imgcat, $parentid) = $db->sql_fetchrow($result);
	echo "<center><font class=\"option\"><b>"._EDITCATEGORY."</b></font></center><br>"
	."<form name=\"post\" action=\"".$admin_file.".php\" method=\"post\">"
	."<script language=\"JavaScript\" type=\"text/javascript\" src=\"javascripts/ShowImage.js\"></script>"
	."<table border=\"0\" cellpadding=\"3\" cellspacing=\"0\" align=\"center\">"
	."<tr><td>"._TITLE.":</td><td><input type=\"text\" name=\"title\" value=\"$title\" size=\"65\" style=\"width:400px\"></td></tr>"
	."<tr><td>"._SUBTITLE.":</td><td><textarea name=\"description\" cols=\"65\" rows=\"5\" style=\"width:400px\">$description</textarea></td></tr>";
	
	if ($parentid != 0) {
        $result2 = $db->sql_query("SELECT cid, title, parentid FROM ".$prefix."_media2_categories WHERE parentid != '$parentid'");
        echo "<tr><td>"._INCAT.":</td><td><select name=\"parentid\" style=\"width:400px\">";
        while (list($cid2, $ctitle2, $parentid2) = $db->sql_fetchrow($result2)) {
			if ($parentid2 != 0) $ctitle2 = media2getparent($parentid2, $ctitle2);
			$sel = ($cid2 == $parentid) ? "selected" : "";
			echo "<option value=\"$cid2\" $sel>$ctitle2</option>";
		}
		echo "</select></td></tr>";
	} else {
		echo "<input type=\"hidden\" name=\"parentid\" value=\"0\">";
		}
	echo "<tr><td>"._IMG.":</td><td><select name=\"imgcat\" onChange=\"ShowImage('post', 'imgcat', '1')\" style=\"width:400px\">"
	."<option value=\"modules/media2/imgcat/No.gif\">"._NO."</option>";
	$dir = opendir("modules/media2/imgcat");
	while ($entry = readdir($dir)) {
		if (preg_match("/(\.gif|\.png|\.jpg|\.jpeg)$/is", $entry) && $entry != "." && $entry != ".." && $entry != "No.gif") {
			$entryname = str_replace("_", " ", preg_replace("/^(.*)\..*$/", "\\1", $entry));
			$sel = ($imgcat == $entry) ? "selected" : "";
			echo "<option value=\"modules/media2/imgcat/".$entry."\" $sel>$entryname</option>";
		}
	}
	closedir($dir);
	$imgcat = (!$imgcat) ? "No.gif" : $imgcat;
	echo "</select></td></tr>"
	."<tr><td>"._PREVIEW.":</td><td><img src=\"modules/media2/imgcat/".$imgcat."\" name=\"pictures\" alt=\""._IMG."\"></td></tr>"
	."<tr><td align=\"center\" colspan=\"2\"><table><tr><td><input type=\"hidden\" name=\"cid\" value=\"$cid\"><input type=\"hidden\" name=\"op\" value=\"save_media2_category\"><input type=\"submit\" value=\""._SAVECHANGES."\"></td></form>"
	."<form action=\"".$admin_file.".php\" method=\"post\"><td><input type=\"hidden\" name=\"cid\" value=\"$cid\"><input type=\"hidden\" name=\"op\" value=\"del_media2_cat\"><input type=\"submit\" value=\""._DELETE."\"></td></tr></form></table></tr></td></table>";
	CloseTable();
	//m@rt upgrate stop
  
}

	//m@rt upgrate start
function save_media2_category($cid, $title, $description, $imgcat, $parentid) {
    global $prefix, $db, $admin_file;
    $imgcat = str_replace("modules/media2/imgcat/", "", $imgcat);
	$imgcat = (!$imgcat || $imgcat == "No.gif") ? "" : $imgcat;
    $db->sql_query("UPDATE ".$prefix."_media2_categories SET title='$title', cdescription='$description', cimg='$imgcat', parentid='$parentid' where cid='$cid'");
    Header("Location: ".$admin_file.".php?op=cat_media2");
}
	//m@rt upgrate stop

function del_media2_cat($cid, $ok=0) {
    global $prefix, $db, $admin_file;
    if ($ok == 1) {
        $db->sql_query("DELETE FROM ".$prefix."_media2_categories WHERE cid='$cid'");
        $db->sql_query("DELETE FROM ".$prefix."_media2_categories WHERE parentid='$cid'");
        $result = $db->sql_query("SELECT lid FROM ".$prefix."_media2 WHERE cid='$cid'");
        while (list($lid) = $db->sql_fetchrow($result)) {
			$db->sql_query("DELETE FROM ".$prefix."_comment WHERE cid='$lid' AND modul='media2'");
        }
        $db->sql_query("DELETE FROM ".$prefix."_media2 WHERE cid='$cid'");
		Header("Location: ".$admin_file.".php?op=cat_media2");
    } else {
        include("header.php");
        media2Navi();
        OpenTable();
		list($title) = $db->sql_fetchrow($db->sql_query("SELECT title FROM ".$prefix."_media2_categories WHERE cid='$cid'"));
		echo "<center><font class=\"option\">"._DELCATEGORY.": $title</font><br /><br />"
		.""._DELFCATNOTE."<br /><br />[ <a href=\"".$admin_file.".php?op=cat_media2\">"._NO."</a> | <a href=\"".$admin_file.".php?op=del_media2_cat&cid=$cid&ok=1\">"._YES."</a> ]</center>";
		CloseTable();
	
    }
}

function media2_save($title, $description, $cid, $filelink, $author, $albumn, $year, $langt, $format, $quality, $links, $time, $director, $f_roles, $size) {
	global $prefix, $db, $path, $admin_file, $max_size, $ftypefile, $fiwidth, $fiheight, $stop;
	$links = $_POST['links'];
	$b = 0;
	foreach ($links as $key => $val) {
		if ($val != "") {
			if ($b == 0) {
				$links = $val;
				$b++;
			} else {
				$links .= ",".$val."";
			}
		}
	}
	$links = text_filter($links);
	$cid = intval($cid);
	$ip = getenv("REMOTE_ADDR");
	if ($filelink == "http://") $filelink = "";
	$filename = upload($path, $ftypefile, $max_size, "media2", $fiwidth, $fiheight);	
	if ($filename && !$stop) {
		$file_name = "".$path."/".$filename."";
		$filelink = ($file_name) ? $file_name : $filelink;
		$db->sql_query("INSERT INTO ".$prefix."_media2 (lid, cid, title, description, url, date, size, roles, name, album, year, lang, format, quality, links, time, director, ip_sender, status) VALUES (NULL, '$cid', '$title', '$description', '$filelink', now(), '$size', '$f_roles', '$author', '$albumn', '$year', '$langt', '$format', '$quality', '$links', '$time', '$director', '$ip', '1')");
	} elseif (!$stop) { 
		$db->sql_query("INSERT INTO ".$prefix."_media2 (lid, cid, title, description, url, date, size, roles, name, album, year, lang, format, quality, links, time, director, ip_sender, status) VALUES (NULL, '$cid', '$title', '$description', '$filelink', now(), '$size', '$f_roles', '$author', '$albumn', '$year', '$langt', '$format', '$quality', '$links', '$time', '$director', '$ip', '1')");
	} elseif ($stop) {
		$stop = $stop;
		}
	if (!$stop) {
		Header("Location: ".$admin_file.".php?op=media2");
	} else {
		add_media2();
	}
}

function edit_media2($lid) {
	global $prefix, $db, $admin_file, $nlinks, $langtm, $formatm, $qualitym;
	$result = $db->sql_query("SELECT cid, title, description, url, size, roles, name, album, year, lang, format, quality, links, time, director FROM ".$prefix."_media2 WHERE lid='$lid'");
	list($f_cid, $f_title, $f_description, $f_url, $f_size, $f_roles, $f_name, $f_album, $f_year, $f_langt, $f_format, $f_quality, $f_links, $f_time, $f_director) = $db->sql_fetchrow($result);
	$links = explode(",", $f_links);
	include("header.php");
	media2Navi();
	OpenTable();
	echo "<center><font class=\"option\"><b>"._FILEEDIT."</b></font></center><br>"
	."<form name=\"post\" action=\"".$admin_file.".php\" method=\"post\">"
	."<table border=\"0\" cellpadding=\"3\" cellspacing=\"0\" align=\"center\">"
	."<tr><td>Разместил:</td><td><input type=\"text\" name=\"author\" value=\"$f_name\" size=\"65\" style=\"width:400px\"></td></tr>"
	."<tr><td>Название / Исполнитель:</td><td><input type=\"text\" name=\"title\" value=\"$f_title\" size=\"65\" style=\"width:400px\"></td></tr>"
	."<tr><td>Альбом:</td><td><input type=\"text\" name=\"albumn\" value=\"$f_album\" size=\"65\" style=\"width:400px\"></td></tr>"	
	."<tr><td>"._CATEGORY.":</td><td><select name=\"cid\"style=\"width:400px\"><option value=\"0\">"._HOMEFILES."</option>";
	$result = $db->sql_query("SELECT cid, title, parentid FROM ".$prefix."_media2_categories ORDER BY parentid,title");
	while (list($cid2, $title, $parentid2) = $db->sql_fetchrow($result)) {
		if ($parentid2 != 0) $title = media2getparent($parentid2, $title);
		if ($cid2 == $f_cid) echo "<option value=\"$cid2\" selected>$title</option>";
		echo "<option value=\"$cid2\">$title</option>";
	}
	echo "</select></td></tr>"
	."<tr><td>"._SUBTITLE.":</td><td><textarea id=\"area\" name=\"description\" cols=\"65\" rows=\"10\" style=\"width:400px\" OnKeyPress=\"TransliteFeld(this, event)\" OnSelect=\"FieldName(this, this.name)\" OnClick=\"FieldName(this, this.name)\" OnKeyUp=\"FieldName(this, this.name)\">".preg_replace("/<br.*/", "", $f_description)."</textarea>".get_code("area")."</td></tr>"
	."<tr><td>Год выпуска:</td><td>"
	."<select name=\"year\" style=\"width:400px\">"
	."<option value=\"\">Нет информации</option>";
	$date = getdate();
	$year = $date[year] - 100;
	while ($year <= $date[year]) {
		$sel = ($year == $f_year) ? "selected" : "";
		echo "<option value=\"$year\" $sel>$year</option>";
		$year++;	
	}
	echo "</select></td></tr>"
	."<tr><td>разраб</td><td><input type=\"text\" name=\"director\" value=\"$f_director\" size=\"65\" style=\"width:400px\"></td></tr>"
	."<tr><td>минималка</td><td><input type=\"text\" name=\"f_roles\" value=\"$f_roles\" size=\"65\" style=\"width:400px\"></td></tr>"
	."<tr><td>рекомендуем
</td><td><input type=\"text\" name=\"time\" value=\"$f_time\" size=\"65\" style=\"width:400px\"></td></tr>"
	."<tr><td>Язык:</td><td>"
	."<select name=\"langt\" style=\"width:400px\">"
	."<option value=\"\">Нет информации</option>";
	$langt = explode(",", $langtm);
	foreach ($langt as $key => $val) {
		$sel = ($val == $f_langt && $val != "") ? "selected" : "";
		echo "<option value=\"$val\" $sel>$val</option>";
	}
	echo "</select></td></tr>"
	."<tr><td>Формат:</td><td>"
	."<select name=\"format\" style=\"width:400px\">"
	."<option value=\"\">Нет информации</option>";
	$format = explode(",", $formatm);
	foreach ($format as $key => $val) {
		$sel = ($val == $f_format && $val != "") ? "selected" : "";
		echo "<option value=\"$val\" $sel>$val</option>";
	}
	echo "</select></td></tr>"
	."<tr><td>Качество:</td><td>"
	."<select name=\"quality\" style=\"width:400px\">"
	."<option value=\"\">Нет информации</option>";
	$quality = explode(",", $qualitym);
	foreach ($quality as $key => $val) {
		$sel = ($val == $f_quality && $val != "") ? "selected" : "";
		echo "<option value=\"$val\" $sel>$val</option>";
	}
	echo "</select></td></tr>"
	."<tr><td>"._FILELINK.":</td><td><input type=\"text\" name=\"filelink\" value=\"$f_url\" size=\"65\" style=\"width:400px\"></td></tr>"
	."<tr><td>Общий размер:</td><td><input type=\"text\" name=\"size\" value=\"$f_size\" size=\"65\" style=\"width:400px\"></td></tr>"
	."<tr><td>"._FILE_NEW_DATE."</td><td><input type=\"radio\" name=\"f_date\" value=\"1\">"._YES." &nbsp;&nbsp; <input type=\"radio\" name=\"f_date\" value=\"0\" checked>"._NO."</tr>"
	."<tr><td colspan=\"2\" align=\"center\">";
			$i = 0;
	while ($i < $nlinks) {
		$a = $i + 1;
		$display = ($i !== 0 && $links[$i] == "") ? "style=\"display:none;\"" : "";
		echo "<div id=\"dis".$i."\" ".$display.">"
		."<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" align=\"center\"><tr><td width=\"100%\">"._URL." - $a:</td><td><input type=\"text\" name=\"links[]\" value=\"".$links[$i]."\" size=\"60\" style=\"width:382px\"></td><td>&nbsp;<img src=\"images/editor/plus.gif\" border=\"0\" alt=\""._ADD."\" title=\""._ADD."\" id=\"menu".$a."\" OnClick=\"SwitchMenu('dis".$a."')\" style=\"cursor:pointer;\"></td></tr></table><table border=\"0\" cellpadding=\"2\" cellspacing=\"0\"><tr><td></td></tr></table>"
		."</div>";
		$i++;
	}
	echo "<input type=\"hidden\" name=\"lid\" value=\"$lid\"><input type=\"hidden\" name=\"op\" value=\"media2_edit_save\">"
	."<input type=\"submit\" value=\""._SAVEFILEED."\"></td></tr></form></table>";
    CloseTable();
 
}

function media2_edit_save($lid, $title, $description, $cid, $filelink, $author, $albumn,  $year,  $langt, $format, $quality, $links, $time, $director, $f_roles, $size, $f_date) {
	global $prefix, $db, $admin_file;
	$links = $_POST['links'];
	$b = 0;
	foreach ($links as $key => $val) {
		if ($val != "") {
			if ($b == 0) {
				$links = $val;
				$b++;
			} else {
				$links .= ",".$val."";
			}
		}
	}
	$links = text_filter($links);
	if ($f_date == 1) {
		$db->sql_query("UPDATE ".$prefix."_media2 SET cid='$cid', title='$title', description='$description', url='$filelink', date=now(), size='$size', roles='$f_roles', name='$author', album='$albumn', year='$year', lang='$langt', format='$format', quality='$quality', links='$links',  time='$time', director='$director' WHERE lid='$lid'");
	} else {
		$db->sql_query("UPDATE ".$prefix."_media2 SET cid='$cid', title='$title', description='$description', url='$filelink', size='$size', roles='$f_roles', name='$author', album='$albumn', year='$year', lang='$langt', format='$format', quality='$quality', links='$links', time='$time', director='$director' WHERE lid='$lid'");
	}
    Header("Location: ".$admin_file.".php?op=media2");
}

function delit_media2($lid, $ok=0) {
	global $prefix, $db, $temp_path, $path, $admin_file;
    if ($ok==1) {
		$sql = "SELECT url FROM ".$prefix."_media2 WHERE lid=$lid";
		$result = $db->sql_query($sql);
        $row = $db->sql_fetchrow($result);
        $filelink = $row[url];
        $filel = array_reverse(explode("/", $filelink));
		if (file_exists("".$temp_path."/".$filel[0]."")) {
			$delf = "".$temp_path."/".$filel[0]."";
			@unlink($delf);
        }
        if (file_exists("".$path."/".$filel[0]."")) {
			$delf = "".$path."/".$filel[0]."";
			@unlink($delf);
        }
        $db->sql_query("DELETE FROM ".$prefix."_comment WHERE cid='$lid' AND modul='media2'");
        $db->sql_query("DELETE FROM ".$prefix."_media2 WHERE lid='$lid'");
        Header("Location: ".$admin_file.".php?op=media2");
    } else {
		list($title) = $db->sql_fetchrow($db->sql_query("SELECT title FROM ".$prefix."_media2 WHERE lid='$lid'"));
        include("header.php");
		media2Navi();
        OpenTable();
		echo "<center>"._DELETE." \"$title\"?<br><br>[ <a href=\"".$admin_file.".php?op=delit_media2&lid=$lid&ok=1\">"._YES."</a> | <a href=\"".$admin_file.".php?op=media2\">"._NO."</a> ]</center>";
		CloseTable();
       
    }
}

function new_media2() {
    global $prefix, $db, $admin_file;
    include("header.php");
	media2Navi();
    $result = $db->sql_query("SELECT lid, title, description, ip_sender FROM ".$prefix."_media2 WHERE status='0' ORDER BY lid");
    if ($db->sql_numrows($result) > 0) {
		OpenTable();
		echo "<center><font class=\"option\"><b>"._ADDNEWFILES."</b></font></center><br>"
		."<table border=\"0\" cellpadding=\"3\" cellspacing=\"1\" width=\"100%\" class=\"bgcolor4\">"
		."<th>"._TITLE."</th><th>"._SUBTITLE."</th><th>"._IPSENDER."</th><th>"._FUNCTIONS."</th></tr>";
		while (list($lid, $title, $description, $ip_sender) = $db->sql_fetchrow($result)) {
			echo "<td class=\"bgcolor1\">$title</td>"
			."<td class=\"bgcolor1\">$description</td>"
			."<td class=\"bgcolor1\" align=\"center\"><a href=\"".$admin_file.".php?op=SecurityBlocker&new_ip=$ip_sender\" title=\""._BANIPSENDER."\">$ip_sender</a></td>"
			."<td class=\"bgcolor1\" align=\"center\"><a href=\"".$admin_file.".php?op=delit_media2&lid=$lid\" title=\""._DELETE."\"><img src=images/delete.gif border=\"0\" alt=\""._DELETE."\"></a> <a href=\"".$admin_file.".php?op=view_add_media2&lid=$lid\" title=\""._EDIT."\"><img src=\"images/edit.gif\" border=\"0\" alt=\""._EDIT."\"></a></td></tr>";
		}
		echo "</table>";
		CloseTable();
	}

}

function brocen_media2() {
    global $prefix, $db, $admin_file;
    include("header.php");
    media2Navi();
    $result = $db->sql_query("SELECT lid, title, url FROM ".$prefix."_media2 WHERE status='2' ORDER BY lid");
    if ($db->sql_numrows($result) > 0) {
		OpenTable();
		echo "<center><font class=\"option\">"._ADDBROCFILES."</font></center><br>";
		echo "<table border=\"0\" cellpadding=\"3\" cellspacing=\"1\" width=\"100%\" class=\"bgcolor4\">";
		echo "<th>"._TITLE."</th><th>"._FUNCTIONS."</th></tr>";
		while (list($lid, $title, $url) = $db->sql_fetchrow($result)) {
			echo "<tr><td class=\"bgcolor1\">$title</td>";
			echo "<td class=\"bgcolor1\" align=\"center\"><a href=\"".$admin_file.".php?op=edit_media2&lid=$lid\" title=\""._EDIT."\"><img src=images/edit.gif border=\"0\" alt=\""._EDIT."\"></a> <a href=\"".$admin_file.".php?op=ignore_broc_media2&lid=$lid\" title=\""._IGNORE."\"><img src=images/delete.gif border=\"0\" alt=\""._IGNORE."\"></a></td></tr>";
		}
		echo "</table>";
		CloseTable();
	}
 
}

function ignore_broc_media2($lid) {
    global $prefix, $db, $admin_file;
    $db->sql_query("UPDATE ".$prefix."_media2 SET status='1' WHERE lid='$lid'");
    Header("Location: ".$admin_file.".php?op=brocen_media2");
}

function view_add_media2($lid) {
	global $prefix, $db, $admin_file, $nlinks, $langtm, $formatm, $qualitym;
	$result = $db->sql_query("SELECT cid, title, description, url, size, roles, name, album, year, lang, format, quality, links, time, director FROM ".$prefix."_media2 WHERE lid='$lid'");
	list($f_cid, $f_title, $f_description, $f_url, $f_size, $f_roles, $f_name, $f_album, $f_year, $f_langt, $f_format, $f_quality, $f_links, $f_time, $f_director) = $db->sql_fetchrow($result);
	 $links = explode(",", $f_links);
     include("header.php");
     media2Navi();
     OpenTable();
	 echo "<center><font class=\"option\"><b>"._FILEEDIT."</b></font></center><br>"
	."<form name=\"post\" action=\"".$admin_file.".php\" method=\"post\">"
	."<table border=\"0\" cellpadding=\"3\" cellspacing=\"0\" align=\"center\">"
	."<tr><td>Разместил:</td><td><input type=\"text\" name=\"author\" value=\"$f_name\" size=\"65\" style=\"width:400px\"></td></tr>"
	."<tr><td>Название / Исполнитель:</td><td><input type=\"text\" name=\"title\" value=\"$f_title\" size=\"65\" style=\"width:400px\"></td></tr>"
	."<tr><td>Альбом:</td><td><input type=\"text\" name=\"albumn\" value=\"$f_album\" size=\"65\" style=\"width:400px\"></td></tr>"	
	."<tr><td>"._CATEGORY.":</td><td><select name=\"cid\"style=\"width:400px\"><option value=\"0\">"._HOMEFILES."</option>";
	$result = $db->sql_query("SELECT cid, title, parentid FROM ".$prefix."_media2_categories ORDER BY parentid,title");
	while (list($cid2, $title, $parentid2) = $db->sql_fetchrow($result)) {
		if ($parentid2 != 0) $title = media2getparent($parentid2, $title);
		if ($cid2 == $f_cid) echo "<option value=\"$cid2\" selected>$title</option>";
		echo "<option value=\"$cid2\">$title</option>";
	}
	echo "</select></td></tr>"
	."<tr><td>"._SUBTITLE.":</td><td><textarea id=\"area\" name=\"description\" cols=\"65\" rows=\"10\" style=\"width:400px\" OnKeyPress=\"TransliteFeld(this, event)\" OnSelect=\"FieldName(this, this.name)\" OnClick=\"FieldName(this, this.name)\" OnKeyUp=\"FieldName(this, this.name)\">".preg_replace("/<br.*/", "", $f_description)."</textarea>".get_code("area")."</td></tr>"
	."<tr><td>Год выпуска:</td><td>"
	."<select name=\"year\" style=\"width:400px\">"
	."<option value=\"\">Нет информации</option>";
	$date = getdate();
	$year = $date[year] - 100;
	while ($year <= $date[year]) {
		$sel = ($year == $f_year) ? "selected" : "";
		echo "<option value=\"$year\" $sel>$year</option>";
		$year++;	
	}
	echo "</select></td></tr>"
	."<tr><td>разраб</td><td><input type=\"text\" name=\"director\" value=\"$f_director\" size=\"65\" style=\"width:400px\"></td></tr>"
	."<tr><td>минимаклка</td><td><input type=\"text\" name=\"f_roles\" value=\"$f_roles\" size=\"65\" style=\"width:400px\"></td></tr>"
	."<tr><td>рекомендуем
</td><td><input type=\"text\" name=\"time\" value=\"$f_time\" size=\"65\" style=\"width:400px\"></td></tr>"
	."<tr><td>Язык:</td><td>"
	."<select name=\"langt\" style=\"width:400px\">"
	."<option value=\"\">Нет информации</option>";
	$langt = explode(",", $langtm);
	foreach ($langt as $key => $val) {
		$sel = ($val == $f_langt && $val != "") ? "selected" : "";
		echo "<option value=\"$val\" $sel>$val</option>";
	}
	echo "</select></td></tr>"
	."<tr><td>Формат:</td><td>"
	."<select name=\"format\" style=\"width:400px\">"
	."<option value=\"\">Нет информации</option>";
	$format = explode(",", $formatm);
	foreach ($format as $key => $val) {
		$sel = ($val == $f_format && $val != "") ? "selected" : "";
		echo "<option value=\"$val\" $sel>$val</option>";
	}
	echo "</select></td></tr>"
	."<tr><td>Качество:</td><td>"
	."<select name=\"quality\" style=\"width:400px\">"
	."<option value=\"\">Нет информации</option>";
	$quality = explode(",", $qualitym);
	foreach ($quality as $key => $val) {
		$sel = ($val == $f_quality && $val != "") ? "selected" : "";
		echo "<option value=\"$val\" $sel>$val</option>";
	}
	echo "</select></td></tr>";
	echo "<tr><td>"._FILELINK."</td><td><input type=\"text\" name=\"filelink\" value=\"$f_url\" size=\"65\" style=\"width:400px\"></td></tr>"
	."<tr><td>Общий размер:</td><td><input type=\"text\" name=\"size\" value=\"$f_size\" size=\"65\" style=\"width:400px\"></td></tr>"
	."<tr><td colspan=\"2\" align=\"center\">";
			$i = 0;
	while ($i < $nlinks) {
		$a = $i + 1;
		$display = ($i !== 0 && $links[$i] == "") ? "style=\"display:none;\"" : "";
		echo "<div id=\"dis".$i."\" ".$display.">"
		."<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" align=\"center\"><tr><td width=\"100%\">"._URL." - $a:</td><td><input type=\"text\" name=\"links[]\" value=\"".$links[$i]."\" size=\"60\" style=\"width:382px\"></td><td>&nbsp;<img src=\"images/editor/plus.gif\" border=\"0\" alt=\""._ADD."\" title=\""._ADD."\" id=\"menu".$a."\" OnClick=\"SwitchMenu('dis".$a."')\" style=\"cursor:pointer;\"></td></tr></table><table border=\"0\" cellpadding=\"2\" cellspacing=\"0\"><tr><td></td></tr></table>"
		."</div>";
		$i++;
	}
	echo "<input type=\"hidden\" name=\"lid\" value=\"$lid\">"
	."<tr><td align=\"center\" colspan=\"2\"><table><tr><td><input type=\"hidden\" name=\"op\" value=\"media2_add_save\"><input type=\"submit\" value=\""._ADDFILE."\"></td></form>"
	."<form action=\"".$admin_file.".php\" method=\"post\"><td><input type=\"hidden\" name=\"op\" value=\"delit_media2\"><input type=\"hidden\" name=\"lid\" value=\"$lid\"><input type=\"submit\" value=\""._DELETE."\"></td></tr></form></table></tr></td></table>";
	CloseTable();
    
}

function move_media2_cat($fromcid, $incid) {
    global $prefix, $db, $admin_file;
    $db->sql_query("UPDATE ".$prefix."_media2 SET cid='$incid' WHERE cid='$fromcid'");
    Header("Location: ".$admin_file.".php?op=media2");
}

function media2_add_save($lid, $title, $description, $cid, $filelink, $author, $albumn,  $year,  $langt, $format, $quality, $links, $time, $director, $f_roles, $size) {
    global $prefix, $db, $temp_path, $path, $admin_file;
 	$links = $_POST['links'];
	$b = 0;
	foreach ($links as $key => $val) {
		if ($val != "") {
			if ($b == 0) {
				$links = $val;
				$b++;
			} else {
				$links .= ",".$val."";
			}
		}
	}
    $filel = array_reverse(explode("/", $filelink));
	if (file_exists("".$temp_path."/".$filel[0]."")) {
		$oldfile = "".$temp_path."/".$filel[0]."";
		$newfile = "".$path."/".$filel[0]."";
		@rename($oldfile, $newfile);
		$filelink = "".$path."/".$filel[0]."";
    }
    $db->sql_query("UPDATE ".$prefix."_media2 SET cid='$cid', title='$title', description='$description', url='$filelink', date=now(), size='$size', roles='$f_roles', name='$author', album='$albumn', year='$year', lang='$langt', format='$format', quality='$quality', links='$links',  time='$time', director='$director', status='1'  WHERE lid='$lid'");
    Header("Location: ".$admin_file.".php?op=media2");
}

function media2conf() {
	global $prefix, $db, $admin_file;
	include("header.php");
	media2Navi();
	include("config/config_media2.php");
	$permtest = end_chmod("config/config_media2.php", 666);
	if ($permtest) warning($permtest, "", "", 1);
	OpenTable();
	$file_t = intval($file_t / 86400);
	echo "<center><font class='option'><b>"._GENSITEINFO."</b></font></center><br>"
    ."<form action='".$admin_file.".php' method='post'>"
	."<table border='0' align='center' cellpadding='3' cellspacing='0'>"
	."<tr><td>"._F_0.":</td><td><input type='text' name='xtemp_path' value='$temp_path' maxlength='45' size='45' style='width:300px'></td></tr>"
	."<tr><td>"._F_1.":</td><td><input type='text' name='xpath' value='$path' maxlength='45' size='45' style='width:300px'></td></tr>"
	."<tr><td>Максимальный размер изображения, в байтах:</td><td><input type='text' name='xmax_size' value='$max_size' maxlength='25' size='45' style='width:300px'></td></tr>"
	."<tr><td>Допустимые форматы изображения:</td><td><input type='text' name='xftypefile' value='$ftypefile' maxlength='25' size='45' style='width:300px'></td></tr>"
	."<tr><td>"._AWIDTH.":</td><td><input type='text' name='xfiwidth' value='$fiwidth' size='65' style='width:300px'></td></tr>"
	."<tr><td>"._AHEIGHT.":</td><td><input type='text' name='xfiheight' value='$fiheight' size='65' style='width:300px'></td></tr>"
	."<tr><td>"._GDWIDTH.":</td><td><input type='text' name='xfigdwidth' value='$figdwidth' size='65' style='width:300px'></td></tr>"
	."<tr><td>"._F_3.":</td><td><input type='text' name='xnumsubkat' value='$numsubkat' maxlength='25' size='45' style='width:300px'></td></tr>"
	."<tr><td>"._F_4.":</td><td><input type='text' name='xtabcolumn' value='$tabcolumn' maxlength='25' size='45' style='width:300px'></td></tr>"
	."<tr><td>"._F_5.":</td><td><input type='text' name='xfilenum' value='$filenum' maxlength='25' size='45' style='width:300px'></td></tr>"
	."<tr><td>"._VOTING_TIME.":</td><td><input type='text' name='xfile_t' value='$file_t' maxlength='25' size='45' style='width:300px'></td></tr>"
	."<tr><td>Количество в списке:</td><td><input type='text' name='xfilelistnum' value='$filelistnum' maxlength='25' size='45' style='width:300px'></td></tr>"
	."<tr><td>Количество ссылок:</td><td><input type='text' name='xnlinks' value='$nlinks' maxlength='25' size='45' style='width:300px'></td></tr>"
	."<tr><td>Язык:</td><td><input type='text' name='xlangtm' value='$langtm' maxlength='255' size='45' style='width:300px'></td></tr>"
	."<tr><td>Формат:</td><td><input type='text' name='xformatm' value='$formatm' maxlength='100' size='45' style='width:300px'></td></tr>"
	."<tr><td>Качество:</td><td><input type='text' name='xqualitym' value='$qualitym' maxlength='100' size='45' style='width:300px'></td></tr>";
	echo "<tr><td>"._GDACTIVE."</td><td>";
	if ($figdactive == 1) {
		echo "<input type='radio' name='xfigdactive' value='1' checked>"._YES." &nbsp;<input type='radio' name='xfigdactive' value='0'>"._NO."";
    } else {
        echo "<input type='radio' name='xfigdactive' value='1'>"._YES." &nbsp;<input type='radio' name='xfigdactive' value='0' checked>"._NO."";
    }
	echo "<tr><td>"._F_6."</td><td>";
	if ($commentfiles == 1) {
		echo "<input type='radio' name='xcommentfiles' value='1' checked>"._YES." &nbsp;<input type='radio' name='xcommentfiles' value='0'>"._NO."";
    } else {
        echo "<input type='radio' name='xcommentfiles' value='1'>"._YES." &nbsp;<input type='radio' name='xcommentfiles' value='0' checked>"._NO."";
    }
	echo "</td></tr><tr><td>"._F_7."</td><td>";
	if ($poolfiles == 1) {
		echo "<input type='radio' name='xpoolfiles' value='1' checked>"._YES." &nbsp;<input type='radio' name='xpoolfiles' value='0'>"._NO."";
    } else {
        echo "<input type='radio' name='xpoolfiles' value='1'>"._YES." &nbsp;<input type='radio' name='xpoolfiles' value='0' checked>"._NO."";
    }
	echo "</td></tr><tr><td>"._F_8."</td><td>";
	if ($addfiles == 1) {
		echo "<input type='radio' name='xaddfiles' value='1' checked>"._YES." &nbsp;<input type='radio' name='xaddfiles' value='0'>"._NO."";
    } else {
        echo "<input type='radio' name='xaddfiles' value='1'>"._YES." &nbsp;<input type='radio' name='xaddfiles' value='0' checked>"._NO."";
    }
	echo "</td></tr><tr><td>"._F_9."</td><td>";
	if ($addquest == 1) {
		echo "<input type='radio' name='xaddquest' value='1' checked>"._YES." &nbsp;<input type='radio' name='xaddquest' value='0'>"._NO."";
    } else {
        echo "<input type='radio' name='xaddquest' value='1'>"._YES." &nbsp;<input type='radio' name='xaddquest' value='0' checked>"._NO."";
    }
	echo "</td></tr><tr><td>"._F_10."</td><td>";
	if ($showsubkat == 1) {
		echo "<input type='radio' name='xshowsubkat' value='1' checked>"._YES." &nbsp;<input type='radio' name='xshowsubkat' value='0'>"._NO."";
    } else {
        echo "<input type='radio' name='xshowsubkat' value='1'>"._YES." &nbsp;<input type='radio' name='xshowsubkat' value='0' checked>"._NO."";
    }
	echo "</td></tr><tr><td>"._F_11."</td><td>";
	if ($broclink == 1) {
		echo "<input type='radio' name='xbroclink' value='1' checked>"._YES." &nbsp;<input type='radio' name='xbroclink' value='0'>"._NO."";
    } else {
        echo "<input type='radio' name='xbroclink' value='1'>"._YES." &nbsp;<input type='radio' name='xbroclink' value='0' checked>"._NO."";
    }
	echo "</td></tr><tr><td>"._F_12."</td><td>";
	if ($downfiles == 1) {
		echo "<input type='radio' name='xdownfiles' value='1' checked>"._YES." &nbsp;<input type='radio' name='xdownfiles' value='0'>"._NO."";
    } else {
        echo "<input type='radio' name='xdownfiles' value='1'>"._YES." &nbsp;<input type='radio' name='xdownfiles' value='0' checked>"._NO."";
    }
	echo "</td></tr><tr><td>"._UPFILE."</td><td>";
	if ($uploadfiles == 1) {
		echo "<input type='radio' name='xuploadfiles' value='1' checked>"._YES." &nbsp;<input type='radio' name='xuploadfiles' value='0'>"._NO."";
    } else {
        echo "<input type='radio' name='xuploadfiles' value='1'>"._YES." &nbsp;<input type='radio' name='xuploadfiles' value='0' checked>"._NO."";
    }
	echo "</td></tr><tr><td>Показывать описания для категорий?</td><td>";
	if ($showtext == 1) {
		echo "<input type='radio' name='xshowtext' value='1' checked>"._YES." &nbsp;<input type='radio' name='xshowtext' value='0'>"._NO."";
    } else {
        echo "<input type='radio' name='xshowtext' value='1'>"._YES." &nbsp;<input type='radio' name='xshowtext' value='0' checked>"._NO."";
    }
	echo "</td></tr><tr><td>Увеличивать изобрадения?</td><td>";
	if ($viewimg == 1) {
		echo "<input type='radio' name='xviewimg' value='1' checked>"._YES." &nbsp;<input type='radio' name='xviewimg' value='0'>"._NO."";
    } else {
        echo "<input type='radio' name='xviewimg' value='1'>"._YES." &nbsp;<input type='radio' name='xviewimg' value='0' checked>"._NO."";
    }
	echo "</td></tr><tr><td>Показывать изображения категорий?</td><td>";
	if ($showimgcat == 1) {
		echo "<input type='radio' name='xshowimgcat' value='1' checked>"._YES." &nbsp;<input type='radio' name='xshowimgcat' value='0'>"._NO."";
    } else {
        echo "<input type='radio' name='xshowimgcat' value='1'>"._YES." &nbsp;<input type='radio' name='xshowimgcat' value='0' checked>"._NO."";
    }
	echo "</td></tr><tr><td>Выводит количество файлов в категориях?</td><td>";
	if ($showfilesincat == 1) {
		echo "<input type='radio' name='xshowfilesincat' value='1' checked>"._YES." &nbsp;<input type='radio' name='xshowfilesincat' value='0'>"._NO."";
    } else {
        echo "<input type='radio' name='xshowfilesincat' value='1'>"._YES." &nbsp;<input type='radio' name='xshowfilesincat' value='0' checked>"._NO."";
    }
	echo "</td></tr><tr><td>Выводит количество файлов в подкатегориях?</td><td>";
	if ($showfilesinsubcat == 1) {
		echo "<input type='radio' name='xshowfilesinsubcat' value='1' checked>"._YES." &nbsp;<input type='radio' name='xshowfilesinsubcat' value='0'>"._NO."";
    } else {
        echo "<input type='radio' name='xshowfilesinsubcat' value='1'>"._YES." &nbsp;<input type='radio' name='xshowfilesinsubcat' value='0' checked>"._NO."";
    }
	echo "</td></tr></table>";
	echo "<center><br><input type='hidden' name='op' value='media2Save'><input type='submit' value='" . _SAVECHANGES . "'></center></form>";
	CloseTable();

}

function media2Save($xtemp_path, $xpath, $xmax_size, $xftypefile, $xfiwidth, $xfiheight, $xfigdwidth, $xnumsubkat, $xtabcolumn, $xfilenum, $xfile_t, $xfilelistnum, $xnlinks, $xlangtm, $xformatm, $xqualitym, $xfigdactive, $xcommentfiles, $xpoolfiles, $xaddfiles, $xaddquest, $xshowsubkat, $xbroclink, $xdownfiles, $xuploadfiles, $xshowtext, $xviewimg, $xshowimgcat, $xshowfilesincat, $xshowfilesinsubcat) {
	global $admin_file;
	$protect = array("\n" => "", "\t" => "", "\r" => "", " " => "");
	$xftypefile = (!$xftypefile) ? "gif,jpg,jpeg,png" : strtolower(strtr($xftypefile, $protect));
	$xfile_t = (!$xfile_t) ? 86400 : intval($xfile_t * 86400);
	$xfilelistnum = (!intval($xfilelistnum)) ? 50 : $xfilelistnum;
	$xnlinks = (!intval($xnlinks)) ? 10 : $xnlinks;
	$xmax_size = (!intval($xmax_size)) ? 51200 : $xmax_size;
	$xfiwidth = (!intval($xfiwidth)) ? 500 : $xfiwidth;
	$xfiheight = (!intval($xfiheight)) ? 500 : $xfiheight;
	$xfigdwidth = (!intval($xfigdwidth)) ? 150 : $xfigdwidth;
	$content = "\$temp_path = \"$xtemp_path\";\n";
	$content .= "\$path = \"$xpath\";\n";
	$content .= "\$max_size = \"$xmax_size\";\n";
	$content .= "\$ftypefile = \"$xftypefile\";\n";
	$content .= "\$fiwidth = \"$xfiwidth\";\n";
	$content .= "\$fiheight = \"$xfiheight\";\n";
	$content .= "\$figdwidth = \"$xfigdwidth\";\n";
	$content .= "\$numsubkat = \"$xnumsubkat\";\n";
	$content .= "\$tabcolumn = \"$xtabcolumn\";\n";
	$content .= "\$filenum = \"$xfilenum\";\n";
	$content .= "\$file_t = \"$xfile_t\";\n";
	$content .= "\$filelistnum = \"$xfilelistnum\";\n";
	$content .= "\$nlinks = \"$xnlinks\";\n";
	$content .= "\$langtm = \"$xlangtm\";\n";
	$content .= "\$formatm = \"$xformatm\";\n";
	$content .= "\$qualitym = \"$xqualitym\";\n";
	$content .= "\$figdactive = \"$xfigdactive\";\n";
	$content .= "\$commentfiles = \"$xcommentfiles\";\n";
	$content .= "\$poolfiles = \"$xpoolfiles\";\n";
	$content .= "\$addfiles = \"$xaddfiles\";\n";
	$content .= "\$addquest = \"$xaddquest\";\n";
	$content .= "\$showsubkat = \"$xshowsubkat\";\n";
	$content .= "\$broclink = \"$xbroclink\";\n";
	$content .= "\$downfiles = \"$xdownfiles\";\n";
	$content .= "\$uploadfiles = \"$xuploadfiles\";\n";
	$content .= "\$showtext = \"$xshowtext\";\n";
	$content .= "\$viewimg = \"$xviewimg\";\n";
	$content .= "\$showimgcat = \"$xshowimgcat\";\n";
	$content .= "\$showfilesincat = \"$xshowfilesincat\";\n";
	$content .= "\$showfilesinsubcat = \"$xshowfilesinsubcat\";\n";
	save_conf("config/config_media2.php", $content);
	Header("Location: ".$admin_file.".php?op=media2conf");
}

switch ($op) {
	case "media2":
    media2();
    break;

	case "add_media2":
    add_media2();
    break;

	case "cat_media2":
    cat_media2();
    break;

    case "add_media2_category":
    add_media2_category($title, $description, $imgcat);
    break;

    case "add_media2_sub_cat":
    add_media2_sub_cat($cid, $title, $description, $imgsubcat);
    break;

    case "edit_media2_category":
    edit_media2_category($cid);
    break;

    case "save_media2_category":
    save_media2_category($cid, $title, $description, $imgcat, $parentid);
    break;

    case "del_media2_cat":
    del_media2_cat($cid, $ok);
    break;

    case "media2_save":
    media2_save($title, $description, $cid, $filelink, $author, $albumn, $year, $langt, $format, $quality, $links, $time, $director, $f_roles, $size);
    break;

    case "new_media2":
    new_media2();
    break;

    case "brocen_media2":
    brocen_media2();
    break;

    case "edit_media2":
    edit_media2($lid);
    break;

    case "media2_edit_save":
    media2_edit_save($lid, $title, $description, $cid, $filelink, $author, $albumn, $year, $langt, $format, $quality, $links, $time, $director, $f_roles, $size, $f_date);
    break;

    case "delit_media2":
    delit_media2($lid, $ok);
    break;

    case "view_add_media2":
    view_add_media2($lid);
    break;

    case "ignore_broc_media2":
    ignore_broc_media2($lid);
    break;

    case "move_media2_cat":
    move_media2_cat($fromcid, $incid);
    break;

    case "media2_add_save":
    media2_add_save($lid, $title, $description, $cid, $filelink, $author, $albumn, $year, $langt, $format, $quality, $links, $time, $director, $f_roles, $size);
    break;

	case "media2conf":
    media2conf();
    break;

    case "media2Save":
    media2Save($xtemp_path, $xpath, $xmax_size, $xftypefile, $xfiwidth, $xfiheight, $xfigdwidth, $xnumsubkat, $xtabcolumn, $xfilenum, $xfile_t, $xfilelistnum, $xnlinks, $xlangtm, $xformatm, $xqualitym, $xfigdactive, $xcommentfiles, $xpoolfiles, $xaddfiles, $xaddquest, $xshowsubkat, $xbroclink, $xdownfiles, $xuploadfiles, $xshowtext, $xviewimg, $xshowimgcat, $xshowfilesincat, $xshowfilesinsubcat);
    break;
}
?>