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

(-)a/C4/Serials.pm (-4 / +4 lines)
Lines 1402-1408 sub NewSubscription { Link Here
1402
    $innerloop3, $status, $notes, $letter, $firstacquidate, $irregularity,
1402
    $innerloop3, $status, $notes, $letter, $firstacquidate, $irregularity,
1403
    $numberpattern, $locale, $callnumber, $manualhistory, $internalnotes,
1403
    $numberpattern, $locale, $callnumber, $manualhistory, $internalnotes,
1404
    $serialsadditems, $staffdisplaycount, $opacdisplaycount, $graceperiod,
1404
    $serialsadditems, $staffdisplaycount, $opacdisplaycount, $graceperiod,
1405
    $location, $enddate, $skip_serialseq, $itemtype, $previousitemtype
1405
    $location, $enddate, $skip_serialseq, $itemtype, $previousitemtype, $mana_id
1406
    ) = @_;
1406
    ) = @_;
1407
    my $dbh = C4::Context->dbh;
1407
    my $dbh = C4::Context->dbh;
1408
1408
Lines 1416-1423 sub NewSubscription { Link Here
1416
            irregularity, numberpattern, locale, callnumber,
1416
            irregularity, numberpattern, locale, callnumber,
1417
            manualhistory, internalnotes, serialsadditems, staffdisplaycount,
1417
            manualhistory, internalnotes, serialsadditems, staffdisplaycount,
1418
            opacdisplaycount, graceperiod, location, enddate, skip_serialseq,
1418
            opacdisplaycount, graceperiod, location, enddate, skip_serialseq,
1419
            itemtype, previousitemtype)
1419
            itemtype, previousitemtype, mana_id)
1420
        VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)
1420
        VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?, ?)
1421
        |;
1421
        |;
1422
    my $sth = $dbh->prepare($query);
1422
    my $sth = $dbh->prepare($query);
1423
    $sth->execute(
1423
    $sth->execute(
Lines 1428-1434 sub NewSubscription { Link Here
1428
        $firstacquidate, $irregularity, $numberpattern, $locale, $callnumber,
1428
        $firstacquidate, $irregularity, $numberpattern, $locale, $callnumber,
1429
        $manualhistory, $internalnotes, $serialsadditems, $staffdisplaycount,
1429
        $manualhistory, $internalnotes, $serialsadditems, $staffdisplaycount,
1430
        $opacdisplaycount, $graceperiod, $location, $enddate, $skip_serialseq,
1430
        $opacdisplaycount, $graceperiod, $location, $enddate, $skip_serialseq,
1431
        $itemtype, $previousitemtype
1431
        $itemtype, $previousitemtype, $mana_id
1432
    );
1432
    );
1433
1433
1434
    my $subscriptionid = $dbh->{'mysql_insertid'};
1434
    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-small" 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-small" 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 32-37 use Koha::Acquisition::Bookseller; Link Here
32
use Date::Calc qw/Today Day_of_Year Week_of_Year Add_Delta_Days/;
32
use Date::Calc qw/Today Day_of_Year Week_of_Year Add_Delta_Days/;
33
use Carp;
33
use Carp;
34
34
35
use LWP::UserAgent;
36
use Koha::SharedContent;
37
use Koha::Patrons;
38
use Koha::Subscriptions;
39
use Koha::Libraries;
40
35
my $query = new CGI;
41
my $query = new CGI;
36
my $op = $query->param('op') || q{};
42
my $op = $query->param('op') || q{};
37
my $issueconfirmed = $query->param('issueconfirmed');
43
my $issueconfirmed = $query->param('issueconfirmed');
Lines 67-97 my ($totalissues,@serialslist) = GetSerials($subscriptionid); Link Here
67
$totalissues-- if $totalissues; # the -1 is to have 0 if this is a new subscription (only 1 issue)
73
$totalissues-- if $totalissues; # the -1 is to have 0 if this is a new subscription (only 1 issue)
68
74
69
if ($op eq 'del') {
75
if ($op eq 'del') {
70
	if ($$subs{'cannotedit'}){
76
    if ($$subs{'cannotedit'}){
71
		carp "Attempt to delete subscription $subscriptionid by ".C4::Context->userenv->{'id'}." not allowed";
77
        carp "Attempt to delete subscription $subscriptionid by ".C4::Context->userenv->{'id'}." not allowed";
72
		print $query->redirect("/cgi-bin/koha/serials/subscription-detail.pl?subscriptionid=$subscriptionid");
78
        print $query->redirect("/cgi-bin/koha/serials/subscription-detail.pl?subscriptionid=$subscriptionid");
73
		exit;
79
        exit;
74
	}
80
    }
75
	
81
76
    # Asking for confirmation if the subscription has not strictly expired yet or if it has linked issues
82
    # Asking for confirmation if the subscription has not strictly expired yet or if it has linked issues
77
    my $strictlyexpired = HasSubscriptionStrictlyExpired($subscriptionid);
83
    my $strictlyexpired = HasSubscriptionStrictlyExpired($subscriptionid);
78
    my $linkedissues = CountIssues($subscriptionid);
84
    my $linkedissues = CountIssues($subscriptionid);
79
    my $countitems   = HasItems($subscriptionid);
85
    my $countitems   = HasItems($subscriptionid);
80
    if ($strictlyexpired == 0 || $linkedissues > 0 || $countitems>0) {
86
    if ($strictlyexpired == 0 || $linkedissues > 0 || $countitems>0) {
81
		$template->param(NEEDSCONFIRMATION => 1);
87
        $template->param(NEEDSCONFIRMATION => 1);
82
		if ($strictlyexpired == 0) { $template->param("NOTEXPIRED" => 1); }
88
        if ($strictlyexpired == 0) { $template->param("NOTEXPIRED" => 1); }
83
		if ($linkedissues     > 0) { $template->param("LINKEDISSUES" => 1); }
89
        if ($linkedissues     > 0) { $template->param("LINKEDISSUES" => 1); }
84
		if ($countitems       > 0) { $template->param("LINKEDITEMS"  => 1); }
90
        if ($countitems       > 0) { $template->param("LINKEDITEMS"  => 1); }
85
    } else {
91
    } else {
86
		$issueconfirmed = "1";
92
        $issueconfirmed = "1";
87
    }
93
    }
88
    # If it's ok to delete the subscription, we do so
94
    # If it's ok to delete the subscription, we do so
89
    if ($issueconfirmed eq "1") {
95
    if ($issueconfirmed eq "1") {
90
		&DelSubscription($subscriptionid);
96
        &DelSubscription($subscriptionid);
91
        print $query->redirect("/cgi-bin/koha/serials/serials-home.pl");
97
        print $query->redirect("/cgi-bin/koha/serials/serials-home.pl");
92
        exit;
98
        exit;
93
    }
99
    }
94
}
100
}
101
elsif ( $op and $op eq "share" ) {
102
    my $mana_language;
103
    if ( $query->param('mana_language') ) {
104
        $mana_language = $query->param('mana_language');
105
    }
106
    else {
107
        $mana_language = C4::Context->preference('language');
108
    }
109
110
    my $mana_email;
111
    if ( $loggedinuser ne 0 ) {
112
        my $borrower = Koha::Patrons->find($loggedinuser);
113
        $mana_email = $borrower->email
114
          if ( ( not defined($mana_email) ) or ( $mana_email eq '' ) );
115
        $mana_email = $borrower->emailpro
116
          if ( ( not defined($mana_email) ) or ( $mana_email eq '' ) );
117
        $mana_email =
118
          Koha::Libraries->find( C4::Context->userenv->{'branch'} )->branchemail
119
          if ( ( not defined($mana_email) ) or ( $mana_email eq '' ) );
120
    }
121
    $mana_email = C4::Context->preference('KohaAdminEmailAddress')
122
      if ( ( not defined($mana_email) ) or ( $mana_email eq '' ) );
123
    my %versions = C4::Context::get_versions();
124
125
    my $mana_info = {
126
        language    => $mana_language,
127
        kohaversion => $versions{'kohaVersion'},
128
        exportemail => $mana_email
129
    };
130
    my $sub_mana_info = Koha::Subscription::get_sharable_info($subscriptionid);
131
    $sub_mana_info = { %$sub_mana_info, %$mana_info };
132
    my $result = Koha::SharedContent::manaPostRequest( "subscription",
133
        $sub_mana_info );
134
    if ( $result->{code} eq "200" and $result->{code} eq "201" ) {
135
        my $subscription = Koha::Subscriptions->find($subscriptionid);
136
        $subscription->set( { mana_id => $result->{id} } )->store;
137
        $subs->{mana_id} = $result->{id};
138
    }
139
    $template->param( mana_code => $result->{code} );
140
}
141
95
my $hasRouting = check_routing($subscriptionid);
142
my $hasRouting = check_routing($subscriptionid);
96
143
97
(undef, $cookie, undef, undef)
144
(undef, $cookie, undef, undef)
98
- 

Return to bug 17047