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=open-ils-dev', 'postgres');
13 OpenILS::Application::Storage::CDBI->db_Main->{ AutoCommit } = 1;
17 #-------------------------------------------------------------------------------
19 #-------------------------------------------------------------------------------
22 Content-type: text/html
29 border: dashed lightgrey 1px;
30 background-color: #EEE;
31 border-collapse: collapse;
39 border: solid lightgrey 1px;
47 background-color: lightblue;
48 border: solid blue 1px;
53 <body style='padding: 25px;'>
55 <h1>Organizational Unit Type Setup</h1>
60 #-------------------------------------------------------------------------------
62 #-------------------------------------------------------------------------------
64 my %ou_cols = ( qw/id SysID name Name depth Depth parent ParentType can_have_vols CanHaveVolumes can_have_users CanHaveUsers/ );
66 my @col_display_order = ( qw/id name depth parent can_have_vols can_have_users/ );
68 #-------------------------------------------------------------------------------
70 #-------------------------------------------------------------------------------
72 if (my $action = $cgi->param('action')) {
73 if ( $action eq 'Remove Selected' ) {
74 for my $id ( ($cgi->param('id')) ) {
75 actor::org_unit_type->retrieve($id)->delete;
77 } elsif ( $action eq 'Update Selected' ) {
78 for my $id ( ($cgi->param('id')) ) {
79 my $u = actor::org_unit_type->retrieve($id);
80 for my $col (@col_display_order) {
81 $u->$col( $cgi->param($col."_$id") );
85 } elsif ( $action eq 'Add New' ) {
86 actor::org_unit_type->create( { map {defined($cgi->param($_)) ? ($_ => $cgi->param($_)) : () } @col_display_order } );
91 #-------------------------------------------------------------------------------
93 #-------------------------------------------------------------------------------
95 #-----------------------------------------------------------------------
97 #-----------------------------------------------------------------------
98 print "<form method='POST'>".
99 "<table class='table_class'><tr class='header_class'>\n";
101 for my $col ( @col_display_order ) {
102 print th($ou_cols{$col});
105 print '<th>Action</th></tr>';
107 for my $row ( sort { $a->depth <=> $b->depth } (actor::org_unit_type->retrieve_all) ) {
110 td("<input type='text' name='name_$row' value='". $row->name() ."'>"),
111 td("<input type='text' size=3 name='depth_$row' value='". $row->depth() ."'>"),
112 td("<select name='parent_$row'><option>-- Select One --</option>".do{
114 for my $type ( sort {$a->depth <=> $b->depth} actor::org_unit_type->retrieve_all) {
115 $out .= "<option value='$type' ".do{
116 if ($row->parent == $type->id) {
119 }.">".$type->name.'</option>'
123 td("<input type='checkbox' name='can_have_vols_$row' value='t' ". do{if($row->can_have_vols){"checked"}} .">"),
124 td("<input type='checkbox' name='can_have_users_$row' value='t' ". do{if($row->can_have_users){"checked"}} .">"),
125 td("<input type='checkbox' value='$row' name='id'>"),
129 print "<tr class='new_row_class'>",
131 td("<input type='text' name='name'>"),
132 td("<input type='text' size=3 name='depth'>"),
133 td("<select name='parent'><option>-- Select One --</option>".do{
135 for my $type ( sort {$a->depth <=> $b->depth} actor::org_unit_type->retrieve_all) {
136 $out .= "<option value='$type'>".$type->name.'</option>'
140 td("<input type='checkbox' name='can_have_vols' value='t'>"),
141 td("<input type='checkbox' name='can_have_users' value='t'>"),
145 print "<input type='submit' name='action' value='Remove Selected'/> | ";
146 print "<input type='submit' name='action' value='Update Selected'/> | ";
147 print "<input type='submit' name='action' value='Add New'/></form><hr/>";
150 print "</body></html>";