package WebGUI::Macro::GroupTextUp;

#-------------------------------------------------------------------
# GroupIdTextUp macro is Copyright 2009 by Jaroslaw Danielski
#              TELVINET http://www.webgui.pl
#-------------------------------------------------------------------
# This software is distributed under the same license as WebGUI, the
# GPL.  Please refer to (docs/license.txt) that came with WebGUI
# before using this software.
#-------------------------------------------------------------------
# 						     jd@telvinet.pl
#-------------------------------------------------------------------

#-------------------------------------------------------------------
# WebGUI is Copyright 2001-2009 Plain Black Corporation.
#-------------------------------------------------------------------
# Please read the legal notices (docs/legal.txt) and the license
# (docs/license.txt) that came with this distribution before using
# this software.
#-------------------------------------------------------------------
# http://www.plainblack.com                     info@plainblack.com
#-------------------------------------------------------------------

use strict;


=head1 NAME

Package WebGUI::Macro::GroupTextUp

=head1 DESCRIPTION

Macro for displaying a text message to user's in a certain group. 
Macro reads each params pair and trying to conform if user belong to this group.
If belongs member text will be shown and macro stops confirmation.

=head2 process ( groupName, member [, groupName, member ] ... )

Marco requires one pair (groupName, member) at least. You can write many pairs.

=head3 groupName

The name of the group whose members will be shown the message.

=head3 member

The text to be displayed to someone in the group.

=cut


#-------------------------------------------------------------------
sub process {
    my $session = shift;
    my @params = @_;
	
    while (my $groupName = shift @params) {
	my $member = shift @params;
	my ($groupId) = $session->dbSlave->quickArray("select groupId from groups where groupName=?",[$groupName]);
	if ($groupId eq "") {
	    my $i18n = WebGUI::International->new($session, 'Macro_GroupText');
	    return sprintf $i18n->get('group not found'), $groupName
	}
	return ($member) if $session->user->isInGroup($groupId);
    }
    return ("");	
}

1;

