<?php  

/* 

  Copyright (c) 2007 Jason Birch

  This library is free software; you can redistribute it and/or
  modify it under the terms of version 2.1 of the GNU Lesser
  General Public License as published by the Free Software Foundation.

  This library is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  Lesser General Public License for more details.

  You should have received a copy of the GNU Lesser General Public
  License along with this library; if not, write to the Free Software
  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA

*/

// Define the path to your webconfig file if it's somewhere else
define("MG_WEB_CONFIG_FILE",'./webconfig.ini');

// This is only here because .Net users need to be able to use this too...
class MgServiceType
{
  const 
ResourceService 
}

$usageString "\nThis script provides you with a list of all external file locations in your Library\n\n  Usage: ".$argv[0]." <AdministratorPassword>\n\n";

if (
$argc != 
{
  print (
$usageString);

else 
{

  
$adminPassword $argv[1];

  try
  {

    
// Perform some basic site setup
    
MgInitializeWebTier (MG_WEB_CONFIG_FILE);
    
$userInfo = new MgUserInformation("Administrator"$adminPassword);
    
$siteConnection = new MgSiteConnection();
    
$siteConnection->Open($userInfo);
    
$resourceService $siteConnection->CreateService(MgServiceType::ResourceService);

    
// Enumerates all FeatureSources in the library and flip into a SimpleXML object
    
$resourceID = new MgResourceIdentifier("Library://");
    
$byteReader $resourceService->EnumerateResources($resourceID, -1"FeatureSource");
    
$resourcesXML = new SimpleXMLElement($byteReader->ToString());
    
    
// Iterate FeatureSource resources, grab their resource content, and
    // output the resource ID and path for known file-based parameters
    
foreach ($resourcesXML->xpath('//ResourceId') as $currentId
    {
      
$resourceID = new MgResourceIdentifier($currentId);
      
$byteReader $resourceService->GetResourceContent($resourceID);
      
$resourceXML = new SimpleXMLElement($byteReader->ToString());
      
$fileResources $resourceXML->xpath('//Parameter[Name="DefaultFileLocation"]|//Parameter[Name="File"]|//Parameter[Name="DefaultRasterFileLocation"]');
      foreach (
$fileResources as $fileResource)
      {
        print 
'"'.$currentId.'","'.$fileResource->Value.'"'."\n";
      }
    }

    exit(
0);
   
  }
  catch ( 
MgException $e )
  {
    print (
$usageString);
    print (
"  Error: ".$e->GetMessage()."\n\n");
  }
  catch ( 
Exception $e )
  {
    print (
$usageString);
    print (
"  Error: ".$e->GetMessage()."\n\n");
  }
}

exit(
1);

?>