<?php
#
#   FILE:  SPT--MDHome.php
#
#   FUNCTIONS PROVIDED:
#       PrintTotalNumberOfResources()
#       PrintNumberOfReleasedResources()
#       PrintTotalNumberOfClassifications()
#       PrintTotalNumberOfControlledNames()
#           - print current values for each of the above
#
#   FUNCTIONS EXPECTED:
#       None
#
#   Part of the Scout Portal Toolkit
#   Copyright 2004 Internet Scout Project
#   http://scout.wisc.edu
#

PageTitle("Metadata Tool");


# ----- EXPORTED FUNCTIONS ---------------------------------------------------

function PrintTotalNumberOfResources()
{
    global $G_CollectionStats;

    print(number_format($G_CollectionStats["TotalNumberOfResources"]));
}

function PrintNumberOfReleasedResources()
{
    global $G_CollectionStats;

    print(number_format($G_CollectionStats["NumberOfReleasedResources"]));
}

function PrintNumberOfRatedResources()
{
    global $G_CollectionStats;

    print(number_format($G_CollectionStats["NumberOfRatedResources"]));
}

function PrintTotalNumberOfClassifications()
{
    global $G_CollectionStats;

    print(number_format($G_CollectionStats["TotalNumberOfClassifications"]));
}

function PrintTotalNumberOfControlledNames()
{
    global $G_CollectionStats;

    print(number_format($G_CollectionStats["TotalNumberOfControlledNames"]));
}

function PrintTotalSearchTerms()
{
    global $G_CollectionStats;

    print(number_format($G_CollectionStats["TotalSearchTerms"]));
}


# ----- LOCAL FUNCTIONS ------------------------------------------------------


# ----- MAIN -----------------------------------------------------------------

if (!CheckAuthorization(PRIV_RESOURCEADMIN, PRIV_CLASSADMIN, PRIV_NAMEADMIN, PRIV_MYRESOURCEADMIN, PRIV_RELEASEADMIN)) {  return;  }


global $G_CollectionStats, $G_StatsUpdateTime;

$DB = new Database();

if (isset($_GET["US"]))
{
    global $AF;
    $AF->LoadFunction("UpdateCollectionStats");
    UpdateCollectionStats();
    $AF->SetJumpToPage("MDHome");
}
else
{
    $G_StatsUpdateTime = $DB->Query(
        "SELECT Updated FROM CachedValues WHERE Name='CollectionStats'",
        "Updated");

    if (time() - strtotime($G_StatsUpdateTime) > 3600) {
        global $AF;
        $AF->QueueTask("UpdateCollectionStats");
    }

    $G_CollectionStats = unserialize(
        $DB->Query(
            "SELECT Value FROM CachedValues WHERE Name='CollectionStats'",
            "Value"));
}

?>
