06a2c8aad4483971694850470b6368cf5161d0de
[Evergreen.git] / Open-ILS / src / reporter / templates / stage3.ttk
1 [%
2
3 PROCESS inputs;
4 PROCESS class_manip;
5 PROCESS widget_manip;
6 PROCESS logic_header.ttk;
7 INCLUDE logout.ttk;
8
9 templates = DBI.tie('reporter.stage2', 'id')
10 reports = DBI.tie('reporter.stage3', 'id')
11 rpt = {};
12 tmpl = {};
13
14
15 IF CGI.param('id');
16         tid = CGI.param('stage2');
17         tmpl = templates.$tid;
18         rid = CGI.param('id');
19         rpt = reports.$rid;
20 END;
21
22
23 WRAPPER html/html;
24    INCLUDE header.ttk + navbar.ttk title="Reports";
25    WRAPPER html/body;
26       IF CGI.param('action') == 'Schedule';
27          PROCESS schedule_stage3;
28       ELSIF CGI.param('action') == 'Save';
29          PROCESS save_stage3;
30       ELSIF CGI.param('action') == 'Run Now';
31          PROCESS save_stage3;
32                 ELSIF CGI.param('id');
33                         PROCESS view_stage3;
34                 ELSE;
35                         PROCESS list_stage3s;
36       END;
37    END;
38    INCLUDE footer.ttk;
39 END;
40
41
42 BLOCK schedule_stage3;
43         WRAPPER form method='POST';
44                 'Run Date:';
45                 INCLUDE text name='runtime' value='yyyy-mm-dd';
46                 '<br>';
47
48                 'Optional Recurrence:';
49                 INCLUDE text name='recurrence-count' value='0';
50                 WRAPPER select name='recurrence-interval';
51                         INCLUDE option value='days' content='Day(s)';
52                         INCLUDE option value='weeks' content='Week(s)';
53                         INCLUDE option value='months' content='Month(s)';
54                 END;
55
56                 FOR p = CGI.param();
57                         NEXT IF p == 'action';
58                         NEXT IF p == 'runtime';
59                         INCLUDE hidden name=p value=CGI.param(p);
60                 END;
61                 '<br>';
62                 INCLUDE submit name='action' value='Save';
63         END;
64 END;
65
66 BLOCK list_stage3s;
67 END;
68
69
70 BLOCK save_stage3;
71         stage2 = CGI.param('stage2');
72         runtime = CGI.param('runtime') OR 'now';
73         pub = CGI.param('publicreport') OR 'f';
74         owner = user.id();
75
76         p_obj = {};
77         FOR p = CGI.param();
78
79                 logme([p,CGI.param(p)]);
80
81                 parts = p.split(':');
82                 p1 = parts.0;
83                 p2 = parts.1;
84                 p3 = parts.2;
85                 p4 = parts.3;
86                 p5 = parts.4;
87                 p6 = parts.5;
88                 
89                 IF p6;
90
91                         IF p_obj.$p1.$p2.$p3.$p4.$p5.$p6.defined;
92                                 IF p_obj.$p1.$p2.$p3.$p4.$p5.$p6.size > 1;
93                                         p_obj.$p1.$p2.$p3.$p4.$p5.$p6.push(CGI.param(p));
94                                 ELSE;
95                                         tmp = [ p_obj.$p1.$p2.$p3.$p4.$p5.$p6, CGI.param(p) ];
96                                         p_obj.$p1.$p2.$p3.$p4.$p5.$p6 = tmp;
97                                 END;
98                         ELSE;
99                                 p_obj.$p1.$p2.$p3.$p4.$p5.$p6 = CGI.param(p);
100                         END;
101
102                 ELSIF p5;
103
104                         IF p_obj.$p1.$p2.$p3.$p4.$p5.defined;
105                                 IF p_obj.$p1.$p2.$p3.$p4.$p5.size > 1;
106                                         p_obj.$p1.$p2.$p3.$p4.$p5.push(CGI.param(p));
107                                 ELSE;
108                                         tmp = [ p_obj.$p1.$p2.$p3.$p4.$p5, CGI.param(p) ];
109                                         p_obj.$p1.$p2.$p3.$p4.$p5 = tmp;
110                                 END;
111                         ELSE;
112                                 p_obj.$p1.$p2.$p3.$p4.$p5 = CGI.param(p);
113                         END;
114
115                 ELSIF p4;
116
117                         IF p_obj.$p1.$p2.$p3.$p4.defined;
118                                 IF p_obj.$p1.$p2.$p3.$p4.size > 1;
119                                         p_obj.$p1.$p2.$p3.$p4.push(CGI.param(p));
120                                 ELSE;
121                                         tmp = [ p_obj.$p1.$p2.$p3.$p4, CGI.param(p) ];
122                                         p_obj.$p1.$p2.$p3.$p4 = tmp;
123                                 END;
124                         ELSE;
125                                 p_obj.$p1.$p2.$p3.$p4 = CGI.param(p);
126                         END;
127
128                 ELSIF p3;
129
130                         IF p_obj.$p1.$p2.$p3.defined;
131                                 IF p_obj.$p1.$p2.$p3.size > 1;
132                                         p_obj.$p1.$p2.$p3.push(CGI.param(p));
133                                 ELSE;
134                                         tmp = [ p_obj.$p1.$p2.$p3, CGI.param(p) ];
135                                         p_obj.$p1.$p2.$p3 = tmp;
136                                 END;
137                         ELSE;
138                                 p_obj.$p1.$p2.$p3 = CGI.param(p);
139                         END;
140
141                 ELSIF p2;
142
143                         IF p_obj.$p1.$p2.defined;
144                                 IF p_obj.$p1.$p2.size > 1;
145                                         p_obj.$p1.$p2.push(CGI.param(p));
146                                 ELSE;
147                                         tmp = [ p_obj.$p1.$p2, CGI.param(p) ];
148                                         p_obj.$p1.$p2 = tmp;
149                                 END;
150                         ELSE;
151                                 p_obj.$p1.$p2 = CGI.param(p);
152                         END;
153
154                 ELSE;
155
156                         p_obj.$p = CGI.param(p);
157
158                 END;
159         END;
160
161         params = utils.perl2JSON( p_obj );
162
163         recurrence = '0 sec';
164         IF CGI.param('recurrence-count') > 0;
165                 recurrence = CGI.param('recurrence-count') _ ' ' _ CGI.param('recurrence-interval');
166         END;
167
168         logme([stage2, params, owner, pub]);
169
170         q = DBI.prepare( stage3_insert );
171         CALL q.execute(stage2, params, owner, pub, runtime, recurrence);
172
173         FOR new_s3 = DBI.query("SELECT * FROM reporter.stage3_id_seq;");
174                 tid = new_s3.last_value;
175                 INCLUDE view_stage3 rpt = reports.$tid;
176         END;
177 END;
178
179
180
181
182 BLOCK view_stage3;
183         logme(rpt.params);
184         params = utils.JSON2perl( rpt.params );
185
186         # stuff goes here ...
187
188 END;
189
190 %]