View | Details | Raw Unified | Return to bug 15380
Collapse All | Expand All

(-)a/admin/authtypes.pl (-80 / +86 lines)
Lines 1-8 Link Here
1
#!/usr/bin/perl
1
#!/usr/bin/perl
2
2
3
# written 20/02/2002 by paul.poulain@free.fr
3
# Copyright 2002 paul.poulain@biblibre.com
4
5
# Copyright 2000-2002 Katipo Communications
4
# Copyright 2000-2002 Katipo Communications
5
# Copyright 2015 Koha Development Team
6
#
6
#
7
# This file is part of Koha.
7
# This file is part of Koha.
8
#
8
#
Lines 25-115 use C4::Context; Link Here
25
use C4::Auth;
25
use C4::Auth;
26
use C4::Output;
26
use C4::Output;
27
27
28
sub StringSearch  {
28
use Koha::Authorities;
29
    my $string = shift || '';
29
use Koha::Authority::Types;
30
    my $dbh = C4::Context->dbh;
31
    return $dbh->selectall_arrayref(q|
32
        SELECT authtypecode, authtypetext, auth_tag_to_report, summary
33
        FROM auth_types
34
        WHERE (authtypecode like ?) ORDER BY authtypecode
35
    |, { Slice => {} }, $string . "%" );
36
}
37
30
38
my $input = new CGI;
31
my $input        = new CGI;
39
my $script_name  = "/cgi-bin/koha/admin/authtypes.pl";
40
my $searchfield  = $input->param('authtypecode');  # FIXME: Auth Type search not really implemented
41
my $authtypecode = $input->param('authtypecode');
32
my $authtypecode = $input->param('authtypecode');
42
my $op           = $input->param('op')     || '';
33
my $op           = $input->param('op') || 'list';
43
my ($template, $borrowernumber, $cookie)
34
my @messages;
44
    = get_template_and_user({template_name => "admin/authtypes.tt",
35
my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
45
                query => $input,
36
    {   template_name   => "admin/authtypes.tt",
46
                type => "intranet",
37
        query           => $input,
47
                authnotrequired => 0,
38
        type            => "intranet",
48
                flagsrequired => {parameters => 'parameters_remaining_permissions'},
39
        authnotrequired => 0,
49
                debug => 1,
40
        flagsrequired   => { parameters => 'parameters_remaining_permissions' },
50
                });
41
        debug           => 1,
51
42
    }
52
$template->param(
53
    script_name => $script_name,
54
    ($op || 'else') => 1,
55
);
43
);
56
44
57
my $dbh = C4::Context->dbh;
45
if ( $op eq 'add_form' ) {
46
    my $authority_type;
47
    if ($authtypecode) {
48
        $authority_type = Koha::Authority::Types->find($authtypecode);
49
    }
50
51
    $template->param( authority_type => $authority_type );
52
} elsif ( $op eq 'add_validate' ) {
53
    my $authtypecode       = $input->param('authtypecode');
54
    my $authtypetext       = $input->param('authtypetext');
55
    my $auth_tag_to_report = $input->param('auth_tag_to_report');
56
    my $summary            = $input->param('summary');
57
    my $is_a_modif         = $input->param('is_a_modif');
58
58
59
# called by default. Used to create form to add or  modify a record
59
    if ($is_a_modif) {
60
if ($op eq 'add_form') {
60
        my $authority_type = Koha::Authority::Types->find($authtypecode);
61
    #---- if primkey exists, it's a modify action, so read values to modify...
61
        $authority_type->authtypetext($authtypetext);
62
    if ( defined $authtypecode) {
62
        $authority_type->auth_tag_to_report($auth_tag_to_report);
63
        my $sth = $dbh->prepare("SELECT * FROM auth_types WHERE authtypecode=?");
63
        $authority_type->summary($summary);
64
        $sth->execute($authtypecode);
64
        eval { $authority_type->store; };
65
        my $data = $sth->fetchrow_hashref();
65
        if ($@) {
66
        $template->param(
66
            push @messages, { type => 'error', code => 'error_on_update' };
67
            authtypecode       => $authtypecode,
67
        } else {
68
            authtypetext       => $data->{'authtypetext'},
68
            push @messages, { type => 'message', code => 'success_on_update' };
69
            auth_tag_to_report => $data->{'auth_tag_to_report'},
69
        }
70
            summary            => $data->{'summary'},
70
    } else {
71
        my $authority_type = Koha::Authority::Type->new(
72
            {   authtypecode       => $authtypecode,
73
                authtypetext       => $authtypetext,
74
                auth_tag_to_report => $auth_tag_to_report,
75
                summary            => $summary,
76
            }
71
        );
77
        );
78
        eval { $authority_type->store; };
79
        if ($@) {
80
            push @messages, { type => 'error', code => 'error_on_insert' };
81
        } else {
82
            push @messages, { type => 'message', code => 'success_on_insert' };
83
        }
72
    }
84
    }
73
                                                    # END $OP eq ADD_FORM
85
    $op = 'list';
74
################## ADD_VALIDATE ##################################
86
75
# called by add_form, used to insert/modify data in DB
87
} elsif ( $op eq 'delete_confirm' ) {
76
} elsif ($op eq 'add_validate') {
88
    my $authority_type = Koha::Authority::Types->find($authtypecode);
77
    my $sth = $input->param('modif') ? 
89
    my $authorities_using_it = Koha::Authorities->search( { authtypecode => $authtypecode } )->count;
78
            $dbh->prepare("UPDATE auth_types SET authtypetext=? ,auth_tag_to_report=?, summary=? WHERE authtypecode=?") :
90
    $template->param(
79
            $dbh->prepare("INSERT INTO auth_types SET authtypetext=?, auth_tag_to_report=?, summary=?, authtypecode=?") ;
91
        authority_type       => $authority_type,
80
    $sth->execute($input->param('authtypetext'),$input->param('auth_tag_to_report'),$input->param('summary'),$input->param('authtypecode'));
92
        authorities_using_it => $authorities_using_it,
81
    print $input->redirect($script_name);    # FIXME: unnecessary redirect
93
    );
82
    exit;
94
} elsif ( $op eq 'delete_confirmed' ) {
83
                                                    # END $OP eq ADD_VALIDATE
95
    my $authorities_using_it = Koha::Authorities->search( { authtypecode => $authtypecode } )->count;
84
################## DELETE_CONFIRM ##################################
96
    if ( $authorities_using_it == 0 ) {
85
# called by default form, used to confirm deletion of data in DB
97
        my $authority_type = Koha::Authority::Types->find($authtypecode);
86
} elsif ($op eq 'delete_confirm') {
98
        my $deleted = eval { $authority_type->delete; };
87
    #start the page and read in includes
88
    my $sth=$dbh->prepare("SELECT count(*) AS total FROM auth_tag_structure WHERE authtypecode=?");
89
    $sth->execute($authtypecode);
90
    my $total = $sth->fetchrow_hashref->{total};
91
99
92
    my $sth2 = $dbh->prepare("SELECT * FROM auth_types WHERE authtypecode=?");
100
        if ( $@ or not $deleted ) {
93
    $sth2->execute($authtypecode);
101
            push @messages, { type => 'error', code => 'error_on_delete' };
94
    my $data = $sth2->fetchrow_hashref;
102
        } else {
103
            push @messages, { type => 'message', code => 'success_on_delete' };
104
        }
105
    } else {
106
        push @messages, { type => 'error', code => 'error_on_delete' };
107
    }
108
    $op = 'list';
109
}
110
111
if ( $op eq 'list' ) {
112
    my $authority_types = Koha::Authority::Types->search( {}, { order_by => ['authtypecode'] } );
113
    $template->param( authority_types => $authority_types, );
114
}
115
116
$template->param(
117
    messages => \@messages,
118
    op       => $op,
119
);
95
120
96
    $template->param(authtypecode => $authtypecode,
97
                     authtypetext => $data->{'authtypetext'},
98
                          summary => $data->{'summary'},
99
                            total => $total);
100
                                                    # END $OP eq DELETE_CONFIRM
101
################## DELETE_CONFIRMED ##################################
102
# called by delete_confirm, used to effectively confirm deletion of data in DB
103
} elsif ($op eq 'delete_confirmed') {
104
    #start the page and read in includes
105
    my $sth=$dbh->prepare("DELETE FROM auth_types WHERE authtypecode=?");
106
    $sth->execute(uc $input->param('authtypecode'));
107
    print $input->redirect($script_name);   # FIXME: unnecessary redirect
108
    exit;
109
                                                    # END $OP eq DELETE_CONFIRMED
110
################## DEFAULT ##################################
111
} else { # DEFAULT
112
    my $results = StringSearch($searchfield);
113
    $template->param( loop => $results );
114
} #---- END $OP eq DEFAULT
115
output_html_with_http_headers $input, $cookie, $template->output;
121
output_html_with_http_headers $input, $cookie, $template->output;
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/authtypes.tt (-95 / +127 lines)
Lines 1-8 Link Here
1
[% INCLUDE 'doc-head-open.inc' %]
1
[% INCLUDE 'doc-head-open.inc' %]
2
<title>Koha &rsaquo; Administration &rsaquo; Authority types
2
<title>Koha &rsaquo; Administration &rsaquo; Authority types
3
[% IF ( add_form ) %]
3
[% IF op == 'add_form' %]
4
&rsaquo; [% IF authtypecode.defined %]Modify authority type[% ELSE %]New authority type[% END %]
4
&rsaquo; [% IF authority_type.authtypecode %]Modify authority type[% ELSE %]New authority type[% END %]
5
[% ELSIF ( delete_confirm ) %]
5
[% ELSIF op == 'delete_confirm' %]
6
&rsaquo; Confirm deletion of authority type
6
&rsaquo; Confirm deletion of authority type
7
[% END %]
7
[% END %]
8
</title>
8
</title>
Lines 30-39 Link Here
30
<div id="breadcrumbs">
30
<div id="breadcrumbs">
31
         <a href="/cgi-bin/koha/mainpage.pl">Home</a>
31
         <a href="/cgi-bin/koha/mainpage.pl">Home</a>
32
&rsaquo; <a href="/cgi-bin/koha/admin/admin-home.pl">Administration</a>
32
&rsaquo; <a href="/cgi-bin/koha/admin/admin-home.pl">Administration</a>
33
&rsaquo; <a href="[% script_name %]">Authority types</a>
33
&rsaquo; <a href="/cgi-bin/koha/admin/authtypes.pl">Authority types</a>
34
[% IF ( add_form ) %]
34
[% IF op == 'add_form' %]
35
&rsaquo; [% IF authtypecode.defined %]Modify[% ELSE %]New[% END %] Authority type
35
&rsaquo; [% IF authority_type.authtypecode %]Modify[% ELSE %]New[% END %] Authority type
36
[% ELSIF ( delete_confirm ) %]
36
[% ELSIF op == 'delete_confirm' %]
37
&rsaquo; Confirm deletion of authority type
37
&rsaquo; Confirm deletion of authority type
38
[% END %]
38
[% END %]
39
</div>
39
</div>
Lines 43-143 Link Here
43
	<div id="yui-main">
43
	<div id="yui-main">
44
	  <div class="yui-b">
44
	  <div class="yui-b">
45
45
46
[% IF ( add_form ) %]
46
[% FOR m IN messages %]
47
47
    <div class="dialog [% m.type %]">
48
    <form action="[% script_name %]" name="Aform" method="post" class="validated">
48
        [% SWITCH m.code %]
49
    <fieldset class="rows">
49
        [% CASE 'error_on_update' %]
50
    <legend>
50
            An error occurred when updating this authority type. Perhaps it already exists.
51
    [% IF authtypecode.defined %]
51
        [% CASE 'error_on_insert' %]
52
        Modify authority type
52
            An error occurred when adding this authority type. The authority type code might already exist.
53
	[% ELSE %]
53
        [% CASE 'error_on_delete' %]
54
        New authority type
54
            An error occurred when deleting this authority type. Check the logs.
55
	[% END %]
55
        [% CASE 'success_on_update' %]
56
    </legend>
56
            Authority type updated successfully.
57
    <ol>
57
        [% CASE 'success_on_insert' %]
58
        <li>
58
            Authority type added successfully.
59
    [% IF authtypecode.defined %]
59
        [% CASE 'success_on_delete' %]
60
            <span class="label">Authority type</span>
60
            Authority type deleted successfully.
61
            <input type="hidden" name="op" value="add_validate" />
61
        [% CASE %]
62
            <input type="hidden" name="checked" value="0" />
62
            [% m.code %]
63
            <input type="hidden" name="authtypecode" value="[% authtypecode %]" />[% authtypecode %]
64
    [% ELSE %]
65
            <label for="authtypecode" class="required">Authority type: </label>
66
            <input id="authtypecode" type="text" class="required" required="required" name="authtypecode" size="10" maxlength="10" onblur="toUC(this)" />
67
            <span class="required">Required</span>
68
    [% END %]
69
        </li>
70
        <li>
71
            <label for="authtypetext" class="required">Description: </label><input type="text" id="authtypetext" name="authtypetext" size="40" maxlength="80" value="[% authtypetext |html %]" class="required" required="required" />
72
            <span class="required">Required</span>
73
        </li>
74
		<li><label for="summary">Summary: </label><textarea id="summary" name="summary" cols="55" rows="7">[% summary %]</textarea></li>
75
		<li>
76
		<p class="tip">Note: for 'Authority field to copy', enter the authority field that should be copied from the authority record to the bibliographic record. E.g., in MARC21, field 100 in the authority record should be copied to field 100 in the bibliographic record</p>
77
		<label for="auth_tag_to_report">Authority field to copy: </label><input type="text" id="auth_tag_to_report" name="auth_tag_to_report" size="5" maxlength="3" value="[% auth_tag_to_report %]" />
78
		<input type="hidden" name="op" value="add_validate" />
79
        [% IF authtypecode.defined %]
80
        <input type="hidden" name="modif" value="1" />
81
        [% END %]
63
        [% END %]
82
        </li>
64
    </div>
83
    </ol>
84
	</fieldset>
85
    <fieldset class="action">
86
        <input type="submit" value="Submit" />
87
        <a class="cancel" href="[% script_name %]">Cancel</a>
88
    </fieldset>
89
	</form>
90
[% END %]
65
[% END %]
91
66
92
[% IF ( delete_confirm ) %]
93
        <div class="dialog alert"><h3>Confirm deletion of authority structure definition for <span class="ex">'[% authtypetext %]' ([% authtypecode %])</span></h3>
94
	[% IF ( total ) %]
95
		<p>This record is used <strong>[% total %]</strong> times</p>
96
	[% END %]		
97
			<form action="[% script_name %]" method="post"><input type="hidden" name="op" value="delete_confirmed" />
98
			<input type="hidden" name="authtypecode" value="[% authtypecode %]" />
99
            <fieldset class="action"><input type="submit" class="approve" value="Yes, delete" />
100
		</form>
101
        <form action="[% script_name %]" method="get"><input type="submit" class="deny" value="No, do not delete" /></form>
102
		</div>
103
[% END %]
104
67
105
[% IF ( else ) %]
106
68
107
<div id="toolbar" class="btn-toolbar">
69
[% IF op == 'add_form' %]
108
    <a id="authtype" class="btn btn-small" href="[% script_name %]?op=add_form"><i class="fa fa-plus"></i> New authority type</a>
70
    <form action="/cgi-bin/koha/admin/authtypes.pl" name="Aform" method="post" class="validated">
109
</div>
71
        <fieldset class="rows">
72
            <legend>
73
                [% IF authority_type.authtypecode %]
74
                    Modify authority type
75
                [% ELSE %]
76
                    New authority type
77
                [% END %]
78
            </legend>
79
            <ol>
80
                <li>
81
                    [% IF authority_type.authtypecode %]
82
                            <span class="label">Authority type</span>
83
                            <input type="hidden" name="op" value="add_validate" />
84
                            <input type="hidden" name="checked" value="0" />
85
                            <input type="hidden" name="authtypecode" value="[% authority_type.authtypecode %]" />[% authority_type.authtypecode %]
86
                    [% ELSE %]
87
                            <label for="authtypecode" class="required">Authority type: </label>
88
                            <input id="authtypecode" type="text" class="required" required="required" name="authtypecode" size="10" maxlength="10" onblur="toUC(this)" />
89
                            <span class="required">Required</span>
90
                    [% END %]
91
                </li>
92
                <li>
93
                    <label for="authtypetext" class="required">Description: </label>
94
                    <input type="text" id="authtypetext" name="authtypetext" size="40" maxlength="80" value="[% authority_type.authtypetext |html %]" class="required" required="required" />
95
                    <span class="required">Required</span>
96
                </li>
97
                <li>
98
                    <label for="summary">Summary: </label>
99
                    <textarea id="summary" name="summary" cols="55" rows="7">[% authority_type.summary %]</textarea>
100
                </li>
101
                <li>
102
                    <p class="tip">Note: for 'Authority field to copy', enter the authority field that should be copied from the authority record to the bibliographic record. E.g., in MARC21, field 100 in the authority record should be copied to field 100 in the bibliographic record</p>
103
                    <label for="auth_tag_to_report">Authority field to copy: </label>
104
                    <input type="text" id="auth_tag_to_report" name="auth_tag_to_report" size="5" maxlength="3" value="[% authority_type.auth_tag_to_report %]" />
105
                    <input type="hidden" name="op" value="add_validate" />
106
                    [% IF authority_type.authtypecode %]
107
                        <input type="hidden" name="is_a_modif" value="1" />
108
                    [% END %]
109
                </li>
110
            </ol>
111
        </fieldset>
112
        <fieldset class="action">
113
            <input type="submit" value="Submit" />
114
            <a class="cancel" href="/cgi-bin/koha/admin/authtypes.pl">Cancel</a>
115
        </fieldset>
116
    </form>
117
[% END %]
110
118
111
<h1>Authority types</h1>
119
[% IF op == 'delete_confirm' %]
112
<p>Define authority types, then authority MARC structure in the same way you define itemtypes and biblio MARC tag structure. Authority values are managed through plugins</p>
120
    <div class="dialog alert">
113
<table id="authtypes">
121
        [% IF authorities_using_it %]
114
    <thead>
122
            <h3>This authority type cannot be deleted</h3>
115
	<tr>
123
            <p>This record is used <strong>[% authorities_using_it %]</strong> times</p>
116
		<th>Code</th>
124
            <a class="cancel" href="/cgi-bin/koha/admin/authtypes.pl">Back to the list</a>
117
		<th>Description</th>
125
        [% ELSE %]
118
		<th>Summary</th>
126
            <h3>Confirm deletion of authority structure definition for <span class="ex">'[% authority_type.authtypetext %]' ([% authority_type.authtypecode %])</span></h3>
119
		<th>Auth field copied</th>
127
            <form action="/cgi-bin/koha/admin/authtypes.pl" method="post">
120
		<th>&nbsp;</th>
128
                <input type="hidden" name="op" value="delete_confirmed" />
121
		<th>Edit</th>
129
                <input type="hidden" name="authtypecode" value="[% authority_type.authtypecode %]" />
122
		<th>Delete</th>
130
                <fieldset class="action"><input type="submit" class="approve" value="Yes, delete" /></fieldset>
123
	</tr>
131
            </form>
124
    </thead>
132
            <form action="/cgi-bin/koha/admin/authtypes.pl" method="get">
125
    <tbody>
133
                <input type="submit" class="deny" value="No, do not delete" />
126
	[% FOREACH loo IN loop %]
134
            </form>
127
		<tr>
135
        [% END %]
128
			<td>[% loo.authtypecode %]</td>
136
    </div>
129
			<td>[% loo.authtypetext %]</td>
137
[% END %]
130
			<td>[% loo.summary %]</td>
138
131
			<td>[% loo.auth_tag_to_report %]</td>
139
[% IF op == 'list' %]
132
			<td><a href="auth_tag_structure.pl?authtypecode=[% loo.authtypecode %]" class="button parameters" >MARC structure</a></td>
140
    <div id="toolbar" class="btn-toolbar">
133
			<td><a href="[% loo.script_name %]?op=add_form&amp;authtypecode=[% loo.authtypecode |html %]">Edit</a></td>
141
        <a id="authtype" class="btn btn-small" href="/cgi-bin/koha/admin/authtypes.pl?op=add_form"><i class="fa fa-plus"></i> New authority type</a>
134
			<td><a href="[% loo.script_name %]?op=delete_confirm&amp;authtypecode=[% loo.authtypecode |html %]">Delete</a></td>
142
    </div>
135
		</tr>
136
	[% END %]
137
    <tbody>
138
</table>
139
143
144
    <h1>Authority types</h1>
145
    <p>Define authority types, then authority MARC structure in the same way you define itemtypes and biblio MARC tag structure. Authority values are managed through plugins</p>
146
    <table id="authtypes">
147
        <thead>
148
        <tr>
149
            <th>Code</th>
150
            <th>Description</th>
151
            <th>Summary</th>
152
            <th>Auth field copied</th>
153
            <th>&nbsp;</th>
154
            <th>Edit</th>
155
            <th>Delete</th>
156
        </tr>
157
        </thead>
158
        <tbody>
159
        [% FOREACH authority_type IN authority_types %]
160
            <tr>
161
                <td>[% authority_type.authtypecode %]</td>
162
                <td>[% authority_type.authtypetext %]</td>
163
                <td>[% authority_type.summary %]</td>
164
                <td>[% authority_type.auth_tag_to_report %]</td>
165
                <td><a href="auth_tag_structure.pl?authtypecode=[% authority_type.authtypecode %]" class="button parameters" >MARC structure</a></td>
166
                <td><a href="/cgi-bin/koha/admin/authtypes.pl?op=add_form&amp;authtypecode=[% authority_type.authtypecode |html %]">Edit</a></td>
167
                <td><a href="/cgi-bin/koha/admin/authtypes.pl?op=delete_confirm&amp;authtypecode=[% authority_type.authtypecode |html %]">Delete</a></td>
168
            </tr>
169
        [% END %]
170
        <tbody>
171
    </table>
140
[% END %]
172
[% END %]
173
141
</div>
174
</div>
142
</div>
175
</div>
143
<div class="yui-b">
176
<div class="yui-b">
144
- 

Return to bug 15380