(bug #2040) This prevent users to post empty suggestions, and post the same suggestio...
[koha.git] / C4 / Suggestions.pm
index 4250db0..1f9daef 100644 (file)
@@ -89,9 +89,11 @@ sub SearchSuggestion  {
     my $dbh = C4::Context->dbh;
     my $query = "
     SELECT suggestions.*,
+        U1.branchcode   AS branchcodesuggestedby,
         U1.surname   AS surnamesuggestedby,
         U1.firstname AS firstnamesuggestedby,
         U1.borrowernumber AS borrnumsuggestedby,
+        U1.branchcode AS branchcodesuggestedby,
         U2.surname   AS surnamemanagedby,
         U2.firstname AS firstnamemanagedby,
         U2.borrowernumber AS borrnummanagedby
@@ -116,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 ='')";
             }
@@ -223,6 +225,7 @@ sub GetSuggestionByStatus {
     my $query = qq(SELECT suggestions.*,
                         U1.surname   AS surnamesuggestedby,
                         U1.firstname AS firstnamesuggestedby,
+            U1.branchcode AS branchcodesuggestedby,
                                                U1.borrowernumber AS borrnumsuggestedby,
                         U2.surname   AS surnamemanagedby,
                         U2.firstname AS firstnamemanagedby,
@@ -234,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 ='')";
             }
@@ -284,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
@@ -328,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
@@ -427,7 +432,8 @@ sub ModStatus {
         To => $emailinfo->{byemail},
         From => $emailinfo->{libemail},
         Subject => 'Koha suggestion',
-        Message => "".$template->output
+        Message => "".$template->output,
+        'Content-Type' => 'text/plain; charset="utf8"',
     );
     sendmail(%mail);
 }