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