#!/usr/bin/perl -Tw -I. -I/usr/local/positive/Perl

#
# This software is copyright (c) 2001-2002 Positive Networks, Inc.  All rights reserved.
#
# This software is the proprietary and confidential property of Positive Networks, Inc.
# Possession, transmission, publication, or use of this software is prohibited except by prior written consent.
#

use strict;
use Pos::Webtop::Web::ModuleLoader;

my $tb           = Pos::Webtop::Toolbox->new();
my $client       = $tb->getClient();
my $cgi          = $tb->getCgi();
my $db           = $tb->getWebtopDbWriter();
my $oem          = $tb->getOem();

$client->checkSession();

my $launchId     = $cgi->param('launchId');
my $launchIdHash = $cgi->param('launchIdHash');

my @launchInfo   = $db->query(sql => "
	select
		launch_point_id,
		customer_id,
		run_as_user_id,
		app_id
	from
		w_launch_points
	where
		launch_point_hash = '" . $db->escape(dirty => $launchIdHash) . "'
		AND launch_point_id = '" . $db->escape(dirty => $launchId) . "'
	");

if (scalar(@launchInfo) == 0) {
	print STDERR "Invalid information supplied.\n";

	exit 0;
}

my ($launchPointId, $customerId, $userId, $appId, $arguments) = @{ $launchInfo[0] };

# Create a session that does not need to authenticate.
$client->createInitializedSession(userId => $userId, customerId => $customerId, launcherSession => 1);

print "Content-type: text/html\n\n

	<script language='javascript' version='1.3'>

		function onOcxLoadedCustom() {


			installExecuteApplication('LAUNCHER', '$launchPointId', '$appId');

		}

	</script>

	" . Pos::Webtop::OcxLauncher::getFrameHtml(tb => $tb);


# Always commit at the end.
$db->commit;
