<?php
if (!defined('ADMIN_FILE')) {
	die("Illegal File Access");
}

function validnew() {
	global $prefix, $offset, $gallerypath, $temppath, $db, $admin_file;
	include("header.php");
	navigationAdmin("<b><a href=\"".$admin_file.".php?op=album&do=showoptions\">"._GALCONFIG."</a></b> &gt;&gt; <b>"._GALVALIDNEWMEDIA."</b>");
	OpenTable();
	echo "<form method=\"POST\" action=\"".$admin_file.".php?op=album\"><input type=\"hidden\" name=\"op\" value=\"album\"><input type=\"hidden\" name=\"do\" value=\"validnew\"><input type=\"hidden\" name=\"type\" value=\"validate\">";
	echo "<center><font class=\"option\"><b>"._GALPOSTEDMEDIA."</b></font><br><br>";
	$sql = "SELECT count(*) FROM $prefix"._album_pictures_newpicture."";
	$result = $db->sql_query($sql);
	$limit = 5;
	echo "<input type=\"hidden\" name=\"limit\" value=\"$limit\">";
	list($numrows) = $db->sql_fetchrow($result);
	if ($numrows>0) {
		if (!isset($offset) || $offset=="") {
			$offset=0;
		}
		$pages = intval($numrows/$limit);
		$offset = intval($offset);
		$limit = intval($limit);
		$sql = "SELECT pid, gid, img, submitter, date, name, description, width, height FROM $prefix"._album_pictures_newpicture." LIMIT $offset, $limit";
		$res = $db->sql_query($sql);
		if ($offset!=0) {
			$prevoffset = $offset-$limit;
			$gid = intval($gid);
			$nav = "<a href=\"".$admin_file.".php?op=album&do=validnew&amp;type=checknew&amp;offset=$prevoffset\">[&lt;&lt;]</a>&nbsp;[&nbsp;";
		}
		if ($numrows%$limit) {
			$pages++;
		}
		for ($i=1;$i<=$pages; $i++) {
			$newoffset=$limit*($i-1);
			if ($newoffset==$offset) {
				if ($i==1) {
					if ($pages==1) {
						$nav .= "[ ".$i." ]";
					} else {
						$nav .= "[ ".$i."&nbsp;|&nbsp;";
					}
				} elseif ($i==$pages) {
					$nav .= $i."&nbsp;]";
				} else {
					$nav .= $i."&nbsp;|&nbsp;";
				}
			} else {
				$gid = intval($gid);
				if ($i < $pages) {
					$nav .= "<a href=\"".$admin_file.".php?op=album&do=validnew&amp;type=checknew&amp;offset=$newoffset\"><b>$i</b></a>&nbsp;|&nbsp;";
				} else {
					$nav .= "<a href=\"".$admin_file.".php?op=album&do=validnew&amp;type=checknew&amp;offset=$newoffset\"><b>$i</b></a>&nbsp;]&nbsp;";
				}
			}
		}
		if (!(($offset/$limit)==($pages-1)) && $pages!=1) {
			$gid = intval($gid);
			$newoffset=$offset+$limit;
			$nav .= "<a href=\"".$admin_file.".php?op=album&do=validnew&amp;type=checknew&amp;offset=$newoffset\">[&gt;&gt;]</a>";
		}
		echo "$nav</center>";
		echo "<table border=\"0\" align=\"center\">";
		$i=0;
		while (list($pid, $gid, $img, $submitter, $date, $name, $description, $width, $height) = $db->sql_fetchrow($res)) {
			echo "<tr><td><table border=\"0\" class=\"bodyline\"><tr><td><a href=\"$temppath/$img\" target=\"_blank\"><img src=\"$temppath/$img\" border=\"0\" height=\"250\" width=\"250\"></a></td></tr></table>";
			echo "</td><td><table border=\"0\"><tr><td>"._GALFILENAME.":</td><td><input type=\"hidden\" name=\"OldFileName$i\" value=\"$img\"><input type=\"hidden\" name=\"FileId$i\" value=\"$pid\"><input type=\"text\" name=\"FileName$i\" size=\"50\" value=\"$img\" style=\"width=300px\"></td></tr><tr><td>"._GALVALIDNEW.":</td><td><input type=\"radio\" name=\"Task$i\" value=\"Validate\" checked></td></tr><tr><td>"._GALDELETE.":</td><td><input type=\"radio\" name=\"Task$i\" value=\"Delete\"></td></tr><tr><td>"._GALSELECTCATEGORY.":</td><td><select name=\"Category$i\" style=\"width=300px\">";
			$categories = listcategories("$gallerypath");
			$categories = explode(" ", trim($categories));
			while(list($key, $val) = each($categories)) {
				$result = $db->sql_query("select gallid, gallname, parent from $prefix"._album_categories." where gallid=".$val);
				list($gallid, $gallname, $parent) = $db->sql_fetchrow($result);
				$nbtabs = indent($gallid);
				$tab = "";
				for ($j=0; $j<$nbtabs; $j++) $tab .= "&nbsp;&nbsp;";
				if ($gallid==$gid) {
					echo "<option selected value=\"$gallid\">$tab$gallname</option>";
				} else {
					echo "<option value=\"$gallid\">$tab$gallname</option>";
				}
			}
			echo "</select></td></tr><tr><td>"._GALWIDTHXHEIGHT.":</td><td><input type=\"text\" name=\"Width$i\" size=\"4\" value=\"$width\"> x <input type=\"text\" name=\"Height$i\" size=\"4\" value=\"$height\"></td></tr><tr><td>"._GALMEDIANAME.":</td><td><input type=\"text\" name=\"MediaName$i\" size=\"50\" value=\"$name\" style=\"width=300px\"></td></tr><tr><td>"._GALDATEADDED.":</td><td><input type=\"text\" name=\"Date$i\" size=\"50\" value=\"$date\" style=\"width=300px\"></td></tr><tr><td>"._GALSUBMITTER.":</td><td><input type=\"text\" name=\"Submitter$i\" size=\"50\" value=\"$submitter\" style=\"width=300px\"></td></tr><tr><td>"._GALDESCRIPTION.":</td><td><textarea  name=\"Description$i\" rows=\"5\" cols=\"50\" style=\"width=300px\">$description</textarea></td></tr></table></td></tr>";
			$i++;
		}
		echo "<tr><td colspan=\"2\" align=\"center\"><br><input type=\"submit\" value=\""._SAVECHANGES."\" name=\"add\"></td></tr>";
	}
	echo "</table></form>";
	CloseTable();
	include("footer.php");;
}
?>