summaryrefslogtreecommitdiff
path: root/rt/webrt/Admin/Queues/Scrips.html
blob: 95b8c43787043227348184b8d0f76078663c1062 (plain)
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<& /Admin/Elements/Header, Title => 'Edit scrips' &>
<& /Admin/Elements/QueueTabs, id => $QueueObj->Id &>

<& /Elements/ListActions, actions => \@actions &>

<& /Elements/TitleBoxStart, title => $description &>
 
<h2>Global Scrips</h2>
<& /Admin/Elements/ListGlobalScrips &>
<BR> 
  <FORM METHOD=POST ACTION="Scrips.html">
    <INPUT TYPE=HIDDEN NAME=id VALUE=<%$id%>>
<h2>Queue Scrips</h2>
% if ($Scrips->Count > 0 ) {
<TABLE>
<TR>
<TD>Delete
</TD>
<TD>
</TR>
% while (my $scrip = $Scrips->Next ) {
<TR>
<TD>
<INPUT TYPE="CHECKBOX" NAME="DeleteScrip-<%$scrip->Id%>">
</TD>
<TD>
<% $scrip->ConditionObj->Name %> 
<% $scrip->ActionObj->Name %> with template
<% $scrip->TemplateObj->Name %>
</TD>
</TR>
% }
</TABLE>
% }
<BR>
<h2>Add a scrip to this queue</h2>
Condition: <& /Admin/Elements/SelectScripCondition, Name => 'NewScripCondition' &>
	  Action: <& /Admin/Elements/SelectScripAction, Name => 'NewScripAction' &>
	  Template: <& /Admin/Elements/SelectTemplate, Name => 'NewScripTemplate', DefaultQueue => $id &>

<& /Elements/TitleBoxEnd &>
<& /Elements/Submit &>
</FORM>
<%init>
my (@actions, $description);

my $Scrips = new RT::Scrips ($session{'CurrentUser'});
unless ($id =~ /^\d+$/) {
    Abort("$id isn't a valid Queue id.");
}

unless ($Scrips->LimitToQueue($id)) {
    Abort("Couldn't load Scrips.");
        }

my $QueueObj = new RT::Queue($session{'CurrentUser'});
$QueueObj->Load($id);

if ($QueueObj->id) {
    $description = "Modify scrips for queue '". $QueueObj->Name ."'";
}
else {
    $description = "Modify global scrips";
}


if ($NewScripAction and $NewScripCondition) {
    my $NewScrip = new RT::Scrip($session{'CurrentUser'});
    
    my ($retval, $msg) = $NewScrip->Create ( ScripAction => $NewScripAction,
				     ScripCondition => $NewScripCondition,
				     Stage => 'TransactionCreate',
				     Queue => $id,
				     Template => $NewScripTemplate);
    if (defined $retval) {
        push @actions, $msg;
    }
    else {
        push @actions, $msg;
    }
}

# {{{ deal with modifying and deleting existing scrips
my ($key );
foreach $key (keys %ARGS) {
	# {{{ if we're trying to delete the scrip
    if ($key =~ /^DeleteScrip-(\d+)/) {
            my $id = $1;
	        my $scrip = new RT::Scrip($session{'CurrentUser'});
	        $scrip->Load($id);
    	    my ($retval, $msg) = $scrip->Delete;
	    if ($retval) {
	        push @actions, 'Scrip deleted';
	    }
	    else {
		push @actions, $msg;
	    }
	}
	# }}}

    
}
# }}}
</%init>

<%ARGS>
$NewScripCondition => undef
$NewScripAction => undef
$NewScripTemplate => undef
$id => undef         #some identifier that a Queue could 
</%ARGS>