4 USE start = DateTime(now = 1);
5 USE two_digits = format('%02d');
10 PROCESS logic_header.ttk;
13 templates = DBI.tie('reporter.stage2', 'id')
14 reports = DBI.tie('reporter.stage3', 'id')
15 output = DBI.tie('reporter.output', 'id')
20 IF CGI.param('output');
21 oid = CGI.param('output');
28 tmpl = templates.$tid;
32 rid = CGI.param('id');
35 tmpl = templates.$tid;
40 INCLUDE header.ttk + navbar.ttk title="Reports";
42 IF CGI.param('action') == 'Schedule';
43 PROCESS schedule_stage3;
44 ELSIF CGI.param('action') == 'enable_stage3';
46 ELSIF CGI.param('action') == 'disable_stage3';
48 ELSIF CGI.param('action') == 'Reschedule';
50 ELSIF CGI.param('action') == 'Save';
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';
58 ELSIF CGI.param('action') == 'Run Now';
60 ELSIF CGI.param('id');
70 BLOCK schedule_stage3;
71 WRAPPER form method='POST';
73 INCLUDE text name='runtime' value= start.year _ '-' _ two_digits(start.month) _ '-' _ two_digits(start.day);
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)';
85 NEXT IF p == 'action';
86 NEXT IF p == 'runtime';
87 FOR pval = CGI.param(p);
88 INCLUDE hidden name=p value=pval;
92 INCLUDE submit name='action' value='Save';
101 stage2 = CGI.param('stage2');
102 runtime = CGI.param('runtime') OR 'now';
103 pub = CGI.param('publicreport') OR 'f';
109 logme([p,CGI.param(p)]);
111 parts = p.split(':');
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));
125 tmp = [ p_obj.$p1.$p2.$p3.$p4.$p5.$p6, CGI.param(p) ];
126 p_obj.$p1.$p2.$p3.$p4.$p5.$p6 = tmp;
129 p_obj.$p1.$p2.$p3.$p4.$p5.$p6 = CGI.param(p);
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));
138 tmp = [ p_obj.$p1.$p2.$p3.$p4.$p5, CGI.param(p) ];
139 p_obj.$p1.$p2.$p3.$p4.$p5 = tmp;
142 p_obj.$p1.$p2.$p3.$p4.$p5 = CGI.param(p);
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));
151 tmp = [ p_obj.$p1.$p2.$p3.$p4, CGI.param(p) ];
152 p_obj.$p1.$p2.$p3.$p4 = tmp;
155 p_obj.$p1.$p2.$p3.$p4 = CGI.param(p);
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));
164 tmp = [ p_obj.$p1.$p2.$p3, CGI.param(p) ];
165 p_obj.$p1.$p2.$p3 = tmp;
168 p_obj.$p1.$p2.$p3 = CGI.param(p);
173 IF p_obj.$p1.$p2.defined;
174 IF p_obj.$p1.$p2.size > 1;
175 p_obj.$p1.$p2.push(CGI.param(p));
177 tmp = [ p_obj.$p1.$p2, CGI.param(p) ];
181 p_obj.$p1.$p2 = CGI.param(p);
186 p_obj.$p = CGI.param(p);
191 params = utils.perl2JSON( p_obj );
193 recurrence = '0 sec';
194 IF CGI.param('recurrence-count') > 0;
195 recurrence = CGI.param('recurrence-count') _ ' ' _ CGI.param('recurrence-interval');
198 logme([stage2, params, owner, pub]);
200 q = DBI.prepare( stage3_insert );
201 CALL q.execute(stage2, params, owner, pub, runtime, recurrence);
203 FOR new_s3 = DBI.query("SELECT * FROM reporter.stage3_id_seq;");
204 rid = new_s3.last_value;
207 tmpl = templates.$tid;
213 q = DBI.prepare( 'DELETE FROM reporter.stage3 WHERE id = ?' );
214 CALL q.execute(rpt.id);
218 q = DBI.prepare( 'DELETE FROM reporter.output WHERE id = ?' );
219 CALL q.execute(out.id);
224 q = DBI.prepare( 'UPDATE reporter.stage3 SET disable = FALSE WHERE id = ?' );
225 CALL q.execute(CGI.param('id'));
230 q = DBI.prepare( 'UPDATE reporter.stage3 SET disable = TRUE WHERE id = ?' );
231 CALL q.execute(CGI.param('id'));
236 q = DBI.prepare( 'UPDATE reporter.stage3 SET runtime = ? WHERE id = ?' );
237 CALL q.execute(CGI.param('newtime'), CGI.param('id'));
242 q = DBI.prepare( 'UPDATE reporter.stage3 SET rerun = TRUE WHERE id = ?' );
243 CALL q.execute(rpt.id);
249 params = utils.JSON2perl( rpt.params );
250 s2_params = utils.JSON2perl( tmpl.params );
254 WRAPPER html/table style="border-collapse:collapse";
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;";
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;";
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;";
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";
278 INCLUDE html/cell content=rpt.runtime style="border:solid gray 1px;";
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;";
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 ' ';
290 INCLUDE anchor content='Clone and Edit' href='stage2?action=edit&id=' _ rpt.stage2 _ '&report=' _ rpt.id;
291 ' ';
292 IF user.id == rpt.owner;
293 INCLUDE anchor content='Run again' href=CGI.url('-path', 1) _ '?action=rerun&id=' _ rpt.id;
294 ' ';
296 INCLUDE anchor content='Enable' href=CGI.url('-path', 1) _ '?action=enable_stage3&id=' _ rpt.id;
298 INCLUDE anchor content='Disable' href=CGI.url('-path', 1) _ '?action=disable_stage3&id=' _ rpt.id;
300 ' ';
301 INCLUDE anchor content='Delete' href=CGI.url('-path', 1) _ '?action=delete_stage3&id=' _ rpt.id;
302 ' ';
311 type_map = { 'csv' => 'csv', 'excel' => 'xls', 'html' => 'html' };
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";
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;";
323 IF run.state == 'complete';
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);
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;";
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;";
347 IF run.complete_time;
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;";
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;";
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;";
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;";
371 IF run.complete_time || run.error_time;
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 ' ';