<?php 
define('THIS_SCRIPT', 'os_publisher');
include "admin/main/config.php";

$vbulletin->input->clean_array_gpc('r', array(
	'id'  => TYPE_UINT
));

if (!$vbulletin->GPC['id'])
{
?>
	<script type="text/javascript"><!--
		tb_remove();
	//--></script>
<?php
	exit;
}

$release = $vbulletin->db->query_first("
	SELECT release_date AS dateline, console_id, game_title, notallowed
	FROM cms_game
	WHERE id = {$vbulletin->GPC['id']}
");

if (!$vbulletin->userinfo['userid'])
{
?>
	<script type="text/javascript"><!--
		tb_remove();
		if (confirm("You have to be a registered member to post a <?php echo (!$release['notallowed'] AND $release['dateline'] <= TIMENOW)? 'Reader' : 'Hype'; ?> Score. Would you like to register now?"))
		{
			window.location = "<?php echo "{$vbulletin->options['bburl2']}/register.php"; ?>";
		}
	//--></script>
<?php
	exit;
}

$type = (!$release['notallowed'] AND $release['dateline'] <= TIMENOW)? 'RS' : 'HS';

//removed so user can Update his Vote Comment
/*
$score = $vbulletin->db->query_first("
	SELECT game_id
	FROM cms_readerscore
	WHERE game_id = " . intval($_REQUEST['id']) . " AND userid = {$vbulletin->userinfo['userid']} AND type = '$type'
");

if ($score['game_id'])
{
/
?>

	<script type="text/javascript"><!--
		tb_remove();
		window.alert("You have already added your <?php echo (!$release['notallowed'] AND $release['dateline'] <= TIMENOW)? 'Reader Score' : 'Hype Score'; ?> for <?php echo $release['game_title']; ?>. To read other <?php echo (!$release['notallowed'] AND $release['dateline'] <= TIMENOW)? 'Reader Scores' : 'Hype Scores'; ?> click the View All link.");
	//--></script>
<?php
	exit;
}
*/
$platforms = $vbulletin->db->query_read("
	SELECT name, id
	FROM cms_console
	WHERE id IN ($release[console_id])
");

?>
<style type="text/css">
<!--
.rating {
margin-top:-10px;
	height: 40px;
	cursor: pointer;
	clear: both;
	display: block;
}
.rating:after {
	content: '.';
	display: block;
	height: 0;
	width: 0;
	clear: both;
	visibility: hidden;
}
.cancel,
.star {
	float: left;
	width: 25px;
	height: 25px;
	overflow: hidden;
	text-indent: -999em;
	cursor: pointer;
}
.star-left,
.star-right {
  width: 13px
}
.cancel,
.cancel a {background: url(/images/os-delete.gif) no-repeat 0 25px; display:none}

.star,
.star a {background: url(/images/os-star.gif) no-repeat 0 0px;}
.star-left,
.star-left a {background: url(/images/os-star-left.gif) no-repeat 0 0px;}
.star-right,
.star-right a {background: url(/images/os-star-right.gif) no-repeat 0 0px;}
	
.star a {
	display: block;
	width: 100%;
	height: 100%;
	background-position: 0 0px;
}

.cancel a {
	display: none;
	width: 100%;
	height: 100%;
	background-position: 0 0px;
}
div.rating div.on a {
	background-position: 0 -25px;
}
div.rating div.hover a,
div.rating div a:hover {
	background-position: 0 -25px;
}
#title_med_white{ background-image:url(/images/title_med_white.gif); height:35px; width:480px;}
#comment { font-size:11px; padding-top:5px; text-align:center; background-color:#FFF; width:478px; border-left: solid 1px #838d97; border-right: solid 1px #838d97; border-bottom: solid 1px #838d97;	background-image:url(/images/gen_whitebg.gif); background-repeat:repeat-y;}
#comment_row { text-align:left; padding:5px 10px 5px 10px; margin-bottom:0px; clear:both; overflow:auto; }
#title_text{ padding:6px 0 0 20px; color:#FFF; font-weight:bold; text-transform: uppercase;}
#comment_row1 { text-align:left; padding:5px 10px 5px 10px; margin-bottom:0px; overflow:auto; width:350px;}
#comment_row2 { text-align:left; padding:5px 10px 5px 10px; margin-bottom:0px; overflow:auto; width:80px;}

.newscomments, .newscomments a, .newsSub a { color:#9aa3ad; text-decoration:none; margin: 0px; }
.newscomments a:hover, .newsSub a:hover { color:#9aa3ad; text-decoration:underline; margin: 0px;}

#topfilter { color: #FFFFFF; border: 1px outset #FFFFFF; padding: 0; background-color: #293849; }
//--></style>
<div id="title_med_white" style="margin-top:5px;">
<?php
if (!$release['notallowed'] AND $release['dateline'] < TIMENOW)
{
?>
	<div id="title_text">Reader Score</div>
<?php
}
else
{
?>
	<div id="title_text">Hype Score</div>
<?php
}
?>
</div>
<div id="comment" style="overflow:hidden;">
	<form name="comments" action="/game.php?id=<?php echo $vbulletin->GPC['id']; ?>" method="post" onsubmit="osports_submit(this); return false;">
		<input type="hidden" name="score" id="hidden_score" value="0">
		<input type="hidden" name="do" value="score">
		<input type="hidden" name="id" value="<?php echo $vbulletin->GPC['id']; ?>">
		<?php
		if (!$release['notallowed'] AND $release['dateline'] < TIMENOW)
		{
		?>
		<div id="comment_row"><img src="/images/navarrow.gif" align="absmiddle" />&nbsp;<span class="newscomments"><strong><?php echo $vbulletin->userinfo['username']; ?></strong></span> <strong>tell us what you think about </strong><span class="newscomments"><strong><?php echo $release['game_title']; ?></strong></span></div>
		<?php
		}
		else
		{
		?>
		<div id="comment_row"><img src="/images/navarrow.gif" align="absmiddle" />&nbsp;<span class="newscomments"><strong><?php echo $vbulletin->userinfo['username']; ?></strong></span> <strong>how good do you think </strong><span class="newscomments"><strong><?php echo $release['game_title']; ?></strong></span> <strong>is going to be?</strong></div>
		<?php
		}
		?>
		<div id="comment_row">
			<span><strong>Rating:</strong></span>
			<div id="rate1" class="rating">&nbsp;</div>
			<div style="clear:both"><span id="ratingnum">0</span> out of 10</div>
			<strong>Platform:</strong><br />
			<select name="console" size="1" id="topfilter" style="width:80px; background-color: #585e66;">
			<?php
			while($platform = $vbulletin->db->fetch_array($platforms))
			{
			?>
				<option value="<?php echo $platform['id']; ?>"><?php echo $platform['name']; ?></option>
			<?php
			}
			?>
			</select>
			<br /><br />
			<strong>Comment:</strong><br />
			<?PHP 
			$score = $vbulletin->db->query_first("
			SELECT game_id, comment
			FROM cms_readerscore
			WHERE game_id = {$vbulletin->GPC['id']} AND userid = {$vbulletin->userinfo['userid']} AND type = '$type' ");

			if ($score['game_id'])
			{ $value = "Edited: ". str_replace("Edited: ","",$score['comment']); } else { $value = false; }
			?>
			<textarea style="width:450px; height:150px; font-size:12px; font-family:Arial, Helvetica, sans-serif;" name="comment"><?php echo $value; ?></textarea><br />
		</div>
		<div id="comment_row1" style="text-align:left; float:left;">
			<input type="image" src="/images/button_cancel.gif" name="submit" value="Cancel" onclick="tb_remove(); return false;">&nbsp;&nbsp;
		</div>
		<div id="comment_row2" style="text-align:right; float:right;">
			<input type="image" src="/images/button_submit.gif" name="submit" value="Submit">&nbsp;&nbsp;
		</div>
	</form>
</div>

<script type="text/javascript">
<!--
var ratingDiv  = fetch_object('ratingnum');

osImg = new Array();
osImg[0] = new Image();
osImg[0].src = "http://www.operationsports.com/images/os-star.gif";

osImg[1] = new Image();
osImg[1].src = "http://www.operationsports.com/images/os-star-right.gif";

osImg[2] = new Image();
osImg[2].src = "http://www.operationsports.com/images/os-star-left.gif";

osImg[3] = new Image();
osImg[3].src = "http://www.operationsports.com/images/os-delete.gif";

osImg[4] = new Image();
osImg[4].src = "http://www.operationsports.com/images/title_med_white.gif";

osImg[5] = new Image();
osImg[5].src = "http://www.operationsports.com/images/gen_whitebg.gif";

osImg[6] = new Image();
osImg[6].src = "http://www.operationsports.com/images/button_submit.gif";

osImg[7] = new Image();
osImg[7].src = "http://www.operationsports.com/images/button_cancel.gif";

jQuery.fn.rating = function(options) {
	
	var settings = {
    increment : .5, // value to increment by
    maxvalue  : 10,   // max number of stars
    curvalue  : 0    // number of selected stars
  };
  
  if(options) {
    jQuery.extend(settings, options);
  };
  jQuery.extend(settings, {cancel: (settings.maxvalue > 1) ? true : false});
   
   
  var container = jQuery(this);
	
	jQuery.extend(container, {
    averageRating: settings.curvalue
  });
  settings.increment = (settings.increment < .75) ? .5 : 1;
  var s = 0;
	for(var i= 0; i <= settings.maxvalue ; i++){
    if (i == 0) {
	    if(settings.cancel == true){
        var div = '<div class="cancel"><a href="#0" title="Cancel Rating">Cancel Rating</a></div>';
        container.append(div);
      }
    } else {
      var $div = $('<div class="star"></div>')
        .append('<a href="#'+i+'" title="Give it '+i+'/'+settings.maxvalue+'">'+i+'</a>')
        .appendTo(container);
      if (settings.increment == .5) {
        if (s%2) {
          $div.addClass('star-left');
        } else {
          $div.addClass('star-right');
        }
      }
    }
    i=i-1+settings.increment;
    s++;
  }
	
	var stars = jQuery(container).children('.star');
  var cancel = jQuery(container).children('.cancel');
	
  stars
    .mouseover(function(){
      event.drain();
      event.fill(this);
      ratingDiv.innerHTML = jQuery(this).children('a')[0].href.split('#')[1];
    })
    .mouseout(function(){
      event.drain();
      event.reset();
      ratingDiv.innerHTML = settings.curvalue;
    })
    .focus(function(){
      event.drain();
      event.fill(this);
    })
    .blur(function(){
      event.drain();
      event.reset();
    });

  stars.click(function(){
		if(settings.cancel == true){
      settings.curvalue = (stars.index(this) * settings.increment) + settings.increment;
      $("input#hidden_score").val(jQuery(this).children('a')[0].href.split('#')[1]);
      ratingDiv.innerHTML = settings.curvalue;
			return false;
		} else if (settings.maxvalue == 1) {
			settings.curvalue = (settings.curvalue == 0) ? 1 : 0;
			$(this).toggleClass('on');
			$("input#hidden_score").val(jQuery(this).children('a')[0].href.split('#')[1]);
			ratingDiv.innerHTML = settings.curvalue;
			return false;
		}
		return true;
			
  });

  // cancel button events
	if(cancel){
    cancel
    .mouseover(function(){
      event.drain();
      jQuery(this).addClass('on');
    })
    .mouseout(function(){
      event.reset();
      jQuery(this).removeClass('on');
    })
    .focus(function(){
      event.drain();
      jQuery(this).addClass('on');
    })
    .blur(function(){
      event.reset();
      jQuery(this).removeClass('on');
    });
      
    // click events.
    cancel.click(function(){
      event.drain();
      settings.curvalue = 0;
      $("input#hidden_score").val(0);
      return false;
    });
  }
        
	var event = {
		fill: function(el){ // fill to the current mouse position.
			var index = stars.index(el) + 1;
			stars
				.children('a').css('width', '100%').end()
				.slice(0,index).addClass('hover').end();
		},
		drain: function() { // drain all the stars.
			stars
				.filter('.on').removeClass('on').end()
				.filter('.hover').removeClass('hover').end();
		},
		reset: function(){ // Reset the stars to the default index.
			stars.slice(0,settings.curvalue / settings.increment).addClass('on').end();
		}
	};    
	event.reset();
	
	return(this);	
};

function osports_submit(thisobj)
{
	var form = new vB_Hidden_Form('ajax.php');

	form.add_variables_from_object(thisobj);

	$.ajax({
		type: "POST",
		url: "/ajax.php",
		data: form.build_query_string(),
		dataType: 'text',
		cache: false,
		timeout: vB_Default_Timeout,
		success: function(responseText) {
			switch(responseText)
			{
				case 'error #1':
					if (confirm("You have to be a registered member to submit a <?php echo (!$release['notallowed'] AND $release['dateline'] <= TIMENOW)? 'Reader' : 'Hype'; ?> Score. Would you like to register now?"))
					{
						tb_remove();
						window.location = "<?php echo "{$vbulletin->options['bburl2']}/register.php"; ?>";
					}
					break;
				case 'error #2':
					window.alert("Incorrect game selected, you may need to reload the page.");
					break;
				case 'error #3':
					window.alert("You have already added your <?php echo (!$release['notallowed'] AND $release['dateline'] <= TIMENOW)? 'Reader Score' : 'Hype Score'; ?> for <?php echo $release['game_title']; ?>. To read other <?php echo (!$release['notallowed'] AND $release['dateline'] <= TIMENOW)? 'Reader Score' : 'Hype Score'; ?> click the View All link.");
					tb_remove();
					break;
				case 'error #4':
					window.alert('Missing fields. Please make sure you have completed all the fields and selected an score value.');
					break;
				case 'UPDATE':
					window.alert("Your <?php echo (!$release['notallowed'] AND $release['dateline'] <= TIMENOW)? "Reader" : "Hype"; ?> Score has been Updated.");
					tb_remove();
					window.location.href = '/game.php?id=<?php echo $vbulletin->GPC['id']; ?>&goto=comment';
					break;
				case 'OK':
					window.alert("Your <?php echo (!$release['notallowed'] AND $release['dateline'] <= TIMENOW)? "Reader" : "Hype"; ?> Score has been added.");
					tb_remove();
					window.location.href = '/game.php?id=<?php echo $vbulletin->GPC['id']; ?>&goto=comment';
					break;
				case 'error #0':
				default:
					window.alert("Unfortunately there was an unexpected error submitting your data. Please try again.");
					tb_remove();
					break;
			}
		}
	});
}

$('#rate1').rating({maxvalue:10, increment:.5, cancel:false});
//--></script>
<?php 

exec_shut_down();

?>