adding cities & roadtype (from SAN-OP)

This commit is contained in:
tipaul 2006-05-23 11:44:23 +00:00
parent 8d75bc7426
commit 90f484c145
4 changed files with 661 additions and 0 deletions

167
admin/cities.pl Executable file
View File

@ -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<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=cities.pl\"></html>";
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<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=cities.pl\"></html>";
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;

166
admin/roadtype.pl Executable file
View File

@ -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<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=roadtype.pl\"></html>";
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<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=roadtype.pl\"></html>";
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;

View File

@ -0,0 +1,176 @@
<!-- TMPL_INCLUDE NAME="doc-head-open.inc" -->Koha -- System administration: cities
<!-- TMPL_INCLUDE NAME="doc-head-close.inc" -->
<!-- TMPL_INCLUDE NAME="menus.inc" -->
<!-- TMPL_INCLUDE NAME="menu-admin.inc" -->
<!-- TMPL_IF NAME="add_form" -->
<!-- TMPL_IF NAME="cityid" -->
<h1>Modify a city</h1>
<!-- TMPL_ELSE -->
<h1>Add a city</h1>
<!-- /TMPL_IF -->
<form action="<!-- TMPL_VAR NAME="script_name" -->" name="Aform" method="post">
<input type="hidden" name="op" value="add_validate">
<input type="hidden" name="checked" value="0">
<input type="hidden" name="cityid" value="<!-- TMPL_VAR NAME="cityid" -->">
<!-- TMPL_IF NAME="cityid" -->
<p class="p_borrowers">
<label>City id</label>
<label><b><!-- TMPL_VAR NAME="cityid" --></b></label>
</p>
<!-- /TMPL_IF -->
<p>
<label>City name</label>
<input type="text" name="city_name" size="40" maxlength="80" value="<!-- TMPL_VAR NAME="city_name" escape=HTML -->">&nbsp;
</p>
<p>
<label>City zipcode</label>
<input type="text" name="city_zipcode" size="10" maxlength="10" value="<!-- TMPL_VAR NAME="city_zipcode" -->">
</p>
<p>
<div >
<input class="button" type="button" onclick="Check(this.form)" value="OK">
</div>
</p>
</form>
<!-- /TMPL_IF -->
<!-- TMPL_IF NAME="delete_confirm" -->
<table>
<tr>
<td>
<b>City id</b>
</td>
<td>
<!-- TMPL_VAR NAME="cityid" -->
</td>
</tr>
<form action="<!-- TMPL_VAR NAME="script_name" -->" method="post">
<input type="hidden" name="op" value="delete_confirmed">
<input type="hidden" name="cityid" value="<!-- TMPL_VAR NAME="cityid" -->">
<tr>
<td>city name</td>
<td><!-- TMPL_VAR NAME="city_name" --></td>
</tr>
<tr>
<td>City zipcode</td>
<td><!-- TMPL_VAR NAME="city_zipcode" --></td>
</tr>
</tr>
<!-- TMPL_IF NAME="totalgtzero" -->
<tr>
<td colspan="2" align="center" class="problem">This record is used <!-- TMPL_VAR NAME="total" --> times. Impossible to delete it</td>
</tr>
<tr>
<td colspan="2">
</form><form action="<!-- TMPL_VAR NAME="script_name" -->" method="post">
<input type="submit" value="OK">
</form>
</td>
</tr>
<!-- TMPL_ELSE -->
<tr>
<td colspan="2" align="center">confirm deletion</td>
</tr>
<tr>
<td><input type="submit" value="YES"></form></td>
<td><form action="<!-- TMPL_VAR NAME="script_name" -->" method="post">
<input type="submit" value="NO"></form></td>
</tr>
<!-- /TMPL_IF -->
</table>
<!-- /TMPL_IF -->
<!-- TMPL_IF NAME="else" -->
<h2>Cities management</h2>
<!-- TMPL_IF NAME="searchfield" -->
Searching: <!-- TMPL_VAR NAME="searchfield" -->
<!-- /TMPL_IF -->
<form action="<TMPL_VAR NAME="script_name">" method="post">
<input type="text" name="city_name" value="<!-- TMPL_VAR NAME="searchfield" -->">
<input type="submit" name="submit" value="OK" class="button">
</form>
<table>
<tr>
<th>City id</th>
<th>City name</th>
<th>City zipcode</th>
<th> </th>
<th> </th>
</tr>
<!-- TMPL_LOOP NAME="loop" -->
<!-- TMPL_IF NAME="toggle" -->
<tr class="hilighted">
<!-- TMPL_ELSE -->
<tr>
<!-- /TMPL_IF -->
<td><!-- TMPL_VAR NAME="cityid" --></td>
<td><!-- TMPL_VAR NAME="city_name" --></td>
<td><!-- TMPL_VAR NAME="city_zipcode" --></td>
<td><a href="<!-- TMPL_VAR NAME="script_name" -->?op=add_form&amp;cityid=<!-- TMPL_VAR NAME="cityid" -->">edit</a></td>
<td><a href="<!-- TMPL_VAR NAME="script_name" -->?op=delete_confirm&amp;cityid=<!-- TMPL_VAR NAME="cityid" -->">delete</a></td>
</tr>
<!-- /TMPL_LOOP -->
</table>
<p><form action="<!-- TMPL_VAR NAME="script_name" -->" method="post">
<input type="hidden" name="op" value="add_form">
<input type="submit" class="button" value="Add a city" alt="Add city"><br>
</form></p>
<!-- /TMPL_IF -->
<!-- TMPL_INCLUDE NAME="intranet-bottom.inc" -->
<script language="javascript" type="text/javascript">
function _(s) { return s } // dummy function for gettext
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function isNotNull(f,noalert) {
if (f.value.length == 0) {
return false;
}
return true;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function toUC(f) {
var x=f.value.toUpperCase();
f.value=x;
return true;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function isNum(v,maybenull) {
var n = new Number(v.value);
if (isNaN(n)) {
return false;
}
if (maybenull == 0 && v.value =='') {
return false;
}
return true;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function isDate(f) {
var t = Date.parse(f.value);
if (isNaN(t)) {
return false;
}
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function Check(f) {
var ok=1;
var _alertString="";
var alertString2;
if (f.city_zipcode.value.length == 0 && f.city_name.value.length == 0 ) {
_alertString += "\n- " + _("City name & zipcode missing");
alert(_alertString);
}
else{
document.Aform.submit();
}
}
</script>

View File

@ -0,0 +1,152 @@
<!-- TMPL_INCLUDE NAME="doc-head-open.inc" -->Koha -- system administration: road types
<!-- TMPL_INCLUDE NAME="doc-head-close.inc" -->
<!-- TMPL_INCLUDE NAME="menus.inc" -->
<!-- TMPL_INCLUDE NAME="menu-admin.inc" -->
<!-- TMPL_IF NAME="add_form" -->
<!-- TMPL_IF NAME="id_city" -->
<h1>Modifier un type de voie</h1>
<!-- TMPL_ELSE -->
<h1>Ajouter un type de voie</h1>
<!-- /TMPL_IF -->
<form action="<!-- TMPL_VAR NAME="script_name" -->" name="Aform" method="post">
<input type="hidden" name="op" value="add_validate">
<input type="hidden" name="checked" value="0">
<input type="hidden" name="roadtypeid" value="<!-- TMPL_VAR NAME="roadtypeid" -->">
<!-- TMPL_IF NAME="roadtypeid" -->
<p>
<label>Road type</label>
<label><b><!-- TMPL_VAR NAME="roadtypeid" --></b></label>
</p>
<!-- /TMPL_IF -->
<p>
<label>Road type</label>
<input type="text" name="road_type" size="40" maxlength="80" value="<!-- TMPL_VAR NAME="road_type" escape=HTML -->">
</p>
<p>
<div >
<input class="button" type="button" onclick="Check(this.form)" value="OK">
</div>
</p>
</form>
<!-- /TMPL_IF -->
<!-- TMPL_IF NAME="delete_confirm" -->
<table>
<tr>
<th>Road type id </th>
<th>
<!-- TMPL_VAR NAME="roadtypeid" -->
</td>
</tr>
<form action="<!-- TMPL_VAR NAME="script_name" -->" method="post">
<input type="hidden" name="op" value="delete_confirmed">
<input type="hidden" name="roadtypeid" value="<!-- TMPL_VAR NAME="roadtypeid" -->">
<tr>
<td>Rod type</td>
<td><!-- TMPL_VAR NAME="road_type" --></td>
</tr>
</tr>
<tr>
<td colspan="2" align="center">Confirm deletion</td>
</tr>
<tr>
<td><input type="submit" value="YES"></form></td>
<td><form action="<!-- TMPL_VAR NAME="script_name" -->" method="post">
<input type="submit" value="NO"></form></td>
</tr>
</table>
<!-- /TMPL_IF -->
<!-- TMPL_IF NAME="else" -->
<h2>Road type</h2>
<!-- TMPL_IF NAME="searchfield" -->
Search on <!-- TMPL_VAR NAME="searchfield" -->
<!-- /TMPL_IF -->
<form action="<TMPL_VAR NAME="script_name">" method="post">
<input type="text" name="road_type" value="<!-- TMPL_VAR NAME="searchfield" -->">
<input type="submit" name="submit" value="OK" class="button">
</form>
<table>
<tr>
<th>Road type</bh>
<th> </th>
<th> </th>
</tr>
<!-- TMPL_LOOP NAME="loop" -->
<!-- TMPL_IF NAME="toggle" -->
<tr class="hilighted">
<!-- TMPL_ELSE -->
<tr>
<!-- /TMPL_IF -->
<td><!-- TMPL_VAR NAME="road_type" --></td>
<td><a href="<!-- TMPL_VAR NAME="script_name" -->?op=add_form&amp;roadtypeid=<!-- TMPL_VAR NAME="roadtypeid" -->">edit</a></td>
<td><a href="<!-- TMPL_VAR NAME="script_name" -->?op=delete_confirm&amp;roadtypeid=<!-- TMPL_VAR NAME="roadtypeid" -->">delete</a></td>
</tr>
<!-- /TMPL_LOOP -->
</table>
<p><form action="<!-- TMPL_VAR NAME="script_name" -->" method="post">
<input type="hidden" name="op" value="add_form">
<input type="submit" class="button" value="Add road type" alt="Add road type"><br>
</form></p>
<!-- /TMPL_IF -->
<!-- TMPL_INCLUDE NAME="intranet-bottom.inc" -->
<script language="javascript" type="text/javascript">
function _(s) { return s } // dummy function for gettext
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function isNotNull(f,noalert) {
if (f.value.length == 0) {
return false;
}
return true;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function toUC(f) {
var x=f.value.toUpperCase();
f.value=x;
return true;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function isNum(v,maybenull) {
var n = new Number(v.value);
if (isNaN(n)) {
return false;
}
if (maybenull == 0 && v.value =='') {
return false;
}
return true;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function isDate(f) {
var t = Date.parse(f.value);
if (isNaN(t)) {
return false;
}
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function Check(f) {
var ok=1;
var _alertString="";
var alertString2;
if (f.road_type.value.length == 0 ) {
_alertString += "\n- " + _("Road type");
alert(_alertString);
}
else{
document.Aform.submit();
}
}
</script>