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

(-)a/C4/Suggestions.pm (-4 / +21 lines)
Lines 26-32 use CGI; Link Here
26
use C4::Context;
26
use C4::Context;
27
use C4::Output;
27
use C4::Output;
28
use C4::Dates qw(format_date format_date_in_iso);
28
use C4::Dates qw(format_date format_date_in_iso);
29
use C4::SQLHelper qw(:all);
30
use C4::Debug;
29
use C4::Debug;
31
use C4::Letters;
30
use C4::Letters;
32
use List::MoreUtils qw(any);
31
use List::MoreUtils qw(any);
Lines 426-433 Insert a new suggestion on database with value given on input arg. Link Here
426
425
427
sub NewSuggestion {
426
sub NewSuggestion {
428
    my ($suggestion) = @_;
427
    my ($suggestion) = @_;
428
429
    my $new_suggestion = { %$suggestion };
429
    $suggestion->{STATUS} = "ASKED" unless $suggestion->{STATUS};
430
    $suggestion->{STATUS} = "ASKED" unless $suggestion->{STATUS};
430
    return InsertInTable( "suggestions", $suggestion );
431
    $new_suggestion->{status} = $suggestion->{STATUS};
432
    delete $new_suggestion->{STATUS};
433
434
    my $rs = Koha::Database->new->schema->resultset('Suggestion');
435
    return $rs->create($new_suggestion)->id;
431
}
436
}
432
437
433
=head2 ModSuggestion
438
=head2 ModSuggestion
Lines 445-453 Note that there is no function to modify a suggestion. Link Here
445
450
446
sub ModSuggestion {
451
sub ModSuggestion {
447
    my ($suggestion) = @_;
452
    my ($suggestion) = @_;
448
    my $status_update_table = UpdateInTable( "suggestions", $suggestion );
453
    return unless( $suggestion and defined($suggestion->{suggestionid}) );
454
455
    my $mod_suggestion = { %$suggestion };
456
    my $status = $suggestion->{STATUS};
457
    delete $mod_suggestion->{STATUS};
458
    $mod_suggestion->{status} = $status;
459
460
    my $rs = Koha::Database->new->schema->resultset('Suggestion')->find($suggestion->{suggestionid});
461
    my $status_update_table = 1;
462
    eval {
463
        $rs->update($mod_suggestion);
464
    };
465
    $status_update_table = 0 if( $@ );
449
466
450
    if ( $suggestion->{STATUS} ) {
467
    if ( $status ) {
451
468
452
        # fetch the entire updated suggestion so that we can populate the letter
469
        # fetch the entire updated suggestion so that we can populate the letter
453
        my $full_suggestion = GetSuggestion( $suggestion->{suggestionid} );
470
        my $full_suggestion = GetSuggestion( $suggestion->{suggestionid} );
(-)a/opac/opac-suggestions.pl (+1 lines)
Lines 33-38 my $input = new CGI; Link Here
33
my $allsuggestions  = $input->param('showall');
33
my $allsuggestions  = $input->param('showall');
34
my $op              = $input->param('op');
34
my $op              = $input->param('op');
35
my $suggestion      = $input->Vars;
35
my $suggestion      = $input->Vars;
36
delete $suggestion->{negcap};
36
my $negcaptcha      = $input->param('negcap');
37
my $negcaptcha      = $input->param('negcap');
37
38
38
# If a spambot accidentally populates the 'negcap' field in the sugesstions form, then silently skip and return.
39
# If a spambot accidentally populates the 'negcap' field in the sugesstions form, then silently skip and return.
(-)a/suggestion/suggestion.pl (-21 / +27 lines)
Lines 95-100 my $tabcode = $input->param('tabcode'); Link Here
95
# filter informations which are not suggestion related.
95
# filter informations which are not suggestion related.
96
my $suggestion_ref  = $input->Vars;
96
my $suggestion_ref  = $input->Vars;
97
97
98
# get only the columns of Suggestion
99
my $schema = Koha::Database->new()->schema;
100
my $columns = ' '.join(' ', $schema->source('Suggestion')->columns).' ';
101
my $suggestion_only = { map { $columns =~ / $_ / ? ($_ => $suggestion_ref->{$_}) : () } keys($suggestion_ref) };
102
$suggestion_only->{STATUS} = $suggestion_ref->{STATUS};
103
98
delete $$suggestion_ref{$_} foreach qw( suggestedbyme op displayby tabcode edit_field );
104
delete $$suggestion_ref{$_} foreach qw( suggestedbyme op displayby tabcode edit_field );
99
foreach (keys %$suggestion_ref){
105
foreach (keys %$suggestion_ref){
100
    delete $$suggestion_ref{$_} if (!$$suggestion_ref{$_} && ($op eq 'else' || $op eq 'change'));
106
    delete $$suggestion_ref{$_} if (!$$suggestion_ref{$_} && ($op eq 'else' || $op eq 'change'));
Lines 115-140 $template->param('borrowernumber' => $borrowernumber); Link Here
115
##  Operations
121
##  Operations
116
##
122
##
117
if ( $op =~ /save/i ) {
123
if ( $op =~ /save/i ) {
118
        if ( $$suggestion_ref{"STATUS"} ) {
124
        if ( $suggestion_only->{"STATUS"} ) {
119
        if ( my $tmpstatus = lc( $$suggestion_ref{"STATUS"} ) =~ /ACCEPTED|REJECTED/i ) {
125
        if ( my $tmpstatus = lc( $suggestion_only->{"STATUS"} ) =~ /ACCEPTED|REJECTED/i ) {
120
            $$suggestion_ref{ lc( $$suggestion_ref{"STATUS"}) . "date" } = C4::Dates->today;
126
            $suggestion_only->{ lc( $suggestion_only->{"STATUS"}) . "date" } = C4::Dates->today;
121
            $$suggestion_ref{ lc( $$suggestion_ref{"STATUS"}) . "by" }   = C4::Context->userenv->{number};
127
            $suggestion_only->{ lc( $suggestion_only->{"STATUS"}) . "by" }   = C4::Context->userenv->{number};
122
        }
128
        }
123
        $$suggestion_ref{"manageddate"} = C4::Dates->today;
129
        $suggestion_only->{"manageddate"} = C4::Dates->today;
124
        $$suggestion_ref{"managedby"}   = C4::Context->userenv->{number};
130
        $suggestion_only->{"managedby"}   = C4::Context->userenv->{number};
125
    }
131
    }
126
    if ( $$suggestion_ref{'suggestionid'} > 0 ) {
132
    if ( $suggestion_only->{'suggestionid'} > 0 ) {
127
        &ModSuggestion($suggestion_ref);
133
        &ModSuggestion($suggestion_only);
128
    } else {
134
    } else {
129
        ###FIXME:Search here if suggestion already exists.
135
        ###FIXME:Search here if suggestion already exists.
130
        my $suggestions_loop =
136
        my $suggestions_loop =
131
            SearchSuggestion( $suggestion_ref );
137
            SearchSuggestion( $suggestion_only );
132
        if (@$suggestions_loop>=1){
138
        if (@$suggestions_loop>=1){
133
            #some suggestion are answering the request Donot Add
139
            #some suggestion are answering the request Donot Add
134
        } 
140
        } 
135
        else {    
141
        else {    
136
            ## Adding some informations related to suggestion
142
            ## Adding some informations related to suggestion
137
            &NewSuggestion($suggestion_ref);
143
            &NewSuggestion($suggestion_only);
138
        }
144
        }
139
        # empty fields, to avoid filter in "SearchSuggestion"
145
        # empty fields, to avoid filter in "SearchSuggestion"
140
    }  
146
    }  
Lines 160-175 elsif ($op=~/edit/) { Link Here
160
elsif ($op eq "change" ) {
166
elsif ($op eq "change" ) {
161
    # set accepted/rejected/managed informations if applicable
167
    # set accepted/rejected/managed informations if applicable
162
    # ie= if the librarian has choosen some action on the suggestions
168
    # ie= if the librarian has choosen some action on the suggestions
163
    if ($$suggestion_ref{"STATUS"} eq "ACCEPTED"){
169
    if ($suggestion_only->{"STATUS"} eq "ACCEPTED"){
164
        $$suggestion_ref{"accepteddate"}=C4::Dates->today;
170
        $suggestion_only->{"accepteddate"}=C4::Dates->today;
165
        $$suggestion_ref{"acceptedby"}=C4::Context->userenv->{number};
171
        $suggestion_only->{"acceptedby"}=C4::Context->userenv->{number};
166
    } elsif ($$suggestion_ref{"STATUS"} eq "REJECTED"){
172
    } elsif ($suggestion_only->{"STATUS"} eq "REJECTED"){
167
        $$suggestion_ref{"rejecteddate"}=C4::Dates->today;
173
        $suggestion_only->{"rejecteddate"}=C4::Dates->today;
168
        $$suggestion_ref{"rejectedby"}=C4::Context->userenv->{number};
174
        $suggestion_only->{"rejectedby"}=C4::Context->userenv->{number};
169
    }
175
    }
170
    if ($$suggestion_ref{"STATUS"}){
176
    if ($suggestion_only->{"STATUS"}){
171
        $$suggestion_ref{"manageddate"}=C4::Dates->today;
177
        $suggestion_only->{"manageddate"}=C4::Dates->today;
172
        $$suggestion_ref{"managedby"}=C4::Context->userenv->{number};
178
        $suggestion_only->{"managedby"}=C4::Context->userenv->{number};
173
    }
179
    }
174
    if ( my $reason = $$suggestion_ref{"reason$tabcode"}){
180
    if ( my $reason = $$suggestion_ref{"reason$tabcode"}){
175
        if ( $reason eq "other" ) {
181
        if ( $reason eq "other" ) {
Lines 183-190 elsif ($op eq "change" ) { Link Here
183
    }
189
    }
184
    foreach my $suggestionid (@editsuggestions) {
190
    foreach my $suggestionid (@editsuggestions) {
185
        next unless $suggestionid;
191
        next unless $suggestionid;
186
        $$suggestion_ref{'suggestionid'}=$suggestionid;
192
        $suggestion_only->{'suggestionid'}=$suggestionid;
187
        &ModSuggestion($suggestion_ref);
193
        &ModSuggestion($suggestion_only);
188
    }
194
    }
189
    my $params = '';
195
    my $params = '';
190
    foreach my $key (
196
    foreach my $key (
(-)a/t/db_dependent/Suggestions.t (-2 / +1 lines)
Lines 89-95 my $mod_suggestion1 = { Link Here
89
    publishercode => 'my modified publishercode',
89
    publishercode => 'my modified publishercode',
90
};
90
};
91
my $status = ModSuggestion($mod_suggestion1);
91
my $status = ModSuggestion($mod_suggestion1);
92
is( $status, '0E0', 'ModSuggestion without the suggestion id returns 0E0' );
92
is( $status, undef, 'ModSuggestion without the suggestion id returns undef' );
93
93
94
$mod_suggestion1->{suggestionid} = $my_suggestionid;
94
$mod_suggestion1->{suggestionid} = $my_suggestionid;
95
$status = ModSuggestion($mod_suggestion1);
95
$status = ModSuggestion($mod_suggestion1);
96
- 

Return to bug 12627