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

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

  my ($BID, $PID) = ($UB::QUERY{'PID'} =~ /BID_(\d+)-PID_(\d+)/);

  (
    my ($Post) = &DB::BinarySelect (
      TABLE   => "B".$BID,
      COLUMNS => [
        "ID"              ,
        "SUBJECT"         ,
        "USERNAME"        ,
        "NICKNAME"        ,
        "EMAIL"           ,
        "REPLY_NOTIFY"    ,
        "SIGNATURE"       ,
        "SYMBOL"          ,
        "IP"              ,
        "HOST"            ,
        "APROVED"         ,
        "READ_ONLY"       ,
        "ATTACHMENT"
      ],
      KEY     => $PID
    )
  ) || &HTML::Error("Internal Database Error", $DB::Error);

  &Standard::FileOpen(*POST, "r", $SYSTEM::DB_PATH."/B".$BID."/".$PID.".src");
    $Post->{'MESSAGE'} = join ("", <POST>);
  close (POST);

  my %FORM;
  $FORM{'FORM_USERNAME'}  = $Post->{'USERNAME'};
  $FORM{'FORM_NICKNAME'}  = $Post->{'NICKNAME'} || "";
  $FORM{'FORM_EMAIL'}     = $Post->{'EMAIL'}    || "";

  $FORM{'FORM_SUBJECT'}     = $UB::QUERY{'FORM_SUBJECT'}    || $Post->{'SUBJECT'} || "";
  $FORM{'FORM_MESSAGE'}     = $UB::QUERY{'FORM_MESSAGE'}    || $Post->{'MESSAGE'} || "";

  if ($Post->{'ATTACHMENT'}) {
    $FORM{'ATTACHMENT'} = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href=\"$SYSTEM::UPLOAD_URL/Post-".$BID."-".$PID."-$Post->{'ATTACHMENT'}\" target=\"PHOTO\">$Post->{'ATTACHMENT'}</a><br>";
  }

  $FORM{'FORM_ATTACHMENT_ACTION-1'} = &HTML::Radio (
    NAME    => "FORM_ATTACHMENT_ACTION",
    VALUE   => "KEEP"                  ,
    CHECKED => $UB::QUERY{'FORM_ATTACHMENT_ACTION'} || ($Post->{'ATTACHMENT'} ? "KEEP" : "") || "UPLOAD",
    EXTRA     => ($Post->{'ATTACHMENT'} ? "" : "disabled")
  );
  $FORM{'FORM_ATTACHMENT_ACTION-2'} = &HTML::Radio (
    NAME    => "FORM_ATTACHMENT_ACTION",
    VALUE   => "REMOVE"                ,
    CHECKED => $UB::QUERY{'FORM_ATTACHMENT_ACTION'} || ($Post->{'ATTACHMENT'} ? "KEEP" : "") || "UPLOAD",
    EXTRA     => ($Post->{'ATTACHMENT'} ? "" : "disabled")
  );
  $FORM{'FORM_ATTACHMENT_ACTION-3'} = &HTML::Radio (
    NAME    => "FORM_ATTACHMENT_ACTION",
    VALUE   => "UPLOAD"                ,
    CHECKED => $UB::QUERY{'FORM_ATTACHMENT_ACTION'} || ($Post->{'ATTACHMENT'} ? "KEEP" : "") || "UPLOAD"
  );

  $FORM{'FORM_IP_HOST'} = ($Post->{'IP'} || "n/a")." / ".($Post->{'HOST'} || "n/a");

  $FORM{'FORM_EMAIL_NOTIFY'}      = &HTML::Checkbox (
    NAME    => "FORM_EMAIL_NOTIFY"               ,
    VALUE   => "1"                               ,
    CHECKED => $UB::QUERY{'FORM_EMAIL_NOTIFY'} || $Post->{'REPLY_NOTIFY'}
  );
  $FORM{'FORM_SIGNATURE_INCLUDE'} = &HTML::Checkbox (
    NAME    => "FORM_SIGNATURE_INCLUDE"          ,
    VALUE   => "1"                               ,
    CHECKED => $UB::QUERY{'FORM_SIGNATURE_INCLUDE'} || $Post->{'SIGNATURE'}
  );

  if ($UB::STYLE{'MESSGAE_ICONS'}) {
    $FORM{'FORM_SYMBOL'} .= "<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\"><tr>";

    $FORM{'FORM_SYMBOL'} .= "<td width=\"20\">";
    $FORM{'FORM_SYMBOL'} .= &HTML::Radio (
      NAME    => "FORM_SYMBOL"  ,
      VALUE   => "Default"      ,
      CHECKED => $UB::QUERY{'FORM_SYMBOL'} || "Default"
    );
    $FORM{'FORM_SYMBOL'} .= "</td><td width=\"20\">";

    if ($UB::STYLE{'ICONS'}->{'Default'}) {
      my $URL = $UB::STYLE{'ICONS'}->{'Default'};
         $URL = $SYSTEM::IMAGE_URL."/".$SYSTEM::DEFAULT_THEME."/".$URL unless $URL =~ /^http:\/\//;
      $FORM{'FORM_SYMBOL'} .= "<img src=\"$URL\" border=\"0\" alt=\"Default\">";
    }
    $FORM{'FORM_SYMBOL'} .= "</td>";

    my $COUNTER = 1;
    foreach my $SYMBOL (sort keys %{ $UB::STYLE{'ICONS'} }) {
      next if $SYMBOL eq "Default";

      $FORM{'FORM_SYMBOL'} .= "</tr><tr>" if $COUNTER >= $UB::STYLE{'ICONS_PER_ROW'};

      if ($UB::STYLE{'ICONS'}->{ $SYMBOL }) {
        $FORM{'FORM_SYMBOL'} .= "<td width=\"20\">";
        $FORM{'FORM_SYMBOL'} .= &HTML::Radio (
          NAME    => "FORM_SYMBOL"  ,
          VALUE   => "$SYMBOL"      ,
          CHECKED => $UB::QUERY{'FORM_SYMBOL'} || "Default"
        );
        $FORM{'FORM_SYMBOL'} .= "</td><td width=\"20\">";

        my $URL = $UB::STYLE{'ICONS'}->{ $SYMBOL };
           $URL = $SYSTEM::IMAGE_URL."/".$SYSTEM::DEFAULT_THEME."/".$URL unless $URL =~ /^http:\/\//;
        $FORM{'FORM_SYMBOL'} .= "<img src=\"$URL\" border=\"0\" alt=\"$SYMBOL\">";
        $FORM{'FORM_SYMBOL'} .= "</td>";
      }
    }

    $FORM{'FORM_SYMBOL'} .= "<td>&nbsp;</td><td>&nbsp;</td>" x ($UB::STYLE{'ICONS_PER_ROW'} * $COUNTER + 1);

    $FORM{'FORM_SYMBOL'} .= "</tr></table>";
  }

  &Standard::PrintHTMLHeader();
  print &HTML::Header;
  print<<HTML;
<form action="$SYSTEM::CP_URL/Panel.$SYSTEM::EXT" method="post" enctype="multipart/form-data">
<input type="hidden" name="action" value="DoModifyMessage">
<input type="hidden" name="BID" value="$BID">
<input type="hidden" name="PID" value="$PID">
<input type="hidden" name="UID" value="$FORM{'FORM_USERNAME'}">
<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> / Members Accounts Management / Modify member account
    </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 modifying message.<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>
            &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>Subject <font color="Red"><b>*</b></font></td>
                      <td width="100%"><input type="text" name="FORM_SUBJECT" value="$FORM{'FORM_SUBJECT'}" size="45" maxlength="32" style="width:100%"></td>
                      <td width="20" valign="top" nowrap><img src="$SYSTEM::IMAGE_URL/help.gif" width=20 height=20 border=0 alt="subject of this message"></td>
                    </tr>
                    <tr>
                      <td width="100" valign="top" nowrap>Message Icon</td>
                      <td width="100%" valign="top">$FORM{'FORM_SYMBOL'}</td>
                      <td width="20" valign="top" nowrap><img src="$SYSTEM::IMAGE_URL/help.gif" width=20 height=20 border=0 alt="message"></td>
                    </tr>
                    <tr>
                      <td width="100" valign="top" nowrap>Message <font color="Red"><b>*</b></font></td>
                      <td width="100%" valign="top"><textarea cols=45 rows=10 name="FORM_MESSAGE" wrap="virtual" style="width=100%">$FORM{'FORM_MESSAGE'}</textarea></td>
                      <td width="20" valign="top" nowrap><img src="$SYSTEM::IMAGE_URL/help.gif" width=20 height=20 border=0 alt="message"></td>
                    </tr>
                    <tr>
                      <td width="100" valign="top" nowrap>IP/Host</td>
                      <td width="100%" colspan="2">$FORM{'FORM_IP_HOST'}</td>
                    </tr>
                    <tr>
                      <td width="100" valign="top" nowrap>Attachment</td>
                      <td width="100%">$FORM{'FORM_ATTACHMENT_ACTION-1'}Keep this attachment.<br>$FORM{'ATTACHMENT'}
                      $FORM{'FORM_ATTACHMENT_ACTION-2'}Remove this attachment.<br>$FORM{'ATTACHMENT'}
                      $FORM{'FORM_ATTACHMENT_ACTION-3'}Upload a new attachment.<br>
                      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input name="FORM_ATTACHMENT" size="30" type="file" accept="image/gif,image/jpeg,image/x-png" class="TextField"></td>
                      <td width="20" valign="top" nowrap><img src="$SYSTEM::IMAGE_URL/help.gif" width=20 height=20 border=0 alt="keep it?, remove it?, or upload a new one?"></td>
                    </tr>
                    <tr>
                      <td colspan="2">$FORM{'FORM_EMAIL_NOTIFY'}Email notification?</td>
                      <td width="20" valign="top" nowrap><img src="$SYSTEM::IMAGE_URL/help.gif" width=20 height=20 border=0 alt="email notidication?"></td>
                    </tr>
                    <tr>
                      <td colspan="2">$FORM{'FORM_SIGNATURE_INCLUDE'}Include Signature?</td>
                      <td width="20" valign="top" nowrap><img src="$SYSTEM::IMAGE_URL/help.gif" width=20 height=20 border=0 alt="include signature?"></td>
                    </tr>
                  </table>
                </td>
              </tr>
            </table>
          </td>
        </tr>
      </table>
      <table width="100%" border="0" cellspacing="0" cellpadding="5">
        <tr>
          <td align="right"><input type="submit" value="Modify it">&nbsp;&nbsp;<input type="Reset" value="Cancel"></td>
        </tr>
      </table>
    </td>
  </tr>
</table>
</form>
</body>
</html>
HTML
}


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