%# Conscious is when you are aware of something and conscience is when you
%# wish you weren't.

<& /RG/Elements/PageHeader &>

<form action="Page.html">
<table width="100%" border="0" cellspacing="4" cellpadding="0">
  <tr>
    <td>
      <table border="0" cellspacing="0" cellpadding="6" class="poptable" width="100%">
        <tr> 
          <td>
            <table border="0" cellspacing="0" cellpadding="4" align="center">
              <tr> 
                <td class="tableEmboss" bgcolor="#144678"><font color="#FFFFFF"><&|/l&>Page Setup</&></font></td>
                <td width="2">
                  <p align="center">&nbsp; </p>
                </td>
                <td class="tableEmboss" bgcolor="#144678"><font color="#FFFFFF"><&|/l&>Margin settings</&></font> 
                </td>
              </tr>
              <tr> 
                <td valign="top" class="tableEmboss"> 
                  <table width="100%" border="0" cellspacing="0" cellpadding="0">
% my $count = 0;
% foreach my $section ($ContentObj->Sections) {
%     my $SectionObj = $ContentObj->SectionObj(++$count);
                    <tr valign=middle>
                      <td width="25%" align="center"><nobr>
		      <% loc($section) %>
                      </nobr></td>
                      <td width="75%" align="left"><nobr>
                        <input type="checkbox" name="Section-<% $count %>-hidden" value="on"
			 <% $SectionObj->att('hidden') ? 'checked' : '' %>>
                        <&|/l&>Hide</&>
% if ($section =~ /header|footer/) {
			&nbsp;
                        <input type="checkbox" name="Section-<% $count %>-separator" value="on"
			 <% $SectionObj->att('separator') ? 'checked' : '' %>>
                        <&|/l&>Show separator</&>
% }
                        </nobr></td>
                    </tr>
% }
                  </table>
                </td>
                <td width="2">&nbsp;</td>
                <td valign="top" class="tableEmboss"> 
                  <table width="100%" border="0" cellspacing="0" cellpadding="2">
                    <tr> 
% foreach my $key (map "margin_$_", qw/top bottom left right/) {
% $m->print("</tr><tr>") if $key eq 'margin_left';
% my $margin = $HeadObj->att($key);
% $margin = 200 unless length($margin);
                      <td align="center"><nobr>
			  <% loc($key) %>:
                          <input style="width: 30px" value="<% int($margin) %>" type="text" name="Head-<% $key %>" size="10">mm
                      </nobr></td>
% }
                    </tr>
		    <tr><td height="35" colspan="2" valign="bottom">
		    <&|/l&>Paper size:</&>
% my $Paper = $HeadObj->att('paper') || 'A4';
<select name="Head-paper">
% foreach my $item (qw(A4 A3 A2 A1 B4 B3 B2 B1)) {
<option value="<% $item %>" <% ($Paper eq $item) ? 'selected' : '' %>><% loc($item) %></option>
% }
</select>
		    </td></tr>
		    <tr>
% my $Orientation = $HeadObj->att('orientation') || 'portrait';
% foreach my $item (qw(portrait landscape)) {
		    <td align=right><input
		    <% ($item eq $Orientation) && "checked" %>
		    type="radio" name="Head-orientation" value="<% $item %>"><% loc(ucfirst($item)) %></td>
% }
		    </tr>
                  </table>
                </td>
              </tr>
            </table>
          </td>
        </tr>
      </table>
    </td>
  </tr>
  <tr> 
    <td height="48" align="center">
        <input type="submit" name="Submit" value=" <&|/l&>Change</&> ">
        <input type="button" name="Cancel" onclick="window.close()" value=" <&|/l&>Cancel</&> ">
    </td>
  </tr>
</table>
</body>
</html>

<%INIT>
our $DB;
my $ReportObj = $DB->ReportObj($session{reportId});
my $ContentObj = DBIx::ReportBuilder->new(
    Handle	=> $ReportObj->HandleObj,
    SearchHook	=> $ReportObj->SearchHook,
    Content	=> $session{reportContent},
    Loc         => \&loc,
);
my $HeadObj = $ContentObj->root->first_child('head');

if ($Submit) {
    my $count = 0;
    foreach my $section ($ContentObj->Sections) {
	my $SectionObj = $ContentObj->SectionObj(++$count);
	$SectionObj->del_att('separator', 'hidden');
    }

    foreach my $key (keys %ARGS) {
	if ($key =~ /^Head-(\w+)$/) {
	    $HeadObj->set_att($1 => $ARGS{$key});
	}
	elsif ($key =~ /^Section-(\d+)-(\w+)$/) {
	    $ContentObj->SectionObj($1)->set_att($2 => $ARGS{$key});
	}
    }
    $session{reportContent} = $ContentObj->RenderXML;
    $m->print("<html><body><script><!--\nwindow.close();\n--></script></body></html>");
    return;
}
</%INIT>

<%ARGS>
$Submit	=> undef
</%ARGS>
