###############################################################################
# CP_ListAccounts.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 ListAccounts {

  my ($Action, $Address, $Description, $Script, $Form, $Submit);
  if ($UB::QUERY{'FORM_ACTION'} eq "DeActivateAccounts") {
    $Action      = "DoDeActivateAccounts";
    $Address     = "Activated/Deactivate members accounts";
    $Description = "Please select which members accounts that you want to de/activated them.";
    $Script      = "<SCRIPT LANGUAGE=\"JavaScript\"> function Confirm () { return confirm(\"Are you sure to de/activate these members accounts?\"); } </SCRIPT>";
    $Form        = " onSubmit = \"return Confirm();\"";
    $Submit      = "De/Activate";
  } elsif ($UB::QUERY{'FORM_ACTION'} eq "EmailAccounts") {
    $Action      = "EmailAccounts";
    $Address     = "Email member(s)";
    $Description = "Please select which members that you want to email to.";
    $Script      = "";
    $Form        = "";
    $Submit      = "Next &gt;";
  } elsif ($UB::QUERY{'FORM_ACTION'} eq "ModifyAccount") {
    $Action      = "ModifyAccount";
    $Address     = "Modify member account";
    $Description = "Please choose which member account that you want to modify.";
    $Script      = "";
    $Form        = "";
    $Submit      = "Next &gt;";
  } elsif ($UB::QUERY{'FORM_ACTION'} eq "MoveAccounts") {
    $Action      = "MoveAccounts";
    $Address     = "Move member(s) account";
    $Description = "Please select which members account that you want to move.";
    $Script      = "";
    $Form        = "";
    $Submit      = "Next &gt;";
  } elsif ($UB::QUERY{'FORM_ACTION'} eq "RemoveAccounts") {
    $Action      = "DoRemoveAccounts";
    $Address     = "Remove member(s) accounts";
    $Description = "Please select which members accounts that you want to remove.";
    $Script      = "<SCRIPT LANGUAGE=\"JavaScript\"> function Confirm () { return confirm(\"Are you sure to remove these members accounts?\"); } </SCRIPT>";
    $Form        = " onSubmit = \"return Confirm();\"";
    $Submit      = "Remove";
  }

  my $time = time;

  my $LAST_POST_SECOND;
  if (($UB::QUERY{'FORM_LAST_POST_DAYS'} ne "*") && ($UB::QUERY{'FORM_LAST_POST_DAYS'} ne "NA")) {
    if ($UB::QUERY{'FORM_LAST_POST_BOOLEAN'} eq "GT") {
      $LAST_POST_SECOND = ">";
    } else {
      $LAST_POST_SECOND = "<";
    }
    $LAST_POST_SECOND .= $time - ($UB::QUERY{'FORM_LAST_POST_DAYS'} * 60 * 60 * 24);
  } else {
    if ($UB::QUERY{'FORM_LAST_POST_DAYS'} eq "*") {
      $LAST_POST_SECOND = "*";
    } else {
      $LAST_POST_SECOND = "";
    }
  }

  my $TOTAL_POSTS;
  if (($UB::QUERY{'FORM_TOTAL_POST_NUMBER'} ne "*") && ($UB::QUERY{'FORM_TOTAL_POST_NUMBER'} ne "NA")) {
    if ($UB::QUERY{'FORM_TOTAL_POST_BOOLEAN'} eq "GT") {
      $TOTAL_POSTS = ">";
    } else {
      $TOTAL_POSTS = "<";
    }
    $TOTAL_POSTS .= $UB::QUERY{'FORM_TOTAL_POST_NUMBER'};
  } else {
    if ($UB::QUERY{'FORM_TOTAL_POST_NUMBER'} eq "*") {
      $TOTAL_POSTS = "*";
    } else {
      $TOTAL_POSTS = "";
    }
  }

  my ($Accounts) = &DB::Query (
    TABLE   => "Accounts",
    WHERE   => {
      USERNAME => [($UB::QUERY{'FORM_USERNAME'}) ? "=~".$UB::QUERY{'FORM_USERNAME'} : "*"],
      NICKNAME => [($UB::QUERY{'FORM_NICKNAME'}) ? "=~".$UB::QUERY{'FORM_NICKNAME'} : "*"],

      LEVEL   => [$UB::QUERY{'FORM_LEVEL'}, "<$UB::MEMBER{'LEVEL'}"],
      GROUP   => [$UB::QUERY{'FORM_GROUP'}],
      STATUS  => [$UB::QUERY{'FORM_STATUS'}],

      LAST_POST_SECOND => [$LAST_POST_SECOND],
      TOTAL_POSTS      => [$TOTAL_POSTS]
    },
    MATCH   => "ALL",
    SORT    => $UB::QUERY{'FORM_SORT_FIELD'} || "",
    BY      => $UB::QUERY{'FORM_SORT_ORDER'} || "",
  );

  my %Level = (
    30 => $GENERAL::MEMBER_LEVEL_30,
    50 => $GENERAL::MEMBER_LEVEL_50,
    70 => $GENERAL::MEMBER_LEVEL_70,
  );

  my %Status = (
    30 => "Deactivated",
    50 => "Activated"  ,
  );

  &Standard::PrintHTMLHeader();
  print &HTML::Header;
  print<<HTML;
$Script
<form action="$SYSTEM::CP_URL/Panel.$SYSTEM::EXT" method="post" name="form"$Form>
<input type="hidden" name="action" value="$Action">
<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 /  $Address
    </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>
                      $Description
                      </td>
                    </tr>
                  </table>
                </td>
              </tr>
            </table>
            &nbsp;<br>
            <table width="100%" border="1" cellspacing="0" cellpadding="2" bordercolordark="White" bordercolorlight="Gray">
              <tr height=24>
                <td width="20" nowrap>&nbsp;</td>
                <td nowrap>&nbsp;Username&nbsp;</td>
                <td nowrap>&nbsp;Nickname&nbsp;</td>
                <td nowrap>&nbsp;Status&nbsp;</td>
                <td nowrap>&nbsp;Level&nbsp;</td>
                <td nowrap>&nbsp;Group&nbsp;</td>
                <td nowrap>&nbsp;Total post&nbsp;</td>
                <td nowrap>&nbsp;Registered Date&nbsp;</td>
                <td nowrap>&nbsp;Last post&nbsp;</td>
                <td nowrap>&nbsp;Last login&nbsp;</td>
              </tr>
HTML
  for (my $i = 0; $i <= $#{$Accounts}; $i++) {
    my $Account = $Accounts->[$i];
    my $Form;
    if ($UB::QUERY{'FORM_ACTION'} eq "ModifyAccount") {
      $Form = &HTML::Radio (
        NAME    => "UID",
        VALUE   => $Account->{'USERNAME'}
      );
    } elsif (($UB::QUERY{'FORM_ACTION'} eq "DeActivateAccounts") || ($UB::QUERY{'FORM_ACTION'} eq "EmailAccounts") || ($UB::QUERY{'FORM_ACTION'} eq "MoveAccounts") || ($UB::QUERY{'FORM_ACTION'} eq "RemoveAccounts")) {
      $Form = &HTML::Checkbox (
        NAME    => "UID",
        VALUE   => $Account->{'USERNAME'}
      );
    }
    print<<HTML;
              <tr bgcolor="White">
                <td bgcolor="Silver" nowrap>$Form</td>
                <td>&nbsp;<a href="$SYSTEM::UB_URL/UltraBoard.$SYSTEM::EXT?action=Profile&UID=$Account->{'USERNAME'}" target="PROFILE">$Account->{'USERNAME'}</a>&nbsp;</td>
                <td>&nbsp;$Account->{'NICKNAME'}&nbsp;</td>
                <td>&nbsp;$Status{$Account->{'STATUS'}}&nbsp;</td>
                <td align="center">&nbsp;$Account->{'LEVEL'}&nbsp;</td>
                <td>&nbsp;$Account->{'GROUP_TEXT'}&nbsp;</td>
                <td align="center" nowrap>&nbsp;$Account->{'TOTAL_POSTS'}&nbsp;</td>
                <td nowrap>&nbsp;$Account->{'REGISTERED_DATE'}&nbsp;</td>
                <td nowrap>&nbsp;${ \(($Account->{'LAST_POST_DATE'}) ? $Account->{'LAST_POST_DATE'}." ".$Account->{'LAST_POST_TIME'} : "n/a") }&nbsp;</td>
                <td nowrap>&nbsp;${ \(($Account->{'LAST_LOGIN_DATE'}) ? $Account->{'LAST_LOGIN_DATE'}." ".$Account->{'LAST_LOGIN_TIME'} : "n/a") }&nbsp;</td>
              </tr>
HTML
  }
print<<HTML;
            </table>
          </td>
        </tr>
      </table>
      <table width="100%" border="0" cellspacing="0" cellpadding="5">
        <tr>
          <td align="right"><input type="submit" value="$Submit">&nbsp;&nbsp;<input type="Reset" value="Cancel"></td>
        </tr>
      </table>
    </td>
  </tr>
</table>
</form>
</body>
</html>
HTML
}

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