1 %# BEGIN BPS TAGGED BLOCK {{{
5 %# This software is Copyright (c) 1996-2013 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'} );
160 $cf->SetContextObject( $ArticleObj );
163 $RT::Logger->error( "Couldn't load custom field #". $cfid );
167 if ( $arg =~ /-Upload$/ ) {
168 $create_args{"CustomField-$cfid"} = _UploadedFile( $arg );
172 my $type = $cf->Type;
175 if ( ref $ARGS{ $arg } eq 'ARRAY' ) {
176 @values = @{ $ARGS{ $arg } };
177 } elsif ( $type =~ /text/i ) {
178 @values = ($ARGS{ $arg });
180 @values = split /\r*\n/, $ARGS{ $arg } || '';
182 @values = grep $_ ne '',
189 grep defined, @values;
191 $create_args{"CustomField-$cfid"} = \@values;
196 ( $id, $msg ) = $ArticleObj->Create(
197 Summary => $ARGS{'Summary'},
198 Name => $ARGS{'Name'},
199 Class => $ARGS{'Class'},
200 Topics => $ARGS{'Topics'},
203 push( @results, $msg );
207 $ArticleObj->Load($id);
209 $title = loc( 'Modify article #[_1]', $ArticleObj->Id );
213 $m->redirect($ARGS{next});
216 MaybeRedirectForResults(
217 Actions => \@results,
218 Arguments => { id => $ArticleObj->id },
223 $ClassObj->Load($Class);
224 unless ( $ClassObj->Id ) {
225 $m->comp( "/Elements/Error",
226 Why => loc( "'[_1]' isn't a valid class identifier", $Class ) );
228 $ArticleObj = RT::Article->new( $session{'CurrentUser'} );
231 $title = loc('Create a new article');
236 $ArticleObj->Load($id);
237 unless ( $ArticleObj->id ) {
238 $m->comp( "/Elements/Error",
239 Why => loc("Unable to load article") );
242 my @attribs = qw(Name Summary Class);
244 @results = UpdateRecordObject(
245 AttributesRef => \@attribs,
246 Object => $ArticleObj,
250 my @cf_results = ProcessObjectCustomFieldUpdates(
251 Object => $ArticleObj,
254 @results = ( @results, @cf_results );
256 # Delete links that are gone gone gone.
257 foreach my $arg ( keys %ARGS ) {
258 if ( $arg =~ /DeleteLink-(.*?)-(RefersTo|MemberOf|RefersTo)-(.*)$/ ) {
263 my ( $val, $msg ) = $ArticleObj->DeleteLink(
275 my @linktypes = qw(DependsOn MemberOf RefersTo );
277 foreach my $linktype (@linktypes) {
279 for my $luri ( split( / /, ( $ARGS{ $ArticleObj->Id . "-$linktype" } || '' )) ) {
280 $luri =~ s/\s*$//; # Strip trailing whitespace
282 $ArticleObj->AddLink( Target => $luri, Type => $linktype );
284 delete $ARGS{ $ArticleObj->Id . "-$linktype" } if $val;
287 for my $luri ( split( / /, ( $ARGS{ "$linktype-" . $ArticleObj->Id } || '' )) ) {
289 $ArticleObj->AddLink( Base => $luri, Type => $linktype );
291 delete $ARGS{ "$linktype-" . $ArticleObj->Id } if $val;
297 if ( $ARGS{'EditTopics'} ) {
298 $topics{$_}++ for @{ $ARGS{'Topics'} };
300 RT::ObjectTopics->new( $session{'CurrentUser'} );
301 $objTopics->LimitToObject($ArticleObj);
302 while ( my $t = $objTopics->Next ) {
303 $topics{ $t->Topic }--;
305 for my $id ( keys %topics ) {
306 if ( $topics{$id} > 0 ) {
307 my ( $val, $msg ) = $ArticleObj->AddTopic( Topic => $id );
310 elsif ( $topics{$id} < 0 ) {
311 my ( $val, $msg ) = $ArticleObj->DeleteTopic( Topic => $id );
317 $title = loc( 'Modify article #[_1]', $ArticleObj->Id );
320 # if they're working on an existing article
321 if ( $ArticleObj->id ) {
322 unless ( $ArticleObj->CurrentUserHasRight('ShowArticle') ) {
323 $m->comp( "/Elements/Error",
324 Why => loc("No permission to view Article") );