<?php
define('idDiGIR_globals','$Id: DiGIR_globals.php,v 1.17 2004/06/25 20:50:00 vieglais Exp $');
if (defined('idDIGIR_VERSION_REQUEST'))
    return;
/**
* $Id: DiGIR_globals.php,v 1.17 2004/06/25 20:50:00 vieglais Exp $
* 
* DiGIR_globals.php
* Global constants for DiGIR provider and associated services
* This script also sets the include_path for this instance of PHP
* so that the libaries can be located.
*
* Running this script without being included within another script
* such as DiGIR entry point results in a number of tests being run to
* check the values of configurable variables.
*
* The default installation assumes the following folde structure
*
* DiGIR
*    config    		(configuration files- NOT web accessible)
*    cache     		(location of temporary cache files- writable by web)
*    log		(location of log files - writable by web)
*    www		(root folder of DiGIR script - web accessible)
*       pear		(PEAR libraries)
*       xpath		(XPath processor support library)
*       adodb		(SQL database abstraction library)
*
*/

/*
Important change to defined names (06 apr 2003):
All defines used by DIGIR now have a DIGIR prefix.  This is to avoid potential conflict
with names defiend in other libraries.

SCRIPT_START_TIME => DIGIR_SCRIPTSTART_TIME
PROVIDER_CONFIG_DIR => DIGIR_CONFIG_DIR
PROVIDER_RESOURCE_FILE => DIGIR_RESOURCE_FILE
HOST_METADATA_FILE => DIGIR_METADATA_FILE
USE_CACHE => DIGIR_USE_CACHE
CACHE_DIRECTORY => DIGIR_CACHE_DIRECTORY
METADATA_CACHE_LIFE_SECONDS => DIGIR_METADATA_CACHE_LIFE_SECONDS
FORMAT_CACHE_LIFE_SECONDS => DIGIR_FORMAT_CACHE_LIFE_SECONDS
RESULTSET_CACHE_LIFE_SECONDS => DIGIR_RESULTSET_CACHE_LIFE_SECONDS
INVENTORY_CACHE_LIFE_SECONDS => DIGIR_INVENTORY_CACHE_LIFE_SECONDS
SCRIPT_CACHE_LIFE_SECONDS => DIGIR_SCRIPT_CACHE_LIFE_SECONDS
UDDI_CACHE_LIFE_SECONDS => DIGIR_UDDI_CACHE_LIFE_SECONDS
ABSOLUTE_RECORD_LIMIT => DIGIR_ABS_RECORD_LIMIT
ALLOW_REMOTE_JOINS => DIGIR_ALLOW_REMOTE_JOINS
MAX_JOIN_TERMS => DIGIR_MAX_JOIN_TERMS
SQL_QUOTE => DIGIR_SQL_QUOTE
SQL_QUOTE_ESCAPE => DIGIR_SQL_QUOTE_ESCAPE
XPATH_LIBRARY => DIGIR_XPATH_LIBRARY
ADODB_LIBRARY => DIGIR_ADODB_LIBRARY


*/

$CVSFileID = '$Id: DiGIR_globals.php,v 1.17 2004/06/25 20:50:00 vieglais Exp $';

/*
* Setting DIGIR_ALLOW_CONFIG_DUMP to TRUE will cause all the defines in this file
* to be dumped to the browser when this script is called directly.  This can be useful
* during the installation process when checking the actual values of the config settings.
* SECURITY WARNING: set this to FALSE or delete this entry when you have finished configuring.
*/
if (!defined('DIGIR_ALLOW_CONFIG_DUMP'))
    define('DIGIR_ALLOW_CONFIG_DUMP',TRUE);

/**
* Load the local configuration file, which is used to override the default
* values for the defines in this file.	
*/
ini_set('include_path','.');
$tmp = @include_once('localconfig.php');
if (!$tmp)
{
	//error - no localconfig.php!
	//not much point continuing past here since the installation has problems...
	$msg = "DiGIR installation at: ".realpath("..")."\n";
	$msg .= "Fatal Error due to a configuration problem. The file:\n"
               ."  localconfig.php\nmust exist in the same folder as DiGIR.php\n"
               ."If this is a new installation, copy\n"
               ."  www/localconfig_dist.php\n to\n  www/localconfig.php\n";
	if (headers_sent())
	{
		echo "<error>".$msg."</error>";
	}
	else
	{
		echo "<pre>".$msg."</pre></body></html>";
	}
	flush();
	die();
}

/**
* This is the maximum time in seconds that the script can run.
*/
if (!defined('DIGIR_MAX_RUNTIME'))
    define('DIGIR_MAX_RUNTIME',120);

/**
* Record the start time of the script.  We'll check the delta
* every now and then and try and bail out with some semblence of 
* elegance before PHP dies.
*/
define('DIGIR_SCRIPTSTART_TIME',time());

/**
* Set the root folder to the parent of the folder the script is being run from.
*/
if (!defined('DIGIR_ROOT_DIR'))
{
    $rootdir = dirname(__FILE__);
    define('DIGIR_ROOT_DIR',$rootdir);
}

/**
* Try and determine the appropriate path seperator
* windows = ";", unix = ":"
*/
if (!defined('DIGIR_PATH_SEP'))
{
	if (substr(PHP_OS, 0, 3) == 'WIN')
	{
	    define('DIGIR_OS_WINDOWS', true);
	    define('DIGIR_OS_UNIX',    false);
	    define('DIGIR_OS',    'Windows');
	    define('DIGIR_PATH_SEP',';');
	}
	else
	{
	    define('DIGIR_OS_WINDOWS', false);
	    define('DIGIR_OS_UNIX',    true);
	    define('DIGIR_OS',    'Unix'); // blatant assumption
	    define('DIGIR_PATH_SEP',':');
	}
}

/**
* The full path to the directory used to contain configuration information.
*/
if (!defined('DIGIR_CONFIG_DIR'))
    define ('DIGIR_CONFIG_DIR',realpath(DIGIR_ROOT_DIR.'/../config'));
    
/**
* The include path to find libaries
*/
if (!defined('DIGIR_INCLUDE_PATH'))
{
	$pth = ".";
	$pth .= DIGIR_PATH_SEP.realpath(DIGIR_ROOT_DIR.'/../lib/pear');
	$pth .= DIGIR_PATH_SEP.realpath(DIGIR_ROOT_DIR.'/../lib');
/*
*		Add following line per http://iobis.org/tech/provider/config.
*		12 Sep 2005 EFC
*/
	$pth .= DIGIR_PATH_SEP.realpath(DIGIR_ROOT_DIR.'/../www');
	define('DIGIR_INCLUDE_PATH',$pth);
}
ini_set('include_path',DIGIR_INCLUDE_PATH);

// a mini-test of the include path
$tmp = @include_once('Log.php');
if (!$tmp)
{
    //This is a serious problem.  Log.php is in the PEAR
    //libraries, and if it can not be loaded then we can not
    //continue, since it is likely that the PEAR libraries are in the
    //wrong place.
    $msg = "Fatal Error.  This DiGIR provider is not configured correctly. \n";
    $msg .= "The include_path does not resolve the location of the required libraries. \n";
    $msg .= "Include path = ".ini_get('include_path');
    if (headers_sent())
    {
        echo "<error>".$msg."</error>";
    }
    else
    {
        echo "<pre>\n".$msg;
    }
    flush();
    die();
}

//it is assumed in many places that routines contained here
//are available - so just load it now.
include_once('DiGIR_errors.php');

//Load DiGIR_utils - some routines from there are used below.
include_once('DiGIR_utils.php');

/**
* The enable or disable (FALSE) the use of the mb_string library.  This library
* is required for translation between character encodings, and so if your
* data or metadata contain *any* characters outside of 7 bit ASCII, then you
* *must* enable use of the mbstring library.
*/
if (!defined('DIGIR_USE_MBSTRING'))
    define('DIGIR_USE_MBSTRING',TRUE);

/**
* Load the mbstring library if not already loaded.
* Note that dl() is only available when the PHP interpreter is running
* in CGI mode.  
*/
if (!extension_loaded('mbstring'))
{
    if (DIGIR_USE_MBSTRING)
    {
        //try and load it using dl()
        $res = loadlibrary_x('mbstring');
        if (!$res)
        {
            AppendError(DC_NOMBSTRING,
                'MB_STRING library is not available for character conversions',
                DIAG_WARN);
        }
    }
}

/////////////////////////////////////////////
//Stuff more specific to DiGIR operation

/**
* The file name of the Resources xml file which contains a list of resource
* names and associated configuration information.  Must be located in the
* DIGIR_CONFIG_DIR folder.
*/
if (!defined('DIGIR_RESOURCE_FILE'))
    define ('DIGIR_RESOURCE_FILE','resources.xml');

/**
* This is the file that contains metadata information about the host
* It must reside in the DIGIR_CONFIG_DIR.
*/
if (!defined('DIGIR_METADATA_FILE'))
    define('DIGIR_METADATA_FILE','providerMeta.xml');

/**
* Indicates whether the caching system should be used.  If you have a fast
* system and like to see the CPU meter pegged, then it's probably ok to
* turn caching off...
*/
if (!defined('DIGIR_USE_CACHE'))
    define('DIGIR_USE_CACHE',FALSE);

/**
* The directory that will be used by the cache.  This is a full path to a folder
* that has permissions for the php interpreter to create sub-folders and write
* content.  The specified folder must exist.
*/
if (!defined('DIGIR_CACHE_DIRECTORY'))
    define('DIGIR_CACHE_DIRECTORY',realpath(DIGIR_ROOT_DIR.'/../cache'));

/**
* This folder is used to stash incoming requests when _DEBUG is true
*/
if (!defined('DIGIR_DEBUG_DIR'))
    define('DIGIR_DEBUG_DIR',DIGIR_CACHE_DIRECTORY);

/**
* Number of seconds that cached metadata will be used before forcing an update.
* Default is once a day.
*/
if (!defined('DIGIR_METADATA_CACHE_LIFE_SECS'))
    define('DIGIR_METADATA_CACHE_LIFE_SECS',86400);

/**
* Number of seconds a cached record format is kept before checking for a new version
*/
if (!defined('DIGIR_FORMAT_CACHE_LIFE_SECS'))
    define('DIGIR_FORMAT_CACHE_LIFE_SECS',86400);
    
/**
* Indicates the time in seconds that a search response will remain in the cache.
* A unique request is identified by the combination of the parameters used to
* invoke getContent().  Default duration is zero, which turns off caching.
*/
if (!defined('DIGIR_RESULTSET_CACHE_LIFE_SECS'))
    define('DIGIR_RESULTSET_CACHE_LIFE_SECS',0);
    
/**
* Indicates the time in seconds that an inventory response will remain in the cache.
* A unique request is identified by the combination of the parameters used to
* invoke scanColumn().  Default duration is one hour.
*/
if (!defined('DIGIR_INVENTORY_CACHE_LIFE_SECS'))
    define('DIGIR_INVENTORY_CACHE_LIFE_SECS',3600);
    
/**
* Cache life of the javascript generator
*/
if (!defined('DIGIR_SCRIPT_CACHE_LIFE_SECONDS'))
    define('DIGIR_SCRIPT_CACHE_LIFE_SECONDS',86400);
    
/**
* Cache life of the UDDI query
*/
if (!defined('DIGIR_UDDI_CACHE_LIFE_SECONDS'))
    define('DIGIR_UDDI_CACHE_LIFE_SECONDS',86400);
    
/**
* Absolute number of records that can be returned in a response.  Applicable to
* search and scan.
*/
if (!defined('DIGIR_ABS_RECORD_LIMIT'))
    define('DIGIR_ABS_RECORD_LIMIT',10000);

/**
* Default number of records to be returned when no count is specified.
*/
if (!defined('DIGIR_DEFAULT_PAGESIZE'))
    define('DIGIR_DEFAULT_PAGESIZE',DIGIR_ABS_RECORD_LIMIT);

/**
* If true then DiGIR tests the parameter of an IN() COP to see if it's a URL
* If it is, then it will retrieve the document from the request which can be
* a DiGIR search response with a single column, or it can be a simple text
* file with one term per row.  The terms from the DiGIR response or the
* simple text file are used as the IN() COP terms.  DIGIR_MAX_JOIN_TERMS 
* places an absolute limit on the number of terms that can be used in a join.
*/
if (!defined('DIGIR_ALLOW_REMOTE_JOINS'))
    define('DIGIR_ALLOW_REMOTE_JOINS',TRUE);

/**
* The maximum number of terms that are used in a remote join operation.  Only
* the first n values are used, where n is DIGIR_MAX_JOIN_TERMS.
*/
if (!defined('DIGIR_MAX_JOIN_TERMS'))
    define('DIGIR_MAX_JOIN_TERMS',100);

if (!defined('DIGIR_SQL_QUOTE'))
    define('DIGIR_SQL_QUOTE',"'");
    
if (!defined('DIGIR_SQL_QUOTE_ESCAPE'))
    define('DIGIR_SQL_QUOTE_ESCAPE',"''");
    
/**
* Indicates if searches on text fields will be case sensitive.
* Check if your database supports the "LOWER" SQL function before setting to FALSE.
*/
if (!defined('DIGIR_CASE_SENSITIVE_SEARCH'))
    define('DIGIR_CASE_SENSITIVE_SEARCH',TRUE);


/**
* For logging.
*/

if (!defined("DIGIRLOG_TYPE"))
    define("DIGIRLOG_TYPE","file");
    
if (!defined("DIGIRLOG_PATH"))
	define("DIGIRLOG_PATH",realpath(DIGIR_ROOT_DIR."/../log"));
    
/**
* The name of the file that log information will be recorded to.
*/
if (!defined("DIGIRLOG_NAME"))
    define("DIGIRLOG_NAME","log.txt");

if (!defined("DIGIRLOG_OPTIONS"))
    define("DIGIRLOG_OPTIONS",implode(",",array()));


/**
* Log level.  Valid values for this are
* PEAR_LOG_EMERG
* PEAR_LOG_ALERT
* PEAR_LOG_CRIT
* PEAR_LOG_ERR
* PEAR_LOG_WARNING
* PEAR_LOG_NOTICE
* PEAR_LOG_INFO
* PEAR_LOG_DEBUG
* Table installations should set this to PEAR_LOG_INFO to record transactions
*/
if (!defined("DIGIRLOG_LEVEL"))
    define("DIGIRLOG_LEVEL",PEAR_LOG_DEBUG);

/**
* This is the relative or absolute path to the xpath library
*/
if (!defined('DIGIR_XPATH_LIBRARY'))
	define('DIGIR_XPATH_LIBRARY','xpath/XPath.class.php');

/**
* This is the relative or absolute path to the php ADODB library
*/
if (!defined('DIGIR_ADODB_LIBRARY'))
	define('DIGIR_ADODB_LIBRARY','adodb/adodb.inc.php');


define('DIGIR_SQL_DATEQUOTE','#');
define('DIGIR_TIME2SQL','%d-%b-%Y %T');

/**
* Set this true to allow incoming debug requests.
*/
if (!defined('DIGIR_ALLOWDEBUG'))
    define('DIGIR_ALLOWDEBUG',FALSE);

if (!defined('DIGIR_STATUSINTERVAL'))
    define('DIGIR_STATUSINTERVAL',3600);
    
if (!defined('DIGIR_STATUSPICKLE'))
    define('DIGIR_STATUSPICKLE',realpath(DIGIRLOG_PATH."/DiGIRStatus.txt"));


///////////////////////////////////////////////////////////////////
////DiGIRm parameters
/**
* Set this to true to allow DiGIRm to process multiple target requests
*/
if (!defined('DIGIRM_ALLOW'))
    define('DIGIRM_ALLOW',false);
/**
* This is the folder DiGIRm will use for caching responses.  Must be
* writable by the web server process.
*/
if (!defined('DIGIRM_CACHE'))
    define('DIGIRM_CACHE',DIGIR_CACHE_DIRECTORY);
/**
* maximum number of targets allowed to query in a single request.
* There is really no limit to this except for the server resources.  If none
* of the queries are against this machine then the process is quite efficient.
*/
if (!defined('DIGIRM_MAX_TARGETS'))
    define('DIGIRM_MAX_TARGETS',128);
/**
* Maximum number of sockets allowed to be open at once.  DiGIRm will select
* between sockets and reuse sockets as necessary to service all the requests.
* On win32 it's probably not a good idea to set this higher than 32.
*/
if (!defined('DIGIRM_MAX_SIMULTANEOUS'))
    define('DIGIRM_MAX_SIMULTANEOUS',8);

if (!defined('DIGIRM_LOG_PATH'))
    define('DIGIRM_LOG_PATH',realpath(DIGIR_ROOT_DIR."/../log"));
/**
* The name of the file that will contain log entries for DiGIRm.  The folder must
* exist and be writable by the web server process.
*/
if (!defined('DIGIRM_LOG_NAME'))
    define('DIGIRM_LOG_NAME','digirm.txt');
/**
* The logging level.  Same as for DiGIR.php described above.
*/
if (!defined('DIGIRM_LOG_LEVEL'))
    define('DIGIRM_LOG_LEVEL',PEAR_LOG_DEBUG);
/**
* The maximum time in seconds that the process will run.
*/
if (!defined('DIGIRM_MAX_RUNTIME'))
    define('DIGIRM_MAX_RUNTIME',120);

if (!defined('DIGIRM_STATUSINTERVAL'))
    define('DIGIRM_STATUSINTERVAL',3600);

if (!defined('DIGIRM_STATUSPICKLE'))
    define('DIGIRM_STATUSPICKLE',realpath(DIGIRLOG_PATH."/DiGIRmStatus.txt"));

//////////////////////////////////////////////////////
//// WMS operating parameters

if (!defined('DIGIRWMS_STATUSINTERVAL'))
    define('DIGIRWMS_STATUSINTERVAL',3600);

if (!defined('DIGIRWMS_STATUSPICKLE'))
    define('DIGIRWMS_STATUSPICKLE',realpath(DIGIRLOG_PATH."/DiGIRwmsStatus.txt"));

/**
* Set this to true or false to enable or disable the WMS service respectively.
*/
if (!defined('DIGIRWMS_ALLOW'))
    define('DIGIRWMS_ALLOW',false);

//////////////////////////////////////////////////////
//// Administrative tools parameters

/**
* URL path from the administrative environment (scripts being run under the "admin" dir)
* to the directory where the CSS files reside. Do not include the CSS file name. If user  
* configured the web server according to the installation instructions, default value is:
*/
if (!defined('DIGIRADMIN_CSS_URL'))
    define('DIGIRADMIN_CSS_URL','../');

/////////////////////////////////////////////////////////////////////////////
// Nothing to change past here
/////////////////////////////////////////////////////////////////////////////

define('DIGIR_MIN_PHP_VERSION','4.2.3');

/**
* This is the formatting string used to generate time stamps.
*/
define('TIME_FORMAT_STRING','Y-m-d H:i:sO');

//define('DiGIRNameSpace','http://www.namespaceTBD.org/digir');
define('DiGIRNameSpace','http://digir.net/schema/protocol/2003/1.0');
define('XMLSCHEMANS','http://www.w3.org/2001/XMLSchema');
define('XMLSCHEMAINST','http://www.w3.org/2001/XMLSchema-instance');
define('DiGIRmNameSpace','http://digir.net/schema/digirm/2003/1.0');

define("request_getCapabilities",1);
define("request_Search",2);
define("request_Scan",3);

//Fail any search on a string using a comparison of less than 3 characters.
define("g_MinTextLength",3);

// Global Constants
//Type of query element
define("q_NONE",0);
define("q_SIMPLE",1);
define("q_COMPLEX",2);

// type of node
define("op_NONE",0);
define("op_AND",1);
define("op_OR",2);
define("op_ANDNOT",3);
define("op_ORNOT",4);
define("op_ATTR",5);
define("op_RESULTSET",6);
define("op_ATTRIBUTESET",7);

// comparison operators == value of "USE" attributes
define("cp_root_value",32);
define("cp_lt",32);
define("cp_lteq",33);
define("cp_eq",34);
define("cp_gteq",35);
define("cp_gt",36);
define("cp_neq",37);
define("cp_like",38);
define("cp_in",39);
define("cp_contains",40);         //index server CONTAINS
define("cp_freetext",41);         //index server FREETEXT
define("cp_matches",42);          //index server MATCHES
define("cp_undefined",43);        //just use the default for this type

define("RPNConceptType",100);     //indicates that the concept in the filter is identified by ZID
define("XMLConceptType",101);     //concept is identified by the name in an XML filter structure

// matches RPN comparison (type 2)) attributes to filter comparison constants
$g_RPNCompAttrs = array(
    1=>cp_lt,
    2=>cp_lteq,
    3=>cp_eq,
    4=>cp_gteq,
    5=>cp_gt,
    6=>cp_neq,
    7=>cp_like,
    8=>cp_in,
    9=>cp_contains,
    10=>cp_freetext,
    11=>cp_matches
);

// data "types" == family of SQL data type
define("type_TEXT",0);
define("type_NUMERIC",1);
define("type_BBOUNDING",2);
define("type_JULIANDAY",3);
define("type_DATETIME",4);
define("type_SQLSTUB",5);

//SQL keywords for sort order.
define('SORT_ASCENDING','ASC');
define('SORT_DESCENDING','DESC');


//Global variables
$g_bForceNoCase = false;                    //set true to use no case comparisons for case sensitive SQL db's
$g_cDelimiter = ",";
$g_cMultiTermDelimiter = ",";
$g_cBoundingBoxDelimiter = " ";
$g_DefaultType2Comparison = 3;
$g_cTermDelimiter = "\"";
$g_SQLDateFormat = "'%Y-%m-%d %H:%M:%S'";   //used to generate time strings for SQL DATETIME comparisons by strftime()
$g_SQLWildCard = "%";                       //"*" for access ODBC, "%" for every other SQL database


//test block - executed if script called directly
if ((isset($_SERVER['SCRIPT_NAME']) && preg_match("/\/DiGIR_globals.php/i",$_SERVER['SCRIPT_NAME'])) ||
    (isset($_SERVER['argv'][0]) && strcasecmp($_SERVER['argv'][0],'DiGIR_globals.php') === 0))
{
    $tmp = @include_once('PHPUnit.php');
    if (!$tmp)
    {
        //error - unable to load phpUnit.php!
        $msg = "Fatal Error- unable to load phpUnit.php.\n".
            "There is a problem with the installation that prevents loading the necessary libraries";
        if (headers_sent())
        {
                echo "<error>".$msg."</error>";
        }
        else
        {
                echo "<pre>".$msg;
        }
        flush();
        phpinfo();
        die();
    }
    
	
    class GlobalsTest extends PHPUnit_TestCase 
    {
        var $loglevels;
            
        function GlobalsTest($name) 
        {
            $this->PHPUnit_TestCase($name);
        }

        function setUp() 
        {
            $this->loglevels = array(PEAR_LOG_EMERG,
                    PEAR_LOG_ALERT,PEAR_LOG_CRIT,PEAR_LOG_ERR,
                    PEAR_LOG_WARNING,PEAR_LOG_NOTICE,PEAR_LOG_INFO,
                    PEAR_LOG_DEBUG);
        }
        
        function assertRange($v,$minv,$maxv,$msg)
        {
            $res = array(TRUE,'ok');
            if ($v < $minv)
            {
                $res[0] = FALSE;
                $res[1] = sprintf($msg,'low',$v);
            }	
            if ($v > $maxv)
            {
                $res[0] = FALSE;
                $res[1] = sprintf($msg,'high',$v);
            }	
            return $res;
        }
         
        function test_DIGIR_CONFIG_DIR()
        {
            $this->assertTrue(file_exists(DIGIR_CONFIG_DIR),
                'DIGIR_CONFIG_DIR ('.DIGIR_CONFIG_DIR.') does not exist.');
        }
        
        function test_DIGIR_RESOURCE_FILE()
        {
            $this->assertTrue(file_exists(realpath(DIGIR_CONFIG_DIR.'/'.DIGIR_RESOURCE_FILE)),
                'DIGIR_RESOURCE_FILE ('.realpath(DIGIR_CONFIG_DIR.'/'.DIGIR_RESOURCE_FILE).') does not exist.');				
        }
        
        function test_DIGIR_METADATA_FILE()
        {
            $this->assertTrue(file_exists(realpath(DIGIR_CONFIG_DIR.'/'.DIGIR_METADATA_FILE)),
                'DIGIR_RESOURCE_FILE ('.realpath(DIGIR_CONFIG_DIR.'/'.DIGIR_METADATA_FILE).') does not exist.');				
        }
        
        function test_DIGIR_MAX_RUNTIME()
        {
            $res = $this->assertRange(DIGIR_MAX_RUNTIME,10,180,
                    'DIGIR_MAX_RUNTIME is probably too %s (%d)');
            $this->assertTrue($res[0],$res[1]);
        }
        
        function test_DIGIR_DEBUG_DIR()
        {
            $this->assertTrue(file_exists(DIGIR_DEBUG_DIR),
                '[Advisory] DIGIR_DEBUG_DIR ('.DIGIR_DEBUG_DIR.') does not exist.');
        }
        
        function test_DIGIR_CACHE_DIRECTORY()
        {
            $this->assertTrue(file_exists(DIGIR_CACHE_DIRECTORY),
                'DIGIR_CACHE_DIRECTORY ('.DIGIR_CACHE_DIRECTORY.') does not exist.');
        }

        function test_DIGIR_METADATA_CACHE_LIFE_SECS()
        {
            $res = $this->assertRange(DIGIR_METADATA_CACHE_LIFE_SECS,360,86400*30,
                    '[Advisory] DIGIR_METADATA_CACHE_LIFE_SECS is set %s (%d)');
            $this->assertTrue($res[0],$res[1]);
        }

        function Test_DIGIR_FORMAT_CACHE_LIFE_SECS()
        {
                $res = $this->assertRange(DIGIR_METADATA_CACHE_LIFE_SECS,360,86400*30,
                        '[Advisory] DIGIR_FORMAT_CACHE_LIFE_SECS is set %s (%d)');
                $this->assertTrue($res[0],$res[1]);
        }

        function Test_DIGIR_RESULTSET_CACHE_LIFE_SECS()
        {
                $res = $this->assertRange(DIGIR_RESULTSET_CACHE_LIFE_SECS,60,43200,
                        '[Advisory] DIGIR_RESULTSET_CACHE_LIFE_SECS is set %s (%d)');
                $this->assertTrue($res[0],$res[1]);
        }
        
        function Test_DIGIR_INVENTORY_CACHE_LIFE_SECS()
        {
                $res = $this->assertRange(DIGIR_INVENTORY_CACHE_LIFE_SECS,60,43200,
                        '[Advisory] DIGIR_INVENTORY_CACHE_LIFE_SECS is set %s (%d)');
                $this->assertTrue($res[0],$res[1]);
        }
        function Test_DIGIR_SCRIPT_CACHE_LIFE_SECONDS()
        {
                $res = $this->assertRange(DIGIR_SCRIPT_CACHE_LIFE_SECONDS,60,43200,
                        '[Advisory] DIGIR_SCRIPT_CACHE_LIFE_SECONDS is set %s (%d)');
                $this->assertTrue($res[0],$res[1]);
        }
        function Test_DIGIR_UDDI_CACHE_LIFE_SECONDS()
        {
                $res = $this->assertRange(DIGIR_UDDI_CACHE_LIFE_SECONDS,60,43200,
                        '[Advisory] DIGIR_UDDI_CACHE_LIFE_SECONDS is set %s (%d)');
                $this->assertTrue($res[0],$res[1]);
        }
        function Test_DIGIR_ABS_RECORD_LIMIT()
        {
                $res = $this->assertRange(DIGIR_ABS_RECORD_LIMIT,100,100000,
                        '[Advisory] DIGIR_ABS_RECORD_LIMIT is set %s (%d)');
                $this->assertTrue($res[0],$res[1]);
        }
        function Test_DIGIR_DEFAULT_PAGESIZE()
        {
                $res = $this->assertRange(DIGIR_DEFAULT_PAGESIZE,50,10000,
                        '[Advisory] DIGIR_DEFAULT_PAGESIZE is set %s (%d)');
                $this->assertTrue($res[0],$res[1]);
        }
        
        function test_DIGIR_ALLOW_REMOTE_JOINS()
        {
                $this->assertTrue(DIGIR_ALLOW_REMOTE_JOINS,
                        '[Advisory] Remote joins are disabled. Functionality may be reduced');
        }

        function Test_DIGIR_MAX_JOIN_TERMS()
        {
                $res = $this->assertRange(DIGIR_MAX_JOIN_TERMS,10,1000,
                        '[Advisory] DIGIR_MAX_JOIN_TERMS is set %s (%d)');
                $this->assertTrue($res[0],$res[1]);
        }
        
        function test_DIGIRLOG_LEVEL()
        {
                if (DIGIRLOG_LEVEL == PEAR_LOG_DEBUG)
                        $this->assertTrue(FALSE,'[Advisory] DIGIRLOG_LEVEL is set to record debug messages');
                $this->assertTrue(in_array(DIGIRLOG_LEVEL,$this->loglevels),
                        'DIGIRLOG_LEVEL is not a valid PEAR_LOG level.');
        }
        
        function test_DIGIRLOG_NAME()
        {
                $this->assertTrue(file_exists(realpath(DIGIRLOG_PATH.'/'.DIGIRLOG_NAME)),
                        'DIGIRLOG_NAME ('.realpath(DIGIRLOG_PATH.'/'.DIGIRLOG_NAME).') does not exist.');
        }
        
        function test_OpenLog()
        {
            $g_LOG = &Log::singleton(DIGIRLOG_TYPE,
                DIGIRLOG_PATH.DIGIRLOG_NAME,
                $_SERVER['REMOTE_ADDR'],
                explode(",",DIGIRLOG_OPTIONS),
                DIGIRLOG_LEVEL);
    $this->assertTrue($g_LOG,'The DiGIR Log could not be instantiated.');
    $g_LOG = NULL;
        }
        
        function test_DIGIR_XPATH_LIBRARY()
        {
                $incpath = ini_get('include_path');
                $res = @include_once(DIGIR_XPATH_LIBRARY);
                $this->assertTrue($res,'The xpath library ('.DIGIR_XPATH_LIBRARY.') could not be loaded.  Include_path = ['.$incpath.']');
        }
        
        function test_DIGIR_ADODB_LIBRARY()
        {
                $incpath = ini_get('include_path');
                $res = @include_once(DIGIR_ADODB_LIBRARY);
                $this->assertTrue($res,'The adodb library ('.DIGIR_ADODB_LIBRARY.') could not be loaded.  Include_path = ['.$incpath.']');
        }
        function test_DIGIR_STATUSINTERVAL()
        {
            $res = $this->assertRange(DIGIR_STATUSINTERVAL,60,7200,
                    '[Advisory] DIGIR_STATUSINTERVAL is set %s (%d)');
            $this->assertTrue($res[0],$res[1]);
        }
        function test_DIGIR_STATUSPICKLE()
        {
            $fname = DIGIR_STATUSPICKLE.".test";
            $fh = fopen($fname,"wb");
            if ($fh)
            {
                fclose($fh);
                unlink($fname);
            }
            $this->assertTrue($fh,
                sprintf("The folder containing the DIGIR_STATUSPICKLE (%s) appears to be unwritable.",DIGIR_STATUSPICKLE));
        }
        function test_DIGIRM_STATUSINTERVAL()
        {
            $res = $this->assertRange(DIGIRM_STATUSINTERVAL,60,7200,
                    '[Advisory] DIGIRM_STATUSINTERVAL is set %s (%d)');
            $this->assertTrue($res[0],$res[1]);
        }
        function test_DIGIRM_STATUSPICKLE()
        {
            $fname = DIGIRM_STATUSPICKLE.".test";
            $fh = fopen($fname,"wb");
            if ($fh)
            {
                fclose($fh);
                unlink($fname);
            }
            $this->assertTrue($fh,
                sprintf("The folder containing the DIGIRM_STATUSPICKLE (%s) appears to be unwritable.",DIGIRM_STATUSPICKLE));
        }
        function test_DIGIRWMS_STATUSINTERVAL()
        {
            $res = $this->assertRange(DIGIRWMS_STATUSINTERVAL,60,7200,
                    '[Advisory] DIGIRWMS_STATUSINTERVAL is set %s (%d)');
            $this->assertTrue($res[0],$res[1]);
        }
        function test_DIGIRWMS_STATUSPICKLE()
        {
            $fname = DIGIRWMS_STATUSPICKLE.".test";
            $fh = fopen($fname,"wb");
            if ($fh)
            {
                fclose($fh);
                unlink($fname);
            }
            $this->assertTrue($fh,
                sprintf("The folder containing the DIGIRWMS_STATUSPICKLE (%s) appears to be unwritable.",DIGIRWMS_STATUSPICKLE));
        }
        function test_MBSTRINGLIB()
        {
            $this->assertTrue(extension_loaded('mbstring'),
                "The mbstring extension is not loaded.  Check PHP.ini or dl('php_mbstring.dll') in localconfig.php.");
        }
    }

    echo "<h1>DiGIR_globals.php Test</h1>";
    echo "<p>".idDiGIR_globals."</p>";
    flush();

    //Dump the configuration settings (if allowed)
    if (DIGIR_ALLOW_CONFIG_DUMP)
    {
        echo "<p><b>[Warning]</b><br />DIGIR_ALLOW_CONFIG_DUMP is set to TRUE.  This may "
        ."pose a security risk.  Please set this to FALSE when installation is "
        ."complete.  To do this, open <code>localconfig.php</code> with a text editor"
        ." and uncomment or add the line:</p>\n"
        ."<p><code>define('DIGIR_ALLOW_CONFIG_DUMP',FALSE);</code></p>\n";
        echo "<h3>DiGIR Configuration Values</h3>\n";
        echo "<pre>";
        echo "  Installation folder = ".realpath("..")."\n";
        $adefs = get_defined_constants();
        $adeftmp = array();
        foreach ($adefs as $k=>$v)
        {
            if (strpos($k,'DIGIR') === 0)
            {
                $adeftmp[$k] = $v;
            }
        }
        ksort($adeftmp);
        foreach ($adeftmp as $k=>$v)
        {
            if (strpos($k,'DIGIR') === 0)
            {
                echo sprintf("  %s = %s\n",$k,(string)$v);
            }
        }
        echo "\n";
        echo "</pre>";
        echo "<hr />";
    }
    flush();

    echo "<h2>Test Results</h2>\n";
    echo "<p>All tests here should pass.  </p>";
    echo "<p>Failure for those with an [Advisory] flag is not a critical "
    ."issue but should probably be adjusted for improved performance</p>"
    ."<hr />";

    $suite = new PHPUnit_TestSuite('GlobalsTest');
    $result = PHPUnit::run($suite);
    echo $result->toHTML();
    
    echo "<hr />";
    echo "<p>Done.</p>";
}
?>
