1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
<% encode_json($return) %>\
<%init>
my $id = $cgi->param('id');
my $starts = $cgi->param('starts');
my $due = $cgi->param('due');
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
my $return;
if ( $ticket ) {
my($orv, $omsg) = $ticket->SetOwner( $username, 'Steal' );
$orv = 1 if ! $orv && $omsg =~ /already own/i;
if ( $orv ) {
my $date = RT::Date->new( $session{CurrentUser} );
$date->Set( Format=>'unix', Value=>$starts, );
my($srv, $smsg) = $ticket->SetStarts( $date->ISO );
$srv = 1 if ! $srv && $smsg =~ /already the current value/i;
my $ddate;
unless ( ! $srv ) {
$ddate = RT::Date->new( $session{CurrentUser} );
$ddate->Set( Format=>'unix', Value=>$due, );
my($drv, $dmsg) = $ticket->SetDue( $ddate->ISO );
#XXX lame
}
if ( $srv ) {
my ($sm, $sh) = ( $date->Localtime('user'))[1,2];
my ($em, $eh) = ($ddate->Localtime('user'))[1,2];
#false laziness w/CalendarSlotSchedule and CalendarDaySchedule
my %hash = $m->comp('/rt/Ticket/Elements/Customers', Ticket => $ticket);
my @cust_main = values( %{$hash{cust_main}} );
$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),
};
} else {
$return = { 'error' => $smsg };
}
} else {
$return = { 'error' => $omsg };
}
} else {
$return = { 'error' => 'Unknown ticket id' };
}
</%init>
|