<?
include("../includes/site_config.php");
include("include/header.php");
include("../includes/tab_functions.js");
include('paginate.php');
include('../lib/lib.Functions.php');

$option_manager = new OptionManager();
$CONST_MAIL=$option_manager->GetValue('mail');

if(isset($_REQUEST['rID'])){
$rid=form_get('rID');
$de=mysql_query("DELETE from profile_comment where MD5(comment_id)='$rid'");
}


if(isset($_REQUEST['approve']) && isset($_REQUEST['Submit']))
{ 
$approve = $_REQUEST['approve'];

foreach($approve as $key=>$value)
	{

if($value==2)	{
	$upd=mysql_query("UPDATE profile_comment set com_approved='$value' where comment_id='$key'");
				}
				
if($value==3)	{
	$quePic=mysql_fetch_object(mysql_query("SELECT * from profile_comment LEFT JOIN members on(mem_id=mem_userid) where comment_id='$key'"));
	$del=mysql_query("DELETE from profile_comment where comment_id='$key'");
	
	send_mail ("$quePic->mem_email", "$CONST_MAIL", "$CONST_COMPANY ".COM_REJ, MAIL_UNAPPROVEDCOM,$type,"ON");
			 	}
	}

}


$ret_com=mysql_query("select * from profile_comment where com_approved='0' order by comment_id DESC");

$ret_count=mysql_num_rows($ret_com);




?>
<?php include('approve_menu.php'); ?>
<div class="mainwidth">
<div class="admin-page-header"><div class="admin-page-heading">&nbsp;&nbsp;Approve Comments</div></div>
<div class="clear"></div>
<div class="admin-page">
<!--<table><tr><td> <tr><td class="admin-head"><?=AWAITING_APP?>:</td></tr></td></tr>
<tr > 


            <td>&nbsp;</td>
</tr>			
</table>-->

<form name="FrmCom" method="post" action="<?=$_SERVER['PHP_SELF']?>">

<table width="600" border="0" cellspacing="2" cellpadding="0" align="center">

 <? 
	
	if($ret_count < 1){?>

<tr > 


            <td>&nbsp;</td>


 <td  align="left"> <font color="#CC0000" size="+2">Nothing To Approve!</font></td>



 <td align="center"></td>

          </tr>

<? }?>

  <? while($comment=mysql_fetch_object($ret_com)){
  
  //$com_memid = $comment['com_memid'];
  $srtQuery = mysql_query("SELECT * FROM adverts WHERE adv_userid=$comment->mem_id");
  $strquery = mysql_fetch_object($srtQuery);
  //echo $strquery->adv_username; 
 $rstQuery = mysql_fetch_object(mysql_query("SELECT * FROM adverts WHERE adv_userid=$comment->com_memid"));
 //echo $rstQuery->adv_username;
  ?>
  
  <tr>
    <td><?php echo $strquery->adv_username;?> comments on <?php echo $rstQuery->adv_username; ?>'s Profile: </td>
  </tr>
  <tr>
    <td>
      <label>
        <textarea name="textarea" cols="100" rows="5"><?=$comment->comment?></textarea>
        </label>   </td>
  </tr>
  <tr>
    <td>
      <select name="approve[<?=$comment->comment_id?>]" >
        <option value="2">Accept</option>
        <option value="3">Reject</option>
		<option value="Skip">Skip</option>
      </select>    </td>
  </tr>
  <tr>
    <td><br>
      
        <input type="hidden" name="com_id[]" value="<?=$comment->comment_id?>" /></td>
		 
  </tr><? } if($ret_count > 0){?>
  <tr>
  <td><input type="submit" name="Submit" value="Save"></td></tr>
  <? } ?>
</table>
</form>
</div><div class="admin-page-bottom"></div></div><br /><br />
<!--Approved comments code starts here... -->
<div class="mainwidth">
<div class="admin-page-header"><div class="admin-page-heading">&nbsp;&nbsp;<?=APPR_COM?></div></div>
<div class="clear"></div>
<div class="admin-page">

<table border="0" cellspacing="0" cellpadding="0">
<tr>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
  </tr>
  
<?
$quer="select * from profile_comment LEFT JOIN members ON (com_memid=mem_userid) where com_approved='2' OR com_approved='1'";
$record_per_page='20';

$pager = new PS_Pagination($link,$quer,$record_per_page,5);
$rs = $pager->paginate();

//$no=mysql_num_rows($sel);

 ?>
  <tr>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
  </tr>
   <? while($app_Blog=mysql_fetch_object($rs)){?>
   <form action="<?=$_SERVER['PHP_SELF']?>?type=ab" method="post">
 <tr><td  width="150px"> <?=$app_Blog->mem_username?></td>
  <td><?=$app_Blog->comment?></td>
  <td><? if($DEMO==false){?><a href="<?=$_SERVER['PHP_SELF']?>?rID=<?=md5($app_Blog->comment_id)?>">delete</a><? }?></td>
  
  
  
  </tr>
  
  <tr>
    <td>&nbsp;</td>
  </tr>
   </form>
  <? }?>
  <tr>
    <td>&nbsp;</td>
  </tr>
  
 <tr align="right"><td>&nbsp;</td><td><? echo $pager->renderNext(); ?></td></tr>
</table>

</div><div class="admin-page-bottom"></div></div><br /><br />

<?php include("include/footer.php");  ?>