<?php
include("../includes/site_config.php");
include('../session_handler.inc');
include('../functions.php');
include('../error.php');
include('../message.php');
include('../lib/lib.Functions.php');
include('paginate.php');
$option_manager = new OptionManager();
$CONST_MAIL = $option_manager->GetValue('mail'); 
$mode=$_GET['mode'];
# retrieve the template
$area = 'member';
if(isset($_REQUEST['rID'])){
$rid=form_get('rID');

$de=mysql_query("DELETE from blogs where MD5(blg_id)='$rid'");

}
# process an authorisation
if ($mode=='next') {
    $txtBlog=form_get('txtBlog');
	
    $lstPrivate=$_POST['lstPrivate'];
    $rdoApprove=$_POST['rdoApprove'];
    $hiddenuserid=$_POST['hiddenuserid'];
	$hiddenid=$_POST['hiddenid'];
    $hiddenname=$_POST['hiddenname'];
    $hiddenemail=$_POST['hiddenemail'];
    $offset=$_POST['offset'];
    $reason=stripslashes($_POST['reason']);
    if ($rdoApprove=='Approve') {
            # approved will show up in search
         	$query="update blogs set blg_message= \"$txtBlog\", blg_approved='Y' where blg_id=$hiddenid";
            if (!mysql_query($query,$link)) {error_page(mysql_error(),GENERAL_SYSTEM_ERROR);}

            $data['ReceiverName'] = $hiddenname;
            $data['Reason'] = $reason;
            $data['Url'] = $CONST_URL;
            $data['SupportEmail'] = $CONST_MAIL;

            list($type,$message) = getTemplateByName("blog",$data,getDefaultLanguage($hiddenuserid));
            send_mail ("$hiddenemail", "$CONST_MAIL", "$CONST_COMPANY ".PRGAUTHBLOG_APR, $message,$type,"ON");

    } elseif ($rdoApprove=='Reject') {
            # rejected will not show up in search or for approval until user amends
            //$query="update blogs set blg_message= \"$txtBlog\", blg_approved='N' where blg_id=$hiddenid";
			$query="delete from blogs where blg_id=$hiddenid";
            $que=mysql_query($query,$link);
			if(!$que) {error_page(mysql_error(),GENERAL_SYSTEM_ERROR);}

            $reason=trim($reason);
            if (empty($reason)) $reason="NULL";

            $data['ReceiverName'] = $hiddenname;
            $data['Url'] = $CONST_URL;
            $data['Reason'] = $reason;
            $data['SupportEmail'] = $CONST_MAIL;

            list($type,$message) = getTemplateByName("blog_rej",$data,getDefaultLanguage($hiddenuserid));
            send_mail ("$hiddenemail", "$CONST_MAIL", "$CONST_COMPANY ".PRGAUTHBLOG_UNAPR, $message,$type,"ON");

    } elseif ($rdoApprove=='Skip') {
        $offset++;
    }
}

if (!$offset) $offset=0;
$result = mysql_query("SELECT *, UNIX_TIMESTAMP(blg_datetime) as blgdate, mem_username, mem_email FROM blogs
                    LEFT JOIN members ON (blg_userid=mem_userid)
                           WHERE blg_approved='N' LIMIT $offset,1",$link);
$TOTAL = mysql_num_rows($result);
# if nothing is returned then show error otherwise get data
if ($TOTAL > 0) { ?>


<? 
        //$error_message="<p><a href='$CONST_LINK_ROOT/admin/index.php'>Continue</a></p>";
        //display_page($error_message,PRGAUTHBLOG_TEXT1);
//echo "<script> location.href='$CONST_LINK_ROOT/admin/index.php'</script>";


        $sql_array = mysql_fetch_object($result);
}
?>
<?php include("include/header.php"); ?>
<?php include('approve_menu.php'); ?>

<div class="mainwidth">
<div class="admin-page-header"><div class="admin-page-heading">&nbsp;&nbsp;Approve Blogs</div></div>
<div class="clear"></div>
<div class="admin-page">

  <table width="<?php print("$CONST_TABLE_WIDTH"); ?>" align="<?php print("$CONST_TABLE_ALIGN"); ?>" border="0" cellspacing="<?php print("$CONST_TABLE_CELLSPACING"); ?>" cellpadding="<?php print("$CONST_TABLE_CELLPADDING"); ?>">
   
   <tr>
      
    <td align="right">&nbsp; </td>
    </tr>
    <? 
	if ($TOTAL > 0) { ?>
    <tr><td>
        <table width="100%"  border="0" cellpadding="<?php print("$CONST_SUBTABLE_CELLPADDING"); ?>" cellspacing="<?php print("$CONST_SUBTABLE_CELLSPACING"); ?>">
        <form enctype='multipart/form-data' method='post' action='<?=$_SERVER['PHP_SELF']?><?php print("?PHPSESSID=".session_id()); ?>&mode=next' name="FrmAuthorise">
            <input type='hidden' name="hiddenuserid" value="<?php print("$sql_array->blg_userid"); ?>">
            <input type='hidden' name="hiddenid" value="<?php print("$sql_array->blg_id"); ?>">
            <input type='hidden' name="hiddenemail" value="<?php print("$sql_array->mem_email"); ?>">
            <input type='hidden' name="hiddenname" value="<?php print("$sql_array->mem_username"); ?>">
          <input type="hidden" name="offset" value="<?=$offset?>" />
          <tr>
            <td>
                <table width="100%" align="left" border="0" cellspacing="0" cellpadding="5">
                    <tr class="tdhead" >
                        <td align="left"><?php $text=($sql_array->blg_private=='Y')?GENERAL_PRIVATE:GENERAL_PUBLIC; echo $text;  ?>&nbsp;</td>
                        <td align="right"><?php echo date("D, j M Y G:i:s",$sql_array->blgdate); ?>&nbsp;</td>
                    </tr>
                    <tr class="tdeven">
					<td>Title:</td>
                      <td colspan="2"><input name="title" type="text" value="<?=$sql_array->blg_title?>" size="50"/></td>
                    </tr>
                    <tr class="tdeven">
					<td>Blog:</td>
                        <td colspan="2"><textarea name="txtBlog" rows="5" cols="80" class="inputl"><?php echo $sql_array->blg_message; ?></textarea></td>
                    </tr>
                    <tr align="right" class="tdfoot"><td colspan="2" >&nbsp;</td></tr>
                    <tr align="right"><td colspan="2">&nbsp;</td></tr>
                </table>
          </td>
          </tr>
          <tr align="center" class="tdodd">
            <td colspan="4" > <input type="radio" name="rdoApprove" value="Approve">
              <?php echo AFF_AUTHORISE_APPROVE?>&nbsp; <input type="radio" name="rdoApprove" value="Reject" >
              <?php echo AFF_AUTHORISE_REJECT?> &nbsp; <input type="radio" name="rdoApprove" value="Skip" checked>
              <?php echo AFF_AUTHORISE_SKIP?><br> <?php echo AFF_AUTHORISE_REASON?>
              <input name='reason' type='text' class="inputl" size='30'></td>
          </tr>
          <tr align="center">
            <td colspan="4" class="tdfoot"> <input type="submit" name="Submit" value="<?php echo BUTTON_SUBMIT ?>" class="button">
            </td>
          </tr>
        </form>
      </table></td>
    </tr><? }else { ?>
  
  <tr > 


            <td>&nbsp;</td>


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



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

          </tr>
  
  <? }?>
  </table>
 </div></div><div class="admin-page-bottom"></div></div><br /><br />
 
 
 
 <div class="mainwidth">
<div class="admin-page-header"><div class="admin-page-heading">&nbsp;&nbsp;<?=APPR_BLG?></div></div>
<div class="clear"></div>
<div class="admin-page">
   <table width="100%"  border="0" cellpadding="<?php print("$CONST_SUBTABLE_CELLPADDING"); ?>" cellspacing="<?php print("$CONST_SUBTABLE_CELLSPACING"); ?>">
  <tr><td>&nbsp;</td></tr>
  <div class="admin-head"></div>
      
  
  <? 
  
  $quer = "SELECT *, UNIX_TIMESTAMP(blg_datetime) as blgdate, mem_username, mem_email FROM blogs
                    LEFT JOIN members ON (blg_userid=mem_userid)
                           WHERE blg_approved='Y' ORDER BY blgdate DESC";
					   
	$record_per_page='20';

$pager = new PS_Pagination($link,$quer,$record_per_page,5);
$rs = $pager->paginate();					   
	while($app_Blog=mysql_fetch_object($rs)){					   
  ?>
  <tr><td  width="125px"> <?=$app_Blog->mem_username?></td>
  <td><?=$app_Blog->blg_message?></td>
  <td><? if($DEMO==false){?><a href="<?=$_SERVER['PHP_SELF']?>?rID=<?=md5($app_Blog->blg_id)?>">delete</a><? }?></td>
  
  
  
  </tr>
  <tr><td>&nbsp;</td></tr>
  <? }?>
   <tr align="right"><td>&nbsp;</td><td><? echo $pager->renderNext(); ?></td></tr>
  </table>
  
        </div></div><div class="admin-page-bottom"></div></div>
<?php include("include/footer.php"); ?>