<?php
define('idDiGIR_index','$Id: index.php,v 1.8 2003/06/23 19:59:39 vieglais Exp $');
if (defined('idDIGIR_VERSION_REQUEST'))
    return;
?>
<html>
<head>
    <title>DiGIR Provider Service</title>
    <link rel="stylesheet" href="digir.css">
</head>
<body>
<table border='0'>
<tr><td><img src='digir_button.gif'></td><td><p class='title'>DiGIR Provider Service</p></td></tr>
<tr><td colspan='2'><pre>$Id: index.php,v 1.8 2003/06/23 19:59:39 vieglais Exp $</pre></td></tr>
<tr><td colspan='2'><!--start of content -->
<?php
//Advertise service information for this provider
// DiGIR service
// DiGIRm service
// WMS service
// Resources available and their metadata
include_once('DiGIR.php');
@include_once('localconfig.php');
include_once('DiGIR_globals.php');
include_once('DiGIR_status.php');

function basic_installCheck()
{
    $has_meta = file_exists(realpath(DIGIR_CONFIG_DIR.'/'.DIGIR_METADATA_FILE));
    $has_resources = file_exists(realpath(DIGIR_CONFIG_DIR.'/'.DIGIR_RESOURCE_FILE));
    if ($has_meta & $has_resources)
    {
        return TRUE;
    }
    ?>
    <h2>Provider Configuration Error</h2>
    <p>The following problems have been identified with this DiGIR Provider installation:</p>
    <?php
    if (!$has_meta)
    {
        ?>
<h3>No Provider Metadata</h3>
<p>The DiGIR Provider service metadata file (<code><?php echo DIGIR_METADATA_FILE; ?></code>)
could not be found at the expected location (<code><?php echo realpath(DIGIR_CONFIG_DIR.'/'.DIGIR_METADATA_FILE); ?></code>).</p>
<p>If this is a new installation, you can copy the file <code><?php echo realpath(DIGIR_CONFIG_DIR.'/example/'.DIGIR_METADATA_FILE); ?></code>
to <code><?php echo realpath(DIGIR_CONFIG_DIR.'/'.DIGIR_METADATA_FILE); ?></code> to get started.</p>
        <?
    }
    if (!$has_resources)
    {
        ?>
<h3>No Provider Resource List</h3>
<p>The DiGIR Provider service resources file (<code><?php echo DIGIR_RESOURCE_FILE; ?></code>)
could not be found at the expected location (<code><?php echo realpath(DIGIR_CONFIG_DIR.'/'.DIGIR_RESOURCE_FILE); ?></code>).</p>
<p>If this is a new installation, you can copy the file <code><?php echo realpath(DIGIR_CONFIG_DIR.'/example/'.DIGIR_RESOURCE_FILE); ?></code>
to <code><?php echo realpath(DIGIR_CONFIG_DIR.'/'.DIGIR_RESOURCE_FILE); ?></code> to get started.</p>
        <?
    }
    return false;
}

function showDiGIRProvider($digir_svc)
{
    $digir_svcstatus = getStatus(DIGIR_STATUSINTERVAL,DIGIR_STATUSPICKLE,0);
    if ($digir_svcstatus[0] > 0)
    {
//        $digir_svcstatus[1] = ($digir_svcstatus[1]*100)/$digir_svcstatus[0];
//        $digir_svcstatus[2] = ($digir_svcstatus[2]*100)/$digir_svcstatus[0];
//        $digir_svcstatus[3] = ($digir_svcstatus[3]*100)/$digir_svcstatus[0];
        $digir_svcstatus[0] = $digir_svcstatus[0]*(3600/DIGIR_STATUSINTERVAL);
        $digir_svcstatus[1] = $digir_svcstatus[1]*(3600/DIGIR_STATUSINTERVAL);
        $digir_svcstatus[2] = $digir_svcstatus[2]*(3600/DIGIR_STATUSINTERVAL);
        $digir_svcstatus[3] = $digir_svcstatus[3]*(3600/DIGIR_STATUSINTERVAL);
    }
?>
    <h2>DiGIR Provider</h2>
    <p>The DiGIR Provider service provides an endpoint that conforms to the
    DiGIR protocol.</p>
    <table border='1'>
    <tr><td>Endpoint</td><td colspan='3'><?php echo "<a href='$digir_svc'>$digir_svc</a>"?></td></tr>
    <tr><td>Revision</td><td colspan='3'><code><?php echo idDiGIR_DiGIR; ?></code></td></tr>
    <tr><td>Status (hits/hr)</td><td align='center'>Metadata</td><td align='center'>Search</td><td align='center'>Inventory</td></tr>
    <tr><td align='center' id='digir_status'><?php printf("%.0f",$digir_svcstatus[0]); ?></td>
    <td align='center' id='digir_metadata'><?php echo printf("%.0f",$digir_svcstatus[1]); ?></td>
    <td align='center' id='digir_search'><?php echo printf("%.0f",$digir_svcstatus[2]); ?></td>
    <td align='center' id='digir_inventory'><?php echo printf("%.0f",$digir_svcstatus[3]); ?></td>
    </tr>
    </table>
<?php
}

function showDiGIRm($digirm_svc)
{
?>
    <h2>DiGIRm Service</h2>
    <p>The DiGIRm endpoint provides a service with similar functionality to the
    DiGIR Provider service except that it accepts multiple targets.  This
    service is experimental.</p>
<?php
    if (DIGIRM_ALLOW)
    {
        include_once('DiGIRm.php');
        $digir_svcstatus = getStatus(DIGIRM_STATUSINTERVAL,DIGIRM_STATUSPICKLE,0);
        if ($digir_svcstatus[0] > 0)
        {
            $digir_svcstatus[0] = $digir_svcstatus[0]*(3600/DIGIRM_STATUSINTERVAL);
            $digir_svcstatus[1] = $digir_svcstatus[1]*(3600/DIGIRM_STATUSINTERVAL);
            $digir_svcstatus[2] = $digir_svcstatus[2]*(3600/DIGIRM_STATUSINTERVAL);
            $digir_svcstatus[3] = $digir_svcstatus[3]*(3600/DIGIRM_STATUSINTERVAL);
        }
?>
    <table border='1'>
    <tr><td>Endpoint</td><td colspan='3'><?php echo "<a href='$digirm_svc'>$digirm_svc</a>"?></td></tr>
    <tr><td>Revision</td><td colspan='3'><code><?php echo idDiGIR_DiGIRm; ?></code></td></tr>
    <tr><td>Status (hits/hr)</td><td align='center'>Metadata</td><td align='center'>Search</td><td align='center'>Inventory</td></tr>
    <tr><td align='center' id='digirm_status'><?php printf("%.0f",$digir_svcstatus[0]); ?></td>
    <td align='center' id='digirm_metadata'><?php echo printf("%.0f",$digir_svcstatus[1]); ?></td>
    <td align='center' id='digirm_search'><?php echo printf("%.0f",$digir_svcstatus[2]); ?></td>
    <td align='center' id='digirm_inventory'><?php echo printf("%.0f",$digir_svcstatus[3]); ?></td>
    </tr>
    </table>
<?php
    }
    else
    {
        echo "<p>The DiGIRm Service is disabled on this target.</p>\n";
    }
}

function showWMS($digirwms_svc)
{
?>
    <h2>DiGIR WMS Service</h2>
    <p>The WMS service implements a simple version of the Open GIS
    Consortium's Web Mapping Service.</p>
<?php
    if (DIGIRWMS_ALLOW)
    {
        include_once('DiGIR_wms.php');
        $digir_svcstatus = getStatus(DIGIRWMS_STATUSINTERVAL,DIGIRWMS_STATUSPICKLE,0);
        if ($digir_svcstatus[0] > 0)
        {
            $digir_svcstatus[0] = $digir_svcstatus[0]*(3600/DIGIRWMS_STATUSINTERVAL);
            $digir_svcstatus[1] = $digir_svcstatus[0]*(3600/DIGIRWMS_STATUSINTERVAL);
            $digir_svcstatus[2] = $digir_svcstatus[0]*(3600/DIGIRWMS_STATUSINTERVAL);
            $digir_svcstatus[3] = $digir_svcstatus[0]*(3600/DIGIRWMS_STATUSINTERVAL);
        }
?>
        <table border='1'>
        <tr><td>Endpoint</td><td colspan='3'><?php echo "<a href='$digirwms_svc'>$digirwms_svc</a>"?></td></tr>
        <tr><td>Revision</td><td colspan='3'><code><?php echo idDiGIR_wms; ?></code></td></tr>
        <tr><td>Status (hits/hr)</td><td align='center'>Metadata</td><td align='center'>Search</td><td align='center'>Inventory</td></tr>
        <tr><td align='center' id='digirwms_status'><?php printf("%.0f",$digir_svcstatus[0]); ?></td>
        <td align='center' id='digirwms_metadata'><?php echo printf("%.0f",$digir_svcstatus[1]); ?></td>
        <td align='center' id='digirwms_search'><?php echo printf("%.0f",$digir_svcstatus[2]); ?></td>
        <td align='center' id='digirwms_inventory'><?php echo printf("%.0f",$digir_svcstatus[3]); ?></td>
        </tr>
        </table>
<?php
    }
    else
    {
        echo "<p>The Web Mapping Service is disabled on this target.</p>\n";
    }
}

//////////////////////////
//main part here

if (basic_installCheck())
{
    $sn = isset($_SERVER['SERVER_NAME'])?$_SERVER['SERVER_NAME']:'localhost';
    $sp = isset($_SERVER['SERVER_PORT'])?$_SERVER['SERVER_PORT']:'80';
    $ss = isset($_SERVER['SCRIPT_NAME'])?$_SERVER['SCRIPT_NAME']:'/DiGIR.php';
    $ss = strrev(strstr(strrev($ss),"/"));
    $digir_svc = "http://$sn:$sp$ss"."DiGIR.php";
    $digirm_svc = "http://$sn:$sp$ss"."DiGIRm.php";
    $digirwms_svc = "http://$sn:$sp$ss"."DiGIR_wms.php";
    
    showDiGIRProvider($digir_svc);
    echo "<hr />\n";
    showDiGIRm($digirm_svc);
    echo "<hr />\n";
    showWMS($digirwms_svc);
    echo "<hr />\n";
}
?>
<!--end of content --></td></tr>
</table>
</body>
</html>
