###############################################################################
# CP_DoModifyGroup.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;

use strict;

sub DoModifyGroup {

# =========================================================================== #
# Verify Variables

  # checking missing fields
  if ($UB::QUERY{'FORM_TITLE'} eq "") { &Error("You forgot to fill the \"Title\" field.") };

  # checking length of fields
  if (length($UB::QUERY{'FORM_TITLE'}) > 128) {
    &Error("The \"Title\" field cannot more than 128 characters.");
  }

  if (length($UB::QUERY{'FORM_DESCRIPTION'}) > 256) {
    &Error("The \"Description\" field cannot more than 256 characters.");
  }

# =========================================================================== #
# Assign Variables
  my %FORM;

  $FORM{'TITLE'}       = $UB::QUERY{'FORM_TITLE'};
  $FORM{'TITLE'}       = &Standard::EncodeHTML($FORM{'TITLE'});

  $FORM{'DESCRIPTION'} = $UB::QUERY{'FORM_DESCRIPTION'};
  $FORM{'DESCRIPTION'} = &Standard::EncodeHTML($FORM{'DESCRIPTION'});

  if (
    ($UB::QUERY{'FORM_FILE_ATTACH'} eq "1"  ) ||
    ($UB::QUERY{'FORM_FILE_ATTACH'} eq "on" ) ||
    ($UB::QUERY{'FORM_FILE_ATTACH'} eq "y"  ) ||
    ($UB::QUERY{'FORM_FILE_ATTACH'} eq "yes")
  ) {
    if ($UB::QUERY{'FORM_MAX_FILE_SIZE'} > 1) {
      $FORM{'MAX_FILE_SIZE'} = $UB::QUERY{'FORM_MAX_FILE_SIZE'};
    }
  }

  ($FORM{'TITLE'}, $FORM{'DESCRIPTION'}) = &Standard::WordFilter($FORM{'TITLE'}, $FORM{'DESCRIPTION'});

# =========================================================================== #
# Update Group from Database

  (
    &DB::Update (
      TABLE  => "Groups",
      VALUES => {
        TITLE         => $FORM{'TITLE'}         || "",
        DESCRIPTION   => $FORM{'DESCRIPTION'}   || "",
        MAX_FILE_SIZE => $FORM{'MAX_FILE_SIZE'} || ""
      },
      KEY    => $UB::QUERY{'GID'}
    )
  ) || &HTML::Error("Internal Database Error", $DB::Error);

  &Success(\%FORM);
}

###############################################################################
# Error function
# - function of printing error message of modifying member group
sub Error {
  my ($message) = @_;

  require "$UB::SOURCES_PATH/CP_ModifyGroup.src";
  &Source::ModifyGroup($message);

  exit;
}

###############################################################################
# Success function
# - function of printing success message of modifying member group
sub Success {
  my ($FORM) = @_;

  &Standard::PrintHTMLHeader();
  print &HTML::Header;
  print<<HTML;
<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> / Member Group Management /  Modify member group
    </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>The member group has been modified, following is the information of this group.</td>
                    </tr>
                  </table>
                </td>
              </tr>
            </table>
            &nbsp;<br>
            &nbsp;&nbsp;General Information
            <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 width="100" valign="top" nowrap>Title</td>
                      <td width="100%">$FORM->{'TITLE'}</td>
                    </tr>
                    <tr>
                      <td width="100" valign="top" nowrap>Description</td>
                      <td width="100%">$FORM->{'DESCRIPTION'}</td>
                    </tr>
                  </table>
                </td>
              </tr>
            </table>
          </td>
        </tr>
      </table>
    </td>
  </tr>
</table>
</body>
</html>
HTML

  exit;
}

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