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

(-)a/C4/Serials.pm (-4 / +4 lines)
Lines 1409-1415 sub NewSubscription { Link Here
1409
    $innerloop3, $status, $notes, $letter, $firstacquidate, $irregularity,
1409
    $innerloop3, $status, $notes, $letter, $firstacquidate, $irregularity,
1410
    $numberpattern, $locale, $callnumber, $manualhistory, $internalnotes,
1410
    $numberpattern, $locale, $callnumber, $manualhistory, $internalnotes,
1411
    $serialsadditems, $staffdisplaycount, $opacdisplaycount, $graceperiod,
1411
    $serialsadditems, $staffdisplaycount, $opacdisplaycount, $graceperiod,
1412
    $location, $enddate, $skip_serialseq, $itemtype, $previousitemtype
1412
    $location, $enddate, $skip_serialseq, $itemtype, $previousitemtype, $mana_id
1413
    ) = @_;
1413
    ) = @_;
1414
    my $dbh = C4::Context->dbh;
1414
    my $dbh = C4::Context->dbh;
1415
1415
Lines 1423-1430 sub NewSubscription { Link Here
1423
            irregularity, numberpattern, locale, callnumber,
1423
            irregularity, numberpattern, locale, callnumber,
1424
            manualhistory, internalnotes, serialsadditems, staffdisplaycount,
1424
            manualhistory, internalnotes, serialsadditems, staffdisplaycount,
1425
            opacdisplaycount, graceperiod, location, enddate, skip_serialseq,
1425
            opacdisplaycount, graceperiod, location, enddate, skip_serialseq,
1426
            itemtype, previousitemtype)
1426
            itemtype, previousitemtype, mana_id)
1427
        VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)
1427
        VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?, ?)
1428
        |;
1428
        |;
1429
    my $sth = $dbh->prepare($query);
1429
    my $sth = $dbh->prepare($query);
1430
    $sth->execute(
1430
    $sth->execute(
Lines 1435-1441 sub NewSubscription { Link Here
1435
        $firstacquidate, $irregularity, $numberpattern, $locale, $callnumber,
1435
        $firstacquidate, $irregularity, $numberpattern, $locale, $callnumber,
1436
        $manualhistory, $internalnotes, $serialsadditems, $staffdisplaycount,
1436
        $manualhistory, $internalnotes, $serialsadditems, $staffdisplaycount,
1437
        $opacdisplaycount, $graceperiod, $location, $enddate, $skip_serialseq,
1437
        $opacdisplaycount, $graceperiod, $location, $enddate, $skip_serialseq,
1438
        $itemtype, $previousitemtype
1438
        $itemtype, $previousitemtype, $mana_id
1439
    );
1439
    );
1440
1440
1441
    my $subscriptionid = $dbh->{'mysql_insertid'};
1441
    my $subscriptionid = $dbh->{'mysql_insertid'};
(-)a/Koha/SharedContent.pm (+14 lines)
Lines 40-45 sub manaRequest { Link Here
40
    return $result if ( $response->code =~ /^2..$/ );
40
    return $result if ( $response->code =~ /^2..$/ );
41
}
41
}
42
42
43
sub manaPostRequest {
44
    my $resource = shift;
45
    my $content  = shift;
46
47
    my $url = "$MANA_IP/$resource.json";
48
    my $request = HTTP::Request->new( POST => $url );
49
50
    $content->{bulk_import} = 0;
51
    my $json = to_json( $content, { utf8 => 1 } );
52
    $request->content($json);
53
54
    return manaRequest($request);
55
}
56
43
sub manaGetRequest {
57
sub manaGetRequest {
44
    my $resource   = shift;
58
    my $resource   = shift;
45
    my $parameters = shift;
59
    my $parameters = shift;
(-)a/Koha/Subscription.pm (+51 lines)
Lines 22-27 use Modern::Perl; Link Here
22
use Carp;
22
use Carp;
23
23
24
use Koha::Database;
24
use Koha::Database;
25
use Koha::Biblios;
26
use Koha::Biblioitems;
27
use Koha::Subscriptions;
28
use Koha::Subscription::Frequencies;
29
use Koha::Subscription::Numberpatterns;
30
use JSON;
25
31
26
use base qw(Koha::Object);
32
use base qw(Koha::Object);
27
33
Lines 39-44 Koha::Subscription - Koha Subscription Object class Link Here
39
45
40
=cut
46
=cut
41
47
48
sub get_sharable_info {
49
    my $shared_sub_id = shift;
50
    my $subscription  = Koha::Subscriptions->find($shared_sub_id);
51
    my $biblio        = Koha::Biblios->find( $subscription->biblionumber );
52
    my $biblioitem    = Koha::Biblioitems->find(
53
        { 'biblionumber' => $subscription->biblionumber } );
54
    my $sub_frequency =
55
      Koha::Subscription::Frequencies->find( $subscription->periodicity );
56
    my $sub_numberpatteern =
57
      Koha::Subscription::Numberpatterns->find( $subscription->numberpattern );
58
59
    my $sub_mana_info = {
60
        'title'           => $biblio->title,
61
        'sfdescription'   => $sub_frequency->description,
62
        'unit'            => $sub_frequency->unit,
63
        'unitsperissue'   => $sub_frequency->unitsperissue,
64
        'issuesperunit'   => $sub_frequency->issuesperunit,
65
        'label'           => $sub_numberpatteern->label,
66
        'sndescription'   => $sub_numberpatteern->description,
67
        'numberingmethod' => $sub_numberpatteern->numberingmethod,
68
        'label1'          => $sub_numberpatteern->label1,
69
        'add1'            => $sub_numberpatteern->add1,
70
        'every1'          => $sub_numberpatteern->every1,
71
        'whenmorethan1'   => $sub_numberpatteern->whenmorethan1,
72
        'setto1'          => $sub_numberpatteern->setto1,
73
        'numbering1'      => $sub_numberpatteern->numbering1,
74
        'label2'          => $sub_numberpatteern->label2,
75
        'add2'            => $sub_numberpatteern->add2,
76
        'every2'          => $sub_numberpatteern->every2,
77
        'whenmorethan2'   => $sub_numberpatteern->whenmorethan2,
78
        'setto2'          => $sub_numberpatteern->setto2,
79
        'numbering2'      => $sub_numberpatteern->numbering2,
80
        'label3'          => $sub_numberpatteern->label3,
81
        'add3'            => $sub_numberpatteern->add3,
82
        'every3'          => $sub_numberpatteern->every3,
83
        'whenmorethan3'   => $sub_numberpatteern->whenmorethan3,
84
        'setto3'          => $sub_numberpatteern->setto3,
85
        'numbering3'      => $sub_numberpatteern->numbering3,
86
        'issn'            => $biblioitem->issn,
87
        'ean'             => $biblioitem->ean,
88
        'publishercode'   => $biblioitem->publishercode
89
    };
90
    return $sub_mana_info;
91
}
92
42
sub _type {
93
sub _type {
43
    return 'Subscription';
94
    return 'Subscription';
44
}
95
}
(-)a/installer/data/mysql/atomicupdate/mana_01-add_mana_id_in_subscription.sql (+1 lines)
Line 0 Link Here
1
ALTER TABLE subscription ADD mana_id int(11);
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/serials-toolbar.inc (+108 lines)
Lines 13-18 Link Here
13
            window.location="subscription-detail.pl?subscriptionid=[% subscriptionid %]&op=reopen";
13
            window.location="subscription-detail.pl?subscriptionid=[% subscriptionid %]&op=reopen";
14
        }
14
        }
15
    }
15
    }
16
    function share() {
17
        window.location="subscription-detail.pl?subscriptionid=[% subscriptionid %]&op=share";
18
    }
16
19
17
	 $(document).ready(function() {
20
	 $(document).ready(function() {
18
        $("#deletesub").click(function(){
21
        $("#deletesub").click(function(){
Lines 43-48 Link Here
43
            [% ELSE %]
46
            [% ELSE %]
44
                <div class="btn-group"><a id="newsubscription" class="btn btn-default btn-sm" href="/cgi-bin/koha/serials/subscription-add.pl"><i class="fa fa-plus"></i> New subscription</a></div>
47
                <div class="btn-group"><a id="newsubscription" class="btn btn-default btn-sm" href="/cgi-bin/koha/serials/subscription-add.pl"><i class="fa fa-plus"></i> New subscription</a></div>
45
            [% END %]
48
            [% END %]
49
            [% IF Koha.Preference('Mana') %]
50
                [% IF one_language_enabled==0 or mana_id %]
51
                    <div class="btn-group"><a data-toggle="modal" data-toggle="tooltip" title="Your email address will be associated to your sharing." data-target="#mana_share_modal" class="btn btn-small"><i class="fa fa-share-alt"></i> Share</a></div>
52
                [% ELSE %]
53
                    <div class="btn-group" data-toggle="tooltip" title="Your email address will be associated to your sharing."><a class="btn btn-small" onclick="share()"><i class="fa fa-share-alt"></i> Share</a></div>
54
                [% END %]
55
            [% END %]
46
        [% END %]
56
        [% END %]
47
57
48
        [% IF ( CAN_user_serials_edit_subscription || CAN_user_serials_create_subscription || CAN_user_serials_delete_subscription ) %]
58
        [% IF ( CAN_user_serials_edit_subscription || CAN_user_serials_create_subscription || CAN_user_serials_delete_subscription ) %]
Lines 99-101 Link Here
99
        [% END %]
109
        [% END %]
100
    </div>
110
    </div>
101
[% END %]
111
[% END %]
112
113
<div id="mana_share_modal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="mana_share_modal_label" style="display: none;">
114
    <div class="modal-dialog">
115
        <div class="modal-content">
116
            <div class="modal-header">
117
                <h3 id="mana_share_modal_label">Share [% bibliotitle %] to Mana</h3>
118
            </div>
119
            <div class="modal-body">
120
                [% IF (mana_id) %]
121
                    <div class="alert">
122
                        <p>Your subscription is already linked with a Mana subscription model. Share it if you have made modifications, otherwide it will do nothing.</p>
123
                    </div>
124
                [% END %]
125
                [% IF ( languages_loop ) %]
126
                    [% UNLESS ( one_language_enabled ) %]
127
                        <div class="rows">
128
                            <p>The frequency and the numberpattern of [% bibliotitle %] are :</p>
129
                            <ol>
130
                                <li><span class="label">Frequency : </span>
131
                                        [% frequency.description %]
132
                                </li>
133
                                <li><span class="label">Number pattern : </span>
134
                                    [% numberpattern.label %]
135
                                </li>
136
                            </ol>
137
                        </div>
138
                        <div class="rows">
139
                            <form method="get" id="mana_share_form" action="/cgi-bin/koha/serials/subscription-detail.pl" class="validated" >
140
                                <fieldset>
141
                                    <label for="mana_language">Language of your sharing :</label>
142
                                    <select id="mana_language" name="mana_language">
143
                                        [% FOREACH languages_loo IN languages_loop %]
144
                                            [% IF ( languages_loo.group_enabled ) %]
145
                                                [% IF ( languages_loo.plural ) %]
146
                                                    [% FOREACH sublanguages_loo IN languages_loo.sublanguages_loop %]
147
                                                        [% IF ( sublanguages_loo.enabled ) %]
148
                                                            [% IF ( sublanguages_loo.sublanguage_current ) %]
149
                                                                <option value="[% languages_loo.rfc4646_subtag %]" selected>
150
                                                                    [% sublanguages_loo.native_description %]
151
                                                                    [% sublanguages_loo.script_description %]
152
                                                                    [% sublanguages_loo.region_description %]
153
                                                                    [% sublanguages_loo.variant_description %]
154
                                                                    ([% sublanguages_loo.rfc4646_subtag %])
155
                                                                </option>
156
                                                            [% ELSE %]
157
                                                                <option value="[% languages_loo.rfc4646_subtag %]">
158
                                                                    [% sublanguages_loo.native_description %]
159
                                                                    [% sublanguages_loo.script_description %]
160
                                                                    [% sublanguages_loo.region_description %]
161
                                                                    [% sublanguages_loo.variant_description %]
162
                                                                    ([% sublanguages_loo.rfc4646_subtag %])
163
                                                                </option>
164
                                                            [% END %]
165
                                                        [% END %]
166
                                                    [% END %]
167
                                                [% ELSE %]
168
                                                    [% IF ( languages_loo.group_enabled ) %]
169
                                                        [% IF ( languages_loo.current ) %]
170
                                                            <option value="[% languages_loo.rfc4646_subtag %]" selected>
171
                                                                [% IF ( languages_loo.native_description ) %]
172
                                                                    [% languages_loo.native_description %]
173
                                                                [% ELSE %]
174
                                                                    [% languages_loo.rfc4646_subtag %]
175
                                                                [% END %]
176
                                                            </option>
177
                                                        [% ELSE %]
178
                                                            <option value="[% languages_loo.rfc4646_subtag %]">
179
                                                                [% IF ( languages_loo.native_description ) %]
180
                                                                    [% languages_loo.native_description %]
181
                                                                [% ELSE %]
182
                                                                    [% languages_loo.rfc4646_subtag %]
183
                                                                [% END %]
184
                                                            </option>
185
                                                        [% END %]
186
                                                    [% END %]
187
                                                [% END %]
188
                                            [% END %]
189
                                        [% END %]
190
                                    </select>
191
                                    <input type="hidden" id="op" name="op" value="share"/>
192
                                    <input type="hidden" id="subscriptionid" name="subscriptionid" value="[% subscriptionid %]"/>
193
                                </fieldset>
194
                            </form>
195
                        </div>
196
                    [% END %]
197
                [% END %]
198
            </div>
199
            <div class="modal-footer">
200
                <button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
201
                [% IF one_language_enabled==0 %]
202
                    <button type="submit" form="mana_share_form" class="btn btn-primary">Share</button>
203
                [% ELSE %]
204
                    <div class="btn-group"><a class="btn btn-primary" onclick="share()">Share</a></div>
205
                [% END %]
206
            </div>
207
        </div>
208
    </div>
209
</div>
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-detail.tt (-2 / +14 lines)
Lines 1-6 Link Here
1
[% USE Koha %]
1
[% USE Koha %]
2
[% USE Branches %]
2
[% USE Branches %]
3
[% USE AuthorisedValues %]
3
[% USE AuthorisedValues %]
4
[% USE Koha %]
4
[% INCLUDE 'doc-head-open.inc' %]
5
[% INCLUDE 'doc-head-open.inc' %]
5
<title>Koha &rsaquo; Serials &rsaquo; Details for subscription #[% subscriptionid %]</title>
6
<title>Koha &rsaquo; Serials &rsaquo; Details for subscription #[% subscriptionid %]</title>
6
[% INCLUDE 'doc-head-close.inc' %]
7
[% INCLUDE 'doc-head-close.inc' %]
Lines 41-47 $(document).ready(function() { Link Here
41
   <div id="bd">
42
   <div id="bd">
42
	<div id="yui-main">
43
	<div id="yui-main">
43
	<div class="yui-b">
44
	<div class="yui-b">
44
	[% INCLUDE 'serials-toolbar.inc' %]
45
    [% INCLUDE 'serials-toolbar.inc' mana_id = mana_id %]
45
46
46
    <h1>Subscription for [% bibliotitle%] [% IF closed %](closed)[% END %]</h1>
47
    <h1>Subscription for [% bibliotitle%] [% IF closed %](closed)[% END %]</h1>
47
    [% IF ( abouttoexpire ) %]
48
    [% IF ( abouttoexpire ) %]
Lines 70-76 $(document).ready(function() { Link Here
70
			</form>
71
			</form>
71
72
72
	</div>
73
	</div>
73
	[% END %] <!-- NEEDSCONFIRMATION -->
74
    [% END %] <!-- NEEDSCONFIRMATION -->
75
    [% IF mana_code.defined %]
76
        <div id="alert-community" class="dialog message">
77
            <p>
78
                [% IF (mana_code == 201) %]
79
                    The export is done, thank you for your contribution.
80
                [% ELSIF (mana_code == 200) %]
81
                    The model already exists on Mana, thank you for your contribution.
82
                [% END %]
83
            </p>
84
        </div>
85
    [% END %]
74
86
75
<div id="subscription_description" class="toptabs">
87
<div id="subscription_description" class="toptabs">
76
<ul class="ui-tabs-nav">
88
<ul class="ui-tabs-nav">
(-)a/serials/subscription-detail.pl (-13 / +59 lines)
Lines 33-38 use Koha::Acquisition::Bookseller; Link Here
33
use Date::Calc qw/Today Day_of_Year Week_of_Year Add_Delta_Days/;
33
use Date::Calc qw/Today Day_of_Year Week_of_Year Add_Delta_Days/;
34
use Carp;
34
use Carp;
35
35
36
use LWP::UserAgent;
37
use Koha::SharedContent;
38
use Koha::Patrons;
39
use Koha::Subscriptions;
40
use Koha::Libraries;
41
36
my $query = new CGI;
42
my $query = new CGI;
37
my $op = $query->param('op') || q{};
43
my $op = $query->param('op') || q{};
38
my $issueconfirmed = $query->param('issueconfirmed');
44
my $issueconfirmed = $query->param('issueconfirmed');
Lines 68-98 my ($totalissues,@serialslist) = GetSerials($subscriptionid); Link Here
68
$totalissues-- if $totalissues; # the -1 is to have 0 if this is a new subscription (only 1 issue)
74
$totalissues-- if $totalissues; # the -1 is to have 0 if this is a new subscription (only 1 issue)
69
75
70
if ($op eq 'del') {
76
if ($op eq 'del') {
71
	if ($$subs{'cannotedit'}){
77
    if ($$subs{'cannotedit'}){
72
		carp "Attempt to delete subscription $subscriptionid by ".C4::Context->userenv->{'id'}." not allowed";
78
        carp "Attempt to delete subscription $subscriptionid by ".C4::Context->userenv->{'id'}." not allowed";
73
		print $query->redirect("/cgi-bin/koha/serials/subscription-detail.pl?subscriptionid=$subscriptionid");
79
        print $query->redirect("/cgi-bin/koha/serials/subscription-detail.pl?subscriptionid=$subscriptionid");
74
		exit;
80
        exit;
75
	}
81
    }
76
	
82
77
    # Asking for confirmation if the subscription has not strictly expired yet or if it has linked issues
83
    # Asking for confirmation if the subscription has not strictly expired yet or if it has linked issues
78
    my $strictlyexpired = HasSubscriptionStrictlyExpired($subscriptionid);
84
    my $strictlyexpired = HasSubscriptionStrictlyExpired($subscriptionid);
79
    my $linkedissues = CountIssues($subscriptionid);
85
    my $linkedissues = CountIssues($subscriptionid);
80
    my $countitems   = HasItems($subscriptionid);
86
    my $countitems   = HasItems($subscriptionid);
81
    if ($strictlyexpired == 0 || $linkedissues > 0 || $countitems>0) {
87
    if ($strictlyexpired == 0 || $linkedissues > 0 || $countitems>0) {
82
		$template->param(NEEDSCONFIRMATION => 1);
88
        $template->param(NEEDSCONFIRMATION => 1);
83
		if ($strictlyexpired == 0) { $template->param("NOTEXPIRED" => 1); }
89
        if ($strictlyexpired == 0) { $template->param("NOTEXPIRED" => 1); }
84
		if ($linkedissues     > 0) { $template->param("LINKEDISSUES" => 1); }
90
        if ($linkedissues     > 0) { $template->param("LINKEDISSUES" => 1); }
85
		if ($countitems       > 0) { $template->param("LINKEDITEMS"  => 1); }
91
        if ($countitems       > 0) { $template->param("LINKEDITEMS"  => 1); }
86
    } else {
92
    } else {
87
		$issueconfirmed = "1";
93
        $issueconfirmed = "1";
88
    }
94
    }
89
    # If it's ok to delete the subscription, we do so
95
    # If it's ok to delete the subscription, we do so
90
    if ($issueconfirmed eq "1") {
96
    if ($issueconfirmed eq "1") {
91
		&DelSubscription($subscriptionid);
97
        &DelSubscription($subscriptionid);
92
        print $query->redirect("/cgi-bin/koha/serials/serials-home.pl");
98
        print $query->redirect("/cgi-bin/koha/serials/serials-home.pl");
93
        exit;
99
        exit;
94
    }
100
    }
95
}
101
}
102
elsif ( $op and $op eq "share" ) {
103
    my $mana_language;
104
    if ( $query->param('mana_language') ) {
105
        $mana_language = $query->param('mana_language');
106
    }
107
    else {
108
        $mana_language = C4::Context->preference('language');
109
    }
110
111
    my $mana_email;
112
    if ( $loggedinuser ne 0 ) {
113
        my $borrower = Koha::Patrons->find($loggedinuser);
114
        $mana_email = $borrower->email
115
          if ( ( not defined($mana_email) ) or ( $mana_email eq '' ) );
116
        $mana_email = $borrower->emailpro
117
          if ( ( not defined($mana_email) ) or ( $mana_email eq '' ) );
118
        $mana_email =
119
          Koha::Libraries->find( C4::Context->userenv->{'branch'} )->branchemail
120
          if ( ( not defined($mana_email) ) or ( $mana_email eq '' ) );
121
    }
122
    $mana_email = C4::Context->preference('KohaAdminEmailAddress')
123
      if ( ( not defined($mana_email) ) or ( $mana_email eq '' ) );
124
    my %versions = C4::Context::get_versions();
125
126
    my $mana_info = {
127
        language    => $mana_language,
128
        kohaversion => $versions{'kohaVersion'},
129
        exportemail => $mana_email
130
    };
131
    my $sub_mana_info = Koha::Subscription::get_sharable_info($subscriptionid);
132
    $sub_mana_info = { %$sub_mana_info, %$mana_info };
133
    my $result = Koha::SharedContent::manaPostRequest( "subscription",
134
        $sub_mana_info );
135
    if ( $result->{code} eq "200" and $result->{code} eq "201" ) {
136
        my $subscription = Koha::Subscriptions->find($subscriptionid);
137
        $subscription->set( { mana_id => $result->{id} } )->store;
138
        $subs->{mana_id} = $result->{id};
139
    }
140
    $template->param( mana_code => $result->{code} );
141
}
142
96
my $hasRouting = check_routing($subscriptionid);
143
my $hasRouting = check_routing($subscriptionid);
97
144
98
(undef, $cookie, undef, undef)
145
(undef, $cookie, undef, undef)
99
- 

Return to bug 17047