<& /Admin/Elements/Header, title => "Modify template ".$TemplateObj->id&>
<& /Admin/Elements/SystemTabs &>
<& /Elements/ListActions, actions => \@results &>

<& /Elements/TitleBoxStart, title => $title &>

<FORM METHOD=POST ACTION="Template.html">
%if ($create ) {
<INPUT TYPE=HIDDEN NAME=template VALUE="new">
% } else {
<INPUT TYPE=HIDDEN NAME=template VALUE="<%$TemplateObj->Id%>">
% }

%# hang onto the queue id
<INPUT TYPE=HIDDEN name="Queue" value="<%$Queue%>">


Name: <input name="Name" VALUE="<%$TemplateObj->Name%>" SIZE=20><BR>
Description: <input name="Description" VALUE="<%$TemplateObj->Description%>" SIZE=80><BR>

<TEXTAREA NAME=Content ROWS=25 COLS=80 WRAP=SOFT>
<%$TemplateObj->Content%></TEXTAREA>

<& /Elements/TitleBoxEnd&>
<&/Elements/Submit&>
</FORM>



<%INIT>

my $TemplateObj = new RT::Template($session{'CurrentUser'});
my  ($title, @results);

if ($create) {
  $title = "Create a template";
}

else {
  if ($template eq 'new') {
      my ($val, $msg) =  $TemplateObj->Create(Queue => $Queue, Name => $Name);
      Abort("Could not create template: $msg") unless ($val);
     push @results, $msg;
     $title = 'Created template ' . $TemplateObj->Name(); 
    }
    else {
       $TemplateObj->Load($template) || Abort('No Template');
      $title = 'Editing template ' . $TemplateObj->Name(); 
    }
  
    
}
if ($TemplateObj->Id()) {
  my @attribs = qw( Description Content Queue Name);
  my @aresults = UpdateRecordObject( AttributesRef => \@attribs, 
				     Object => $TemplateObj, 
				     ARGSRef => \%ARGS);
  push @results, @aresults;
}
</%INIT>
<%ARGS>
$Queue => undef
$template => undef
$create => undef
$Name => undef
</%ARGS>
