]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/reporter/templates/stage3.ttk
5bed69862a04cb3f97afa49fc40926c367a8dba9
[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 output = DBI.tie('reporter.output', 'id')
12 rpt = {};
13 tmpl = {};
14
15
16 IF CGI.param('output');
17         oid = CGI.param('output');
18         out = output.$oid;
19
20         rid = out.stage3;
21         rpt = reports.$rid;
22
23         tid = rpt.stage2;
24         tmpl = templates.$tid;
25 END;
26
27 IF CGI.param('id');
28         rid = CGI.param('id');
29         rpt = reports.$rid;
30         tid = rpt.stage2;
31         tmpl = templates.$tid;
32 END;
33
34
35 WRAPPER html/html;
36    INCLUDE header.ttk + navbar.ttk title="Reports";
37    WRAPPER html/body;
38       IF CGI.param('action') == 'Schedule';
39          PROCESS schedule_stage3;
40       ELSIF CGI.param('action') == 'enable_stage3';
41          PROCESS enable;
42       ELSIF CGI.param('action') == 'disable_stage3';
43          PROCESS disable;
44       ELSIF CGI.param('action') == 'Reschedule';
45          PROCESS resched;
46       ELSIF CGI.param('action') == 'Save';
47          PROCESS save_stage3;
48       ELSIF CGI.param('action') == 'delete_stage3';
49          PROCESS delete_stage3;
50       ELSIF CGI.param('action') == 'delete_output';
51          PROCESS delete_output;
52       ELSIF CGI.param('action') == 'rerun';
53          PROCESS rerun;
54       ELSIF CGI.param('action') == 'Run Now';
55          PROCESS save_stage3;
56                 ELSIF CGI.param('id');
57                         PROCESS view_stage3;
58                 ELSE;
59                         PROCESS list_stage3s;
60       END;
61    END;
62    INCLUDE footer.ttk;
63 END;
64
65
66 BLOCK schedule_stage3;
67         WRAPPER form method='POST';
68                 'Run Date:';
69                 INCLUDE text name='runtime' value='yyyy-mm-dd';
70                 '<br>';
71
72                 'Optional Recurrence:';
73                 INCLUDE text name='recurrence-count' value='0';
74                 WRAPPER select name='recurrence-interval';
75                         INCLUDE option value='minutes' content='Minutes(s)'; # for testing
76                         INCLUDE option value='hours' content='Hours(s)'; # for testing
77                         INCLUDE option value='days' content='Day(s)';
78                         INCLUDE option value='weeks' content='Week(s)';
79                         INCLUDE option value='months' content='Month(s)';
80                 END;
81
82                 FOR p = CGI.param();
83                         NEXT IF p == 'action';
84                         NEXT IF p == 'runtime';
85                         FOR pval = CGI.param(p);
86                                 INCLUDE hidden name=p value=pval;
87                         END;
88                 END;
89                 '<br>';
90                 INCLUDE submit name='action' value='Save';
91         END;
92 END;
93
94 BLOCK list_stage3s;
95 END;
96
97
98 BLOCK save_stage3;
99         stage2 = CGI.param('stage2');
100         runtime = CGI.param('runtime') OR 'now';
101         pub = CGI.param('publicreport') OR 'f';
102         owner = user.id();
103
104         p_obj = {};
105         FOR p = CGI.param();
106
107                 logme([p,CGI.param(p)]);
108
109                 parts = p.split(':');
110                 p1 = parts.0;
111                 p2 = parts.1;
112                 p3 = parts.2;
113                 p4 = parts.3;
114                 p5 = parts.4;
115                 p6 = parts.5;
116                 
117                 IF p6;
118
119                         IF p_obj.$p1.$p2.$p3.$p4.$p5.$p6.defined;
120                                 IF p_obj.$p1.$p2.$p3.$p4.$p5.$p6.size > 1;
121                                         p_obj.$p1.$p2.$p3.$p4.$p5.$p6.push(CGI.param(p));
122                                 ELSE;
123                                         tmp = [ p_obj.$p1.$p2.$p3.$p4.$p5.$p6, CGI.param(p) ];
124                                         p_obj.$p1.$p2.$p3.$p4.$p5.$p6 = tmp;
125                                 END;
126                         ELSE;
127                                 p_obj.$p1.$p2.$p3.$p4.$p5.$p6 = CGI.param(p);
128                         END;
129
130                 ELSIF p5;
131
132                         IF p_obj.$p1.$p2.$p3.$p4.$p5.defined;
133                                 IF p_obj.$p1.$p2.$p3.$p4.$p5.size > 1;
134                                         p_obj.$p1.$p2.$p3.$p4.$p5.push(CGI.param(p));
135                                 ELSE;
136                                         tmp = [ p_obj.$p1.$p2.$p3.$p4.$p5, CGI.param(p) ];
137                                         p_obj.$p1.$p2.$p3.$p4.$p5 = tmp;
138                                 END;
139                         ELSE;
140                                 p_obj.$p1.$p2.$p3.$p4.$p5 = CGI.param(p);
141                         END;
142
143                 ELSIF p4;
144
145                         IF p_obj.$p1.$p2.$p3.$p4.defined;
146                                 IF p_obj.$p1.$p2.$p3.$p4.size > 1;
147                                         p_obj.$p1.$p2.$p3.$p4.push(CGI.param(p));
148                                 ELSE;
149                                         tmp = [ p_obj.$p1.$p2.$p3.$p4, CGI.param(p) ];
150                                         p_obj.$p1.$p2.$p3.$p4 = tmp;
151                                 END;
152                         ELSE;
153                                 p_obj.$p1.$p2.$p3.$p4 = CGI.param(p);
154                         END;
155
156                 ELSIF p3;
157
158                         IF p_obj.$p1.$p2.$p3.defined;
159                                 IF p_obj.$p1.$p2.$p3.size > 1;
160                                         p_obj.$p1.$p2.$p3.push(CGI.param(p));
161                                 ELSE;
162                                         tmp = [ p_obj.$p1.$p2.$p3, CGI.param(p) ];
163                                         p_obj.$p1.$p2.$p3 = tmp;
164                                 END;
165                         ELSE;
166                                 p_obj.$p1.$p2.$p3 = CGI.param(p);
167                         END;
168
169                 ELSIF p2;
170
171                         IF p_obj.$p1.$p2.defined;
172                                 IF p_obj.$p1.$p2.size > 1;
173                                         p_obj.$p1.$p2.push(CGI.param(p));
174                                 ELSE;
175                                         tmp = [ p_obj.$p1.$p2, CGI.param(p) ];
176                                         p_obj.$p1.$p2 = tmp;
177                                 END;
178                         ELSE;
179                                 p_obj.$p1.$p2 = CGI.param(p);
180                         END;
181
182                 ELSE;
183
184                         p_obj.$p = CGI.param(p);
185
186                 END;
187         END;
188
189         params = utils.perl2JSON( p_obj );
190
191         recurrence = '0 sec';
192         IF CGI.param('recurrence-count') > 0;
193                 recurrence = CGI.param('recurrence-count') _ ' ' _ CGI.param('recurrence-interval');
194         END;
195
196         logme([stage2, params, owner, pub]);
197
198         q = DBI.prepare( stage3_insert );
199         CALL q.execute(stage2, params, owner, pub, runtime, recurrence);
200
201         FOR new_s3 = DBI.query("SELECT * FROM reporter.stage3_id_seq;");
202                 rid = new_s3.last_value;
203                 rpt = reports.$rid;
204                 tid = rpt.stage2;
205                 tmpl = templates.$tid;
206                 INCLUDE view_stage3;
207         END;
208 END;
209
210 BLOCK delete_stage3;
211         q = DBI.prepare( 'DELETE FROM reporter.stage3 WHERE id = ?' );
212         CALL q.execute(rpt.id);
213 END;
214
215 BLOCK delete_output;
216         q = DBI.prepare( 'DELETE FROM reporter.output WHERE id = ?' );
217         CALL q.execute(out.id);
218         INCLUDE view_stage3;
219 END;
220
221 BLOCK enable;
222         q = DBI.prepare( 'UPDATE reporter.stage3 SET disable = FALSE WHERE id = ?' );
223         CALL q.execute(CGI.param('id'));
224         INCLUDE view_stage3;
225 END;
226
227 BLOCK disable;
228         q = DBI.prepare( 'UPDATE reporter.stage3 SET disable = TRUE WHERE id = ?' );
229         CALL q.execute(CGI.param('id'));
230         INCLUDE view_stage3;
231 END;
232
233 BLOCK resched;
234         q = DBI.prepare( 'UPDATE reporter.stage3 SET runtime = ? WHERE id = ?' );
235         CALL q.execute(CGI.param('newtime'), CGI.param('id'));
236         INCLUDE view_stage3;
237 END;
238
239 BLOCK rerun;
240         q = DBI.prepare( 'UPDATE reporter.stage3 SET rerun = TRUE WHERE id = ?' );
241         CALL q.execute(rpt.id);
242         INCLUDE view_stage3;
243 END;
244
245 BLOCK view_stage3;
246         logme(rpt.params);
247         params = utils.JSON2perl( rpt.params );
248         s2_params = utils.JSON2perl( tmpl.params );
249
250
251         WRAPPER html/center;
252                 WRAPPER html/table style="border-collapse:collapse";
253                         WRAPPER html/row;
254                                 INCLUDE html/cell content="<b>Report Name</b>" style="border:solid gray 1px;";
255                                 INCLUDE html/cell content=params.reportname style="border:solid gray 1px;";
256                         END;
257                         WRAPPER html/row;
258                                 INCLUDE html/cell content="<b>Based on Template</b>" style="border:solid gray 1px;";
259                                 INCLUDE html/cell content=s2_params.templatename style="border:solid gray 1px;";
260                         END;
261                         WRAPPER html/row;
262                                 INCLUDE html/cell content="<b>Creation Time</b>" style="border:solid gray 1px;";
263                                 INCLUDE html/cell content=rpt.create_date.chunk(19).0 style="border:solid gray 1px;";
264                         END;
265                         WRAPPER html/row;
266                                 INCLUDE html/cell content="<b>Scheduled Run Time</b>" style="border:solid gray 1px;";
267                                 IF user.id == rpt.owner;
268                                         WRAPPER html/cell style="border:solid gray 1px;";
269                                                 WRAPPER form method="post";
270                                                         INCLUDE hidden name="id" value=rpt.id;
271                                                         INCLUDE text name="newtime" value=rpt.runtime.chunk(19).0;
272                                                         INCLUDE submit name="action" value="Reschedule";
273                                                 END;
274                                         END;
275                                 ELSE;
276                                         INCLUDE html/cell content=rpt.runtime style="border:solid gray 1px;";
277                                 END;
278                         END;
279                         WRAPPER html/row;
280                                 INCLUDE html/cell content="<b>Recurrence Interval</b>" style="border:solid gray 1px;";
281                                 INCLUDE html/cell content=rpt.recurrence style="border:solid gray 1px;";
282                         END;
283                         WRAPPER html/row;
284                                 INCLUDE html/cell content="<b>Actions</b>" style="border:solid gray 1px;";
285                                 WRAPPER html/cell style="border:solid gray 1px;";
286                                         INCLUDE anchor content='Refresh' href=CGI.url('-path', 1) _ '?id=' _ rpt.id;
287                                         '&nbsp;&nbsp;&nbsp;';
288                                         INCLUDE anchor content='Clone and Edit' href='stage2?action=edit&id=' _ rpt.stage2 _ '&report=' _ rpt.id;
289                                         '&nbsp;&nbsp;&nbsp;';
290                                         IF user.id == rpt.owner;
291                                                 INCLUDE anchor content='Run again' href=CGI.url('-path', 1) _ '?action=rerun&id=' _ rpt.id;
292                                                 '&nbsp;&nbsp;&nbsp;';
293                                                 IF rpt.disable;
294                                                         INCLUDE anchor content='Enable' href=CGI.url('-path', 1) _ '?action=enable_stage3&id=' _ rpt.id;
295                                                 ELSE;
296                                                         INCLUDE anchor content='Disable' href=CGI.url('-path', 1) _ '?action=disable_stage3&id=' _ rpt.id;
297                                                 END;
298                                                 '&nbsp;&nbsp;&nbsp;';
299                                                 INCLUDE anchor content='Delete' href=CGI.url('-path', 1) _ '?action=delete_stage3&id=' _ rpt.id;
300                                                 '&nbsp;&nbsp;&nbsp;';
301                                         END;
302                                 END;
303                         END;
304                 END;
305         END;
306
307         '<br><br>';
308
309         type_map = { 'csv' => 'csv', 'excel' => 'xls', 'html' => 'html' };
310
311         WRAPPER html/center;
312                 '<b>Report Runs:</b>';
313                 run_q = DBI.prepare("SELECT * FROM reporter.output WHERE stage3 = ? ORDER BY queue_time DESC");
314                 FOR run = run_q.execute(rpt.id);
315                         "<a name='$run.id'>";
316                         WRAPPER html/table style="border-collapse:collapse";
317                                 WRAPPER html/row;
318                                         INCLUDE html/cell content="<b>Current State</b>" style="border:solid gray 1px;" width="20%";
319                                         WRAPPER html/cell style="border:solid gray 1px;";
320                                                 run.state;
321                                                 IF run.state == 'complete';
322                                                         '<br>';
323                                                         FOR f = params.output_format.list;
324                                                                 h = tmpl.stage1 _ '/' _ tmpl.id _
325                                                                         '/' _ rpt.id _ '/' _ run.id _
326                                                                         '/report-data.' _ type_map.$f;
327                                                                 link(content=f, href=h);
328                                                                 IF !loop.last;
329                                                                         '  |  ';
330                                                                 END;
331                                                         END;
332                                                 END;
333                                         END;
334                                 END;
335                                 WRAPPER html/row;
336                                         INCLUDE html/cell content="<b>Queue Time</b>" style="border:solid gray 1px;";
337                                         INCLUDE html/cell content=run.queue_time style="border:solid gray 1px;";
338                                 END;
339                                 IF run.run_time;
340                                         WRAPPER html/row;
341                                                 INCLUDE html/cell content="<b>Run Time</b>" style="border:solid gray 1px;";
342                                                 INCLUDE html/cell content=run.run_time style="border:solid gray 1px;";
343                                         END;
344                                 END;
345                                 IF run.complete_time;
346                                         WRAPPER html/row;
347                                                 INCLUDE html/cell content="<b>Complete Time</b>" style="border:solid gray 1px;";
348                                                 INCLUDE html/cell content=run.complete_time style="border:solid gray 1px;";
349                                         END;
350                                 END;
351                                 IF run.query;
352                                         WRAPPER html/row;
353                                                 INCLUDE html/cell content="<b>Query</b>" style="border:solid gray 1px;";
354                                                 INCLUDE html/cell content=run.query style="border:solid gray 1px;";
355                                         END;
356                                 END;
357                                 IF run.error;
358                                         WRAPPER html/row;
359                                                 INCLUDE html/cell content="<b>Error</b>" style="border:solid gray 1px;";
360                                                 INCLUDE html/cell content=run.error style="border:solid gray 1px;";
361                                         END;
362                                 END;
363                                 IF run.error_time;
364                                         WRAPPER html/row;
365                                                 INCLUDE html/cell content="<b>Error Time</b>" style="border:solid gray 1px;";
366                                                 INCLUDE html/cell content=run.error_time style="border:solid gray 1px;";
367                                         END;
368                                 END;
369                                 IF run.complete_time || run.error_time;
370                                         WRAPPER html/row;
371                                                 INCLUDE html/cell content="<b>Actions</b>" style="border:solid gray 1px;";
372                                                 WRAPPER html/cell style="border:solid gray 1px;";
373                                                         IF user.id == rpt.owner;
374                                                                 INCLUDE anchor content='Delete' href=CGI.url('-path', 1) _ '?action=delete_output&output=' _ run.id;
375                                                                 '&nbsp;&nbsp;&nbsp;';
376                                                         END;
377                                                 END;
378                                         END;
379                                 END;
380                         END;
381                         '</a><br><br>';
382                 END;
383         END;
384 END;
385
386 %]