[Koha-patches] [PATCH] Editing C4::Suggestions.pm

Henri-Damien LAURENT henridamien.laurent at biblibre.com
Tue Aug 25 23:56:16 CEST 2009


Enhancing C4::SearchSuggestion
And changing its API
Changing C4::Suggestions API taking a hashref for NewSuggestion and ModSuggestion
---
 C4/Letters.pm                                      |    1 +
 C4/Suggestions.pm                                  |  225 +++++-----------
 acqui/acqui-home.pl                                |    2 +-
 acqui/newordersuggestion.pl                        |    8 +-
 .../prog/en/modules/suggestion/suggestion.tmpl     |  283 ++++++++++++++++++++
 .../prog/en/modules/opac-suggestions.tmpl          |   26 ++-
 opac/opac-suggestions.pl                           |   94 +++----
 suggestion/suggestion.pl                           |  269 +++++++++++++++++++
 t/db_dependent/Suggestions.t                       |   24 ++
 9 files changed, 718 insertions(+), 214 deletions(-)
 create mode 100755 koha-tmpl/intranet-tmpl/prog/en/modules/suggestion/suggestion.tmpl
 create mode 100755 suggestion/suggestion.pl
 create mode 100644 t/db_dependent/Suggestions.t

diff --git a/C4/Letters.pm b/C4/Letters.pm
index 6d33b3f..535e87d 100644
--- a/C4/Letters.pm
+++ b/C4/Letters.pm
@@ -486,6 +486,7 @@ sub parseletter_sth {
     ($table eq 'reserves'     ) ? "SELECT * FROM $table WHERE borrowernumber = ? and biblionumber = ?" :
     ($table eq 'borrowers'    ) ? "SELECT * FROM $table WHERE borrowernumber = ?"                      :
     ($table eq 'branches'     ) ? "SELECT * FROM $table WHERE     branchcode = ?"                      :
+    ($table eq 'suggestions'  ) ? "SELECT * FROM $table WHERE borrowernumber = ? and biblionumber = ?" :
     ($table eq 'aqbooksellers') ? "SELECT * FROM $table WHERE             id = ?"                      : undef ;
     unless ($query) {
         warn "ERROR: No parseletter_sth query for table '$table'";
diff --git a/C4/Suggestions.pm b/C4/Suggestions.pm
index 491739c..b31772f 100644
--- a/C4/Suggestions.pm
+++ b/C4/Suggestions.pm
@@ -20,11 +20,14 @@ package C4::Suggestions;
 
 use strict;
 use CGI;
-use Mail::Sendmail;
 
 use C4::Context;
 use C4::Output;
 use C4::Dates qw(format_date);
+use C4::SQLHelper qw(:all);
+use C4::Debug;
+use C4::Letters;
+use List::MoreUtils qw(any);
 use vars qw($VERSION @ISA @EXPORT);
 
 BEGIN {
@@ -39,7 +42,7 @@ BEGIN {
 		&GetSuggestionByStatus
 		&DelSuggestion
 		&CountSuggestion
-		&ModStatus
+		&ModSuggestion
 		&ConnectSuggestionAndBiblio
 		&GetSuggestionFromBiblionumber
 	);
@@ -72,7 +75,7 @@ Suggestions done by other borrowers can be seen when not "AVAILABLE"
 
 =head2 SearchSuggestion
 
-(\@array) = &SearchSuggestion($user,$author,$title,$publishercode,$status,$suggestedbyme,$branchcode)
+(\@array) = &SearchSuggestion($suggestionhashref_to_search)
 
 searches for a suggestion
 
@@ -85,9 +88,10 @@ Note the status is stored twice :
 =cut
 
 sub SearchSuggestion  {
-    my ($user,$author,$title,$publishercode,$status,$suggestedbyme,$branchcode)=@_;
+    my ($suggestion)=@_;
     my $dbh = C4::Context->dbh;
-    my $query = "
+	my @sql_params;
+    my @query =(q{ 
     SELECT suggestions.*,
         U1.branchcode   AS branchcodesuggestedby,
         B1.branchname AS branchnamesuggestedby,
@@ -107,62 +111,44 @@ sub SearchSuggestion  {
     LEFT JOIN categories AS C1 ON C1.categorycode = U1.categorycode
     LEFT JOIN branches AS B1 ON B1.branchcode = U1.branchcode
     LEFT JOIN branches AS B2 ON B2.branchcode = U2.branchcode
-    WHERE 1=1 ";
+	WHERE status NOT IN ('CLAIMED')
+	} , map {
+	    if ( my $s = $$suggestion{$_} ) {
+		push @sql_params,'%'.$s.'%'; 
+		" and suggestions.$_ like ? ";
+	    } else { () }
+	} qw( title author isbn publishercode collectiontitle )
+	);
 
-    my @sql_params;
-    if ($author) {
-       push @sql_params,"%".$author."%";
-       $query .= " and author like ?";
-    }
-    if ($title) {
-        push @sql_params,"%".$title."%";
-        $query .= " and suggestions.title like ?";
+	my $userenv = C4::Context->userenv;
+    if (C4::Context->preference('IndependantBranches')) {
+			if ($userenv) {
+				if (($userenv->{flags} % 2) != 1 && !$$suggestion{branchcode}){
+				   push @sql_params,$$userenv{branch};
+				   push @query,q{ and (branchcode = ? or branchcode ='')};
+				}
+			}
     }
-    if ($publishercode) {
-        push @sql_params,"%".$publishercode."%";
-        $query .= " and publishercode like ?";
-    }
-    if (C4::Context->preference("IndependantBranches") || $branchcode) {
-        my $userenv = C4::Context->userenv;
-        if ($userenv) {
-            unless ($userenv->{flags} % 2 == 1){
-                push @sql_params,$userenv->{branch};
-                $query .= " and (U1.branchcode = ? or U1.branchcode ='')";
-            }
-        }
-        if ($branchcode) {
-            push @sql_params,$branchcode;
-            $query .= " and (U1.branchcode = ? or U1.branchcode ='')";
-        }
-    }
-    if ($status) {
-        push @sql_params,$status;
-        $query .= " and status=?";
-    }
-    if ($suggestedbyme) {
-        unless ($suggestedbyme eq -1) {
-            push @sql_params,$user;
-            $query .= " and suggestedby=?";
-        }
-    } else {
-        $query .= " and managedby is NULL";
+
+    foreach my $field (grep { my $fieldname=$_;
+		any {$fieldname eq $_ } qw<
+	status branchcode itemtype suggestedby managedby acceptedby
+	bookfundid biblionumber
+	>} keys %$suggestion
+    ) {
+		if ($$suggestion{$field}){
+			push @sql_params,$$suggestion{$field};
+			push @query, " and suggestions.$field=?";
+		} 
+		else {
+			push @query, " and (suggestions.$field='' OR suggestions.$field IS NULL)";
+		}
     }
-    my $sth=$dbh->prepare($query);
+
+	$debug && warn "@query";
+    my $sth=$dbh->prepare("@query");
     $sth->execute(@sql_params);
-    my @results;
-    my $even=1; # the even variable is used to set even / odd lines, for highlighting
-    while (my $data=$sth->fetchrow_hashref){
-        $data->{$data->{STATUS}} = 1;
-        if ($even) {
-            $even=0;
-            $data->{even}=1;
-        } else {
-            $even=1;
-        }
-#         $data->{date} = format_date($data->{date});
-        push(@results,$data);
-    }
-    return (\@results);
+	return ($sth->fetchall_arrayref({}));
 }
 
 =head2 GetSuggestion
@@ -234,8 +220,8 @@ sub GetSuggestionByStatus {
                         U1.firstname AS firstnamesuggestedby,
                         U1.branchcode AS branchcodesuggestedby,
                         B1.branchname AS branchnamesuggestedby,
-			U1.borrowernumber AS borrnumsuggestedby,
-			U1.categorycode AS categorycodesuggestedby,
+						U1.borrowernumber AS borrnumsuggestedby,
+						U1.categorycode AS categorycodesuggestedby,
                         C1.description AS categorydescriptionsuggestedby,
                         U2.surname   AS surnamemanagedby,
                         U2.firstname AS firstnamemanagedby,
@@ -265,7 +251,6 @@ sub GetSuggestionByStatus {
     
     my $results;
     $results=  $sth->fetchall_arrayref({});
-#     map{$_->{date} = format_date($_->{date})} @$results;
     return $results;
 }
 
@@ -335,117 +320,47 @@ sub CountSuggestion {
 =head2 NewSuggestion
 
 
-&NewSuggestion($borrowernumber,$title,$author,$publishercode,$note,$copyrightdate,$volumedesc,$publicationyear,$place,$isbn,$biblionumber)
+&NewSuggestion($suggestion)
 
 Insert a new suggestion on database with value given on input arg.
 
 =cut
 
 sub NewSuggestion {
-    my ($borrowernumber,$title,$author,$publishercode,$note,$copyrightdate,$volumedesc,$publicationyear,$place,$isbn,$biblionumber,$reason) = @_;
-    my $dbh = C4::Context->dbh;
-    my $query = qq |
-        INSERT INTO suggestions
-            (status,suggestedby,title,author,publishercode,note,copyrightdate,
-            volumedesc,publicationyear,place,isbn,biblionumber,reason)
-        VALUES ('ASKED',?,?,?,?,?,?,?,?,?,?,?,?)
-    |;
-    my $sth = $dbh->prepare($query);
-    $sth->execute($borrowernumber,$title,$author,$publishercode,$note,$copyrightdate,$volumedesc,$publicationyear,$place,$isbn,$biblionumber,$reason);
+    my ($suggestion) = @_;
+	return InsertInTable("suggestions",$suggestion); 
 }
 
-=head2 ModStatus
+=head2 ModSuggestion
 
-&ModStatus($suggestionid,$status,$managedby,$biblionumber)
+&ModSuggestion($suggestion)
 
-Modify the status (status can be 'ASKED', 'ACCEPTED', 'REJECTED', 'ORDERED')
-and send a mail to notify the user that did the suggestion.
+Modify the suggestion according to the hash passed by ref.
+The hash HAS to contain suggestionid
+Data not defined is not updated unless it is a note or sort1 
+Send a mail to notify the user that did the suggestion.
 
-Note that there is no function to modify a suggestion : only the status can be modified, thus the name of the function.
+Note that there is no function to modify a suggestion. 
 
 =cut
 
-sub ModStatus {
-    my ($suggestionid,$status,$managedby,$biblionumber,$reason) = @_;
-    my $dbh = C4::Context->dbh;
-    my $sth;
-    if ($managedby>0) {
-        if ($biblionumber) {
-        my $query = qq|
-            UPDATE suggestions
-            SET    status=?,managedby=?,biblionumber=?,reason=?
-            WHERE  suggestionid=?
-        |;
-        $sth = $dbh->prepare($query);
-        $sth->execute($status,$managedby,$biblionumber,$reason,$suggestionid);
-        } else {
-            my $query = qq|
-                UPDATE suggestions
-                SET    status=?,managedby=?,reason=?
-                WHERE  suggestionid=?
-            |;
-            $sth = $dbh->prepare($query);
-            $sth->execute($status,$managedby,$reason,$suggestionid);
-        }
-   } else {
-        if ($biblionumber) {
-            my $query = qq|
-                UPDATE suggestions
-                SET    status=?,biblionumber=?,reason=?
-                WHERE  suggestionid=?
-            |;
-            $sth = $dbh->prepare($query);
-            $sth->execute($status,$biblionumber,$reason,$suggestionid);
-        }
-        else {
-            my $query = qq|
-                UPDATE suggestions
-                SET    status=?,reason=?
-                WHERE  suggestionid=?
-            |;
-            $sth = $dbh->prepare($query);
-            $sth->execute($status,$reason,$suggestionid);
+sub ModSuggestion {
+    my ($suggestion)=@_;
+	my $status_update_table=UpdateInTable("suggestions", $suggestion);
+    # check mail sending.
+    if ($$suggestion{STATUS}){
+        my $letter=C4::Letters::getletter('suggestions',$$suggestion{STATUS});
+        if ($letter){
+        my $enqueued = C4::Letters::EnqueueLetter({
+            letter=>$letter,
+            borrowernumber=>$$suggestion{suggestedby},
+            suggestionid=>$$suggestion{suggestionid},
+            msg_transport_type=>'email'
+            });
+        if (!$enqueued){warn "can't enqueue letter $letter";}
         }
     }
-    # check mail sending.
-    my $queryMail = "
-        SELECT suggestions.*,
-            boby.surname AS bysurname,
-            boby.firstname AS byfirstname,
-            boby.email AS byemail,
-            lib.surname AS libsurname,
-            lib.firstname AS libfirstname,
-            lib.email AS libemail
-        FROM suggestions
-            LEFT JOIN borrowers AS boby ON boby.borrowernumber=suggestedby
-            LEFT JOIN borrowers AS lib ON lib.borrowernumber=managedby
-        WHERE suggestionid=?
-    ";
-    $sth = $dbh->prepare($queryMail);
-    $sth->execute($suggestionid);
-    my $emailinfo = $sth->fetchrow_hashref;
-    my $template = gettemplate("suggestion/mail_suggestion_$status.tmpl", "intranet", CGI->new());
-
-    $template->param(
-        byemail => $emailinfo->{byemail},
-        libemail => $emailinfo->{libemail},
-        status => $emailinfo->{status},
-        title => $emailinfo->{title},
-        author =>$emailinfo->{author},
-        libsurname => $emailinfo->{libsurname},
-        libfirstname => $emailinfo->{libfirstname},
-        byfirstname => $emailinfo->{byfirstname},
-        bysurname => $emailinfo->{bysurname},
-        reason => $emailinfo->{reason}
-    );
-    my %mail = (
-        To => $emailinfo->{byemail},
-        From => $emailinfo->{libemail},
-        Subject => 'Koha suggestion',
-        Message => "".$template->output,
-        'Content-Type' => 'text/plain; charset="utf8"',
-    );
-    sendmail(%mail);
+	return $status_update_table;
 }
 
 =head2 ConnectSuggestionAndBiblio
diff --git a/acqui/acqui-home.pl b/acqui/acqui-home.pl
index 339885d..22ee900 100755
--- a/acqui/acqui-home.pl
+++ b/acqui/acqui-home.pl
@@ -111,7 +111,7 @@ for ( my $i = 0 ; $i < $count ; $i++ ) {
 # suggestions
 my $status           = $query->param('status') || "ASKED";
 my $suggestion       = CountSuggestion($status);
-my $suggestions_loop = &SearchSuggestion( '', '', '', '', $status, '' );
+my $suggestions_loop = &SearchSuggestion( {status=> $status} );
 
 $template->param(
     classlist        => $classlist,
diff --git a/acqui/newordersuggestion.pl b/acqui/newordersuggestion.pl
index e56e521..7d53bc2 100755
--- a/acqui/newordersuggestion.pl
+++ b/acqui/newordersuggestion.pl
@@ -126,8 +126,12 @@ if ( $op eq 'connectDuplicate' ) {
 
 # getting all suggestions.
 my $suggestions_loop =
-  &SearchSuggestion( $borrowernumber, $author, $title, $publishercode,'ACCEPTED',
-    -1 );
+  &SearchSuggestion( 
+  				{ suggestedby 	=> $borrowernumber, 
+				author		  	=> $author, 
+				title			=> $title, 
+				publishercode	=> $publishercode,
+				status		    => 'ACCEPTED'});
 my $vendor = GetBookSellerFromId($supplierid);
 $template->param(
     suggestions_loop        => $suggestions_loop,
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/suggestion/suggestion.tmpl b/koha-tmpl/intranet-tmpl/prog/en/modules/suggestion/suggestion.tmpl
new file mode 100755
index 0000000..1784a29
--- /dev/null
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/suggestion/suggestion.tmpl
@@ -0,0 +1,283 @@
+<!-- TMPL_INCLUDE NAME="doc-head-open.inc" --><title><!-- TMPL_IF NAME="LibraryNameTitle" --><!-- TMPL_VAR NAME="LibraryNameTitle" --><!-- TMPL_ELSE -->Koha Online<!-- /TMPL_IF --> Catalog &rsaquo;  
+<!-- TMPL_IF name="op_save" --><!-- TMPL_IF name="suttesionid" -->Edit purchase suggestion #<!-- TMPL_VAR name="suggestionid" --><!--TMPL_ELSE-->Enter a new purchase suggestion<!-- /TMPL_IF --><!--TMPL_ELSE-->Suggestions<!-- /TMPL_IF --></title>
+<!-- TMPL_INCLUDE NAME="doc-head-close.inc" -->
+<!--TMPL_IF Name="op_else"--> <script type="text/javascript" src="<!-- TMPL_VAR name="themelang" -->/lib/jquery/plugins/jquery.tablesorter.min.js"></script>
+<script type="text/JavaScript">
+ // <![CDATA[
+
+   	function yuiToolbar() {
+	    new YAHOO.widget.Button("newsuggestion");
+	}
+  $.tablesorter.addParser({
+      id: 'articles', 
+      is: function(s) {return false;  }, 
+      format: function(s) { return s.toLowerCase().replace(/^(the|an|a) /,''); }, 
+      type: 'text' 
+  });
+  /**
+   *  displayOther.
+   *  This function display the select or an textaera to write a reason.
+   */
+  function displayOther(id,show,hide) {$("#"+hide+id).hide(); $("#"+show+id).show(); }
+  $(document).ready(function() {
+	  yuiToolbar();
+      $('#suggestiontabs > ul').tabs({
+      	select: function(ui) {
+            $("#loadingtab").show();
+        },
+        show: function(ui) {
+            $("#loadingtab").hide();
+        }
+    	});
+    $.tablesorter.defaults.widgets = ['zebra'];
+
+<!--TMPL_LOOP Name="suggestions"-->
+    $("#<!--TMPL_VAR Name="suggestiontype"-->t").tablesorter({<!-- TMPL_IF EXPR="dateformat eq 'metric'" -->
+    dateFormat: 'uk',<!-- /TMPL_IF -->
+      headers: {0:{sorter: false}, 1: { sorter: 'articles' },5:{sorter: false},6:{sorter: false},7:{sorter: false}, 8:{sorter: false},9:{sorter: false},10:{sorter: false}}
+    });
+    $("#CheckAll<!--TMPL_VAR Name="suggestiontype"-->").click(function(){
+        $("#<!--TMPL_VAR Name="suggestiontype"-->t :checkbox").attr('checked', $("#CheckAll<!--TMPL_VAR Name="suggestiontype"-->").is(':checked'));
+    });
+    $("div[id*=other_reason<!--TMPL_VAR Name="suggestiontype"-->]").hide();
+    $("input[name*=other_reason<!--TMPL_VAR Name="suggestiontype"-->]").focus(function(){ $(this).val(""); });
+    $("select[name*=reason<!--TMPL_VAR Name="suggestiontype"-->]").change(function(){
+      if($(this).children("[selected]").val() == "other"){
+      displayOther($(this).attr("name").replace(/reason/,""),"other_reason<!--TMPL_VAR Name="suggestiontype"-->","select-reason<!--TMPL_VAR Name="suggestiontype"-->");
+      }
+    });
+<!--/TMPL_LOOP-->
+    $("a[href*=back]").click(function(){
+      var sid = $(this).attr("href").replace(/#back/,"");
+      displayOther(sid,"select-reason","other_reason");
+      $("#reason"+sid).find("option[value='']").attr("selected","selected");
+    });
+  }); 
+// ]]>
+</script>
+<style type="text/css">
+.overlay { top: 180px; left: 50%; position: absolute; margin-left: -100px; width: 200px; text-align: center; display: none; margin-top: -10px; background: #eeffd4; padding : .5em; color: #000; }
+</style>
+<!--/TMPL_IF-->
+</head>
+<body>              
+<!-- TMPL_INCLUDE name="header.inc" -->
+<!-- TMPL_INCLUDE NAME="cat-search.inc" -->
+<div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo; <a href="/cgi-bin/koha/acqui/acqui-home.pl">Acquisitions</a> &rsaquo; <!-- TMPL_IF name="op_save" --><!-- TMPL_IF name="suggestionid" -->Suggestion edit #<!-- TMPL_VAR name="suggestionid" --><!--TMPL_ELSE-->New purchase suggestion<!-- /TMPL_IF --><!--TMPL_ELSE-->Suggestions<!-- /TMPL_IF --> </div>
+
+<div id="doc3" class="yui-t2">
+   <div id="bd">
+	<div id="yui-main">
+	<div class="yui-b">
+<!-- TMPL_IF name="op_save" -->
+    <form id="add_edit" action="suggestion.pl" method="post">
+<!-- TMPL_IF name="suggestionid" -->
+    <h1>Edit purchase suggestion #<!-- TMPL_VAR name="suggestionid" --></h1>
+    <input type="hidden" name="suggestionid" value="<!-- TMPL_VAR name="suggestionid" -->"/>
+<!--TMPL_ELSE-->  
+    <h1>Enter a new purchase suggestion</h1>
+<!--/TMPL_IF-->    
+   <fieldset class="rows"> <legend>Bibliographic information</legend><ol>
+    <li><label for="title">Title:</label><input type="text" id="title" name="title" size="50" maxlentgh="80" value="<!--TMPL_VAR Name="title"-->"/></li>
+    <li><label for="author">Author:</label><input type="text" id="author" name="author" size="50" maxlength="80" value="<!--TMPL_VAR Name="author"-->"/></li>
+    <li><label for="copyrightdate">Copyright date:</label><input type="text" id="copyrightdate" name="copyrightdate" size="4" maxlength="4" value="<!--TMPL_VAR Name="copyrightdate"-->" /></li>
+    <li><label for="isbn">ISBN or ISSN or other standard number:</label></label><input type="text" id="isbn" name="isbn" size="50" maxlength="80" value="<!--TMPL_VAR Name="isbn"-->"/></li>
+    <li><label for="publishercode">Publisher:</label><input type="text" id="publishercode" name="publishercode" size="50" maxlength="80" value="<!--TMPL_VAR Name="publishercode"-->"/></li>
+    <li><label for="place">Publication Place:</label><input type="text" id="place" name="place" size="50" maxlength="80" value="<!--TMPL_VAR Name="place"-->"/></li>
+    <li><label for="collectiontitle">Collection Title :</label></label><input type="text" id="collectiontitle" name="collectiontitle" size="50" maxlength="80" value="<!--TMPL_VAR Name="collectiontitle"-->"/></li>
+    <li><label for="itemtype">Document Type :</label><select name="itemtype" >
+      <!--TMPL_LOOP Name="itemtypeloop"--><!--TMPL_IF Name="selected"--><option selected="selected" value="<!--TMPL_VAR Name="code" -->"><!--TMPL_ELSE--><option value="<!--TMPL_VAR Name="code" -->"><!--/TMPL_IF--><!-- TMPL_IF name="imageurl"--><img border="0" src="<!--TMPL_VAR Name="imageurl" -->" alt="<!--TMPL_VAR Name="description" -->" /><!-- /TMPL_IF --><!--TMPL_VAR Name="description" --></option>
+      <!--/TMPL_LOOP-->
+        </select></li>
+    <li><label for="note">Notes:</label><textarea name="note" id="note" rows="5" cols="40" value="<!--TMPL_VAR Name="note"-->"></textarea></li>       
+    <li><label for="sort1">Sort1:</label><textarea name="sort1" id="sort1" rows="5" cols="40" value="<!--TMPL_VAR Name="sort1"-->"></textarea></li>       
+    </ol></fieldset>
+   <fieldset class="rows"> <legend>Suggestion management</legend><ol>
+    <!--TMPL_IF Name="suggestionid"--><li><label for="status"> status :</label><select name="status"><option value="">No Status</option>
+<!-- TMPL_LOOP name="status_loop" --><!-- TMPL_IF NAME="selected" --><option value="<!-- TMPL_VAR name="code" -->" selected="selected"><!-- TMPL_VAR name="desc" --></option><!-- TMPL_ELSE --><option value="<!-- TMPL_VAR name="code" -->"><!-- TMPL_VAR name="desc" --></option><!-- /TMPL_IF --><!-- /TMPL_LOOP --></select><!--/TMPL_IF-->
+	<table>
+	<thead><th>&nbsp;</th><th>date</th><th>by</th></thead>
+	<tbody>
+    <tr><td>Suggestion creation </td><td><input type="text" id="createdon" name="createdon" size="10" maxlentgh="10" value="<!--TMPL_VAR Name="createdon"-->"/></td>
+    <td><input type="hidden" id="suggestedby" name="suggestedby" value="<!--TMPL_VAR Name="suggestedby"-->"/><!-- TMPL_IF NAME="guarantorid" --><input id="guarantorsearch" type="button" value="Change" onclick="Dopopguarantor('guarantor_search.pl');" /><!-- TMPL_ELSE --><input id="guarantorsearch" type="button" value="Set to Patron" onclick="Dopopguarantor('guarantor_search.pl');" /><!-- /TMPL_IF -->
+            <input id="guarantordelete" type="button" value="Delete" /><!--TMPL_VAR Name="suggestedbyinformation"-->
+	</td>
+	</tr>
+    <tr><td>Suggestion management </td><td><input type="text" id="managedon" name="managedon" size="10" maxlength="10" value="<!--TMPL_VAR Name="managedon"-->" /></td>
+    <td><input type="hidden" id="managedby" name="managedby" value="<!--TMPL_VAR Name="managedby"-->"/><!--TMPL_VAR Name="managedbyinformation"--></td></tr>
+    <tr><td>Suggestion Accepted </td><td><input type="text" id="acceptedon" name="acceptedon" size="10" maxlength="10" value="<!--TMPL_VAR Name="acceptedon"-->" /></td>
+    <td><input type="hidden" id="acceptedby" name="acceptedby" value="<!--TMPL_VAR Name="acceptedby"-->"/><!--TMPL_VAR Name="acceptedbyinformation"--></td></tr>
+	</tbody>
+	</table>
+   </fieldset>   
+   <fieldset class="rows"> <legend>Acquisition information</legend><ol>
+    <li><label for="branchcode">Branchcode:</label> 
+        <select name="branchcode" id="branchcode">
+            <option value="">Any</option><!-- TMPL_LOOP name="branchloop" -->
+            <!-- TMPL_IF NAME="selected" --><option value="<!-- TMPL_VAR name="value" -->" selected="selected"><!-- TMPL_VAR name="branchname" --></option><!-- TMPL_ELSE --><option value="<!-- TMPL_VAR name="value" -->"><!-- TMPL_VAR name="branchname" --></option><!-- /TMPL_IF --><!-- /TMPL_LOOP -->
+        </select>
+    </li>
+    <li><label for="budgetid">Budget:</label>
+        <select name="budgetid" id="budgetid">
+            <option value="">Any</option><!-- TMPL_LOOP name="budgetsloop" -->
+            <!-- TMPL_IF NAME="selected" --><option value="<!-- TMPL_VAR name="budget_id" -->" selected="selected"><!-- TMPL_VAR name="budget_name" --></option><!-- TMPL_ELSE --><option value="<!-- TMPL_VAR name="budget_id" -->"><!-- TMPL_VAR name="budget_name" --></option><!-- /TMPL_IF --><!-- /TMPL_LOOP -->
+        </select>
+   </li>
+   </fieldset>   
+        <fieldset class="action"><input type="hidden" name="op" value="<!--TMPL_VAR Name="op"-->" /><!--TMPL_IF Name="suggestionid"--><input type="submit" value="Save" /><a class="action" href="suggestion.pl?suggestionid=<!--TMPL_VAR Name="suggestionid"-->">Cancel</a><!--TMPL_ELSE--><input type="submit" value="Submit Your Suggestion" /><a class="action" href="add.pl">Cancel</a><!--/TMPL_IF-->
+        </fieldset>
+    </form>
+<!-- /TMPL_IF -->
+
+<!-- TMPL_IF name="op_else" -->
+	  <div id="toolbar">
+      <ul class="toolbar">
+       <li> <a id="newsuggestion" href="suggestion.pl?op=add">New purchase suggestion</a></li>
+    </ul></div>
+<!--Filter block-->
+    <form name="suggestionfilter" action="suggestion.pl" method="get">
+<a onclick="javascript:if (document.getElementsByName('limits')[0].style.display=='none'){document.getElementsByName('limits')[0].style.display='block';} else {document.getElementsByName('limits')[0].style.display='none';}">Filters</a>
+				<div style="display:none;" name="limits">
+				<fieldset><legend> Bibliographic information : </legend>
+                    <label for="title"> Title :</label><input type="text" name="title" value="<!-- TMPL_VAR name="title"-->" />
+                    <label for="author"> Author :</label><input type="text" name="author" value="<!-- TMPL_VAR name="author"-->" />
+                    <label for="isbn"> isbn :</label><input type="text" name="isbn" value="<!-- TMPL_VAR name="isbn"-->" /><br/>
+                    <label for="publishercode"> Publisher :</label><input type="text" name="publishercode" value="<!-- TMPL_VAR name="publishercode"-->" />
+                    <label for="publicationyear"> Publication year :</label><input type="text" name="publicationyear" value="<!-- TMPL_VAR name="publicationyear"-->" />
+                    <label for="collectiontitle"> Collection Title :</label><input type="text" name="collectiontitle" value="<!-- TMPL_VAR name="collectiontitle"-->" />
+                </fieldset>
+                <fieldset><legend> Suggestion information: </legend>
+                    <label for="status"> status :</label><select name="status"><option value="">Any</option>
+<!-- TMPL_LOOP name="status_loop" --><!-- TMPL_IF NAME="selected" --><option value="<!-- TMPL_VAR name="code" -->" selected="selected"><!-- TMPL_VAR name="desc" --></option><!-- TMPL_ELSE --><option value="<!-- TMPL_VAR name="code" -->"><!-- TMPL_VAR name="desc" --></option><!-- /TMPL_IF --><!-- /TMPL_LOOP -->
+                                                          </select><br/>
+                    <label for="suggestedby"> suggested By :</label><select name="suggestedby"><option value="">Any</option>
+<!-- TMPL_LOOP name="suggestedby_loop" --><!-- TMPL_IF NAME="selected" --><option value="<!-- TMPL_VAR name="code" -->" selected="selected"><!-- TMPL_VAR name="desc" --></option><!-- TMPL_ELSE --><option value="<!-- TMPL_VAR name="code" -->"><!-- TMPL_VAR name="desc" --></option><!-- /TMPL_IF --><!-- /TMPL_LOOP -->
+                                                                     </select>
+                    <label for="suggestedon"> suggested on :</label><br/>
+                    <label for="managedby"> management user :</label><select name="suggestionmanagedby"><option value="">Any</option>
+<!-- TMPL_LOOP name="suggestionmanagedby_loop" --><!-- TMPL_IF NAME="selected" --><option value="<!-- TMPL_VAR name="code" -->" selected="selected"><!-- TMPL_VAR name="desc" --></option><!-- TMPL_ELSE --><option value="<!-- TMPL_VAR name="code" -->"><!-- TMPL_VAR name="desc" --></option><!-- /TMPL_IF --><!-- /TMPL_LOOP -->
+                                                                     </select>
+                    <label for="managedon"> management date :</label><br/>
+                    <label for="acceptedby"> Accepted by :</label><select name="suggestionacceptedby"><option value="">Any</option>
+<!-- TMPL_LOOP name="suggestionacceptedby_loop" --><!-- TMPL_IF NAME="selected" --> <option value="<!-- TMPL_VAR name="code" -->" selected="selected"><!-- TMPL_VAR name="desc" --></option><!-- TMPL_ELSE --><option value="<!-- TMPL_VAR name="code" -->"><!-- TMPL_VAR name="desc" --></option><!-- /TMPL_IF --><!-- /TMPL_LOOP -->
+		                                      </select>
+                    <label for="acceptedon"> Accepted on:</label>
+                </fieldset>
+                <fieldset ><legend> Acquistion information :</legend>
+                    <label for="bookfundid"> BookFund :</label><select name="bookfundid"><option value="">Any</option><!-- TMPL_LOOP name="bookfundsloop" -->
+        <!-- TMPL_IF NAME="selected" --> <option value="<!-- TMPL_VAR name="bookfundid" -->" selected="selected"><!-- TMPL_VAR name="bookfundname" --></option><!-- TMPL_ELSE --><option value="<!-- TMPL_VAR name="bookfundid" -->"><!-- TMPL_VAR name="bookfundname" --></option><!-- /TMPL_IF -->
+      <!-- /TMPL_LOOP --></select>
+                    <label for="branchcode"> For :</label><select name="branchcode" id="branchcode">
+        <option value="">Any</option><!-- TMPL_LOOP name="branchloop" -->
+		<!-- TMPL_IF NAME="selected" --> <option value="<!-- TMPL_VAR name="value" -->" selected="selected"><!-- TMPL_VAR name="branchname" --></option><!-- TMPL_ELSE --> <option value="<!-- TMPL_VAR name="value" -->"><!-- TMPL_VAR name="branchname" --></option><!-- /TMPL_IF -->
+      <!-- /TMPL_LOOP --></select>
+                </fieldset>
+				</div>
+                <label for="displayby">Organise By</label>
+                <select name="displayby" id="displayby">
+        <option value="">No tabs</option>
+        <option value="STATUS">status</option>
+        <option value="branchcode">Library</option>
+        <option value="itemtype">Item Type</option>
+        <option value="sort1">Sort1</option>
+        <option value="managedby">Managed by</option>
+        <option value="acceptedby">Accepted by</option>
+					</select><br/>
+                    <input type="submit" value="Search" />
+            </form>
+<!--TMPL_UNLESS Name="notabs"-->        
+  <div id="sorting" class="overlay">Sorting...</div>
+  <div id="loadingtab" class="overlay">Loading tab...</div>
+  <div id="suggestiontabs" class="toptabs">
+  <ul class="ui-tabs-nav">
+<!--TMPL_LOOP Name="suggestions"-->
+<!--TMPL_IF Name="first"--><li class="ui-tabs-selected"><!--TMPL_ELSE--><li><!--/TMPL_IF--><a href="suggestion.pl#<!--TMPL_VAR Name="suggestiontype"-->"><!--TMPL_IF Name="suggestiontypelabel"--><!--TMPL_VAR Name="suggestiontypelabel"--><!--TMPL_ELSE-->No name<!--/TMPL_IF--> (<!--TMPL_VAR Name="suggestionscount"-->)</a></li>
+<!--/TMPL_LOOP -->
+    </ul>
+	</div>
+<!--/TMPL_UNLESS -->        
+  
+ <!--TMPL_LOOP Name="suggestions"-->
+  <div id="<!--TMPL_VAR Name="suggestiontype"-->">
+<form name="f<!--TMPL_VAR Name="suggestiontype"-->" method="post" action="/cgi-bin/koha/suggestion/suggestion.pl#<!--TMPL_VAR Name="suggestiontype"-->">
+
+<!-- TMPL_IF NAME="suggestions_loop" -->
+    <table id="<!--TMPL_VAR Name="suggestiontype"-->t" >
+        <thead>
+            <th><input type="checkbox" id="CheckAll<!--TMPL_VAR Name="suggestiontype"-->" >Check <!--TMPL_IF Name="notabs"-->All <!--TMPL_ELSE-->tab <!--/TMPL_IF--></th>
+            <th>Suggestion</th>
+            <th>Suggested by /on</th>
+            <th>Managed by /on</th>
+            <th>For</th>
+            <th>Budget</th>
+            <th>Status</th>
+    </thead>
+        <tbody><!-- TMPL_LOOP NAME="suggestions_loop" -->
+            <!-- TMPL_IF name="even" --><tr class="highlight"><!-- TMPL_ELSE --><tr><!-- /TMPL_IF -->
+                <td>
+                    <input type="checkbox" name="edit_field" value="<!--TMPL_VAR name="suggestionid" -->" />
+                </td>
+                <td><a href="suggestion.pl?suggestionid=<!-- TMPL_VAR NAME="suggestionid" -->&op=edit" title="suggestion" >
+    <!-- TMPL_VAR NAME="title" --><!-- TMPL_IF NAME="author" -->, by <!-- TMPL_VAR NAME="author" --><!-- /TMPL_IF --></a><br />
+                    <!-- TMPL_IF name="copyrightdate" -->&copy; <!-- TMPL_VAR name="copyrightdate" --> <!-- /TMPL_IF -->
+                        <!-- TMPL_IF name="volumedesc" -->; Volume:<i><!-- TMPL_VAR name="volumedesc" --></i> <!-- /TMPL_IF -->
+                        <!-- TMPL_IF name="isbn" -->; ISBN :<i><!-- TMPL_VAR name="isbn" --></i> <!-- /TMPL_IF --><!-- TMPL_IF name="publishercode" -->; Published by <!-- TMPL_VAR name="publishercode" --> <!-- /TMPL_IF --><!-- TMPL_IF name="publicationyear" --> in <i><!-- TMPL_VAR name="publicationyear" --></i> <!-- /TMPL_IF --><!-- TMPL_IF name="place" --> in <i><!-- TMPL_VAR name="place" --></i> <!-- /TMPL_IF --><!-- TMPL_IF name="collectiontitle" -->;<!-- TMPL_VAR name="collectiontitle" --> <!-- /TMPL_IF --><!-- TMPL_IF name="itemtype" -->;<!-- TMPL_VAR name="itemtype" --> <!-- /TMPL_IF --><br /><!-- TMPL_IF name="note" --><!-- TMPL VAR NAME="note" --><!-- /TMPL_IF --><!-- TMPL_IF name="sort1" -->;<!-- TMPL_VAR name="sort1" --> <!-- /TMPL_IF -->
+                </td>
+                <td>
+                    <!--TMPL_IF Name="emailsuggestedby"--><a href="mailto:<!-- TMPL_VAR name="emailsuggestedby" -->"><!--/TMPL_IF--><!-- TMPL_VAR name="surnamesuggestedby" --><!-- TMPL_IF name="firstnamesuggestedby" -->, <!-- TMPL_VAR name="firstnamesuggestedby" --><!-- /TMPL_IF --> <!--TMPL_IF Name="emailsuggestedby"--></a><!--/TMPL_IF-->
+                    <!--TMPL_IF Name="createdon"--><br/><!-- TMPL_VAR name="createdon" --><!--/TMPL_IF-->
+                </td>
+                <td>
+                    <!--TMPL_IF Name="emailmanagedby"--><a href="mailto:<!-- TMPL_VAR name="emailmanagedby" -->"><!--/TMPL_IF--><!-- TMPL_VAR name="surnamemanagedby" --><!-- TMPL_IF name="firstnamemanagedby" -->, <!-- TMPL_VAR name="firstnamemanagedby" --><!-- /TMPL_IF --> <!--TMPL_IF Name="emailmanagedby"--></a><!--/TMPL_IF-->
+                    <!--TMPL_IF Name="managedon"--><br/><!-- TMPL_VAR name="managedon" --><!--/TMPL_IF-->
+                </td>
+                <td>
+                    <!-- TMPL_VAR name="branchcode" -->
+                </td>
+                <td>
+                    <!-- TMPL_VAR name="aqbudgetid" -->
+                </td>
+                <td>
+                    <!-- TMPL_IF name="ASKED" -->Requested<!-- /TMPL_IF --> <!-- TMPL_IF name="ACCEPTED" -->Accepted<!-- /TMPL_IF --> <!-- TMPL_IF name="ORDERED" -->Ordered<!-- /TMPL_IF --> <!-- TMPL_IF name="REJECTED" -->Rejected<!-- /TMPL_IF --> <!-- TMPL_IF name="CHECKED" -->Checked<!-- /TMPL_IF --> <!-- TMPL_IF name="reason" --><br />(<!-- TMPL_VAR name="reason" -->)<!-- /TMPL_IF -->
+                </td>
+         </tr>
+        <!-- /TMPL_LOOP --></tbody>
+        </table>  <fieldset>
+	  <div id="select-reason<!-- TMPL_VAR NAME="suggestiontype" -->">
+     <label for="reason<!-- TMPL_VAR NAME="suggestiontype" -->">Choose a reason for all marked entries:</label>                 <select id="reason<!-- TMPL_VAR NAME="suggestiontype" -->" name="reason<!-- TMPL_VAR NAME="suggestiontype" -->">
+                      <option value=""> -- Choose a reason -- </option>
+                        <!--TMPL_LOOP Name="reasonsloop"-->
+                        <option value="<!--TMPL_VAR Name="lib" -->"><!--TMPL_VAR Name="lib" --></option>
+                        <!--/TMPL_LOOP-->
+                      <option value="other">Others...</option>
+                      </select>  
+      </div>
+        <div id="other_reason<!-- TMPL_VAR NAME="suggestiontype" -->">
+		<label for="other_reason<!-- TMPL_VAR NAME="suggestiontype" -->">Enter a reason for all marked entries:</label>
+			<input type="text" size="31" id="select-other_reason<!-- TMPL_VAR NAME="suggestiontype" -->" name="other_reason<!-- TMPL_VAR NAME="suggestiontype" -->" value="please note your reason here..." /> <a href="#back<!-- TMPL_VAR NAME="suggestiontype" -->">Cancel</a>
+		</div>
+		<div id="status<!-- TMPL_VAR NAME="suggestiontype" -->">
+		<input type="radio" name="STATUS" value="ACCEPTED">Accept
+		<input type="radio" name="STATUS" value="CHECKED">Check
+		<input type="radio" name="STATUS" value="REJECTED">Reject
+		</div>
+		<div id="action<!-- TMPL_VAR NAME="suggestiontype" -->">
+		<input type="checkbox" onclick="javascript:if (this.checked){document.f<!-- TMPL_VAR NAME="suggestiontype" -->.op.value='delete';}else{document.f<!-- TMPL_VAR NAME="suggestiontype" -->.op.value='change'}"/> Delete
+		</div>
+
+	<input type="hidden" name="tabcode" value="<!-- TMPL_VAR NAME="suggestiontype" -->"/>
+	<input type="hidden" name="op" value="change"/>
+  </fieldset>
+        <fieldset class="action">
+	<input type="submit" value="Submit" /></fieldset>
+</form>
+<!-- TMPL_ELSE -->
+    <b>No Results.</b>
+<!-- /TMPL_IF -->
+</div>
+<!--/TMPL_LOOP-->
+	</div>
+	</div>
+
+</div>
+<!--TMPL_INCLUDE Name="intranet-bottom.inc"-->
diff --git a/koha-tmpl/opac-tmpl/prog/en/modules/opac-suggestions.tmpl b/koha-tmpl/opac-tmpl/prog/en/modules/opac-suggestions.tmpl
index aaba1eb..b14bf76 100644
--- a/koha-tmpl/opac-tmpl/prog/en/modules/opac-suggestions.tmpl
+++ b/koha-tmpl/opac-tmpl/prog/en/modules/opac-suggestions.tmpl
@@ -63,10 +63,20 @@ $.tablesorter.addParser({
     <li><label for="title">Title:</label><input type="text" id="title" name="title" size="50" maxlength="80" /></li>
     <li><label for="author">Author:</label><input type="text" id="author" name="author" size="50" maxlength="80" /></li>
     <li><label for="copyrightdate">Copyright date:</label><input type="text" id="copyrightdate" name="copyrightdate" size="4" maxlength="4" /></li>
+    <li><label for="isbn">ISBN or ISSN or other standard number:</label></label><input type="text" id="isbn" name="isbn" size="50" maxlength="80" /></li>
     <li><label for="publishercode">Publisher:</label><input type="text" id="publishercode" name="publishercode" size="50" maxlength="80" /></li>
+    <li><label for="collectiontitle">Collection title:</label><input type="text" id="collectiontitle" name="collectiontitle" size="50" maxlength="80" /></li>
+    <li><label for="place">Publication Place :</label><input type="text" id="place" name="place" size="50" maxlength="80" /></li>
+    <li><label for="itemtype">Document Type:</label><select name="itemtype" >
+            <option value="">Default</option>
+        <!-- TMPL_LOOP name="itemtypeloop" -->
+			<!-- TMPL_IF name="selected" --><option value="<!-- TMPL_VAR name="itemtype"-->" selected="selected"> <!--TMPL_ELSE--><option value="<!-- TMPL_VAR name="itemtype" -->"> <!--/TMPL_IF--> <!--TMPL_IF Name="imageurl"--><img alt="<!-- TMPL_VAR name="description" -->" src="<!--TMPL_VAR Name="imageurl"-->"><!--TMPL_ELSE--><!-- TMPL_VAR name="description" --><!--/TMPL_IF--></option>
+        <!-- /TMPL_LOOP -->
+        </select> </li>
+    <li><label for="sort1">Sort1:</label><input type="text" id="sort1" name="sort1" size="50" maxlength="80" /></li>
     <li><label for="note">Notes:</label><textarea name="note" id="note" rows="5" cols="40"></textarea></li>
     </ol></fieldset>
-        <fieldset class="action"><input type="hidden" name="op" value="add_confirm" /><input type="submit" value="Submit Your Suggestion" /> <a class="action" href="/cgi-bin/koha/opac-suggestions.pl">Cancel</a></fieldset>
+        <fieldset class="action"><input type="hidden" name="suggestedby" value="<!--TMPL_VAR Name="suggestedbyme"-->" /><input type="hidden" name="op" value="add_confirm" /><input type="submit" value="Submit Your Suggestion" /> <a class="action" href="/cgi-bin/koha/opac-suggestions.pl">Cancel</a></fieldset>
     </form>
 
 <!-- /TMPL_IF -->
@@ -101,8 +111,8 @@ $.tablesorter.addParser({
             </form><!-- /TMPL_IF -->
         <form action="/cgi-bin/koha/opac-suggestions.pl" method="post">
             <input type="hidden" name="op" value="delete_confirm" />
-			<div><!-- TMPL_IF NAME="loggedinusername" --><span class="checkall"><a href="#" id="CheckAll">Select All</a></span>
-		<span class="clearall"><a href="#" id="CheckNone">Clear All</a></span> | <a class="new" href="/cgi-bin/koha/opac-suggestions.pl?op=add">New purchase suggestion</a><!-- TMPL_ELSE --><!-- TMPL_IF NAME="AnonSuggestions" --><a class="new" href="/cgi-bin/koha/opac-suggestions.pl?op=add">New purchase suggestion</a><!-- /TMPL_IF --><!-- /TMPL_IF -->
+			<div><span class="checkall"><a href="#" id="CheckAll">Select All</a></span>
+		<span class="clearall"><a href="#" id="CheckNone">Clear All</a></span> | <!-- TMPL_IF NAME="loggedinusername" --><a class="new" href="/cgi-bin/koha/opac-suggestions.pl?op=add">New purchase suggestion</a><!-- TMPL_ELSE --><!-- TMPL_IF NAME="AnonSuggestions" --><a class="new" href="/cgi-bin/koha/opac-suggestions.pl?op=add">New purchase suggestion</a><!-- /TMPL_IF --><!-- /TMPL_IF -->
 </div>
 			<table id="suggestt" class="checkboxed">
 			<thead><tr>
@@ -116,28 +126,30 @@ $.tablesorter.addParser({
         <tbody><!-- TMPL_LOOP NAME="suggestions_loop" -->
             <!-- TMPL_IF name="even" --><tr><!-- TMPL_ELSE --><tr class="highlight"><!-- /TMPL_IF -->
 <!-- TMPL_IF NAME="loggedinusername" --><td>
-    <!-- TMPL_IF NAME="showcheckbox" -->
-                    <input type="checkbox" name="delete_field" value="<!--TMPL_VAR name="suggestionid" -->" />
-    <!-- /TMPL_IF -->
+                    <input type="checkbox" name="delete_field" value="<!--TMPL_VAR name="ordernumber" -->" />
                 </td><!-- /TMPL_IF -->
                 <td>
                     <p><strong><!-- TMPL_VAR NAME="title" escape="html" --></strong></p>
                     <p><!-- TMPL_IF name="author" --><!-- TMPL_VAR NAME="author" -->,<!-- /TMPL_IF -->
                         <!-- TMPL_IF name="copyrightdate" --> - <!-- TMPL_VAR NAME="copyrightdate" -->,<!-- /TMPL_IF --> 
                         <!-- TMPL_IF name="publishercode" --> - <!-- TMPL_VAR name="publishercode" --><!-- /TMPL_IF -->
+                        <!-- TMPL_IF name="place" -->(<!-- TMPL_VAR name="place" -->)<!-- /TMPL_IF -->
+                        <!-- TMPL_IF name="collectiontitle" --> , <!-- TMPL_VAR name="collectiontitle" --><!-- /TMPL_IF -->
+                        <!-- TMPL_IF name="itemtype" --> - <!-- TMPL_VAR name="itemtype" --><!-- /TMPL_IF -->
                     </p>
                 </td>
                 <td>
                     <!-- TMPL_VAR name="note" -->
                 </td>
                 <!-- TMPL_IF NAME="OPACViewOthersSuggestions" --><td>
-                    <!-- TMPL_IF NAME="branchnamesuggestedby" --><!-- TMPL_VAR name="branchnamesuggestedby" --><!-- TMPL_ELSE -->&nbsp;<!-- /TMPL_IF -->
+                    <!-- TMPL_IF NAME="branchcodesuggestedby" --><!-- TMPL_VAR name="branchcodesuggestedby" --><!-- TMPL_ELSE -->&nbsp;<!-- /TMPL_IF -->
                 </td><!-- /TMPL_IF -->
                 <td>
 					<!-- TMPL_IF NAME="surnamemanagedby" --><!-- TMPL_VAR name="surnamemanagedby" --><!-- TMPL_IF name="firstnamemanagedby" -->,<!-- /TMPL_IF --> <!-- TMPL_VAR name="firstnamemanagedby" --><!-- TMPL_ELSE -->&nbsp;<!-- /TMPL_IF -->
                 </td>
                 <td>
                     <!-- TMPL_IF name="ASKED" -->Requested<!-- /TMPL_IF -->
+                    <!-- TMPL_IF name="CHECKED" -->Checked by the library<!-- /TMPL_IF -->
                     <!-- TMPL_IF name="ACCEPTED" -->Accepted by the library<!-- /TMPL_IF -->
                     <!-- TMPL_IF name="ORDERED" -->Ordered by the library<!-- /TMPL_IF -->
                     <!-- TMPL_IF name="REJECTED" -->Suggestion declined <!-- /TMPL_IF -->
diff --git a/opac/opac-suggestions.pl b/opac/opac-suggestions.pl
index a12826a..cd512de 100755
--- a/opac/opac-suggestions.pl
+++ b/opac/opac-suggestions.pl
@@ -21,27 +21,21 @@ use warnings;
 use CGI;
 use C4::Auth;    # get_template_and_user
 use C4::Branch;
+use C4::Koha;
 use C4::Output;
 use C4::Suggestions;
+use C4::Koha;
+use C4::Dates;
 
 my $input           = new CGI;
-my $title           = $input->param('title');
-my $author          = $input->param('author');
-my $note            = $input->param('note');
-my $copyrightdate   = $input->param('copyrightdate');
-my $publishercode   = $input->param('publishercode');
-my $volumedesc      = $input->param('volumedesc');
-my $publicationyear = $input->param('publicationyear');
-my $place           = $input->param('place');
-my $isbn            = $input->param('isbn');
-my $status          = $input->param('status');
-my $suggestedbyme   = (defined $input->param('suggestedby')? $input->param('suggestedby'):1);
+my $allsuggestions  = $input->param('showall');
 my $op              = $input->param('op');
+my $suggestion      = $input->Vars;
+delete $$suggestion{$_} foreach qw<op suggestedbyme>;
 $op = 'else' unless $op;
 
 my ( $template, $borrowernumber, $cookie );
 
-my $dbh = C4::Context->dbh;
 
 if ( C4::Context->preference("AnonSuggestions") ) {
     ( $template, $borrowernumber, $cookie ) = get_template_and_user(
@@ -52,8 +46,8 @@ if ( C4::Context->preference("AnonSuggestions") ) {
             authnotrequired => 1,
         }
     );
-    if ( !$borrowernumber ) {
-        $borrowernumber = C4::Context->preference("AnonSuggestions");
+    if ( !$$suggestion{suggestedby} ) {
+        $$suggestion{suggestedby} = C4::Context->preference("AnonSuggestions");
     }
 }
 else {
@@ -66,24 +60,30 @@ else {
         }
     );
 }
-
+if ($allsuggestions){
+	delete $$suggestion{suggestedby};
+}
+else {
+	$$suggestion{suggestedby} ||= $borrowernumber unless ($allsuggestions);
+}
+warn "bornum:",$borrowernumber;
+use YAML;
+my $suggestions_loop =
+  &SearchSuggestion( $suggestion);
 if ( $op eq "add_confirm" ) {
-    &NewSuggestion(
-        $borrowernumber, $title,         $author,     $publishercode,
-        $note,           $copyrightdate, $volumedesc, $publicationyear,
-        $place,          $isbn,          ''
-    );
-
-    # empty fields, to avoid filter in "SearchSuggestion"
-    $title           = '';
-    $author          = '';
-    $publishercode   = '';
-    $copyrightdate   = '';
-    $volumedesc      = '';
-    $publicationyear = '';
-    $place           = '';
-    $isbn            = '';
-    $op              = 'else';
+	if (@$suggestions_loop>=1){
+		#some suggestion are answering the request Donot Add	
+	} 
+	else {
+		$$suggestion{'suggestioncreatedon'}=C4::Dates->today;
+		$$suggestion{'branchcode'}=C4::Context->userenv->{"branch"};
+		&NewSuggestion($suggestion);
+		# empty fields, to avoid filter in "SearchSuggestion"
+		$$suggestion{$_}='' foreach qw<title author publishercode copyrightdate place collectiontitle isbn STATUS>;
+		$suggestions_loop =
+		   &SearchSuggestion( $suggestion );
+	}
+	$op              = 'else';
 }
 
 if ( $op eq "delete_confirm" ) {
@@ -93,28 +93,24 @@ if ( $op eq "delete_confirm" ) {
     }
     $op = 'else';
 }
-
-my $suggestions_loop =
-  &SearchSuggestion( $borrowernumber, $author, $title, $publishercode, $status,
-    $suggestedbyme );
-
-foreach my $suggestion(@$suggestions_loop) {
-    if($suggestion->{'suggestedby'} == $borrowernumber) {
-        $suggestion->{'showcheckbox'} = $borrowernumber;
-    } else {
-        $suggestion->{'showcheckbox'} = 0;
-    }
+map{ $_->{'branchcodesuggestedby'}=GetBranchInfo($_->{'branchcodesuggestedby'})->[0]->{'branchname'}} @$suggestions_loop;  
+my $supportlist=GetSupportList();				
+foreach my $support(@$supportlist){
+	if ($$support{'imageurl'}){
+		$$support{'imageurl'}= getitemtypeimagelocation( 'intranet', $$support{'imageurl'} );
+	}
+	else {
+	   delete $$support{'imageurl'}
+	}
 }
-
 $template->param(
+	%$suggestion,
+	itemtypeloop=> $supportlist,
     suggestions_loop => $suggestions_loop,
-    title            => $title,
-    author           => $author,
-    publishercode    => $publishercode,
-    status           => $status,
-    suggestedbyme    => $suggestedbyme,
+    showall    => $allsuggestions,
     "op_$op"         => 1,
-	suggestionsview => 1
+	  suggestionsview => 1
 );
 
 output_html_with_http_headers $input, $cookie, $template->output;
+
diff --git a/suggestion/suggestion.pl b/suggestion/suggestion.pl
new file mode 100755
index 0000000..c455e3f
--- /dev/null
+++ b/suggestion/suggestion.pl
@@ -0,0 +1,269 @@
+#!/usr/bin/perl
+
+# This file is part of Koha.
+#
+# Koha is free software; you can redistribute it and/or modify it under the
+# terms of the GNU General Public License as published by the Free Software
+# Foundation; either version 2 of the License, or (at your option) any later
+# version.
+#
+# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along with
+# Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
+# Suite 330, Boston, MA  02111-1307 USA
+
+use strict;
+require Exporter;
+use CGI;
+use C4::Auth;    # get_template_and_user
+use C4::Output;
+use C4::Suggestions;
+use C4::Koha; #GetItemTypes
+use C4::Branch;
+use C4::Budgets;
+use C4::Search;
+use C4::Dates qw(format_date);
+use C4::Members;
+use C4::Debug;
+
+sub Init{
+    my $suggestion= shift @_;
+    foreach my $date qw(createdon managedon){
+        $suggestion->{$date}=(($suggestion->{$date} eq "0000-00-00" ||$suggestion->{$date} eq "")?
+                                $suggestion->{$date}=C4::Dates->today:
+                                format_date($suggestion->{$date}) 
+                              );
+    }               
+    $suggestion->{'acceptedon'}=(($suggestion->{'acceptedon'} eq "0000-00-00" ||$suggestion->{'acceptedon'} eq "")?
+                                "":
+                                format_date($suggestion->{'acceptedon'}) 
+                              );
+    $suggestion->{'managedby'}=C4::Context->userenv->{"id"} unless ($suggestion->{'managedby'});
+    $suggestion->{'createdby'}=C4::Context->userenv->{"id"} unless ($suggestion->{'createdby'});
+    $suggestion->{'branchcode'}=C4::Context->userenv->{"branch"} unless ($suggestion->{'branchcode'});
+}
+
+sub GetCriteriumDesc{
+    my ($criteriumvalue,$displayby)=@_;
+    return ($criteriumvalue eq 'ASKED'?"pending":lc $criteriumvalue) if ($displayby =~/status/i);
+    return (GetBranchName($criteriumvalue)) if ($displayby =~/branchcode/);
+    return (GetSupportName($criteriumvalue)) if ($displayby =~/itemtype/);
+    if ($displayby =~/managedby/||$displayby =~/acceptedby/){
+        my $borr=C4::Members::GetMember(borrowernumber=>$criteriumvalue);
+		return "" unless $borr;
+#		warn '$borr : ',Data::Dumper::Dumper($borr);
+        return $$borr{firstname}.", ".$$borr{surname};
+    }  
+}
+
+my $input           = CGI->new;
+my $suggestedbyme   = (defined $input->param('suggestedbyme')? $input->param('suggestedbyme'):1);
+my $op              = $input->param('op')||'else';
+my @editsuggestions = $input->param('edit_field');
+my $branchfilter   = $input->param('branchcode');
+my $suggestedby    = $input->param('suggestedby');
+my $managedby    = $input->param('managedby');
+my $displayby    = $input->param('displayby');
+my $tabcode    = $input->param('tabcode');
+
+# filter informations which are not suggestion related.
+my $suggestion_ref  = $input->Vars;
+delete $$suggestion_ref{$_} foreach qw<suggestedbyme op displayby tabcode edit_field>;
+foreach (keys %$suggestion_ref){
+	delete $$suggestion_ref{$_} if (!$$suggestion_ref{$_} && ($op eq 'else' || $op eq 'change'));
+}
+my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
+        {
+            template_name   => "suggestion/suggestion.tmpl",
+            query           => $input,
+            type            => "intranet",
+            flagsrequired   => { catalogue => 1 },
+        }
+    );
+
+#########################################
+##  Operations
+##
+if ($op =~/save/i){
+    if ($$suggestion_ref{'suggestionid'}>0){
+      &ModSuggestion($suggestion_ref);
+    }  
+    else {
+        ###FIXME:Search here if suggestion already exists.
+        my $suggestions_loop =
+            SearchSuggestion( $suggestion_ref );
+	    if (@$suggestions_loop>=1){
+		    #some suggestion are answering the request Donot Add	
+	    } 
+	    else {    
+        	## Adding some informations related to suggestion
+        	&NewSuggestion($suggestion_ref);
+        }
+        # empty fields, to avoid filter in "SearchSuggestion"
+    }  
+    map{delete $$suggestion_ref{$_}} keys %$suggestion_ref;
+    $op = 'else';
+}
+elsif ($op=~/add/) {
+    #Adds suggestion  
+    Init($suggestion_ref);
+    $op ='save';
+} 
+elsif ($op=~/edit/) {
+    #Edit suggestion  
+    $suggestion_ref=&GetSuggestion($$suggestion_ref{'suggestionid'});
+    Init($suggestion_ref);
+    $op ='save';
+}  
+elsif ($op eq "change" ) {
+	if ($$suggestion_ref{"STATUS"}){
+		my $tmpstatus=($$suggestion_ref{"STATUS"} eq "ACCEPTED"?"accepted":"managed");
+		$$suggestion_ref{"$tmpstatus"."on"}=C4::Dates->today;
+		$$suggestion_ref{"$tmpstatus"."by"}=C4::Context->userenv->{number};
+	}
+	if ( my $reason = $$suggestion_ref{"reason$tabcode"}){
+		if ( $reason eq "other" ) {
+				$reason = $$suggestion_ref{"other_reason$tabcode"};
+		}
+		$$suggestion_ref{'reason'}=$reason;
+	}
+	delete $$suggestion_ref{$_} foreach ("reason$tabcode", "other_reason$tabcode");
+ 	foreach (keys %$suggestion_ref){
+		delete $$suggestion_ref{$_} unless ($$suggestion_ref{$_});
+	}
+    foreach my $suggestionid (@editsuggestions) {
+		next unless $suggestionid;
+		$$suggestion_ref{'suggestionid'}=$suggestionid;
+        &ModSuggestion($suggestion_ref);
+    }
+    $op = 'else';
+}elsif ($op eq "delete" ) {
+    foreach my $delete_field (@editsuggestions) {
+        &DelSuggestion( $borrowernumber, $delete_field,'intranet' );
+    }
+    $op = 'else';
+}
+if ($op=~/else/) {
+    $op='else';
+    
+	$displayby||="STATUS";
+    my $criteria_list=GetDistinctValues("suggestions.".$displayby);
+    my @allsuggestions;
+    foreach my $criteriumvalue (map{$$_{'value'}} @$criteria_list){
+        my $definedvalue = defined $$suggestion_ref{$displayby} && $$suggestion_ref{$displayby} ne "";
+        
+        next if ($definedvalue && $$suggestion_ref{$displayby} ne $criteriumvalue);
+        $$suggestion_ref{$displayby}=$criteriumvalue;
+        warn $$suggestion_ref{$displayby}."=$criteriumvalue; $displayby";
+    
+        my $suggestions = &SearchSuggestion($suggestion_ref);
+        foreach (@$suggestions){
+            foreach my $date qw(createdon managedon acceptedon){
+                if ($_->{$date} ne "0000-00-00" && $_->{$date} ne "" ){
+                $_->{$date}=format_date($_->{$date}) ;
+                } else {
+                $_->{$date}="" ;
+                }             
+            }    
+        }
+        push @allsuggestions,{
+                            "suggestiontype"=>$criteriumvalue||"suggest",
+                            "suggestiontypelabel"=>GetCriteriumDesc($criteriumvalue,$displayby)||"",
+                            "suggestionscount"=>scalar(@$suggestions),             
+                            'suggestions_loop'=>$suggestions,
+							};
+		
+        delete $$suggestion_ref{$displayby} unless $definedvalue;
+    }
+    my $reasonsloop = GetAuthorisedValues("SUGGEST");
+    $template->param(
+        "displayby"=> $displayby,        
+        "notabs"=> $displayby eq "",        
+        suggestions       => \@allsuggestions,
+        reasonsloop       => $reasonsloop,
+    );
+}
+
+foreach my $element qw<managedby createdby suggestedby rejectedby>{
+	warn $$suggestion_ref{$element};
+	if ($$suggestion_ref{$element}){
+		my $member=GetMember(borrowernumber=>$$suggestion_ref{$element});
+		my $presentation_string=$$member{firstname}." ".$$member{surname}." ".GetBranchName($$member{branchcode})." ".$$member{description}." ".$$member{category_type};
+		warn $presentation_string;
+		$template->param($element."information"=>$presentation_string);
+	}
+}
+$template->param(
+    %$suggestion_ref,  
+    "op_$op"                => 1,
+    dateformat    => C4::Context->preference("dateformat"),
+    "op"             =>$op,
+);
+
+
+####################
+## Initializing selection lists
+
+#branch display management
+my $onlymine=C4::Context->preference('IndependantBranches') && 
+             C4::Context->userenv && 
+             C4::Context->userenv->{flags}!=1 && 
+             C4::Context->userenv->{branch};
+my $branches = GetBranches($onlymine);
+my @branchloop;
+
+foreach my $thisbranch ( sort {$branches->{$a}->{'branchname'} cmp $branches->{$b}->{'branchname'}} keys %$branches ) {
+     my %row = (
+        value      => $thisbranch,
+        branchname => $branches->{$thisbranch}->{'branchname'},
+        selected   => ($branches->{$thisbranch}->{'branchcode'} eq $branchfilter)
+                      ||($branches->{$thisbranch}->{'branchcode'} eq $$suggestion_ref{'branchcode'})    
+    );
+    push @branchloop, \%row;
+}
+$branchfilter=C4::Context->userenv->{'branch'} if ($onlymine && !$branchfilter);
+
+$template->param( branchloop => \@branchloop,
+                  branchfilter => $branchfilter);
+
+# the index parameter is different for item-level itemtypes
+my $supportlist=GetSupportList();				
+foreach my $support(@$supportlist){
+    $$support{'selected'}= $$support{'code'} eq $$suggestion_ref{'itemtype'};
+	if ($$support{'imageurl'}){
+		$$support{'imageurl'}= getitemtypeimagelocation( 'intranet', $$support{'imageurl'} );
+	}
+	else {
+	   delete $$support{'imageurl'}
+	}
+}
+$template->param(itemtypeloop=>$supportlist);
+
+#Budgets management
+my $searchbudgets={ budget_branchcode=>$branchfilter} if $branchfilter;
+my $budgets = GetBudgets($searchbudgets);
+
+foreach (@$budgets){
+	$_->{'selected'}=1 if ($$suggestion_ref{'budget_id'} && $_{'budget_id'} eq $$suggestion_ref{'budget_id'})
+};
+
+$template->param( budgetsloop => $budgets);
+
+my %hashlists; 
+foreach my $field qw(managedby acceptedby suggestedby STATUS){
+    my $values_list;
+    $values_list=GetDistinctValues("suggestions.".$field) ;
+    my @codes_list = map{
+						{ 'code'=>$$_{'value'},
+						  'desc'=>GetCriteriumDesc($$_{'value'},$field),
+						  'selected'=> $$_{'value'} eq $$suggestion_ref{$field}
+						}
+				      } @$values_list;
+    $hashlists{lc($field)."_loop"}=\@codes_list;
+}
+$template->param(%hashlists);
+
+output_html_with_http_headers $input, $cookie, $template->output;
diff --git a/t/db_dependent/Suggestions.t b/t/db_dependent/Suggestions.t
new file mode 100644
index 0000000..001dc24
--- /dev/null
+++ b/t/db_dependent/Suggestions.t
@@ -0,0 +1,24 @@
+#!/usr/bin/perl
+#
+# This Koha test module is a stub!
+# Add more tests here!!!
+
+use strict;
+use warnings;
+use Data::Dumper;
+
+use C4::Suggestions;
+
+use Test::More tests =>6; 
+
+BEGIN {
+    use_ok('C4::Suggestions');
+}
+
+my ($suggestionid, $suggestion, $status);
+ok($suggestionid= NewSuggestion( {title=>'Petit traité de philosohpie',author=>'Hubert de Chardassé',publishercode=>'Albin Michel'} ), "NewSuggestion OK");
+ok($suggestion= GetSuggestion( $suggestionid), "GetSuggestion OK");
+ok($status= ModSuggestion( {title=>'test Modif Simple', suggestionid=>$suggestionid} ), "ModSuggestion Simple OK");
+ok($status= ModSuggestion( {STATUS=>'STALLED', suggestionid=>$suggestionid} ), "ModSuggestion Status OK");
+ok(@{SearchSuggestion( {STATUS=>'STALLED'} )}>0, "SearchSuggestion Status OK");
+
-- 
1.6.0.4




More information about the Koha-patches mailing list