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

(-)a/admin/add_user_search.pl (-1 / +1 lines)
Lines 43-49 my $selection_type = $input->param('selection_type') || 'add'; Link Here
43
43
44
my $referer = $input->referer();
44
my $referer = $input->referer();
45
45
46
# If this script is called by acqui/basket.pl
46
# If this script is called by admin/aqbudgets.pl
47
# the patrons to return should be superlibrarian or have the order_manage
47
# the patrons to return should be superlibrarian or have the order_manage
48
# acquisition flag.
48
# acquisition flag.
49
my $search_patrons_with_acq_perm_only =
49
my $search_patrons_with_acq_perm_only =
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/common/patron_search.tt (-9 / +18 lines)
Lines 114-131 function filter() { Link Here
114
114
115
    // modify parent window owner element
115
    // modify parent window owner element
116
    [% IF selection_type == 'add' %]
116
    [% IF selection_type == 'add' %]
117
        [%# Note that add_user could sent data instead of borrowername too %]
118
        function add_user(borrowernumber, borrowername) {
117
        function add_user(borrowernumber, borrowername) {
119
            var p = window.opener;
118
            var p = window.opener;
120
            $("#info").hide();
119
            // In one place (serials/routing.tt), the page is reload on every add
121
            $("#error").hide();
120
            // We have to wait for the page to be there
122
            if ( p.add_user(borrowernumber, borrowername) < 0 ) {
121
            function wait_for_opener () {
123
                $("#error").html(_("Borrower '%s' is already in the list.").format(borrowername));
122
                if ( ! $(opener.document).find('body').size() ) {
124
                $("#error").show();
123
                    setTimeout(wait_for_opener, 500);
125
            } else {
124
                } else {
126
                $("#info").html(_("Borrower '%s' added.").format(borrowername));
125
                    [%# Note that add_user could sent data instead of borrowername too %]
127
                $("#info").show();
126
                    $("#info").hide();
127
                    $("#error").hide();
128
                    if ( p.add_user(borrowernumber, borrowername) < 0 ) {
129
                        $("#error").html(_("Borrower '%s' is already in the list.").format(borrowername));
130
                        $("#error").show();
131
                    } else {
132
                        $("#info").html(_("Borrower '%s' added.").format(borrowername));
133
                        $("#info").show();
134
                    }
135
                }
128
            }
136
            }
137
            wait_for_opener();
129
        }
138
        }
130
    [% ELSIF selection_type == 'select' %]
139
    [% ELSIF selection_type == 'select' %]
131
        function select_user(borrowernumber, data) {
140
        function select_user(borrowernumber, data) {
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/member-search.tt (-83 lines)
Lines 1-83 Link Here
1
[% INCLUDE 'doc-head-open.inc' %]
2
<title>Koha &rsaquo; Member Search &rsaquo; [% bookselname %]</title>
3
[% INCLUDE 'doc-head-close.inc' %]
4
<script type="text/javascript">
5
<!--
6
7
function add_member(subscriptionid,borrowernumber){
8
     var myurl = "routing.pl?subscriptionid="+subscriptionid+"&borrowernumber="+borrowernumber+"&op=add";
9
     window.opener.location.href = myurl;
10
}
11
12
//-->
13
</script>
14
<style type="text/css">
15
   #custom-doc { width:36.46em;*width:35.53em;min-width:430px; margin:auto; text-align:left; padding: 1em; }
16
   </style>
17
</head>
18
<body id="ser_member-search" class="ser">
19
<div id="custom-doc" class="yui-t7">
20
   
21
<div id="bd">
22
<div id="yui-main">
23
<div id="search" class="yui-g">
24
	<form action="[% actionname %]" method="get">
25
            <input type="hidden" name="subscriptionid" id="subscriptionid" value="[% subscriptionid %]" />
26
		<fieldset class="rows">
27
			<legend> Filter :</legend>
28
			<ol>
29
			<li><label for="member">Name:</label> <input type="hidden" name="surname" value="[% surname %]" />
30
			<input type="text" name="member" id="member" value="[% member %]" /></li>
31
            <li><label for="branchcode"> Library:</label><select name="branchcode" id="branchcode">
32
			<option value="">Any</option>[% FOREACH branchloo IN branchloop %]
33
			[% IF ( branchloo.selected ) %]
34
			<option value="[% branchloo.value %]" selected="selected">[% branchloo.branchname %]</option>[% ELSE %]
35
			<option value="[% branchloo.value %]">[% branchloo.branchname %]</option>[% END %]
36
			[% END %]</select></li>
37
			<li><label for="categorycode">Category:</label><select name="categorycode" id="categorycode">
38
			<option value="">Any</option>[% FOREACH categoryloo IN categoryloop %]
39
			[% IF ( categoryloo.selected ) %]
40
			<option value="[% categoryloo.categorycode %]" selected="selected">[% categoryloo.description %]</option>[% ELSE %]
41
			<option value="[% categoryloo.categorycode %]">[% categoryloo.description %]</option>[% END %]
42
			[% END %]</select></li>
43
			</ol>
44
			<fieldset class="action"><input type="submit" value="Search" /></fieldset>
45
	      </fieldset>
46
	  </form>
47
</div> 
48
[% IF ( resultsloop ) %]
49
<div id="searchheader" style="margin-top:.7em;"> <h3>Results [% from %] to [% to %] of [% numresults %] found for [% IF ( member ) %]'<span class="ex">[% member %]</span>'[% END %][% IF ( surname ) %]'<span class="ex">[% surname %]</span>'[% END %]</h3></div>
50
<div class="searchresults">
51
52
<table id="memberresultst">
53
	<thead>
54
		<tr>
55
		<th>Card</th>
56
		<th>Name</th>
57
		<th>Library</th>
58
		<th>Add</th>
59
		</tr>
60
	</thead>
61
	<tbody>
62
		[% FOREACH resultsloo IN resultsloop %]
63
		[% IF ( loop.odd ) %]<tr class="highlight">[% ELSE %]<tr>[% END %]
64
		<td>[% resultsloo.cardnumber %] </td>
65
		<td>[% resultsloo.surname %], [% resultsloo.firstname %] </td>
66
		<td>[% resultsloo.branchcode %] </td>
67
		<td><a onclick="add_member([% subscriptionid %],[% resultsloo.borrowernumber %]); return false" href="/cgi-bin/koha/serials/routing.pl?subscriptionid=[% resultsloo.subscriptionid %]&amp;borrowernumber=[% resultsloo.borrowernumber %]&amp;op=add">Add</a></td></tr>
68
		[% END %]
69
	</tbody>
70
</table>
71
[% IF ( multipage ) %]<div class="pages">[% paginationbar %]</div>[% END %]
72
</div>
73
[% ELSE %]
74
[% IF ( searching ) %]
75
<p>No results found</p>
76
[% END %]
77
[% END %]
78
<fieldset class="action"><a href="#" class="button close">Close</a></fieldset>
79
</div>
80
81
</div> 
82
83
[% INCLUDE 'intranet-bottom.inc' %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/routing.tt (-32 / +46 lines)
Lines 9-17 function reorder_item(sid,rid,rank){ Link Here
9
    window.location.href=mylocation; 
9
    window.location.href=mylocation; 
10
}
10
}
11
11
12
function search_member(subscriptionid){
12
    function userPopup() {
13
    var myurl = 'member-search.pl?subscriptionid='+subscriptionid; window.open(myurl,'FindAMember','width=550,height=480,toolbar=no,scrollbars=yes');
13
        window.open("/cgi-bin/koha/serials/add_user_search.pl",
14
}
14
            'PatronPopup',
15
            'width=740,height=450,location=yes,toolbar=no,'
16
            + 'scrollbars=yes,resize=yes'
17
        );
18
    }
19
20
    function add_user(borrowernumber) {
21
        var myurl = "routing.pl?subscriptionid="+[% subscriptionid %]+"&borrowernumber="+borrowernumber+"&op=add";
22
        window.location.href = myurl;
23
    }
15
24
16
//-->
25
//-->
17
</script>
26
</script>
Lines 47-83 function search_member(subscriptionid){ Link Here
47
[% END %]
56
[% END %]
48
</select> [% issue %]</li>
57
</select> [% issue %]</li>
49
58
50
[% IF memberloop %]
59
<li>
51
<li><span class="label">Recipients:</span><table style="clear:none;margin:0;">
60
    <span class="label">Recipients:</span>
52
        <tr><th>Name</th>
61
    [% IF memberloop %]
53
            <th>Rank</th>
62
        <table style="clear:none;margin:0;">
54
            <th>Delete</th>
63
            <tr><th>Name</th>
55
        </tr>
64
                <th>Rank</th>
56
        [% USE m_loop = iterator(memberloop) %]
65
                <th>Delete</th>
57
        [% FOREACH member IN m_loop %]
66
            </tr>
58
        <tr><td>[% member.name %]</td>
67
            [% USE m_loop = iterator(memberloop) %]
59
            <td>
68
            [% FOREACH member IN m_loop %]
60
                <select name="itemrank" onchange="reorder_item([%- subscriptionid -%], [%- member.routingid -%], this.value)">
69
            <tr><td>[% member.name %]</td>
61
                [% rankings = [1 .. m_loop.size] %]
70
                <td>
62
                [% FOREACH r IN rankings %]
71
                    <select name="itemrank" onchange="reorder_item([%- subscriptionid -%], [%- member.routingid -%], this.value)">
63
                    [% IF r == member.ranking %]
72
                    [% rankings = [1 .. m_loop.size] %]
64
                      <option selected="selected" value="[% r %]">[% r %]</option>
73
                    [% FOREACH r IN rankings %]
65
                    [% ELSE %]
74
                        [% IF r == member.ranking %]
66
                      <option value="[% r %]">[% r %]</option>
75
                          <option selected="selected" value="[% r %]">[% r %]</option>
76
                        [% ELSE %]
77
                          <option value="[% r %]">[% r %]</option>
78
                        [% END %]
67
                    [% END %]
79
                    [% END %]
68
                [% END %]
80
                    </select>
69
                </select>
81
                </td>
70
            </td>
82
                <td><a href="/cgi-bin/koha/serials/routing.pl?routingid=[% member.routingid %]&amp;subscriptionid=[% subscriptionid %]&amp;op=delete">Delete</a></td>
71
            <td><a href="/cgi-bin/koha/serials/routing.pl?routingid=[% member.routingid %]&amp;subscriptionid=[% subscriptionid %]&amp;op=delete">Delete</a></td>
83
            </tr>
72
        </tr>
84
            [% END %]
85
        </table>
86
    [% END %]
87
88
    <p style="margin-left:10em;">
89
        <input type="button" onclick="userPopup()" value="Add recipients" />
90
        [% IF memberloop %]
91
            <a href="/cgi-bin/koha/serials/routing.pl?subscriptionid=[% subscriptionid %]&amp;op=delete" class="button">Delete all</a>
73
        [% END %]
92
        [% END %]
74
        </table><p style="margin-left:10em;"><a onclick="search_member([% subscriptionid %]); return false"
93
    </p>
75
href="/cgi-bin/koha/serials/member-search.pl?subscriptionid=[% subscriptionid %]" class="button">Add recipients</a> &nbsp; <a
94
</li>
76
href="/cgi-bin/koha/serials/routing.pl?subscriptionid=[% subscriptionid %]&amp;op=delete" class="button">Delete all</a></p></li>
77
[% ELSE %]
78
<li><span class="label">Recipients:</span>
79
    <a onclick="search_member([% subscriptionid %]); return false" href="/cgi-bin/koha/serials/member-search.pl?subscriptionid=[% subscriptionid %]" class="button">Add recipients</a></li>
80
[% END %]
81
95
82
	<li><label for="notes">Notes:</label><textarea name="notes" id="notes" rows="3" cols="50">[% routingnotes %]</textarea></li>
96
	<li><label for="notes">Notes:</label><textarea name="notes" id="notes" rows="3" cols="50">[% routingnotes %]</textarea></li>
83
	</ol>
97
	</ol>
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/tables/members_results.tt (+20 lines)
Line 0 Link Here
1
[% USE To %]
2
{
3
    "sEcho": [% sEcho %],
4
    "iTotalRecords": [% iTotalRecords %],
5
    "iTotalDisplayRecords": [% iTotalDisplayRecords %],
6
    "aaData": [
7
        [% FOREACH data IN aaData %]
8
            {
9
                "dt_cardnumber":
10
                    "[% data.cardnumber %]",
11
                "dt_name":
12
                    "<span style='white-space:nowrap'><a href='/cgi-bin/koha/members/moremember.pl?borrowernumber=[% data.borrowernumber %]'>[% INCLUDE 'patron-title.inc' borrowernumber = data.borrowernumber category_type = data.category_type firstname = data.firstname surname = data.surname othernames = data.othernames cardnumber = data.cardnumber invert_name = 1%]</a></span>",
13
                "dt_branch":
14
                    "[% data.branchname |html %]",
15
                "dt_action":
16
                    "<a style='cursor:pointer' onclick='add_user(\"[% data.borrowernumber %]\", \"[% data.firstname %] [% data.surname %]\"); return false;'>Add</a>"
17
            }[% UNLESS loop.last %],[% END %]
18
        [% END %]
19
    ]
20
}
(-)a/serials/add_user_search.pl (+51 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
3
# This file is part of Koha.
4
#
5
# Copyright 2014 BibLibre
6
#
7
# Koha is free software; you can redistribute it and/or modify it
8
# under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; either version 3 of the License, or
10
# (at your option) any later version.
11
#
12
# Koha is distributed in the hope that it will be useful, but
13
# WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
16
#
17
# You should have received a copy of the GNU General Public License
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
20
use Modern::Perl;
21
22
use CGI qw ( -utf8 );
23
use C4::Auth;
24
use C4::Output;
25
use C4::Members;
26
27
my $input = new CGI;
28
29
my $dbh = C4::Context->dbh;
30
31
my ( $template, $loggedinuser, $cookie, $staff_flags ) = get_template_and_user(
32
    {   template_name   => "common/patron_search.tt",
33
        query           => $input,
34
        type            => "intranet",
35
        authnotrequired => 0,
36
        flagsrequired => { serials => 'routing' },
37
    }
38
);
39
40
my $q = $input->param('q') || '';
41
my $op = $input->param('op') || '';
42
43
my $referer = $input->referer();
44
45
$template->param(
46
    view => ( $input->request_method() eq "GET" ) ? "show_form" : "show_results",
47
    columns => ['cardnumber', 'name', 'branch', 'action'],
48
    json_template => 'serials/tables/members_results.tt',
49
    selection_type => 'add',
50
);
51
output_html_with_http_headers( $input, $cookie, $template->output );
(-)a/serials/member-search.pl (-179 lines)
Lines 1-178 Link Here
1
#!/usr/bin/perl
2
3
# Parts copyright Catalyst IT 2010
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
=head1 member-search.pl
21
22
Member Search.pl script used to search for members to add to a routing list
23
24
=cut
25
26
use strict;
27
use warnings;
28
use CGI qw ( -utf8 );
29
use C4::Auth;       # get_template_and_user
30
use C4::Output;
31
use C4::Members;    # BornameSearch
32
use C4::Branch;
33
use C4::Category;
34
use File::Basename;
35
36
my $cgi          = new CGI;
37
my $theme = $cgi->param('theme') || "default";
38
my $resultsperpage = $cgi->param('resultsperpage')||C4::Context->preference("PatronsPerPage")||20;
39
my $startfrom = $cgi->param('startfrom')||1;
40
41
my $patron = $cgi->Vars;
42
foreach (keys %$patron){
43
    delete $$patron{$_} unless($$patron{$_});
44
}
45
46
my @categories=C4::Category->all;
47
my $branches=(defined $$patron{branchcode}?GetBranchesLoop($$patron{branchcode}):GetBranchesLoop());
48
my $subscriptionid = $cgi->param('subscriptionid');
49
my $searchstring   = $cgi->param('member');
50
51
my %categories_dislay;
52
my ($template, $loggedinuser, $cookie);
53
    ($template, $loggedinuser, $cookie)
54
    = get_template_and_user({template_name => "serials/member-search.tt",
55
                 query => $cgi,
56
                 type => "intranet",
57
                 authnotrequired => 0,
58
                 flagsrequired => { serials => 'routing' },
59
                 });
60
61
foreach my $category (@categories){
62
	my $hash={
63
			category_description=>$$category{description},
64
			category_type=>$$category{category_type}
65
			 };
66
	$categories_dislay{$$category{categorycode}} = $hash;
67
}
68
$template->param(
69
        "AddPatronLists_".C4::Context->preference("AddPatronLists")=> "1",
70
            );
71
if (C4::Context->preference("AddPatronLists")=~/code/){
72
    $categories[0]->{'first'}=1;
73
}
74
75
my $member=$cgi->param('member');
76
my $orderby=$cgi->param('orderby');
77
$orderby = "surname,firstname" unless $orderby;
78
if (defined $member) {
79
    $member =~ s/,//g;   #remove any commas from search string
80
    $member =~ s/\*/%/g;
81
}
82
83
my ($count,$results);
84
85
if ( C4::Context->preference("IndependentBranches") ) {
86
    if (   C4::Context->userenv
87
        && !C4::Context->IsSuperLibrarian()
88
        && C4::Context->userenv->{'branch'} )
89
    {
90
        $$patron{branchcode} = C4::Context->userenv->{'branch'};
91
    }
92
}
93
$$patron{firstname}.="\%" if ($$patron{firstname});
94
$$patron{surname}.="\%" if ($$patron{surname});
95
96
my @searchpatron;
97
push @searchpatron, $member if ($member);
98
push @searchpatron, $patron if ( keys %$patron );
99
my $from = ( $startfrom - 1 ) * $resultsperpage;
100
my $to   = $from + $resultsperpage;
101
if (@searchpatron) {
102
    ($results) = Search(
103
        \@searchpatron,
104
        [ { surname => 0 }, { firstname => 0 } ],
105
        undef,
106
        undef,
107
        [ "firstname", "surname", "email", "othernames", "cardnumber" ],
108
        "start_with"
109
    );
110
}
111
if ($results) {
112
    $count = scalar(@$results);
113
}
114
my @resultsdata;
115
$to=($count>$to?$to:$count);
116
my $index=$from;
117
foreach my $borrower(@$results[$from..$to-1]){
118
    # find out stats
119
    $borrower->{'dateexpiry'}= C4::Dates->new($borrower->{'dateexpiry'},'iso')->output('syspref');
120
    if ($categories_dislay{$borrower->{'categorycode'}}){
121
        my %row = (
122
	    count => $index++,
123
	    %$borrower,
124
	    %{$categories_dislay{$$borrower{categorycode}}},
125
	);
126
	push(@resultsdata, \%row);
127
    }
128
    else {
129
	 warn $borrower->{'cardnumber'} ." has a bad category code of " . $borrower->{'categorycode'} ."\n";
130
    }
131
}
132
if ($$patron{branchcode}){
133
	foreach my $branch (grep{$_->{value} eq $$patron{branchcode}}@$branches){
134
		$$branch{selected}=1;
135
	}
136
}
137
if ($$patron{categorycode}){
138
	foreach my $category (grep{$_->{categorycode} eq $$patron{categorycode}}@categories){
139
		$$category{selected}=1;
140
	}
141
}
142
my %parameters=
143
(  %{$patron},
144
    'orderby' => $orderby,
145
    'resultsperpage' => $resultsperpage,
146
    'type'=> 'intranet');
147
my $base_url =
148
    'member-search.pl?&amp;'
149
  . join(
150
    '&amp;',
151
    map { "$_=$parameters{$_}" } (keys %parameters)
152
  );
153
154
$template->param(
155
    paginationbar => pagination_bar(
156
        $base_url,  int( $count / $resultsperpage ) + 1,
157
        $startfrom, 'startfrom'
158
    ),
159
    startfrom => $startfrom,
160
    from      => ($startfrom-1)*$resultsperpage+1,
161
    to        => $to,
162
    multipage => ($count != $to+1 || $startfrom!=1),
163
);
164
$template->param(
165
    branchloop=>$branches,
166
	categoryloop=>\@categories,
167
);
168
169
170
$template->param(
171
        searching       => "1",
172
		actionname		=> basename($0),
173
		%$patron,
174
        numresults      => $count,
175
        resultsloop     => \@resultsdata,
176
            );
177
178
output_html_with_http_headers $cgi, $cookie, $template->output;
179
- 

Return to bug 13891