use C4::Context;
-sub StringSearch {
+sub AuthorizedValuesForCategory {
my ($searchstring,$type)=@_;
my $dbh = C4::Context->dbh;
$searchstring=~ s/\'/\\\'/g;
my @data=split(' ',$searchstring);
my $count=@data;
- my $sth=$dbh->prepare("Select id,category,authorised_value,lib from authorised_values where (category like ?) order by category,authorised_value");
- $sth->execute("$data[0]%");
+ my $sth=$dbh->prepare("Select id,category,authorised_value,lib from authorised_values where (category = ?) order by category,authorised_value");
+ $sth->execute("$data[0]");
my @results;
my $cnt=0;
while (my $data=$sth->fetchrow_hashref){
return ($cnt,\@results);
}
+sub _already_exists {
+ my ($category, $authorised_value) = @_;
+ my $dbh = C4::Context->dbh;
+ my $sth = $dbh->prepare_cached("SELECT COUNT(*) FROM authorised_values
+ WHERE category = ?
+ AND authorised_value = ?");
+ $sth->execute($category, $authorised_value);
+ my ($count) = $sth->fetchrow_array();
+ $sth->finish();
+ return $count;
+}
+
my $input = new CGI;
my $searchfield=$input->param('searchfield');
$searchfield=~ s/\,//g;
# called by add_form, used to insert/modify data in DB
} elsif ($op eq 'add_validate') {
my $dbh = C4::Context->dbh;
- my $sth=$dbh->prepare("replace authorised_values (id,category,authorised_value,lib) values (?,?,?,?)");
- my $lib = $input->param('lib');
- undef $lib if ($lib eq ""); # to insert NULL instead of a blank string
+
+ if (_already_exists($input->param('category'), $input->param('authorised_value'))) {
+ $template->param(duplicate_category => $input->param('category'),
+ duplicate_value => $input->param('authorised_value'),
+ else => 1);
+ default_form();
+ } else {
+ my $sth=$dbh->prepare("replace authorised_values (id,category,authorised_value,lib) values (?,?,?,?)");
+ my $lib = $input->param('lib');
+ undef $lib if ($lib eq ""); # to insert NULL instead of a blank string
- $sth->execute($input->param('id'), $input->param('category'), $input->param('authorised_value'), $lib);
- $sth->finish;
- print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=authorised_values.pl?searchfield=".$input->param('category')."\"></html>";
- exit;
+ $sth->execute($input->param('id'), $input->param('category'), $input->param('authorised_value'), $lib);
+ $sth->finish;
+ print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=authorised_values.pl?searchfield=".$input->param('category')."\"></html>";
+ exit;
+ }
################## DELETE_CONFIRM ##################################
# called by default form, used to confirm deletion of data in DB
} elsif ($op eq 'delete_confirm') {
# END $OP eq DELETE_CONFIRMED
################## DEFAULT ##################################
} else { # DEFAULT
+ default_form();
+} #---- END $OP eq DEFAULT
+output_html_with_http_headers $input, $cookie, $template->output;
+
+exit 0;
+
+sub default_form {
# build categories list
my $sth = $dbh->prepare("select distinct category from authorised_values");
$sth->execute;
if (!$searchfield) {
$searchfield=$category_list[0];
}
- my ($count,$results)=StringSearch($searchfield,'web');
+ my ($count,$results)=AuthorizedValuesForCategory($searchfield,'web');
my $toggle=1;
my @loop_data = ();
# builds value list
script_name => $script_name,
);
}
-} #---- END $OP eq DEFAULT
-output_html_with_http_headers $input, $cookie, $template->output;
+}
+
<p>This table is used in MARC definition. You can define as many categories as you want, and as many authorized values as you want in each category.</p>
<p>When you define the MARC subfield structure, you can link a subfield to a authorized-value category. When the user ask for adding of modifying a biblio,
the subfield is not entered through a free field, but though a list of authorized values</p>
+<!-- TMPL_IF name="duplicate_category" -->
+<div>
+<span class="problem">Could not add value "<!-- TMPL_VAR name="duplicate_value" -->" for category
+ "<!-- TMPL_VAR name="duplicate_category" -->" — value already present.
+</span>
+</div>
+<!-- /TMPL_IF -->
<form action="/cgi-bin/koha/admin/authorised_values.pl" method="post"><label for="searchfield">Show Category: </label><!-- TMPL_VAR name="tab_list" --> <input type="submit" value="Submit" /></form>
<table>
<tr>
<input type="submit" value="Next Page >>" /></form>
<!-- /TMPL_IF -->
+<div id="action">
+ <a href= "/cgi-bin/koha/admin/authorised_values.pl?op=add_form&category=<!-- TMPL_VAR NAME="category" -->">Add Authorized value for <!-- TMPL_VAR name="category" --></a>
+ <a href= "/cgi-bin/koha/admin/authorised_values.pl?op=add_form">Add New Category</a>
+</div>
+
<!-- /TMPL_IF -->
</div>