6 PROCESS logic_header.ttk;
9 templates = DBI.tie('reporter.stage2', 'id')
10 reports = DBI.tie('reporter.stage3', 'id')
11 output = DBI.tie('reporter.output', 'id')
16 IF CGI.param('output');
17 oid = CGI.param('output');
24 tmpl = templates.$tid;
28 rid = CGI.param('id');
31 tmpl = templates.$tid;
36 INCLUDE header.ttk + navbar.ttk title="Reports";
38 IF CGI.param('action') == 'Schedule';
39 PROCESS schedule_stage3;
40 ELSIF CGI.param('action') == 'enable_stage3';
42 ELSIF CGI.param('action') == 'disable_stage3';
44 ELSIF CGI.param('action') == 'Reschedule';
46 ELSIF CGI.param('action') == 'Save';
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';
54 ELSIF CGI.param('action') == 'Run Now';
56 ELSIF CGI.param('id');
66 BLOCK schedule_stage3;
67 WRAPPER form method='POST';
69 INCLUDE text name='runtime' value='yyyy-mm-dd';
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)';
83 NEXT IF p == 'action';
84 NEXT IF p == 'runtime';
85 FOR pval = CGI.param(p);
86 INCLUDE hidden name=p value=pval;
90 INCLUDE submit name='action' value='Save';
99 stage2 = CGI.param('stage2');
100 runtime = CGI.param('runtime') OR 'now';
101 pub = CGI.param('publicreport') OR 'f';
107 logme([p,CGI.param(p)]);
109 parts = p.split(':');
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));
123 tmp = [ p_obj.$p1.$p2.$p3.$p4.$p5.$p6, CGI.param(p) ];
124 p_obj.$p1.$p2.$p3.$p4.$p5.$p6 = tmp;
127 p_obj.$p1.$p2.$p3.$p4.$p5.$p6 = CGI.param(p);
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));
136 tmp = [ p_obj.$p1.$p2.$p3.$p4.$p5, CGI.param(p) ];
137 p_obj.$p1.$p2.$p3.$p4.$p5 = tmp;
140 p_obj.$p1.$p2.$p3.$p4.$p5 = CGI.param(p);
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));
149 tmp = [ p_obj.$p1.$p2.$p3.$p4, CGI.param(p) ];
150 p_obj.$p1.$p2.$p3.$p4 = tmp;
153 p_obj.$p1.$p2.$p3.$p4 = CGI.param(p);
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));
162 tmp = [ p_obj.$p1.$p2.$p3, CGI.param(p) ];
163 p_obj.$p1.$p2.$p3 = tmp;
166 p_obj.$p1.$p2.$p3 = CGI.param(p);
171 IF p_obj.$p1.$p2.defined;
172 IF p_obj.$p1.$p2.size > 1;
173 p_obj.$p1.$p2.push(CGI.param(p));
175 tmp = [ p_obj.$p1.$p2, CGI.param(p) ];
179 p_obj.$p1.$p2 = CGI.param(p);
184 p_obj.$p = CGI.param(p);
189 params = utils.perl2JSON( p_obj );
191 recurrence = '0 sec';
192 IF CGI.param('recurrence-count') > 0;
193 recurrence = CGI.param('recurrence-count') _ ' ' _ CGI.param('recurrence-interval');
196 logme([stage2, params, owner, pub]);
198 q = DBI.prepare( stage3_insert );
199 CALL q.execute(stage2, params, owner, pub, runtime, recurrence);
201 FOR new_s3 = DBI.query("SELECT * FROM reporter.stage3_id_seq;");
202 rid = new_s3.last_value;
205 tmpl = templates.$tid;
211 q = DBI.prepare( 'DELETE FROM reporter.stage3 WHERE id = ?' );
212 CALL q.execute(rpt.id);
216 q = DBI.prepare( 'DELETE FROM reporter.output WHERE id = ?' );
217 CALL q.execute(out.id);
222 q = DBI.prepare( 'UPDATE reporter.stage3 SET disable = FALSE WHERE id = ?' );
223 CALL q.execute(CGI.param('id'));
228 q = DBI.prepare( 'UPDATE reporter.stage3 SET disable = TRUE WHERE id = ?' );
229 CALL q.execute(CGI.param('id'));
234 q = DBI.prepare( 'UPDATE reporter.stage3 SET runtime = ? WHERE id = ?' );
235 CALL q.execute(CGI.param('newtime'), CGI.param('id'));
240 q = DBI.prepare( 'UPDATE reporter.stage3 SET rerun = TRUE WHERE id = ?' );
241 CALL q.execute(rpt.id);
247 params = utils.JSON2perl( rpt.params );
248 s2_params = utils.JSON2perl( tmpl.params );
252 WRAPPER html/table style="border-collapse:collapse";
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;";
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;";
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;";
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";
276 INCLUDE html/cell content=rpt.runtime style="border:solid gray 1px;";
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;";
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 ' ';
288 IF user.id == rpt.owner;
289 INCLUDE anchor content='Run again' href=CGI.url('-path', 1) _ '?action=rerun&id=' _ rpt.id;
290 ' ';
292 INCLUDE anchor content='Enable' href=CGI.url('-path', 1) _ '?action=enable_stage3&id=' _ rpt.id;
294 INCLUDE anchor content='Disable' href=CGI.url('-path', 1) _ '?action=disable_stage3&id=' _ rpt.id;
296 ' ';
297 INCLUDE anchor content='Delete' href=CGI.url('-path', 1) _ '?action=delete_stage3&id=' _ rpt.id;
298 ' ';
307 type_map = { 'csv' => 'csv', 'excel' => 'xls', 'html' => 'html' };
310 '<b>Report Runs:</b>';
311 run_q = DBI.prepare("SELECT * FROM reporter.output WHERE stage3 = ? ORDER BY queue_time DESC");
312 FOR run = run_q.execute(rpt.id);
313 "<a name='$run.id'>";
314 WRAPPER html/table style="border-collapse:collapse";
316 INCLUDE html/cell content="<b>Current State</b>" style="border:solid gray 1px;" width="20%";
317 WRAPPER html/cell style="border:solid gray 1px;";
319 IF run.state == 'complete';
321 FOR f = params.output_format.list;
322 h = tmpl.stage1 _ '/' _ tmpl.id _
323 '/' _ rpt.id _ '/' _ run.id _
324 '/report-data.' _ type_map.$f;
325 link(content=f, href=h);
334 INCLUDE html/cell content="<b>Queue Time</b>" style="border:solid gray 1px;";
335 INCLUDE html/cell content=run.queue_time style="border:solid gray 1px;";
339 INCLUDE html/cell content="<b>Run Time</b>" style="border:solid gray 1px;";
340 INCLUDE html/cell content=run.run_time style="border:solid gray 1px;";
343 IF run.complete_time;
345 INCLUDE html/cell content="<b>Complete Time</b>" style="border:solid gray 1px;";
346 INCLUDE html/cell content=run.complete_time style="border:solid gray 1px;";
351 INCLUDE html/cell content="<b>Query</b>" style="border:solid gray 1px;";
352 INCLUDE html/cell content=run.query style="border:solid gray 1px;";
357 INCLUDE html/cell content="<b>Error</b>" style="border:solid gray 1px;";
358 INCLUDE html/cell content=run.error style="border:solid gray 1px;";
363 INCLUDE html/cell content="<b>Error Time</b>" style="border:solid gray 1px;";
364 INCLUDE html/cell content=run.error_time style="border:solid gray 1px;";
367 IF run.complete_time || run.error_time;
369 INCLUDE html/cell content="<b>Actions</b>" style="border:solid gray 1px;";
370 WRAPPER html/cell style="border:solid gray 1px;";
371 IF user.id == rpt.owner;
372 INCLUDE anchor content='Delete' href=CGI.url('-path', 1) _ '?action=delete_output&output=' _ run.id;
373 ' ';