#!/usr/local/bin/perl
# chooser.cgi
# Outputs HTML for a frame-based svc chooser
require './smf-lib.pl';
&init_config();
&ReadParse();
# type specifies svc, inst or both
$type = "both";
if (defined($in{'type'})) {
$type = $in{'type'};
}
if ((defined($in{'add'})) && ($in{'add'})) {
# Only use last fmri by default
$in{'fmri'} =~ s/\s+$//;
if ($in{'fmri'} =~ /\n(.*)$/) {
$in{'fmri'} = $1;
}
}
$fmri = $in{'fmri'};
if ($fmri =~ /^svc\:\/([^\:]*)\:*(.*)$/) {
# fmri entered is valid
$svc = $1;
$inst = $2;
}
else {
$fmri = "svc:/";
$svc = "";
$inst = "";
}
$add = int($in{'add'});
$frame = $in{'frame'};
if ($frame eq "" ) {
$frame = 0;
}
if ($in{'frame'} == 0) {
# base frame
&PrintHeader();
if ($in{'type'} eq "svc")
{ print "
$text{'svc_chooser_titlesvc'}\n"; }
elsif ($in{'type'} eq "inst")
{ print "$text{'svc_chooser_titleinst'}\n";}
else
{ print "$text{'svc_chooser_titleboth'}\n";}
print "\n";
}
elsif ($in{'frame'} == 1) {
# List of svcs
&header();
print <
function svcclick(fmri, inst, expand, isvalid)
{
if ((inst == "") || (inst == ":")) {
selected_fmri = fmri;
}
else {
selected_fmri = fmri+inst;
}
curr = top.bottomframe.document.forms[0].fmri.value;
if (isvalid ==1) {
top.bottomframe.document.forms[0].fmri.value = selected_fmri;
}
if (expand == 1) {
location ="svc_chooser.cgi?frame=1&add=$add&type=$type&fmri="+fmri+inst;
}
}
EOF
print "", &text('svc_chooser_fmri', $fmri),"\n";
print "\n";
&footer();
}
elsif ($in{'frame'} == 2) {
# Current fmri and OK/cancel buttons
&header();
print <
function fmrichosen()
{
if ($add == 0) {
top.opener.ifield.value = document.forms[0].fmri.value;
}
else {
if (top.opener.ifield.value != "") {
top.opener.ifield.value += " ";
}
top.opener.ifield.value += document.forms[0].fmri.value;
}
top.close();
}
EOF
print "\n";
print "\n";
print " | \n";
print "";
print " |
\n";
&footer();
}