[Koha-patches] [PATCH] BUG 9163 - Cataloguing validation workflow

Vitor FERNANDES vitorfernandes87 at gmail.com
Wed Nov 28 16:58:36 CET 2012


Added 3 systems preferences instead of one:

- 1 to use/not use the validation workflow
- 1 to set the validation framework code
- 1 to set the users with access to the validation framework

addbook.pl and addbiblio.pl show the frameworkcodes in the drop list according to settings:

- if validation off shows all
- if validation on and framework code is different than validation framework code, shows the framework code
- if validation on and framework code equal to validation framework code and the user have permissions, shows the framework code
- if validation on and framework code equal to validation framework code and the user doesn't have permissions, don't shows the framework code

addbiblio.pl also changed to:

- prevent any user to use the validation framework (if validation on) when putting the code in the browser URL
- if validation on always set suppress = 1 in framework different than the validating one
---
 cataloguing/addbiblio.pl                           |   26 +++++++++++++++++---
 cataloguing/addbooks.pl                            |   25 +++++++++++++++----
 installer/data/mysql/sysprefs.sql                  |    3 +++
 installer/data/mysql/updatedatabase.pl             |    9 +++++++
 .../en/modules/admin/preferences/cataloguing.pref  |   19 +++++++++++++-
 5 files changed, 73 insertions(+), 9 deletions(-)

diff --git a/cataloguing/addbiblio.pl b/cataloguing/addbiblio.pl
index 2d591c6..03f9f87 100755
--- a/cataloguing/addbiblio.pl
+++ b/cataloguing/addbiblio.pl
@@ -22,8 +22,9 @@
 use strict;
 #use warnings; FIXME - Bug 2505
 use CGI;
+use CGI::Session;
 use C4::Output;
-use C4::Auth;
+use C4::Auth qw/:DEFAULT get_session/;
 use C4::Biblio;
 use C4::Search;
 use C4::AuthoritiesMarc;
@@ -718,7 +719,16 @@ my $dbh           = C4::Context->dbh;
 my $hostbiblionumber = $input->param('hostbiblionumber');
 my $hostitemnumber = $input->param('hostitemnumber');
 
-    
+# getting userID
+my $sessionID = $input->cookie("CGISESSID") ;
+my $session = get_session($sessionID);
+my $userid = $session->param('id');
+
+# getting validation variables
+my $validation = C4::Context->preference('CatalogingValidation');
+my $validationframework = C4::Context->preference('CatalogingValidationFramework');
+my %validationusers = map { $_ => 1 } split(/,/,C4::Context->preference('CatalogingValidationUsers'));
+ 
 my $userflags = 'edit_catalogue';
 if ($frameworkcode eq 'FA'){
     $userflags = 'fast_cataloging';
@@ -738,6 +748,10 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
     }
 );
 
+# Clear the framework code if validation is on and the framework code is equal to validation framework but the user is not authorized to use it
+# Avoid users to user validation framework adding the code to the URL
+$frameworkcode = '' if ($validation && ($frameworkcode eq $validationframework && !$validationusers{$userid}));
+
 if ($frameworkcode eq 'FA'){
     # We need to grab and set some variables in the template for use on the additems screen
     $template->{VARS}->{'circborrowernumber'} = $input->param('borrowernumber');
@@ -759,7 +773,11 @@ foreach my $thisframeworkcode ( keys %$frameworks ) {
 	if ($frameworkcode eq $thisframeworkcode){
 		$row{'selected'} = 1;
 		}
-	push @frameworkcodeloop, \%row;
+	# Add the framework code if validation is off.
+	# Add the framework code if validation is on, the framework code is equal to validation framework and the user is not authorized to use it
+	if (!$validation || ($validation && ($thisframeworkcode ne $validationframework || ($thisframeworkcode eq $validationframework && $validationusers{$userid})))) {
+		push @frameworkcodeloop, \%row;
+	}
 } 
 $template->param( frameworkcodeloop => \@frameworkcodeloop,
 	breedingid => $breedingid );
@@ -853,6 +871,8 @@ if ( $op eq "addbiblio" ) {
             ModBiblio( $record, $biblionumber, $frameworkcode );
         }
         else {
+	    # force 942$n = 1 when validation is on and isn't validation framework
+	    $record->field('942')->update('n' => '1') if ($validation && ($frameworkcode ne $validationframework));
             ( $biblionumber, $oldbibitemnum ) = AddBiblio( $record, $frameworkcode );
         }
         if ($redirect eq "items" || ($mode ne "popup" && !$is_a_modif && $redirect ne "view")){
diff --git a/cataloguing/addbooks.pl b/cataloguing/addbooks.pl
index 7bca2f3..efc57f7 100755
--- a/cataloguing/addbooks.pl
+++ b/cataloguing/addbooks.pl
@@ -27,7 +27,8 @@
 use strict;
 use warnings;
 use CGI;
-use C4::Auth;
+use CGI::Session;
+use C4::Auth qw/:DEFAULT get_session/;
 use C4::Biblio;
 use C4::Breeding;
 use C4::Output;
@@ -36,6 +37,16 @@ use C4::Search;
 
 my $input = new CGI;
 
+# getting userID
+my $sessionID = $input->cookie("CGISESSID");
+my $session = get_session($sessionID);
+my $userid = $session->param('id');
+
+# getting validation variables
+my $validation = C4::Context->preference('CatalogingValidation');
+my $validationframework = C4::Context->preference('CatalogingValidationFramework');
+my %validationusers = map { $_ => 1 } split(/,/,C4::Context->preference('CatalogingValidationUsers'));
+
 my $success = $input->param('biblioitem');
 my $query   = $input->param('q');
 my @value   = $input->param('value');
@@ -58,10 +69,14 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
 my $frameworks = getframeworks;
 my @frameworkcodeloop;
 foreach my $thisframeworkcode ( sort {$frameworks->{$a} cmp $frameworks->{$b}}keys %{$frameworks} ) {
-    push @frameworkcodeloop, {
-        value         => $thisframeworkcode,
-        frameworktext => $frameworks->{$thisframeworkcode}->{'frameworktext'},
-    };
+	# Add the framework code if validation is off.
+	# Add the framework code if validation is on, the framework code is equal to validation framework and the user is not authorized to use it
+	if (!$validation || ($validation && ($thisframeworkcode ne $validationframework || ($thisframeworkcode eq $validationframework && $validationusers{$userid})))) {
+		push @frameworkcodeloop, {
+	        	value         => $thisframeworkcode,
+			frameworktext => $frameworks->{$thisframeworkcode}->{'frameworktext'},
+	    	};
+	}
 }
 
 
diff --git a/installer/data/mysql/sysprefs.sql b/installer/data/mysql/sysprefs.sql
index 44f9eb3..8a84c46 100644
--- a/installer/data/mysql/sysprefs.sql
+++ b/installer/data/mysql/sysprefs.sql
@@ -387,3 +387,6 @@ INSERT INTO systempreferences (variable,value,explanation,type) VALUES('INTRAdid
 INSERT INTO systempreferences (variable, value, options, explanation, type) VALUES ('BlockReturnOfWithdrawnItems', '1', '0', 'If enabled, items that are marked as withdrawn cannot be returned.', 'YesNo');
 INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('HoldsToPullStartDate','2','Set the default start date for the Holds to pull list to this many days ago',NULL,'Integer');
 INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('alphabet','A B C D E F G H I J K L M N O P Q R S T U V W X Y Z','Alphabet than can be expanded into browse links, e.g. on Home > Patrons',NULL,'free');
+INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('CatalogingValidation', '0','Active cataloging validation',NULL,'YesNo');
+INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('CatalogingValidationFramework','','Cataloging validation framework',NULL,'long');
+INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('CatalogingValidationUsers', '','Cataloging validation users',NULL,'long');
diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl
index 966ec9b..11fe365 100755
--- a/installer/data/mysql/updatedatabase.pl
+++ b/installer/data/mysql/updatedatabase.pl
@@ -6083,6 +6083,15 @@ if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) {
     SetVersion($DBversion);
 }
 
+$DBversion = "XXX";
+if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) {
+    $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('CatalogingValidation', '0','Active cataloging validation',NULL,'YesNo');");
+    $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('CatalogingValidationFramework','','Cataloging validation framework',NULL,'long');");
+    $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('CatalogingValidationUsers', '','Cataloging validation users',NULL,'long');");
+    print "Upgrade to $DBversion done (Bug 9163 - Cataloguing validation workflow)\n";
+    SetVersion($DBversion);
+}
+
 =head1 FUNCTIONS
 
 =head2 TableExists($table)
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/cataloguing.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/cataloguing.pref
index 91f15c3..bf98eb7 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/cataloguing.pref
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/cataloguing.pref
@@ -156,4 +156,21 @@ Cataloging:
             - pref: OpacSuppressionByIPRange
               class: short
             - (Leave blank if not used. Define a range like <code>192.168.</code>.)
-
+    Validation:
+        -
+            - pref: CatalogingValidation
+              choices:
+                  yes: Use
+                  no: "Don't use"
+            - "cataloging validation. This allows some users to use a special MARC framework (only visible to them) to validate and put the record online in OPAC.<br />"
+            - "NOTE:<br /> - All MARC frameworks except the validation framework (set in CatalogingValidationFramework) needs to have the suppress subfield hidden.<br /> - The validation framework needs to have suppress subfield visible.<br />- The system preference OPACSuppresion needs to be on.<br /> - The users with access to the validation framework are set in CatalogingValidationUsers."
+        -
+            - "Code of the validation framework:"
+            - pref: CatalogingValidationFramework
+              class: long
+            - "<br />NOTE:<br /> - CatalogingValidation needs to be on.<br /> - The framework needs to be created in the MARC frameworks administration panel.<br /> - The framework needs to have suppress subfield visible."
+        -
+            - "The following users (list comma separated) will have access to validation framework:"
+            - pref: CatalogingValidationUsers
+              class: long
+            - "<br />NOTE:<br /> - CatalogingValidation needs to be on."
-- 
1.7.9.5



More information about the Koha-patches mailing list