X-Git-Url: http://koha-dev.rot13.org:8081/gitweb/?a=blobdiff_plain;f=admin%2Fcategorie.pl;h=521346b15df48c82a6a16f2b8270550049a5a3b6;hb=2bc542789fdf9d551a408bc8349daa062a37c496;hp=ab99eaaed89ac04c52ce8fd6cf23276c968c0020;hpb=7dc774ec29e2b6f48115a28435e8f5219c286c90;p=koha_gimpoz diff --git a/admin/categorie.pl b/admin/categorie.pl index ab99eaaed8..521346b15d 100755 --- a/admin/categorie.pl +++ b/admin/categorie.pl @@ -32,37 +32,34 @@ # 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::Output; -use C4::Search; -use HTML::Template; use C4::Auth; -use C4::Interface::CGI::Output; +use C4::Output; +use C4::Dates; +use C4::Form::MessagingPreferences; sub StringSearch { - my ($env,$searchstring,$type)=@_; + my ($searchstring,$type)=@_; my $dbh = C4::Context->dbh; $searchstring=~ s/\'/\\\'/g; my @data=split(' ',$searchstring); my $count=@data; - my $query="Select * from categories where (description like \"$data[0]%\")"; - my $sth=$dbh->prepare($query); - $sth->execute; + my $sth=$dbh->prepare("Select * from categories where (description like ?) order by category_type,description,categorycode"); + $sth->execute("$data[0]%"); my @results; - my $cnt=0; while (my $data=$sth->fetchrow_hashref){ push(@results,$data); - $cnt ++; } # $sth->execute; $sth->finish; - return ($cnt,\@results); + return (scalar(@results),\@results); } my $input = new CGI; @@ -70,13 +67,13 @@ my $searchfield=$input->param('description'); my $script_name="/cgi-bin/koha/admin/categorie.pl"; my $categorycode=$input->param('categorycode'); my $op = $input->param('op'); -$searchfield=~ s/\,//g; my ($template, $loggedinuser, $cookie) - = get_template_and_user({template_name => "parameters/categorie.tmpl", + = get_template_and_user({template_name => "admin/categorie.tmpl", query => $input, type => "intranet", authnotrequired => 0, + flagsrequired => {parameters => 1}, debug => 1, }); @@ -95,43 +92,59 @@ if ($op eq 'add_form') { my $data; if ($categorycode) { my $dbh = C4::Context->dbh; - my $sth=$dbh->prepare("select categorycode,description,enrolmentperiod,upperagelimit,dateofbirthrequired,finetype,bulk,enrolmentfee,issuelimit,reservefee,overduenoticerequired from categories where categorycode='$categorycode'"); - $sth->execute; + my $sth=$dbh->prepare("select categorycode,description,enrolmentperiod,enrolmentperioddate,upperagelimit,dateofbirthrequired,enrolmentfee,issuelimit,reservefee,hidelostitems,overduenoticerequired,category_type from categories where categorycode=?"); + $sth->execute($categorycode); $data=$sth->fetchrow_hashref; $sth->finish; } - $template->param(description => $data->{'description'}, + $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'}, - finetype => $data->{'finetype'}, - bulk => $data->{'bulk'}, - enrolmentfee => $data->{'enrolmentfee'}, + enrolmentfee => sprintf("%.2f",$data->{'enrolmentfee'}), overduenoticerequired => $data->{'overduenoticerequired'}, issuelimit => $data->{'issuelimit'}, - reservefee => $data->{'reservefee'}); + reservefee => sprintf("%.2f",$data->{'reservefee'}), + hidelostitems => $data->{'hidelostitems'}, + category_type => $data->{'category_type'}, + DHTMLcalendar_dateformat => C4::Dates->DHTMLcalendar(), + "type_".$data->{'category_type'} => 1, + SMSSendDriver => C4::Context->preference("SMSSendDriver") + ); + 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 } elsif ($op eq 'add_validate') { $template->param(add_validate => 1); + my $is_a_modif = $input->param("is_a_modif"); my $dbh = C4::Context->dbh; - my $query = "replace categories (categorycode,description,enrolmentperiod,upperagelimit,dateofbirthrequired,finetype,bulk,enrolmentfee,issuelimit,reservefee,overduenoticerequired) values ("; - $query.= $dbh->quote($input->param('categorycode')).","; - $query.= $dbh->quote($input->param('description')).","; - $query.= $dbh->quote($input->param('enrolmentperiod')).","; - $query.= $dbh->quote($input->param('upperagelimit')).","; - $query.= $dbh->quote($input->param('dateofbirthrequired')).","; - $query.= $dbh->quote($input->param('finetype')).","; - $query.= $dbh->quote($input->param('bulk')).","; - $query.= $dbh->quote($input->param('enrolmentfee')).","; - $query.= $dbh->quote($input->param('issuelimit')).","; - $query.= $dbh->quote($input->param('reservefee')).","; - $query.= $dbh->quote($input->param('overduenoticerequired')).")"; - my $sth=$dbh->prepare($query); - $sth->execute; - $sth->finish; + 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=?, enrolmentperioddate=?,upperagelimit=?,dateofbirthrequired=?,enrolmentfee=?,reservefee=?,hidelostitems=?,overduenoticerequired=?,category_type=? WHERE categorycode=?"); + $sth->execute(map { $input->param($_) } ('description','enrolmentperiod','enrolmentperioddate','upperagelimit','dateofbirthrequired','enrolmentfee','reservefee','hidelostitems','overduenoticerequired','category_type','categorycode')); + $sth->finish; + } else { + my $sth=$dbh->prepare("INSERT INTO categories (categorycode,description,enrolmentperiod,enrolmentperioddate,upperagelimit,dateofbirthrequired,enrolmentfee,reservefee,hidelostitems,overduenoticerequired,category_type) values (?,?,?,?,?,?,?,?,?,?,?)"); + $sth->execute(map { $input->param($_) } ('categorycode','description','enrolmentperiod','enrolmentperioddate','upperagelimit','dateofbirthrequired','enrolmentfee','reservefee','hidelostitems','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; + # END $OP eq ADD_VALIDATE ################## DELETE_CONFIRM ################################## # called by default form, used to confirm deletion of data in DB @@ -139,32 +152,32 @@ if ($op eq 'add_form') { $template->param(delete_confirm => 1); my $dbh = C4::Context->dbh; - my $sth=$dbh->prepare("select count(*) as total from categoryitem where categorycode='$categorycode'"); - $sth->execute; + my $sth=$dbh->prepare("select count(*) as total from borrowers where categorycode=?"); + $sth->execute($categorycode); my $total = $sth->fetchrow_hashref; $sth->finish; $template->param(total => $total->{'total'}); - my $sth2=$dbh->prepare("select categorycode,description,enrolmentperiod,upperagelimit,dateofbirthrequired,finetype,bulk,enrolmentfee,issuelimit,reservefee,overduenoticerequired from categories where categorycode='$categorycode'"); - $sth2->execute; + my $sth2=$dbh->prepare("select categorycode,description,enrolmentperiod,enrolmentperioddate,upperagelimit,dateofbirthrequired,enrolmentfee,issuelimit,reservefee,hidelostitems,overduenoticerequired,category_type from categories where categorycode=?"); + $sth2->execute($categorycode); my $data=$sth2->fetchrow_hashref; $sth2->finish; if ($total->{'total'} >0) { $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'}, - finetype => $data->{'finetype'}, - bulk => $data->{'bulk'}, - enrolmentfee => $data->{'enrolmentfee'}, + enrolmentfee => sprintf("%.2f",$data->{'enrolmentfee'}), overduenoticerequired => $data->{'overduenoticerequired'}, issuelimit => $data->{'issuelimit'}, - reservefee => $data->{'reservefee'}); - - + reservefee => sprintf("%.2f",$data->{'reservefee'}), + hidelostitems => $data->{'hidelostitems'}, + category_type => $data->{'category_type'}, + ); # END $OP eq DELETE_CONFIRM ################## DELETE_CONFIRMED ################################## # called by delete_confirm, used to effectively confirm deletion of data in DB @@ -172,37 +185,74 @@ if ($op eq 'add_form') { $template->param(delete_confirmed => 1); my $dbh = C4::Context->dbh; my $categorycode=uc($input->param('categorycode')); - my $query = "delete from categories where categorycode='$categorycode'"; - my $sth=$dbh->prepare($query); - $sth->execute; + my $sth=$dbh->prepare("delete from categories where categorycode=?"); + $sth->execute($categorycode); $sth->finish; + print "Content-Type: text/html\n\n"; + exit; + # END $OP eq DELETE_CONFIRMED } else { # DEFAULT $template->param(else => 1); - my $env; my @loop; - my ($count,$results)=StringSearch($env,$searchfield,'web'); + my ($count,$results)=StringSearch($searchfield,'web'); 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'}, - finetype => $results->[$i]{'finetype'}, - bulk => $results->[$i]{'bulk'}, - enrolmentfee => $results->[$i]{'enrolmentfee'}, - overduenoticerequired => $results->[$i]{'overduenoticerequired'}, - issuelimit => $results->[$i]{'issuelimit'}, - reservefee => $results->[$i]{'reservefee'} ); + 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'}), + hidelostitems => $results->[$i]{'hidelostitems'}, + 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; } $template->param(loop => \@loop); - + # check that I (institution) and C (child) exists. otherwise => warning to the user + my $dbh = C4::Context->dbh; + my $sth=$dbh->prepare("select category_type from categories where category_type='C'"); + $sth->execute; + my ($categoryChild) = $sth->fetchrow; + $template->param(categoryChild => $categoryChild); + $sth=$dbh->prepare("select category_type from categories where category_type='I'"); + $sth->execute; + my ($categoryInstitution) = $sth->fetchrow; + $template->param(categoryInstitution => $categoryInstitution); + $sth->finish; } #---- END $OP eq DEFAULT - - - 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; +}