90919af12c14f7bb2b765b5c232835217d1515af
[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;
101                         END;
102                 END;
103
104                 WRAPPER html/row;
105                         INCLUDE html/cell colspan=5 content="Filters:";
106                 END;
107
108                 FOR f_table IN params.filter.keys;
109                         logme([f_table]);
110                         table = config.findnodes( "/reporter/tables/table[@id='$f_table']");
111                         WRAPPER html/row;
112                                 INCLUDE html/cell;
113                                 INCLUDE html/cell colspan=4 align='left' content=table.findvalue( 'label' );
114                         END;
115
116                         FOR f_field IN params.filter.$f_table.keys;
117                                 logme([f_table,f_field]);
118                                 FOR f_fam IN params.filter.$f_table.$f_field.keys;
119                                         logme([f_table,f_field,f_fam]);
120                                         f_widget = params.filter.$f_table.$f_field.$f_fam;
121                                         logme([f_table,f_field,f_fam,f_widget]);
122
123                                         WRAPPER html/row;
124                                                 field = table.findnodes( "fields/field[@name='$f_field']" );
125                                                 fam = config.findnodes( "/reporter/widgets/widget-family[@name='$f_fam']" );
126                                                 widget = fam.findnodes( "widget[@name='$f_widget']" );
127
128                                                 INCLUDE html/cell colspan=2;
129                                                 INCLUDE html/cell align='right' content=field.findvalue( 'label' );
130                                                 INCLUDE html/cell align='center' content=fam.findvalue( 'label' );
131                                                 INCLUDE html/cell align='left' content=widget.findvalue( 'label' );
132                                         END;
133                                 END;
134                         END;
135                 END;
136
137                 WRAPPER html/row;
138                         INCLUDE html/cell colspan=5 content="Available Attributes:";
139                 END;
140
141         END;
142 END;
143
144
145
146
147
148 BLOCK run_stage2;
149
150 END;
151
152 %]