RT# 82949 - changes section name from fees to pricing, better opiton
[freeside.git] / httemplate / misc / xmlhttp-ticket-update.html
index bd58b95..01fb1b4 100644 (file)
@@ -8,14 +8,18 @@ my $username = $cgi->param('username');
 
 my $ticket = FS::TicketSystem->get_ticket_object( \%session, ticket_id=>$id );
 
-#hmm, this should happen in a single transaction and either commit or rollback,
-# but in reality failures "Don't Happen" so its not like a ticket gets
-# half changed
+#hmm, this should happen in a single transaction and either commit or rollback
 
 my $return;
 if ( $ticket ) {
 
-  my($orv, $omsg) = $ticket->SetOwner( $username, 'Steal' );
+  my $curowner = $ticket->OwnerObj->Name;
+  my($orv, $omsg);
+  if (( $curowner eq $FS::CurrentUser::CurrentUser->username ) or ( $curowner eq 'nobody' )) {
+    ($orv, $omsg) = $ticket->SetOwner( $username );
+  } else {
+    ($orv, $omsg) = $ticket->SetOwner( $username, 'Steal' );
+  }
   $orv = 1 if ! $orv && $omsg =~ /already own/i;
 
   if ( $orv ) {
@@ -42,15 +46,18 @@ if ( $ticket ) {
       my %hash = $m->comp('/rt/Ticket/Elements/Customers', Ticket => $ticket);
       my @cust_main = values( %{$hash{cust_main}} );
 
+      my $timelabel = FS::sched_avail::pretty_time($sh*60+$sm). '-'.
+                      FS::sched_avail::pretty_time($eh*60+$em);
+      my $titlelabel = encode_entities($cust_main[0]->_FreesideURILabel);
+
       $return = { 'error'       => '',
                   #'starts'      => $starts,
                   #'due'         => $due,
                   #'username'    => $username,
                                    #false laziness w/CalendarSlotSchedule
-                  'sched_label' =>
-                     FS::sched_avail::pretty_time($sh*60+$sm). '-'.
-                     FS::sched_avail::pretty_time($eh*60+$em). ': '.
-                     encode_entities($cust_main[0]->_FreesideURILabel),
+                  'sched_label' => $timelabel . ': ' . $titlelabel,
+                  'sched_label_time' => $timelabel,
+                  'sched_label_title' => $titlelabel,
                 };
     } else {
       $return = { 'error' => $smsg };