1 %# BEGIN BPS TAGGED BLOCK {{{
5 %# This software is Copyright (c) 1996-2017 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'} );
120 $ClassObj->Load($Class);
121 Abort(loc("'[_1]' isn't a valid class", $Class)) unless $ClassObj->Id;
128 $title = loc('Create a new article');
129 foreach my $arg ( sort keys %ARGS ) {
130 if ( $arg =~ /^Transaction-(\d+)$/ ) {
131 my $trans = RT::Transaction->new( $session{'CurrentUser'} );
133 $CFContent{ $ARGS{$arg} } .= "\n\n" if $CFContent{ $ARGS{$arg} };
134 $CFContent{ $ARGS{$arg} } .= $trans->Content;
141 elsif ( $id eq 'new' ) {
143 if ( $ARGS{'RefersTo-new'} ) {
144 @{ $create_args{'RefersTo-new'} } =
145 split( /\s+/, $ARGS{'RefersTo-new'} );
148 if ( $ARGS{'new-RefersTo'} ) {
149 @{ $create_args{'new-RefersTo'} } =
150 split( /\s+/, $ARGS{'new-RefersTo'} );
153 my %cfs = ProcessObjectCustomFieldUpdatesForCreate(
155 ContextObject => $ClassObj,
159 ( $id, $msg ) = $ArticleObj->Create(
160 Summary => $ARGS{'Summary'},
161 Name => $ARGS{'Name'},
162 Class => $ARGS{'Class'},
163 Topics => $ARGS{'Topics'},
167 push( @results, $msg );
171 $ArticleObj->Load($id);
173 $title = loc( 'Modify article #[_1]', $ArticleObj->Id );
177 $m->redirect($ARGS{next});
180 MaybeRedirectForResults(
181 Actions => \@results,
182 Arguments => { id => $ArticleObj->id },
187 $ArticleObj = RT::Article->new( $session{'CurrentUser'} );
190 $title = loc('Create a new article');
195 $ArticleObj->Load($id);
196 unless ( $ArticleObj->id ) {
197 $m->comp( "/Elements/Error",
198 Why => loc("Unable to load article") );
201 my @attribs = qw(Name Summary Class);
203 @results = UpdateRecordObject(
204 AttributesRef => \@attribs,
205 Object => $ArticleObj,
209 my @cf_results = ProcessObjectCustomFieldUpdates(
210 Object => $ArticleObj,
213 @results = ( @results, @cf_results );
215 # Delete links that are gone gone gone.
216 foreach my $arg ( keys %ARGS ) {
217 if ( $arg =~ /DeleteLink-(.*?)-(RefersTo|MemberOf|RefersTo)-(.*)$/ ) {
222 my ( $val, $msg ) = $ArticleObj->DeleteLink(
234 my @linktypes = qw(DependsOn MemberOf RefersTo );
236 foreach my $linktype (@linktypes) {
238 for my $luri ( split( / /, ( $ARGS{ $ArticleObj->Id . "-$linktype" } || '' )) ) {
239 $luri =~ s/\s*$//; # Strip trailing whitespace
241 $ArticleObj->AddLink( Target => $luri, Type => $linktype );
243 delete $ARGS{ $ArticleObj->Id . "-$linktype" } if $val;
246 for my $luri ( split( / /, ( $ARGS{ "$linktype-" . $ArticleObj->Id } || '' )) ) {
248 $ArticleObj->AddLink( Base => $luri, Type => $linktype );
250 delete $ARGS{ "$linktype-" . $ArticleObj->Id } if $val;
256 if ( $ARGS{'EditTopics'} ) {
257 $topics{$_}++ for @{ $ARGS{'Topics'} };
259 RT::ObjectTopics->new( $session{'CurrentUser'} );
260 $objTopics->LimitToObject($ArticleObj);
261 while ( my $t = $objTopics->Next ) {
262 $topics{ $t->Topic }--;
264 for my $id ( keys %topics ) {
265 if ( $topics{$id} > 0 ) {
266 my ( $val, $msg ) = $ArticleObj->AddTopic( Topic => $id );
269 elsif ( $topics{$id} < 0 ) {
270 my ( $val, $msg ) = $ArticleObj->DeleteTopic( Topic => $id );
276 $title = loc( 'Modify article #[_1]', $ArticleObj->Id );
279 # if they're working on an existing article
280 if ( $ArticleObj->id ) {
281 unless ( $ArticleObj->CurrentUserHasRight('ShowArticle') ) {
282 $m->comp( "/Elements/Error",
283 Why => loc("No permission to view Article") );