b867855e4f0c5f1995f7624d8758ed15e8a29c24
[Evergreen.git] / Open-ILS / src / reporter / templates / stage2.ttk
1 [%
2
3 PROCESS inputs;
4 PROCESS logic_header.ttk;
5
6 templates = DBI.tie('reporter.stage2', 'id')
7 tmpl = {};
8
9
10 IF CGI.param('id');
11         tid = CGI.param('id');
12         tmpl = templates.$tid;
13 END;
14
15
16 WRAPPER html/html;
17    INCLUDE header.ttk title="Report Templates";
18    WRAPPER html/body;
19       INCLUDE logout.ttk;
20       IF CGI.param('action') == 'save';
21          PROCESS save_stage2;
22       ELSIF CGI.param('action') == 'edit';
23          PROCESS edit_stage2;
24       ELSIF CGI.param('action') == 'run';
25          PROCESS run_stage2;
26                 ELSE;
27          PROCESS view_stage2;
28       END;
29    END;
30    INCLUDE footer.ttk;
31 END;
32
33
34
35
36 BLOCK save_stage2;
37         stage1 = CGI.param('stage1');
38         pub = CGI.param('publictemplate') OR 'f';
39         owner = user.id();
40
41         p_obj = {};
42         FOR p IN CGI.param();
43
44                 logme([p,CGI.param(p)]);
45
46                 parts = p.split(':');
47                 p1 = parts.0;
48                 p2 = parts.1;
49                 p3 = parts.2;
50                 p4 = parts.3;
51                 
52                 IF p4
53                         AND (CGI.param("$p1:$p2:$p3") == p4)
54                         AND (CGI.param("$p1:$p2").list.grep("^$p3$"))
55                         AND (CGI.param("$p1").list.grep("^$p2$"));
56
57                         p_obj.$p1.$p2.$p3.$p4 = CGI.param(p);
58
59                 ELSIF p1 != 'filter';
60                         p_obj.$p1 = CGI.param(p);
61                 END;
62
63         END;
64
65         params = utils.perl2JSON( p_obj );
66
67         logme([stage1, params, owner, pub]);
68
69         q = DBI.prepare( stage2_insert );
70         junk = q.execute(stage1, params, owner, pub);
71
72         FOR new_s2 = DBI.query("SELECT * FROM reporter.stage2_id_seq;");
73                 tid = new_s2.last_value;
74                 INCLUDE view_stage2 tmpl = templates.$tid;
75         END;
76 END;
77
78
79
80
81 BLOCK edit_stage2;
82
83 END;
84
85
86
87
88
89 BLOCK view_stage2;
90         logme(tmpl.params);
91         params = utils.JSON2perl( tmpl.params );
92
93         WRAPPER html/table border=0 width='100%';
94                 WRAPPER html/row;
95                         WRAPPER html/cell colspan=5 align='center';
96                                 s1_name_xpath = '/reporter/tables/table[@id="' _ params.stage1 _ '"]/label';
97                                 INCLUDE anchor
98                                         text=config.findvalue( s1_name_xpath )
99                                         href="stage1?id=" _ params.stage1;
100                                 ' :: ' _ params.templatename _ '<br>';
101                                 INCLUDE anchor
102                                         text="Create a report from this template"
103                                         href=CGI.url('-path', 1, '-query', 1) _ '&action=run';
104                         END;
105                 END;
106
107                 WRAPPER html/row;
108                         INCLUDE html/cell colspan=5 content="Filters:";
109                 END;
110
111                 FOR f_table IN params.filter.keys;
112                         logme([f_table]);
113                         table = config.findnodes( "/reporter/tables/table[@id='$f_table']");
114                         WRAPPER html/row;
115                                 INCLUDE html/cell;
116                                 INCLUDE html/cell colspan=4 align='left' content=table.findvalue( 'label' );
117                         END;
118
119                         FOR f_field IN params.filter.$f_table.keys;
120                                 logme([f_table,f_field]);
121                                 FOR f_fam IN params.filter.$f_table.$f_field.keys;
122                                         logme([f_table,f_field,f_fam]);
123                                         f_widget = params.filter.$f_table.$f_field.$f_fam;
124                                         logme([f_table,f_field,f_fam,f_widget]);
125
126                                         WRAPPER html/row;
127                                                 field = table.findnodes( "fields/field[@name='$f_field']" );
128                                                 fam = config.findnodes( "/reporter/widgets/widget-family[@name='$f_fam']" );
129                                                 widget = fam.findnodes( "widget[@name='$f_widget']" );
130
131                                                 INCLUDE html/cell colspan=2;
132                                                 INCLUDE html/cell align='right' content=field.findvalue( 'label' );
133                                                 INCLUDE html/cell align='center' content=fam.findvalue( 'label' );
134                                                 INCLUDE html/cell align='left' content=widget.findvalue( 'label' );
135                                         END;
136                                 END;
137                         END;
138                 END;
139
140                 WRAPPER html/row;
141                         INCLUDE html/cell colspan=5 content="Available Attributes:";
142                 END;
143
144         END;
145 END;
146
147
148
149
150
151 BLOCK run_stage2;
152         logme(tmpl.params);
153         params = utils.JSON2perl( tmpl.params );
154
155    %]<br/><form id="stage3_new" name="stage3_new" action="stage3" method="POST">[%
156
157         WRAPPER html/table border=0 width='100%';
158                 WRAPPER html/row;
159                         WRAPPER html/cell colspan=4 align='center';
160                                 s1_name_xpath = '/reporter/tables/table[@id="' _ params.stage1 _ '"]/label';
161                                 INCLUDE anchor
162                                         text=config.findvalue( s1_name_xpath )
163                                         href="stage1?id=" _ params.stage1;
164                                 ' :: ' _ params.templatename;
165                         END;
166                 END;
167
168                 WRAPPER html/row;
169                         INCLUDE html/cell colspan=4 content="Filters:";
170                 END;
171
172                 FOR f_table IN params.filter.keys;
173                         logme([f_table]);
174                         table = config.findnodes( "/reporter/tables/table[@id='$f_table']");
175                         WRAPPER html/row;
176                                 INCLUDE html/cell;
177                                 INCLUDE html/cell colspan=3 align='left' content=table.findvalue( 'label' );
178                         END;
179
180                         FOR f_field IN params.filter.$f_table.keys;
181                                 logme([f_table,f_field]);
182                                 FOR f_fam IN params.filter.$f_table.$f_field.keys;
183                                         logme([f_table,f_field,f_fam]);
184                                         f_widget = params.filter.$f_table.$f_field.$f_fam;
185                                         logme([f_table,f_field,f_fam,f_widget]);
186
187                                         WRAPPER html/row;
188                                                 field = table.findnodes( "fields/field[@name='$f_field']" );
189                                                 fam = config.findnodes( "/reporter/widgets/widget-family[@name='$f_fam']" );
190                                                 widget = fam.findnodes( "widget[@name='$f_widget']" );
191
192                                                 w_file = 'widgets/' _ fam.findvalue('@name') _ '.' _ widget.findvalue('@name');
193                                                 INCLUDE html/cell colspan=2;
194                                                 INCLUDE html/cell align='right' content=field.findvalue( 'label' );
195
196                                                 WRAPPER html/cell align='center';
197                                                         TRY;
198                                                                         INCLUDE $w_file;
199                                                         CATCH;
200                                                                 %]ARG!! Couldn't render widget [% $w_file %] ([% error.info %])!!![%
201                                                         END;
202                                                 END;
203                                         END;
204                                 END;
205                         END;
206                 END;
207
208                 WRAPPER html/row;
209                         INCLUDE html/cell colspan=5 content="Available Attributes:";
210                 END;
211
212         END;
213
214         INCLUDE submit name="action" value="schedule";
215
216         %]</form>[%
217 END;
218
219 %]