This commit was generated by cvs2svn to compensate for changes in r2523,
[freeside.git] / rt / webrt / Admin / Queues / Scrips.html
1 <& /Admin/Elements/Header, Title => 'Edit scrips' &>
2 <& /Admin/Elements/QueueTabs, id => $QueueObj->Id &>
3
4 <& /Elements/ListActions, actions => \@actions &>
5
6 <& /Elements/TitleBoxStart, title => $description &>
7  
8 <h2>Global Scrips</h2>
9 <& /Admin/Elements/ListGlobalScrips &>
10 <BR> 
11   <FORM METHOD=POST ACTION="Scrips.html">
12     <INPUT TYPE=HIDDEN NAME=id VALUE=<%$id%>>
13 <h2>Queue Scrips</h2>
14 % if ($Scrips->Count > 0 ) {
15 <TABLE>
16 <TR>
17 <TD>Delete
18 </TD>
19 <TD>
20 </TR>
21 % while (my $scrip = $Scrips->Next ) {
22 <TR>
23 <TD>
24 <INPUT TYPE="CHECKBOX" NAME="DeleteScrip-<%$scrip->Id%>">
25 </TD>
26 <TD>
27 <% $scrip->ConditionObj->Name %> 
28 <% $scrip->ActionObj->Name %> with template
29 <% $scrip->TemplateObj->Name %>
30 </TD>
31 </TR>
32 % }
33 </TABLE>
34 % }
35 <BR>
36 <h2>Add a scrip to this queue</h2>
37 Condition: <& /Admin/Elements/SelectScripCondition, Name => 'NewScripCondition' &>
38           Action: <& /Admin/Elements/SelectScripAction, Name => 'NewScripAction' &>
39           Template: <& /Admin/Elements/SelectTemplate, Name => 'NewScripTemplate', DefaultQueue => $id &>
40
41 <& /Elements/TitleBoxEnd &>
42 <& /Elements/Submit &>
43 </FORM>
44 <%init>
45 my (@actions, $description);
46
47 my $Scrips = new RT::Scrips ($session{'CurrentUser'});
48 unless ($id =~ /^\d+$/) {
49     Abort("$id isn't a valid Queue id.");
50 }
51
52 unless ($Scrips->LimitToQueue($id)) {
53     Abort("Couldn't load Scrips.");
54         }
55
56 my $QueueObj = new RT::Queue($session{'CurrentUser'});
57 $QueueObj->Load($id);
58
59 if ($QueueObj->id) {
60     $description = "Modify scrips for queue '". $QueueObj->Name ."'";
61 }
62 else {
63     $description = "Modify global scrips";
64 }
65
66
67 if ($NewScripAction and $NewScripCondition) {
68     my $NewScrip = new RT::Scrip($session{'CurrentUser'});
69     
70     my ($retval, $msg) = $NewScrip->Create ( ScripAction => $NewScripAction,
71                                      ScripCondition => $NewScripCondition,
72                                      Stage => 'TransactionCreate',
73                                      Queue => $id,
74                                      Template => $NewScripTemplate);
75     if (defined $retval) {
76         push @actions, $msg;
77     }
78     else {
79         push @actions, $msg;
80     }
81 }
82
83 # {{{ deal with modifying and deleting existing scrips
84 my ($key );
85 foreach $key (keys %ARGS) {
86         # {{{ if we're trying to delete the scrip
87     if ($key =~ /^DeleteScrip-(\d+)/) {
88             my $id = $1;
89                 my $scrip = new RT::Scrip($session{'CurrentUser'});
90                 $scrip->Load($id);
91             my ($retval, $msg) = $scrip->Delete;
92             if ($retval) {
93                 push @actions, 'Scrip deleted';
94             }
95             else {
96                 push @actions, $msg;
97             }
98         }
99         # }}}
100
101     
102 }
103 # }}}
104 </%init>
105
106 <%ARGS>
107 $NewScripCondition => undef
108 $NewScripAction => undef
109 $NewScripTemplate => undef
110 $id => undef         #some identifier that a Queue could 
111 </%ARGS>