import rt 3.6.4
[freeside.git] / rt / html / REST / 1.0 / Forms / ticket / default
index 78f6c95..69e385f 100644 (file)
@@ -2,7 +2,7 @@
 %# 
 %# COPYRIGHT:
 %#  
-%# This software is Copyright (c) 1996-2005 Best Practical Solutions, LLC 
+%# This software is Copyright (c) 1996-2007 Best Practical Solutions, LLC 
 %#                                          <jesse@bestpractical.com>
 %# 
 %# (Except where explicitly superseded by other copyright notices)
@@ -22,7 +22,9 @@
 %# 
 %# You should have received a copy of the GNU General Public License
 %# along with this program; if not, write to the Free Software
-%# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+%# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+%# 02110-1301 or visit their web page on the internet at
+%# http://www.gnu.org/copyleft/gpl.html.
 %# 
 %# 
 %# CONTRIBUTION SUBMISSION POLICY:
 $id
 $changes => {}
 $fields => undef
+$args => undef
 </%ARGS>
-<%perl>
+<%INIT>
 use MIME::Entity;
 
 my @comments;
 my ($c, $o, $k, $e) = ("", [], {}, 0);
 my %data   = %$changes;
 my $ticket = new RT::Ticket $session{CurrentUser};
-my @dates  = qw(Created Starts Started Due Resolved Told);
+my @dates  = qw(Created Starts Started Due Resolved Told LastUpdated);
 my @people = qw(Requestors Cc AdminCc);
 my @create = qw(Queue Requestor Subject Cc AdminCc Owner Status Priority
                 InitialPriority FinalPriority TimeEstimated TimeWorked
@@ -83,7 +86,7 @@ if ($id ne 'new') {
     }
 }
 else {
-    if (%data == 0) {
+    if (!keys(%data)) {
         # GET ticket/new: Return a suitable default form.
         # We get defaults from queue/1 (XXX: What if it isn't there?).
         my $due = new RT::Date $session{CurrentUser};
@@ -95,7 +98,7 @@ else {
         $starts->SetToNow;
 
         return [
-            "# Required: Queue, Requestor, Subject",
+            "# Required: id, Queue",
             [ qw(id Queue Requestor Subject Cc AdminCc Owner Status Priority
                  InitialPriority FinalPriority TimeEstimated Starts Due Text) ],
             {
@@ -127,11 +130,26 @@ else {
             if (exists $create{lc $k}) {
                 $v{$create{lc $k}} = delete $data{$k};
             }
+            # Set custom field
+            elsif ($k =~ /^CF-/i) {
+                my $cf = RT::CustomField->new( $RT::SystemUser );
+                my $cfk = $k;
+                $cfk =~ s/^CF-//i;
+                unless($cf->LoadByName( Name => $cfk )) {
+                    push @comments, "# Invalid custom field name ($cfk)";
+                    delete $data{$k};
+                    next;
+                }
+                $v{"CustomField-".$cf->Id()} = delete $data{$k};
+            }
             elsif (lc $k eq 'text') {
                 $text = delete $data{$k};
             }
         }
 
+        # people fields allow multiple values
+        $v{$_} = vsplit($v{$_}) foreach ( grep $create{lc $_}, @people );
+
         if ($text) {
             $v{MIMEObj} =
                 MIME::Entity->build(
@@ -141,20 +159,23 @@ else {
                 );
         }
 
-        $ticket->Create(%v);
-        unless ($ticket->Id) {
-            return [ "# Could not create ticket.", [], {}, 1 ];
+        my($tid,$trid,$terr) = $ticket->Create(%v);    
+        unless ($tid) {
+            push(@comments, "# Could not create ticket.");
+            push(@comments, "# " . $terr);
+            goto DONE;
         }
 
         delete $data{id};
         $id = $ticket->Id;
         push(@comments, "# Ticket $id created.");
-        goto DONE if %data == 0;
+        # see if the hash is empty
+        goto DONE if ! keys(%data);
     }
 }
 
 # Now we know we're dealing with an existing ticket.
-if (%data == 0) {
+if (!keys(%data)) {
     my ($time, $key, $val, @data);
 
     push @data, [ id    => "ticket/".$ticket->Id   ];
@@ -171,7 +192,7 @@ if (%data == 0) {
     }
 
     foreach $key (@people) {
-       next unless (!%$fields || (exists $fields->{lc $key}));
+        next unless (!%$fields || (exists $fields->{lc $key}));
         push @data, [ $key => [ $ticket->$key->MemberEmailAddresses ] ];
     }
 
@@ -190,6 +211,18 @@ if (%data == 0) {
         push @data, [ $key => $val ];
     }
 
+    # Display custom fields
+    my $CustomFields = $ticket->QueueObj->TicketCustomFields();
+    while (my $cf = $CustomFields->Next()) {
+       next unless (!%$fields || (exists $fields->{"cf-".lc $cf->Name}));
+        my $vals = $ticket->CustomFieldValues($cf->Id());
+        my @out = ();
+        while (my $v = $vals->Next()) {
+            push @out, $v->Content;
+        }
+        push @data, [ 'CF-' . $cf->Name => join ',', @out ];
+    }
+
     my %k = map {@$_} @data;
     $o = [ map {$_->[0]} @data ];
     $k = \%k;
@@ -271,6 +304,20 @@ else {
                 $s =~ s/^# //;
             }
         }
+        # Set custom field
+        elsif ($key =~ /^CF-/i) {
+            my $cf = RT::CustomField->new( $RT::SystemUser );
+            $key =~ s/^CF-//i;
+            if (not $cf->LoadByName( Name => $key )) {
+                $n = 0;
+                $s = "Unknown custom field.";
+            }
+            else {
+                ($n, $s) = $ticket->AddCustomFieldValue(
+                             Field => $cf, Value => $val );
+                $s =~ s/^# // if defined $s;
+            }
+        }
         elsif ($key ne 'id' && $key ne 'type' && $key ne 'creator') {
             $n = 0;
             $s = "Unknown field.";
@@ -295,4 +342,4 @@ DONE:
 $c ||= join("\n", @comments) if @comments;
 return [$c, $o, $k, $e];
 
-</%perl>
+</%INIT>