adding hours of operation
authormiker <miker@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Thu, 20 Apr 2006 03:49:44 +0000 (03:49 +0000)
committermiker <miker@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Thu, 20 Apr 2006 03:49:44 +0000 (03:49 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@3760 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/src/cgi-bin/lib-setup.cgi
Open-ILS/src/perlmods/OpenILS/Application/Storage/CDBI/actor.pm
Open-ILS/src/perlmods/OpenILS/Application/Storage/Driver/Pg/dbi.pm
Open-ILS/src/sql/Pg/005.schema.actors.sql

index 9be5b20..4e54f5e 100755 (executable)
@@ -1,6 +1,7 @@
 #!/usr/bin/perl
 use strict;
 
+use DateTime;
 use OpenILS::Application::Storage;
 use OpenILS::Application::Storage::CDBI;
 
@@ -9,11 +10,13 @@ use OpenILS::Application::Storage::Driver::Pg;
 
 use CGI qw/:standard start_*/;
 our %config;
-do '##CONFIG##/live-db-setup.pl';
+#do '##CONFIG##/live-db-setup.pl';
+do '/openils/conf/live-db-setup.pl';
 
 OpenILS::Application::Storage::CDBI->connection($config{dsn},$config{usr},$config{pw});
 OpenILS::Application::Storage::CDBI->db_Main->{ AutoCommit } = 1;
 
+
 my $cgi = new CGI;
 
 #-------------------------------------------------------------------------------
@@ -34,6 +37,14 @@ if (my $action = $cgi->param('action')) {
                        }
                        $u->update;
                }
+       } elsif ( $action eq 'Update Hours' ) {
+               for my $id ( ($cgi->param('id')) ) {
+                       my $hoo = actor::org_unit::hours_of_operation->retrieve($id);
+                       for my $col ( $hoo->columns('Essential') ) {
+                               $hoo->$col( $cgi->param($col) );
+                       }
+                       $hoo->update;
+               }
        } elsif ( $action eq 'Add New' ) {
                actor::org_unit->create( { map { defined($cgi->param($_)) ? ($_ => $cgi->param($_)) : () } keys %org_cols } );
        } elsif ( $action eq 'Save Address' ) {
@@ -162,7 +173,7 @@ for my $lib ( actor::org_unit->search( {parent_ou=>undef} ) ) {
        $name =~ s/'/\\'/og;
        $top = $lib->id;
        print <<"       HEADER";
-<div style="float: left;">
+<div>
        <script language='javascript'>
        var tree = new dTree("tree");
        tree.add($lib, -1, "$name", "$uri?action=child&id=$lib", "$name");
@@ -200,7 +211,7 @@ if (my $action = $cgi->param('action')) {
                        # child form
                        #-----------------------------------------------------------------------
 
-                       print "<h2>Edit ".$node->name."</h2>";
+                       print "<hr/><h2>Edit ".$node->name."</h2>";
                        print   "<form method='POST'>".
                                "<table class='table_class'><tr class='header_class'>\n";
        
@@ -244,14 +255,59 @@ if (my $action = $cgi->param('action')) {
                        );
 
                        print Tr( "<td colspan='2'><input type='submit' name='action' value='Update'/></td>" );
+                       print   "</table></form>";
+
+                       #-------------------------------------------------------------------------
+                       # Hours of operation form
+                       #-------------------------------------------------------------------------
+
+               
+                       
+                       my %dow = (
+                               0 => 'Monday',
+                               1 => 'Tuesday',
+                               2 => 'Wednesday',
+                               3 => 'Thursday',
+                               4 => 'Friday',
+                               5 => 'Saturday',
+                               6 => 'Sunday',
+                       );
+                               
+                       print "<hr/><h2>Hours of Operation for ".$node->name."</h2>".
+                               "<form method='POST'>".
+                               "<table class='table_class'><tr class='header_class'>\n";
 
-                       print   "</table></form><hr/><table cellspacing='20'><tr>";
+                       print Tr(
+                               th('Day of Week'),
+                               th('Open time'),
+                               th('Close time'),
+                       );
 
+                       my $hoo = actor::org_unit::hours_of_operation->find_or_create( { id => $node->id } );
+                       for my $day ( 0 .. 6 ) {
+                               my $open = "dow_${day}_open";
+                               my $close = "dow_${day}_close";
 
+                               print Tr(
+                                       th($dow{$day}),
+                                       td("<input type='text' name='$open' value=\"". $hoo->$open  ."\">"),
+                                       td("<input type='text' name='$close' value=\"". $hoo->$close ."\">"),
+                               );
+                       }
+
+                       print Tr( "<td colspan='3'>".
+                                 "<input type='hidden' value='$node' name='id'>".
+                                 "<input type='submit' name='action' value='Update Hours'/></td>"
+                       );
+                       print   "</table></form>";
+                       
+                       
                        #-------------------------------------------------------------------------
                        # Address edit form
                        #-------------------------------------------------------------------------
 
+                       print "<hr/><h2>Adresses for ".$node->name."</h2>";
+                       print   "<table cellspacing='20'><tr>";
                        my %addrs = (   ill_address     => 'ILL Address',
                                        holds_address   => 'Consortial Holds Address',
                                        mailing_address => 'Mailing Address',
@@ -271,7 +327,7 @@ if (my $action = $cgi->param('action')) {
                                                id              => $addr?$addr->id:'',
                                );
 
-                               print '</tr><tr>' if ($a eq 'holds_address');
+                               #print '</tr><tr>' if ($a eq 'holds_address');
                                print <<"                               TABLE";
 
 <td>
index 0b3d9b3..20af240 100644 (file)
@@ -78,6 +78,16 @@ __PACKAGE__->columns( Essential => qw/parent_ou ou_type mailing_address billing_
                                ill_address holds_address shortname name/);
 
 #-------------------------------------------------------------------------------
+package actor::org_unit::hours_of_operation;
+use base qw/actor/;
+
+__PACKAGE__->table( 'actor_hours_of_operation' );
+__PACKAGE__->columns( Primary => qw/id/);
+__PACKAGE__->columns( Essential => qw/dow_0_open dow_0_close dow_1_open dow_1_close dow_2_open dow_2_close
+                                       dow_3_open dow_3_close dow_4_open dow_4_close dow_5_open dow_5_close
+                                       dow_6_open dow_6_close/);
+
+#-------------------------------------------------------------------------------
 package actor::org_unit_setting;
 use base qw/actor/;
 
index 8553161..c4b7270 100644 (file)
        actor::org_unit_type->sequence( 'actor.org_unit_type_id_seq' );
 
        #---------------------------------------------------------------------
+       package actor::org_unit::hours_of_operation;
+       
+       actor::org_unit::hours_of_operation->table( 'actor.hours_of_operation' );
+
+       #---------------------------------------------------------------------
        package actor::org_unit;
        
        actor::org_unit->table( 'actor.org_unit' );
index 00ba21c..c98621e 100644 (file)
@@ -389,6 +389,24 @@ INSERT INTO actor.org_unit (parent_ou, ou_type, shortname, name) VALUES (3, 3, '
 INSERT INTO actor.org_unit (parent_ou, ou_type, shortname, name) VALUES (4, 4, 'SL1', 'Example Sub-lib 1');
 INSERT INTO actor.org_unit (parent_ou, ou_type, shortname, name) VALUES (6, 5, 'BM1', 'Example Bookmobile 1');
 
+CREATE TABLE actor.hours_of_operation (
+       id              INT     PRIMARY KEY REFERENCES actor.org_unit (id) ON DELETE CASCADE,
+       dow_0_open      TIME    NOT NULL DEFAULT '09:00',
+       dow_0_close     TIME    NOT NULL DEFAULT '17:00',
+       dow_1_open      TIME    NOT NULL DEFAULT '09:00',
+       dow_1_close     TIME    NOT NULL DEFAULT '17:00',
+       dow_2_open      TIME    NOT NULL DEFAULT '09:00',
+       dow_2_close     TIME    NOT NULL DEFAULT '17:00',
+       dow_3_open      TIME    NOT NULL DEFAULT '09:00',
+       dow_3_close     TIME    NOT NULL DEFAULT '17:00',
+       dow_4_open      TIME    NOT NULL DEFAULT '09:00',
+       dow_4_close     TIME    NOT NULL DEFAULT '17:00',
+       dow_5_open      TIME    NOT NULL DEFAULT '09:00',
+       dow_5_close     TIME    NOT NULL DEFAULT '17:00',
+       dow_6_open      TIME    NOT NULL DEFAULT '09:00',
+       dow_6_close     TIME    NOT NULL DEFAULT '17:00'
+);
+
 -- Workstation registration...
 CREATE TABLE actor.workstation (
        id              SERIAL  PRIMARY KEY,