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

(-)a/admin/share_content.pl (+89 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it
6
# under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 3 of the License, or
8
# (at your option) any later version.
9
#
10
# Koha is distributed in the hope that it will be useful, but
11
# WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License
16
# along with Koha; if not, see <http://www.gnu.org/licenses>.
17
18
use Modern::Perl;
19
20
use CGI qw ( -utf8 );
21
use JSON;
22
use HTTP::Request;
23
24
use C4::Auth;
25
use C4::Output;
26
27
use Koha::SharedContent;
28
29
my $query = new CGI;
30
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
31
    {
32
        template_name   => "admin/share_content.tt",
33
        query           => $query,
34
        type            => "intranet",
35
        authnotrequired => 0,
36
        flagsrequired   => { parameters => '*' },
37
        debug           => 1,
38
    }
39
);
40
41
my $op = $query->param('op') || q||;
42
43
if ( $op eq 'save' ) {
44
    my $auto_share = $query->param('autosharewithmana');
45
    my $mana = $query->param('mana');
46
47
    C4::Context->set_preference('Mana', $mana);
48
49
    if ( $auto_share ne '' ) {
50
        C4::Context->set_preference('AutoShareWithMana', 'subscription');
51
    } else {
52
        C4::Context->set_preference('AutoShareWithMana', '');
53
    }
54
}
55
56
if ( $op eq 'reset' ) {
57
    C4::Context->set_preference('ManaToken', '');
58
}
59
60
if ( $op eq 'send' ) {
61
    my $name = $query->param('lastname');
62
    my $firstname = $query->param('firstname');
63
    my $email = $query->param('email');
64
65
    my $content = to_json({firstname => $firstname,
66
                           lastname => $name,
67
                           email => $email});
68
69
    my $mana_ip = C4::Context->config('mana_config');
70
    my $url = "$mana_ip/getsecuritytoken";
71
    my $request = HTTP::Request->new( POST => $url );
72
    $request->content($content);
73
    my $result = Koha::SharedContent::process_request($request);
74
75
    $template->param( result => $result );
76
77
    if ( $result->{code} eq '201' && $result->{token} ) {
78
        C4::Context->set_preference('ManaToken', $result->{token});
79
    }
80
}
81
82
83
my $mana_url = C4::Context->config('mana_config') || '';
84
85
$template->param(
86
    mana_url    => $mana_url,
87
);
88
89
output_html_with_http_headers $query, $cookie, $template->output;
(-)a/koha-tmpl/intranet-tmpl/lib/jquery/activatemana.js (-18 lines)
Lines 1-18 Link Here
1
$(document).ready(function(){
2
    $("#activatemana").on("click", function(){
3
        var mylastname = $("#lastname").val()
4
        var myfirstname = $("#firstname").val()
5
        var myemail = $("#email").val()
6
        $.ajax( {
7
            type: "POST",
8
            url: "/cgi-bin/koha/svc/mana/token",
9
            data: { lastname: mylastname, firstname: myfirstname, email: myemail},
10
            dataType: "json",
11
        })
12
        .done(function(result){
13
            $("#pref_ManaToken").val(result.token);
14
            $("#pref_ManaToken").trigger("input");
15
        });
16
        return false;
17
    });
18
});
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/admin-home.tt (-3 / +5 lines)
Lines 14-23 Link Here
14
    <div class="row">
14
    <div class="row">
15
        <div class="col-md-10 col-md-offset-1 col-lg-8 col-lg-offset-2">
15
        <div class="col-md-10 col-md-offset-1 col-lg-8 col-lg-offset-2">
16
            [% IF ( Koha.Preference('Mana') == 2) %]
16
            [% IF ( Koha.Preference('Mana') == 2) %]
17
                <fieldset>
17
                <div class="dialog alert">
18
                    <p><center> You haven't decided if you want to activate Mana Knowlede Base, please let us know by clicking<center></p>
18
                    <p><center> You haven't decided if you want to activate Mana Knowlede Base, please let us know by clicking<center></p>
19
                    <a href=/cgi-bin/koha/admin/preferences.pl?tab=&op=search&searchfield=request+to+mana+webservice><center>Here</center></a>
19
                    <a href=/cgi-bin/koha/admin/share_content.pl><center>Here</center></a>
20
                </fieldset>
20
                </div>
21
           [% END %]
21
           [% END %]
22
        <h1>Koha administration</h1>
22
        <h1>Koha administration</h1>
23
        <div class="row">
23
        <div class="row">
Lines 141-146 Link Here
141
                    [% END %]
141
                    [% END %]
142
                    <dt><a href="/cgi-bin/koha/admin/usage_statistics.pl">Share your usage statistics</a></dt>
142
                    <dt><a href="/cgi-bin/koha/admin/usage_statistics.pl">Share your usage statistics</a></dt>
143
                    <dd>Share with the Koha community the usage statistics of your Koha installation.</dd>
143
                    <dd>Share with the Koha community the usage statistics of your Koha installation.</dd>
144
                    <dt><a href="/cgi-bin/koha/admin/share_content.pl">Using Mana-KB</a></dt>
145
                    <dd>Share content (subscriptions, reports) with Koha communty</dd>
144
                </dl>
146
                </dl>
145
            </div>
147
            </div>
146
        </div>
148
        </div>
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences.tt (-1 lines)
Lines 197-203 Link Here
197
    [% Asset.js("lib/jquery/plugins/humanmsg.js") | $raw %]
197
    [% Asset.js("lib/jquery/plugins/humanmsg.js") | $raw %]
198
    [% Asset.js("js/ajax.js") | $raw %]
198
    [% Asset.js("js/ajax.js") | $raw %]
199
    [% Asset.js("js/pages/preferences.js") | $raw %]
199
    [% Asset.js("js/pages/preferences.js") | $raw %]
200
    [% Asset.js("lib/jquery/activatemana.js") | $raw %]
201
    [%# Add WYSIWYG editor for htmlarea system preferences %]
200
    [%# Add WYSIWYG editor for htmlarea system preferences %]
202
    [% INCLUDE 'wysiwyg-systempreferences.inc' %]
201
    [% INCLUDE 'wysiwyg-systempreferences.inc' %]
203
[% END %]
202
[% END %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/web_services.pref (-1 lines)
Lines 71-77 Web services: Link Here
71
             - "Security token used to authenticate on mana:"
71
             - "Security token used to authenticate on mana:"
72
             - pref: ManaToken
72
             - pref: ManaToken
73
               class: Text
73
               class: Text
74
             - <br> You need a security token to authenticate on Mana. If this sytem preference is empty, please fill in the following form, you will receive an email to confirm and activate your token. <br> <form> First name <input name="firstname" type="text" id="firstname"> <br> Last name <input name="lastname" type=text id=lastname> <br> Email address <input name="email" type=text id=email><br> <input type=submit id=activatemana value="Send"></form>
75
        -
74
        -
76
            - 'Fields automatically shared with mana'
75
            - 'Fields automatically shared with mana'
77
            - pref: AutoShareWithMana
76
            - pref: AutoShareWithMana
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/share_content.tt (+158 lines)
Line 0 Link Here
1
[% USE raw %]
2
[% USE Asset %]
3
[% SET footerjs = 1 %]
4
[% USE Koha %]
5
[% INCLUDE 'doc-head-open.inc' %]
6
<title>Koha &rsaquo; Administration &rsaquo; Koha usage statistics</title>
7
[% INCLUDE 'doc-head-close.inc' %]
8
</head>
9
10
<body id="admin_usage_statistics" class="admin">
11
[% INCLUDE 'header.inc' %]
12
[% INCLUDE 'cat-search.inc' %]
13
14
<div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo; <a href="/cgi-bin/koha/admin/admin-home.pl">Administration</a> &rsaquo; Usage statistics</div>
15
16
<div class="main container-fluid">
17
    <div class="row">
18
        <div class="col-sm-10 col-sm-push-2">
19
            <div class="col-sm-6">
20
                [% IF result.code != 201 && result.msg %]
21
                    <div class="alert alert-danger" role="alert">
22
                        [% result.msg | html %]
23
                    </div>
24
                [% END %]
25
26
                [% IF result.code == 201  %]
27
                    <div class="dialog message" role="alert">
28
Well done! You successfully created your Mana KB account. Check your mailbox and follow instructions.
29
                    </div>
30
                [% END %]
31
32
                [% UNLESS (mana_url) %]
33
                    <div class="alert alert-danger" role="alert">
34
                        Mana config is currently empty, this feature will not work. Please contact your site administartor.
35
                    </div>
36
                [% END %]
37
38
                <h1>Share content with the Koha community using Mana KB</h1>
39
                <p>Mana-kb is a global knowledge base for library-centric data. It has been designed initially to interact with Koha, the Open Source ILS, but can be used by any other software.</p>
40
41
                <p>Mana centralize commun information between other Koha to facilitate the creation of new subscriptions, vendors, report queries etc... You can search, share, import and comment the content of Mana. The informations shared with Mana KB are shared under the CC-0 license. More infos about CC-0 license <a href="https://creativecommons.org/choose/zero/">here</a>.</p>
42
43
                <p>Learn more about Mana on the <a href="https://wiki.koha-community.org/wiki/Mana_central_database">official documentation</a>.</p>
44
45
                [% IF (mana_url) %]
46
                <p> Your Mana KB server is currently: <strong>[% mana_url | url %]</strong></p>
47
                [% END %]
48
49
                <form id="mana_preference" method="post">
50
                    <fieldset class="rows">
51
                        <ol>
52
                            <li>
53
                                <label for="mana">Use Mana KB for sharing content: </label>
54
                                <select name="mana">
55
                                    [% IF Koha.Preference('Mana') == 0 %]
56
                                        <option value="0" selected="selected">No</option>
57
                                    [% ELSE %]
58
                                        <option value="0"">No</option>
59
                                    [% END %]
60
61
                                    [% IF Koha.Preference('Mana') == 1 %]
62
                                        <option value="1" selected="selected">Yes</option>
63
                                    [% ELSE %]
64
                                        <option value="1">Yes</option>
65
                                    [% END %]
66
67
                                    [% IF Koha.Preference('Mana') == 2 %]
68
                                        <option value="2" selected="selected">No, let me think about it</option>
69
                                    [% ELSE %]
70
                                        <option value="2">No, let me think about it</option>
71
                                    [% END %]
72
                                </select>
73
                                <div class="hint">Enable Mana allow you to search, import and comment content from Mana server, and, to share your own.</div>
74
                            </li>
75
                            <li>
76
                                <label for="autosharewithmana">Auto subscriptions sharing: </label>
77
                                [% IF Koha.Preference('AutoShareWithMana').grep('subscription').size == 0 %]
78
                                    <input type="checkbox" name="autosharewithmana">
79
                                [% ELSE %]
80
                                    <input type="checkbox" name="autosharewithmana" checked="checked">
81
                                [% END %]
82
                                <div class="hint">If checked, new subscriptions you created yourself will be automatically shared with Mana KB.</div>
83
                            </li>
84
                            <li>
85
                                <input type="hidden" name="op" value="save">
86
                                <input type="submit" value="Save">
87
                            </li>
88
                        </ol>
89
                    </fieldset>
90
                </form>
91
92
                [% UNLESS Koha.Preference('ManaToken') %]
93
                    <h3>Configure Mana KB</h3>
94
                    <p>Once you have enabled Mana, let's start to set it up. Type your first name, last name, email address and click on send. This will send a account creation request to Mana KB that will respond back with a Mana token (a crypted id that uniquely identify your Koha). This token will automatically be saved in your database. Just after that, you will receive an email. Read it and follow the instructions.</p>
95
                [% END %]
96
97
                [% IF Koha.Preference('ManaToken') %]
98
                    <form id="mana_token" method="post">
99
                        <fieldset class="rows" id="mana_token">
100
                        <legend>Mana KB token</legend>
101
                            <ol>
102
                                <li>
103
                                    <label for="token">Mana token: </label>
104
                                    <input type="text" name="token" value="[% Koha.Preference('ManaToken') | html %]" size="50" disabled="disabled">
105
                                    <div class="hint">Your unique security token used for authentication on Mana KB service (anti spam).</div>
106
                                </li>
107
                                <li>
108
                                    <input type="hidden" name="op" value="reset">
109
                                    <input type="submit" value="Reset your token">
110
                                </li>
111
                            </ol>
112
                        </fieldset>
113
                    </form>
114
                [% ELSE %]
115
                    <form id="mana_request" method="post">
116
                        <fieldset class="rows" id="mana_subscription">
117
                            <ol>
118
                                <li>
119
                                    <label for="firstname">First name: </label>
120
                                    <input type="text" name="firstname">
121
                                </li>
122
                                <li>
123
                                    <label for="lastname">Last name: </label>
124
                                    <input type="text" name="lastname">
125
                                </li>
126
                                <li>
127
                                    <label for="email">Email: </label>
128
                                    <input type="text" name="email" size="45" required="required">
129
                                </li>
130
                                <li>
131
                                    <input type="hidden" name="op" value="send">
132
                                    <input type="submit" value="Send to Mana KB">
133
                                </li>
134
                            </ol>
135
                        </fieldset>
136
                    </form>
137
                [% END %]
138
            </div>
139
        </div> <!-- /.col-sm-10.col-sm-push-2 -->
140
141
        <div class="col-sm-2 col-sm-pull-10">
142
            <aside>
143
                [% INCLUDE 'admin-menu.inc' %]
144
            </aside>
145
        </div> <!-- /.col-sm-2.col-sm-pull-10 -->
146
     </div> <!-- /.row -->
147
148
[% MACRO jsinclude BLOCK %]
149
    [% Asset.js("js/admin-menu.js") | $raw %]
150
    <script>
151
        $(document).ready(function() {
152
            $('#mana_token').submit(function() {
153
                return confirm("This will delete the Mana token from Koha. Do you want to continue?");
154
            });
155
        });
156
    </script>
157
[% END %]
158
[% INCLUDE 'intranet-bottom.inc' %]
(-)a/svc/mana/token (-56 lines)
Lines 1-55 Link Here
1
#!/usr/bin/perl
2
3
# Copyright 2016 BibLibre Baptiste Wojtkowski
4
#
5
# This file is part of Koha.
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
21
22
use Modern::Perl;
23
24
use Koha::SharedContent;
25
use C4::Auth qw(check_cookie_auth);
26
27
use CGI;
28
use JSON;
29
30
my $input = new CGI;
31
binmode STDOUT, ":encoding(UTF-8)";
32
print $input->header( -type => 'text/plain', -charset => 'UTF-8' );
33
34
my ( $auth_status, $sessionID ) =
35
  check_cookie_auth( $input->cookie('CGISESSID'),
36
    { serials => 'create_subscription' } );
37
38
if ( $auth_status ne "ok" ) {
39
    exit 0;
40
}
41
42
my $mana_ip = C4::Context->config('mana_config');
43
44
my $url = "$mana_ip/getsecuritytoken";
45
my $request = HTTP::Request->new( POST => $url );
46
47
my $content;
48
$content->{ firstname }= $input->param("firstname");
49
$content->{ lastname }= $input->param("lastname");
50
$content->{ email }= $input->param("email");
51
my $json = to_json( $content, { utf8 => 1 } );
52
$request->content($json);
53
my $result = Koha::SharedContent::process_request($request);
54
55
print(to_json($result));
56
- 

Return to bug 17047