The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.
%# RT::Extension::MandatoryFields
%#
%# Copyright 2011 synetics GmbH, http://i-doit.org/
%#
%# This program is free software; you can redistribute it and/or modify it under
%# the same terms as Perl itself.
%#
%# Request Tracker (RT) is Copyright Best Practical Solutions, LLC.

<%INIT>
my $ARGSRef = $ARGS{'ARGSRef'};

if ((defined($$ARGSRef{'id'}) && $$ARGSRef{'id'} eq 'new')) {
    my %mandatoryFields = RT->Config->Get('MandatoryFields');

    my @supportedFields = (
        ## Message details
        'Requestors',
        'Cc',
        'Subject',
        'Content',
        'Attach',
    );

    for my $field (@supportedFields) {
        if ((exists $mandatoryFields{$field}) &&
            ( ( !(ref $mandatoryFields{$field} eq 'ARRAY') &&
                   (($mandatoryFields{$field} eq 'true') ||
                   ($mandatoryFields{$field} eq 'all')) ) ||
              (  (ref $mandatoryFields{$field} eq 'ARRAY') &&
                   (grep {$_ eq $$ARGSRef{Queue}} @{$mandatoryFields{$field}})) ) &&
            ((!$$ARGSRef{$field}) || ($$ARGSRef{$field} =~ /^[ \t]*$/))) {
            $$skip_create = 1;
            push @{$results}, loc('[_1]: mandatory field', loc($field));
        }
    }
}
</%INIT>

<%ARGS>
$skip_create => undef
$results => undef
</%ARGS>