<?php
include("includes/site_info.php");
include("session_handler.inc");

if(!preg_match("/\/home.php/",$_SERVER['HTTP_REFERER'])){
	echo "<script>location.href='" . $CONST_LINK_ROOT . "/home.php#ccover'</script>"; die;
}

$WUserID = $_SESSION['Sess_UserId'];
$WUserType = $_SESSION['Sess_UserType'];
$WUserName = $_SESSION['Sess_UserName'];

$mode = $_REQUEST['mode'];

if ($_REQUEST['postID']) { $postID = $_REQUEST['postID']; }
else { $postID = 0; }

if($mode=="Yes") {
$active_query=mysql_query("SELECT title, optionFor FROM market_Post where mem_userid=$WUserID and postID=$postID limit 1",$link) or die(mysql_error());
$activeTotal = mysql_num_rows($active_query);
if($activeTotal>0) {
	$sql = mysql_fetch_object($active_query);
	$forID = $sql->optionFor;

   $query2="UPDATE market_Post set modDate=now(), repostDate=now(), expDate=ADDDATE(now(), INTERVAL 3 MONTH) where mem_userid=$WUserID and postID=$postID";
   $result2=mysql_query($query2,$link) or die(mysql_error());

	echo '<table width="400" border=0 cellpadding="5" cellspacing="0" class="white_back_t_xb">';
	echo '<tr>';
	echo '<td align="center">';
	echo "WOW! <strong>$sql->title</strong> has been reposted!";
	echo '</td>';
	echo '</tr>';
	echo '</table>';
	echo "<script type='text/javascript'>setTimeout(function() { parent.jQuery.facebox.close(); window.location.reload(); }, 1000);</script>";
	
die;
} else {
	echo '<table width="100%" border=0 cellpadding="5" cellspacing="0" class="white_back_t_xb">';
	echo '<tr>';
	echo '<td align="center">Ops! An Error Has Occurred! Please try again!</strong></td>';
	echo '</tr>';
	echo '</table>';
	echo "<script type='text/javascript'>setTimeout(function() { parent.jQuery.facebox.close(); }, 1000);</script>";
die;
}
}

$active_query=mysql_query("SELECT title FROM market_Post where mem_userid=$WUserID and postID=$postID limit 1",$link) or die(mysql_error());
$activeTotal = mysql_num_rows($active_query);
if($activeTotal>0) {
$sql = mysql_fetch_object($active_query);
?>
<script type="text/javascript">
jQuery(document).ready(function(){
    jQuery("#form_rePost").submit(function(){
	 	jQuery('#loading1').show();
	jQuery('input[type=submit]').attr("disabled","disabled");

	var str = 'mode=Yes&' + jQuery(this).serialize();

   		jQuery.ajax({
   		type: "POST",
   		url: "postContinue.php",
   		data: str,
   		success: function(result){
		jQuery('#loading1').hide();	
		jQuery('#msg_content_form').hide();	
 		jQuery("#msg_content").fadeIn('slow');
 		jQuery('#msg_content').html(result);
		}

 });
return false;
    });
});
   </script>
   <div id="loading1" style="display:none;" align="center"><img src="images/loader.gif"></div>
   <div id="msg_content" style="display:none;"></div>
<div id="msg_content_form">
<form name='form_rePost' id='form_rePost' method="post" style="padding:0; margin:0; border:0;">
<table width="400" border=0 cellpadding="5" cellspacing="0" class="white_back_t_xb">
  <tr>
  	<td align="left">Do you really want to repost <strong><?=ucwords($sql->title)?></strong>? </td>
  </tr>
  <tr>
  	<td align="center">
	  <input type='hidden' name='postID' value='<?=$postID?>' />
	<input name="submit" type="submit" id="submit" value="Yes" class="button"/>
      <input name="cancel" type="button" id="cancel" value="No" class="button" onclick="javascript: jQuery.facebox.close(); return false;"/>	  </td>
  </tr>
</table>
</form>
</div>
<?php
} else {
	echo '<table width="100%" border=0 cellpadding="5" cellspacing="0" class="white_back_t_xb">';
	echo '<tr>';
	echo '<td align="center">Ops! An Error Has Occurred! Please try again!</strong></td>';
	echo '</tr>';
	echo '</table>';
	echo "<script type='text/javascript'>setTimeout(function() { parent.jQuery.facebox.close(); }, 1000);</script>";
}
?>