From 3a0136c1e58f1ce2dc92fbab85e940b064f7a65c Mon Sep 17 00:00:00 2001
From: Chris Nighswonger <[EMAIL PROTECTED]>
Date: Fri, 20 Jun 2008 00:36:10 -0500
Subject: [PATCH] kohabug 2238 This patch allows patrons to add books to public open/free lists whether they are logged in or not.

---
 C4/Auth.pm                                         |   48 +++++++++++++-------
 C4/Context.pm                                      |   14 +++---
 koha-tmpl/opac-tmpl/prog/en/includes/masthead.inc  |    4 +-
 .../prog/en/modules/opac-addbybiblionumber.tmpl    |   10 +++-
 .../opac-tmpl/prog/en/modules/opac-results.tmpl    |    6 +-
 .../opac-tmpl/prog/en/modules/opac-shelves.tmpl    |    2 +-
 opac/opac-addbybiblionumber.pl                     |    7 ++-
 opac/opac-search.pl                                |    1 +
 8 files changed, 60 insertions(+), 32 deletions(-)

diff --git a/C4/Auth.pm b/C4/Auth.pm
index 9311c88..9a34809 100755
--- a/C4/Auth.pm
+++ b/C4/Auth.pm
@@ -144,10 +144,13 @@ sub get_template_and_user {
         # user info
         $template->param( loggedinusername => $user );
         $template->param( sessionID        => $sessionID );
-		my $shelves;
-		if ($shelves = C4::Context->get_shelves_userenv()) {
-        	$template->param( barshelves     => scalar (@$shelves));
-        	$template->param( barshelvesloop => $shelves);
+
+		my ($pubshelves, $barshelves);
+		if (($pubshelves, $barshelves) = C4::Context->get_shelves_userenv()) {
+        	$template->param( barshelves     => scalar (@$barshelves));
+        	$template->param( pubshelves     => scalar (@$pubshelves));
+        	$template->param( barshelvesloop => $barshelves);
+        	$template->param( pubshelvesloop => $pubshelves);
 		}
 
         $borrowernumber = getborrowernumber($user);
@@ -235,11 +238,13 @@ sub get_template_and_user {
         $template->param( js_widgets => $in->{'js_widgets'} );
 
         $template->param( sessionID        => $sessionID );
-		my $shelves;
-		if ($shelves = C4::Context->get_shelves_userenv()) {
-        	$template->param( barshelves     => scalar (@$shelves));
-        	$template->param( barshelvesloop => $shelves);
+		
+		my ($pubshelves);	# an anonymous user has no 'barshelves'...
+		if (($pubshelves) = C4::Context->get_shelves_userenv()) {
+        	$template->param( pubshelves     => scalar (@$pubshelves));
+        	$template->param( pubshelvesloop => $pubshelves);
 		}
+
 	}
 
     if ( $in->{'type'} eq "intranet" ) {
@@ -491,7 +496,7 @@ sub checkauth {
     # state variables
     my $loggedin = 0;
     my %info;
-    my ( $userid, $cookie, $sessionID, $flags, $shelves );
+    my ( $userid, $cookie, $sessionID, $flags, $barshelves, $pubshelves );
     my $logout = $query->param('logout.x');
 
     if ( $userid = $ENV{'REMOTE_USER'} ) {
@@ -515,7 +520,8 @@ sub checkauth {
                 $session->param('branchname'),   $session->param('flags'),
                 $session->param('emailaddress'), $session->param('branchprinter')
             );
-            C4::Context::set_shelves_userenv($session->param('shelves'));
+            C4::Context::set_shelves_userenv('bar',$session->param('barshelves'));
+            C4::Context::set_shelves_userenv('pub',$session->param('pubshelves'));
             $debug and printf STDERR "AUTH_SESSION: (%s)\t%s %s - %s\n", map {$session->param($_)} qw(cardnumber firstname surname branch) ;
             $ip       = $session->param('ip');
             $lasttime = $session->param('lasttime');
@@ -695,9 +701,16 @@ sub checkauth {
 					$session->param('branchname'),   $session->param('flags'),
 					$session->param('emailaddress'), $session->param('branchprinter')
 				);
-				$shelves = GetShelvesSummary($borrowernumber,2,10);
-				$session->param('shelves', $shelves);
-				C4::Context::set_shelves_userenv($shelves);
+
+				# Grab borrower's shelves and add to the session...
+				$barshelves = GetShelvesSummary($borrowernumber,2,10);
+				$session->param('barshelves', $barshelves);
+				C4::Context::set_shelves_userenv('bar',$barshelves);
+
+				# Grab the public shelves and add to the session...
+				$pubshelves = GetShelvesSummary(0,2,10);
+				$session->param('pubshelves', $pubshelves);
+				C4::Context::set_shelves_userenv('pub',$pubshelves);
 			}
         	else {
             	if ($userid) {
@@ -710,9 +723,12 @@ sub checkauth {
             # if we are here this is an anonymous session; add public lists to it and a few other items...
             # anonymous sessions are created only for the OPAC
 			$debug and warn "Initiating an anonymous session...";
-			$shelves = GetShelvesSummary(0,2,10);
-			$session->param('shelves', $shelves);
-			C4::Context::set_shelves_userenv($shelves);
+
+			# Grab the public shelves and add to the session...
+			$pubshelves = GetShelvesSummary(0,2,10);
+			$session->param('pubshelves', $pubshelves);
+			C4::Context::set_shelves_userenv('pub',$pubshelves);
+			
 			# setting a couple of other session vars...
 			$session->param('ip',$session->remote_addr());
 			$session->param('lasttime',time());
diff --git a/C4/Context.pm b/C4/Context.pm
index e81fd95..88bd1ad 100644
--- a/C4/Context.pm
+++ b/C4/Context.pm
@@ -901,20 +901,22 @@ sub set_userenv{
     return $cell;
 }
 
-sub set_shelves_userenv ($) {
-	my $lists = shift or return undef;
+sub set_shelves_userenv ($$) {
+	my ($type, $shelves) = @_ or return undef;
 	my $activeuser = $context->{activeuser} or return undef;
-	$context->{userenv}->{$activeuser}->{shelves} = $lists;
-	# die "set_shelves_userenv: $lists";
+	$context->{userenv}->{$activeuser}->{barshelves} = $shelves if $type eq 'bar';
+	$context->{userenv}->{$activeuser}->{pubshelves} = $shelves if $type eq 'pub';
 }
+
 sub get_shelves_userenv () {
 	my $active;
 	unless ($active = $context->{userenv}->{$context->{activeuser}}) {
 		warn "get_shelves_userenv cannot retrieve context->{userenv}->{context->{activeuser}}";
 		return undef;
 	}
-	my $lists = $active->{shelves} or return undef;#  die "get_shelves_userenv: activeenv has no ->{shelves}";
-	return $lists;
+	my $pubshelves = $active->{pubshelves} or undef;
+	my $barshelves = $active->{barshelves} or undef;#  die "get_shelves_userenv: activeenv has no ->{shelves}";
+	return $pubshelves, $barshelves;
 }
 
 =item _new_userenv
diff --git a/koha-tmpl/opac-tmpl/prog/en/includes/masthead.inc b/koha-tmpl/opac-tmpl/prog/en/includes/masthead.inc
index bc384f5..d9d5f64 100755
--- a/koha-tmpl/opac-tmpl/prog/en/includes/masthead.inc
+++ b/koha-tmpl/opac-tmpl/prog/en/includes/masthead.inc
@@ -88,9 +88,9 @@
 <div id="listsmenu" class="yuimenu" style="display: none">
     <div class="bd">
 	<h4>Public Lists</h4>
-		<!-- TMPL_IF NAME="barshelves" -->
+		<!-- TMPL_IF NAME="pubshelves" -->
 			<ul class="first-of-type">
-			<!-- TMPL_LOOP NAME="barshelvesloop" -->
+			<!-- TMPL_LOOP NAME="pubshelvesloop" -->
 			<!-- TMPL_UNLESS NAME="private" --><li class="yuimenuitem"><a href="/cgi-bin/koha/opac-shelves.pl?viewshelf=<!-- TMPL_VAR NAME="shelfnumber" -->"><!-- TMPL_VAR NAME="shelfname"  ESCAPE="html" --></a></li><!-- /TMPL_UNLESS -->
 			<!-- /TMPL_LOOP -->
 			</ul>   
diff --git a/koha-tmpl/opac-tmpl/prog/en/modules/opac-addbybiblionumber.tmpl b/koha-tmpl/opac-tmpl/prog/en/modules/opac-addbybiblionumber.tmpl
index 0617b22..5b5a003 100644
--- a/koha-tmpl/opac-tmpl/prog/en/modules/opac-addbybiblionumber.tmpl
+++ b/koha-tmpl/opac-tmpl/prog/en/modules/opac-addbybiblionumber.tmpl
@@ -8,6 +8,7 @@
 <body id="addtolist">
 <div id="custom-doc" class="yui-t7">
 <div class="container">
+<!-- TMPL_IF NAME="authorized" -->
 <!-- TMPL_UNLESS NAME="newshelf" --><!-- TMPL_IF NAME="multiple"-->
     <h1>Add <!-- TMPL_VAR NAME="total"--> items to <!-- TMPL_IF NAME="singleshelf" --><em><!-- TMPL_VAR NAME="shelfname" --></em>: <!-- TMPL_ELSE -->a list:<!-- /TMPL_IF --></h1>
 <!-- TMPL_ELSE -->
@@ -55,9 +56,14 @@
  <!-- TMPL_LOOP NAME="biblios" --> <input type="hidden" name="biblionumber" value="<!-- TMPL_VAR NAME="biblionumber" -->" /><!-- /TMPL_LOOP -->
     <fieldset class="action"><input type="submit" value="Save" class="submit" /> <a class="close cancel" href="#">Cancel</a></fieldset>
 </form><!-- /TMPL_UNLESS -->
-
+<!-- TMPL_ELSE -->
+<p align="center">
+	This is not an open list.
+	Items cannot be added to it.
+</p>
+<!-- /TMPL_IF -->
 <p align="center">
-    <a href="#" class="close">close this window.</a>
+    <a href="#" class="close">Close this window.</a>
 </p>
 </div></div>
 </body>
diff --git a/koha-tmpl/opac-tmpl/prog/en/modules/opac-results.tmpl b/koha-tmpl/opac-tmpl/prog/en/modules/opac-results.tmpl
index 352e9b6..a5f54c5 100644
--- a/koha-tmpl/opac-tmpl/prog/en/modules/opac-results.tmpl
+++ b/koha-tmpl/opac-tmpl/prog/en/modules/opac-results.tmpl
@@ -19,7 +19,7 @@ $(document).ready(function(){
     });
 	$("span.clearall").html("<a id=\"CheckNone\" href=\"#\">Clear All</a>");
 	$("span.checkall").html("<a id=\"CheckAll\" href=\"#\">Select All</a>");
-	$("span.addto").html("<label for=\"addto\">Add to: </label><select name=\"addto\" id=\"addto\"><option value=\"\"></option><!-- TMPL_IF name="opacbookbag" --><option value=\"addtocart\">Cart</option><!-- /TMPL_IF --><!-- TMPL_IF NAME="virtualshelves" --><!-- TMPL_IF NAME="loggedinusername" --><optgroup label=\"Lists:\"><!-- TMPL_IF NAME="barshelves" --><!-- TMPL_LOOP NAME="barshelvesloop" --><!-- TMPL_IF EXPR="category == 1" --><option id=\"s<!-- TMPL_VAR NAME="shelfnumber" -->\" value=\"addtolist\"><!-- TMPL_VAR NAME="shelfname" ESCAPE="html"--></option><!-- /TMPL_IF --><!-- /TMPL_LOOP --><!-- /TMPL_IF --><option value=\"newlist\">[ New List ]</option></optgroup><!-- TMPL_ELSE --><option value=\"newlist\">List</option><!-- /TMPL_IF --><!-- /TMPL_IF --></select> <input type=\"submit\" class=\"submit\" value=\"Save\" />");
+	$("span.addto").html("<label for=\"addto\">Add to: </label><select name=\"addto\" id=\"addto\"><option value=\"\"></option><!-- TMPL_IF name="opacbookbag" --><option value=\"addtocart\">Cart</option><!-- /TMPL_IF --><!-- TMPL_IF NAME="virtualshelves" --><!-- TMPL_IF NAME="loggedinusername" --><optgroup label=\"Your Lists:\"><!-- TMPL_IF NAME="barshelves" --><!-- TMPL_LOOP NAME="barshelvesloop" --><!-- TMPL_IF EXPR="category == 1" --><option id=\"s<!-- TMPL_VAR NAME="shelfnumber" -->\" value=\"addtolist\"><!-- TMPL_VAR NAME="shelfname" ESCAPE="html"--></option><!-- /TMPL_IF --><!-- /TMPL_LOOP --><!-- /TMPL_IF --></optgroup><optgroup label=\"Public Lists:\"><!-- TMPL_IF NAME="pubshelves" --><!-- TMPL_LOOP NAME="pubshelvesloop" --><option id=\"s<!-- TMPL_VAR NAME="shelfnumber" -->\" value=\"addtolist\"><!-- TMPL_VAR NAME="shelfname" ESCAPE="html"--></option><!-- /TMPL_LOOP --><!-- /TMPL_IF --></optgroup><option value=\"newlist\">[ New List ]</option><!-- TMPL_ELSE --><optgroup label=\"Public Lists:\"><!-- TMPL_IF NAME="pubshelves" --><!-- TMPL_LOOP NAME="pubshelvesloop" --><option id=\"s<!-- TMPL_VAR NAME="shelfnumber" -->\" value=\"addtolist\"><!-- TMPL_VAR NAME="shelfname" ESCAPE="html"--></option><!-- /TMPL_LOOP --><!-- /TMPL_IF --></optgroup><!-- /TMPL_IF --><!-- /TMPL_IF --></select> <input type=\"submit\" class=\"submit\" value=\"Save\" />");
 	$("#addto").change(function(){
 		cartList();
 	});
@@ -30,9 +30,9 @@ $(document).ready(function(){
 	function cartList(){
 			if($("#addto").find("option:selected").attr("value") == "addtolist"){
 			var shelfnumber = $("#addto").find("option:selected").attr("id").replace("s","");
-			<!-- TMPL_IF NAME="loggedinusername" -->if (vShelfAdd()) {
+			if (vShelfAdd()) {
 			Dopop('/cgi-bin/koha/opac-addbybiblionumber.pl?selectedshelf='+shelfnumber+'&' + vShelfAdd());
-			}<!-- TMPL_ELSE --> alert('You must be logged in to create or add to Lists'); <!-- /TMPL_IF -->
+			}
 			return false;			
 		} else if($("#addto").find("option:selected").attr("value") == "newlist"){
 			<!-- TMPL_IF NAME="loggedinusername" -->if (vShelfAdd()) {
diff --git a/koha-tmpl/opac-tmpl/prog/en/modules/opac-shelves.tmpl b/koha-tmpl/opac-tmpl/prog/en/modules/opac-shelves.tmpl
index bd67918..c744352 100644
--- a/koha-tmpl/opac-tmpl/prog/en/modules/opac-shelves.tmpl
+++ b/koha-tmpl/opac-tmpl/prog/en/modules/opac-shelves.tmpl
@@ -91,7 +91,7 @@ $.tablesorter.addParser({
 		<!-- TMPL_IF NAME="manageshelf" --><div><span class="checkall"></span>
 		<span class="clearall"></span> | <a class="editshelf" href="/cgi-bin/koha/opac-shelves.pl?shelfnumber=<!-- TMPL_VAR NAME="shelfnumber" -->&amp;op=modif">Edit List</a> <form method="post" action="opac-shelves.pl">
 <input type="hidden" value="1" name="shelves"/>
-<input type="hidden" value="1" name="DEL-1"/>
+<input type="hidden" value="1" name="DEL-<!-- TMPL_VAR NAME="shelfnumber" -->"/>
 <input type="submit" class="deleteshelf" value="Delete List" onclick="return confirmDelete(_('Are you sure you want to remove this List?'));"/></form>
 </div><!-- /TMPL_IF -->
     <!-- TMPL_IF NAME="manageshelf" --><form action="/cgi-bin/koha/opac-shelves.pl" method="post" name="myform" class="checkboxed">
diff --git a/opac/opac-addbybiblionumber.pl b/opac/opac-addbybiblionumber.pl
index 265827c..6104b5c 100755
--- a/opac/opac-addbybiblionumber.pl
+++ b/opac/opac-addbybiblionumber.pl
@@ -26,7 +26,6 @@ use strict;
 use C4::Biblio;
 use CGI;
 use C4::VirtualShelves;
-# use C4::Circulation;	# not really used
 use C4::Auth;
 use C4::Output;
 
@@ -49,6 +48,9 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
 
 $shelfnumber = AddShelf(  $newvirtualshelf, $loggedinuser, $category ) if $newvirtualshelf;
 
+# verify user is authorized to perform the action on the shelf...
+my $authorized = 1 if ( (ShelfPossibleAction( $loggedinuser, $selectedshelf )) );
+
 # multiple bibs might come in as '/' delimited string (from where, i don't see), or as array.
 
 my $multiple = 0;
@@ -59,7 +61,7 @@ if (scalar(@biblionumber) == 1) {
 if ($shelfnumber && ($shelfnumber != -1)) {
 	for my $bib (@biblionumber){
 		&AddToShelfFromBiblio($bib,$shelfnumber);
-	}
+	}	
 	print $query->header;
 	print "<html><body onload=\"window.close();\"><div>Please close this window to continue.</div></body></html>";
 	exit;
@@ -116,6 +118,7 @@ else {
 		multiple => (scalar(@biblios) > 1),
 		total    => scalar @biblios,
 		biblios  => [EMAIL PROTECTED],
+		authorized	=> $authorized,
 	);
 
 	output_html_with_http_headers $query, $cookie, $template->output;
diff --git a/opac/opac-search.pl b/opac/opac-search.pl
index b0e0e50..b03554e 100755
--- a/opac/opac-search.pl
+++ b/opac/opac-search.pl
@@ -58,6 +58,7 @@ else {
     authnotrequired => 1,
     }
 );
+
 if ($cgi->param("format") eq 'rss2') {
 	$template->param("rss2" => 1);
 }
-- 
1.5.5.GIT

_______________________________________________
Koha-patches mailing list
[email protected]
http://lists.koha.org/mailman/listinfo/koha-patches

Reply via email to