yay! the reporter spits out csv and excel now ... html tomorrow (with any luck)
[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 rpt = {};
12 tmpl = {};
13
14
15 IF CGI.param('id');
16         rid = CGI.param('id');
17         rpt = reports.$rid;
18         tid = rpt.stage2;
19         tmpl = templates.$tid;
20 END;
21
22
23 WRAPPER html/html;
24    INCLUDE header.ttk + navbar.ttk title="Reports";
25    WRAPPER html/body;
26       IF CGI.param('action') == 'Schedule';
27          PROCESS schedule_stage3;
28       ELSIF CGI.param('action') == 'Save';
29          PROCESS save_stage3;
30       ELSIF CGI.param('action') == 'Run Now';
31          PROCESS save_stage3;
32                 ELSIF CGI.param('id');
33                         PROCESS view_stage3;
34                 ELSE;
35                         PROCESS list_stage3s;
36       END;
37    END;
38    INCLUDE footer.ttk;
39 END;
40
41
42 BLOCK schedule_stage3;
43         WRAPPER form method='POST';
44                 'Run Date:';
45                 INCLUDE text name='runtime' value='yyyy-mm-dd';
46                 '<br>';
47
48                 'Optional Recurrence:';
49                 INCLUDE text name='recurrence-count' value='0';
50                 WRAPPER select name='recurrence-interval';
51                         INCLUDE option value='days' content='Day(s)';
52                         INCLUDE option value='weeks' content='Week(s)';
53                         INCLUDE option value='months' content='Month(s)';
54                 END;
55
56                 FOR p = CGI.param();
57                         NEXT IF p == 'action';
58                         NEXT IF p == 'runtime';
59                         INCLUDE hidden name=p value=CGI.param(p);
60                 END;
61                 '<br>';
62                 INCLUDE submit name='action' value='Save';
63         END;
64 END;
65
66 BLOCK list_stage3s;
67 END;
68
69
70 BLOCK save_stage3;
71         stage2 = CGI.param('stage2');
72         runtime = CGI.param('runtime') OR 'now';
73         pub = CGI.param('publicreport') OR 'f';
74         owner = user.id();
75
76         p_obj = {};
77         FOR p = CGI.param();
78
79                 logme([p,CGI.param(p)]);
80
81                 parts = p.split(':');
82                 p1 = parts.0;
83                 p2 = parts.1;
84                 p3 = parts.2;
85                 p4 = parts.3;
86                 p5 = parts.4;
87                 p6 = parts.5;
88                 
89                 IF p6;
90
91                         IF p_obj.$p1.$p2.$p3.$p4.$p5.$p6.defined;
92                                 IF p_obj.$p1.$p2.$p3.$p4.$p5.$p6.size > 1;
93                                         p_obj.$p1.$p2.$p3.$p4.$p5.$p6.push(CGI.param(p));
94                                 ELSE;
95                                         tmp = [ p_obj.$p1.$p2.$p3.$p4.$p5.$p6, CGI.param(p) ];
96                                         p_obj.$p1.$p2.$p3.$p4.$p5.$p6 = tmp;
97                                 END;
98                         ELSE;
99                                 p_obj.$p1.$p2.$p3.$p4.$p5.$p6 = CGI.param(p);
100                         END;
101
102                 ELSIF p5;
103
104                         IF p_obj.$p1.$p2.$p3.$p4.$p5.defined;
105                                 IF p_obj.$p1.$p2.$p3.$p4.$p5.size > 1;
106                                         p_obj.$p1.$p2.$p3.$p4.$p5.push(CGI.param(p));
107                                 ELSE;
108                                         tmp = [ p_obj.$p1.$p2.$p3.$p4.$p5, CGI.param(p) ];
109                                         p_obj.$p1.$p2.$p3.$p4.$p5 = tmp;
110                                 END;
111                         ELSE;
112                                 p_obj.$p1.$p2.$p3.$p4.$p5 = CGI.param(p);
113                         END;
114
115                 ELSIF p4;
116
117                         IF p_obj.$p1.$p2.$p3.$p4.defined;
118                                 IF p_obj.$p1.$p2.$p3.$p4.size > 1;
119                                         p_obj.$p1.$p2.$p3.$p4.push(CGI.param(p));
120                                 ELSE;
121                                         tmp = [ p_obj.$p1.$p2.$p3.$p4, CGI.param(p) ];
122                                         p_obj.$p1.$p2.$p3.$p4 = tmp;
123                                 END;
124                         ELSE;
125                                 p_obj.$p1.$p2.$p3.$p4 = CGI.param(p);
126                         END;
127
128                 ELSIF p3;
129
130                         IF p_obj.$p1.$p2.$p3.defined;
131                                 IF p_obj.$p1.$p2.$p3.size > 1;
132                                         p_obj.$p1.$p2.$p3.push(CGI.param(p));
133                                 ELSE;
134                                         tmp = [ p_obj.$p1.$p2.$p3, CGI.param(p) ];
135                                         p_obj.$p1.$p2.$p3 = tmp;
136                                 END;
137                         ELSE;
138                                 p_obj.$p1.$p2.$p3 = CGI.param(p);
139                         END;
140
141                 ELSIF p2;
142
143                         IF p_obj.$p1.$p2.defined;
144                                 IF p_obj.$p1.$p2.size > 1;
145                                         p_obj.$p1.$p2.push(CGI.param(p));
146                                 ELSE;
147                                         tmp = [ p_obj.$p1.$p2, CGI.param(p) ];
148                                         p_obj.$p1.$p2 = tmp;
149                                 END;
150                         ELSE;
151                                 p_obj.$p1.$p2 = CGI.param(p);
152                         END;
153
154                 ELSE;
155
156                         p_obj.$p = CGI.param(p);
157
158                 END;
159         END;
160
161         params = utils.perl2JSON( p_obj );
162
163         recurrence = '0 sec';
164         IF CGI.param('recurrence-count') > 0;
165                 recurrence = CGI.param('recurrence-count') _ ' ' _ CGI.param('recurrence-interval');
166         END;
167
168         logme([stage2, params, owner, pub]);
169
170         q = DBI.prepare( stage3_insert );
171         CALL q.execute(stage2, params, owner, pub, runtime, recurrence);
172
173         FOR new_s3 = DBI.query("SELECT * FROM reporter.stage3_id_seq;");
174                 tid = new_s3.last_value;
175                 INCLUDE view_stage3 rpt = reports.$tid;
176         END;
177 END;
178
179
180
181
182 BLOCK view_stage3;
183         logme(rpt.params);
184         params = utils.JSON2perl( rpt.params );
185         s2_params = utils.JSON2perl( tmpl.params );
186
187
188         WRAPPER html/center;
189                 WRAPPER html/table style="border-collapse:collapse";
190                         WRAPPER html/row;
191                                 INCLUDE html/cell content="<b>Report Name</b>" style="border:solid gray 1px;";
192                                 INCLUDE html/cell content=params.reportname style="border:solid gray 1px;";
193                         END;
194                         WRAPPER html/row;
195                                 INCLUDE html/cell content="<b>Based on Template</b>" style="border:solid gray 1px;";
196                                 INCLUDE html/cell content=s2_params.templatename style="border:solid gray 1px;";
197                         END;
198                         WRAPPER html/row;
199                                 INCLUDE html/cell content="<b>Creation Time</b>" style="border:solid gray 1px;";
200                                 INCLUDE html/cell content=rpt.create_date style="border:solid gray 1px;";
201                         END;
202                         WRAPPER html/row;
203                                 INCLUDE html/cell content="<b>Scheduled Run Time</b>" style="border:solid gray 1px;";
204                                 INCLUDE html/cell content=rpt.runtime style="border:solid gray 1px;";
205                         END;
206                         WRAPPER html/row;
207                                 INCLUDE html/cell content="<b>Recurrence Interval</b>" style="border:solid gray 1px;";
208                                 INCLUDE html/cell content=rpt.recurrence style="border:solid gray 1px;";
209                         END;
210                 END;
211         END;
212
213         '<br><br>';
214
215         type_map = { 'csv' => 'csv', 'excel' => 'xls', 'html' => 'html' };
216
217         WRAPPER html/center;
218                 '<b>Report Runs:</b>';
219                 run_q = DBI.prepare("SELECT * FROM reporter.output WHERE stage3 = ? ORDER BY queue_time DESC");
220                 FOR run = run_q.execute(rpt.id);
221                         WRAPPER html/table style="border-collapse:collapse";
222                                 WRAPPER html/row;
223                                         INCLUDE html/cell content="<b>Current State</b>" style="border:solid gray 1px;" width="20%";
224                                         WRAPPER html/cell style="border:solid gray 1px;";
225                                                 run.state;
226                                                 IF run.state == 'complete';
227                                                         '<br>';
228                                                         FOR f = params.output_format.list;
229                                                                 h = tmpl.stage1 _ '/' _ tmpl.id _
230                                                                         '/' _ rpt.id _ '/' _ run.id _
231                                                                         '/report-data.' _ type_map.$f;
232                                                                 link(content=f, href=h);
233                                                                 IF !loop.last;
234                                                                         '  |  ';
235                                                                 END;
236                                                         END;
237                                                 END;
238                                         END;
239                                 END;
240                                 WRAPPER html/row;
241                                         INCLUDE html/cell content="<b>Queue Time</b>" style="border:solid gray 1px;";
242                                         INCLUDE html/cell content=run.queue_time style="border:solid gray 1px;";
243                                 END;
244                                 IF run.run_time;
245                                         WRAPPER html/row;
246                                                 INCLUDE html/cell content="<b>Run Time</b>" style="border:solid gray 1px;";
247                                                 INCLUDE html/cell content=run.run_time style="border:solid gray 1px;";
248                                         END;
249                                 END;
250                                 IF run.complete_time;
251                                         WRAPPER html/row;
252                                                 INCLUDE html/cell content="<b>Complete Time</b>" style="border:solid gray 1px;";
253                                                 INCLUDE html/cell content=run.complete_time style="border:solid gray 1px;";
254                                         END;
255                                 END;
256                                 IF run.query;
257                                         WRAPPER html/row;
258                                                 INCLUDE html/cell content="<b>Query</b>" style="border:solid gray 1px;";
259                                                 INCLUDE html/cell content=run.query style="border:solid gray 1px;";
260                                         END;
261                                 END;
262                                 IF run.error;
263                                         WRAPPER html/row;
264                                                 INCLUDE html/cell content="<b>Error</b>" style="border:solid gray 1px;";
265                                                 INCLUDE html/cell content=run.error style="border:solid gray 1px;";
266                                         END;
267                                 END;
268                                 IF run.error_time;
269                                         WRAPPER html/row;
270                                                 INCLUDE html/cell content="<b>Error Time</b>" style="border:solid gray 1px;";
271                                                 INCLUDE html/cell content=run.error_time style="border:solid gray 1px;";
272                                         END;
273                                 END;
274                         END;
275                         '<br><br>';
276                 END;
277         END;
278 END;
279
280 %]