<?
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 essay_answers where MD5(ess_id)='$rid'");
	}


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

		foreach($approve as $key=>$value)
			{
				if($value==2)	{
				$quePic=mysql_fetch_object(mysql_query("SELECT * from essay_answers LEFT JOIN
				members on(essay_userid=mem_userid) where ess_id='$key'"));
				$upd=mysql_query("UPDATE essay_answers set approved='$value' where ess_id='$key'");
				send_mail ("$quePic->mem_email", "$CONST_MAIL", "$CONST_COMPANY ".ESS_APR, MAIL_APPROVED_ESSAY,$type,"ON");
			}
				
			if($value==3)
			
			{
				$quePic=mysql_fetch_object(mysql_query("SELECT * from essay_answers LEFT JOIN
				members on(essay_userid=mem_userid) where ess_id='$key'"));
				
				$del=mysql_query("DELETE from essay_answers where ess_id='$key'");
				
				send_mail ("$quePic->mem_email", "$CONST_MAIL", "$CONST_COMPANY ".ESS_REJ, MAIL_UNAPPROVED_ESSAY,$type,"ON");
			}
		}
	}


$retEss=mysql_query("select * from essay_answers where approved='0' order by ess_id DESC");

$ret_count=mysql_num_rows($retEss);




?>
<?php include('approve_menu.php'); ?>
<div class="mainwidth">
<div class="admin-page-header"><div class="admin-page-heading">&nbsp;&nbsp;Approve Essays</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($Essay=mysql_fetch_object($retEss)){
  
  //$com_memid = $Essay['com_memid'];
  $srtQuery = mysql_query("SELECT * FROM adverts WHERE adv_userid='$Essay->essay_userid'");
  $strquery = mysql_fetch_object($srtQuery);
  //echo $strquery->adv_username; 

 //echo $rstQuery->adv_username;
  ?>
  
  <tr>
    <td><?php echo $strquery->adv_username;?>'s Essay: </td>
  </tr>
  <tr>
    <td>
      <label>
        <textarea name="textarea" cols="100" rows="5"><?=$Essay->essay_answer?></textarea> 
    <br />
      <select name="approve[<?=$Essay->ess_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="<?=$Essay->ess_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>
  
<?
$query="select * from essay_answers LEFT JOIN members ON (essay_userid=mem_userid) where approved='2' OR approved='1'";
$record_per_page='20';

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

//$no=mysql_num_rows($sel);

 ?>
   <tr>
    <td>&nbsp;</td>
  </tr>
   <? while($appEssay=mysql_fetch_object($rs)){?>
   <form action="<?=$_SERVER['PHP_SELF']?>?type=ab" method="post">

 <tr><td width="15%"> <?=$appEssay->mem_username?></td>
  <td width="70%"><?=$appEssay->essay_answer?></td>
  <td align="center"><? if($DEMO==false){?><a href="<?=$_SERVER['PHP_SELF']?>?rID=<?=md5($appEssay->ess_id)?>">delete</a><? }?></td>
  
  
  
  </tr>
  
  <tr>
    <td>&nbsp;</td>
  </tr>
   </form>
  <? }?>
  <tr>
    <td>&nbsp;</td>
  </tr>
  
 <tr align="right"><td colspan="3"><? echo $pager->renderNext(); ?></td></tr>
</table>

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

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