<?php

include("../includes/site_config.php");
include('../session_handler.inc');
include('../message.php');
include('../deletes.php');
$mode=$_REQUEST['mode'];
/*
if ($Sess_UserType != "A") {
	exit;
}*/

# retrieve the template
$area = 'member';

if(!($months = $_POST[months]))
	if(!($months = $_GET[months]))
		$months = 1;
$sql_query = "SELECT * FROM members WHERE DATE_ADD(mem_lastvisit, INTERVAL $months MONTH) < CURDATE() ORDER BY mem_lastvisit DESC";
//echo $sql_query;
if($_POST[mode] == 'delete')
{
	if($months)
	{
		restrict_demo();
		$sql_result_members = mysql_query($sql_query, $link);
		while($member = mysql_fetch_object($sql_result_members))
		{
			delete_advert($member->mem_userid);
			delete_me($member->mem_userid);
			delete_match($member->mem_userid);
		}
	}
	header("Location: $CONST_LINK_ROOT/admin/prune_members.php?PHPSESSID=".session_id()."&months=$months");
	exit;
}


$sql_result_members = mysql_query($sql_query, $link);
?>
<?php include("include/header.php"); ?>
<style type="text/css">
<!--
.style1 {
	color: #FF0000;
	font-style: italic;
	font-weight: bold;
}
-->
</style>


<div class="mainwidth">
<div class="admin-page-header"><div class="admin-page-heading">&nbsp;&nbsp;Prune Inactive Members</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><form method="post"><table width="<?php print("$CONST_TABLE_WIDTH"); ?>" align="<?php print("$CONST_TABLE_ALIGN"); ?>" border="0" cellspacing="<?php print("$CONST_SUBTABLE_CELLSPACING"); ?>" cellpadding="<?php print("$CONST_SUBTABLE_CELLPADDING"); ?>">
        <!--DWLayoutTable-->
          <tr>
            <td height="19" colspan="5" align='left' valign='top' class=""><?=PRUNE_NOTE?>
              <p>&nbsp;</p></td>
          </tr>

          <input type="hidden" name="mode" value="delete">
          <tr class="pagetitle">
            <td width="4" align='left' valign='top' class="normal"></td>
            <td align='left' valign='top' class="normal" colspan="2">
              <b><?=INACTIVE_MEMBERS_DURATION?>: </b>
              <select class="input" name="months" onchange="window.location = '<?=$CONST_LINK_ROOT?>/admin/prune_members.php?PHPSESSID=<?=session_id()?>&months=' + this.options[this.selectedIndex].value;">
              	<?php for($i = 1; $i <= 136; $i++) { ?>
              		<option value="<?=$i?>"<?php if($months == $i) echo ' selected'; ?>><?=$i?>
              	<?php } ?>
              </select>
              <?=INACTIVE_MEMBERS_MONTHS?>            </td>
            <td align='left' valign='top' class="normal" colspan="2">
            	<input type="submit" value="<?=INACTIVE_MEMBERS_DELETE?>" class="normal" onclick="return(confirm('<?=INACTIVE_MEMBERS_TEXT2?>') ? confirm('<?=INACTIVE_MEMBERS_TEXT3?>') : false);">            </td>
          </tr>
          <tr>
            <td colspan="5" align='left' valign='top' class="normal">&nbsp;</td>
          </tr>
          <?php if(mysql_num_rows($sql_result_members)) { ?>
			<tr class='tdhead'>
                 <td>&nbsp;</td>
                 <td><b><?=INACTIVE_MEMBERS_USERNAME?></b></td>
                 <td><!--DWLayoutEmptyCell-->&nbsp;</td>
                 <td><!--DWLayoutEmptyCell-->&nbsp;</td>
                 <td><!--DWLayoutEmptyCell-->&nbsp;</td>
            </tr>
            <?php while ($member = mysql_fetch_object($sql_result_members)) { ?>
				<tr class='normal'>
					<td>&nbsp;</td>
					<td><?=$member->mem_username?></td>
					<td><!--DWLayoutEmptyCell-->&nbsp;</td>
				  <td><!--DWLayoutEmptyCell-->&nbsp;</td>
				  <td><!--DWLayoutEmptyCell-->&nbsp;</td>
			  </tr>
            <?php } ?>
          <?php } else { ?>
			<tr>
				<td colspan="5" align='center' valign='top' class="normal"><b><?=INACTIVE_MEMBERS_TEXT1?></b></td>
			</tr>
          <?php } ?>
      </table>
      </form></td>
    </tr>
</table></div><div class="admin-page-bottom"></div></div>
<?php include("include/footer.php"); ?>
