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>Selection Criteria</b>" style="border:solid gray 1px; vertical-align: top;";
287 WRAPPER html/cell style="border:solid gray 1px;";
288 WRAPPER html/table width="100%" style="border-collapse:collapse;";
289 FOR t = params.filter.keys;
290 FOR c = params.filter.$t.keys;
291 FOR wf = params.filter.$t.$c.keys;
292 FOR w = params.filter.$t.$c.$wf.keys;
294 xpath = '/reporter/tables/table[@id="' _ t _ '" and @fact-table="true"]';
295 table = config.findnodes(xpath);
297 xpath = '/reporter/tables/table[@id=//link[@id="' _ t _ '"]/@table]';
298 table = config.findnodes(xpath);
302 content = table.findvalue('label')
303 style="border:solid gray 1px; top; font-weight:bold;";
305 xpath = 'fields/field[@name="' _ c _ '"]/label';
307 content = table.findvalue(xpath)
308 style="border:solid gray 1px; font-weight:bold;";
311 style="border:solid gray 1px; vertical-align: top;";
312 w_file = 'widgets/' _ wf _ '.' _ w;
313 current_value = params.filter.$t.$c.$wf.$w;
326 INCLUDE html/cell content="<b>Output Attributes</b>" style="border:solid gray 1px; vertical-align: top;";
327 WRAPPER html/cell style="border:solid gray 1px;";
328 FOR t = params.output.keys;
329 FOR c = params.output.$t.keys;
330 xpath = '/reporter/tables/table[@id="' _ t _ '" and @fact-table="true"]';
331 table = config.findnodes(xpath);
333 xpath = '/reporter/tables/table[@id=//link[@id="' _ t _ '"]/@table]';
334 table = config.findnodes(xpath);
337 xpath = 'fields/field[@name="' _ c _ '"]/label';
338 table.findvalue('label') _ ' -- ' _ table.findvalue(xpath) _ '<br/>';
345 INCLUDE html/cell content="<b>Actions</b>" style="border:solid gray 1px;";
346 WRAPPER html/cell style="border:solid gray 1px;";
347 INCLUDE anchor content='Refresh' href=CGI.url('-path', 1) _ '?id=' _ rpt.id;
348 ' ';
349 INCLUDE anchor content='Clone and Edit' href='stage2?action=edit&id=' _ rpt.stage2 _ '&report=' _ rpt.id;
350 ' ';
351 IF user.id == rpt.owner;
352 INCLUDE anchor content='Run again' href=CGI.url('-path', 1) _ '?action=rerun&id=' _ rpt.id;
353 ' ';
355 INCLUDE anchor content='Enable' href=CGI.url('-path', 1) _ '?action=enable_stage3&id=' _ rpt.id;
357 INCLUDE anchor content='Disable' href=CGI.url('-path', 1) _ '?action=disable_stage3&id=' _ rpt.id;
359 ' ';
360 INCLUDE anchor content='Delete' href=CGI.url('-path', 1) _ '?action=delete_stage3&id=' _ rpt.id;
361 ' ';
370 type_map = { 'csv' => 'csv', 'excel' => 'xls', 'html' => 'html' };
373 '<b>Report Runs:</b>';
374 run_q = DBI.prepare("SELECT * FROM reporter.output WHERE stage3 = ? ORDER BY queue_time DESC");
375 FOR run = run_q.execute(rpt.id);
376 "<a name='$run.id'>";
377 WRAPPER html/table style="border-collapse:collapse";
379 INCLUDE html/cell content="<b>Current State</b>" style="border:solid gray 1px;" width="20%";
380 WRAPPER html/cell style="border:solid gray 1px;";
382 IF run.state == 'complete';
384 FOR f = params.output_format.list;
385 h = tmpl.stage1 _ '/' _ tmpl.id _
386 '/' _ rpt.id _ '/' _ run.id _
387 '/report-data.' _ type_map.$f;
388 link(content=f, href=h);
397 INCLUDE html/cell content="<b>Queue Time</b>" style="border:solid gray 1px;";
398 INCLUDE html/cell content=run.queue_time style="border:solid gray 1px;";
402 INCLUDE html/cell content="<b>Run Time</b>" style="border:solid gray 1px;";
403 INCLUDE html/cell content=run.run_time style="border:solid gray 1px;";
406 IF run.complete_time;
408 INCLUDE html/cell content="<b>Complete Time</b>" style="border:solid gray 1px;";
409 INCLUDE html/cell content=run.complete_time style="border:solid gray 1px;";
414 INCLUDE html/cell content="<b>Query</b>" style="border:solid gray 1px;";
415 INCLUDE html/cell content=run.query style="border:solid gray 1px;";
420 INCLUDE html/cell content="<b>Error</b>" style="border:solid gray 1px;";
421 INCLUDE html/cell content=run.error style="border:solid gray 1px;";
426 INCLUDE html/cell content="<b>Error Time</b>" style="border:solid gray 1px;";
427 INCLUDE html/cell content=run.error_time style="border:solid gray 1px;";
430 IF run.complete_time || run.error_time;
432 INCLUDE html/cell content="<b>Actions</b>" style="border:solid gray 1px;";
433 WRAPPER html/cell style="border:solid gray 1px;";
434 IF user.id == rpt.owner;
435 INCLUDE anchor content='Delete' href=CGI.url('-path', 1) _ '?action=delete_output&output=' _ run.id;
436 ' ';