--- /dev/null
+#! /usr/bin/perl
+#
+# Copyright 2008 LibLime
+#
+# 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::Auth;
+use C4::Context;
+use C4::Output;
+use C4::Koha;
+use C4::Members::AttributeTypes;
+
+my $script_name = "/cgi-bin/koha/admin/patron-attr-types.pl";
+
+my $input = new CGI;
+my $op = $input->param('op');
+
+
+my ($template, $loggedinuser, $cookie)
+ = get_template_and_user({template_name => "admin/patron-attr-types.tmpl",
+ query => $input,
+ type => "intranet",
+ authnotrequired => 0,
+ flagsrequired => {parameters => 1},
+ debug => 1,
+ });
+
+$template->param(script_name => $script_name);
+
+my $code = $input->param("code");
+
+my $display_list = 0;
+if ($op eq "edit_attribute_type") {
+ edit_attribute_type_form($template, $code);
+} elsif ($op eq "edit_attribute_type_confirmed") {
+ $display_list = add_update_attribute_type('edit', $template, $code);
+} elsif ($op eq "add_attribute_type") {
+ add_attribute_type_form($template);
+} elsif ($op eq "add_attribute_type_confirmed") {
+ $display_list = add_update_attribute_type('add', $template, $code);
+} elsif ($op eq "delete_attribute_type") {
+ $display_list = delete_attribute_type_form($template, $code);
+} elsif ($op eq "delete_attribute_type_confirmed") {
+ delete_attribute_type($template, $code);
+ $display_list = 1;
+} else {
+ $display_list = 1;
+}
+
+if ($display_list) {
+ unless (C4::Context->preference('ExtendedPatronAttributes')) {
+ $template->param(WARNING_extended_attributes_off => 1);
+ }
+ patron_attribute_type_list($template);
+}
+
+output_html_with_http_headers $input, $cookie, $template->output;
+
+exit 0;
+
+sub add_attribute_type_form {
+ my $template = shift;
+
+ $template->param(
+ attribute_type_form => 1,
+ confirm_op => 'add_attribute_type_confirmed',
+ );
+ authorised_value_category_list($template);
+}
+
+sub error_add_attribute_type_form {
+ my $template = shift;
+
+ $template->param(description => $input->param('description'));
+
+ if ($input->param('repeatable')) {
+ $template->param(repeatable_checked => 'checked="checked"');
+ }
+ if ($input->param('unique_id')) {
+ $template->param(unique_id_checked => 'checked="checked"');
+ }
+ if ($input->param('password_allowed')) {
+ $template->param(password_allowed_checked => 'checked="checked"');
+ }
+ if ($input->param('opac_display')) {
+ $template->param(opac_display_checked => 'checked="checked"');
+ }
+ if ($input->param('staff_searchable')) {
+ $template->param(staff_searchable_checked => 'checked="checked"');
+ }
+
+ $template->param(
+ attribute_type_form => 1,
+ confirm_op => 'add_attribute_type_confirmed',
+ );
+ authorised_value_category_list($template, $input->param('authorised_value_category'));
+}
+
+sub add_update_attribute_type {
+ my $op = shift;
+ my $template = shift;
+ my $code = shift;
+
+ my $description = $input->param('description');
+
+ my $attr_type;
+ if ($op eq 'edit') {
+ $attr_type = C4::Members::AttributeTypes->fetch($code);
+ $attr_type->description($description);
+ } else {
+ my $existing = C4::Members::AttributeTypes->fetch($code);
+ if (defined($existing)) {
+ $template->param(duplicate_code_error => $code);
+ error_add_attribute_type_form($template);
+ return 0;
+ }
+ $attr_type = C4::Members::AttributeTypes->new($code, $description);
+ my $repeatable = $input->param('repeatable');
+ $attr_type->repeatable($repeatable);
+ my $unique_id = $input->param('unique_id');
+ $attr_type->unique_id($unique_id);
+ }
+
+ my $opac_display = $input->param('opac_display');
+ $attr_type->opac_display($opac_display);
+ my $staff_searchable = $input->param('staff_searchable');
+ $attr_type->staff_searchable($staff_searchable);
+ my $authorised_value_category = $input->param('authorised_value_category');
+ $attr_type->authorised_value_category($authorised_value_category);
+ my $password_allowed = $input->param('password_allowed');
+ $attr_type->password_allowed($password_allowed);
+
+ if ($op eq 'edit') {
+ $template->param(edited_attribute_type => $attr_type->code());
+ } else {
+ $template->param(added_attribute_type => $attr_type->code());
+ }
+ $attr_type->store();
+
+ return 1;
+}
+
+sub delete_attribute_type_form {
+ my $template = shift;
+ my $code = shift;
+
+ my $attr_type = C4::Members::AttributeTypes->fetch($code);
+ my $display_list = 0;
+ if (defined($attr_type)) {
+ $template->param(
+ delete_attribute_type_form => 1,
+ confirm_op => "delete_attribute_type_confirmed",
+ code => $code,
+ description => $attr_type->description(),
+ );
+ } else {
+ $template->param(ERROR_delete_not_found => $code);
+ $display_list = 1;
+ }
+ return $display_list;
+}
+
+sub delete_attribute_type {
+ my $template = shift;
+ my $code = shift;
+
+ my $attr_type = C4::Members::AttributeTypes->fetch($code);
+ if (defined($attr_type)) {
+ if ($attr_type->num_patrons() > 0) {
+ $template->param(ERROR_delete_in_use => $code);
+ $template->param(ERROR_num_patrons => $attr_type->num_patrons());
+ } else {
+ $attr_type->delete();
+ $template->param(deleted_attribute_type => $code);
+ }
+ } else {
+ $template->param(ERROR_delete_not_found => $code);
+ }
+}
+
+sub edit_attribute_type_form {
+ my $template = shift;
+ my $code = shift;
+
+ my $attr_type = C4::Members::AttributeTypes->fetch($code);
+
+ $template->param(code => $code);
+ $template->param(description => $attr_type->description());
+
+ if ($attr_type->repeatable()) {
+ $template->param(repeatable_checked => 'checked="checked"');
+ }
+ $template->param(repeatable_disabled => 'disabled="disabled"');
+ if ($attr_type->unique_id()) {
+ $template->param(unique_id_checked => 'checked="checked"');
+ }
+ $template->param(unique_id_disabled => 'disabled="disabled"');
+ if ($attr_type->password_allowed()) {
+ $template->param(password_allowed_checked => 'checked="checked"');
+ }
+ if ($attr_type->opac_display()) {
+ $template->param(opac_display_checked => 'checked="checked"');
+ }
+ if ($attr_type->staff_searchable()) {
+ $template->param(staff_searchable_checked => 'checked="checked"');
+ }
+
+ authorised_value_category_list($template, $attr_type->authorised_value_category());
+
+ $template->param(
+ attribute_type_form => 1,
+ edit_attribute_type => 1,
+ confirm_op => 'edit_attribute_type_confirmed',
+ );
+
+}
+
+sub patron_attribute_type_list {
+ my $template = shift;
+
+ my @attr_types = C4::Members::AttributeTypes::GetAttributeTypes();
+ $template->param(available_attribute_types => \@attr_types);
+ $template->param(display_list => 1);
+}
+
+sub authorised_value_category_list {
+ my $template = shift;
+ my $selected = @_ ? shift : '';
+
+ my $categories = GetAuthorisedValueCategories();
+ my @list = ();
+ foreach my $category (@$categories) {
+ my $entry = { category => $category };
+ $entry->{selected} = 1 if $category eq $selected;
+ push @list, $entry;
+ }
+ $template->param(authorised_value_categories => \@list);
+}
<li><a href="/cgi-bin/koha/admin/categorie.pl">Patron types and categories</a></li>
<li><a href="/cgi-bin/koha/admin/cities.pl">Cities and towns</a></li>
<li><a href="/cgi-bin/koha/admin/roadtype.pl">Road types</a></li>
+ <li><a href="/cgi-bin/koha/admin/patron-attr-types.pl">Patron attribute types</a></li>
<li><a href="/cgi-bin/koha/admin/issuingrules.pl">Circulation rules</a></li>
<li><a href="/cgi-bin/koha/admin/smart-rules.pl">Alternate circulation rules</a></li>
<li><a href="/cgi-bin/koha/admin/finesrules.pl">Fines rules</a></li>
<dt><a href="/cgi-bin/koha/admin/roadtype.pl" >Road types</a>
</dt>
<dd>Define road types (street, avenue, way, etc.). Road types display as authorized values when adding/editing patrons and can be used in geographic statistics.</dd>
+ <dt><a href="/cgi-bin/koha/admin/patron-attr-types.pl">Patron attribute types</a></dt>
+ <dd>Define extended attributes (identifiers and statistical categories) for patron records</dd>
<dt><a href="/cgi-bin/koha/admin/issuingrules.pl">Circulation rules</a></dt>
<dd>Define circulation rules in a matrix for libraries / patrons / itemtypes / circ codes (number of checkouts, duration, fee, etc.).</dd>
<dt><a href="/cgi-bin/koha/admin/finesrules.pl">Fines rules</a></dt>
--- /dev/null
+<!-- TMPL_INCLUDE NAME="doc-head-open.inc" -->
+<title>Koha › Administration › Patron Attribute Types
+<!-- TMPL_IF name="attribute_type_form" -->
+ <!-- TMPL_IF name="edit_attribute_type" -->
+ › Modify patron attribute type
+ <!-- TMPL_ELSE -->
+ › Add patron attribute type
+ <!-- /TMPL_IF -->
+<!-- /TMPL_IF -->
+<!-- TMPL_IF name="delete_attribute_type_form" -->
+ › Confirm deletion of patron attribute type "<!-- TMPL_VAR name="code" -->"
+<!-- /TMPL_IF -->
+</title>
+<!-- TMPL_INCLUDE NAME="doc-head-close.inc" -->
+
+<script type="text/javascript">
+//<![CDATA[
+
+function DoCancel(f) {
+ f.op.value='';
+ document.Aform.submit();
+}
+
+function CheckAttributeTypeForm(f) {
+ var ok=1;
+ var _alertString="";
+ var alertString2;
+ if (f.code.value.length==0) {
+ _alertString += "\n- " + _("Patron attribute type code missing");
+ }
+ if (f.description.value.length==0) {
+ _alertString += "\n- " + _("Description missing");
+ }
+ if (_alertString.length==0) {
+ document.Aform.submit();
+ } else {
+ alertString2 = _("Form not submitted because of the following problem(s)");
+ alertString2 += "\n------------------------------------------------------------------------------------\n";
+ alertString2 += _alertString;
+ alert(alertString2);
+ }
+}
+
+//]]>
+</script>
+</head>
+<body>
+<!-- TMPL_INCLUDE NAME="header.inc" -->
+<!-- TMPL_INCLUDE NAME="cat-search.inc" -->
+
+<div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> › <a href="/cgi-bin/koha/admin/admin-home.pl">Administration</a> › <!-- TMPL_IF name="display_list" -->Patron Attribute Types<!-- TMPL_ELSE --><a href="/cgi-bin/koha/admin/patron-attr-types.pl">Patron Attribute Types</a><!-- /TMPL_IF -->
+<!-- TMPL_IF name="attribute_type_form" -->
+ <!-- TMPL_IF name="edit_attribute_type" -->
+ › Modify patron attribute type
+ <!-- TMPL_ELSE -->
+ › Add patron attribute type
+ <!-- /TMPL_IF -->
+<!-- /TMPL_IF -->
+<!-- TMPL_IF name="delete_attribute_type_form" -->
+ › Confirm deletion of patron attribute type "<!-- TMPL_VAR name="code" -->"
+<!-- /TMPL_IF -->
+</div>
+
+<div id="doc3" class="yui-t2">
+
+ <div id="bd">
+ <div id="yui-main">
+ <div class="yui-b">
+
+<!-- TMPL_IF name="WARNING_extended_attributes_off" -->
+<div class="dialog message">Because the 'ExtendedPatronAttributes` system preference is currently OFF, extended patron attributes
+cannot be given to patron records. Go
+<a href="/cgi-bin/koha/admin/systempreferences.pl?op=add_form&searchfield=ExtendedPatronAttributes">here</a> if you wish to turn
+this feature on.</div>
+<!-- /TMPL_IF -->
+
+<!-- TMPL_IF name="attribute_type_form" -->
+ <!-- TMPL_IF name="edit_attribute_type" -->
+<h2>Modify patron attribute type</h2>
+ <!-- TMPL_ELSE -->
+<h2>Add patron attribute type</h2>
+ <!-- /TMPL_IF -->
+<!-- TMPL_IF name="duplicate_code_error" -->
+<div class="dialog message">Could not add patron attribute type "<!-- TMPL_VAR name="duplicate_code_error" -->"
+ — one with that code already exists.
+</div>
+<!-- /TMPL_IF -->
+<form action="<!-- TMPL_VAR name="script_name" -->" name="Aform" method="post">
+ <input type="hidden" name="op" value="<!-- TMPL_VAR name="confirm_op"-->" />
+ <fieldset class="rows">
+ <ol>
+ <li>
+ <!-- TMPL_IF name="edit_attribute_type" -->
+ <span class="label">Patron attribute type code: </span>
+ <input type="hidden" name="code" value="<!-- TMPL_VAR name="code" -->" />
+ <!-- TMPL_VAR name="code" -->
+ <!-- TMPL_ELSE -->
+ <label for="code">Patron attribute type code: </label>
+ <input type="text" id="code" name="code" size="10" maxlength="10" />
+ <!-- /TMPL_IF -->
+ </li>
+ <li><label for="description">Description: </label>
+ <input type="text" id="description" name="description" size="50" maxlength="250"
+ value="<!-- TMPL_VAR name="description" escape="HTML" -->" />
+ </li>
+ <li><label for="repeatable">Repeatable: </label>
+ <input type="checkbox" id="repeatable" name="repeatable" <!-- TMPL_VAR name="repeatable_checked" -->
+ <!-- TMPL_VAR name="repeatable_disabled" --> />
+ <span>Check to let a patron record have multiple values of this attribute.
+ This setting cannot be changed after an attribute is defined.</span>
+ </li>
+ <li><label for="unique_id">Unique identifier: </label>
+ <input type="checkbox" id="unique_id" name="unique_id" <!-- TMPL_VAR name="unique_id_checked" -->
+ <!-- TMPL_VAR name="unique_id_disabled" --> />
+ <span>If checked, attribute will be a unique identifier — if a value is given to a patron record, the same value
+ cannot be given to a different record. This setting cannot be changed after an attribute is defined.</span>
+ </li>
+ <li><label for="password_allowed">Allow password: </label>
+ <input type="checkbox" id="password_allowed" name="password_allowed" <!-- TMPL_VAR name="password_allowed_checked" --> />
+ <span>Check to make it possible to associate a password with this attribute.</span>
+ </li>
+ <li><label for="opac_display">Display in OPAC: </label>
+ <input type="checkbox" id="opac_display" name="opac_display" <!-- TMPL_VAR name="opac_display_checked" --> />
+ <span>Check to display this attribute on a patron's details page in the OPAC.</span>
+ </li>
+ <li><label for="staff_searchable">Searchable: </label>
+ <input type="checkbox" id="staff_searchable" name="staff_searchable" <!-- TMPL_VAR name="staff_searchable_checked" --> />
+ <span>Check to make this attribute staff_searchable in the staff patron search.</span>
+ </li>
+ <li><label for="authorised_value_category">Authorised value category: </label>
+ <select name="authorised_value_category" id="authorised_value_category">
+ <option value="" />
+ <!-- TMPL_LOOP name="authorised_value_categories" -->
+ <!-- TMPL_IF name="selected" -->
+ <option value="<!-- TMPL_VAR name="category" -->" selected="selected">
+ <!-- TMPL_VAR name="category" -->
+ </option>
+ <!-- TMPL_ELSE -->
+ <option value="<!-- TMPL_VAR name="category" -->">
+ <!-- TMPL_VAR name="category" -->
+ </option>
+ <!-- /TMPL_IF -->
+ <!-- /TMPL_LOOP -->
+ </select>
+ <span>Authorised value category; if one is selected, the patron record input page will only allow values
+ to be chosen from the authorised value list. However, an authorised value list is not
+ enforced during batch patron import.</span>
+ </li>
+ </ol>
+ </fieldset>
+ <fieldset class="action">
+ <!-- TMPL_IF name="edit_attribute_type" -->
+ <input type="button" value="Save"
+ onclick="CheckAttributeTypeForm(this.form)" />
+ <!-- TMPL_ELSE -->
+ <input type="button" value="Save"
+ onclick="CheckAttributeTypeForm(this.form)" />
+ <!-- /TMPL_IF-->
+ <a class="cancel" href="/cgi-bin/koha/admin/patron-attr-types.pl">Cancel</a>
+ </fieldset>
+</form>
+<!-- /TMPL_IF -->
+
+<!-- TMPL_IF name="delete_attribute_type_form" -->
+<div class="dialog alert"><h3>Confirm deletion of patron attribute type <span class="ex">'<!-- TMPL_VAR name="code" -->' (<!-- TMPL_VAR name="description" -->)</span>?</h3>
+<form action="<!-- TMPL_VAR name="script_name" -->" name="Aform" method="post">
+ <input type="hidden" name="op" value="<!-- TMPL_VAR name="confirm_op"-->" />
+ <input type="hidden" name="code" value="<!-- TMPL_VAR name="code" -->" />
+ <input type="submit" value="Delete patron attribute type" class="approve" /></form>
+ <form action="<!-- TMPL_VAR name="script_name" -->" method="get">
+ <input type="submit" value="No, Do Not Delete" class="deny" />
+</form></div>
+<!-- /TMPL_IF -->
+
+<!-- TMPL_IF name="display_list" -->
+
+<div id="toolbar">
+ <script type="text/javascript">
+ //<![CDATA[
+ // prepare DOM for YUI Toolbar
+ $(document).ready(function() {
+ yuiToolbar();
+ });
+ // YUI Toolbar Functions
+ function yuiToolbar() {
+ new YAHOO.widget.Button("newrule");
+ } //]]>
+ </script>
+ <ul class="toolbar">
+ <li><a id="newrule" href="<!-- TMPL_VAR name="script_name" -->?op=add_attribute_type">New Patron Attribute Type</a></li>
+</ul></div>
+
+<h2>Patron Attribute Types</h2>
+<!-- TMPL_IF name="added_attribute_type" -->
+<div class="dialog message">Added patron attribute type "<!-- TMPL_VAR name="added_attribute_type" -->"</div>
+<!-- /TMPL_IF -->
+<!-- TMPL_IF name="edited_attribute_type" -->
+<div class="dialog message">Modified patron attribute type "<!-- TMPL_VAR name="edited_attribute_type" -->"</div>
+<!-- /TMPL_IF -->
+<!-- TMPL_IF name="deleted_attribute_type" -->
+<div class="dialog message">Deleted patron attribute type "<!-- TMPL_VAR name="deleted_attribute_type" -->"</div>
+<!-- /TMPL_IF -->
+<!-- TMPL_IF name="ERROR_delete_in_use" -->
+<div class="dialog message">Could not delete patron attribute type "<!-- TMPL_VAR name="ERROR_delete_in_use" -->"
+ — it is in use by <!-- TMPL_VAR name="ERROR_num_patrons" --> patron records</div>
+<!-- /TMPL_IF -->
+<!-- TMPL_IF name="ERROR_delete_not_found" -->
+<div class="dialog message">Could not delete patron attribute type "<!-- TMPL_VAR name="ERROR_delete_not_found" -->"
+ — it was already absent from the database.</div>
+<!-- /TMPL_IF -->
+<!-- TMPL_IF NAME="available_attribute_types" --><table>
+ <tr>
+ <th>Code</th>
+ <th>Description</th>
+ <th>Actions</th>
+ </tr>
+ <!-- TMPL_LOOP name="available_attribute_types" -->
+ <tr>
+ <td><!-- TMPL_VAR name="code" --></td>
+ <td><!-- TMPL_VAR name="description" --></td>
+ <td>
+ <a href="<!-- TMPL_VAR name="script_name" -->?op=edit_attribute_type&code=<!-- TMPL_VAR name="code" escape="HTML" -->">Edit</a>
+ <a href="<!-- TMPL_VAR name="script_name" -->?op=delete_attribute_type&code=<!-- TMPL_VAR name="code" escape="HTML" -->">Delete</a>
+ </td>
+ </tr>
+ <!-- /TMPL_LOOP -->
+</table><!-- TMPL_ELSE --><p>There are no saved patron attribute types.</p><!-- /TMPL_IF -->
+
+<div class="paginationBar"><!-- TMPL_VAR NAME="pagination_bar" --></div>
+
+<!-- /TMPL_IF -->
+
+</div>
+</div>
+<div class="yui-b">
+<!-- TMPL_INCLUDE NAME="admin-menu.inc" -->
+</div>
+</div>
+<!-- TMPL_INCLUDE NAME="intranet-bottom.inc" -->