# # #
use Compress::Zlib;
use Date::Format qw(time2str);
use Cmates::Config qw( %CONFIG );
use Cmates::Sales qw( %S );
use Cmates::Group;
use Cmates::Circle;
use Cmates::MessageBoard::Topic;
use Cmates::MessageBoard::Thread;
use Cmates::Group::Permission;
use Cmates::MessageBoard;
use Cmates::Group qw(:org_types :sub_types);
use Data::Dumper;

use strict;

my $is_compressed = 0;
#if ($ENV{HTTP_ACCEPT_ENCODING} =~ /gzip/) {
#  $is_compressed = 1;
#  $forge->header( Content_encoding => "gzip" );
#  $forge->buffer( 1 );
#}

my($cgi, $scribe) = @_;

my $group_id = $cgi->param('group_id') or die "no group_id";
my $community_type = $cgi->param('type');

my $group = Cmates::Group::fetch($group_id) or die "group_id: $group_id does not exist";

my $circle = Cmates::Circle::fetch($group->{'org_id'});

my $expires = $scribe->{expires};

my $tab_type;

my $org_type = $group->{org_type};
my $sub_type = $group->{sub_type};

if ( $org_type eq 'S') {
  if($sub_type == 1) {
    $tab_type = 'school';
  } else {
    $tab_type = 'college';
  }
} elsif ($org_type eq 'W') {
  $tab_type = 'work';

} elsif ($org_type eq 'U') {
  $tab_type = 'military';
} elsif ($org_type eq 'C') {

  if($sub_type == 1) {
    $tab_type = 'reunion';
  } elsif($sub_type == 2) {
    $tab_type = 'interestgroup';
  } elsif($sub_type == 3) {
    $tab_type = 'privategroup';
  } elsif($sub_type == 4) {
    $tab_type = 'privategroup';
  }
}

return $forge->redirect("$CONFIG{URL_HOME}/cmo/mboard/mboardredirect.jsp?communityID=$group->{org_id}&tabType=$tab_type");



my $top_topics = Cmates::MessageBoard::top_topics($group_id, $scribe->{registration_id}, $scribe->{su});

my $site = 'groups';

# They want to sell ads based on specific interest groups, so we want to
# change the campaign value to reflect those when they come up.

my $campaign;
my %groupCampaigns = (
  'Military Memories' => {
    '_default' => 'Groups/Military',
  },
  'Military Discussions' => {
    '_default' => 'Groups/Military',
  },
  'School Days' => {
    '_default' => 'Groups/School',
  },
  'Timely Topics' => {
    '_default' => 'Groups/Timely',
  },
  'Arts & Entertainment' => {
    '_default' => 'Groups/ArtsEntertainment',
    'TV/Radio' => 'Groups/ArtsEntertainment/TVRadio',
    'Music' => 'Groups/ArtsEntertainment/Music',
    'Celebrities' => 'Groups/ArtsEntertainment/Celebrities',
    'Movies' => 'Groups/ArtsEntertainment/Movies',
    'Books' => 'Groups/ArtsEntertainment/Books',
  },
  'College Days' => {
    '_default' => 'Groups/College',
    'Sports' => 'Groups/College/Sports',
  },
  'Family Life' => {
    '_default' => 'Groups/FamilyLife',
    'Parenting' => 'Groups/FamilyLife/Parenting',
    'Pets' => 'Groups/FamilyLife/Pets',
  },
  'Hobbies & Leisure' => {
    '_default' => 'Groups/HobbiesLeisure',
    'Science & Nature' => 'Groups/HobbiesLeisure/ScienceNature',
    'Beer & Wine' => 'Groups/HobbiesLeisure/BeerWine',
    'Automotive' => 'Groups/HobbiesLeisure/Automobiles',
    'Travel' => 'Groups/HobbiesLeisure/Travel',
    'Cooking' => 'Groups/HobbiesLeisure/Cooking',
    'Gardening' => 'Groups/HobbiesLeisure/Gardening',
    'House and Home Improvement' => 'Groups/HobbiesLeisure/HomeImprovement',
    'Photography' => 'Groups/HobbiesLeisure/Photography',
    'Health and Wellness' => 'Groups/HobbiesLeisure/HealthWellness',
    'Computing' => 'Groups/HobbiesLeisure/Computing',
    'Personal Finance' => 'Groups/HobbiesLeisure/PersonalFinance',
    'Holiday Fun' => 'Groups/HobbiesLeisure/Holidays',
    'Relationships' => 'Groups/HobbiesLeisure/Relationships',
  },
  'In the Workplace' => {
    '_default' => 'Groups/Workplace',
    'Job Search' => 'Groups/Workplace/Jobsearch',
    'Professional Development' => 'Groups/Workplace/ProfDev',
  },
  'Sports' => {
    '_default' => 'Groups/Sports',
    'Baseball' => 'Groups/Sports/Baseball',
    'Football' => 'Groups/Sports/Football',
    'Basketball' => 'Groups/Sports/Basketball',
    'Golf' => 'Groups/Sports/Golf',
  },
  'Travel' => {
    '_default' => 'Groups/Travel',
    'International Travel' => 'Groups/Travel/International',
    'Cruises' => 'Groups/Travel/Cruises',
  },
);


if ($groupCampaigns{$circle->{circle_category}}->{$circle->{name}}) {
  $campaign = $groupCampaigns{$circle->{circle_category}}->{$circle->{name}};
} else {
  $campaign = $groupCampaigns{$circle->{circle_category}}->{_default};
}
$campaign ||= 'messageboard';



my $can_create = Cmates::Group::Permission->can_create($group);
my $hostonly_topic_id;
my $hostonly_thread_id;

if( $scribe->{su} ){
  $hostonly_topic_id = Cmates::MessageBoard::hostonly_topic_id($group->{group_id});

  $hostonly_thread_id = 
    Cmates::MessageBoard::hostonly_moved_thread_id($group->{group_id});
}

my $encoded_group = $forge->encode_entities($group->{name});

# Set S numbers depending on site we're in
my %GROUP_S_MAP = (
      CIRCLES() => {
        REUNION() => {
           start_new_link => '',
        },
        INTEREST_GROUP() => {
           start_new_link => '12515',
        },
        PRIVATE_GROUP_AUTO() => {
           start_new_link => '',
        },
        PRIVATE_GROUP() => {
           start_new_link => '',
        },
      }, 
      SCHOOLS() => {
         K_12() => {
           start_new_link => '12358',
         },
         COLLEGE() => {
           start_new_link => '12360',
         },
      },
     WORK() => {
	 start_new_link => '12362',
     },
     MILITARY() => {
	 start_new_link => '12364',
     },
     GENERAL() => {
	 start_new_link => '',
     }
);
my $s_group = $GROUP_S_MAP{$group->{org_type}}{$group->{sub_type}} || $GROUP_S_MAP{$group->{org_type}};
my $s_number = $s_group->{start_new_link};

# 
<% $forge->include('page_start', title => "$encoded_group Group Message Board") %> <% $forge->include('header', $scribe, campaign => $campaign) %> <% $forge->include('primary_nav', $scribe) %> <% $forge->include('body_start') %> <% $forge->include('content_start', $scribe, campaign => $campaign) %> <% my $designtheme = "school"; my $primarycolor = "2d8000"; my $secondarycolor = "97ca00"; my $homelink = "2d8000"; my $listlink = "2d8000"; my $mboardlink = "2d8000"; my $palbumlink = "2d8000"; if ($community_type eq "hs") { } elsif ($community_type eq "col") { $designtheme = "college"; $primarycolor = "840010"; $secondarycolor = "d0bc57"; } elsif ($community_type eq "wk") { $designtheme = "work"; $primarycolor = "336699"; $secondarycolor = "8fabc7"; } elsif ($community_type eq "mil") { $designtheme = "military"; $primarycolor = "808845"; $secondarycolor = "a0a674"; } else { $designtheme = "group"; $primarycolor = "6637a5"; $secondarycolor = "cab3ea"; } if (($community_type) && ($group->{org_type} eq "C")) { $designtheme = "reunion"; $primarycolor = "504c65"; $secondarycolor = "c2c2d2"; } %> <% $forge->include('navheader_start', group => $group, communitytype => $community_type, headingname => $encoded_group, highlight => 'mb') %>
<% $forge->include('title',"My $encoded_group Group") %> <% $forge->include('flat_nav', params => $group, page => 'messageboard') %>
$encoded_group Message Board

<% if (!$scribe->{member}) { %> Put faces to these names. See member photos and more when you upgrade to Gold membership. As low as $2.46/month.
<% } %> <% if ($can_create) { %> add a folder

<% } %>
<% my $last_thread_topic = {}; foreach my $thread_topic (@$top_topics) { if( $last_thread_topic->{topic_id} != $thread_topic->{topic_id} ){ if($last_thread_topic->{topic_id}){ %> <% } %> <% } $last_thread_topic = $thread_topic; next unless defined $thread_topic->{thread_id}; $thread_topic->{modified_date} = time2str("%h %e %Y", $thread_topic->{timestamp}); $thread_topic->{subject} = Cmates::MessageBoard::Message::filter($group, $thread_topic->{subject}); my $next_message_number = $thread_topic->{message_number} + 1; %> <% my $nick = $thread_topic->{nickname}; my $year; if( $nick =~ m/^(.*)\s*(\d{4})$/ ) { $nick = $1; $year = $2; } my $yearlink; if( $year && $group->{'org_type'} eq 'S' ) { if($community_type eq 'col') { $yearlink = "{'org_id'}&yearRangeType=0&startYear=$year&endYear=$year\">$year"; } else { $yearlink = "{'org_id'}&yearRangeType=0&startYear=$year&endYear=$year\">$year"; } } %> <% } %> <% if($last_thread_topic){ %> <% } %>

View all $last_thread_topic->{visible_threads} discussions | Start a new discussion | Mark all discussions as read
{topic_visible} ? '' : 'style="font-style: italic"') %> >$thread_topic->{name} $thread_topic->{visible_threads} Discussions New  All

$thread_topic->{subject} <% if($thread_topic->{new}){ %> Mark all messages as read <% } %> <% if( $thread_topic->{topic_id} == $hostonly_topic_id ) { if($thread_topic->{old_topic_id}){ %> Restore Discussion <% } %> <% } elsif($scribe->{su}) { %> Move Discussion to Admin <% } %>

Started By: $nick <% print $yearlink ? "$yearlink " : ''; %> $thread_topic->{modified_date} $thread_topic->{new} $thread_topic->{visible_messages}

  View all $last_thread_topic->{visible_threads} discussions | Start a new discussion | Mark all discussions as read


<% $forge->include('ads/adblock', campaign => $campaign) %> <% $forge->include('segment/right_col/mboards', $scribe) %>
<% $forge->include('navheader_end', group => $group, communitytype => $community_type, headingname => $encoded_group) %> <% $forge->include('ads/bottomright', campaign => $campaign) %> <% $forge->include('footer', campaign => $campaign) %> <% $forge->include('content_end') %> <% $forge->include('body_end') %> <% $forge->include('page_end') %>
if ($is_compressed) { @{ $forge->{_tie_obj} } = Compress::Zlib::memGzip( join '', @{ $forge->{_tie_obj} } ); } # #