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/acqui/newordersuggestion.pl (-10 / +10 lines)
Lines 93-102 use Modern::Perl; Link Here
93
use CGI qw ( -utf8 );
93
use CGI qw ( -utf8 );
94
use C4::Auth qw( get_template_and_user );
94
use C4::Auth qw( get_template_and_user );
95
use C4::Output qw( output_html_with_http_headers );
95
use C4::Output qw( output_html_with_http_headers );
96
use C4::Suggestions qw( ConnectSuggestionAndBiblio SearchSuggestion );
96
use C4::Suggestions qw( ConnectSuggestionAndBiblio );
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 301-307 Link Here
301
301
302
                            [% IF ( deleted ) %]<div class="alert alert-info">The selected suggestions have been deleted.</div>[% END %]
302
                            [% IF ( deleted ) %]<div class="alert alert-info">The selected suggestions have been deleted.</div>[% END %]
303
303
304
                            [% IF suggestions_loop OR title_filter %]
304
                            [% IF suggestions.count OR title_filter %]
305
                                [% SET can_delete_suggestion = 0 %]
305
                                <form action="/cgi-bin/koha/opac-suggestions.pl" class="form-inline" id="search_suggestions_form" method="get">
306
                                <form action="/cgi-bin/koha/opac-suggestions.pl" class="form-inline" id="search_suggestions_form" method="get">
306
                                    <div class="form-row">
307
                                    <div class="form-row">
307
                                        <label for="title_filter">Search for:</label>
308
                                        <label for="title_filter">Search for:</label>
Lines 328-334 Link Here
328
                                    </div>
329
                                    </div>
329
                                </form>
330
                                </form>
330
                            [% END %]
331
                            [% END %]
331
                            [% IF suggestions_loop %]
332
                            [% IF suggestions.count %]
332
                                [% SET can_delete_suggestion = 0 %]
333
                                [% SET can_delete_suggestion = 0 %]
333
                                <form action="/cgi-bin/koha/opac-suggestions.pl" method="post" id="delete_suggestions">
334
                                <form action="/cgi-bin/koha/opac-suggestions.pl" method="post" id="delete_suggestions">
334
                                    <input type="hidden" name="op" value="delete_confirm" />
335
                                    <input type="hidden" name="op" value="delete_confirm" />
Lines 372-445 Link Here
372
                                            </tr>
373
                                            </tr>
373
                                        </thead>
374
                                        </thead>
374
                                        <tbody>
375
                                        <tbody>
375
                                            [% FOREACH suggestions_loo IN suggestions_loop %]
376
                                            [% FOREACH suggestion IN suggestions %]
376
                                                <tr>
377
                                                <tr>
377
                                                    [% IF ( loggedinusername ) %]
378
                                                    [% IF logged_in_user %]
378
                                                        <td class="selectcol">
379
                                                        <td class="selectcol">
379
                                                            [% IF ( suggestions_loo.showcheckbox ) %]
380
                                                            [% IF logged_in_user.borrowernumber == suggestion.suggester.borrowernumber %]
380
                                                                [% SET can_delete_suggestion = 1 %]
381
                                                                [% SET can_delete_suggestion = 1 %]
381
                                                                <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 %]" />
382
                                                                <input type="checkbox" class="cb" id="id[% suggestion.suggestionid | html %]" name="delete_field" data-title="[% suggestion.title | html %]" value="[% suggestion.suggestionid | html %]" />
382
                                                            [% END %]
383
                                                            [% END %]
383
                                                        </td>
384
                                                        </td>
384
                                                    [% END %]
385
                                                    [% END %]
385
                                                    <td>
386
                                                    <td>
386
                                                        <p>
387
                                                        <p>
387
                                                            <label for="id[% suggestions_loo.suggestionid | html %]">
388
                                                            <label for="id[% suggestions_loo.suggestionid | html %]">
388
                                                                [% IF suggestions_loo.biblionumber %]
389
                                                                [% IF suggestion.biblionumber %]
389
                                                                    <strong><a href="/cgi-bin/koha/opac-detail.pl?biblionumber=[% suggestions_loo.biblionumber | uri %]">[% suggestions_loo.title | html %]</a></strong>
390
                                                                    <strong><a href="/cgi-bin/koha/opac-detail.pl?biblionumber=[% suggestion.biblionumber | uri %]">[% suggestion.title | html %]</a></strong>
390
                                                                [% ELSE %]
391
                                                                [% ELSE %]
391
                                                                    <strong>[% suggestions_loo.title | html %]</strong>
392
                                                                    <strong>[% suggestion.title | html %]</strong>
392
                                                                [% END %]
393
                                                                [% END %]
393
                                                            </label>
394
                                                            </label>
394
                                                        </p>
395
                                                        </p>
395
                                                            <p>[% IF ( suggestions_loo.author ) %][% suggestions_loo.author | html %],[% END %]
396
                                                            <p>[% IF ( suggestion.author ) %][% suggestion.author | html %],[% END %]
396
                                                                [% IF ( suggestions_loo.copyrightdate ) %] - [% suggestions_loo.copyrightdate | html %],[% END %]
397
                                                                [% IF ( suggestion.copyrightdate ) %] - [% suggestion.copyrightdate | html %],[% END %]
397
                                                                [% IF ( suggestions_loo.publishercode ) %] - [% suggestions_loo.publishercode | html %][% END %]
398
                                                                [% IF ( suggestion.publishercode ) %] - [% suggestion.publishercode | html %][% END %]
398
                                                                [% IF ( suggestions_loo.place ) %]([% suggestions_loo.place | html %])[% END %]
399
                                                                [% IF ( suggestion.place ) %]([% suggestion.place | html %])[% END %]
399
                                                                [% IF ( suggestions_loo.collectiontitle ) %] , [% suggestions_loo.collectiontitle | html %][% END %]
400
                                                                [% IF ( suggestion.collectiontitle ) %] , [% suggestion.collectiontitle | html %][% END %]
400
                                                                [% IF ( suggestions_loo.itemtype ) %] - [% AuthorisedValues.GetByCode( 'SUGGEST_FORMAT', suggestions_loo.itemtype, 1 ) | html %][% END %]
401
                                                                [% IF ( suggestion.itemtype ) %] - [% AuthorisedValues.GetByCode( 'SUGGEST_FORMAT', suggestion.itemtype, 1 ) | html %][% END %]
401
                                                        </p>
402
                                                        </p>
402
                                                    </td>
403
                                                    </td>
403
                                                    <td>
404
                                                    <td>
404
                                                        [% IF ( suggestions_loo.suggesteddate ) %][% suggestions_loo.suggesteddate |$KohaDates %][% END %]
405
                                                        [% IF ( suggestion.suggesteddate ) %][% suggestion.suggesteddate |$KohaDates %][% END %]
405
                                                    </td>
406
                                                    </td>
406
                                                    <td>
407
                                                    <td>
407
                                                        [% IF ( suggestions_loo.note ) %]
408
                                                        [% IF ( suggestion.note ) %]
408
                                                            <span class="tdlabel">Note: </span>
409
                                                            <span class="tdlabel">Note: </span>
409
                                                            [% suggestions_loo.note | html %]
410
                                                            [% suggestion.note | html %]
410
                                                        [% END %]
411
                                                        [% END %]
411
                                                    </td>
412
                                                    </td>
412
                                                    [% IF Koha.Preference( 'OPACViewOthersSuggestions' ) == 1 %]
413
                                                    [% IF Koha.Preference( 'OPACViewOthersSuggestions' ) == 1 %]
413
                                                        <td>
414
                                                        <td>
414
                                                            [% IF ( suggestions_loo.branchcodesuggestedby ) %]
415
                                                            [% IF suggestion.suggestedby %]
415
                                                                <span class="tdlabel">Suggested for:</span>
416
                                                                <span class="tdlabel">Suggested for:</span>
416
                                                                [% suggestions_loo.branchcodesuggestedby | html %]
417
                                                                [% Branches.GetName(suggestion.suggester.branchcode) | html %]
417
                                                            [% END %]
418
                                                            [% END %]
418
                                                        </td>
419
                                                        </td>
419
                                                    [% END %]
420
                                                    [% END %]
420
                                                    [% IF Koha.Preference( 'OpacSuggestionManagedBy' ) %]
421
                                                    [% IF Koha.Preference( 'OpacSuggestionManagedBy' ) %]
421
                                                    <td>
422
                                                    <td>
422
                                                        [% IF ( suggestions_loo.surnamemanagedby ) %]
423
                                                        [% IF suggestion.managedby %]
423
                                                            <span class="tdlabel">Managed by:</span>
424
                                                            <span class="tdlabel">Managed by:</span>
424
                                                            [% suggestions_loo.surnamemanagedby | html %]
425
                                                            [% INCLUDE 'patron-title.inc' patron = suggestion.manager %]
425
                                                            [% IF ( suggestions_loo.firstnamemanagedby ) %]    , [% suggestions_loo.firstnamemanagedby | html %]
426
                                                            [% IF ( suggestion.manageddate ) %] - [% suggestion.manageddate | $KohaDates %][% END %]
426
                                                            [% END %]
427
                                                        [% END %]
427
                                                        [% END %]
428
                                                    </td>
428
                                                    </td>
429
                                                    [% END %]
429
                                                    [% END %]
430
                                                    <td>
430
                                                    <td>
431
                                                        <span class="tdlabel">Status:</span>
431
                                                        <span class="tdlabel">Status:</span>
432
                                                        [% IF ( suggestions_loo.ASKED ) %]Requested
432
                                                        [% IF ( suggestion.STATUS == 'ASKED' ) %]Requested
433
                                                        [% ELSIF ( suggestions_loo.CHECKED ) %]Checked by the library
433
                                                        [% ELSIF ( suggestion.STATUS == 'CHECKED' ) %]Checked by the library
434
                                                        [% ELSIF ( suggestions_loo.ACCEPTED ) %]Accepted by the library
434
                                                        [% ELSIF ( suggestion.STATUS == 'ACCEPTED' ) %]Accepted by the library
435
                                                        [% ELSIF ( suggestions_loo.ORDERED ) %]Ordered by the library
435
                                                        [% ELSIF ( suggestion.STATUS == 'ORDERED' ) %]Ordered by the library
436
                                                        [% ELSIF ( suggestions_loo.REJECTED ) %]Suggestion declined
436
                                                        [% ELSIF ( suggestion.STATUS == 'REJECTED' ) %]Suggestion declined
437
                                                        [% ELSIF ( suggestions_loo.AVAILABLE ) %]Available in the library
437
                                                        [% ELSIF ( suggestion.STATUS == 'AVAILABLE' ) %]Available in the library
438
                                                        [% ELSE %] [% AuthorisedValues.GetByCode( 'SUGGEST_STATUS', suggestions_loo.STATUS, 1 ) | html %] [% END %]
438
                                                        [% ELSE %] [% AuthorisedValues.GetByCode( 'SUGGEST_STATUS', suggestion.STATUS, 1 ) | html %] [% END %]
439
                                                        [% IF ( suggestions_loo.reason ) %]([% suggestions_loo.reason | html %])[% END %]
439
                                                        [% IF ( suggestion.reason ) %]([% suggestion.reason | html %])[% END %]
440
                                                    </td>
440
                                                    </td>
441
                                                </tr>
441
                                                </tr>
442
                                            [% END # / FOREACH suggestions_loo %]
442
                                            [% END # / FOREACH suggestions %]
443
                                        </tbody>
443
                                        </tbody>
444
                                    </table>
444
                                    </table>
445
445
Lines 478-484 Link Here
478
                                        <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>
478
                                        <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>
479
                                    [% END %]
479
                                    [% END %]
480
                                [% END %]
480
                                [% END %]
481
                            [% END # / IF suggestions_loop %]
481
                            [% END # / IF suggestions.count %]
482
482
483
                        [% END # IF op_else %]
483
                        [% END # IF op_else %]
484
                    </div> <!-- / #usersuggestions -->
484
                    </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 (-42 / +31 lines)
Lines 28-34 use C4::Suggestions qw( Link Here
28
    DelSuggestion
28
    DelSuggestion
29
    MarcRecordFromNewSuggestion
29
    MarcRecordFromNewSuggestion
30
    NewSuggestion
30
    NewSuggestion
31
    SearchSuggestion
32
);
31
);
33
use C4::Koha qw( GetAuthorisedValues );
32
use C4::Koha qw( GetAuthorisedValues );
34
use C4::Scrubber;
33
use C4::Scrubber;
Lines 100-135 else { Link Here
100
    );
99
    );
101
}
100
}
102
101
102
my $suggested_by;
103
if ( $op eq 'else' ) {
103
if ( $op eq 'else' ) {
104
    if ( C4::Context->preference("OPACViewOthersSuggestions") ) {
104
    if ( C4::Context->preference("OPACViewOthersSuggestions") ) {
105
        if ( $borrowernumber ) {
105
        if ( $borrowernumber ) {
106
            # A logged in user is able to see suggestions from others
106
            # A logged in user is able to see suggestions from others
107
            $suggestion->{suggestedby} = $suggested_by_anyone
107
            $suggested_by = $suggested_by_anyone
108
                ? undef
108
                ? undef
109
                : $borrowernumber;
109
                : $borrowernumber;
110
        }
110
        }
111
        else {
111
        # else: Non logged in user is able to see all suggestions
112
            # Non logged in user is able to see all suggestions
113
            $suggestion->{suggestedby} = undef;
114
        }
115
    }
112
    }
116
    else {
113
    else {
117
        if ( $borrowernumber ) {
114
        if ( $borrowernumber ) {
118
            $suggestion->{suggestedby} = $borrowernumber;
115
            $suggested_by = $borrowernumber;
119
        }
116
        }
120
        else {
117
        else {
121
            $suggestion->{suggestedby} = -1;
118
            $suggested_by = -1;
122
        }
119
        }
123
    }
120
    }
124
} else {
121
} else {
125
    if ( $borrowernumber ) {
122
    if ( $borrowernumber ) {
126
        $suggestion->{suggestedby} = $borrowernumber;
123
        $suggested_by = $borrowernumber;
127
    }
124
    }
128
    else {
125
    else {
129
        $suggestion->{suggestedby} = C4::Context->preference("AnonymousPatron");
126
        $suggested_by = C4::Context->preference("AnonymousPatron");
130
    }
127
    }
131
}
128
}
132
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
133
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
134
    $op = 'add_confirm';
142
    $op = 'add_confirm';
135
    my $biblio = MarcRecordFromNewSuggestion($suggestion);
143
    my $biblio = MarcRecordFromNewSuggestion($suggestion);
Lines 155-161 if ( $borrowernumber ){ Link Here
155
}
163
}
156
164
157
if ( $op eq "add_confirm" ) {
165
if ( $op eq "add_confirm" ) {
158
    my $suggestions_loop = &SearchSuggestion($suggestion);
166
    my $suggestions = Koha::Suggestions->search($suggestion);
159
    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") )
160
    {
168
    {
161
        push @messages, { type => 'error', code => 'total_suggestions' };
169
        push @messages, { type => 'error', code => 'total_suggestions' };
Lines 164-178 if ( $op eq "add_confirm" ) { Link Here
164
    {
172
    {
165
        push @messages, { type => 'error', code => 'too_many' };
173
        push @messages, { type => 'error', code => 'too_many' };
166
    }
174
    }
167
    elsif ( @$suggestions_loop >= 1 ) {
175
    elsif ( $suggestions->count >= 1 ) {
168
176
169
        #some suggestion are answering the request Donot Add
177
        #some suggestion are answering the request Donot Add
170
        for my $s (@$suggestions_loop) {
178
        while ( my $suggestion = $suggestions->next ) {
171
            push @messages,
179
            push @messages,
172
              {
180
              {
173
                type => 'error',
181
                type => 'error',
174
                code => 'already_exists',
182
                code => 'already_exists',
175
                id   => $s->{suggestionid}
183
                id   => $suggestion->suggestionid
176
              };
184
              };
177
            last;
185
            last;
178
        }
186
        }
Lines 197-220 if ( $op eq "add_confirm" ) { Link Here
197
        $patrons_pending_suggestions_count++;
205
        $patrons_pending_suggestions_count++;
198
        $patrons_total_suggestions_count++;
206
        $patrons_total_suggestions_count++;
199
207
200
        # delete empty fields, to avoid filter in "SearchSuggestion"
201
        foreach my $field ( qw( title author publishercode copyrightdate place collectiontitle isbn STATUS ) ) {
202
            delete $suggestion->{$field}; #clear search filters (except borrower related) to show all suggestions after placing a new one
203
        }
204
        $suggestions_loop = &SearchSuggestion($suggestion);
205
206
        push @messages, { type => 'info', code => 'success_on_inserted' };
208
        push @messages, { type => 'info', code => 'success_on_inserted' };
207
209
208
    }
210
    }
209
    $op = 'else';
211
    $op = 'else';
210
}
212
}
211
213
212
my $suggestions_loop = &SearchSuggestion(
214
my $suggestions = Koha::Suggestions->search_limited(
213
    {
215
    {
214
        suggestedby => $suggestion->{suggestedby},
216
        $suggestion->{suggestedby}
215
        title       => $title_filter,
217
        ? ( suggestedby => $suggestion->{suggestedby} )
218
        : (),
219
        $title_filter
220
        ? ( title       => $title_filter )
221
        : (),
216
    }
222
    }
217
);
223
);
224
218
if ( $op eq "delete_confirm" ) {
225
if ( $op eq "delete_confirm" ) {
219
    my @delete_field = $input->multi_param("delete_field");
226
    my @delete_field = $input->multi_param("delete_field");
220
    foreach my $delete_field (@delete_field) {
227
    foreach my $delete_field (@delete_field) {
Lines 225-248 if ( $op eq "delete_confirm" ) { Link Here
225
    exit;
232
    exit;
226
}
233
}
227
234
228
map{
229
    my $s = $_;
230
    my $library = Koha::Libraries->find($s->{branchcodesuggestedby});
231
    $library ? $s->{branchcodesuggestedby} = $library->branchname : ()
232
} @$suggestions_loop;
233
234
foreach my $suggestion(@$suggestions_loop) {
235
    if($suggestion->{'suggestedby'} == $borrowernumber) {
236
        $suggestion->{'showcheckbox'} = $borrowernumber;
237
    } else {
238
        $suggestion->{'showcheckbox'} = 0;
239
    }
240
    if($suggestion->{'patronreason'}){
241
        my $av = Koha::AuthorisedValues->search({ category => 'OPAC_SUG', authorised_value => $suggestion->{patronreason} });
242
        $suggestion->{'patronreason'} = $av->count ? $av->next->opac_description : '';
243
    }
244
}
245
246
my $patron_reason_loop = GetAuthorisedValues("OPAC_SUG", "opac");
235
my $patron_reason_loop = GetAuthorisedValues("OPAC_SUG", "opac");
247
236
248
my @mandatoryfields;
237
my @mandatoryfields;
Lines 279-285 my @unwantedfields; Link Here
279
268
280
$template->param(
269
$template->param(
281
    %$suggestion,
270
    %$suggestion,
282
    suggestions_loop      => $suggestions_loop,
271
    suggestions           => $suggestions,
283
    patron_reason_loop    => $patron_reason_loop,
272
    patron_reason_loop    => $patron_reason_loop,
284
    "op_$op"              => 1,
273
    "op_$op"              => 1,
285
    $op                   => 1,
274
    $op                   => 1,
(-)a/suggestion/suggestion.pl (-15 / +37 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 213-225 if ( $op =~ /save/i ) { Link Here
213
            }
219
            }
214
        } else {
220
        } else {
215
            ###FIXME:Search here if suggestion already exists.
221
            ###FIXME:Search here if suggestion already exists.
216
            my $suggestions_loop =
222
            my $suggestions= Koha::Suggestions->search_limited( $suggestion_only );
217
                SearchSuggestion( $suggestion_only );
223
            if ( $suggestions->count ) {
218
            if (@$suggestions_loop>=1){
219
                #some suggestion are answering the request Donot Add
224
                #some suggestion are answering the request Donot Add
220
                my @messages;
225
                my @messages;
221
                for my $suggestion ( @$suggestions_loop ) {
226
                while ( my $suggestion = $suggestions->next ) {
222
                    push @messages, { type => 'error', code => 'already_exists', id => $suggestion->{suggestionid} };
227
                    push @messages, { type => 'error', code => 'already_exists', id => $suggestion->suggestionid };
223
                }
228
                }
224
                $template->param( messages => \@messages );
229
                $template->param( messages => \@messages );
225
            }
230
            }
Lines 368-387 if ($op=~/else/) { Link Here
368
        next if ( $definedvalue && $$suggestion_ref{$displayby} ne $criteriumvalue ) and ($displayby ne 'branchcode' && $branchfilter ne '__ANY__' );
373
        next if ( $definedvalue && $$suggestion_ref{$displayby} ne $criteriumvalue ) and ($displayby ne 'branchcode' && $branchfilter ne '__ANY__' );
369
        $$suggestion_ref{$displayby} = $criteriumvalue;
374
        $$suggestion_ref{$displayby} = $criteriumvalue;
370
375
371
        my $suggestions = &SearchSuggestion({ %$suggestion_ref, archived => $filter_archived });
376
        # filter on date fields
372
        foreach my $suggestion (@$suggestions) {
377
        foreach my $field (qw( suggesteddate manageddate accepteddate )) {
373
            if ($suggestion->{budgetid}){
378
            my $from = $field . "_from";
374
                my $bud = GetBudget( $suggestion->{budgetid} );
379
            my $to   = $field . "_to";
375
                $suggestion->{budget_name} = $bud->{budget_name} if $bud;
380
            my $from_dt =
381
              $suggestion_ref->{$from}
382
              ? eval { dt_from_string( $suggestion_ref->{$from} ) }
383
              : undef;
384
            my $to_dt =
385
              $suggestion_ref->{$to}
386
              ? eval { dt_from_string( $suggestion_ref->{$to} ) }
387
              : undef;
388
389
            if ( $from_dt || $to_dt ) {
390
                my $dtf = Koha::Database->new->schema->storage->datetime_parser;
391
                if ( $from_dt && $to_dt ) {
392
                    $suggestion_ref->{$field} = { -between => [ $from_dt, $to_dt ] };
393
                } elsif ( $from_dt ) {
394
                    $suggestion_ref->{$field} = { '>=' => $from_dt };
395
                } elsif ( $to_dt ) {
396
                    $suggestion_ref->{$field} = { '<=' => $to_dt };
397
                }
376
            }
398
            }
377
        }
399
        }
400
        my $suggestions = Koha::Suggestions->search_limited( { %$suggestion_ref, archived => $filter_archived } );
401
378
        push @allsuggestions,{
402
        push @allsuggestions,{
379
                            "suggestiontype"=>$criteriumvalue||"suggest",
403
                            "suggestiontype"=>$criteriumvalue||"suggest",
380
                            "suggestiontypelabel"=>GetCriteriumDesc($criteriumvalue,$displayby)||"",
404
                            "suggestiontypelabel"=>GetCriteriumDesc($criteriumvalue,$displayby)||"",
381
                            "suggestionscount"=>scalar(@$suggestions),             
405
                            'suggestions'     => $suggestions,
382
                            'suggestions_loop'=>$suggestions,
383
                            'reasonsloop'     => $reasonsloop,
406
                            'reasonsloop'     => $reasonsloop,
384
                            } if @$suggestions;
407
                            } if $suggestions->count;
385
408
386
        delete $$suggestion_ref{$displayby} unless $definedvalue;
409
        delete $$suggestion_ref{$displayby} unless $definedvalue;
387
    }
410
    }
388
- 

Return to bug 23991