<?php
  /* STEP 1: LOAD RECORDS - Copy this PHP code block to the TOP of your page BEFORE anything else. */
  require_once "C:/wamp/www/sb/core2/admin/lib/viewer_functions.php";

  # load access levels
  list($accessListRecords) = getRecords(array(
    'tableName'       => '_accesslist',
    'loadCreatedBy'   => false,
    'loadListDetails' => false,
    'orderBy'         => 'tableName',
    'where'           => 'accessLevel >= 6',
  ));

  # load users
  list($usersRecords) = getRecords(array(
    'tableName'       => 'accounts',
    'loadCreatedBy'   => false,
    'loadListDetails' => false,
    'orderBy'         => 'fullname',
  ));

  # create lookup array of users by num
  $usersByNum = array();
  foreach ($usersRecords as $user) {
    $usersByNum[$user['num']] = $user;
  }


?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
 <head>
  <title></title>
  <meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
  <style type="text/css">
    body          { font-family: arial; }
  </style>
 </head>
<body>

<h1>Users By Section</h1>

<?php foreach ($accessListRecords as $accessRecord): ?>

  <?php /* show section tablename header */ ?>
  <?php if (@$lastTable != $accessRecord['tableName']): ?>
    <h2><?php echo $accessRecord['tableName']; ?></h2>
  <?php endif; ?>
  <?php $lastTable = $accessRecord['tableName']; ?>


  <?php /* show section user list */ ?>
  <?php if ($user = @$usersByNum[$accessRecord['userNum']]): ?>
    <a href="admin.php?menu=accounts&action=edit&num=<?php echo $user['num'] ?>"><?php echo $user['fullname'] ?></a><br/>
  <?php endif; ?>


<?php endforeach ?>

</body>
</html>
