<?php 
define('THIS_SCRIPT', 'os_media');
$loadCacheItems = array('lastFive');
include "admin/main/config.php";

checkUrlCorrectness('media');
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "//www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<head>
<title>Operation Sports - Sports Video Games Screenshots and Videos</title>
<meta name="description" content="Operation Sports - is dedicated to information about sports video games, Madden, Fifa, sports news, press releases, reviews, screenshots of games" />
<meta name="keywords" content="Media, Screenshots, Videos, Sports Video Games, Sports Video Games press releases, sports Screenshots, Madden Screenshots, Madden 25, FIFA Screenshots, FIFA, sports, video games, Football Screenshots, Baseball Screenshots, Basketball Screenshots, Golf Screenshots, Hockey Screenshots, games Screenshots, sports Screenshots, games Videos, sports Videos  " />

<link rel="stylesheet" type="text/css" media="screen" href="//forums.operationsports.com/css/gen_stylev3_<?=filemtime('css/gen_stylev3.css')?>.css">
	<link rel="stylesheet" type="text/css" media="screen" href="//forums.operationsports.com/css/profilev4_responsive.css">
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript">
<!--
	var minchars = <?php echo $vbulletin->options['postminchars']?>;
	var SECURITYTOKEN = "<?=$vbulletin->userinfo['securitytoken']?>";
	var BBURL = '<?=$vbulletin->options['bburl2']?>';
	var IMGDIR_MISC = "<?=$stylevar['imgdir_misc']?>";
	var SESSIONURL = "<?=$session['sessionurl_js']?>";
//-->
</script>
	<script type="text/javascript" src="//forums.operationsports.com/js/yahoo/yahoo-dom-event.js?v=<?php echo $vbulletin->options['simpleversion']; ?>"></script>
	<script type="text/javascript" src="//forums.operationsports.com/js/yahoo/connection-min.js?v=<?php echo $vbulletin->options['simpleversion']; ?>"></script>

<script type="text/javascript" src="//forums.operationsports.com<?php echo $vbulletin->options['bburl2']; ?>/clientscript/vbulletin_global.js?v=<?php echo $vbulletin->options['simpleversion']; ?>"></script>
<script type="text/javascript" src="//forums.operationsports.com<?php echo $vbulletin->options['bburl2']; ?>/clientscript/vbulletin_menu.js?v=<?php echo $vbulletin->options['simpleversion']; ?>"></script>
<link rel="shortcut icon" href="/favicon.ico" >
</head>
<?php
include ("include/header_intergiv3.inc.php");
include (DIR . "/include/bannerlogin_temp_test_intergi.inc.php");
?>
<?php

/* if filter */

$vbulletin->input->clean_array_gpc('r', array(
	'Filter' => TYPE_STR,
	'console' => TYPE_STR,
	'sport' => TYPE_STR,
	'added' => TYPE_STR,
	'order' => TYPE_STR,
	'sortby' => TYPE_STR,
	'media' => TYPE_STR,
	'page' => TYPE_UINT
));

if (empty($vbulletin->GPC['media']))
{
	$vbulletin->GPC['media'] = 'images';
}

if($vbulletin->GPC["Filter"] == "Filter")
{
	$where="";
	$and="";
	if($vbulletin->GPC["console"]!="")
	{
		$where=" where " . " cms_media.console_id LIKE '%" . $vbulletin->db->escape_string($vbulletin->GPC["console"]) . "%' ";
		$and="and";
	}
	if($vbulletin->GPC["sport"]!="")
	{
		if($where=="")
		{
			$where=" where ";
		}
		
		$where.=" " . $and . " cms_media.sport_id LIKE '%" . $vbulletin->db->escape_string($vbulletin->GPC["sport"]) . "%' ";
		$and="and";
	}
	if($vbulletin->GPC["added"]!="")
	{
		if($where=="")
		{
			$where=" where ";
		}

		if($vbulletin->GPC['media'] == 'images')
		{
			$where.=" " . $and . " date_format(FROM_UNIXTIME(cms_media.shotupdated),'%Y')='" . $vbulletin->db->escape_string($vbulletin->GPC["added"]) . "' ";
		}
		else if($vbulletin->GPC['media'] == 'videos')
		{
			$where.=" " . $and . " date_format(FROM_UNIXTIME(cms_media.videoupdated),'%Y')='" . $vbulletin->db->escape_string($vbulletin->GPC["added"]) . "' ";
		}
		else
		{
			$where.=" " . $and . " date_format(FROM_UNIXTIME(cms_media.dateupdated),'%Y')='" . $vbulletin->db->escape_string($vbulletin->GPC["added"]) . "' ";
		}

		$and="and";
	}
	if($vbulletin->GPC['media'] == 'videos')
	{
		if($where=="")
		{
			$where=" where ";
		}

		$where.=" " . $and . " (cms_video.vimeoid > 0 OR (cms_osvideo.id > 0 AND cms_osvideo.state = 2))";
		$and="and";
	}
	else if($vbulletin->GPC['media'] == 'images')
	{
		if($where=="")
		{
			$where=" where ";
		}

		$where.=" " . $and . " cms_screenshot.id > 0 ";
		$and="and";
	}
}

switch($vbulletin->GPC['sortby'])
{
	case 'title':
		$sortby = 'cms_game.game_title';
		break;
	case 'platform':
		$sortby = 'cms_media.console_id';
		break;
	case 'date':
	default:
		if($vbulletin->GPC['media'] == 'images')
		{
			$sortby = 'cms_media.shotupdated';
		}
		else if($vbulletin->GPC['media'] == 'videos')
		{
			$sortby = 'cms_media.videoupdated';
		}
		else
		{
			$sortby = 'cms_media.dateupdated';
		}
		break;
}

switch($vbulletin->GPC['order'])
{
	case 'desc':
	case 'asc':
		$order = $vbulletin->GPC['order'];
		break;
	default:
		$order = 'desc';
}

$pagedata = $vbulletin->db->query_first("
	SELECT COUNT(DISTINCT(cms_screenshot.media_id)) AS count
	FROM cms_media
	LEFT JOIN cms_game ON (cms_media.game_id = cms_game.id)
	LEFT JOIN cms_screenshot ON (cms_screenshot.media_id = cms_media.id)
	LEFT JOIN cms_video ON (cms_video.media_id = cms_media.id)
	LEFT JOIN cms_osvideo ON (cms_osvideo.media_id = cms_media.id)
	$where
");
//$pagedata['count'] = ($pagedata['count'] > 400)? 400 : $pagedata['count'];
$pagedata['pagenumber'] = ($vbulletin->GPC['page'] > 1)? $vbulletin->GPC['page'] : 1;

$pagedata['minlimit']   = intval(($pagedata['pagenumber'] - 1) * 40);

$cnx = $vbulletin->db->query_read("
	SELECT DISTINCT(cms_media.id) AS media_id, cms_media.console_id AS platforms, UNIX_TIMESTAMP(cms_media.dateupdated) AS updated, cms_media.shotupdated, cms_media.videoupdated,
		cms_game.game_title, cms_game.game_title
	FROM cms_media AS cms_media
	LEFT JOIN cms_game AS cms_game ON (cms_media.game_id = cms_game.id)
	LEFT JOIN cms_screenshot AS cms_screenshot ON (cms_screenshot.media_id = cms_media.id)
	LEFT JOIN cms_video ON (cms_video.media_id = cms_media.id)
	LEFT JOIN cms_osvideo ON (cms_osvideo.media_id = cms_media.id)
	$where
	ORDER BY $sortby $order
	LIMIT $pagedata[minlimit], 40
");
?>

	<div id="content">

<div id="title_med">
	<div id="title_text">Media</div>
</div>
<div id="overview">
<!--News post-->
	<div id="articlewrapp">
			<div id="articletext">
			<div class="articlecontent">

<center>
<form name="frmFilter" method="post">
	<input type="hidden" name="media" value="<?php echo $vbulletin->GPC['media']; ?>">
	<inpyt type="hidden" name="Filter" value="Filter">
	<?php
	/*platform*/

	$cnxconsole = $db->query_read("SELECT * FROM cms_console ORDER BY name");
	?>
	<select name="console" size="1" id="topfilter">
		<option value="">Platform</option>
		<?php
		while($resconsole = $db->fetch_array($cnxconsole))
		{
			if($vbulletin->GPC["console"]!="" && $vbulletin->GPC["console"]==$resconsole["id"])
			{
		?>
				<option value="<?php echo $resconsole["id"]; ?>" selected><?php echo $resconsole["name"];  ?></option>
		<?php
			}
			else
			{
		?>
				<option value="<?php echo $resconsole["id"]; ?>"><?php echo $resconsole["name"];  ?></option>
		<?php
			}
		}
		?>
	</select>
	<select name="media" size="1" id="topfilter">
		<option value="">Media</option>
		<option value="all" <?php echo ($vbulletin->GPC['media'] == 'all')? 'selected': ''; ?>>All</option>
		<option value="images" <?php echo ($vbulletin->GPC['media'] == 'images')? 'selected': ''; ?>>Screenshots</option>
		<option value="videos" <?php echo ($vbulletin->GPC['media'] == 'videos')? 'selected': ''; ?>>Videos</option>
	</select>
	<?php
	/*sport*/

	$cnxsport = $db->query_read("SELECT * FROM cms_sport WHERE hidden = 0 ORDER BY name");
	?>
	<select name="sport" size="1" id="topfilter">
		<option value="">Sport</option>
		<?php
		while($ressport = $db->fetch_array($cnxsport))
		{
			if($vbulletin->GPC["sport"]!="" && $vbulletin->GPC["sport"]==$ressport["id"])
			{
		?>
				<option value="<?php echo $ressport["id"]; ?>" selected><?php echo $ressport["name"];  ?></option>
		<?php
			}
			else
			{
		?>
				<option value="<?php echo $ressport["id"]; ?>"><?php echo $ressport["name"];  ?></option>
		<?php
			}
		}
		?>
	</select>

	<select name="added" size="1" id="topfilter">
		<option value="">Added</option>
		<?php
		$resadded = $db->query_first("SELECT MIN(date_format(dateupdated,'%Y')) AS minyear FROM cms_media");
		$yearstart = $resadded["minyear"];

		$resadded = $db->query_first("SELECT MAX(date_format(dateupdated,'%Y')) AS maxyear FROM cms_media");
		$yearend = $resadded["maxyear"];

		for($k=$yearstart;$k<=$yearend;$k++)
		{
			if($vbulletin->GPC["added"] != "" && $vbulletin->GPC["added"] == $k)
			{
		?>
				<option value="<?php echo $k; ?>" selected><?php echo $k; ?></option>
		<?php
			}
			else
			{
		?>
				<option value="<?php echo $k; ?>"><?php echo $k; ?></option>
		<?php
			}
		}
		?>
	</select>

	<input type="submit" name="Filter" value="Filter"/>

</form>

</center>
<br/>

	<div id="over_row">
		<div id="over_column_210"><a href="?<?php echo "Filter={$vbulletin->GPC['Filter']}&page={$vbulletin->GPC['page']}&media={$vbulletin->GPC['media']}&sport={$vbulletin->GPC['sport']}&console={$vbulletin->GPC['console']}&added={$vbulletin->GPC['added']}"; ?>&<?if ($vbulletin->GPC["order"]=="desc" && $vbulletin->GPC["sortby"]=="title") {?>sortby=title&order=asc<?}else {?>sortby=title&order=desc<?}?>" class="white">Game Title</a></div>
		<div id="over_column_55" class="scHiddenMobile"><a href="?<?php echo "Filter={$vbulletin->GPC['Filter']}&page={$vbulletin->GPC['page']}&media={$vbulletin->GPC['media']}&sport={$vbulletin->GPC['sport']}&console={$vbulletin->GPC['console']}&added={$vbulletin->GPC['added']}"; ?>&<?if ($vbulletin->GPC["order"]=="desc"  && $vbulletin->GPC["sortby"]=="platform"){?>sortby=platform&order=asc<?}else {?>sortby=platform&order=desc<?}?>" class="white">Platform</a></div>
		<div id="over_column_45" class="scHiddenMobile">Shots</div>
		<div id="over_column_45" class="scHiddenMobile">Videos</div>
		<div id="over_column_58" class="scHiddenMobile"><a href="?<?php echo "Filter={$vbulletin->GPC['Filter']}&page={$vbulletin->GPC['page']}&media={$vbulletin->GPC['media']}&sport={$vbulletin->GPC['sport']}&console={$vbulletin->GPC['console']}&added={$vbulletin->GPC['added']}"; ?>&<?if ($vbulletin->GPC["order"]=="desc"  && $vbulletin->GPC["sortby"]=="date"){?>sortby=date&order=asc<?}else {?>sortby=date&order=desc<?}?>" class="white">Updated</a></div>
	</div>

<?php 
	while($res = $vbulletin->db->fetch_array($cnx))
	{
		//$sport_id=explode(":",$res["sport_id"]);
		$console_id=explode(":",$res["platforms"]);

		$ressportname="";
		$resconsolename="";

		for($count=0;$count<sizeof($console_id);$count++)
		{
			$cnxconsole = $db->query_read("SELECT * FROM cms_console WHERE id = " . $console_id[$count]);
			$line=0;
			while ($resconsole = $db->fetch_array($cnxconsole))
			{
				$resconsolename.=$resconsole["name"] . "<br/>";
				$line=$line+1;
			}
		}

?>
	<div id="over_row">
		<div id="over_column0_210"><a href="<?php echo getUrl('media', $res['game_title'], $res['media_id'])?>" class="news"><?php echo $res["game_title"]; ?></a></div>
		<div id="over_column0_55" class="scHiddenMobile"><? echo $resconsolename; ?></div>
		<div id="over_column0_45" class="scHiddenMobile">
		<?php
		$rows = $vbulletin->db->query_first("SELECT COUNT(*) AS count FROM cms_screenshot WHERE media_id = $res[media_id]");
		
		echo $rows['count']; 
		?></div>
		<div id="over_column0_45" class="scHiddenMobile">
		<? 
		$vimeo   = $vbulletin->db->query_first("SELECT COUNT(*) AS count FROM cms_video WHERE media_id = $res[media_id]");
		$osvideo = $vbulletin->db->query_first("SELECT COUNT(*) AS count FROM cms_osvideo WHERE media_id = $res[media_id] AND state = 2");
		
		echo $vimeo['count'] + $osvideo['count']; 
		?></div>
		<div id="over_column0_58" class="scHiddenMobile">
		<?php 
		if($vbulletin->GPC['media'] == 'videos')
		{
			echo vbdate("M d, Y", $res["videoupdated"]);
		}
		else
		{
			echo vbdate("M d, Y", $res["shotupdated"]);
		}?></div>
	</div>
<?
	}

?>
			</div>
			
		</div>
<?php
if ($pagedata['count'] > 40)
{
?>
<div align="center">
<div id="link_row2">

<div align="center">
<?php
	require_once('include/pagination.inc.php');
	$pagelink="?";
	$pagelink .= "Filter=Filter&sport={$vbulletin->GPC['sport']}&media={$vbulletin->GPC['media']}&console={$vbulletin->GPC['console']}&added={$vbulletin->GPC['added']}&sortby={$vbulletin->GPC['sortby']}&order={$vbulletin->GPC['order']}&page=";

	echo getPaginationString($pagedata['pagenumber'], $pagedata['count'], 40, 3, $pagelink, $pageand, false);
?>

</div>

		</div>
	</div>
<?php
}
?>
</div>

<!--News post-->

</div>

	</div>
	<div id="right">

		<?php include ("include/last5.inc.php"); ?>
    	<?php include ("include/ad300x250.inc.php"); ?>
		<?php include ("include/poll.inc.php"); ?>
	</div>
<?php 

include ("include/footer.inc.php"); 
exec_shut_down();

?>
