1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284
|
%# BEGIN LICENSE BLOCK
%#
%# Copyright (c) 2002-2003 Jesse Vincent <jesse@bestpractical.com>
%#
%# This program is free software; you can redistribute it and/or modify
%# it under the terms of version 2 of the GNU General Public License
%# as published by the Free Software Foundation.
%#
%# A copy of that license should have arrived with this
%# software, but in any event can be snarfed from www.gnu.org.
%#
%# 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. See the
%# GNU General Public License for more details.
%#
%# END LICENSE BLOCK
% if ($id && $id ne 'new') {
<& /RTFM/Article/Elements/Tabs,
Article => $ArticleObj,
current_subtab => "RTFM/Article/Edit.html?id=".$ArticleObj->Id ,
id => $id,
Title => $title &>
% } else {
<& /RTFM/Article/Elements/Tabs,
current_tab => "RTFM/Article/PreCreate.html",
Title => loc('Create a new article') &>
% }
<& /Elements/ListActions, actions => \@results &>
<FORM METHOD=POST ACTION="Edit.html">
<INPUT TYPE=HIDDEN NAME="id" VALUE="<%$id%>">
<& Elements/EditBasics, ArticleObj => $ArticleObj,
EditClass =>$EditClass,
ClassObj =>$ClassObj,
id => $id,
%ARGS &>
<& Elements/EditCustomFields, ArticleObj => $ArticleObj,
CFContent => \%CFContent,
ClassObj => $ClassObj,
id =>$id,
%ARGS &>
<& Elements/EditLinks, ArticleObj => $ArticleObj,
id => $id,
%ARGS &>
<& /Elements/Submit, Label => loc('Save Changes'),
Caption => loc("If you've updated anything above, be sure to"),
color => "#993333" &>
</form>
<%INIT>
my @results;
my $title;
my $Entries = {};
my $ArticleObj = RT::FM::Article->new( $session{'CurrentUser'} );
my $ClassObj = RT::FM::Class->new($session{'CurrentUser'});
my %create_args;
my %CFContent;
my $EditClass = 1;
if ( !$id ) {
$title = loc('Create a new article');
foreach my $arg ( sort keys %ARGS ) {
if ( $arg =~ /^Transaction-(\d+)$/ ) {
my $trans = RT::Transaction->new( $session{'CurrentUser'} );
$trans->Load($1);
$CFContent{ $ARGS{$arg} } .= $trans->Content;
}
}
$ClassObj->Load($Class);
unless ( $ClassObj->Id ) {
$m->comp( "/RTFM/Elements/Error", Why => loc("'[_1]' isn't a valid class identifier", $Class));
}
$EditClass = 0;
$id = 'new';
}
elsif ( $id eq 'new' ) {
if ( $ARGS{'RefersTo-new'} ) {
@{ $create_args{'RefersTo-new'} } =
split ( /\s+/, $ARGS{'RefersTo-new'} );
}
if ( $ARGS{'new-RefersTo'} ) {
@{ $create_args{'new-RefersTo'} } =
split ( /\s+/, $ARGS{'new-RefersTo'} );
}
foreach my $arg ( keys %ARGS ) {
if ( $arg =~ /^Article-new-CustomField-(\d+)-/ ) {
$create_args{'CustomField-'.$1} = $ARGS{$arg};
}
}
my $msg;
( $id, $msg ) = $ArticleObj->Create( Summary => $ARGS{'Summary'},
Name => $ARGS{'Name'},
Class => $ARGS{'Class'},
%create_args );
push ( @results, $msg );
if ($id ) {
$title = loc( 'Modify article #[_1]', $ArticleObj->Id );
}
else {
$ClassObj->Load($Class);
unless ( $ClassObj->Id ) {
$m->comp( "/RTFM/Elements/Error", Why => loc("'[_1]' isn't a valid class identifier", $Class));
}
$id = 'new';
$EditClass = 0;
$title = loc('Create a new article');
}
} else {
$ArticleObj->Load($id);
unless ( $ArticleObj->id ) {
$m->comp( "/RTFM/Elements/Error",
Why => loc("Unable to load article") );
}
my @attribs = qw(Name Summary Class);
@results = UpdateRecordObject( AttributesRef => \@attribs,
Object => $ArticleObj,
ARGSRef => \%ARGS );
my $CustomFields = $ArticleObj->ClassObj->CustomFields();
# Build up a list of articles that we want to work with
my %articles_to_mod;
my %custom_fields_to_mod;
foreach my $arg ( keys %ARGS ) {
if ( $arg =~ /^Article-(\d+)-CustomField-(\d+)-/ ) {
# For each of those articles, find out what custom fields we want to work with.
$custom_fields_to_mod{$1}{$2} = 1;
}
}
# For each of those Articles
foreach my $article ( keys %custom_fields_to_mod ){
my $Article = RT::FM::Article->new( $session{'CurrentUser'} );
$Article->Load($article);
# For each custom field
foreach my $cf ( keys %{ $custom_fields_to_mod{$article} } ) {
foreach my $arg ( keys %ARGS ) {
next unless ( $arg =~ /^Article-$article-CustomField-$cf-/ );
my @tempvalues =
( ref( $ARGS{$arg} ) eq 'ARRAY' )
? @{ $ARGS{$arg} }
: ( $ARGS{$arg} );
# clobber those newlines into something vaguely standard
# that ||1 means that if it doesn't match newline, still add it
my @values =
grep { $_ =~ s/\r\n|\n\r|\n|\r/\n/g || 1 } @tempvalues;
chomp(@values);
if ( ( $arg =~ /-AddValue$/ ) || ( $arg =~ /-Value$/ ) ) {
my $cf_values = $Article->CustomFieldValues($cf);
foreach my $value (@values) {
next unless ($value);
unless ( $cf_values->HasEntryWithContent($value) ) {
my ( $val, $msg ) = $Article->AddCustomFieldValue(
Field => $cf,
Content => $value
);
push ( @results, $msg );
}
}
}
elsif ( $arg =~ /-DeleteValues$/ ) {
foreach my $value (@values) {
next unless ($value);
my ( $val, $msg ) = $Article->DeleteCustomFieldValue(
Field => $cf,
Content => $value
);
push ( @results, $msg );
}
}
elsif ( $arg =~ /-Values$/ ) {
my $cf_values = $Article->CustomFieldValues($cf);
my %values_hash;
foreach my $value (@values) {
next unless ($value);
# build up a hash of values that the new set has
$values_hash{$value} = 1;
unless ( $cf_values->HasEntryWithContent($value) ) {
my ( $val, $msg ) = $Article->AddCustomFieldValue(
Field => $cf,
Content => $value
);
push ( @results, $msg );
}
}
while ( my $cf_value = $cf_values->Next ) {
unless ( $values_hash{ $cf_value->Content } == 1 ) {
my ( $val, $msg ) =
$Article->DeleteCustomFieldValue(
Field => $cf,
Content => $cf_value->Content
);
push ( @results, $msg );
}
}
}
else {
push ( @results,
"User asked for an unknown update type for custom field "
. $cf->Name
. " for Article "
. $Article->id );
}
}
}
}
# Delete links that are gone gone gone.
foreach my $arg ( keys %ARGS ){
if ( $arg =~ /DeleteLink-(.*?)-(RefersTo|MemberOf|RefersTo)-(.*)$/ ) {
my $base = $1;
my $type = $2;
my $target = $3;
my ( $val, $msg ) = $ArticleObj->DeleteLink( Base => $base,
Type => $type,
Target => $target );
push @results, $msg;
}
}
my @linktypes = qw(DependsOn MemberOf RefersTo );
foreach my $linktype (@linktypes) {
for my $luri ( split ( / /, $ARGS{ $ArticleObj->Id . "-$linktype" } ) )
{
$luri =~ s/\s*$//; # Strip trailing whitespace
my ( $val, $msg ) =
$ArticleObj->AddLink( Target => $luri, Type => $linktype );
push @results, $msg;
}
for my $luri ( split ( / /, $ARGS{ "$linktype-" . $ArticleObj->Id } ) )
{
my ( $val, $msg ) =
$ArticleObj->AddLink( Base => $luri, Type => $linktype );
push @results, $msg;
}
}
$title = loc( 'Modify article #[_1]', $ArticleObj->Id );
}
# if they're working on an existing article
if ($ArticleObj->id) {
unless ( $ArticleObj->CurrentUserHasRight('ShowArticle') ) {
$m->comp( "/RTFM/Elements/Error", Why => "No permission to view Article" );
}
}
</%INIT>
<%ARGS>
$id => undef
$Class => undef
</%ARGS>
|