X-Git-Url: http://koha-dev.rot13.org:8081/gitweb/?a=blobdiff_plain;f=admin%2Fcategorie.pl;h=4a5d68390c021b75fe73df35dfc0e44eb21a3587;hb=76184e1db031014cee432ec6d9a78fe87768983c;hp=886260a2265612aa9ae5589436938fbc45e79f62;hpb=737730e4a6e029ca97794d7a4769abe778012216;p=koha_gimpoz diff --git a/admin/categorie.pl b/admin/categorie.pl index 886260a226..4a5d68390c 100755 --- a/admin/categorie.pl +++ b/admin/categorie.pl @@ -32,15 +32,18 @@ # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR # A PARTICULAR PURPOSE. See the GNU General Public License for more details. # -# You should have received a copy of the GNU General Public License along with -# Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place, -# Suite 330, Boston, MA 02111-1307 USA +# You should have received a copy of the GNU General Public License along +# with Koha; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. use strict; +#use warnings; FIXME - Bug 2505 use CGI; use C4::Context; use C4::Auth; use C4::Output; +use C4::Dates; +use C4::Form::MessagingPreferences; sub StringSearch { my ($searchstring,$type)=@_; @@ -48,7 +51,7 @@ sub StringSearch { $searchstring=~ s/\'/\\\'/g; my @data=split(' ',$searchstring); my $count=@data; - my $sth=$dbh->prepare("Select * from categories where (description like ?) order by category_type,description"); + my $sth=$dbh->prepare("Select * from categories where (description like ?) order by category_type,description,categorycode"); $sth->execute("$data[0]%"); my @results; while (my $data=$sth->fetchrow_hashref){ @@ -89,14 +92,17 @@ if ($op eq 'add_form') { my $data; if ($categorycode) { my $dbh = C4::Context->dbh; - my $sth=$dbh->prepare("select categorycode,description,enrolmentperiod,upperagelimit,dateofbirthrequired,enrolmentfee,issuelimit,reservefee,overduenoticerequired,category_type from categories where categorycode=?"); + my $sth=$dbh->prepare("select categorycode,description,enrolmentperiod,enrolmentperioddate,upperagelimit,dateofbirthrequired,enrolmentfee,issuelimit,reservefee,overduenoticerequired,category_type from categories where categorycode=?"); $sth->execute($categorycode); $data=$sth->fetchrow_hashref; $sth->finish; } + $data->{'enrolmentperioddate'} = undef if ($data->{'enrolmentperioddate'} eq '0000-00-00'); + $template->param(description => $data->{'description'}, enrolmentperiod => $data->{'enrolmentperiod'}, + enrolmentperioddate => C4::Dates::format_date($data->{'enrolmentperioddate'}), upperagelimit => $data->{'upperagelimit'}, dateofbirthrequired => $data->{'dateofbirthrequired'}, enrolmentfee => sprintf("%.2f",$data->{'enrolmentfee'}), @@ -104,8 +110,12 @@ if ($op eq 'add_form') { issuelimit => $data->{'issuelimit'}, reservefee => sprintf("%.2f",$data->{'reservefee'}), category_type => $data->{'category_type'}, + DHTMLcalendar_dateformat => C4::Dates->DHTMLcalendar(), "type_".$data->{'category_type'} => 1, ); + if (C4::Context->preference('EnhancedMessagingPreferences')) { + C4::Form::MessagingPreferences::set_form_values({ categorycode => $categorycode } , $template); + } # END $OP eq ADD_FORM ################## ADD_VALIDATE ################################## # called by add_form, used to insert/modify data in DB @@ -113,15 +123,23 @@ if ($op eq 'add_form') { $template->param(add_validate => 1); my $is_a_modif = $input->param("is_a_modif"); my $dbh = C4::Context->dbh; + if($input->param('enrolmentperioddate')){ + $input->param('enrolmentperioddate' => C4::Dates::format_date_in_iso($input->param('enrolmentperioddate')) ); + } + if ($is_a_modif) { - my $sth=$dbh->prepare("UPDATE categories SET description=?,enrolmentperiod=?,upperagelimit=?,dateofbirthrequired=?,enrolmentfee=?,reservefee=?,overduenoticerequired=?,category_type=? WHERE categorycode=?"); - $sth->execute(map { $input->param($_) } ('description','enrolmentperiod','upperagelimit','dateofbirthrequired','enrolmentfee','reservefee','overduenoticerequired','category_type','categorycode')); + my $sth=$dbh->prepare("UPDATE categories SET description=?,enrolmentperiod=?, enrolmentperioddate=?,upperagelimit=?,dateofbirthrequired=?,enrolmentfee=?,reservefee=?,overduenoticerequired=?,category_type=? WHERE categorycode=?"); + $sth->execute(map { $input->param($_) } ('description','enrolmentperiod','enrolmentperioddate','upperagelimit','dateofbirthrequired','enrolmentfee','reservefee','overduenoticerequired','category_type','categorycode')); $sth->finish; } else { - my $sth=$dbh->prepare("INSERT INTO categories (categorycode,description,enrolmentperiod,upperagelimit,dateofbirthrequired,enrolmentfee,reservefee,overduenoticerequired,category_type) values (?,?,?,?,?,?,?,?,?)"); - $sth->execute(map { $input->param($_) } ('categorycode','description','enrolmentperiod','upperagelimit','dateofbirthrequired','enrolmentfee','reservefee','overduenoticerequired','category_type')); + my $sth=$dbh->prepare("INSERT INTO categories (categorycode,description,enrolmentperiod,enrolmentperioddate,upperagelimit,dateofbirthrequired,enrolmentfee,reservefee,overduenoticerequired,category_type) values (?,?,?,?,?,?,?,?,?,?)"); + $sth->execute(map { $input->param($_) } ('categorycode','description','enrolmentperiod','enrolmentperioddate','upperagelimit','dateofbirthrequired','enrolmentfee','reservefee','overduenoticerequired','category_type')); $sth->finish; } + if (C4::Context->preference('EnhancedMessagingPreferences')) { + C4::Form::MessagingPreferences::handle_form_action($input, + { categorycode => $input->param('categorycode') }, $template); + } print "Content-Type: text/html\n\n"; exit; @@ -138,7 +156,7 @@ if ($op eq 'add_form') { $sth->finish; $template->param(total => $total->{'total'}); - my $sth2=$dbh->prepare("select categorycode,description,enrolmentperiod,upperagelimit,dateofbirthrequired,enrolmentfee,issuelimit,reservefee,overduenoticerequired,category_type from categories where categorycode=?"); + my $sth2=$dbh->prepare("select categorycode,description,enrolmentperiod,enrolmentperioddate,upperagelimit,dateofbirthrequired,enrolmentfee,issuelimit,reservefee,overduenoticerequired,category_type from categories where categorycode=?"); $sth2->execute($categorycode); my $data=$sth2->fetchrow_hashref; $sth2->finish; @@ -146,8 +164,9 @@ if ($op eq 'add_form') { $template->param(totalgtzero => 1); } - $template->param(description => $data->{'description'}, + $template->param( description => $data->{'description'}, enrolmentperiod => $data->{'enrolmentperiod'}, + enrolmentperioddate => C4::Dates::format_date($data->{'enrolmentperioddate'}), upperagelimit => $data->{'upperagelimit'}, dateofbirthrequired => $data->{'dateofbirthrequired'}, enrolmentfee => sprintf("%.2f",$data->{'enrolmentfee'}), @@ -174,29 +193,25 @@ if ($op eq 'add_form') { $template->param(else => 1); my @loop; my ($count,$results)=StringSearch($searchfield,'web'); - my $toggle = 0; for (my $i=0; $i < $count; $i++){ - my %row = (categorycode => $results->[$i]{'categorycode'}, - description => $results->[$i]{'description'}, - enrolmentperiod => $results->[$i]{'enrolmentperiod'}, - upperagelimit => $results->[$i]{'upperagelimit'}, - dateofbirthrequired => $results->[$i]{'dateofbirthrequired'}, - enrolmentfee => sprintf("%.2f",$results->[$i]{'enrolmentfee'}), - overduenoticerequired => $results->[$i]{'overduenoticerequired'}, - issuelimit => $results->[$i]{'issuelimit'}, - reservefee => sprintf("%.2f",$results->[$i]{'reservefee'}), - category_type => $results->[$i]{'category_type'}, - "type_".$results->[$i]{'category_type'} => 1, - toggle => $toggle ); + my %row = ( + categorycode => $results->[$i]{'categorycode'}, + description => $results->[$i]{'description'}, + enrolmentperiod => $results->[$i]{'enrolmentperiod'}, + enrolmentperioddate => C4::Dates::format_date($results->[$i]{'enrolmentperioddate'}), + upperagelimit => $results->[$i]{'upperagelimit'}, + dateofbirthrequired => $results->[$i]{'dateofbirthrequired'}, + enrolmentfee => sprintf("%.2f",$results->[$i]{'enrolmentfee'}), + overduenoticerequired => $results->[$i]{'overduenoticerequired'}, + issuelimit => $results->[$i]{'issuelimit'}, + reservefee => sprintf("%.2f",$results->[$i]{'reservefee'}), + category_type => $results->[$i]{'category_type'}, + "type_".$results->[$i]{'category_type'} => 1); + if (C4::Context->preference('EnhancedMessagingPreferences')) { + my $brief_prefs = _get_brief_messaging_prefs($results->[$i]{'categorycode'}); + $row{messaging_prefs} = $brief_prefs if @$brief_prefs; + } push @loop, \%row; - if ( $toggle eq 0 ) - { - $toggle = 1; - } - else - { - $toggle = 0; - } } $template->param(loop => \@loop); # check that I (institution) and C (child) exists. otherwise => warning to the user @@ -213,11 +228,27 @@ if ($op eq 'add_form') { } #---- END $OP eq DEFAULT - - -$template->param(intranetcolorstylesheet => C4::Context->preference("intranetcolorstylesheet"), - intranetstylesheet => C4::Context->preference("intranetstylesheet"), - IntranetNav => C4::Context->preference("IntranetNav"), - ); output_html_with_http_headers $input, $cookie, $template->output; +exit 0; + +sub _get_brief_messaging_prefs { + my $categorycode = shift; + my $messaging_options = C4::Members::Messaging::GetMessagingOptions(); + my $results = []; + PREF: foreach my $option ( @$messaging_options ) { + my $pref = C4::Members::Messaging::GetMessagingPreferences( { categorycode => $categorycode, + message_name => $option->{'message_name'} } ); + next unless $pref->{'transports'}; + my $brief_pref = { + message_attribute_id => $option->{'message_attribute_id'}, + message_name => $option->{'message_name'}, + $option->{'message_name'} => 1 + }; + foreach my $transport ( @{$pref->{'transports'}} ) { + push @{ $brief_pref->{'transports'} }, { transport => $transport }; + } + push @$results, $brief_pref; + } + return $results; +}