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

(-)a/C4/Koha.pm (-150 / +20 lines)
Lines 754-911 sub getallthemes { Link Here
754
754
755
sub getFacets {
755
sub getFacets {
756
    my $facets;
756
    my $facets;
757
    if ( C4::Context->preference("marcflavour") eq "UNIMARC" ) {
757
    
758
        $facets = [
758
    my $dbh = C4::Context->dbh;
759
            {
759
    
760
                idx   => 'su-to',
760
    my $query  = "SELECT idx, label, tags, position, vlength, expanded, category, authorised_value, sep "; 
761
                label => 'Topics',
761
       $query .= "FROM facets WHERE marcflavour = '".C4::Context->preference("marcflavour")."' "; 
762
                tags  => [ qw/ 600ab 601ab 602a 604at 605a 606ax 610a / ],
762
       $query .= "AND active = 1 ";
763
                sep   => ' - ',
763
    
764
            },
764
    if (C4::Context->preference("singleBranchMode")){
765
            {
765
       $query .= "AND singleBranchMode = 0";
766
                idx   => 'su-geo',
767
                label => 'Places',
768
                tags  => [ qw/ 607a / ],
769
                sep   => ' - ',
770
            },
771
            {
772
                idx   => 'su-ut',
773
                label => 'Titles',
774
                tags  => [ qw/ 500a 501a 503a / ],
775
                sep   => ', ',
776
            },
777
            {
778
                idx   => 'au',
779
                label => 'Authors',
780
                tags  => [ qw/ 700ab 701ab 702ab / ],
781
                sep   => C4::Context->preference("UNIMARCAuthorsFacetsSeparator"),
782
            },
783
            {
784
                idx   => 'se',
785
                label => 'Series',
786
                tags  => [ qw/ 225a / ],
787
                sep   => ', ',
788
            },
789
            {
790
                idx  => 'location',
791
                label => 'Location',
792
                tags        => [ qw/ 995e / ],
793
            }
794
            ];
795
796
            unless ( C4::Context->preference("singleBranchMode")
797
                || GetBranchesCount() == 1 )
798
            {
799
                my $DisplayLibraryFacets = C4::Context->preference('DisplayLibraryFacets');
800
                if (   $DisplayLibraryFacets eq 'both'
801
                    || $DisplayLibraryFacets eq 'holding' )
802
                {
803
                    push(
804
                        @$facets,
805
                        {
806
                            idx   => 'holdingbranch',
807
                            label => 'HoldingLibrary',
808
                            tags  => [qw / 995c /],
809
                        }
810
                    );
811
                }
812
813
                if (   $DisplayLibraryFacets eq 'both'
814
                    || $DisplayLibraryFacets eq 'home' )
815
                {
816
                push(
817
                    @$facets,
818
                    {
819
                        idx   => 'homebranch',
820
                        label => 'HomeLibrary',
821
                        tags  => [qw / 995b /],
822
                    }
823
                );
824
                }
825
            }
826
    }
766
    }
827
    else {
767
    
828
        $facets = [
768
    my $sth = $dbh->prepare($query);
829
            {
769
    
830
                idx   => 'su-to',
770
    $sth->execute();
831
                label => 'Topics',
771
    
832
                tags  => [ qw/ 650a / ],
772
    while (my $row = $sth->fetchrow_hashref) {
833
                sep   => '--',
773
        $row->{'tags'} = [ split (',', $row->{'tags'}) ];
834
            },
774
        push @$facets, $row;
835
            #        {
836
            #        idx   => 'su-na',
837
            #        label => 'People and Organizations',
838
            #        tags  => [ qw/ 600a 610a 611a / ],
839
            #        sep   => 'a',
840
            #        },
841
            {
842
                idx   => 'su-geo',
843
                label => 'Places',
844
                tags  => [ qw/ 651a / ],
845
                sep   => '--',
846
            },
847
            {
848
                idx   => 'su-ut',
849
                label => 'Titles',
850
                tags  => [ qw/ 630a / ],
851
                sep   => '--',
852
            },
853
            {
854
                idx   => 'au',
855
                label => 'Authors',
856
                tags  => [ qw/ 100a 110a 700a / ],
857
                sep   => ', ',
858
            },
859
            {
860
                idx   => 'se',
861
                label => 'Series',
862
                tags  => [ qw/ 440a 490a / ],
863
                sep   => ', ',
864
            },
865
            {
866
                idx   => 'itype',
867
                label => 'ItemTypes',
868
                tags  => [ qw/ 952y 942c / ],
869
                sep   => ', ',
870
            },
871
            {
872
                idx => 'location',
873
                label => 'Location',
874
                tags => [ qw / 952c / ],
875
            },
876
            ];
877
878
            unless ( C4::Context->preference("singleBranchMode")
879
                || GetBranchesCount() == 1 )
880
            {
881
                my $DisplayLibraryFacets = C4::Context->preference('DisplayLibraryFacets');
882
                if (   $DisplayLibraryFacets eq 'both'
883
                    || $DisplayLibraryFacets eq 'holding' )
884
                {
885
                    push(
886
                        @$facets,
887
                        {
888
                            idx   => 'holdingbranch',
889
                            label => 'HoldingLibrary',
890
                            tags  => [qw / 952b /],
891
                        }
892
                    );
893
                }
894
895
                if (   $DisplayLibraryFacets eq 'both'
896
                    || $DisplayLibraryFacets eq 'home' )
897
                {
898
                push(
899
                    @$facets,
900
                    {
901
                        idx   => 'homebranch',
902
                        label => 'HomeLibrary',
903
                        tags  => [qw / 952a /],
904
                    }
905
                );
906
                }
907
            }
908
    }
775
    }
776
   
777
    $sth->finish;
778
    
909
    return $facets;
779
    return $facets;
910
}
780
}
911
781
(-)a/admin/facets.pl (+211 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
3
# Copyright 2012 Xercode Media Software S.L.
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it under the
8
# terms of the GNU General Public License as published by the Free Software
9
# Foundation; either version 2 of the License, or (at your option) any later
10
# version.
11
#
12
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License along
17
# with Koha; if not, write to the Free Software Foundation, Inc.,
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20
use strict;
21
use warnings;
22
use CGI;
23
use C4::Context;
24
use C4::Output;
25
use C4::Auth;
26
use C4::Koha;
27
use C4::Languages qw(getTranslatedLanguages);
28
use Data::Dumper;
29
30
my $input = new CGI;
31
our $dbh   = C4::Context->dbh;
32
my $ERROR = $input->param('ERROR') || 0;
33
my $query;
34
my $script_name = "/cgi-bin/koha/admin/facets.pl";
35
36
my $op = $input->param('op') || "";
37
my $id = $input->param('idFacet');
38
39
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
40
    {   template_name   => "admin/facets.tt",
41
        query           => $input,
42
        type            => "intranet",
43
        authnotrequired => 0,
44
        flagsrequired   => { parameters => 1 },
45
        debug           => 1,
46
    }
47
);
48
49
sub getTabListAuthValues {
50
    my $selected = shift;
51
52
    my $sth = $dbh->prepare("SELECT DISTINCT category FROM authorised_values");
53
    $sth->execute;
54
    my @category_list;
55
    my %categories;     # a hash, to check that some hardcoded categories exist.
56
    push(@category_list,"");
57
    while ( my ($category) = $sth->fetchrow_array) {
58
        push(@category_list,$category);
59
    }
60
    
61
    #reorder the list
62
    @category_list = sort {$a cmp $b} @category_list;
63
    my $tab_list = CGI::scrolling_list(-name=>'authorised_value',
64
            -id=>'authorised_value',
65
            -values  => \@category_list,
66
            -default => $selected,
67
            -size    => 1,
68
            -multiple=> 0,
69
            );
70
            
71
    return $tab_list;
72
}
73
74
75
if ($op eq "add_form"){
76
    my $tabListAuthValues = getTabListAuthValues('');
77
    $template->param('tabListAuthValues', $tabListAuthValues);
78
    
79
}elsif ($op eq "save_facet"){
80
    
81
    $query = "INSERT INTO facets ";
82
    $query.= "(marcflavour, idx, label, authorised_value, tags, position, vlength, expanded, singleBranchMode, active, category, sep) ";
83
    $query.= "VALUES (?,?,?,?,?,?,?,?,?,?,?,?)";
84
    my $sth3 = $dbh->prepare($query);
85
86
    $sth3->execute(
87
        $input->param('marcflavour'), 
88
        $input->param('idx'), 
89
        $input->param('label'), 
90
        $input->param('authorised_value'), 
91
        $input->param('tags'), 
92
        $input->param('position'), 
93
        $input->param('vlength'), 
94
        ($input->param('expanded')?1:0), 
95
        ($input->param('singleBranchMode')?1:0), 
96
        ($input->param('active')?1:0),
97
        $input->param('category'),
98
        $input->param('sep')
99
    );
100
    $sth3->finish;
101
    print $input->redirect($script_name);
102
    
103
}elsif( $op eq "edit_form" ){
104
    
105
    $query = "SELECT * FROM facets WHERE idFacet = ?";
106
    my $sth3 = $dbh->prepare($query);
107
    $sth3->execute($id);
108
    my $data = $sth3->fetchrow_hashref;
109
    $template->param(
110
        idFacet => $data->{idFacet},
111
        marcflavour => $data->{marcflavour},
112
        idx => $data->{idx},
113
        label => $data->{label},
114
        authorised_value => $data->{authorised_value},
115
        tags => $data->{tags},
116
        position => $data->{position},
117
        vlength => $data->{vlength},
118
        expanded => $data->{expanded},
119
        singleBranchMode => $data->{singleBranchMode},
120
        active => $data->{active},
121
        category => $data->{category},
122
        sep => $data->{sep}
123
    );
124
    $sth3->finish;
125
126
    my $tabListAuthValues = getTabListAuthValues($data->{authorised_value});
127
    $template->param('tabListAuthValues', $tabListAuthValues);
128
    
129
}elsif( $op eq "update_facet" ){
130
    
131
    $query = "UPDATE facets SET ";
132
    $query.= "marcflavour = ?, idx = ?, label = ?, authorised_value = ?, tags = ?, ";
133
    $query.= "position = ?, vlength = ?, expanded = ?, singleBranchMode = ?, ";
134
    $query.= "active = ?, category = ?, sep = ? ";
135
    $query.= "WHERE idFacet = ?";
136
    my $sth3 = $dbh->prepare($query);
137
    $sth3->execute(
138
        $input->param('marcflavour'),
139
        $input->param('idx'),
140
        $input->param('label'),
141
        $input->param('authorised_value'),
142
        $input->param('tags'),
143
        $input->param('position'),
144
        $input->param('vlength'),
145
        ($input->param('expanded')?1:0),
146
        ($input->param('singleBranchMode')?1:0),
147
        ($input->param('active')?1:0),
148
        $input->param('category'),
149
        $input->param('sep'),
150
        $input->param('idFacet') );
151
    $sth3->finish;
152
    print $input->redirect($script_name);
153
154
}elsif( $op eq "delete_confirmed"){
155
    
156
    $query = "DELETE FROM facets WHERE idFacet = ?";
157
    my $sth3 = $dbh->prepare($query);
158
    $sth3->execute( $id );
159
    $sth3->finish;
160
161
    print $input->redirect($script_name);
162
163
}elsif( $op eq "delete_confirm"){
164
165
    $query = "SELECT * FROM facets WHERE idFacet = ?";
166
    my $sth3 = $dbh->prepare($query);
167
    $sth3->execute($id);
168
    my $data = $sth3->fetchrow_hashref;
169
    $template->param(
170
        idFacet => $data->{idFacet},
171
        marcflavour => $data->{marcflavour},
172
        label => $data->{label},
173
        tags => $data->{tags}
174
    );
175
    $sth3->finish;
176
177
}else{
178
    
179
    $query = "SELECT * FROM facets ";
180
    my $sth3 = $dbh->prepare($query);
181
    $sth3->execute();
182
    my @loop_data;
183
    while ( my $r = $sth3->fetchrow_hashref ) {
184
        push @loop_data, {
185
            idFacet => $r->{idFacet}, 
186
            marcflavour => $r->{marcflavour}, 
187
            idx => $r->{idx},
188
            label => $r->{label},
189
            authorised_value => $r->{authorised_value},
190
            tags => $r->{tags},
191
            expanded => $r->{expanded},
192
            singleBranchMode => $r->{singleBranchMode},
193
            active => $r->{active}
194
        };
195
    }
196
    $template->param( loop => \@loop_data );
197
    $template->param( op => $op ) if ($op ne "");
198
    $template->param( else => 1 );
199
    $sth3->finish;
200
201
}
202
203
$template->param( op => $op ) if ($op ne "");
204
$template->param( id => $id );
205
$template->param( script_name => $script_name );
206
207
my $use_zebra_facets = C4::Context->config('use_zebra_facets');
208
$template->param( use_zebra_facets => $use_zebra_facets );
209
210
output_html_with_http_headers $input, $cookie, $template->output;
211
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/admin-home.tt (+2 lines)
Lines 84-89 Link Here
84
                    <dd>Manage OAI Sets</dd>
84
                    <dd>Manage OAI Sets</dd>
85
                    <dt><a href="/cgi-bin/koha/admin/items_search_fields.pl">Items search fields</a></dt>
85
                    <dt><a href="/cgi-bin/koha/admin/items_search_fields.pl">Items search fields</a></dt>
86
                    <dd>Manage custom fields for items search</dd>
86
                    <dd>Manage custom fields for items search</dd>
87
                    <dt><a href="/cgi-bin/koha/admin/facets.pl">Facet indexes manager</a></dt>
88
                    <dd>Manage indexes to build facets</dd>
87
                </dl>
89
                </dl>
88
90
89
                <h3>Acquisition parameters</h3>
91
                <h3>Acquisition parameters</h3>
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/facets.tt (-1 / +212 lines)
Line 0 Link Here
0
- 
1
[% INCLUDE 'doc-head-open.inc' %]
2
<title>Koha &rsaquo; Administration &rsaquo; Facets
3
[% IF ( op == 'add_form' || op == 'edit_form' ) %]
4
&rsaquo; [% IF ( idFacet ) %]Modify facet[% ELSE %]New facet[% END %]
5
[% ELSIF ( delete_confirm ) %]
6
&rsaquo; Confirm deletion of facet
7
[% END %]
8
</title>
9
[% INCLUDE 'doc-head-close.inc' %]
10
<script type="text/javascript">
11
//<![CDATA[
12
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
13
function isNotNull(f,noalert) {
14
	if (f.value.length ==0) {
15
		return false;
16
	}
17
	return true;
18
}
19
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
20
function toUC(f) {
21
	var x=f.value.toUpperCase();
22
	f.value=x;
23
	return true;
24
}
25
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
26
function Check(f) {
27
	var _alertString="";
28
	var alertString2;
29
	if (f.authtypecode.value.length==0) {
30
		_alertString += "\n- " + _("Authority type : code missing");
31
	}
32
	if (!(isNotNull(window.document.Aform.authtypetext,1))) {
33
		_alertString += "\n- " + _("Description missing");
34
	}
35
	if (_alertString.length==0) {
36
		document.Aform.submit();
37
	} else {
38
		alertString2  = _("Form not submitted because of the following problem(s)");
39
		alertString2 += "\n------------------------------------------------------------------------------------\n";
40
		alertString2 += _alertString;
41
		alert(alertString2);
42
	}
43
}
44
45
//]]>
46
</script>
47
</head>
48
<body id="admin_facets" class="admin">
49
[% INCLUDE 'header.inc' %]
50
[% INCLUDE 'cat-search.inc' %]
51
52
<div id="breadcrumbs">
53
         <a href="/cgi-bin/koha/mainpage.pl">Home</a>
54
&rsaquo; <a href="/cgi-bin/koha/admin/admin-home.pl">Administration</a>
55
&rsaquo; <a href="[% script_name %]">Facets</a>
56
[% IF ( op == 'add_form' || op == 'edit_form' ) %]
57
&rsaquo; [% IF ( idFacet ) %]Modify[% ELSE %]New[% END %] facet
58
[% ELSIF ( delete_confirm ) %]
59
&rsaquo; Confirm deletion of facet
60
[% END %]
61
</div>
62
63
<div id="doc3" class="yui-t2">
64
  <div id="bd">
65
	<div id="yui-main">
66
	  <div class="yui-b">
67
68
[% IF ( op == 'add_form' || op == 'edit_form' ) %]
69
70
    <form action="[% script_name %]" name="Aform" method="post">
71
    <fieldset class="rows">
72
    <legend>
73
    [% IF ( idFacet ) %]
74
        Modify facet
75
	[% ELSE %]
76
        New facet
77
	[% END %]
78
    </legend>
79
    <ol>
80
		<li><label for="authtypetext">Marc flavour: </label>
81
            <select name="marcflavour" id="marcflavour">
82
            	<option value="MARC21" [% IF ( marcflavour == 'MARC21' ) %]selected="selected"[% END %]>MARC21</option>
83
				<option value="NORMARC" [% IF ( marcflavour == 'NORMARC' ) %]selected="selected"[% END %]>NORMARC</option>
84
				<option value="UNIMARC" [% IF ( marcflavour == 'UNIMARC' ) %]selected="selected"[% END %]>UNIMARC</option>
85
            </select>
86
        <li>
87
        <li><label for="idx">Index: </label>
88
            <input type="text" id="idx" name="idx" size="10" maxlength="10" value="[% idx |html %]" /></li>
89
        <li>
90
        <li><label for="label">Label: </label>
91
            <input type="text" id="label" name="label" size="40" maxlength="40" value="[% label |html %]" /></li>
92
        <li>
93
        <li><label for="authorised_value">Authorised value: </label>
94
            [% tabListAuthValues %]
95
        <li>
96
        <li><label for="tags">Tags: </label>
97
            <input type="text" id="tags" name="tags" size="40" maxlength="80" value="[% tags |html %]" /></li>
98
        <li>
99
        <li><label for="position">Position: </label>
100
            <input type="text" id="position" name="position" size="2" maxlength="2" value="[% position |html %]" /></li>
101
        <li>
102
        <li><label for="vlength">Length from position: </label>
103
            <input type="text" id="vlength" name="vlength" size="2" maxlength="2" value="[% vlength |html %]" /></li>
104
        <li>
105
        <li><label for="expanded">Expanded: </label>
106
            <input type="checkbox" name="expanded" id="expanded" value="1" [% IF ( expanded ) %]checked="checked"[% END %]/> 
107
        <li>
108
        <li><label for="singleBranchMode">Single branch mode: </label>
109
            <input type="checkbox" name="singleBranchMode" id="singleBranchMode" value="1" [% IF ( singleBranchMode ) %]checked="checked"[% END %]/> 
110
        <li>
111
        <li><label for="active">Active: </label>
112
            <input type="checkbox" name="active" id="active" value="1" [% IF ( active ) %]checked="checked"[% END %]/> 
113
        <li>
114
        <li><label for="category">Category: </label>
115
            <input type="text" id="category" name="category" size="40" maxlength="80" value="[% category |html %]" /></li>
116
        <li>
117
        <li><label for="category">Separator: </label>
118
            <input type="text" id="sep" name="sep" size="40" maxlength="80" value="[% sep |html %]" /></li>
119
        <li>
120
121
		
122
        [% IF ( idFacet ) %]
123
            <input type="hidden" name="op" value="update_facet" />
124
			<input type="hidden" name="idFacet" value="[% idFacet %]" />
125
		[% ELSE %]
126
            <input type="hidden" name="op" value="save_facet" />
127
        [% END %]
128
        </li>
129
    </ol>
130
	</fieldset>
131
	<fieldset class="action"><input type="submit" value="Submit" onclick="Check(this.form); return false;" />
132
        <a class="cancel" href="[% script_name %]">Cancel</a>
133
    </fieldset>
134
	</form>
135
[% END %]
136
137
[% IF ( op == 'delete_confirm' ) %]
138
        <div class="dialog alert">
139
        	<h3>Confirm deletion of facet with </h3>
140
			<h4>index <span class="ex">'[% label %]'</h4>
141
			<h4>tags <span class="ex">'[% tags %]'</h4>
142
			<h4>marc flavour <span class="ex">'[% marcflavour %]'</h4></span></h3>
143
	[% IF ( total ) %]
144
		<p>This record is used <strong>[% total %]</strong> times</p>
145
	[% END %]		
146
			<form action="[% script_name %]" method="post"><input type="hidden" name="op" value="delete_confirmed" />
147
			<input type="hidden" name="idFacet" value="[% idFacet %]" />
148
			<fieldset class="action"><input type="submit" class="approve" value="Yes, Delete" />
149
		</form>
150
		<form action="[% script_name %]" method="get"><input type="submit" class="deny" value="No, Do Not Delete" /></form>
151
		</div>
152
[% END %]
153
154
[% IF ( else ) %]
155
156
[% IF ( else ) %]<div id="toolbar" class="btn-toolbar">
157
    <a class="btn btn-small" id="facet" href="[% script_name %]?op=add_form"><i class="icon-plus"></i> New facet</a>
158
</div>[% END %]
159
160
<h1>Facets</h1>
161
<p>Definition of indexes to build facets</p>
162
[% IF (use_zebra_facets) %]
163
<div class="alert">
164
	<h3>USE ZEBRA FACETS ENABLED</h3>
165
	Controlfields only works if "use_zebra_facets" is disabled
166
</div>
167
[% END %]
168
<table>
169
	<tr>
170
		<th>Marc flavour</th>
171
		<th>Index</th>
172
		<th>Label</th>
173
		<th>Authorised value</th>
174
		<th>Tags</th>
175
		<th>Expanded</th>
176
		<th>Single branch mode</th>
177
		<th>Active</th>
178
		<th>Edit</th>
179
		<th>Delete</th>
180
	</tr>
181
	
182
	[% FOREACH loo IN loop %]
183
        [% IF ( loop.odd ) %]
184
		<tr>
185
        [% ELSE %]
186
        <tr class="highlight">
187
        [% END %]
188
			<td>[% loo.marcflavour %]</td>
189
			<td>[% loo.idx %]</td>
190
			<td>[% loo.label %]</td>
191
			<td>[% loo.authorised_value %]</td>
192
			<td>[% loo.tags %]</td>
193
			<td>[% IF ( loo.expanded ) %]<span style="color:green;">YES</span>[% ELSE %]<span style="color:red;">NO</span>[% END %]</td>
194
			<td>[% IF ( loo.singleBranchMode ) %]<span style="color:green;">YES</span>[% ELSE %]<span style="color:red;">NO</span>[% END %]</td>
195
			<td>[% IF ( loo.active ) %]<span style="color:green;">YES</span>[% ELSE %]<span style="color:red;">NO</span>[% END %]</td>
196
			<td><a href="[% loo.script_name %]?op=edit_form&amp;idFacet=[% loo.idFacet |html %]">Edit</a></td>
197
			<td><a href="[% loo.script_name %]?op=delete_confirm&amp;idFacet=[% loo.idFacet |html %]">Delete</a></td>
198
		</tr>
199
	[% END %]
200
</table>
201
202
	[% IF ( previous ) %]<p><a href="[% previous %]">&lt;&lt; Previous</a></p>[% END %]
203
	[% IF ( next ) %]<p><a href="[% next %]">Next &gt;&gt;</a></p>[% END %]
204
205
[% END %]
206
</div>
207
</div>
208
<div class="yui-b">
209
[% INCLUDE 'admin-menu.inc' %]
210
</div>
211
</div>
212
[% INCLUDE 'intranet-bottom.inc' %]

Return to bug 15544