<?php

include("../includes/site_config.php");
include('../session_handler.inc');
# retrieve the template
$area = 'member';
?>
<?php include("include/header.php"); ?>
<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">
      <?php 	  //require_once("$CONST_INCLUDE_ROOT/user_status.inc.php");	  require_once("../user_status.inc.php");	  ?>
    </td>
  </tr>
  <tr>
    <td class="pageheader"><?php echo BROWSE_SECTION_NAME ?></td>
  </tr>
  <tr><td>
      <?php
$option=$_GET['option'];
$x=$_GET['x'];
$query = "SELECT *,mem_password FROM adverts LEFT JOIN members ON (adv_userid=mem_userid) ORDER BY adv_createdate desc";
$result=mysql_query($query, $link) or die("Could not complete database query");
$num = mysql_num_rows($result);
if ($num != 0) {
  if ($option) {
    switch ($option) {
        case "first":
            $record_count = 0;
            $start_record = $x + 1;
            $end_record = $start_record + 9;
            break;
        case "previous":
            if ($x < 19){
              $record_count = 0;
              $start_record = 1;
              $end_record = $start_record + 9;
            } else {
              $record_count = 0;
              $start_record = $x - 19;
              $end_record = $start_record + 9;
            }
            break;
        case "next":
            if ($x > $num - 10){
              $record_count = 0;
              $start_record = $num - 9;
              $end_record = $start_record + 9;
            } else {
              $record_count = 0;
              $start_record = $x + 1;
              $end_record = $start_record + 9;
            }
            break;
        case "last":
            $record_count = 0;
            $start_record = $num - 9;
            $end_record = $start_record + 9;
            break;
        default:
            echo CHECKADS_TEXT1;
            break;
    }
    $till = min($num, $end_record);
    echo "<p>Profiles $start_record - $till of $num</p>";
    while (($row = mysql_fetch_array($result)) && ($record_count != $end_record))               {
      $row[adv_comment]=stripslashes($row[adv_comment]);
	  if ($record_count >= $start_record - 1){
          echo "<p><table cellspacing=0 cellpadding=3><tr><td class='td2'>Username: $row[adv_username]</td></tr>";
          echo "<tr><td class='td1'>Password: $row[mem_password]</td></tr>";
          echo "<tr><td class='td2'>Message: $row[adv_comment]</td></tr>";
          echo "</table></p>";
      }
      $record_count = $record_count + 1;
    }
    if ($num > 10) {
        echo "<BR><BR>\n";
        echo "<B><A HREF='$CONST_LINK_ROOT/admin/checkads.php?PHPSESSID=".session_id()."&option=first&x=0'>Move First</A> |
          <A HREF='$CONST_LINK_ROOT/admin/checkads.php?PHPSESSID=".session_id()."&option=previous&x=$record_count'>Previous 10</A> |
          <A HREF='$CONST_LINK_ROOT/admin/checkads.php?PHPSESSID=".session_id()."&option=next&x=$record_count'>Next 10</A> |
          <A HREF='$CONST_LINK_ROOT/admin/checkads.php?PHPSESSID=".session_id()."&option=last&x=$num'>Last 10</A></B>\n";
    }
  } else {
      echo CHECKADS_TEXT2;
      exit;
  }
} else {
  echo CHECKADS_TEXT3;
  exit;
} ?>
    </td>
  </tr>
</table>
<?php include("include/footer.php"); ?>