###############################################################################
# CP_CfgStyle.src                                                             #
###############################################################################
# UltraBoard 2000 by UltraScripts.com, Inc.                                   #
# Scripts written by Jacky Wing Wa Yung, WebMaster@UltraScripts.com           #
# Available from http://www.UltraBoard.org/                                   #
# =========================================================================== #
# COPYRIGHT NOTICE :                                                          #
#                                                                             #
# Copyright (c) 1999-2000 UltraScripts.com, Inc. All Rights Reserved.         #
#                                                                             #
# This program is being distributed as shareware. It may be used and modified #
# free for personal, government or non-profit. Any commercial use must be     #
# registered. However, modified versions cannot be sold or distributed. You   #
# cannot alter the copyright and "powered by" notices throughout the scripts. #
# These notices must be clearly visible to the end users.                     #
#                                                                             #
# WARRANTY DISCLAIMER:                                                        #
#                                                                             #
# THIS PROGRAM IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL, BUT WITHOUT #
# ANY WARRANTY; WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR       #
# FITNESS FOR A PARTICULAR PURPOSE.                                           #
###############################################################################

package Source;

&Standard::Require("Cfg.lib", "$UB::LIBRARIES_PATH/Cfg.lib");

sub CfgStyle {
  my ($ERROR) = @_;

  &Standard::PrintHTMLHeader();
  print &HTML::Header;
  print<<HTML;
<form action="$SYSTEM::CP_URL/Panel.$SYSTEM::EXT" method="post" name="form">
<input type="hidden" name="action" value="DoCfgStyle">
<table width="100%" border="0" cellspacing="0" cellpadding="5">
  <tr bgcolor="Gray">
    <td><font color="White"><b>
      <a href="$SYSTEM::CP_URL/Panel.$SYSTEM::EXT?action=body" target="UBBODY" class="address">Control Panel</a> / General Management / Configure style options
    </b></font></td>
  </tr>
</table>
<table width="100%" border="0" cellspacing="0" cellpadding="3">
  <tr>
    <td>
      <table width="100%" border="0" cellspacing="0" cellpadding="2">
        <tr>
          <td>
            <table width="100%" border="1" cellspacing="0" cellpadding="3" bordercolordark="White" bordercolorlight="Gray">
              <tr>
                <td>
                  <table width="100%" border="0" cellspacing="0" cellpadding="2">
                    <tr>
                      <td>
HTML

  if ($ERROR ne "") {
    print<<HTML;
                        There were the following errors during updating system options.<br>
                        <table width="100%" border="0" cellspacing="2" cellpadding="2">
                          <tr>
                            <td><font color="#FF0000">$ERROR</font></td>
                          </tr>
                        </table>
                        Please make any changes and try again!<br>
HTML
  }

print<<HTML;
                      Please fill out all required (<font color="Red"><b>*</b></font>) fields.
                      </td>
                    </tr>
                  </table>
                </td>
              </tr>
            </table>

HTML

  &Standard::Require("ControlPanel.cfg", "$SYSTEM::THEME_PATH/$SYSTEM::DEFAULT_THEME/Style/ControlPanel.cfg");

  for (my $c = 0; $c <= $#UB::CONTROL_PANEL; $c++) {
    my $Category = $UB::CONTROL_PANEL[$c];

    print<<HTML;
&nbsp;<br>
&nbsp;&nbsp;$Category->{'TITLE'}
<table width="100%" border="1" cellspacing="0" cellpadding="3" bordercolordark="White" bordercolorlight="Gray">
 <tr>
  <td>
   <table width="100%" border="0" cellspacing="0" cellpadding="2">
HTML

    for (my $o = 0; $o <= $#{ $Category->{'OPTIONS'} }; $o++) {
      my $Option = $Category->{'OPTIONS'}[$o];

      if ($Option->{'FORM'}{'TYPE'} eq "TEXTFIELD") {
        if (ref ( $UB::STYLE{ $Option->{'FORM'}{'NAME'} } ) eq "HASH") {
          my @Params = $UB::CGI->param( $Option->{'FORM'}{'VALUE'} );

          my $Counter = 0;
          foreach my $KEY (sort keys %{ $UB::STYLE{ $Option->{'FORM'}{'NAME'} } }) {
            $KEY =~ s/\"/\\\"/g;
            print &TextField (
              TITLE       => $Option->{'TITLE'}." <font face=\"Courier New\">$KEY</font>",
              DESCRIPTION => $Option->{'DESCRIPTION'},
              NAME        => $Option->{'FORM'}{'NAME'}." $KEY",
              VALUE       => (defined $Params[$Counter]) ? $Params[$Counter] : $UB::STYLE{ $Option->{'FORM'}{'VALUE'} }->{ $KEY },
              REQUIRED    => "$Option->{'FORM'}{'REQUIRED'}" || 0,

              MAXLENGTH   => "$Option->{'FORM'}{'MAXLENGTH'}",
              SIZE        => $Option->{'FORM'}{'SIZE'} || "30"
            );
            $Counter++;
          }
        } else {
          my $Param = $UB::QUERY{ $Option->{'FORM'}{'VALUE'} } || $UB::STYLE{ $Option->{'FORM'}{'VALUE'} };
             $Param =~ s/\"/\\\"/g;
          print &TextField (
            TITLE       => $Option->{'TITLE'},
            DESCRIPTION => $Option->{'DESCRIPTION'},
            NAME        => $Option->{'FORM'}{'NAME'},
            VALUE       => $Param,
            REQUIRED    => "$Option->{'FORM'}{'REQUIRED'}" || 0,

            MAXLENGTH   => "$Option->{'FORM'}{'MAXLENGTH'}",
            SIZE        => $Option->{'FORM'}{'SIZE'} || "30"
          );
        }
      } elsif ($Option->{'FORM'}{'TYPE'} eq "RADIO") {
        my $Param = $UB::QUERY{ $Option->{'FORM'}{'SELECT'} } || $UB::STYLE{ $Option->{'FORM'}{'SELECT'} };
           $Param =~ s/\"/\\\"/g;
        print &Radio (
          TITLE       => $Option->{'TITLE'},
          DESCRIPTION => $Option->{'DESCRIPTION'},
          NAME        => $Option->{'FORM'}{'NAME'},
          VALUE       => $Option->{'FORM'}{'VALUE'},
          WRAP        => "$Option->{'FORM'}{'WRAP'}" || 0,
          SELECT      => "$Param",
          REQUIRED    => "$Option->{'FORM'}{'REQUIRED'}" || 0
        );
      } elsif ($Option->{'FORM'}{'TYPE'} eq "TEXTAREA") {
        my $Param = $UB::QUERY{ $Option->{'FORM'}{'VALUE'} } || $UB::STYLE{ $Option->{'FORM'}{'VALUE'} };
           $Param =~ s/\"/\\\"/g;
        print &TextArea (
          TITLE       => $Option->{'TITLE'},
          DESCRIPTION => $Option->{'DESCRIPTION'},
          NAME        => $Option->{'FORM'}{'NAME'},
          VALUE       => "$Param",
          REQUIRED    => "$Option->{'FORM'}{'REQUIRED'}" || 0,

          COLS        => $Option->{'FORM'}{'COLS'} || 30,
          ROWS        => $Option->{'FORM'}{'ROWS'} || 3
        );
      } elsif ($Option->{'FORM'}{'TYPE'} eq "CHECKBOX") {
        my $Param = $UB::QUERY{ $Option->{'FORM'}{'VALUE'} } || $UB::STYLE{ $Option->{'FORM'}{'VALUE'} };
           $Param =~ s/\"/\\\"/g;
        print &CheckBox (
          TITLE       => $Option->{'TITLE'},
          DESCRIPTION => $Option->{'DESCRIPTION'},
          NAME        => $Option->{'FORM'}{'NAME'},
          VALUE       => "$Param",
          REQUIRED    => "$Option->{'FORM'}{'REQUIRED'}" || 0
        );
      } elsif ($Option->{'FORM'}{'TYPE'} eq "SELECT") {
        my $Param = $UB::QUERY{ $Option->{'FORM'}{'SELECT'} } || $UB::STYLE{ $Option->{'FORM'}{'SELECT'} };
           $Param =~ s/\"/\\\"/g;
        print &Select (
          TITLE       => $Option->{'TITLE'},
          DESCRIPTION => $Option->{'DESCRIPTION'},
          NAME        => $Option->{'FORM'}{'NAME'},
          VALUE       => $Option->{'FORM'}{'VALUE'},
          SELECT      => "$Param",
          REQUIRED    => "$Option->{'FORM'}{'REQUIRED'}" || 0,

          SIZE        => $Option->{'FORM'}{'SIZE'},
          MULTIPLE    => $Option->{'FORM'}{'MULTIPLE'}
        );
      }
    }

    print<<HTML;
   </table>
  </td>
 </tr>
</table>
HTML
  }

print<<HTML;
          </td>
        </tr>
      </table>
      <table width="100%" border="0" cellspacing="0" cellpadding="5">
        <tr>
          <td align="right"><input type="submit" value="Update it">&nbsp;&nbsp;<input type="Reset" value="Cancel"></td>
        </tr>
      </table>
    </td>
  </tr>
</table>
</form>
</body>
</html>
HTML
}

###############################################################################
1; # end of CP_CfgStyle.src file
###############################################################################