1 %# BEGIN BPS TAGGED BLOCK {{{
5 %# This software is Copyright (c) 1996-2012 Best Practical Solutions, LLC
6 %# <sales@bestpractical.com>
8 %# (Except where explicitly superseded by other copyright notices)
13 %# This work is made available to you under the terms of Version 2 of
14 %# the GNU General Public License. A copy of that license should have
15 %# been provided with this software, but in any event can be snarfed
18 %# This work is distributed in the hope that it will be useful, but
19 %# WITHOUT ANY WARRANTY; without even the implied warranty of
20 %# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 %# General Public License for more details.
23 %# You should have received a copy of the GNU General Public License
24 %# along with this program; if not, write to the Free Software
25 %# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
26 %# 02110-1301 or visit their web page on the internet at
27 %# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html.
30 %# CONTRIBUTION SUBMISSION POLICY:
32 %# (The following paragraph is not intended to limit the rights granted
33 %# to you to modify and distribute this software under the terms of
34 %# the GNU General Public License and is only of importance to you if
35 %# you choose to contribute your changes and enhancements to the
36 %# community by submitting them to Best Practical Solutions, LLC.)
38 %# By intentionally submitting any modifications, corrections or
39 %# derivatives to this work, or any other work intended for use with
40 %# Request Tracker, to Best Practical Solutions, LLC, you confirm that
41 %# you are the copyright holder for those contributions and you grant
42 %# Best Practical Solutions, LLC a nonexclusive, worldwide, irrevocable,
43 %# royalty-free, perpetual, license to use, copy, create derivative
44 %# works based on those contributions, and sublicense and distribute
45 %# those contributions and any derivatives thereof.
47 %# END BPS TAGGED BLOCK }}}
48 <& /Elements/Header, Title => $title &>
50 <& /Elements/ListActions, actions => \@results &>
52 <form method="post" action="Edit.html" name="EditArticle" id="EditArticle" enctype="multipart/form-data">
53 <input type="hidden" name="next" value="<%$ARGS{next}||''%>" />
54 <input type="hidden" name="id" value="<%$id%>" />
57 <td><h2><&|/l&>Basics</&></h2></td>
60 <& Elements/EditBasics, ArticleObj => $ArticleObj,
61 EditClass =>$EditClass,
62 ClassObj => $ClassObj,
68 <td><h2><&|/l&>Content</&></h2></td>
71 <& Elements/EditCustomFields, ArticleObj => $ArticleObj,
72 CFContent => \%CFContent,
73 ClassObj => $ClassObj,
79 <td><h2><&|/l&>Links</&></h2></td>
82 <& Elements/EditLinks, ArticleObj => $ArticleObj,
87 <td><h2><&|/l&>Topics</&></h2></td>
91 <td class="label"><&|/l&>Topics</&></td>
93 <& Elements/EditTopics, ArticleObj => $ArticleObj,
94 Classes => [$ArticleObj->Id ? $ArticleObj->ClassObj : $ClassObj],
102 <& /Elements/Submit, Label => ($id eq 'new' ? loc('Create') : loc('Save Changes')), color => "#993333" &>
107 if ( exists $ARGS{'Topics'} ) {
109 ref( $ARGS{'Topics'} ) ? $ARGS{'Topics'} : [ $ARGS{'Topics'} ];
116 my $ArticleObj = RT::Article->new( $session{'CurrentUser'} );
117 my $ClassObj = RT::Class->new( $session{'CurrentUser'} );
122 $title = loc('Create a new article');
123 foreach my $arg ( sort keys %ARGS ) {
124 if ( $arg =~ /^Transaction-(\d+)$/ ) {
125 my $trans = RT::Transaction->new( $session{'CurrentUser'} );
127 $CFContent{ $ARGS{$arg} } .= "\n\n" if $CFContent{ $ARGS{$arg} };
128 $CFContent{ $ARGS{$arg} } .= $trans->Content;
132 $ClassObj->Load($Class);
133 unless ( $ClassObj->Id ) {
134 $m->comp( "/Elements/Error",
135 Why => loc( "'[_1]' isn't a valid class identifier", $Class ) );
140 elsif ( $id eq 'new' ) {
142 if ( $ARGS{'RefersTo-new'} ) {
143 @{ $create_args{'RefersTo-new'} } =
144 split( /\s+/, $ARGS{'RefersTo-new'} );
147 if ( $ARGS{'new-RefersTo'} ) {
148 @{ $create_args{'new-RefersTo'} } =
149 split( /\s+/, $ARGS{'new-RefersTo'} );
153 foreach my $arg (keys %ARGS) {
154 next if $arg =~ /-(?:Magic|Category)$/;
155 # Object-RT::Article--CustomField-3-Values
156 if ( $arg =~ /^Object-RT::Article--CustomField-(\d+)(.*?)$/ ) {
159 my $cf = RT::CustomField->new( $session{'CurrentUser'} );
162 $RT::Logger->error( "Couldn't load custom field #". $cfid );
166 if ( $arg =~ /-Upload$/ ) {
167 $create_args{"CustomField-$cfid"} = _UploadedFile( $arg );
171 my $type = $cf->Type;
174 if ( ref $ARGS{ $arg } eq 'ARRAY' ) {
175 @values = @{ $ARGS{ $arg } };
176 } elsif ( $type =~ /text/i ) {
177 @values = ($ARGS{ $arg });
179 @values = split /\r*\n/, $ARGS{ $arg } || '';
181 @values = grep $_ ne '',
188 grep defined, @values;
190 $create_args{"CustomField-$cfid"} = \@values;
195 ( $id, $msg ) = $ArticleObj->Create(
196 Summary => $ARGS{'Summary'},
197 Name => $ARGS{'Name'},
198 Class => $ARGS{'Class'},
199 Topics => $ARGS{'Topics'},
202 push( @results, $msg );
206 $ArticleObj->Load($id);
208 $title = loc( 'Modify article #[_1]', $ArticleObj->Id );
212 $m->redirect($ARGS{next});
215 MaybeRedirectForResults(
216 Actions => \@results,
217 Arguments => { id => $ArticleObj->id },
222 $ClassObj->Load($Class);
223 unless ( $ClassObj->Id ) {
224 $m->comp( "/Elements/Error",
225 Why => loc( "'[_1]' isn't a valid class identifier", $Class ) );
227 $ArticleObj = RT::Article->new( $session{'CurrentUser'} );
230 $title = loc('Create a new article');
235 $ArticleObj->Load($id);
236 unless ( $ArticleObj->id ) {
237 $m->comp( "/Elements/Error",
238 Why => loc("Unable to load article") );
241 my @attribs = qw(Name Summary Class);
243 @results = UpdateRecordObject(
244 AttributesRef => \@attribs,
245 Object => $ArticleObj,
249 my @cf_results = ProcessObjectCustomFieldUpdates(
250 Object => $ArticleObj,
253 @results = ( @results, @cf_results );
255 # Delete links that are gone gone gone.
256 foreach my $arg ( keys %ARGS ) {
257 if ( $arg =~ /DeleteLink-(.*?)-(RefersTo|MemberOf|RefersTo)-(.*)$/ ) {
262 my ( $val, $msg ) = $ArticleObj->DeleteLink(
274 my @linktypes = qw(DependsOn MemberOf RefersTo );
276 foreach my $linktype (@linktypes) {
278 for my $luri ( split( / /, ( $ARGS{ $ArticleObj->Id . "-$linktype" } || '' )) ) {
279 $luri =~ s/\s*$//; # Strip trailing whitespace
281 $ArticleObj->AddLink( Target => $luri, Type => $linktype );
283 delete $ARGS{ $ArticleObj->Id . "-$linktype" } if $val;
286 for my $luri ( split( / /, ( $ARGS{ "$linktype-" . $ArticleObj->Id } || '' )) ) {
288 $ArticleObj->AddLink( Base => $luri, Type => $linktype );
290 delete $ARGS{ "$linktype-" . $ArticleObj->Id } if $val;
296 if ( $ARGS{'EditTopics'} ) {
297 $topics{$_}++ for @{ $ARGS{'Topics'} };
299 RT::ObjectTopics->new( $session{'CurrentUser'} );
300 $objTopics->LimitToObject($ArticleObj);
301 while ( my $t = $objTopics->Next ) {
302 $topics{ $t->Topic }--;
304 for my $id ( keys %topics ) {
305 if ( $topics{$id} > 0 ) {
306 my ( $val, $msg ) = $ArticleObj->AddTopic( Topic => $id );
309 elsif ( $topics{$id} < 0 ) {
310 my ( $val, $msg ) = $ArticleObj->DeleteTopic( Topic => $id );
316 $title = loc( 'Modify article #[_1]', $ArticleObj->Id );
319 # if they're working on an existing article
320 if ( $ArticleObj->id ) {
321 unless ( $ArticleObj->CurrentUserHasRight('ShowArticle') ) {
322 $m->comp( "/Elements/Error",
323 Why => loc("No permission to view Article") );