SetClientIp(GetClientIp());
$user->SetClientAgent(GetClientAgent());
$siteConnection = new MgSiteConnection();
$siteConnection->Open($user);
} else {
/* If a session has previously been established, we can connect using the
* credentials that the user logged in with previously ... these are stored
* in the MapGuide session.
* It is possible for the user to re-authenticate using a different set of
* credentials. Handle this here, but keep the session the same.
*/
$sessionID = $_REQUEST['session'];
session_id(str_replace('_', '-', $sessionID));
session_start();
/* current user is re-authenticating or not? */
if (isset($_REQUEST['username']) && isset($_REQUEST['password'])) {
$user = new MgUserInformation($_REQUEST['username'], $_REQUEST['password']);
$user->SetClientIp(GetClientIp());
$user->SetClientAgent(GetClientAgent());
$user->SetMgSessionId($sessionID);
} else {
$user = new MgUserInformation($sessionID);
$user->SetClientIp(GetClientIp());
$user->SetClientAgent(GetClientAgent());
}
/* open a connection to the site. This will generate exceptions if the user
* is set up properly - not found, invalid password etc
*/
$siteConnection = new MgSiteConnection();
$siteConnection->Open($user);
/* MgUserInformation doesn't tell us who is logged in so we store it
* in the php session for convenience
*/
if (isset($_REQUEST['username']) && isset($_REQUEST['password'])) {
$_SESSION['username'] = $_REQUEST['username'];
}
//echo "".$_SESSION['username']. '';
}
//common resource service to be used by all scripts
$resourceService = $siteConnection->CreateService(MgServiceType::ResourceService);
if (isset($_REQUEST['mapname'])) {
$mapName = $_REQUEST['mapname'];
$mapResourceID = new MgResourceIdentifier( 'Session:'.$sessionID.'//'.$mapName.'.MapDefinition');
$mapStateID = new MgResourceIdentifier('Session:'.$sessionID.'//'.$mapName.'.'.MgResourceType::Map);
}
}
catch (MgException $e)
{
$initializationErrorMessage = $e->GetExceptionMessage();
$initializationErrorDetail = $e->GetDetails();
$initializationErrorStackTrace = $e->GetStackTrace();
$initializationErrorOccurred = true;
//echo "{success: false, message:'".$initializationErrorMessage."'}";
//DisplayInitializationErrorHTML();
}
function InitializationErrorOccurred()
{
global $initializationErrorOccurred;
return $initializationErrorOccurred;
}
function DisplayInitializationErrorHTML()
{
global $initializationErrorMessage, $initializationErrorDetail;
echo "
";
echo "Error
|
";
if($initializationErrorMessage != null)
{
$message = $initializationErrorMessage;
while(strpos($message, '\n'))
{
$message = str_replace('\n', '
', $message);
}
echo "" . $message . " |
";
}
if ($initializationErrorDetail != null && (strlen($initializationErrorDetail) - strlen($initializationErrorMessage) > 4))
{
$detail = $initializationErrorDetail;
while(strpos($detail, '\n'))
{
$detail = str_replace('\n', '
', $detail);
}
echo "" . $detail . " |
";
}
echo "
";
}
function DisplayInitializationErrorText()
{
global $initializationErrorMessage, $initializationErrorDetail, $initializationErrorStackTrace;
echo "ERROR: " . $initializationErrorMessage . "\n";
echo $initializationErrorDetail . "\n";
echo $initializationErrorStackTrace . "\n";
}
function GetDefaultLocale()
{
return "en"; // localizable string
}
function GetLocalizationPath()
{
$thisFile = __FILE__;
$pos = strrpos($thisFile, '\\');
if ($pos == false)
$pos = strrpos($thisFile, '/');
return substr($thisFile, 0, $pos+1) . "../../../text/";
}
function FormatMessage($id, $locale, $params)
{
$text = GetLocalizedString($id, $locale);
for($i = 0; $i < count($params); $i++)
{
$tag = "{" . $i . "}";
$pos1 = strpos($text, $tag);
if($pos1 == false)
break;
if($pos1 > 0)
$begin = substr($text, 0, $pos1);
else
$begin = "";
$end = substr($text, $pos1 + strlen($tag));
$text = $begin . $params[$i] . $end;
}
return $text;
}
function GetSurroundVirtualPath()
{
if (isset($_SERVER["REQUEST_URI"]))
{
$path = $_SERVER["REQUEST_URI"];
$baseuri = substr($path, 0, strrpos($path, '?') + 1);
}
else
{
$baseuri = $_SERVER["PHP_SELF"];
}
return substr($baseuri, 0, strrpos($baseuri, '/') + 1);
}
function GetRootVirtualFolder()
{
if (isset($_SERVER["REQUEST_URI"]))
{
$path = $_SERVER["REQUEST_URI"];
$baseuri = substr($path, 0, strrpos($path, '?') + 1);
}
else
{
$baseuri = $_SERVER["PHP_SELF"];
}
return substr($baseuri, 0, strpos($baseuri, '/', 1));
}
function GetClientOS() {
if(!isset($_SERVER['HTTP_USER_AGENT']))
return 0;
$agent = $_SERVER['HTTP_USER_AGENT'];
if(strpos($agent, "Windows") != FALSE)
return 0;
else if(strpos($agent, "Macintosh") != FALSE)
return 1;
return 2;
}
function EscapeForHtml($str)
{
$org = array("'", "\"", "\n", "<", ">");
$repl = array("'", """, " ", "<", ">" );
return str_replace($org, $repl, $str);
}
function GetDecimalFromLocalizedString($numberString, $locale)
{
if($locale != null && $numberString != null)
{
// Remove thousand separators
$thousandSeparator = GetLocalizedString("THOUSANDSEPARATOR", $locale);
if($thousandSeparator != null && strlen($thousandSeparator) > 0)
{
$numberString = str_replace($thousandSeparator, "", $numberString);
}
// Replace localized decimal separators with "."
$decimalSeparator = GetLocalizedString("DECIMALSEPARATOR", $locale);
if($decimalSeparator != null && strlen($decimalSeparator) > 0 && $decimalSeparator != ".")
{
$numberString = str_replace($decimalSeparator, ".", $numberString);
}
}
return $numberString;
}
function GetClientIp()
{
$clientIp = '';
if (array_key_exists('HTTP_CLIENT_IP', $_SERVER)
&& strcasecmp($_SERVER['HTTP_CLIENT_IP'], 'unknown') != 0)
{
$clientIp = $_SERVER['HTTP_CLIENT_IP'];
}
else if (array_key_exists('HTTP_X_FORWARDED_FOR', $_SERVER)
&& strcasecmp($_SERVER['HTTP_X_FORWARDED_FOR'], 'unknown') != 0)
{
$clientIp = $_SERVER['HTTP_X_FORWARDED_FOR'];
}
else if (array_key_exists('REMOTE_ADDR', $_SERVER))
{
$clientIp = $_SERVER['REMOTE_ADDR'];
}
return $clientIp;
}
function GetClientAgent()
{
return "Fusion Viewer";
}
// Builds a MgFeatureQueryOptions with an explicit property list based
// on the given class definition
//
// This is to ensure that a "select * from featureclass" query from relational
// providers will have its column list bounded to what is recognized in the
// class definition. Some providers are known to produce "select * from table"
// queries that "leak" out column types that the provider does not know how to
// process. Using an explicit property list from its class definition will
// allow us to avoid such issues
function BuildFeatureQueryOptions($classDef)
{
$query = new MgFeatureQueryOptions();
$geomPropName = $classDef->GetDefaultGeometryPropertyName();
$propertyList = $classDef->GetProperties();
for ($i = 0; $i < $propertyList->GetCount(); $i++)
{
$propertyDef = $propertyList->GetItem($i);
$property = $propertyList->GetItem($i)->GetName();
if (($property != $geomPropName) && ($propertyDef->GetPropertyType() == MgFeaturePropertyType::DataProperty))
{
$propertyType = $propertyList->GetItem($i)->GetDataType();
switch ($propertyType) {
case MgPropertyType::Boolean:
$query->AddFeatureProperty($property);
break;
case MgPropertyType::Byte:
$query->AddFeatureProperty($property);
break;
case MgPropertyType::DateTime:
$query->AddFeatureProperty($property);
break;
case MgPropertyType::Single:
$query->AddFeatureProperty($property);
break;
case MgPropertyType::Double:
$query->AddFeatureProperty($property);
break;
case MgPropertyType::Int16:
$query->AddFeatureProperty($property);
break;
case MgPropertyType::Int32:
$query->AddFeatureProperty($property);
break;
case MgPropertyType::Int64:
$query->AddFeatureProperty($property);
break;
case MgPropertyType::String:
$query->AddFeatureProperty($property);
break;
}
} else if ($property == $geomPropName){
$query->AddFeatureProperty($property);
}
}
return $query;
}
?>