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

(-)a/admin/add_user_search.pl (+60 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   => { acquisition => 'budget_modify'  },
37
    }
38
);
39
40
my $q = $input->param('q') || '';
41
my $op = $input->param('op') || '';
42
my $selection_type = $input->param('selection_type') || 'add';
43
44
my $referer = $input->referer();
45
46
# If this script is called by acqui/basket.pl
47
# the patrons to return should be superlibrarian or have the order_manage
48
# acquisition flag.
49
my $search_patrons_with_acq_perm_only =
50
    ( $referer =~ m|admin/aqbudgets.pl| )
51
        ? 1 : 0;
52
53
$template->param(
54
    patrons_with_acq_perm_only => $search_patrons_with_acq_perm_only,
55
    view => ( $input->request_method() eq "GET" ) ? "show_form" : "show_results",
56
    columns => ['cardnumber', 'name', 'branch', 'category', 'action'],
57
    json_template => 'acqui/tables/members_results.tt',
58
    selection_type => $selection_type,
59
);
60
output_html_with_http_headers( $input, $cookie, $template->output );
(-)a/admin/aqbudget_user_search.pl (-89 lines)
Lines 1-89 Link Here
1
#!/usr/bin/perl
2
3
# script to find owner and users for a budget
4
5
# Copyright 2008-2009 BibLibre SARL
6
#
7
# This file is part of Koha.
8
#
9
# Koha is free software; you can redistribute it and/or modify it under the
10
# terms of the GNU General Public License as published by the Free Software
11
# Foundation; either version 2 of the License, or (at your option) any later
12
# version.
13
#
14
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
15
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
16
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
17
#
18
# You should have received a copy of the GNU General Public License along
19
# with Koha; if not, write to the Free Software Foundation, Inc.,
20
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21
22
use Modern::Perl;
23
24
use C4::Auth ;
25
use C4::Output;
26
use CGI qw ( -utf8 );
27
use C4::Dates qw/format_date/;
28
use C4::Members;
29
30
my $input = new CGI;
31
32
my $dbh = C4::Context->dbh;
33
34
my ( $template, $loggedinuser, $cookie, $staff_flags ) = get_template_and_user(
35
    {   template_name   => "admin/aqbudget_user_search.tt",
36
        query           => $input,
37
        type            => "intranet",
38
        authnotrequired => 0,
39
        flagsrequired   => { acquisition => 'budget_modify'  },
40
        debug           => 1,
41
    }
42
);
43
44
# only used if allowthemeoverride is set
45
my $type = $input->param('type');
46
my $member  = $input->param('member') // '';
47
48
$member =~ s/,//g;     #remove any commas from search string
49
$member =~ s/\*/%/g;
50
if ( $member eq '' ) {
51
    $template->param( results => 0 );
52
} else {
53
    $template->param( results => 1 );
54
}
55
56
my @resultsdata;
57
58
if ( $member ) {
59
    my $results = Search($member, "surname");
60
61
    foreach my $res (@$results) {
62
        my $perms = haspermission( $res->{'userid'} );
63
        my $subperms = get_user_subpermissions( $res->{'userid'} );
64
65
        # if the member has 'acqui' permission set, then display to table.
66
        if ( $perms->{superlibrarian} == 1  ||
67
             $perms->{acquisition} == 1  ||
68
             exists $subperms->{acquisition} )
69
        {
70
            my %row = (
71
                borrowernumber    => $res->{'borrowernumber'},
72
                cardnumber        => $res->{'cardnumber'},
73
                surname           => $res->{'surname'},
74
                firstname         => $res->{'firstname'},
75
                categorycode      => $res->{'categorycode'},
76
                branchcode        => $res->{'branchcode'},
77
            );
78
            push( @resultsdata, \%row );
79
        }
80
    }
81
}
82
83
$template->param(
84
    type => $type,
85
    member => $member,
86
    resultsloop => \@resultsdata
87
);
88
89
output_html_with_http_headers $input, $cookie, $template->output;
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/tables/members_results.tt (-1 / +6 lines)
Lines 1-3 Link Here
1
[% USE To %]
1
{
2
{
2
    "sEcho": [% sEcho %],
3
    "sEcho": [% sEcho %],
3
    "iTotalRecords": [% iTotalRecords %],
4
    "iTotalRecords": [% iTotalRecords %],
Lines 14-20 Link Here
14
                "dt_category":
15
                "dt_category":
15
                    "[% data.category_description |html %] ([% data.category_type |html %])",
16
                    "[% data.category_description |html %] ([% data.category_type |html %])",
16
                "dt_action":
17
                "dt_action":
17
                    "<a style='cursor:pointer' onclick='add_user(\"[% data.borrowernumber %]\", \"[% data.firstname %] [% data.surname %]\");'>Select</a>"
18
                    [%- IF selection_type == 'select' -%]
19
                        "<a style='cursor:pointer' onclick='select_user(\"[% data.borrowernumber %]\", [% To.json(data) | html %] );'>Select</a>"
20
                    [%- ELSE -%]
21
                        "<a style='cursor:pointer' onclick='add_user(\"[% data.borrowernumber %]\", \"[% data.firstname %] [% data.surname %]\");'>Select</a>"
22
                    [%- END -%]
18
            }[% UNLESS loop.last %],[% END %]
23
            }[% UNLESS loop.last %],[% END %]
19
        [% END %]
24
        [% END %]
20
    ]
25
    ]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/aqbudget_user_search.tt (-111 lines)
Lines 1-111 Link Here
1
[% INCLUDE 'doc-head-open.inc' %]
2
<title>Koha &rsaquo; Budget
3
    [% IF (type == 'owner') %]
4
        owner
5
    [% ELSE %]
6
        user
7
    [% END %]
8
    search
9
</title>
10
[% INCLUDE 'doc-head-close.inc' %]
11
    <style type="text/css">
12
    #custom-doc {
13
        width:44.46em;
14
        *width:43.39em;
15
        min-width:578px;
16
        margin:auto;
17
        text-align:left;
18
    }
19
    </style>
20
21
    <script type="text/javascript">
22
    //<![CDATA[
23
24
    // modify parent window owner element
25
    function add_user(borrowernumber, borrowername) {
26
        [% IF (type == 'owner') %]
27
            top.opener.edit_owner(borrowernumber, borrowername);
28
            window.close();
29
        [% ELSE %]
30
            var ret = top.opener.add_user(borrowernumber, borrowername);
31
            if (ret != 0) {
32
                alert(_("This user is already in the list."));
33
            }
34
        [% END %]
35
    }
36
37
    //]]>
38
    </script>
39
</head>
40
41
<body id="admin_aqbudget_owner_search" class="admin">
42
<div id="custom-doc" class="yui-t7">
43
<div id="bd">
44
<div class="yui-g">
45
46
<h3>Search for budget
47
    [% IF (type == 'owner') %]
48
        owner
49
    [% ELSE %]
50
        user
51
    [% END %]
52
</h3>
53
<form action="/cgi-bin/koha/admin/aqbudget_user_search.pl" method="post">
54
    <fieldset>
55
        <input type="text" name="member" id="member" value="[% member %]"
56
            class="focus" />
57
58
        <input type="hidden" name="type" value="[% type %]" />
59
        <input type="submit" class="button" value="Search" />
60
    </fieldset>
61
62
    <div class="hint">
63
        Only staff with superlibrarian or acquisitions permissions are returned
64
        in the search results.
65
    </div>
66
</form>
67
68
69
[% IF ( results ) %]
70
    <p>Searched for <span class="ex">[% member %]</span>,
71
    [% resultsloop.size || 0 %] patron(s) found:</p>
72
73
    <table>
74
        <thead>
75
            <tr>
76
                <th>Cardnumber</th>
77
                <th>Name</th>
78
                <th>Library</th>
79
                <th>Categorycode</th>
80
                <th>Select?</th>
81
            </tr>
82
        </thead>
83
84
        <tbody>
85
            [% FOREACH result IN resultsloop %]
86
                <tr>
87
                    <td>[% result.cardnumber %]</td>
88
                    <td>[% result.surname %], [% result.firstname %]</td>
89
                    <td>[% result.branchcode %]</td>
90
                    <td>[% result.categorycode %]</td>
91
                    <td>
92
                    <a style="cursor:pointer"
93
                        onclick="add_user(
94
                            '[% result.borrowernumber %]',
95
                            '[% result.surname %]',
96
                            '[% result.firstname %]'
97
                        );"
98
                    />Select</a>
99
                    </td>
100
                </tr>
101
            [% END %]
102
        </tbody>
103
    </table>
104
[% END %]
105
106
<div id="closewindow">
107
    <a href="#" class="close">Close</a>
108
</div>
109
</div>
110
</div>
111
[% INCLUDE 'intranet-bottom.inc' %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/aqbudgets.tt (-7 / +7 lines)
Lines 16-22 var MSG_PARENT_BENEATH_BUDGET = "- " + _("New budget-parent is beneath budget") Link Here
16
//<![CDATA[
16
//<![CDATA[
17
17
18
    function userPopup() {
18
    function userPopup() {
19
        window.open("/cgi-bin/koha/admin/aqbudget_user_search.pl?type=user",
19
        window.open("/cgi-bin/koha/admin/add_user_search.pl?selection_type=add",
20
            'PatronPopup',
20
            'PatronPopup',
21
            'width=740,height=450,location=yes,toolbar=no,'
21
            'width=740,height=450,location=yes,toolbar=no,'
22
            + 'scrollbars=yes,resize=yes'
22
            + 'scrollbars=yes,resize=yes'
Lines 24-39 var MSG_PARENT_BENEATH_BUDGET = "- " + _("New budget-parent is beneath budget") Link Here
24
    }
24
    }
25
25
26
    function ownerPopup() {
26
    function ownerPopup() {
27
        window.open("/cgi-bin/koha/admin/aqbudget_user_search.pl?type=owner",
27
        window.open("/cgi-bin/koha/admin/add_user_search.pl?selection_type=select",
28
            'PatronPopup',
28
            'PatronPopup',
29
            'width=740,height=450,location=yes,toolbar=no,'
29
            'width=740,height=450,location=yes,toolbar=no,'
30
            + 'scrollbars=yes,resize=yes'
30
            + 'scrollbars=yes,resize=yes'
31
        );
31
        );
32
    }
32
    }
33
33
34
    function edit_owner(borrowernumber, borrowername) {
34
    function select_user(borrowernumber, borrower) {
35
        $('#budget_owner_name').empty();
35
        ownerRemove();
36
        $('#budget_owner_id').val('');
36
        var borrowername = borrower.firstname + ' ' + borrower.surname
37
        if (borrowernumber) {
37
        if (borrowernumber) {
38
            var ownerlink = '<a href="/cgi-bin/koha/members/moremember.pl'
38
            var ownerlink = '<a href="/cgi-bin/koha/members/moremember.pl'
39
                + '?borrowernumber=' + borrowernumber + '">'
39
                + '?borrowernumber=' + borrowernumber + '">'
Lines 44-50 var MSG_PARENT_BENEATH_BUDGET = "- " + _("New budget-parent is beneath budget") Link Here
44
    }
44
    }
45
45
46
    function ownerRemove() {
46
    function ownerRemove() {
47
        edit_owner(0);
47
        $('#budget_owner_name').empty();
48
        $('#budget_owner_id').val('');
48
    }
49
    }
49
50
50
    function add_user(borrowernumber, borrowername) {
51
    function add_user(borrowernumber, borrowername) {
Lines 483-489 var MSG_PARENT_BENEATH_BUDGET = "- " + _("New budget-parent is beneath budget") Link Here
483
        <input type="hidden" name="budget_owner_id" id="budget_owner_id"
484
        <input type="hidden" name="budget_owner_id" id="budget_owner_id"
484
            value="[% budget_owner_id %]" />
485
            value="[% budget_owner_id %]" />
485
486
486
        <!-- FIXME: hardcoded button positions :/ -->
487
        <input type="button" id="edit_owner" value="Edit owner"
487
        <input type="button" id="edit_owner" value="Edit owner"
488
            onclick="ownerPopup(); return false;" />
488
            onclick="ownerPopup(); return false;" />
489
        <input type="button" id="remove_owner" value="Remove owner"
489
        <input type="button" id="remove_owner" value="Remove owner"
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/common/patron_search.tt (+3 lines)
Lines 44-49 $(document).ready(function(){ Link Here
44
            },{
44
            },{
45
                'name': 'template_path',
45
                'name': 'template_path',
46
                'value': '[% json_template %]',
46
                'value': '[% json_template %]',
47
            },{
48
                'name': 'selection_type',
49
                'value': '[% selection_type %]',
47
            }
50
            }
48
            [% IF patrons_with_acq_perm_only %]
51
            [% IF patrons_with_acq_perm_only %]
49
            ,{
52
            ,{
(-)a/svc/members/search (-2 / +3 lines)
Lines 45-50 my $branchcode = $input->param('branchcode'); Link Here
45
my $searchtype = $input->param('searchtype');
45
my $searchtype = $input->param('searchtype');
46
my $searchfieldstype = $input->param('searchfieldstype') || 'standard';
46
my $searchfieldstype = $input->param('searchfieldstype') || 'standard';
47
my $has_permission = $input->param('has_permission');
47
my $has_permission = $input->param('has_permission');
48
my $selection_type = $input->param('selection_type');
48
49
49
if ( $searchfieldstype eq "dateofbirth" ) {
50
if ( $searchfieldstype eq "dateofbirth" ) {
50
    $searchmember = output_pref({dt => dt_from_string($searchmember), dateformat => 'iso', dateonly => 1});
51
    $searchmember = output_pref({dt => dt_from_string($searchmember), dateformat => 'iso', dateonly => 1});
Lines 115-121 $template->param( Link Here
115
    sEcho => $sEcho,
116
    sEcho => $sEcho,
116
    iTotalRecords => $results->{iTotalRecords},
117
    iTotalRecords => $results->{iTotalRecords},
117
    iTotalDisplayRecords => $results->{iTotalDisplayRecords},
118
    iTotalDisplayRecords => $results->{iTotalDisplayRecords},
118
    aaData => $results->{patrons}
119
    aaData => $results->{patrons},
120
    selection_type => $selection_type,
119
);
121
);
120
122
121
output_with_http_headers $input, $cookie, $template->output, 'json';
123
output_with_http_headers $input, $cookie, $template->output, 'json';
122
- 

Return to bug 13891