4 use OpenILS::Application::Storage;
5 use OpenILS::Application::Storage::CDBI;
7 # I need to abstract the driver loading away...
8 use OpenILS::Application::Storage::Driver::Pg;
10 use CGI qw/:standard start_*/;
12 OpenILS::Application::Storage::CDBI->connection('dbi:Pg:host=10.0.0.2;dbname=demo-dev', 'postgres');
13 OpenILS::Application::Storage::CDBI->db_Main->{ AutoCommit } = 1;
17 #-------------------------------------------------------------------------------
19 #-------------------------------------------------------------------------------
21 my %org_cols = ( qw/id GroupID name Name parent ParentGroup/ );
23 my @col_display_order = ( qw/id name parent/ );
25 if (my $action = $cgi->param('action')) {
26 if ( $action eq 'Update' ) {
27 for my $id ( ($cgi->param('id')) ) {
28 my $u = permission::grp_tree->retrieve($id);
29 for my $col ( keys %org_cols ) {
30 $u->$col( $cgi->param($col."_$id") );
34 } elsif ( $action eq 'Set Permissions' ) {
35 my $grp = permission::grp_tree->retrieve($cgi->param('perms'));
36 my @ids = $cgi->param('permission');
37 for my $perm ( permission::perm_list->retrieve_all ) {
38 if (my $id = $cgi->param('permission_'.$perm->id) ) {
39 my $p = permission::grp_perm_map->search({perm=>$id,grp=>$grp->id})->next;
40 my $d = $cgi->param("depth_$id");
42 $p = permission::grp_perm_map->create({perm=>$id,grp=>$grp->id,depth=>$d});
48 permission::grp_perm_map->search({perm=>$perm->id,grp=>$grp->id})->delete_all;
51 $cgi->param('action'=>'child');
52 } elsif ( $action eq 'Add New' ) {
53 permission::grp_tree->create( { map { defined($cgi->param($_)) ? ($_ => $cgi->param($_)) : () } keys %org_cols } );
57 #-------------------------------------------------------------------------------
59 #-------------------------------------------------------------------------------
62 Content-type: text/html
69 border: dashed lightgrey 1px;
70 background-color: #EEE;
71 border-collapse: collapse;
83 border: solid lightgrey 1px;
87 background-color: lightblue;
88 border: solid blue 1px;
93 <script language='javascript' src='/js/widgets/xtree.js'></script>
96 <body style='padding: 25px;'>
98 <h1>User Group Hierarchy Setup</h1>
102 my $uri = $cgi->url(-relative=>1);
105 for my $grp ( permission::grp_tree->search( {parent=>undef} ) ) {
106 my $name = $grp->name;
109 <div style="float: left;">
110 <script language='javascript'>
112 function getById (id) { return document.getElementById(id); }
113 function createAppElement (el) { return document.createElement(el); }
114 function createAppTextNode (txt) { return document.createTextNode(txt); }
116 var node_$grp = new WebFXTree('$name','$uri?action=child&id=$grp');
122 for my $grp ( permission::grp_tree->search_like( {parent => '%'}, {order_by => 'id'} ) ) {
123 my $name = $grp->name;
125 my $parent = $grp->parent;
127 var node_$grp = new WebFXTreeItem('$name','$uri?action=child&id=$grp');
131 for my $grp ( sort {$a->name cmp $b->name} permission::grp_tree->retrieve_all ) {
132 my $parent = $grp->parent;
135 node_$parent.add(node_$grp);
140 document.write(node_$top);
143 <div style="float:right; width:50%;">
147 #-------------------------------------------------------------------------------
149 #-------------------------------------------------------------------------------
151 if (my $action = $cgi->param('action')) {
152 if ( $action eq 'child' ) {
153 my $id = $cgi->param('id');
155 my $node = permission::grp_tree->retrieve($id);
156 #-----------------------------------------------------------------------
158 #-----------------------------------------------------------------------
160 print "<h2>Edit Group '".$node->name."'</h2>";
161 print "<form method='POST'>".
162 "<table class='table_class'><tr class='header_class'>\n";
170 td("<input type='text' name='name_$node' value=\"". $node->name() ."\">"),
173 th($org_cols{parent}),
174 td("<select name='parent_$node'>".do{
175 my $out = '<option>-- Select One --</option>';
176 for my $org ( sort {$a->id <=> $b->id} permission::grp_tree->retrieve_all) {
177 $out .= "<option value='$org' ".do {
178 if ($node->parent == $org->id) {
180 }}.'>'.$org->name.'</option>'
183 }."</select><input type='hidden' value='$node' name='id'>"),
186 print Tr( "<td colspan='2'><input type='submit' name='action' value='Update'/></td>" );
188 print "</table></form><hr/>";
191 print "<h2>Group Permissions</h2>";
193 print "<form method='POST'>".
194 "<table class='table_class'>\n".
195 "<tr class='header_class'><th>Permission</th><th>Select</th><th>At Depth</th></tr>";
197 for my $perm ( sort {$a->code cmp $b->code} permission::perm_list->retrieve_all ) {
199 my $out = '<select name="depth_'.$perm->id.'"><option value="">-- Select One --</option>';
200 for my $outype ( actor::org_unit_type->retrieve_all ) {
202 $out .= "<option value='".$outype->depth."' ".do{
206 my $setting = permission::grp_perm_map->search(
210 $stuff = "selected " if($setting && $outype->depth == $setting->depth);
211 if($stuff && $setting && $setting->grp != $node->id) {
212 $out =~ s/^<select/<select disabled/o;
215 } while (!$stuff && $grp && ($grp = $grp->parent));
217 }.">".$outype->name."</option>";
221 print Tr( "<td>".$perm->code."</td><td>".
222 "<input type='checkbox' name='permission_$perm' value='$perm' ".
227 my $setting = permission::grp_perm_map->search(
231 $stuff = "checked " if ($setting);
232 $stuff .= "disabled " if($setting && $setting->grp != $node->id);
234 } while (!$stuff && $grp && ($grp = $grp->parent));
237 "></td><td>$out</td>"
242 print Tr( "<td colspan='3'><input type='hidden' value='$node' name='perms'>",
243 "<input type='submit' name='action' value='Set Permissions'/></td>" );
244 print "</table></form><hr/>";
248 print "<h2>New Child</h2>";
250 print "<form method='POST'>".
251 "<table class='table_class'>\n";
255 td("<input type='text' name='name'>"),
257 print Tr( "<td colspan='2'><input type='hidden' value='$node' name='parent'>",
258 "<input type='submit' name='action' value='Add New'/></td>" );
259 print "</table></form><hr/>";
265 print "</div></body></html>";