import rt 3.8.7
[freeside.git] / rt / share / html / Tools / Offline.html
1 %# BEGIN BPS TAGGED BLOCK {{{
2 %# 
3 %# COPYRIGHT:
4 %# 
5 %# This software is Copyright (c) 1996-2009 Best Practical Solutions, LLC
6 %#                                          <jesse@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 <& /Elements/Header, Title => loc("Offline upload") &>
49 <& Elements/Tabs, 
50     current_tab => "Tools/Offline.html", 
51     Title => loc("Offline edits") &>
52
53 <& /Elements/ListActions, actions => \@results &>
54
55 % $m->callback( Requestor => \$requestoraddress, Queue => \$qname, %ARGS );
56
57 <form action="Offline.html" name="TicketUpdate" 
58         method="post" enctype="multipart/form-data">
59 <table>
60 <tr>
61 <td class="label">
62 <&|/l&>Default Queue</&>:
63 </td>
64 <td>
65 <& /Elements/SelectQueue, Name => "qname", NamedValues => 1 &>
66 <em><&|/l&>If no queue is specified, create tickets in this queue.</&></em>
67 </td>
68 </tr>
69 <tr>
70 <td class="label">
71 <&|/l&>Default Requestor</&>:
72 </td>
73 <td>
74 <input name="requestoraddress" value="<%$requestoraddress%>" />
75 <em><&|/l&>If no Requestor is specified, create tickets with this requestor.</&></em>
76 </td>
77 </tr>
78 <tr><td class="labeltop">
79 <&|/l&>Template</&>:
80 </td>
81 <td colspan="2">
82 <textarea name="string" cols="80" rows="30"><% $string %></textarea>
83 </td>
84 </tr>
85 <tr><td class="label">
86 <&|/l&>Get template from file</&>:
87 </td>
88 <td>
89 <input name="Template" type="file" />
90 <input type="submit" class="button" name="Parse" value="<&|/l&>Go!</&>" />
91 </td>
92 </tr>
93 </table>
94 <& /Elements/Submit, Name => 'UpdateTickets', Label => loc('Upload'), Caption => loc("Upload your changes"), color => "#993333" &>
95
96 </form>
97 <%args>
98 $requestoraddress => ''
99 $qname => undef
100 $string => undef
101 </%args>
102 <%INIT>
103
104 my @results;
105 use RT::Action::CreateTickets;
106 my $action = RT::Action::CreateTickets->new(CurrentUser => $session{'CurrentUser'});
107 ;
108 if ($ARGS{'Parse'} && $ARGS{'Template'}) {
109     $string = "";
110     my $cgi_object = $m->cgi_object;
111     my $fh = $cgi_object->upload('Template');
112     my $filename = "$fh";
113
114     my ($buffer, $template);
115     while ( my $bytesread = read( $fh, $buffer, 4096 ) ) {
116             $template .= $buffer;
117     }
118     my $encode = RT::I18N::_GuessCharset( $template );
119     require Encode;
120     $template = Encode::decode( $encode, $template );
121     $template =~ s/\r\n/\n/gs;
122     $action->Parse(Content => $template, Queue => $qname, Requestor => $requestoraddress);
123     foreach ( @{ $action->{'create_tickets'} } ) {
124         my $id = $_;
125         $id =~ s/^create\-//;
126         $string .= "===Create-Ticket: $id\n";
127         $string .= $action->{'templates'}->{$_} . "\n";
128     }
129     foreach ( @{ $action->{'update_tickets'} } ) {
130         my $id = $_;
131         $id =~ s/^update\-//;
132         $string .= "===Update-Ticket: $id\n";
133         $string .= $action->{'templates'}->{$_} . "\n";
134     }
135
136
137 } elsif ($ARGS{'UpdateTickets'}) {
138     $action->Parse(Content => $ARGS{string}, Queue => $qname, Requestor=> $requestoraddress);
139     push @results, $action->CreateByTemplate();
140     push @results, $action->UpdateByTemplate();
141 } else {
142     if ($ARGS{'Query'}) {
143         my $Tickets = RT::Tickets->new($session{'CurrentUser'});
144         $Tickets->FromSQL($ARGS{'Query'});
145         
146         while (my $t = $Tickets->Next) {
147             $string .= "===Update-Ticket: " . $t->Id . "\n";
148             $string .= $action->GetUpdateTemplate($t);
149             $string .= "" . "\n";
150         }
151         
152         $string .= "" . "\n";
153         $string .= "===# DO NOT EDIT BELOW THIS LINE#===\n";
154         $string .= "" . "\n";
155         
156         while (my $t = $Tickets->Next) {
157             $string .= "===# DO NOT EDIT #===\n";
158                 $string .= "===Base-Ticket: " . $t->Id . "\n";
159             $string .= $action->GetBaseTemplate($t);
160             $string .= "===# DO NOT EDIT #===\n";
161                 $string .= "" . "\n";
162         }
163     } else {
164         $string .= "===Create-Ticket: ticket1\n";
165         $string .= $action->GetCreateTemplate();
166     }
167 }
168 </%INIT>