View | Details | Raw Unified | Return to bug 23991
Collapse All | Expand All

(-)a/C4/Suggestions.pm (-150 lines)
Lines 41-47 our @EXPORT = qw( Link Here
41
  ModStatus
41
  ModStatus
42
  ModSuggestion
42
  ModSuggestion
43
  NewSuggestion
43
  NewSuggestion
44
  SearchSuggestion
45
  DelSuggestionsOlderThan
44
  DelSuggestionsOlderThan
46
  GetUnprocessedSuggestions
45
  GetUnprocessedSuggestions
47
  MarcRecordFromNewSuggestion
46
  MarcRecordFromNewSuggestion
Lines 72-226 Suggestions done by other borrowers can be seen when not "AVAILABLE" Link Here
72
71
73
=head1 FUNCTIONS
72
=head1 FUNCTIONS
74
73
75
=head2 SearchSuggestion
76
77
(\@array) = &SearchSuggestion($suggestionhashref_to_search)
78
79
searches for a suggestion
80
81
return :
82
C<\@array> : the aqorders found. Array of hash.
83
Note the status is stored twice :
84
* in the status field
85
* as parameter ( for example ASKED => 1, or REJECTED => 1) . This is for template & translation purposes.
86
87
=cut
88
89
sub SearchSuggestion {
90
    my ($suggestion) = @_;
91
    my $dbh = C4::Context->dbh;
92
    my @sql_params;
93
    my @query = (
94
        q{
95
        SELECT suggestions.*,
96
            U1.branchcode       AS branchcodesuggestedby,
97
            B1.branchname       AS branchnamesuggestedby,
98
            U1.surname          AS surnamesuggestedby,
99
            U1.firstname        AS firstnamesuggestedby,
100
            U1.cardnumber       AS cardnumbersuggestedby,
101
            U1.email            AS emailsuggestedby,
102
            U1.borrowernumber   AS borrnumsuggestedby,
103
            U1.categorycode     AS categorycodesuggestedby,
104
            C1.description      AS categorydescriptionsuggestedby,
105
            U2.surname          AS surnamemanagedby,
106
            U2.firstname        AS firstnamemanagedby,
107
            B2.branchname       AS branchnamesuggestedby,
108
            U2.email            AS emailmanagedby,
109
            U2.branchcode       AS branchcodemanagedby,
110
            U2.borrowernumber   AS borrnummanagedby,
111
            U3.surname          AS surnamelastmodificationby,
112
            U3.firstname        AS firstnamelastmodificationby,
113
            BU.budget_name      AS budget_name
114
        FROM suggestions
115
            LEFT JOIN borrowers     AS U1 ON suggestedby=U1.borrowernumber
116
            LEFT JOIN branches      AS B1 ON B1.branchcode=U1.branchcode
117
            LEFT JOIN categories    AS C1 ON C1.categorycode=U1.categorycode
118
            LEFT JOIN borrowers     AS U2 ON managedby=U2.borrowernumber
119
            LEFT JOIN branches      AS B2 ON B2.branchcode=U2.branchcode
120
            LEFT JOIN categories    AS C2 ON C2.categorycode=U2.categorycode
121
            LEFT JOIN borrowers     AS U3 ON lastmodificationby=U3.borrowernumber
122
            LEFT JOIN aqbudgets     AS BU ON budgetid=BU.budget_id
123
        WHERE 1=1
124
    }
125
    );
126
127
    # filter on biblio informations
128
    foreach my $field (
129
        qw( title author isbn publishercode copyrightdate collectiontitle ))
130
    {
131
        if ( $suggestion->{$field} ) {
132
            push @sql_params, '%' . $suggestion->{$field} . '%';
133
            push @query,      qq{ AND suggestions.$field LIKE ? };
134
        }
135
    }
136
137
    # filter on user branch
138
    if (   C4::Context->preference('IndependentBranches')
139
        && !C4::Context->IsSuperLibrarian() )
140
    {
141
        # If IndependentBranches is set and the logged in user is not superlibrarian
142
        # Then we want to filter by the user's library (i.e. cannot see suggestions from other libraries)
143
        my $userenv = C4::Context->userenv;
144
        if ($userenv) {
145
            {
146
                push @sql_params, $$userenv{branch};
147
                push @query,      q{
148
                    AND (suggestions.branchcode=? OR suggestions.branchcode='')
149
                };
150
            }
151
        }
152
    }
153
    elsif (defined $suggestion->{branchcode}
154
        && $suggestion->{branchcode}
155
        && $suggestion->{branchcode} ne '__ANY__' )
156
    {
157
        # If IndependentBranches is not set OR the logged in user is not superlibrarian
158
        # AND the branchcode filter is passed and not '__ANY__'
159
        # Then we want to filter using this parameter
160
        push @sql_params, $suggestion->{branchcode};
161
        push @query,      qq{ AND suggestions.branchcode=? };
162
    }
163
164
    # filter on nillable fields
165
    foreach my $field (
166
        qw( STATUS itemtype suggestedby managedby acceptedby budgetid biblionumber )
167
      )
168
    {
169
        if ( exists $suggestion->{$field}
170
                and defined $suggestion->{$field}
171
                and $suggestion->{$field} ne '__ANY__'
172
                and (
173
                    $suggestion->{$field} ne q||
174
                        or $field eq 'STATUS'
175
                )
176
        ) {
177
            if ( $suggestion->{$field} eq '__NONE__' ) {
178
                push @query, qq{ AND (suggestions.$field = '' OR suggestions.$field IS NULL) };
179
            }
180
            else {
181
                push @sql_params, $suggestion->{$field};
182
                push @query, qq{ AND suggestions.$field = ? };
183
            }
184
        }
185
    }
186
187
    # filter on date fields
188
    my $dtf = Koha::Database->new->schema->storage->datetime_parser;
189
    foreach my $field (qw( suggesteddate manageddate accepteddate )) {
190
        my $from = $field . "_from";
191
        my $to   = $field . "_to";
192
        my $from_dt;
193
        $from_dt = eval { dt_from_string( $suggestion->{$from} ) } if ( $suggestion->{$from} );
194
        my $to_dt;
195
        $to_dt = eval { dt_from_string( $suggestion->{$to} ) } if ( $suggestion->{$to} );
196
        if ( $from_dt ) {
197
            push @query, qq{ AND suggestions.$field >= ?};
198
            push @sql_params, $dtf->format_date($from_dt);
199
        }
200
        if ( $to_dt ) {
201
            push @query, qq{ AND suggestions.$field <= ?};
202
            push @sql_params, $dtf->format_date($to_dt);
203
        }
204
    }
205
206
    # By default do not search for archived suggestions
207
    unless ( exists $suggestion->{archived} && $suggestion->{archived} ) {
208
        push @query, q{ AND suggestions.archived = 0 };
209
    }
210
211
    my $sth = $dbh->prepare("@query");
212
    $sth->execute(@sql_params);
213
    my @results;
214
215
    # add status as field
216
    while ( my $data = $sth->fetchrow_hashref ) {
217
        $data->{ $data->{STATUS} } = 1;
218
        push( @results, $data );
219
    }
220
221
    return ( \@results );
222
}
223
224
=head2 GetSuggestion
74
=head2 GetSuggestion
225
75
226
\%sth = &GetSuggestion($suggestionid)
76
\%sth = &GetSuggestion($suggestionid)
(-)a/Koha/Suggestions.pm (+21 lines)
Lines 32-37 Koha::Suggestions - Koha Suggestion object set class Link Here
32
32
33
=head1 API
33
=head1 API
34
34
35
=cut
36
37
sub search_limited {
38
    my ( $self, $params, $attributes ) = @_;
39
40
    $attributes //= {};
41
    # filter on user branch
42
    if (   C4::Context->preference('IndependentBranches')
43
        && !C4::Context->IsSuperLibrarian() )
44
    {
45
        # If IndependentBranches is set and the logged in user is not superlibrarian
46
        # Then we want to filter by the user's library (i.e. cannot see suggestions from other libraries)
47
        my $userenv = C4::Context->userenv;
48
        if ( $userenv ) {
49
            $params->{branchcode} = { -or => [ $userenv->{branch}, '' ] };
50
        }
51
    }
52
53
    return $self->search($params, $attributes);
54
}
55
35
=head2 Class Methods
56
=head2 Class Methods
36
57
37
=cut
58
=cut
(-)a/acqui/newordersuggestion.pl (-9 / +9 lines)
Lines 97-102 use C4::Suggestions qw( ConnectSuggestionAndBiblio SearchSuggestion ); Link Here
97
use C4::Budgets;
97
use C4::Budgets;
98
98
99
use Koha::Acquisition::Booksellers;
99
use Koha::Acquisition::Booksellers;
100
use Koha::Suggestions;
100
101
101
my $input = CGI->new;
102
my $input = CGI->new;
102
103
Lines 127-149 if ( $op eq 'connectDuplicate' ) { Link Here
127
    ConnectSuggestionAndBiblio( $suggestionid, $duplicateNumber );
128
    ConnectSuggestionAndBiblio( $suggestionid, $duplicateNumber );
128
}
129
}
129
130
130
# getting all suggestions.
131
my $suggestions = Koha::Suggestions->search_limited(
131
my $suggestions_loop = SearchSuggestion(
132
    {
132
    {
133
        author        => $author,
133
        ( $author        ? ( author        => $author )        : () ),
134
        title         => $title,
134
        ( $title         ? ( title         => $title )         : () ),
135
        publishercode => $publishercode,
135
        ( $publishercode ? ( publishercode => $publishercode ) : () ),
136
        STATUS        => 'ACCEPTED'
136
        STATUS => 'ACCEPTED'
137
    }
137
    },
138
    { prefetch => ['managedby', 'suggestedby'] },
138
);
139
);
139
140
140
my $vendor = Koha::Acquisition::Booksellers->find( $booksellerid );
141
my $vendor = Koha::Acquisition::Booksellers->find( $booksellerid );
141
$template->param(
142
$template->param(
142
    suggestions_loop        => $suggestions_loop,
143
    suggestions             => $suggestions,
143
    basketno                => $basketno,
144
    basketno                => $basketno,
144
    booksellerid              => $booksellerid,
145
    booksellerid              => $booksellerid,
145
    name                    => $vendor->name,
146
    name                    => $vendor->name,
146
    loggedinuser            => $borrowernumber,
147
    "op_$op"                => 1,
147
    "op_$op"                => 1,
148
);
148
);
149
149
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/newordersuggestion.tt (-27 / +23 lines)
Lines 41-47 Link Here
41
            <main>
41
            <main>
42
42
43
<h1>Suggestions</h1>
43
<h1>Suggestions</h1>
44
    [% IF ( suggestions_loop ) %]
44
    [% IF suggestions.count %]
45
    <a href="#" id="show_only_mine">Show only mine</a> | <a href="#" id="show_all">Show all suggestions</a>
45
    <a href="#" id="show_only_mine">Show only mine</a> | <a href="#" id="show_all">Show all suggestions</a>
46
    <table id="suggestionst">
46
    <table id="suggestionst">
47
        <thead>
47
        <thead>
Lines 59-107 Link Here
59
        </tr>
59
        </tr>
60
        </thead>
60
        </thead>
61
        <tbody>
61
        <tbody>
62
        [% FOREACH suggestions_loo IN suggestions_loop %]
62
        [% FOREACH suggestion IN suggestions %]
63
            <tr>
63
            <tr>
64
                <td>[% suggestions_loo.managedby | html %]</td>
64
                <td>[% suggestion.managedby | html %]</td>
65
                <td>
65
                <td>
66
                    <p>[% suggestions_loo.title | html %] - [% suggestions_loo.author | html %]</p>
66
                    <p>[% suggestion.title | html %] - [% suggestion.author | html %]</p>
67
                    <p>
67
                    <p>
68
                        [% IF ( suggestions_loo.copyrightdate ) %]&copy; [% suggestions_loo.copyrightdate | html %] [% END %]
68
                        [% IF ( suggestion.copyrightdate ) %]&copy; [% suggestion.copyrightdate | html %] [% END %]
69
                        [% IF ( suggestions_loo.volumedesc ) %]volume: <em>[% suggestions_loo.volumedesc | html %]</em> [% END %]
69
                        [% IF ( suggestion.volumedesc ) %]volume: <em>[% suggestion.volumedesc | html %]</em> [% END %]
70
                        [% IF ( suggestions_loo.isbn ) %]ISBN: <em>[% suggestions_loo.isbn | html %]</em> [% END %]
70
                        [% IF ( suggestion.isbn ) %]ISBN: <em>[% suggestion.isbn | html %]</em> [% END %]
71
                        [% IF ( suggestions_loo.publishercode ) %]<br />published by: [% suggestions_loo.publishercode | html %] [% END %]
71
                        [% IF ( suggestion.publishercode ) %]<br />published by: [% suggestion.publishercode | html %] [% END %]
72
                        [% IF ( suggestions_loo.publicationyear ) %] in <em>[% suggestions_loo.publicationyear | html %]</em> [% END %]
72
                        [% IF ( suggestion.publicationyear ) %] in <em>[% suggestion.publicationyear | html %]</em> [% END %]
73
                        [% IF ( suggestions_loo.place ) %] in <em>[% suggestions_loo.place | html %]</em> [% END %]
73
                        [% IF ( suggestion.place ) %] in <em>[% suggestion.place | html %]</em> [% END %]
74
                        [% IF ( suggestions_loo.note ) %]<p><em>([% suggestions_loo.note | html %])</em></p> [% END %]
74
                        [% IF ( suggestion.note ) %]<p><em>([% suggestion.note | html %])</em></p> [% END %]
75
                    </p>
75
                    </p>
76
                </td>
76
                </td>
77
                <td>[% INCLUDE 'patron-title.inc' patron => suggestion.suggester %]</td>
78
                <td>[% INCLUDE 'patron-title.inc' patron => suggestion.manager %]</td>
77
                <td>
79
                <td>
78
                    [% suggestions_loo.surnamesuggestedby | html %][% IF ( suggestions_loo.firstnamesuggestedby ) %],[% END %] [% suggestions_loo.firstnamesuggestedby | html %]
80
                    [% Branches.GetName(suggestion.branchcode) | html %]
79
                </td>
81
                </td>
80
                <td>
82
                <td>
81
                    [% suggestions_loo.surnamemanagedby | html %][% IF ( suggestions_loo.firstnamemanagedby ) %],[% END %] [% suggestions_loo.firstnamemanagedby | html %]
83
                    [% suggestion.fund.budget_name | html %]
82
                </td>
84
                </td>
83
                <td>
85
                <td>
84
                    [% Branches.GetName(suggestions_loo.branchcode) | html %]
86
                    [% suggestion.price | $Price %]
85
                </td>
87
                </td>
86
                <td>
88
                <td>
87
                    [% suggestions_loo.budget_name | html %]
89
                    [% IF (suggestion.quantity > 0) %]
88
                </td>
90
                        [% suggestion.quantity | html %]
89
                <td>
90
                    [% suggestions_loo.price | $Price %]
91
                </td>
92
                <td>
93
                    [% IF (suggestions_loo.quantity > 0) %]
94
                        [% suggestions_loo.quantity | html %]
95
                    [% END %]
91
                    [% END %]
96
                </td>
92
                </td>
97
                <td>
93
                <td>
98
                    [% suggestions_loo.total | $Price %]
94
                    [% suggestion.total | $Price %]
99
                </td>
95
                </td>
100
                <td class="actions">
96
                <td class="actions">
101
                    [% IF ( suggestions_loo.biblionumber ) %]
97
                    [% IF ( suggestion.biblionumber ) %]
102
                        <a href="neworderempty.pl?booksellerid=[% booksellerid | uri %]&amp;basketno=[% basketno | uri %]&amp;suggestionid=[% suggestions_loo.suggestionid | uri %]&amp;biblio=[% suggestions_loo.biblionumber | uri %]" class="btn btn-default btn-xs"><i class="fa fa-plus"></i> [% tp('verb', 'Order') | html %]</a>
98
                        <a href="neworderempty.pl?booksellerid=[% booksellerid | uri %]&amp;basketno=[% basketno | uri %]&amp;suggestionid=[% suggestion.suggestionid | uri %]&amp;biblio=[% suggestion.biblionumber | uri %]" class="btn btn-default btn-xs"><i class="fa fa-plus"></i> [% tp('verb', 'Order') | html %]</a>
103
                    [% ELSE %]
99
                    [% ELSE %]
104
                        <a href="neworderempty.pl?booksellerid=[% booksellerid | uri %]&amp;basketno=[% basketno | uri %]&amp;suggestionid=[% suggestions_loo.suggestionid | uri %]" class="btn btn-default btn-xs"><i class="fa fa-plus"></i> [% tp('verb', 'Order') | html %]</a>
100
                        <a href="neworderempty.pl?booksellerid=[% booksellerid | uri %]&amp;basketno=[% basketno | uri %]&amp;suggestionid=[% suggestion.suggestionid | uri %]" class="btn btn-default btn-xs"><i class="fa fa-plus"></i> [% tp('verb', 'Order') | html %]</a>
105
                    [% END %]
101
                    [% END %]
106
                </td>
102
                </td>
107
            </tr>
103
            </tr>
Lines 136-142 Link Here
136
        }));
132
        }));
137
        $("#show_only_mine").on('click', function(e){
133
        $("#show_only_mine").on('click', function(e){
138
            e.preventDefault();
134
            e.preventDefault();
139
            suggestionst.fnFilter('^[% loggedinuser | html %]$', 0, true);
135
            suggestionst.fnFilter('^[% logged_in_user.borrowernumber | html %]$', 0, true);
140
        });
136
        });
141
        $("#show_all").on('click', function(e){
137
        $("#show_all").on('click', function(e){
142
            e.preventDefault();
138
            e.preventDefault();
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/members/purchase-suggestions.tt (-8 / +2 lines)
Lines 42-48 Link Here
42
                    <a class="btn btn-default" id="newsuggestion" href="/cgi-bin/koha/suggestion/suggestion.pl?op=add&amp;suggestedby=[% patron.borrowernumber | html %]&amp;redirect=purchase_suggestions&amp;borrowernumber=[% patron.borrowernumber | html %]"><i class="fa fa-plus"></i> New purchase suggestion</a>
42
                    <a class="btn btn-default" id="newsuggestion" href="/cgi-bin/koha/suggestion/suggestion.pl?op=add&amp;suggestedby=[% patron.borrowernumber | html %]&amp;redirect=purchase_suggestions&amp;borrowernumber=[% patron.borrowernumber | html %]"><i class="fa fa-plus"></i> New purchase suggestion</a>
43
                </div>
43
                </div>
44
44
45
                [% IF suggestions %]
45
                [% IF suggestions.count %]
46
                  <table id="suggestions">
46
                  <table id="suggestions">
47
                    <thead>
47
                    <thead>
48
                        <tr>
48
                        <tr>
Lines 79-91 Link Here
79
                                </td>
79
                                </td>
80
                                <td>[% s.note | html %]
80
                                <td>[% s.note | html %]
81
                                <td>
81
                                <td>
82
                                    [% IF ( s.surnamemanagedby ) %]
82
                                    [% INCLUDE 'patron-title.inc' patron => s.manager %]
83
                                        [% s.surnamemanagedby | html %]
84
                                        [% IF ( s.firstnamemanagedby ) %],[% END %]
85
                                        [% s.firstnamemanagedby | html %]
86
                                    [% ELSE %]
87
                                        &nbsp;
88
                                    [% END %]
89
                                </td>
83
                                </td>
90
                                <td data-order="[% s.manageddate | html %]">
84
                                <td data-order="[% s.manageddate | html %]">
91
                                    [% s.manageddate | $KohaDates %]
85
                                    [% s.manageddate | $KohaDates %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/suggestion/suggestion.tt (-55 / +58 lines)
Lines 707-713 Link Here
707
                                    No name
707
                                    No name
708
                                [% END %]
708
                                [% END %]
709
                            [% END %]
709
                            [% END %]
710
                            ([% suggestion.suggestions_loop.size | html %])</a></li>
710
                            ([% suggestion.suggestions.count| html %])</a></li>
711
711
712
                        [% END # /FOREACH suggestion %]
712
                        [% END # /FOREACH suggestion %]
713
                    </ul> <!-- /.ui-tabs-nav -->
713
                    </ul> <!-- /.ui-tabs-nav -->
Lines 717-723 Link Here
717
                <div id="[% suggestion.suggestiontype | html %]">
717
                <div id="[% suggestion.suggestiontype | html %]">
718
                    <form class="update_suggestions" name="f" method="post" action="/cgi-bin/koha/suggestion/suggestion.pl#[% suggestion.suggestiontype| uri %]">
718
                    <form class="update_suggestions" name="f" method="post" action="/cgi-bin/koha/suggestion/suggestion.pl#[% suggestion.suggestiontype| uri %]">
719
719
720
                        [% IF ( suggestion.suggestions_loop ) %]
720
                        [% IF suggestion.suggestions.count %]
721
                            <p>
721
                            <p>
722
                                <a class="checkall" href="#">Check all</a> | <a class="uncheckall" href="#">Uncheck all</a>
722
                                <a class="checkall" href="#">Check all</a> | <a class="uncheckall" href="#">Uncheck all</a>
723
                            </p>
723
                            </p>
Lines 741-853 Link Here
741
                                    </tr>
741
                                    </tr>
742
                                </thead>
742
                                </thead>
743
                                <tbody>
743
                                <tbody>
744
                                    [% FOREACH suggestions_loo IN suggestion.suggestions_loop %]
744
                                    [% FOREACH s IN suggestion.suggestions %]
745
                                        <tr>
745
                                        <tr>
746
                                            <td>
746
                                            <td>
747
                                                <input type="checkbox" name="suggestionid" value="[% suggestions_loo.suggestionid | html %]" />
747
                                                <input type="checkbox" name="suggestionid" value="[% s.suggestionid | html %]" />
748
                                            </td>
748
                                            </td>
749
                                            <td>
749
                                            <td>
750
                                                <a href="suggestion.pl?suggestionid=[% suggestions_loo.suggestionid | uri %]&amp;op=show" title="suggestion" >
750
                                                <a href="suggestion.pl?suggestionid=[% s.suggestionid | uri %]&amp;op=show" title="suggestion" >
751
                                                    [% suggestions_loo.title | html %][% IF ( suggestions_loo.author ) %], by [% suggestions_loo.author | html %][% END %]
751
                                                    [% s.title | html %][% IF ( s.author ) %], by [% s.author | html %][% END %]
752
                                                </a>
752
                                                </a>
753
                                                <br />
753
                                                <br />
754
                                                [% IF ( suggestions_loo.copyrightdate ) %]
754
                                                [% IF ( s.copyrightdate ) %]
755
                                                    &copy; <span class="suggestion_copyrightdate">[% suggestions_loo.copyrightdate | html %]</span>
755
                                                    &copy; <span class="suggestion_copyrightdate">[% s.copyrightdate | html %]</span>
756
                                                [% END %]
756
                                                [% END %]
757
                                                [% IF ( suggestions_loo.volumedesc ) %]
757
                                                [% IF ( s.volumedesc ) %]
758
                                                    ; <span class="suggestion_volume">Volume:<em>[% suggestions_loo.volumedesc | html %]</em></span>
758
                                                    ; <span class="suggestion_volume">Volume:<em>[% s.volumedesc | html %]</em></span>
759
                                                [% END %]
759
                                                [% END %]
760
                                                [% IF ( suggestions_loo.isbn ) %]
760
                                                [% IF ( s.isbn ) %]
761
                                                    ; <span class="suggestion_isbn">ISBN: <em>[% suggestions_loo.isbn | html %]</em></span>
761
                                                    ; <span class="suggestion_isbn">ISBN: <em>[% s.isbn | html %]</em></span>
762
                                                [% END %]
762
                                                [% END %]
763
                                                [% IF ( suggestions_loo.publishercode ) %]
763
                                                [% IF ( s.publishercode ) %]
764
                                                    ; <span class="suggestion_publishercode">Published by [% suggestions_loo.publishercode | html %]</span>
764
                                                    ; <span class="suggestion_publishercode">Published by [% s.publishercode | html %]</span>
765
                                                [% END %]
765
                                                [% END %]
766
                                                [% IF ( suggestions_loo.publicationyear ) %]
766
                                                [% IF ( s.publicationyear ) %]
767
                                                    in <span class="suggestion_publicationyear"><em>[% suggestions_loo.publicationyear | html %]</em></span>
767
                                                    in <span class="suggestion_publicationyear"><em>[% s.publicationyear | html %]</em></span>
768
                                                [% END %]
768
                                                [% END %]
769
                                                [% IF ( suggestions_loo.place ) %]
769
                                                [% IF ( s.place ) %]
770
                                                    in <span class="suggestion_place"><em>[% suggestions_loo.place | html %]</em></span>
770
                                                    in <span class="suggestion_place"><em>[% s.place | html %]</em></span>
771
                                                [% END %]
771
                                                [% END %]
772
                                                [% IF ( suggestions_loo.collectiontitle ) %]
772
                                                [% IF ( s.collectiontitle ) %]
773
                                                    ; <span class="suggestion_collectiontitle">[% suggestions_loo.collectiontitle | html %]</span>
773
                                                    ; <span class="suggestion_collectiontitle">[% s.collectiontitle | html %]</span>
774
                                                [% END %]
774
                                                [% END %]
775
                                                [% IF ( suggestions_loo.itemtype ) %]
775
                                                [% IF ( s.itemtype ) %]
776
                                                    ; <span class="suggestion_itype">[% AuthorisedValues.GetByCode( 'SUGGEST_FORMAT', suggestions_loo.itemtype, 0 ) | html %]</span>
776
                                                    ; <span class="suggestion_itype">[% AuthorisedValues.GetByCode( 'SUGGEST_FORMAT', s.itemtype, 0 ) | html %]</span>
777
                                                [% END %]
777
                                                [% END %]
778
                                                <br />
778
                                                <br />
779
                                                [% IF ( suggestions_loo.note ) %]
779
                                                [% IF ( s.note ) %]
780
                                                    <div class="suggestion_note"><i class="fa fa-comment"></i> [% suggestions_loo.note | html %]</div>
780
                                                    <div class="suggestion_note"><i class="fa fa-comment"></i> [% s.note | html %]</div>
781
                                                [% END %]
781
                                                [% END %]
782
                                                [% IF suggestions_loo.archived %]
782
                                                [% IF s.archived %]
783
                                                    <br /><i class="fa fa-archive"></i> Archived
783
                                                    <br /><i class="fa fa-archive"></i> Archived
784
                                                [% END %]
784
                                                [% END %]
785
                                            </td>
785
                                            </td>
786
                                            <td>
786
                                            <td>
787
                                                <a href="/cgi-bin/koha/members/moremember.pl?borrowernumber=[% suggestions_loo.suggestedby | uri %]">[% suggestions_loo.surnamesuggestedby | html %][% IF ( suggestions_loo.firstnamesuggestedby ) %], [% suggestions_loo.firstnamesuggestedby | html %][% END %] [% IF (suggestions_loo.cardnumbersuggestedby ) %]([% suggestions_loo.cardnumbersuggestedby | html %])[% END %]</a>
787
                                                [% SET suggester = s.suggester %]
788
                                                <a href="/cgi-bin/koha/members/moremember.pl?borrowernumber=[% suggester.borrowernumber | uri %]">[% suggester.surname | html %][% IF suggester.firstname %], [% suggester.firstname | html %][% END %] [% IF suggester.cardnumber %]([% suggester.cardnumber | html %])[% END %]</a>
788
                                            </td>
789
                                            </td>
789
                                            <td data-order="[% suggestions_loo.suggesteddate | html %]">
790
                                            <td data-order="[% s.suggesteddate | html %]">
790
                                                [% IF ( suggestions_loo.suggesteddate ) %][% suggestions_loo.suggesteddate | $KohaDates %][% END %]
791
                                                [% IF ( s.suggesteddate ) %][% s.suggesteddate | $KohaDates %][% END %]
791
                                            </td>
792
                                            </td>
792
                                            <td>
793
                                            <td>
793
                                                <a href="/cgi-bin/koha/members/moremember.pl?borrowernumber=[% suggestions_loo.managedby | uri %]">[% suggestions_loo.surnamemanagedby | html %][% IF ( suggestions_loo.firstnamemanagedby ) %], [% suggestions_loo.firstnamemanagedby | html %][% END %]</a>
794
                                                [% SET manager = s.manager %]
795
                                                <a href="/cgi-bin/koha/members/moremember.pl?borrowernumber=[% manager.borrowernumber | uri %]">[% manager.surname | html %][% IF manager.firstname %], [% manager.firstname | html %][% END %]</a>
794
                                            </td>
796
                                            </td>
795
                                            <td data-order="[% suggestions_loo.manageddate | html %]">
797
                                            <td data-order="[% s.manageddate | html %]">
796
                                                [% IF ( suggestions_loo.manageddate ) %][% suggestions_loo.manageddate | $KohaDates %][% END %]
798
                                                [% IF ( s.manageddate ) %][% s.manageddate | $KohaDates %][% END %]
797
                                            </td>
799
                                            </td>
798
                                            <td>
800
                                            <td>
799
                                                <a href="/cgi-bin/koha/members/moremember.pl?borrowernumber=[% suggestions_loo.lastmodificationby | uri %]">[% suggestions_loo.surnamelastmodificationby | html %][% IF ( suggestions_loo.firstnamelastmodificationby ) %], [% suggestions_loo.firstnamelastmodificationby | html %][% END %]</a>
801
                                                [% SET last_modifier = s.last_modifier %]
802
                                                <a href="/cgi-bin/koha/members/moremember.pl?borrowernumber=[% last_modifier.borrowernumber | uri %]">[% last_modifier.surname | html %][% IF last_modifier.firstname %], [% last_modifier.firstname | html %][% END %]</a>
800
                                            </td>
803
                                            </td>
801
                                            <td data-order="[% suggestions_loo.lastmodificationdate | html %]">
804
                                            <td data-order="[% s.lastmodificationdate | html %]">
802
                                                [% IF ( suggestions_loo.lastmodificationdate ) %][% suggestions_loo.lastmodificationdate | $KohaDates %][% END %]
805
                                                [% IF ( s.lastmodificationdate ) %][% s.lastmodificationdate | $KohaDates %][% END %]
803
                                            </td>
806
                                            </td>
804
                                            <td>
807
                                            <td>
805
                                                [% suggestions_loo.date | $KohaDates %]
808
                                                [% s.lastmodificationdate | $KohaDates %]
806
                                            </td>
809
                                            </td>
807
                                            <td>
810
                                            <td>
808
                                                [% Branches.GetName( suggestions_loo.branchcode ) | html %]
811
                                                [% Branches.GetName( s.branchcode ) | html %]
809
                                            </td>
812
                                            </td>
810
                                            <td>
813
                                            <td>
811
                                                [% suggestions_loo.budget_name | html %]
814
                                                [% s.fund.budget_name | html %]
812
                                            </td>
815
                                            </td>
813
                                            <td>
816
                                            <td>
814
                                                [% IF ( suggestions_loo.ASKED ) %]
817
                                                [% IF s.STATUS == 'ASKED' %]
815
                                                    Pending
818
                                                    Pending
816
                                                [% ELSIF ( suggestions_loo.ACCEPTED ) %]
819
                                                [% ELSIF s.STATUS == 'ACCEPTED' %]
817
                                                    Accepted
820
                                                    Accepted
818
                                                [% ELSIF ( suggestions_loo.ORDERED ) %]
821
                                                [% ELSIF s.STATUS == 'ORDERED' %]
819
                                                    Ordered
822
                                                    Ordered
820
                                                [% ELSIF ( suggestions_loo.REJECTED ) %]
823
                                                [% ELSIF s.STATUS == 'REJECTED' %]
821
                                                    Rejected
824
                                                    Rejected
822
                                                [% ELSIF ( suggestions_loo.CHECKED ) %]
825
                                                [% ELSIF s.STATUS == 'CHECKED' %]
823
                                                    Checked
826
                                                    Checked
824
                                                [% ELSIF ( suggestions_loo.AVAILABLE ) %]
827
                                                [% ELSIF s.STATUS == 'AVAILABLE' %]
825
                                                    Available
828
                                                    Available
826
                                                [% ELSIF AuthorisedValues.GetByCode( 'SUGGEST_STATUS', suggestions_loo.STATUS ) %]
829
                                                [% ELSIF AuthorisedValues.GetByCode( 'SUGGEST_STATUS', s.STATUS ) %]
827
                                                    [% AuthorisedValues.GetByCode( 'SUGGEST_STATUS', suggestions_loo.STATUS ) | html %]
830
                                                    [% AuthorisedValues.GetByCode( 'SUGGEST_STATUS', s.STATUS ) | html %]
828
                                                [% ELSE %]
831
                                                [% ELSE %]
829
                                                    Status unknown
832
                                                    Status unknown
830
                                                [% END %]
833
                                                [% END %]
831
834
832
                                                [% IF ( suggestions_loo.reason ) %]
835
                                                [% IF ( s.reason ) %]
833
                                                    <br />([% suggestions_loo.reason | html %])
836
                                                    <br />([% s.reason | html %])
834
                                                [% END %]
837
                                                [% END %]
835
                                            </td>
838
                                            </td>
836
                                            <td class="actions">
839
                                            <td class="actions">
837
                                                <div class="btn-group dropup">
840
                                                <div class="btn-group dropup">
838
                                                    <a class="btn btn-default btn-xs" role="button" href="suggestion.pl?suggestionid=[% suggestions_loo.suggestionid | html %]&amp;op=edit"><i class="fa fa-pencil"></i> Edit</a><a class="btn btn-default btn-xs dropdown-toggle" id="more_actions_[% suggestions_loo.suggestionid | html %]" role="button" data-toggle="dropdown" href="#"><b class="caret"></b></a>
841
                                                    <a class="btn btn-default btn-xs" role="button" href="suggestion.pl?suggestionid=[% s.suggestionid | html %]&amp;op=edit"><i class="fa fa-pencil"></i> Edit</a><a class="btn btn-default btn-xs dropdown-toggle" id="more_actions_[% s.suggestionid | html %]" role="button" data-toggle="dropdown" href="#"><b class="caret"></b></a>
839
                                                    <ul class="dropdown-menu pull-right" role="menu" aria-labelledby="more_actions_[% suggestions_loo.suggestionid | html %]">
842
                                                    <ul class="dropdown-menu pull-right" role="menu" aria-labelledby="more_actions_[% s.suggestionid | html %]">
840
                                                        <li><a class="deletesuggestion" href="suggestion.pl?op=delete&amp;suggestionid=[% suggestions_loo.suggestionid | html %]"><i class="fa fa-trash"></i> Delete</a></li>
843
                                                        <li><a class="deletesuggestion" href="suggestion.pl?op=delete&amp;suggestionid=[% s.suggestionid | html %]"><i class="fa fa-trash"></i> Delete</a></li>
841
                                                        [% UNLESS suggestions_loo.archived %]
844
                                                        [% UNLESS s.archived %]
842
                                                            <li><a class="archivesuggestion" href="suggestion.pl?op=archive&amp;suggestionid=[% suggestions_loo.suggestionid | html %]"><i class="fa fa-archive"></i> Archive</a></li>
845
                                                            <li><a class="archivesuggestion" href="suggestion.pl?op=archive&amp;suggestionid=[% s.suggestionid | html %]"><i class="fa fa-archive"></i> Archive</a></li>
843
                                                        [% ELSE %]
846
                                                        [% ELSE %]
844
                                                            <li><a class="unarchivesuggestion" href="suggestion.pl?op=unarchive&amp;suggestionid=[% suggestions_loo.suggestionid | html %]"><i class="fa fa-archive"></i> Unarchive</a></li>
847
                                                            <li><a class="unarchivesuggestion" href="suggestion.pl?op=unarchive&amp;suggestionid=[% s.suggestionid | html %]"><i class="fa fa-archive"></i> Unarchive</a></li>
845
                                                        [% END %]
848
                                                        [% END %]
846
                                                    </ul>
849
                                                    </ul>
847
                                                </div>
850
                                                </div>
848
                                            </td>
851
                                            </td>
849
                                        </tr>
852
                                        </tr>
850
                                    [% END # /FOREACH suggestions_loo %]
853
                                    [% END # /FOREACH s %]
851
                                </tbody>
854
                                </tbody>
852
                            </table> <!-- /#table_[% loop.count | html %] -->
855
                            </table> <!-- /#table_[% loop.count | html %] -->
853
856
Lines 1307-1313 Link Here
1307
1310
1308
                columns_settings = [% TablesSettings.GetColumns( 'acqui', 'suggestions', 'suggestions', 'json' ) | $raw %]
1311
                columns_settings = [% TablesSettings.GetColumns( 'acqui', 'suggestions', 'suggestions', 'json' ) | $raw %]
1309
                [% FOREACH suggestion IN suggestions %]
1312
                [% FOREACH suggestion IN suggestions %]
1310
                    [% IF ( suggestion.suggestions_loop ) %]
1313
                    [% IF suggestion.suggestions.count %]
1311
                        KohaTable("table_[% loop.count| html %]", {
1314
                        KohaTable("table_[% loop.count| html %]", {
1312
                            "sorting": [[ 3, "asc" ]],
1315
                            "sorting": [[ 3, "asc" ]],
1313
                            "autoWidth": false,
1316
                            "autoWidth": false,
(-)a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-suggestions.tt (-34 / +34 lines)
Lines 291-297 Link Here
291
291
292
                            [% IF ( deleted ) %]<div class="alert alert-info">The selected suggestions have been deleted.</div>[% END %]
292
                            [% IF ( deleted ) %]<div class="alert alert-info">The selected suggestions have been deleted.</div>[% END %]
293
293
294
                            [% IF suggestions_loop OR title_filter %]
294
                            [% IF suggestions.count OR title_filter %]
295
                                [% SET can_delete_suggestion = 0 %]
295
                                <form action="/cgi-bin/koha/opac-suggestions.pl" class="form-inline" id="search_suggestions_form" method="get">
296
                                <form action="/cgi-bin/koha/opac-suggestions.pl" class="form-inline" id="search_suggestions_form" method="get">
296
                                    <div class="form-row">
297
                                    <div class="form-row">
297
                                        <label for="title_filter">Search for:</label>
298
                                        <label for="title_filter">Search for:</label>
Lines 318-324 Link Here
318
                                    </div>
319
                                    </div>
319
                                </form>
320
                                </form>
320
                            [% END %]
321
                            [% END %]
321
                            [% IF suggestions_loop %]
322
                            [% IF suggestions.count %]
322
                                [% SET can_delete_suggestion = 0 %]
323
                                [% SET can_delete_suggestion = 0 %]
323
                                <form action="/cgi-bin/koha/opac-suggestions.pl" method="post" id="delete_suggestions">
324
                                <form action="/cgi-bin/koha/opac-suggestions.pl" method="post" id="delete_suggestions">
324
                                    <input type="hidden" name="op" value="delete_confirm" />
325
                                    <input type="hidden" name="op" value="delete_confirm" />
Lines 362-435 Link Here
362
                                            </tr>
363
                                            </tr>
363
                                        </thead>
364
                                        </thead>
364
                                        <tbody>
365
                                        <tbody>
365
                                            [% FOREACH suggestions_loo IN suggestions_loop %]
366
                                            [% FOREACH suggestion IN suggestions %]
366
                                                <tr>
367
                                                <tr>
367
                                                    [% IF ( loggedinusername ) %]
368
                                                    [% IF logged_in_user %]
368
                                                        <td class="selectcol">
369
                                                        <td class="selectcol">
369
                                                            [% IF ( suggestions_loo.showcheckbox ) %]
370
                                                            [% IF logged_in_user.borrowernumber == suggestion.suggester.borrowernumber %]
370
                                                                [% SET can_delete_suggestion = 1 %]
371
                                                                [% SET can_delete_suggestion = 1 %]
371
                                                                <input type="checkbox" class="cb" id="id[% suggestions_loo.suggestionid | html %]" name="delete_field" data-title="[% suggestions_loo.title | html %]" value="[% suggestions_loo.suggestionid | html %]" />
372
                                                                <input type="checkbox" class="cb" id="id[% suggestion.suggestionid | html %]" name="delete_field" data-title="[% suggestion.title | html %]" value="[% suggestion.suggestionid | html %]" />
372
                                                            [% END %]
373
                                                            [% END %]
373
                                                        </td>
374
                                                        </td>
374
                                                    [% END %]
375
                                                    [% END %]
375
                                                    <td>
376
                                                    <td>
376
                                                        <p>
377
                                                        <p>
377
                                                            <label for="id[% suggestions_loo.suggestionid | html %]">
378
                                                            <label for="id[% suggestions_loo.suggestionid | html %]">
378
                                                                [% IF suggestions_loo.biblionumber %]
379
                                                                [% IF suggestion.biblionumber %]
379
                                                                    <strong><a href="/cgi-bin/koha/opac-detail.pl?biblionumber=[% suggestions_loo.biblionumber | uri %]">[% suggestions_loo.title | html %]</a></strong>
380
                                                                    <strong><a href="/cgi-bin/koha/opac-detail.pl?biblionumber=[% suggestion.biblionumber | uri %]">[% suggestion.title | html %]</a></strong>
380
                                                                [% ELSE %]
381
                                                                [% ELSE %]
381
                                                                    <strong>[% suggestions_loo.title | html %]</strong>
382
                                                                    <strong>[% suggestion.title | html %]</strong>
382
                                                                [% END %]
383
                                                                [% END %]
383
                                                            </label>
384
                                                            </label>
384
                                                        </p>
385
                                                        </p>
385
                                                            <p>[% IF ( suggestions_loo.author ) %][% suggestions_loo.author | html %],[% END %]
386
                                                            <p>[% IF ( suggestion.author ) %][% suggestion.author | html %],[% END %]
386
                                                                [% IF ( suggestions_loo.copyrightdate ) %] - [% suggestions_loo.copyrightdate | html %],[% END %]
387
                                                                [% IF ( suggestion.copyrightdate ) %] - [% suggestion.copyrightdate | html %],[% END %]
387
                                                                [% IF ( suggestions_loo.publishercode ) %] - [% suggestions_loo.publishercode | html %][% END %]
388
                                                                [% IF ( suggestion.publishercode ) %] - [% suggestion.publishercode | html %][% END %]
388
                                                                [% IF ( suggestions_loo.place ) %]([% suggestions_loo.place | html %])[% END %]
389
                                                                [% IF ( suggestion.place ) %]([% suggestion.place | html %])[% END %]
389
                                                                [% IF ( suggestions_loo.collectiontitle ) %] , [% suggestions_loo.collectiontitle | html %][% END %]
390
                                                                [% IF ( suggestion.collectiontitle ) %] , [% suggestion.collectiontitle | html %][% END %]
390
                                                                [% IF ( suggestions_loo.itemtype ) %] - [% AuthorisedValues.GetByCode( 'SUGGEST_FORMAT', suggestions_loo.itemtype, 1 ) | html %][% END %]
391
                                                                [% IF ( suggestion.itemtype ) %] - [% AuthorisedValues.GetByCode( 'SUGGEST_FORMAT', suggestion.itemtype, 1 ) | html %][% END %]
391
                                                        </p>
392
                                                        </p>
392
                                                    </td>
393
                                                    </td>
393
                                                    <td>
394
                                                    <td>
394
                                                        [% IF ( suggestions_loo.suggesteddate ) %][% suggestions_loo.suggesteddate |$KohaDates %][% END %]
395
                                                        [% IF ( suggestion.suggesteddate ) %][% suggestion.suggesteddate |$KohaDates %][% END %]
395
                                                    </td>
396
                                                    </td>
396
                                                    <td>
397
                                                    <td>
397
                                                        [% IF ( suggestions_loo.note ) %]
398
                                                        [% IF ( suggestion.note ) %]
398
                                                            <span class="tdlabel">Note: </span>
399
                                                            <span class="tdlabel">Note: </span>
399
                                                            [% suggestions_loo.note | html %]
400
                                                            [% suggestion.note | html %]
400
                                                        [% END %]
401
                                                        [% END %]
401
                                                    </td>
402
                                                    </td>
402
                                                    [% IF Koha.Preference( 'OPACViewOthersSuggestions' ) == 1 %]
403
                                                    [% IF Koha.Preference( 'OPACViewOthersSuggestions' ) == 1 %]
403
                                                        <td>
404
                                                        <td>
404
                                                            [% IF ( suggestions_loo.branchcodesuggestedby ) %]
405
                                                            [% IF suggestion.suggestedby %]
405
                                                                <span class="tdlabel">Suggested for:</span>
406
                                                                <span class="tdlabel">Suggested for:</span>
406
                                                                [% suggestions_loo.branchcodesuggestedby | html %]
407
                                                                [% Branches.GetName(suggestion.suggester.branchcode) | html %]
407
                                                            [% END %]
408
                                                            [% END %]
408
                                                        </td>
409
                                                        </td>
409
                                                    [% END %]
410
                                                    [% END %]
410
                                                    [% IF Koha.Preference( 'OpacSuggestionManagedBy' ) %]
411
                                                    [% IF Koha.Preference( 'OpacSuggestionManagedBy' ) %]
411
                                                    <td>
412
                                                    <td>
412
                                                        [% IF ( suggestions_loo.surnamemanagedby ) %]
413
                                                        [% IF suggestion.managedby %]
413
                                                            <span class="tdlabel">Managed by:</span>
414
                                                            <span class="tdlabel">Managed by:</span>
414
                                                            [% suggestions_loo.surnamemanagedby | html %]
415
                                                            [% INCLUDE 'patron-title.inc' patron = suggestion.manager %]
415
                                                            [% IF ( suggestions_loo.firstnamemanagedby ) %]    , [% suggestions_loo.firstnamemanagedby | html %]
416
                                                            [% IF ( suggestion.manageddate ) %] - [% suggestion.manageddate | $KohaDates %][% END %]
416
                                                            [% END %]
417
                                                        [% END %]
417
                                                        [% END %]
418
                                                    </td>
418
                                                    </td>
419
                                                    [% END %]
419
                                                    [% END %]
420
                                                    <td>
420
                                                    <td>
421
                                                        <span class="tdlabel">Status:</span>
421
                                                        <span class="tdlabel">Status:</span>
422
                                                        [% IF ( suggestions_loo.ASKED ) %]Requested
422
                                                        [% IF ( suggestion.STATUS == 'ASKED' ) %]Requested
423
                                                        [% ELSIF ( suggestions_loo.CHECKED ) %]Checked by the library
423
                                                        [% ELSIF ( suggestion.STATUS == 'CHECKED' ) %]Checked by the library
424
                                                        [% ELSIF ( suggestions_loo.ACCEPTED ) %]Accepted by the library
424
                                                        [% ELSIF ( suggestion.STATUS == 'ACCEPTED' ) %]Accepted by the library
425
                                                        [% ELSIF ( suggestions_loo.ORDERED ) %]Ordered by the library
425
                                                        [% ELSIF ( suggestion.STATUS == 'ORDERED' ) %]Ordered by the library
426
                                                        [% ELSIF ( suggestions_loo.REJECTED ) %]Suggestion declined
426
                                                        [% ELSIF ( suggestion.STATUS == 'REJECTED' ) %]Suggestion declined
427
                                                        [% ELSIF ( suggestions_loo.AVAILABLE ) %]Available in the library
427
                                                        [% ELSIF ( suggestion.STATUS == 'AVAILABLE' ) %]Available in the library
428
                                                        [% ELSE %] [% AuthorisedValues.GetByCode( 'SUGGEST_STATUS', suggestions_loo.STATUS, 1 ) | html %] [% END %]
428
                                                        [% ELSE %] [% AuthorisedValues.GetByCode( 'SUGGEST_STATUS', suggestion.STATUS, 1 ) | html %] [% END %]
429
                                                        [% IF ( suggestions_loo.reason ) %]([% suggestions_loo.reason | html %])[% END %]
429
                                                        [% IF ( suggestion.reason ) %]([% suggestion.reason | html %])[% END %]
430
                                                    </td>
430
                                                    </td>
431
                                                </tr>
431
                                                </tr>
432
                                            [% END # / FOREACH suggestions_loo %]
432
                                            [% END # / FOREACH suggestions %]
433
                                        </tbody>
433
                                        </tbody>
434
                                    </table>
434
                                    </table>
435
435
Lines 468-474 Link Here
468
                                        <p><a class="btn btn-link new" href="/cgi-bin/koha/opac-suggestions.pl?op=add"><i class="fa fa-plus" aria-hidden="true"></i> New purchase suggestion</a></p>
468
                                        <p><a class="btn btn-link new" href="/cgi-bin/koha/opac-suggestions.pl?op=add"><i class="fa fa-plus" aria-hidden="true"></i> New purchase suggestion</a></p>
469
                                    [% END %]
469
                                    [% END %]
470
                                [% END %]
470
                                [% END %]
471
                            [% END # / IF suggestions_loop %]
471
                            [% END # / IF suggestions.count %]
472
472
473
                        [% END # IF op_else %]
473
                        [% END # IF op_else %]
474
                    </div> <!-- / #usersuggestions -->
474
                    </div> <!-- / #usersuggestions -->
(-)a/members/deletemem.pl (-6 / +2 lines)
Lines 30-39 use Try::Tiny qw( catch try ); Link Here
30
use C4::Context;
30
use C4::Context;
31
use C4::Output qw( output_and_exit_if_error output_and_exit output_html_with_http_headers );
31
use C4::Output qw( output_and_exit_if_error output_and_exit output_html_with_http_headers );
32
use C4::Auth qw( get_template_and_user );
32
use C4::Auth qw( get_template_and_user );
33
use C4::Suggestions;
34
use Koha::Patrons;
33
use Koha::Patrons;
35
use Koha::Token;
34
use Koha::Token;
36
use Koha::Patron::Categories;
35
use Koha::Patron::Categories;
36
use Koha::Suggestions;
37
37
38
my $input = CGI->new;
38
my $input = CGI->new;
39
39
Lines 99-109 my $countholds = $dbh->selectrow_array("SELECT COUNT(*) FROM reserves WHERE borr Link Here
99
99
100
# Add warning if patron has pending suggestions
100
# Add warning if patron has pending suggestions
101
$template->param(
101
$template->param(
102
    pending_suggestions => scalar @{
102
    pending_suggestions => Koha::Suggestions->search({ suggestedby => $member, STATUS => 'ASKED' })->count,
103
    C4::Suggestions::SearchSuggestion(
104
            { suggestedby => $member, STATUS => 'ASKED' }
105
        )
106
    }
107
);
103
);
108
104
109
$template->param(
105
$template->param(
(-)a/members/purchase-suggestions.pl (-3 / +2 lines)
Lines 23-31 use CGI qw ( -utf8 ); Link Here
23
use C4::Auth qw( get_template_and_user );
23
use C4::Auth qw( get_template_and_user );
24
use C4::Context;
24
use C4::Context;
25
use C4::Output qw( output_and_exit_if_error output_and_exit output_html_with_http_headers );
25
use C4::Output qw( output_and_exit_if_error output_and_exit output_html_with_http_headers );
26
use C4::Members;
27
use C4::Suggestions qw( SearchSuggestion );
28
use Koha::Patrons;
26
use Koha::Patrons;
27
use Koha::Suggestions;
29
28
30
my $input = CGI->new;
29
my $input = CGI->new;
31
30
Lines 49-55 $template->param( Link Here
49
    suggestionsview  => 1,
48
    suggestionsview  => 1,
50
);
49
);
51
50
52
my $suggestions = SearchSuggestion( { suggestedby => $borrowernumber } );
51
my $suggestions = Koha::Suggestions->search_limited( { suggestedby => $borrowernumber }, { prefetch => 'managedby' } );
53
52
54
$template->param( suggestions => $suggestions );
53
$template->param( suggestions => $suggestions );
55
54
(-)a/opac/opac-suggestions.pl (-41 / +31 lines)
Lines 99-134 else { Link Here
99
    );
99
    );
100
}
100
}
101
101
102
my $suggested_by;
102
if ( $op eq 'else' ) {
103
if ( $op eq 'else' ) {
103
    if ( C4::Context->preference("OPACViewOthersSuggestions") ) {
104
    if ( C4::Context->preference("OPACViewOthersSuggestions") ) {
104
        if ( $borrowernumber ) {
105
        if ( $borrowernumber ) {
105
            # A logged in user is able to see suggestions from others
106
            # A logged in user is able to see suggestions from others
106
            $suggestion->{suggestedby} = $suggested_by_anyone
107
            $suggested_by = $suggested_by_anyone
107
                ? undef
108
                ? undef
108
                : $borrowernumber;
109
                : $borrowernumber;
109
        }
110
        }
110
        else {
111
        # else: Non logged in user is able to see all suggestions
111
            # Non logged in user is able to see all suggestions
112
            $suggestion->{suggestedby} = undef;
113
        }
114
    }
112
    }
115
    else {
113
    else {
116
        if ( $borrowernumber ) {
114
        if ( $borrowernumber ) {
117
            $suggestion->{suggestedby} = $borrowernumber;
115
            $suggested_by = $borrowernumber;
118
        }
116
        }
119
        else {
117
        else {
120
            $suggestion->{suggestedby} = -1;
118
            $suggested_by = -1;
121
        }
119
        }
122
    }
120
    }
123
} else {
121
} else {
124
    if ( $borrowernumber ) {
122
    if ( $borrowernumber ) {
125
        $suggestion->{suggestedby} = $borrowernumber;
123
        $suggested_by = $borrowernumber;
126
    }
124
    }
127
    else {
125
    else {
128
        $suggestion->{suggestedby} = C4::Context->preference("AnonymousPatron");
126
        $suggested_by = C4::Context->preference("AnonymousPatron");
129
    }
127
    }
130
}
128
}
131
129
130
my @suggestion_fields =
131
  qw( title author copyrightdate isbn publishercode collectiontitle place quantity itemtype patronreason note );
132
my $suggestion = {
133
    map {
134
        # Keep parameters that are not an empty string
135
        my $p = $input->param($_);
136
        ( defined $p && $p ne '' ? ( $_ => $p ) : () )
137
    } @suggestion_fields
138
};
139
$suggestion->{suggestedby} = $borrowernumber;
140
132
if ( $op eq "add_validate" && not $biblionumber ) { # If we are creating the suggestion from an existing record we do not want to search for duplicates
141
if ( $op eq "add_validate" && not $biblionumber ) { # If we are creating the suggestion from an existing record we do not want to search for duplicates
133
    $op = 'add_confirm';
142
    $op = 'add_confirm';
134
    my $biblio = MarcRecordFromNewSuggestion($suggestion);
143
    my $biblio = MarcRecordFromNewSuggestion($suggestion);
Lines 154-160 if ( $borrowernumber ){ Link Here
154
}
163
}
155
164
156
if ( $op eq "add_confirm" ) {
165
if ( $op eq "add_confirm" ) {
157
    my $suggestions_loop = &SearchSuggestion($suggestion);
166
    my $suggestions = Koha::Suggestions->search($suggestion);
158
    if ( C4::Context->preference("MaxTotalSuggestions") ne '' && $patrons_total_suggestions_count >= C4::Context->preference("MaxTotalSuggestions") )
167
    if ( C4::Context->preference("MaxTotalSuggestions") ne '' && $patrons_total_suggestions_count >= C4::Context->preference("MaxTotalSuggestions") )
159
    {
168
    {
160
        push @messages, { type => 'error', code => 'total_suggestions' };
169
        push @messages, { type => 'error', code => 'total_suggestions' };
Lines 163-177 if ( $op eq "add_confirm" ) { Link Here
163
    {
172
    {
164
        push @messages, { type => 'error', code => 'too_many' };
173
        push @messages, { type => 'error', code => 'too_many' };
165
    }
174
    }
166
    elsif ( @$suggestions_loop >= 1 ) {
175
    elsif ( $suggestions->count >= 1 ) {
167
176
168
        #some suggestion are answering the request Donot Add
177
        #some suggestion are answering the request Donot Add
169
        for my $s (@$suggestions_loop) {
178
        while ( my $suggestion = $suggestions->next ) {
170
            push @messages,
179
            push @messages,
171
              {
180
              {
172
                type => 'error',
181
                type => 'error',
173
                code => 'already_exists',
182
                code => 'already_exists',
174
                id   => $s->{suggestionid}
183
                id   => $suggestion->suggestionid
175
              };
184
              };
176
            last;
185
            last;
177
        }
186
        }
Lines 196-219 if ( $op eq "add_confirm" ) { Link Here
196
        $patrons_pending_suggestions_count++;
205
        $patrons_pending_suggestions_count++;
197
        $patrons_total_suggestions_count++;
206
        $patrons_total_suggestions_count++;
198
207
199
        # delete empty fields, to avoid filter in "SearchSuggestion"
200
        foreach my $field ( qw( title author publishercode copyrightdate place collectiontitle isbn STATUS ) ) {
201
            delete $suggestion->{$field}; #clear search filters (except borrower related) to show all suggestions after placing a new one
202
        }
203
        $suggestions_loop = &SearchSuggestion($suggestion);
204
205
        push @messages, { type => 'info', code => 'success_on_inserted' };
208
        push @messages, { type => 'info', code => 'success_on_inserted' };
206
209
207
    }
210
    }
208
    $op = 'else';
211
    $op = 'else';
209
}
212
}
210
213
211
my $suggestions_loop = &SearchSuggestion(
214
my $suggestions = Koha::Suggestions->search_limited(
212
    {
215
    {
213
        suggestedby => $suggestion->{suggestedby},
216
        $suggestion->{suggestedby}
214
        title       => $title_filter,
217
        ? ( suggestedby => $suggestion->{suggestedby} )
218
        : (),
219
        $title_filter
220
        ? ( title       => $title_filter )
221
        : (),
215
    }
222
    }
216
);
223
);
224
217
if ( $op eq "delete_confirm" ) {
225
if ( $op eq "delete_confirm" ) {
218
    my @delete_field = $input->multi_param("delete_field");
226
    my @delete_field = $input->multi_param("delete_field");
219
    foreach my $delete_field (@delete_field) {
227
    foreach my $delete_field (@delete_field) {
Lines 224-247 if ( $op eq "delete_confirm" ) { Link Here
224
    exit;
232
    exit;
225
}
233
}
226
234
227
map{
228
    my $s = $_;
229
    my $library = Koha::Libraries->find($s->{branchcodesuggestedby});
230
    $library ? $s->{branchcodesuggestedby} = $library->branchname : ()
231
} @$suggestions_loop;
232
233
foreach my $suggestion(@$suggestions_loop) {
234
    if($suggestion->{'suggestedby'} == $borrowernumber) {
235
        $suggestion->{'showcheckbox'} = $borrowernumber;
236
    } else {
237
        $suggestion->{'showcheckbox'} = 0;
238
    }
239
    if($suggestion->{'patronreason'}){
240
        my $av = Koha::AuthorisedValues->search({ category => 'OPAC_SUG', authorised_value => $suggestion->{patronreason} });
241
        $suggestion->{'patronreason'} = $av->count ? $av->next->opac_description : '';
242
    }
243
}
244
245
my $patron_reason_loop = GetAuthorisedValues("OPAC_SUG", "opac");
235
my $patron_reason_loop = GetAuthorisedValues("OPAC_SUG", "opac");
246
236
247
my @mandatoryfields;
237
my @mandatoryfields;
Lines 279-285 my @unwantedfields; Link Here
279
269
280
$template->param(
270
$template->param(
281
    %$suggestion,
271
    %$suggestion,
282
    suggestions_loop      => $suggestions_loop,
272
    suggestions           => $suggestions,
283
    patron_reason_loop    => $patron_reason_loop,
273
    patron_reason_loop    => $patron_reason_loop,
284
    "op_$op"              => 1,
274
    "op_$op"              => 1,
285
    $op                   => 1,
275
    $op                   => 1,
(-)a/suggestion/suggestion.pl (-15 / +38 lines)
Lines 92-98 my $displayby = $input->param('displayby') || ''; Link Here
92
my $tabcode         = $input->param('tabcode');
92
my $tabcode         = $input->param('tabcode');
93
my $save_confirmed  = $input->param('save_confirmed') || 0;
93
my $save_confirmed  = $input->param('save_confirmed') || 0;
94
my $notify          = $input->param('notify');
94
my $notify          = $input->param('notify');
95
my $filter_archived = $input->param('filter_archived');
95
my $filter_archived = $input->param('filter_archived') || 0;
96
96
97
my $reasonsloop     = GetAuthorisedValues("SUGGEST");
97
my $reasonsloop     = GetAuthorisedValues("SUGGEST");
98
98
Lines 109-114 delete $$suggestion_ref{$_} foreach qw( suggestedbyme op displayby tabcode notif Link Here
109
foreach (keys %$suggestion_ref){
109
foreach (keys %$suggestion_ref){
110
    delete $$suggestion_ref{$_} if (!$$suggestion_ref{$_} && ($op eq 'else' ));
110
    delete $$suggestion_ref{$_} if (!$$suggestion_ref{$_} && ($op eq 'else' ));
111
}
111
}
112
delete $suggestion_only->{branchcode} if $suggestion_only->{branchcode} eq '__ANY__';
113
delete $suggestion_only->{budgetid}   if $suggestion_only->{budgetid}   eq '__ANY__';
114
while ( my ( $k, $v ) = each %$suggestion_only ) {
115
    delete $suggestion_only->{$k} if $v eq '';
116
}
117
112
my ( $template, $borrowernumber, $cookie, $userflags ) = get_template_and_user(
118
my ( $template, $borrowernumber, $cookie, $userflags ) = get_template_and_user(
113
        {
119
        {
114
            template_name   => "suggestion/suggestion.tt",
120
            template_name   => "suggestion/suggestion.tt",
Lines 210-222 if ( $op =~ /save/i ) { Link Here
210
            }
216
            }
211
        } else {
217
        } else {
212
            ###FIXME:Search here if suggestion already exists.
218
            ###FIXME:Search here if suggestion already exists.
213
            my $suggestions_loop =
219
            my $suggestions= Koha::Suggestions->search_limited( $suggestion_only );
214
                SearchSuggestion( $suggestion_only );
220
            if ( $suggestions->count ) {
215
            if (@$suggestions_loop>=1){
216
                #some suggestion are answering the request Donot Add
221
                #some suggestion are answering the request Donot Add
217
                my @messages;
222
                my @messages;
218
                for my $suggestion ( @$suggestions_loop ) {
223
                while ( my $suggestion = $suggestions->next ) {
219
                    push @messages, { type => 'error', code => 'already_exists', id => $suggestion->{suggestionid} };
224
                    push @messages, { type => 'error', code => 'already_exists', id => $suggestion->suggestionid };
220
                }
225
                }
221
                $template->param( messages => \@messages );
226
                $template->param( messages => \@messages );
222
            }
227
            }
Lines 365-384 if ($op=~/else/) { Link Here
365
        next if ( $definedvalue && $$suggestion_ref{$displayby} ne $criteriumvalue ) and ($displayby ne 'branchcode' && $branchfilter ne '__ANY__' );
370
        next if ( $definedvalue && $$suggestion_ref{$displayby} ne $criteriumvalue ) and ($displayby ne 'branchcode' && $branchfilter ne '__ANY__' );
366
        $$suggestion_ref{$displayby} = $criteriumvalue;
371
        $$suggestion_ref{$displayby} = $criteriumvalue;
367
372
368
        my $suggestions = &SearchSuggestion({ %$suggestion_ref, archived => $filter_archived });
373
        # filter on date fields
369
        foreach my $suggestion (@$suggestions) {
374
        foreach my $field (qw( suggesteddate manageddate accepteddate )) {
370
            if ($suggestion->{budgetid}){
375
            my $from = $field . "_from";
371
                my $bud = GetBudget( $suggestion->{budgetid} );
376
            my $to   = $field . "_to";
372
                $suggestion->{budget_name} = $bud->{budget_name} if $bud;
377
            my $from_dt =
378
              $suggestion_ref->{$from}
379
              ? eval { dt_from_string( $suggestion_ref->{$from} ) }
380
              : undef;
381
            my $to_dt =
382
              $suggestion_ref->{$to}
383
              ? eval { dt_from_string( $suggestion_ref->{$to} ) }
384
              : undef;
385
386
            if ( $from_dt || $to_dt ) {
387
                my $dtf = Koha::Database->new->schema->storage->datetime_parser;
388
                my @conditions;
389
                if ( $from_dt && $to_dt ) {
390
                    $suggestion_ref->{$field} = { -between => [ $from_dt, $to_dt ] };
391
                } elsif ( $from_dt ) {
392
                    $suggestion_ref->{$field} = { '>=' => $from_dt };
393
                } elsif ( $to_dt ) {
394
                    $suggestion_ref->{$field} = { '<=' => $to_dt };
395
                }
373
            }
396
            }
374
        }
397
        }
398
        my $suggestions = Koha::Suggestions->search_limited( { %$suggestion_ref, archived => $filter_archived } );
399
375
        push @allsuggestions,{
400
        push @allsuggestions,{
376
                            "suggestiontype"=>$criteriumvalue||"suggest",
401
                            "suggestiontype"=>$criteriumvalue||"suggest",
377
                            "suggestiontypelabel"=>GetCriteriumDesc($criteriumvalue,$displayby)||"",
402
                            "suggestiontypelabel"=>GetCriteriumDesc($criteriumvalue,$displayby)||"",
378
                            "suggestionscount"=>scalar(@$suggestions),             
403
                            'suggestions'     => $suggestions,
379
                            'suggestions_loop'=>$suggestions,
380
                            'reasonsloop'     => $reasonsloop,
404
                            'reasonsloop'     => $reasonsloop,
381
                            } if @$suggestions;
405
                            } if $suggestions->count;
382
406
383
        delete $$suggestion_ref{$displayby} unless $definedvalue;
407
        delete $$suggestion_ref{$displayby} unless $definedvalue;
384
    }
408
    }
385
- 

Return to bug 23991