<& /Admin/Elements/Header, Title => loc("Apple GSX") &>
<& /Elements/Tabs &>

% unless ($ok) {
<&| /Widgets/TitleBox, title => loc('Authentication failure'), class => "error" &>
Credentials below are incorrect!
</&>
% }

<form method="post" action="<% RT->Config->Get('WebPath') %>/Admin/Assets/GSX/">
<table>
<tr><td class="label"><label for="UserId"><&|/l&>User ID</&></label></td>
    <td><input name="UserId" id="UserId" value="<% $UserId %>" size="20" /></td>
</tr>

<tr><td class="label"><label for="Password"><&|/l&>Password</&></label></td>
    <td><input name="Password" id="Password" type="password" size="20" /></td>
</tr>

<tr><td class="label"><label for="ServiceAccountNo"><&|/l&>Service Account #</&></label></td>
    <td><input name="ServiceAccountNo" id="ServiceAccountNo" value="<% $ServiceAccountNo %>" size="20" /></td>
</tr>
</table>

<& /Elements/Submit, Name => "Update", Label => loc('Update') &>
</form>
<%init>
$m->clear_and_abort(403) unless $session{'CurrentUser'}->HasRight(
    Object => RT->System,
    Right  => 'SuperUser',
);

my $config = RT->System->FirstAttribute('AppleGSXOptions');
$config = $config ? $config->Content : {};
if ($ARGS{Update}) {
    $config->{UserId}           = $UserId;
    $config->{Password}         = $Password if $Password;
    $config->{ServiceAccountNo} = $ServiceAccountNo;
    RT->System->SetAttribute( Name => 'AppleGSXOptions', Content => $config );
}

my $gsx = RT::Extension::Assets::AppleGSX->Client;
my $ok = $config->{UserId}
      && $config->{Password}
      && $config->{ServiceAccountNo}
      && $gsx->Authenticate;

$UserId           = $config->{UserId};
$ServiceAccountNo = $config->{ServiceAccountNo};
</%init>
<%args>
$UserId => ""
$Password => ""
$ServiceAccountNo => ""
</%args>
