(bug #2040) This prevent users to post empty suggestions, and post the same suggestio...
[koha.git] / C4 / Suggestions.pm
index 88876d4..1f9daef 100644 (file)
@@ -93,7 +93,7 @@ sub SearchSuggestion  {
         U1.surname   AS surnamesuggestedby,
         U1.firstname AS firstnamesuggestedby,
         U1.borrowernumber AS borrnumsuggestedby,
-        U1.branchcode AS branchcode,
+        U1.branchcode AS branchcodesuggestedby,
         U2.surname   AS surnamemanagedby,
         U2.firstname AS firstnamemanagedby,
         U2.borrowernumber AS borrnummanagedby
@@ -118,7 +118,7 @@ sub SearchSuggestion  {
     if (C4::Context->preference("IndependantBranches") || $branchcode) {
         my $userenv = C4::Context->userenv;
         if ($userenv) {
-            unless ($userenv->{flags} == 1){
+            unless ($userenv->{flags} % 2 == 1){
                 push @sql_params,$userenv->{branch};
                 $query .= " and (U1.branchcode = ? or U1.branchcode ='')";
             }
@@ -237,7 +237,7 @@ sub GetSuggestionByStatus {
     if (C4::Context->preference("IndependantBranches") || $branchcode) {
         my $userenv = C4::Context->userenv;
         if ($userenv) {
-            unless ($userenv->{flags} == 1){
+            unless ($userenv->{flags} % 2 == 1){
                 push @sql_params,$userenv->{branch};
                 $query .= " and (U1.branchcode = ? or U1.branchcode ='')";
             }
@@ -287,7 +287,7 @@ sub CountSuggestion {
     my $sth;
     if (C4::Context->preference("IndependantBranches")){
         my $userenv = C4::Context->userenv;
-        if ($userenv->{flags} == 1){
+        if ($userenv->{flags} % 2 == 1){
             my $query = qq |
                 SELECT count(*)
                 FROM   suggestions
@@ -331,15 +331,17 @@ Insert a new suggestion on database with value given on input arg.
 
 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);
+    if ($title) {
+        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);
+    }
 }
 
 =head2 ModStatus