<?PHP
#
#   FILE:  ListPages.php (Pages plugin)
#
#   Part of the Collection Workflow Integration System (CWIS)
#   Copyright 2012 Edward Almasy and Internet Scout
#   http://scout.wisc.edu
#

# check authorization to see page list
$Plugin = $GLOBALS["G_PluginManager"]->GetPluginForCurrentPage();
CheckAuthorization($Plugin->ConfigSetting("PrivilegeToAuthor"),
        $Plugin->ConfigSetting("PrivilegeToEdit"));

# retrieve sort parameters from URL
$H_SortField = GetFormValue("SF", "UpdatedOn");
$H_SortAscending = GetFormValue("SA", 0);

# load page IDs
$PFactory = new Pages_PageFactory();
$PageIds = $PFactory->GetItemIds(NULL, FALSE, $H_SortField, $H_SortAscending);

# get total count of pages
$H_PageCount = count($PageIds);

# get where we currently are in page list
$H_StartingIndex = GetFormValue("SI", 0);

# calculate ID array checksum and reset paging if list has changed
$H_ListChecksum = md5(serialize($PageIds));
if ($H_ListChecksum != GetFormValue("CK")) {  $H_StartingIndex = 0;  }

# prune page IDs down to just currently-selected segment
$H_PagesPerPage = 25;
$PageIds = array_slice($PageIds, $H_StartingIndex, $H_PagesPerPage);

# load pages from page IDs
$H_Pages = array();
foreach ($PageIds as $Id)
{
    $H_Pages[$Id] = new Pages_Page($Id);
}

