]>
Commit | Line | Data |
---|---|---|
84fb5b46 MKG |
1 | %# BEGIN BPS TAGGED BLOCK {{{ |
2 | %# | |
3 | %# COPYRIGHT: | |
4 | %# | |
320f0092 | 5 | %# This software is Copyright (c) 1996-2014 Best Practical Solutions, LLC |
84fb5b46 MKG |
6 | %# <sales@bestpractical.com> |
7 | %# | |
8 | %# (Except where explicitly superseded by other copyright notices) | |
9 | %# | |
10 | %# | |
11 | %# LICENSE: | |
12 | %# | |
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 | |
16 | %# from www.gnu.org. | |
17 | %# | |
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. | |
22 | %# | |
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. | |
28 | %# | |
29 | %# | |
30 | %# CONTRIBUTION SUBMISSION POLICY: | |
31 | %# | |
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.) | |
37 | %# | |
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. | |
46 | %# | |
47 | %# END BPS TAGGED BLOCK }}} | |
48 | % if ( $ARGS{id} && $ARGS{id} ne 'new' ) { | |
49 | <input type="hidden" name="<%$ARGS{'id'}%>-RefersTo" value="<% join(' ',grep {$_} sort keys %uri) %>" /> | |
50 | % } | |
51 | ||
52 | <table class="articles-select-article"> | |
53 | % unless (RT->Config->Get('HideArticleSearchOnReplyCreate')) { | |
54 | <tr> | |
55 | <td><&|/l&>Search for Articles matching</&></td> | |
56 | <td><input size=20 name="<% $name_prefix %>Articles_Content" /></td> | |
57 | </tr> | |
58 | <tr> | |
59 | <td><&|/l&>Include Article:</&></td> | |
60 | <td><input size=20 name="<% $name_prefix %>Articles-Include-Article-Named" /></td> | |
61 | <td><input type="submit" name="Go" value="Go" /></td> | |
62 | </tr> | |
63 | % } | |
64 | % if ($hotlist->Count) { | |
65 | <tr> | |
66 | <td><&|/l&>Select an Article to include</&></td> | |
67 | <td><select name="<% $name_prefix %>Articles-Include-Article-Named-Hotlist" onchange="this.form.submit()"> | |
68 | <option value="" selected><&|/l&>-</&></option> | |
69 | % while (my $article = $hotlist->Next) { | |
70 | <option value="<% $article->Id %>"><%$article->Name|| loc('(no name)')%>: <%$article->Summary || ''%></option> | |
71 | % } | |
72 | </select> | |
73 | </td> | |
74 | <td><input type="submit" name="Go" value="Go" /></td> | |
75 | </tr> | |
76 | % } | |
77 | % my %dedupe_articles; | |
78 | % while (my $article = $articles_content->Next) { | |
79 | % $dedupe_articles{$article->Id}++; | |
80 | <tr> | |
81 | <td> </td> | |
82 | <td><%$article->Name|| loc('(no name)')%>: <%$article->Summary%></td> | |
83 | <td><input type="submit" name="<% $name_prefix %>Articles-Include-Article-<%$article->Id%>" value="Go" /></td> | |
84 | </tr> | |
85 | % } | |
86 | % while (my $article = $articles_basics->Next) { | |
87 | % next if $dedupe_articles{$article->Id}; | |
88 | <tr> | |
89 | <td> </td> | |
90 | <td><%$article->Name || loc('(no name)')%>: <%$article->Summary || ''%></td> | |
91 | <td><input type="submit" name="<% $name_prefix %>Articles-Include-Article-<%$article->Id%>" value="Go" /></td> | |
92 | </tr> | |
93 | % } | |
94 | % if ( @$topics ) { | |
95 | <tr> | |
96 | <td> | |
97 | <&|/l, $QueueObj->Name &>Choose from Topics for [_1]</&> | |
98 | </td> | |
99 | <td> | |
100 | <select name="<% $name_prefix %>Articles-Include-Topic" onchange="this.form.submit()"> | |
101 | <option value="" selected>-</option> | |
102 | % for ( @$topics ) { | |
103 | <option value="<% $_->{id} %>"><%' ' x $_->{depth} . ($_->{name}|| loc('(no name)')) |n%> | |
104 | </option> | |
105 | % } | |
106 | </select> | |
107 | </td> | |
108 | <td><input type="submit" name="Go" value="Go" /></td> | |
109 | </tr> | |
110 | ||
111 | % if ( $ARGS{$name_prefix .'Articles-Include-Topic'} ) { | |
112 | <tr> | |
113 | <td> | |
114 | <&|/l, $included_topic->Name &>Select an Article from [_1]</&> | |
115 | </td> | |
116 | <td> | |
117 | <select name="<% $name_prefix %>Articles-Include-Article" onchange="this.form.submit()"> | |
118 | <option value="" selected>-</option> | |
119 | % while ( my $art = $topic_articles->Next ) { | |
120 | <option value="<% $art->id %>"><%$art->Name||loc('(no name)')%>: <%$art->Summary%></option> | |
121 | % } | |
122 | </select> | |
123 | </td> | |
124 | <td><input type="submit" value="Go" name="Go" /></td> | |
125 | </tr> | |
126 | ||
127 | % } | |
128 | % } | |
129 | ||
130 | ||
131 | </table> | |
132 | ||
133 | <%init> | |
134 | my $QueueObj = $ARGS{QueueObj}; | |
135 | if ( $ARGS{id} && $ARGS{id} ne 'new' && !$QueueObj ) { | |
136 | my $ticket = RT::Ticket->new( $session{CurrentUser} ); | |
137 | $ticket->Load( $ARGS{id} ); | |
138 | $QueueObj = $ticket->QueueObj; | |
139 | } | |
140 | ||
141 | my $skip = 0; | |
142 | $m->callback(CallbackName => "Init", skip => \$skip, Queue => $QueueObj); | |
143 | return if $skip; | |
144 | ||
145 | my $name_prefix = ''; | |
146 | if ( $ARGS{'MessageBoxName'} ) { | |
147 | $name_prefix = $ARGS{'MessageBoxName'} .'-'; | |
148 | } | |
149 | ||
150 | # convert Articles-Include-Article => $id to Articles-Include-Article-$id | |
151 | if ( my $tmp = $ARGS{$name_prefix ."Articles-Include-Article"} ) { | |
152 | $ARGS{$name_prefix ."Articles-Include-Article-$tmp"}++; | |
153 | } | |
154 | ||
155 | my %uri; | |
156 | if ( $ARGS{id} && $ARGS{id} ne 'new' ) { | |
157 | $uri{$_}++ for split ' ', ($ARGS{$ARGS{'id'}.'-RefersTo'} || ''); | |
158 | ||
159 | foreach my $arg (keys %ARGS) { | |
160 | next if $name_prefix && substr($arg, 0, length($name_prefix)) ne $name_prefix; | |
161 | ||
162 | my $article = RT::Article->new($session{'CurrentUser'}); | |
163 | $article->LoadByInclude( | |
164 | Field => substr($arg, length($name_prefix)), | |
165 | Value => $ARGS{$arg}, | |
166 | ); | |
167 | if ($article->Id) { | |
168 | $uri{$article->URI}++; | |
169 | } | |
170 | } | |
171 | } | |
172 | ||
173 | use RT::Articles; | |
174 | ||
175 | my $articles_content = | |
176 | RT::Articles->new( $session{'CurrentUser'} ); | |
177 | my $articles_basics = RT::Articles->new( $session{'CurrentUser'} ); | |
178 | if ( my $tmp = $ARGS{ $name_prefix ."Articles_Content" } ) { | |
179 | $articles_content->LimitCustomField( | |
180 | VALUE => $tmp, OPERATOR => 'LIKE' | |
181 | ); | |
182 | $articles_content->LimitAppliedClasses( Queue => $QueueObj ); | |
183 | ||
184 | $articles_basics->Limit( SUBCLAUSE => 'all', | |
185 | FIELD => 'Name', | |
186 | OPERATOR => 'LIKE', | |
187 | VALUE => $tmp, | |
188 | ENTRYAGGREGATOR => "OR" ); | |
189 | $articles_basics->Limit( SUBCLAUSE => 'all', | |
190 | FIELD => 'Summary', | |
191 | OPERATOR => 'LIKE', | |
192 | VALUE => $tmp, | |
193 | ENTRYAGGREGATOR => "OR" ); | |
194 | $articles_basics->LimitAppliedClasses( Queue => $QueueObj ); | |
195 | } | |
196 | ||
197 | my $hotlist = RT::Articles->new( $session{'CurrentUser'} ); | |
198 | $hotlist->LimitHotlistClasses; | |
199 | $hotlist->LimitAppliedClasses( Queue => $QueueObj ); | |
200 | ||
201 | my ( $topic_articles, $topics, $included_topic ); | |
202 | $topic_articles = RT::Articles->new( $session{CurrentUser} ); | |
203 | $topics = []; | |
204 | ||
205 | my $top_topic = RT::Topic->new( $session{CurrentUser} ); | |
206 | $top_topic->LoadByCols( Name => 'Queues', Parent => 0 , ObjectType => 'RT::System', ObjectId => 1); | |
207 | ||
208 | if ( $top_topic->id ) { | |
209 | my $queue_topic = RT::Topic->new( $session{CurrentUser} ); | |
210 | $queue_topic->LoadByCols( Name => $QueueObj->Name, Parent => $top_topic->id ); | |
211 | if ( $queue_topic->id ) { | |
212 | ||
213 | # store all topics below $queue_topic to $topics | |
214 | topics( $queue_topic, $topics, 0 ); | |
215 | ||
216 | if ( my $tmp = $ARGS{ $name_prefix .'Articles-Include-Topic'} ) { | |
217 | $included_topic = RT::Topic->new( $session{CurrentUser} ); | |
218 | $included_topic->Load( $tmp ); | |
219 | $topic_articles->LimitTopics( $tmp ); | |
220 | $topic_articles->OrderBy( FIELD => 'Name' ); | |
221 | } | |
222 | } | |
223 | } | |
224 | ||
225 | ||
226 | # recursively get all the topics given a top topic | |
227 | sub topics { | |
228 | my $parent = shift; | |
229 | my $out = shift; | |
230 | my $depth = shift; | |
231 | while ( my $topic = $parent->Children->Next ) { | |
232 | push @$out, { id => $topic->id, name => $topic->Name, depth => $depth }; | |
233 | topics( $topic, $out, $depth+1 ); | |
234 | } | |
235 | } | |
236 | ||
237 | </%init> | |
238 | ||
239 |