From 90f484c145413b67f28c097bd73b136e57acbbe5 Mon Sep 17 00:00:00 2001 From: tipaul Date: Tue, 23 May 2006 11:44:23 +0000 Subject: [PATCH] adding cities & roadtype (from SAN-OP) --- admin/cities.pl | 167 +++++++++++++++++ admin/roadtype.pl | 166 +++++++++++++++++ .../intranet-tmpl/prog/en/admin/cities.tmpl | 176 ++++++++++++++++++ .../intranet-tmpl/prog/en/admin/roadtype.tmpl | 152 +++++++++++++++ 4 files changed, 661 insertions(+) create mode 100755 admin/cities.pl create mode 100755 admin/roadtype.pl create mode 100644 koha-tmpl/intranet-tmpl/prog/en/admin/cities.tmpl create mode 100644 koha-tmpl/intranet-tmpl/prog/en/admin/roadtype.tmpl diff --git a/admin/cities.pl b/admin/cities.pl new file mode 100755 index 0000000000..5f092dfeed --- /dev/null +++ b/admin/cities.pl @@ -0,0 +1,167 @@ +#! /usr/bin/perl + +# Copyright 2006 SAN OUEST-PROVENCE et Paul POULAIN +# +# This file is part of Koha. +# +# Koha is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 2 of the License, or (at your option) any later +# version. +# +# Koha is distributed in the hope that it will be useful, but WITHOUT ANY +# 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 + +use strict; +use CGI; +use C4::Context; +use C4::Output; +use C4::Search; +use HTML::Template; +use C4::Auth; +use C4::Interface::CGI::Output; + +sub StringSearch { + my ($env,$searchstring,$type)=@_; + my $dbh = C4::Context->dbh; + $searchstring=~ s/\'/\\\'/g; + my @data=split(' ',$searchstring); + my $count=@data; + my $sth=$dbh->prepare("Select * from cities where (city_name like ?)"); + $sth->execute("$data[0]%"); + my @results; + while (my $data=$sth->fetchrow_hashref){ + push(@results,$data); + } + # $sth->execute; + $sth->finish; + return (scalar(@results),\@results); +} + +my $input = new CGI; +my $searchfield=$input->param('city_name'); +my $script_name="/cgi-bin/koha/admin/cities.pl"; +my $cityid=$input->param('cityid'); +my $op = $input->param('op'); + +my ($template, $loggedinuser, $cookie) + = get_template_and_user({template_name => "admin/cities.tmpl", + query => $input, + type => "intranet", + authnotrequired => 0, + flagsrequired => {parameters => 1, management => 1}, + debug => 1, + }); + + +$template->param( script_name => $script_name, + cityid => $cityid , + searchfield => $searchfield); + + +################## ADD_FORM ################################## +# called by default. Used to create form to add or modify a record +if ($op eq 'add_form') { + $template->param(add_form => 1); + + #---- if primkey exists, it's a modify action, so read values to modify... + my $data; + if ($cityid) { + my $dbh = C4::Context->dbh; + my $sth=$dbh->prepare("select cityid,city_name,city_zipcode from cities where cityid=?"); + $sth->execute($cityid); + $data=$sth->fetchrow_hashref; + $sth->finish; + } + + $template->param( + city_name => $data->{'city_name'}, + city_zipcode => $data->{'city_zipcode'}); +##############ICI##################### +# END $OP eq ADD_FORM +################## ADD_VALIDATE ################################## +# called by add_form, used to insert/modify data in DB +} elsif ($op eq 'add_validate') { + my $dbh = C4::Context->dbh; + my $sth; + + if ($input->param('cityid') ){ + $sth=$dbh->prepare("replace cities (cityid,city_name,city_zipcode) values (?,?,?) "); + $sth->execute(map { $input->param($_) } ('cityid','city_name','city_zipcode')); + + } + else{ + $sth=$dbh->prepare("replace cities (city_name,city_zipcode) values (?,?)"); + $sth->execute(map { $input->param($_) } ('city_name','city_zipcode')); + } + $sth->finish; + 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 +} elsif ($op eq 'delete_confirm') { + $template->param(delete_confirm => 1); + + my $dbh = C4::Context->dbh; + my $sth=$dbh->prepare("select count(*) as total from borrowers,cities where borrowers.select_city=cities.cityid and cityid=?"); + $sth->execute($cityid); + my $total = $sth->fetchrow_hashref; + $sth->finish; + $template->param(total => $total->{'total'}); + my $sth2=$dbh->prepare("select cityid,city_name,city_zipcode from cities where cityid=?"); + $sth2->execute($cityid); + my $data=$sth2->fetchrow_hashref; + $sth2->finish; + if ($total->{'total'} >0) { + $template->param(totalgtzero => 1); + } + + $template->param( + city_name => ( $data->{'city_name'}), + city_zipcode => $data->{'city_zipcode'}); + + + # END $OP eq DELETE_CONFIRM +################## DELETE_CONFIRMED ################################## +# called by delete_confirm, used to effectively confirm deletion of data in DB +} elsif ($op eq 'delete_confirmed') { + my $dbh = C4::Context->dbh; + my $categorycode=uc($input->param('cityid')); + my $sth=$dbh->prepare("delete from cities where cityid=?"); + $sth->execute($cityid); + $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 $toggle = 0; + for (my $i=0; $i < $count; $i++){ + my %row = (cityid => $results->[$i]{'cityid'}, + city_name => $results->[$i]{'city_name'}, + city_zipcode => $results->[$i]{'city_zipcode'}, + toggle => $toggle ); + push @loop, \%row; + if ( $toggle eq 0 ) + { + $toggle = 1; + } + else + { + $toggle = 0; + } + } + $template->param(loop => \@loop); + + +} #---- END $OP eq DEFAULT +output_html_with_http_headers $input, $cookie, $template->output; \ No newline at end of file diff --git a/admin/roadtype.pl b/admin/roadtype.pl new file mode 100755 index 0000000000..f0eff5781c --- /dev/null +++ b/admin/roadtype.pl @@ -0,0 +1,166 @@ +#! /usr/bin/perl + +# Copyright 2006 SAN OUEST-PROVENCE et Paul POULAIN +# +# This file is part of Koha. +# +# Koha is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 2 of the License, or (at your option) any later +# version. +# +# Koha is distributed in the hope that it will be useful, but WITHOUT ANY +# 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 + +use strict; +use CGI; +use C4::Context; +use C4::Output; +use C4::Search; +use HTML::Template; +use C4::Auth; +use C4::Interface::CGI::Output; + +sub StringSearch { + my ($env,$searchstring,$type)=@_; + my $dbh = C4::Context->dbh; + $searchstring=~ s/\'/\\\'/g; + my @data=split(' ',$searchstring); + my $count=@data; + my $sth=$dbh->prepare("Select * from roadtype where (road_type like ?)"); + $sth->execute("$data[0]%"); + my @results; + while (my $data=$sth->fetchrow_hashref){ + push(@results,$data); + } + # $sth->execute; + $sth->finish; + return (scalar(@results),\@results); +} + +my $input = new CGI; +my $searchfield=$input->param('road_type'); +my $script_name="/cgi-bin/koha/admin/roadtype.pl"; +my $roadtypeid=$input->param('roadtypeid'); +my $op = $input->param('op'); + +my ($template, $loggedinuser, $cookie) + = get_template_and_user({template_name => "admin/roadtype.tmpl", + query => $input, + type => "intranet", + authnotrequired => 0, + flagsrequired => {parameters => 1, management => 1}, + debug => 1, + }); + + +$template->param( script_name => $script_name, + roadtypeid => $roadtypeid , + searchfield => $searchfield); + + +################## ADD_FORM ################################## +# called by default. Used to create form to add or modify a record +if ($op eq 'add_form') { + $template->param(add_form => 1); + + #---- if primkey exists, it's a modify action, so read values to modify... + my $data; + if ($roadtypeid) { + my $dbh = C4::Context->dbh; + my $sth=$dbh->prepare("select roadtypeid,road_type from roadtype where roadtypeid=?"); + $sth->execute($roadtypeid); + $data=$sth->fetchrow_hashref; + $sth->finish; + } + + $template->param( + road_type => $data->{'road_type'}, + ); +##############ICI##################### +# END $OP eq ADD_FORM +################## ADD_VALIDATE ################################# +# called by add_form, used to insert/modify data in DB +} elsif ($op eq 'add_validate') { + my $dbh = C4::Context->dbh; + my $sth; + + if ($input->param('roadtypeid') ){ + $sth=$dbh->prepare("replace roadtype (roadtypeid,road_type) values (?,?) "); + $sth->execute(map { $input->param($_) } ('roadtypeid','road_type')); + + } + else{ + $sth=$dbh->prepare("replace roadtype (road_type) values (?)"); + $sth->execute(map { $input->param($_) } ('road_type')); + } + $sth->finish; + 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 +} elsif ($op eq 'delete_confirm') { + $template->param(delete_confirm => 1); + my $dbh = C4::Context->dbh; + my $sth=$dbh->prepare("select count(*) as total from borrowers,roadtype where borrowers.streettype=roadtype.road_type and roadtypeid=?"); + $sth->execute($roadtypeid); + my $total = $sth->fetchrow_hashref; + $sth->finish; + $template->param(total => $total->{'total'}); + my $sth2=$dbh->prepare("select roadtypeid,road_type from roadtype where roadtypeid=?"); + $sth2->execute($roadtypeid); + my $data=$sth2->fetchrow_hashref; + $sth2->finish; + if ($total->{'total'} >0) { + $template->param(totalgtzero => 1); + } + + $template->param( + city_name => ( $data->{'road_type'}), + ); + + + # END $OP eq DELETE_CONFIRM +################## DELETE_CONFIRMED ################################## +# called by delete_confirm, used to effectively confirm deletion of data in DB +} elsif ($op eq 'delete_confirmed') { + my $dbh = C4::Context->dbh; + my $categorycode=uc($input->param('roadtypeid')); + my $sth=$dbh->prepare("delete from roadtype where roadtypeid=?"); + $sth->execute($roadtypeid); + $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 $toggle = 0; + for (my $i=0; $i < $count; $i++){ + my %row = (roadtypeid => $results->[$i]{'roadtypeid'}, + road_type => $results->[$i]{'road_type'}, + toggle => $toggle ); + push @loop, \%row; + if ( $toggle eq 0 ) + { + $toggle = 1; + } + else + { + $toggle = 0; + } + } + $template->param(loop => \@loop); + + +} #---- END $OP eq DEFAULT +output_html_with_http_headers $input, $cookie, $template->output; \ No newline at end of file diff --git a/koha-tmpl/intranet-tmpl/prog/en/admin/cities.tmpl b/koha-tmpl/intranet-tmpl/prog/en/admin/cities.tmpl new file mode 100644 index 0000000000..a73e928ce1 --- /dev/null +++ b/koha-tmpl/intranet-tmpl/prog/en/admin/cities.tmpl @@ -0,0 +1,176 @@ +Koha -- System administration: cities + + + + + + +

Modify a city

+ +

Add a city

+ + +
" name="Aform" method="post"> + + + "> + + +

+ + + +

+ +

+ + ">  +

+

+ + "> +

+ +

+

+ +
+

+
+ + + + + + + + + " method="post"> + + "> + + + + + + + + + + + + + + + + + + + + + + + + + +
+ City id + + +
city name
City zipcode
This record is used times. Impossible to delete it
+
" method="post"> + +
+
confirm deletion
" method="post"> +
+ + + +

Cities management

+ + Searching: + +
" method="post"> + "> + +
+ + + + + + + + + + + + + + + + + + + + + + + + + +
City idCity nameCity zipcode
?op=add_form&cityid=">edit?op=delete_confirm&cityid=">delete
+

" method="post"> + +
+

+ + + + diff --git a/koha-tmpl/intranet-tmpl/prog/en/admin/roadtype.tmpl b/koha-tmpl/intranet-tmpl/prog/en/admin/roadtype.tmpl new file mode 100644 index 0000000000..29636fafe8 --- /dev/null +++ b/koha-tmpl/intranet-tmpl/prog/en/admin/roadtype.tmpl @@ -0,0 +1,152 @@ +Koha -- system administration: road types + + + + + + +

Modifier un type de voie

+ +

Ajouter un type de voie

+ + +
" name="Aform" method="post"> + + + "> + + + +

+ + + +

+ + +

+ + + "> + +

+ +

+

+ +
+

+
+ + + + + + + + " method="post"> + + "> + + + + + + + + + + + + +
Road type id + + +
Rod type
Confirm deletion
" method="post"> +
+ + + +

Road type

+ + Search on + +
" method="post"> + "> + +
+ + + + + + + + + + + + + + + + + + +
Road type +
?op=add_form&roadtypeid=">edit?op=delete_confirm&roadtypeid=">delete
+

" method="post"> + +
+

+ + + + + \ No newline at end of file -- 2.39.5